2009-12-11 09:24:15 +00:00
|
|
|
/*
|
2013-02-16 05:21:58 +00:00
|
|
|
* Copyright 2013 Red Hat Inc.
|
2009-12-11 09:24:15 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors: Ben Skeggs
|
|
|
|
*/
|
2015-01-14 05:04:16 +00:00
|
|
|
#include "priv.h"
|
|
|
|
#include "pad.h"
|
2009-12-11 09:24:15 +00:00
|
|
|
|
2015-01-14 04:11:21 +00:00
|
|
|
#include <core/notify.h>
|
2013-02-16 05:21:58 +00:00
|
|
|
#include <core/option.h>
|
2013-02-14 22:48:58 +00:00
|
|
|
#include <subdev/bios.h>
|
|
|
|
#include <subdev/bios/dcb.h>
|
2014-05-13 03:59:26 +00:00
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* interface to linux i2c bit-banging algorithm
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2015-01-14 05:05:26 +00:00
|
|
|
#ifdef CONFIG_NOUVEAU_I2C_INTERNAL_DEFAULT
|
2013-02-16 05:21:58 +00:00
|
|
|
#define CSTMSEL true
|
|
|
|
#else
|
|
|
|
#define CSTMSEL false
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_pre_xfer(struct i2c_adapter *adap)
|
2012-07-10 04:36:38 +00:00
|
|
|
{
|
2013-02-16 05:21:58 +00:00
|
|
|
struct i2c_algo_bit_data *bit = adap->algo_data;
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c_port *port = bit->data;
|
|
|
|
return nvkm_i2c(port)->acquire(port, bit->timeout);
|
2014-05-29 01:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_post_xfer(struct i2c_adapter *adap)
|
2014-05-29 01:07:16 +00:00
|
|
|
{
|
|
|
|
struct i2c_algo_bit_data *bit = adap->algo_data;
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c_port *port = bit->data;
|
|
|
|
return nvkm_i2c(port)->release(port);
|
2013-02-16 05:21:58 +00:00
|
|
|
}
|
2012-07-10 04:36:38 +00:00
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
static void
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_setscl(void *data, int state)
|
2013-02-16 05:21:58 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c_port *port = data;
|
2013-02-16 05:21:58 +00:00
|
|
|
port->func->drive_scl(port, state);
|
|
|
|
}
|
2012-07-10 04:36:38 +00:00
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
static void
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_setsda(void *data, int state)
|
2013-02-16 05:21:58 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c_port *port = data;
|
2013-02-16 05:21:58 +00:00
|
|
|
port->func->drive_sda(port, state);
|
2012-07-10 04:36:38 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
static int
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_getscl(void *data)
|
2012-07-10 04:36:38 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c_port *port = data;
|
2013-02-16 05:21:58 +00:00
|
|
|
return port->func->sense_scl(port);
|
|
|
|
}
|
2012-07-10 04:36:38 +00:00
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
static int
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_getsda(void *data)
|
2013-02-16 05:21:58 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c_port *port = data;
|
2013-02-16 05:21:58 +00:00
|
|
|
return port->func->sense_sda(port);
|
|
|
|
}
|
2012-07-10 04:36:38 +00:00
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* base i2c "port" class implementation
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2014-05-29 01:35:10 +00:00
|
|
|
int
|
2015-01-14 05:04:16 +00:00
|
|
|
_nvkm_i2c_port_fini(struct nvkm_object *object, bool suspend)
|
2014-05-29 01:35:10 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c_port *port = (void *)object;
|
2014-05-29 01:35:10 +00:00
|
|
|
struct nvkm_i2c_pad *pad = nvkm_i2c_pad(port);
|
|
|
|
nv_ofuncs(pad)->fini(nv_object(pad), suspend);
|
2015-01-14 05:04:16 +00:00
|
|
|
return nvkm_object_fini(&port->base, suspend);
|
2014-05-29 01:35:10 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
void
|
2015-01-14 05:04:16 +00:00
|
|
|
_nvkm_i2c_port_dtor(struct nvkm_object *object)
|
2013-02-16 05:21:58 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c_port *port = (void *)object;
|
2013-02-16 05:21:58 +00:00
|
|
|
i2c_del_adapter(&port->adapter);
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_object_destroy(&port->base);
|
2012-07-10 04:36:38 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
int
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_port_create_(struct nvkm_object *parent, struct nvkm_object *engine,
|
|
|
|
struct nvkm_oclass *oclass, u8 index,
|
|
|
|
const struct i2c_algorithm *algo,
|
|
|
|
const struct nvkm_i2c_func *func,
|
|
|
|
int size, void **pobject)
|
2012-07-10 04:36:38 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_device *device = nv_device(parent);
|
|
|
|
struct nvkm_i2c *i2c = nvkm_i2c(parent);
|
|
|
|
struct nvkm_i2c_port *port;
|
2013-02-16 05:21:58 +00:00
|
|
|
int ret;
|
|
|
|
|
2015-01-14 05:04:16 +00:00
|
|
|
ret = nvkm_object_create_(parent, engine, oclass, 0, size, pobject);
|
2013-02-16 05:21:58 +00:00
|
|
|
port = *pobject;
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
snprintf(port->adapter.name, sizeof(port->adapter.name),
|
2015-01-14 05:04:16 +00:00
|
|
|
"nvkm-%s-%d", device->name, index);
|
2013-02-16 05:21:58 +00:00
|
|
|
port->adapter.owner = THIS_MODULE;
|
2014-02-17 06:17:26 +00:00
|
|
|
port->adapter.dev.parent = nv_device_base(device);
|
2013-02-16 05:21:58 +00:00
|
|
|
port->index = index;
|
2014-05-13 04:47:36 +00:00
|
|
|
port->aux = -1;
|
2013-08-23 17:03:14 +00:00
|
|
|
port->func = func;
|
2014-05-29 01:35:10 +00:00
|
|
|
mutex_init(&port->mutex);
|
2013-02-16 05:21:58 +00:00
|
|
|
|
2015-01-14 05:04:16 +00:00
|
|
|
if ( algo == &nvkm_i2c_bit_algo &&
|
|
|
|
!nvkm_boolopt(device->cfgopt, "NvI2C", CSTMSEL)) {
|
2013-02-16 05:21:58 +00:00
|
|
|
struct i2c_algo_bit_data *bit;
|
|
|
|
|
|
|
|
bit = kzalloc(sizeof(*bit), GFP_KERNEL);
|
|
|
|
if (!bit)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
bit->udelay = 10;
|
|
|
|
bit->timeout = usecs_to_jiffies(2200);
|
|
|
|
bit->data = port;
|
2015-01-14 05:04:16 +00:00
|
|
|
bit->pre_xfer = nvkm_i2c_pre_xfer;
|
|
|
|
bit->post_xfer = nvkm_i2c_post_xfer;
|
|
|
|
bit->setsda = nvkm_i2c_setsda;
|
|
|
|
bit->setscl = nvkm_i2c_setscl;
|
|
|
|
bit->getsda = nvkm_i2c_getsda;
|
|
|
|
bit->getscl = nvkm_i2c_getscl;
|
2013-02-16 05:21:58 +00:00
|
|
|
|
|
|
|
port->adapter.algo_data = bit;
|
|
|
|
ret = i2c_bit_add_bus(&port->adapter);
|
|
|
|
} else {
|
|
|
|
port->adapter.algo_data = port;
|
|
|
|
port->adapter.algo = algo;
|
|
|
|
ret = i2c_add_adapter(&port->adapter);
|
|
|
|
}
|
|
|
|
|
2013-04-24 07:36:57 +00:00
|
|
|
if (ret == 0)
|
2013-02-16 05:21:58 +00:00
|
|
|
list_add_tail(&port->head, &i2c->ports);
|
|
|
|
return ret;
|
2012-07-10 04:36:38 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* base i2c subdev class implementation
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2015-01-14 05:04:16 +00:00
|
|
|
static struct nvkm_i2c_port *
|
|
|
|
nvkm_i2c_find(struct nvkm_i2c *i2c, u8 index)
|
2012-07-10 04:36:38 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_bios *bios = nvkm_bios(i2c);
|
|
|
|
struct nvkm_i2c_port *port;
|
2012-07-10 04:36:38 +00:00
|
|
|
|
|
|
|
if (index == NV_I2C_DEFAULT(0) ||
|
|
|
|
index == NV_I2C_DEFAULT(1)) {
|
|
|
|
u8 ver, hdr, cnt, len;
|
|
|
|
u16 i2c = dcb_i2c_table(bios, &ver, &hdr, &cnt, &len);
|
|
|
|
if (i2c && ver >= 0x30) {
|
2015-08-20 04:54:13 +00:00
|
|
|
u8 auxidx = nvbios_rd08(bios, i2c + 4);
|
2012-07-10 04:36:38 +00:00
|
|
|
if (index == NV_I2C_DEFAULT(0))
|
|
|
|
index = (auxidx & 0x0f) >> 0;
|
|
|
|
else
|
|
|
|
index = (auxidx & 0xf0) >> 4;
|
|
|
|
} else {
|
|
|
|
index = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(port, &i2c->ports, head) {
|
|
|
|
if (port->index == index)
|
2013-02-11 10:06:04 +00:00
|
|
|
return port;
|
2012-07-10 04:36:38 +00:00
|
|
|
}
|
|
|
|
|
2013-02-11 10:06:04 +00:00
|
|
|
return NULL;
|
2012-07-10 04:36:38 +00:00
|
|
|
}
|
|
|
|
|
2015-01-14 05:04:16 +00:00
|
|
|
static struct nvkm_i2c_port *
|
|
|
|
nvkm_i2c_find_type(struct nvkm_i2c *i2c, u16 type)
|
2013-02-16 03:19:18 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c_port *port;
|
2013-02-16 03:19:18 +00:00
|
|
|
|
|
|
|
list_for_each_entry(port, &i2c->ports, head) {
|
2013-02-16 05:21:58 +00:00
|
|
|
if (nv_hclass(port) == type)
|
2013-02-16 03:19:18 +00:00
|
|
|
return port;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-29 01:35:10 +00:00
|
|
|
static void
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_release_pad(struct nvkm_i2c_port *port)
|
2014-05-29 01:35:10 +00:00
|
|
|
{
|
|
|
|
struct nvkm_i2c_pad *pad = nvkm_i2c_pad(port);
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c *i2c = nvkm_i2c(port);
|
2014-05-29 01:35:10 +00:00
|
|
|
|
|
|
|
if (atomic_dec_and_test(&nv_object(pad)->usecount)) {
|
|
|
|
nv_ofuncs(pad)->fini(nv_object(pad), false);
|
|
|
|
wake_up_all(&i2c->wait);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_try_acquire_pad(struct nvkm_i2c_port *port)
|
2014-05-29 01:35:10 +00:00
|
|
|
{
|
|
|
|
struct nvkm_i2c_pad *pad = nvkm_i2c_pad(port);
|
|
|
|
|
|
|
|
if (atomic_add_return(1, &nv_object(pad)->usecount) != 1) {
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_object *owner = (void *)pad->port;
|
2014-05-29 01:35:10 +00:00
|
|
|
do {
|
|
|
|
if (owner == (void *)port)
|
|
|
|
return 0;
|
|
|
|
owner = owner->parent;
|
|
|
|
} while(owner);
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_release_pad(port);
|
2014-05-29 01:35:10 +00:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
pad->next = port;
|
|
|
|
nv_ofuncs(pad)->init(nv_object(pad));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_acquire_pad(struct nvkm_i2c_port *port, unsigned long timeout)
|
2014-05-29 01:35:10 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c *i2c = nvkm_i2c(port);
|
2014-05-29 01:35:10 +00:00
|
|
|
|
|
|
|
if (timeout) {
|
|
|
|
if (wait_event_timeout(i2c->wait,
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_try_acquire_pad(port) == 0,
|
2014-05-29 01:35:10 +00:00
|
|
|
timeout) == 0)
|
|
|
|
return -EBUSY;
|
|
|
|
} else {
|
2015-01-14 05:04:16 +00:00
|
|
|
wait_event(i2c->wait, nvkm_i2c_try_acquire_pad(port) == 0);
|
2014-05-29 01:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-29 01:07:16 +00:00
|
|
|
static void
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_release(struct nvkm_i2c_port *port)
|
2014-05-29 01:35:10 +00:00
|
|
|
__releases(pad->mutex)
|
2014-05-29 01:07:16 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c(port)->release_pad(port);
|
2014-05-29 01:35:10 +00:00
|
|
|
mutex_unlock(&port->mutex);
|
2014-05-29 01:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_acquire(struct nvkm_i2c_port *port, unsigned long timeout)
|
2014-05-29 01:35:10 +00:00
|
|
|
__acquires(pad->mutex)
|
2014-05-29 01:07:16 +00:00
|
|
|
{
|
2014-05-29 01:35:10 +00:00
|
|
|
int ret;
|
|
|
|
mutex_lock(&port->mutex);
|
2015-01-14 05:04:16 +00:00
|
|
|
if ((ret = nvkm_i2c(port)->acquire_pad(port, timeout)))
|
2014-05-29 01:35:10 +00:00
|
|
|
mutex_unlock(&port->mutex);
|
|
|
|
return ret;
|
2014-05-29 01:07:16 +00:00
|
|
|
}
|
|
|
|
|
2012-07-10 04:36:38 +00:00
|
|
|
static int
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_identify(struct nvkm_i2c *i2c, int index, const char *what,
|
|
|
|
struct nvkm_i2c_board_info *info,
|
|
|
|
bool (*match)(struct nvkm_i2c_port *,
|
|
|
|
struct i2c_board_info *, void *), void *data)
|
2009-12-11 09:24:15 +00:00
|
|
|
{
|
2015-08-20 04:54:12 +00:00
|
|
|
struct nvkm_subdev *subdev = &i2c->subdev;
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c_port *port = nvkm_i2c_find(i2c, index);
|
2012-07-10 04:36:38 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!port) {
|
2015-08-20 04:54:12 +00:00
|
|
|
nvkm_debug(subdev, "no bus when probing %s on %d\n",
|
|
|
|
what, index);
|
2012-07-10 04:36:38 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2015-08-20 04:54:12 +00:00
|
|
|
nvkm_debug(subdev, "probing %ss on bus: %d\n", what, port->index);
|
2013-10-20 23:48:55 +00:00
|
|
|
for (i = 0; info[i].dev.addr; i++) {
|
|
|
|
u8 orig_udelay = 0;
|
|
|
|
|
|
|
|
if ((port->adapter.algo == &i2c_bit_algo) &&
|
|
|
|
(info[i].udelay != 0)) {
|
|
|
|
struct i2c_algo_bit_data *algo = port->adapter.algo_data;
|
2015-08-20 04:54:12 +00:00
|
|
|
nvkm_debug(subdev,
|
|
|
|
"using custom udelay %d instead of %d\n",
|
|
|
|
info[i].udelay, algo->udelay);
|
2013-10-20 23:48:55 +00:00
|
|
|
orig_udelay = algo->udelay;
|
|
|
|
algo->udelay = info[i].udelay;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nv_probe_i2c(port, info[i].dev.addr) &&
|
2014-01-14 04:56:22 +00:00
|
|
|
(!match || match(port, &info[i].dev, data))) {
|
2015-08-20 04:54:12 +00:00
|
|
|
nvkm_info(subdev, "detected %s: %s\n", what,
|
|
|
|
info[i].dev.type);
|
2012-07-10 04:36:38 +00:00
|
|
|
return i;
|
|
|
|
}
|
2013-10-20 23:48:55 +00:00
|
|
|
|
|
|
|
if (orig_udelay) {
|
|
|
|
struct i2c_algo_bit_data *algo = port->adapter.algo_data;
|
|
|
|
algo->udelay = orig_udelay;
|
|
|
|
}
|
2012-07-10 04:36:38 +00:00
|
|
|
}
|
|
|
|
|
2015-08-20 04:54:12 +00:00
|
|
|
nvkm_debug(subdev, "no devices found.\n");
|
2012-07-10 04:36:38 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2014-05-13 04:47:36 +00:00
|
|
|
static void
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_intr_fini(struct nvkm_event *event, int type, int index)
|
2014-05-13 04:47:36 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c *i2c = container_of(event, typeof(*i2c), event);
|
|
|
|
struct nvkm_i2c_port *port = i2c->find(i2c, index);
|
|
|
|
const struct nvkm_i2c_impl *impl = (void *)nv_object(i2c)->oclass;
|
2014-05-13 04:47:36 +00:00
|
|
|
if (port && port->aux >= 0)
|
|
|
|
impl->aux_mask(i2c, type, 1 << port->aux, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_intr_init(struct nvkm_event *event, int type, int index)
|
2014-05-13 04:47:36 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c *i2c = container_of(event, typeof(*i2c), event);
|
|
|
|
struct nvkm_i2c_port *port = i2c->find(i2c, index);
|
|
|
|
const struct nvkm_i2c_impl *impl = (void *)nv_object(i2c)->oclass;
|
2014-05-13 04:47:36 +00:00
|
|
|
if (port && port->aux >= 0)
|
|
|
|
impl->aux_mask(i2c, type, 1 << port->aux, 1 << port->aux);
|
|
|
|
}
|
|
|
|
|
2014-08-09 18:10:20 +00:00
|
|
|
static int
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_intr_ctor(struct nvkm_object *object, void *data, u32 size,
|
2014-08-11 03:56:56 +00:00
|
|
|
struct nvkm_notify *notify)
|
2014-08-09 18:10:20 +00:00
|
|
|
{
|
|
|
|
struct nvkm_i2c_ntfy_req *req = data;
|
|
|
|
if (!WARN_ON(size != sizeof(*req))) {
|
|
|
|
notify->size = sizeof(struct nvkm_i2c_ntfy_rep);
|
|
|
|
notify->types = req->mask;
|
|
|
|
notify->index = req->port;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-05-13 04:47:36 +00:00
|
|
|
static void
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_intr(struct nvkm_subdev *subdev)
|
2014-05-13 04:47:36 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c_impl *impl = (void *)nv_oclass(subdev);
|
|
|
|
struct nvkm_i2c *i2c = nvkm_i2c(subdev);
|
|
|
|
struct nvkm_i2c_port *port;
|
2014-05-13 04:47:36 +00:00
|
|
|
u32 hi, lo, rq, tx, e;
|
|
|
|
|
|
|
|
if (impl->aux_stat) {
|
|
|
|
impl->aux_stat(i2c, &hi, &lo, &rq, &tx);
|
|
|
|
if (hi || lo || rq || tx) {
|
|
|
|
list_for_each_entry(port, &i2c->ports, head) {
|
|
|
|
if (e = 0, port->aux < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (hi & (1 << port->aux)) e |= NVKM_I2C_PLUG;
|
|
|
|
if (lo & (1 << port->aux)) e |= NVKM_I2C_UNPLUG;
|
|
|
|
if (rq & (1 << port->aux)) e |= NVKM_I2C_IRQ;
|
|
|
|
if (tx & (1 << port->aux)) e |= NVKM_I2C_DONE;
|
2014-08-09 18:10:20 +00:00
|
|
|
if (e) {
|
|
|
|
struct nvkm_i2c_ntfy_rep rep = {
|
|
|
|
.mask = e,
|
|
|
|
};
|
|
|
|
nvkm_event_send(&i2c->event, rep.mask,
|
|
|
|
port->index, &rep,
|
|
|
|
sizeof(rep));
|
|
|
|
}
|
2014-05-13 04:47:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-09 18:10:20 +00:00
|
|
|
static const struct nvkm_event_func
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_intr_func = {
|
|
|
|
.ctor = nvkm_i2c_intr_ctor,
|
|
|
|
.init = nvkm_i2c_intr_init,
|
|
|
|
.fini = nvkm_i2c_intr_fini,
|
2014-08-09 18:10:20 +00:00
|
|
|
};
|
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
int
|
2015-01-14 05:04:16 +00:00
|
|
|
_nvkm_i2c_fini(struct nvkm_object *object, bool suspend)
|
2012-07-10 04:36:38 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c_impl *impl = (void *)nv_oclass(object);
|
|
|
|
struct nvkm_i2c *i2c = (void *)object;
|
|
|
|
struct nvkm_i2c_port *port;
|
2014-05-13 04:47:36 +00:00
|
|
|
u32 mask;
|
2013-02-16 05:21:58 +00:00
|
|
|
int ret;
|
2012-07-10 04:36:38 +00:00
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
list_for_each_entry(port, &i2c->ports, head) {
|
|
|
|
ret = nv_ofuncs(port)->fini(nv_object(port), suspend);
|
|
|
|
if (ret && suspend)
|
|
|
|
goto fail;
|
2011-11-17 03:56:14 +00:00
|
|
|
}
|
2012-07-10 04:36:38 +00:00
|
|
|
|
2014-05-13 04:47:36 +00:00
|
|
|
if ((mask = (1 << impl->aux) - 1), impl->aux_stat) {
|
|
|
|
impl->aux_mask(i2c, NVKM_I2C_ANY, mask, 0);
|
|
|
|
impl->aux_stat(i2c, &mask, &mask, &mask, &mask);
|
|
|
|
}
|
|
|
|
|
2015-08-20 04:54:06 +00:00
|
|
|
return nvkm_subdev_fini(&i2c->subdev, suspend);
|
2013-02-16 05:21:58 +00:00
|
|
|
fail:
|
|
|
|
list_for_each_entry_continue_reverse(port, &i2c->ports, head) {
|
|
|
|
nv_ofuncs(port)->init(nv_object(port));
|
2011-11-17 03:56:14 +00:00
|
|
|
}
|
2013-02-16 05:21:58 +00:00
|
|
|
|
|
|
|
return ret;
|
2009-12-11 09:24:15 +00:00
|
|
|
}
|
|
|
|
|
2012-07-10 04:36:38 +00:00
|
|
|
int
|
2015-01-14 05:04:16 +00:00
|
|
|
_nvkm_i2c_init(struct nvkm_object *object)
|
2011-07-02 10:43:42 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c *i2c = (void *)object;
|
|
|
|
struct nvkm_i2c_port *port;
|
2013-02-16 05:21:58 +00:00
|
|
|
int ret;
|
|
|
|
|
2015-08-20 04:54:06 +00:00
|
|
|
ret = nvkm_subdev_init(&i2c->subdev);
|
2013-02-16 05:21:58 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
list_for_each_entry(port, &i2c->ports, head) {
|
|
|
|
ret = nv_ofuncs(port)->init(nv_object(port));
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
}
|
2011-11-17 03:56:14 +00:00
|
|
|
}
|
2012-07-10 04:36:38 +00:00
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
return ret;
|
|
|
|
fail:
|
|
|
|
list_for_each_entry_continue_reverse(port, &i2c->ports, head) {
|
|
|
|
nv_ofuncs(port)->fini(nv_object(port), false);
|
2011-11-17 03:56:14 +00:00
|
|
|
}
|
2012-07-10 04:36:38 +00:00
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
return ret;
|
2011-07-02 10:43:42 +00:00
|
|
|
}
|
2009-12-11 09:24:15 +00:00
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
void
|
2015-01-14 05:04:16 +00:00
|
|
|
_nvkm_i2c_dtor(struct nvkm_object *object)
|
2013-02-11 10:06:04 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c *i2c = (void *)object;
|
|
|
|
struct nvkm_i2c_port *port, *temp;
|
2013-02-16 05:21:58 +00:00
|
|
|
|
2014-08-09 18:10:20 +00:00
|
|
|
nvkm_event_fini(&i2c->event);
|
2014-05-13 04:47:36 +00:00
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
list_for_each_entry_safe(port, temp, &i2c->ports, head) {
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_object_ref(NULL, (struct nvkm_object **)&port);
|
2013-02-11 10:06:04 +00:00
|
|
|
}
|
|
|
|
|
2015-08-20 04:54:06 +00:00
|
|
|
nvkm_subdev_destroy(&i2c->subdev);
|
2013-02-11 10:06:04 +00:00
|
|
|
}
|
|
|
|
|
2015-01-14 05:04:16 +00:00
|
|
|
static struct nvkm_oclass *
|
|
|
|
nvkm_i2c_extdev_sclass[] = {
|
|
|
|
nvkm_anx9805_sclass,
|
2013-02-14 22:48:58 +00:00
|
|
|
};
|
|
|
|
|
2014-08-18 22:14:08 +00:00
|
|
|
static void
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_create_port(struct nvkm_i2c *i2c, int index, u8 type,
|
|
|
|
struct dcb_i2c_entry *info)
|
2014-08-18 22:14:08 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
const struct nvkm_i2c_impl *impl = (void *)nv_oclass(i2c);
|
|
|
|
struct nvkm_oclass *oclass;
|
|
|
|
struct nvkm_object *parent;
|
|
|
|
struct nvkm_object *object;
|
2014-08-18 22:14:08 +00:00
|
|
|
int ret, pad;
|
|
|
|
|
|
|
|
if (info->share != DCB_I2C_UNUSED) {
|
|
|
|
pad = info->share;
|
|
|
|
oclass = impl->pad_s;
|
|
|
|
} else {
|
|
|
|
if (type != DCB_I2C_NVIO_AUX)
|
|
|
|
pad = 0x100 + info->drive;
|
|
|
|
else
|
|
|
|
pad = 0x100 + info->auxch;
|
|
|
|
oclass = impl->pad_x;
|
|
|
|
}
|
|
|
|
|
2015-01-14 05:04:16 +00:00
|
|
|
ret = nvkm_object_ctor(nv_object(i2c), NULL, oclass,
|
|
|
|
NULL, pad, &parent);
|
2014-08-18 22:14:08 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
oclass = impl->sclass;
|
|
|
|
do {
|
|
|
|
ret = -EINVAL;
|
|
|
|
if (oclass->handle == type) {
|
2015-01-14 05:04:16 +00:00
|
|
|
ret = nvkm_object_ctor(parent, NULL, oclass,
|
|
|
|
info, index, &object);
|
2014-08-18 22:14:08 +00:00
|
|
|
}
|
|
|
|
} while (ret && (++oclass)->handle);
|
|
|
|
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_object_ref(NULL, &parent);
|
2014-08-18 22:14:08 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
int
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_create_(struct nvkm_object *parent, struct nvkm_object *engine,
|
|
|
|
struct nvkm_oclass *oclass, int length, void **pobject)
|
2009-12-11 09:24:15 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_bios *bios = nvkm_bios(parent);
|
|
|
|
struct nvkm_i2c *i2c;
|
|
|
|
struct nvkm_object *object;
|
2012-07-10 04:36:38 +00:00
|
|
|
struct dcb_i2c_entry info;
|
2014-08-18 22:14:08 +00:00
|
|
|
int ret, i, j, index = -1;
|
2013-02-14 22:48:58 +00:00
|
|
|
struct dcb_output outp;
|
|
|
|
u8 ver, hdr;
|
|
|
|
u32 data;
|
2012-07-10 04:36:38 +00:00
|
|
|
|
2015-01-14 05:04:16 +00:00
|
|
|
ret = nvkm_subdev_create(parent, engine, oclass, 0, "I2C", "i2c", &i2c);
|
2012-07-10 04:36:38 +00:00
|
|
|
*pobject = nv_object(i2c);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-01-14 05:04:16 +00:00
|
|
|
nv_subdev(i2c)->intr = nvkm_i2c_intr;
|
|
|
|
i2c->find = nvkm_i2c_find;
|
|
|
|
i2c->find_type = nvkm_i2c_find_type;
|
|
|
|
i2c->acquire_pad = nvkm_i2c_acquire_pad;
|
|
|
|
i2c->release_pad = nvkm_i2c_release_pad;
|
|
|
|
i2c->acquire = nvkm_i2c_acquire;
|
|
|
|
i2c->release = nvkm_i2c_release;
|
|
|
|
i2c->identify = nvkm_i2c_identify;
|
2014-05-29 01:35:10 +00:00
|
|
|
init_waitqueue_head(&i2c->wait);
|
2012-07-10 04:36:38 +00:00
|
|
|
INIT_LIST_HEAD(&i2c->ports);
|
|
|
|
|
2013-02-16 05:21:58 +00:00
|
|
|
while (!dcb_i2c_parse(bios, ++index, &info)) {
|
2014-08-18 22:14:08 +00:00
|
|
|
switch (info.type) {
|
|
|
|
case DCB_I2C_NV04_BIT:
|
|
|
|
case DCB_I2C_NV4E_BIT:
|
|
|
|
case DCB_I2C_NVIO_BIT:
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_create_port(i2c, NV_I2C_PORT(index),
|
|
|
|
info.type, &info);
|
2014-09-24 00:41:50 +00:00
|
|
|
break;
|
2014-08-18 22:14:08 +00:00
|
|
|
case DCB_I2C_NVIO_AUX:
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_create_port(i2c, NV_I2C_AUX(index),
|
|
|
|
info.type, &info);
|
2014-08-18 22:14:08 +00:00
|
|
|
break;
|
2014-08-18 22:25:40 +00:00
|
|
|
case DCB_I2C_PMGR:
|
|
|
|
if (info.drive != DCB_I2C_UNUSED) {
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_create_port(i2c, NV_I2C_PORT(index),
|
|
|
|
DCB_I2C_NVIO_BIT, &info);
|
2014-08-18 22:25:40 +00:00
|
|
|
}
|
|
|
|
if (info.auxch != DCB_I2C_UNUSED) {
|
2015-01-14 05:04:16 +00:00
|
|
|
nvkm_i2c_create_port(i2c, NV_I2C_AUX(index),
|
|
|
|
DCB_I2C_NVIO_AUX, &info);
|
2014-08-18 22:25:40 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-08-18 22:14:08 +00:00
|
|
|
case DCB_I2C_UNUSED:
|
|
|
|
default:
|
2012-07-10 04:36:38 +00:00
|
|
|
continue;
|
2014-05-29 01:35:10 +00:00
|
|
|
}
|
2009-12-11 09:24:15 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 22:48:58 +00:00
|
|
|
/* in addition to the busses specified in the i2c table, there
|
|
|
|
* may be ddc/aux channels hiding behind external tmds/dp/etc
|
|
|
|
* transmitters.
|
|
|
|
*/
|
2014-09-24 00:41:50 +00:00
|
|
|
index = NV_I2C_EXT(0);
|
2013-02-14 22:48:58 +00:00
|
|
|
i = -1;
|
|
|
|
while ((data = dcb_outp_parse(bios, ++i, &ver, &hdr, &outp))) {
|
|
|
|
if (!outp.location || !outp.extdev)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (outp.type) {
|
|
|
|
case DCB_OUTPUT_TMDS:
|
|
|
|
info.type = NV_I2C_TYPE_EXTDDC(outp.extdev);
|
|
|
|
break;
|
|
|
|
case DCB_OUTPUT_DP:
|
|
|
|
info.type = NV_I2C_TYPE_EXTAUX(outp.extdev);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = -ENODEV;
|
|
|
|
j = -1;
|
2015-01-14 05:04:16 +00:00
|
|
|
while (ret && ++j < ARRAY_SIZE(nvkm_i2c_extdev_sclass)) {
|
2013-02-14 22:48:58 +00:00
|
|
|
parent = nv_object(i2c->find(i2c, outp.i2c_index));
|
2015-01-14 05:04:16 +00:00
|
|
|
oclass = nvkm_i2c_extdev_sclass[j];
|
2013-02-14 22:48:58 +00:00
|
|
|
do {
|
|
|
|
if (oclass->handle != info.type)
|
|
|
|
continue;
|
2015-01-14 05:04:16 +00:00
|
|
|
ret = nvkm_object_ctor(parent, NULL, oclass,
|
|
|
|
NULL, index++, &object);
|
2013-02-14 22:48:58 +00:00
|
|
|
} while (ret && (++oclass)->handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-14 05:04:16 +00:00
|
|
|
ret = nvkm_event_init(&nvkm_i2c_intr_func, 4, index, &i2c->event);
|
2014-05-13 04:47:36 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2009-12-11 09:24:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-05-13 03:59:26 +00:00
|
|
|
|
|
|
|
int
|
2015-01-14 05:04:16 +00:00
|
|
|
_nvkm_i2c_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
|
|
|
|
struct nvkm_oclass *oclass, void *data, u32 size,
|
|
|
|
struct nvkm_object **pobject)
|
2014-05-13 03:59:26 +00:00
|
|
|
{
|
2015-01-14 05:04:16 +00:00
|
|
|
struct nvkm_i2c *i2c;
|
2014-05-13 03:59:26 +00:00
|
|
|
int ret;
|
|
|
|
|
2015-01-14 05:04:16 +00:00
|
|
|
ret = nvkm_i2c_create(parent, engine, oclass, &i2c);
|
2014-05-13 03:59:26 +00:00
|
|
|
*pobject = nv_object(i2c);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|