Skip to content

Commit

Permalink
Merge branch 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare…
Browse files Browse the repository at this point in the history
…-2.6

* 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6:
  go7007: Convert to the new i2c device binding model
  • Loading branch information
Linus Torvalds committed Apr 21, 2009
2 parents daba028 + 7400516 commit c19c6c3
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 418 deletions.
11 changes: 9 additions & 2 deletions drivers/staging/go7007/go7007-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ int go7007_reset_encoder(struct go7007 *go)
/*
* Attempt to instantiate an I2C client by ID, probably loading a module.
*/
static int init_i2c_module(struct i2c_adapter *adapter, int id, int addr)
static int init_i2c_module(struct i2c_adapter *adapter, const char *type,
int id, int addr)
{
struct i2c_board_info info;
char *modname;

switch (id) {
Expand Down Expand Up @@ -226,7 +228,11 @@ static int init_i2c_module(struct i2c_adapter *adapter, int id, int addr)
}
if (modname != NULL)
request_module(modname);
if (wis_i2c_probe_device(adapter, id, addr) == 1)

memset(&info, 0, sizeof(struct i2c_board_info));
info.addr = addr;
strlcpy(info.type, type, I2C_NAME_SIZE);
if (!i2c_new_device(adapter, &info))
return 0;
if (modname != NULL)
printk(KERN_INFO
Expand Down Expand Up @@ -266,6 +272,7 @@ int go7007_register_encoder(struct go7007 *go)
if (go->i2c_adapter_online) {
for (i = 0; i < go->board_info->num_i2c_devs; ++i)
init_i2c_module(&go->i2c_adapter,
go->board_info->i2c_devs[i].type,
go->board_info->i2c_devs[i].id,
go->board_info->i2c_devs[i].addr);
if (go->board_id == GO7007_BOARDID_ADLINK_MPG24)
Expand Down
83 changes: 0 additions & 83 deletions drivers/staging/go7007/go7007-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,87 +31,6 @@
#include "go7007-priv.h"
#include "wis-i2c.h"

/************** Registration interface for I2C client drivers **************/

/* Since there's no way to auto-probe the I2C devices connected to the I2C
* bus on the go7007, we have this silly little registration system that
* client drivers can use to register their I2C driver ID and their
* detect_client function (the one that's normally passed to i2c_probe).
*
* When a new go7007 device is connected, we can look up in a board info
* table by the USB or PCI vendor/product/revision ID to determine
* which I2C client module to load. The client driver module will register
* itself here, and then we can call the registered detect_client function
* to force-load a new client at the address listed in the board info table.
*
* Really the I2C subsystem should have a way to force-load I2C client
* drivers when we have a priori knowledge of what's on the bus, especially
* since the existing I2C auto-probe mechanism is so hokey, but we'll use
* our own mechanism for the time being. */

struct wis_i2c_client_driver {
unsigned int id;
found_proc found_proc;
struct list_head list;
};

static LIST_HEAD(i2c_client_drivers);
static DECLARE_MUTEX(i2c_client_driver_list_lock);

/* Client drivers register here by their I2C driver ID */
int wis_i2c_add_driver(unsigned int id, found_proc found_proc)
{
struct wis_i2c_client_driver *driver;

driver = kmalloc(sizeof(struct wis_i2c_client_driver), GFP_KERNEL);
if (driver == NULL)
return -ENOMEM;
driver->id = id;
driver->found_proc = found_proc;

down(&i2c_client_driver_list_lock);
list_add_tail(&driver->list, &i2c_client_drivers);
up(&i2c_client_driver_list_lock);

return 0;
}
EXPORT_SYMBOL(wis_i2c_add_driver);

void wis_i2c_del_driver(found_proc found_proc)
{
struct wis_i2c_client_driver *driver, *next;

down(&i2c_client_driver_list_lock);
list_for_each_entry_safe(driver, next, &i2c_client_drivers, list)
if (driver->found_proc == found_proc) {
list_del(&driver->list);
kfree(driver);
}
up(&i2c_client_driver_list_lock);
}
EXPORT_SYMBOL(wis_i2c_del_driver);

/* The main go7007 driver calls this to instantiate a client by driver
* ID and bus address, which are both stored in the board info table */
int wis_i2c_probe_device(struct i2c_adapter *adapter,
unsigned int id, int addr)
{
struct wis_i2c_client_driver *driver;
int found = 0;

if (addr < 0 || addr > 0x7f)
return -1;
down(&i2c_client_driver_list_lock);
list_for_each_entry(driver, &i2c_client_drivers, list)
if (driver->id == id) {
if (driver->found_proc(adapter, addr, 0) == 0)
found = 1;
break;
}
up(&i2c_client_driver_list_lock);
return found;
}

/********************* Driver for on-board I2C adapter *********************/

/* #define GO7007_I2C_DEBUG */
Expand Down Expand Up @@ -287,9 +206,7 @@ static struct i2c_algorithm go7007_algo = {

static struct i2c_adapter go7007_adap_templ = {
.owner = THIS_MODULE,
.class = I2C_CLASS_TV_ANALOG,
.name = "WIS GO7007SB",
.id = I2C_ALGO_GO7007,
.algo = &go7007_algo,
};

Expand Down
1 change: 1 addition & 0 deletions drivers/staging/go7007/go7007-priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ struct go7007_board_info {
int audio_main_div;
int num_i2c_devs;
struct {
const char *type;
int id;
int addr;
} i2c_devs[4];
Expand Down
14 changes: 11 additions & 3 deletions drivers/staging/go7007/go7007-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static struct go7007_usb_board board_matrix_ii = {
.num_i2c_devs = 1,
.i2c_devs = {
{
.type = "wis_saa7115",
.id = I2C_DRIVERID_WIS_SAA7115,
.addr = 0x20,
},
Expand Down Expand Up @@ -127,6 +128,7 @@ static struct go7007_usb_board board_matrix_reload = {
.num_i2c_devs = 1,
.i2c_devs = {
{
.type = "wis_saa7113",
.id = I2C_DRIVERID_WIS_SAA7113,
.addr = 0x25,
},
Expand Down Expand Up @@ -164,6 +166,7 @@ static struct go7007_usb_board board_star_trek = {
.num_i2c_devs = 1,
.i2c_devs = {
{
.type = "wis_saa7115",
.id = I2C_DRIVERID_WIS_SAA7115,
.addr = 0x20,
},
Expand Down Expand Up @@ -209,14 +212,17 @@ static struct go7007_usb_board board_px_tv402u = {
.num_i2c_devs = 3,
.i2c_devs = {
{
.type = "wis_saa7115",
.id = I2C_DRIVERID_WIS_SAA7115,
.addr = 0x20,
},
{
.type = "wis_uda1342",
.id = I2C_DRIVERID_WIS_UDA1342,
.addr = 0x1a,
},
{
.type = "wis_sony_tuner",
.id = I2C_DRIVERID_WIS_SONY_TUNER,
.addr = 0x60,
},
Expand Down Expand Up @@ -264,6 +270,7 @@ static struct go7007_usb_board board_xmen = {
.num_i2c_devs = 1,
.i2c_devs = {
{
.type = "wis_ov7640",
.id = I2C_DRIVERID_WIS_OV7640,
.addr = 0x21,
},
Expand Down Expand Up @@ -296,6 +303,7 @@ static struct go7007_usb_board board_matrix_revolution = {
.num_i2c_devs = 1,
.i2c_devs = {
{
.type = "wis_tw9903",
.id = I2C_DRIVERID_WIS_TW9903,
.addr = 0x44,
},
Expand Down Expand Up @@ -385,6 +393,7 @@ static struct go7007_usb_board board_adlink_mpg24 = {
.num_i2c_devs = 1,
.i2c_devs = {
{
.type = "wis_twTW2804",
.id = I2C_DRIVERID_WIS_TW2804,
.addr = 0x00, /* yes, really */
},
Expand Down Expand Up @@ -415,8 +424,9 @@ static struct go7007_usb_board board_sensoray_2250 = {
.num_i2c_devs = 1,
.i2c_devs = {
{
.type = "s2250_board",
.id = I2C_DRIVERID_S2250,
.addr = 0x34,
.addr = 0x43,
},
},
.num_inputs = 2,
Expand Down Expand Up @@ -943,9 +953,7 @@ static struct i2c_algorithm go7007_usb_algo = {

static struct i2c_adapter go7007_usb_adap_templ = {
.owner = THIS_MODULE,
.class = I2C_CLASS_TV_ANALOG,
.name = "WIS GO7007SB EZ-USB",
.id = I2C_ALGO_GO7007_USB,
.algo = &go7007_usb_algo,
};

Expand Down
Loading

0 comments on commit c19c6c3

Please sign in to comment.