diff options
author | Thierry MERLE <thierry.merle@free.fr> | 2007-04-16 23:00:49 +0200 |
---|---|---|
committer | Thierry MERLE <thierry.merle@free.fr> | 2007-04-16 23:00:49 +0200 |
commit | 39ae33f89fddaa51e443c53d66e254a393720017 (patch) | |
tree | e722f878c4d9ca4bb49bb0befa648bc0e217d8c9 /linux/drivers/media/video/usbvision/usbvision-i2c.c | |
parent | d9a89333867ce2c514a813a09dee52ba208a5845 (diff) | |
download | mediapointer-dvb-s2-39ae33f89fddaa51e443c53d66e254a393720017.tar.gz mediapointer-dvb-s2-39ae33f89fddaa51e443c53d66e254a393720017.tar.bz2 |
usbvision: reverting some i2c cleanups
From: Thierry MERLE <thierry.merle@free.fr>
usbvision-i2c.c: reverting some i2c cleanups in order to recover a safe state.
Acked-by: Dwaine Garden <DwaineGarden@rogers.com>
Signed-off-by: Thierry MERLE <thierry.merle@free.fr>
Diffstat (limited to 'linux/drivers/media/video/usbvision/usbvision-i2c.c')
-rw-r--r-- | linux/drivers/media/video/usbvision/usbvision-i2c.c | 66 |
1 files changed, 43 insertions, 23 deletions
diff --git a/linux/drivers/media/video/usbvision/usbvision-i2c.c b/linux/drivers/media/video/usbvision/usbvision-i2c.c index a0eed8633..c00dac30d 100644 --- a/linux/drivers/media/video/usbvision/usbvision-i2c.c +++ b/linux/drivers/media/video/usbvision/usbvision-i2c.c @@ -63,7 +63,7 @@ static inline int try_write_address(struct i2c_adapter *i2c_adap, int i, ret = -1; char buf[4]; - usbvision = i2c_get_adapdata(i2c_adap); + usbvision = (struct usb_usbvision *)i2c_get_adapdata(i2c_adap); buf[0] = 0x00; for (i = 0; i <= retries; i++) { ret = (usbvision_i2c_write(usbvision, addr, buf, 1)); @@ -88,7 +88,7 @@ static inline int try_read_address(struct i2c_adapter *i2c_adap, int i, ret = -1; char buf[4]; - usbvision = i2c_get_adapdata(i2c_adap); + usbvision = (struct usb_usbvision *)i2c_get_adapdata(i2c_adap); for (i = 0; i <= retries; i++) { ret = (usbvision_i2c_read(usbvision, addr, buf, 1)); if (ret == 1) @@ -161,7 +161,8 @@ usbvision_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num) int i, ret; unsigned char addr; - usbvision = i2c_get_adapdata(i2c_adap); + usbvision = (struct usb_usbvision *)i2c_get_adapdata(i2c_adap); + for (i = 0; i < num; i++) { pmsg = &msgs[i]; ret = usb_find_address(i2c_adap, pmsg, i2c_adap->retries, &addr); @@ -226,6 +227,31 @@ static struct i2c_algorithm usbvision_algo = { }; +/* + * registering functions to load algorithms at runtime + */ +static int usbvision_i2c_usb_add_bus(struct i2c_adapter *adap) +{ + PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]"); + PDEBUG(DBG_I2C, "ALGO debugging is enabled [i2c]"); + + /* register new adapter to i2c module... */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) + adap->id |= usbvision_algo.id; +#endif + adap->algo = &usbvision_algo; + + adap->timeout = 100; /* default values, should */ + adap->retries = 3; /* be replaced by defines */ + + i2c_add_adapter(adap); + + PDEBUG(DBG_I2C,"i2c bus for %s registered", adap->name); + + return 0; +} + /* ----------------------------------------------------------------------- */ /* usbvision specific I2C functions */ /* ----------------------------------------------------------------------- */ @@ -234,28 +260,23 @@ static struct i2c_client i2c_client_template; int usbvision_i2c_register(struct usb_usbvision *usbvision) { - int ret; - - usbvision->i2c_adap = i2c_adap_template; - usbvision->i2c_adap.dev.parent = &usbvision->dev->dev; - - PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]"); + memcpy(&usbvision->i2c_adap, &i2c_adap_template, + sizeof(struct i2c_adapter)); + memcpy(&usbvision->i2c_client, &i2c_client_template, + sizeof(struct i2c_client)); sprintf(usbvision->i2c_adap.name + strlen(usbvision->i2c_adap.name), " #%d", usbvision->vdev->minor & 0x1f); - PDEBUG(DBG_I2C,"I2C Registering adaptername: %s", usbvision->i2c_adap.name); - i2c_set_adapdata(&usbvision->i2c_adap,usbvision); - if ((ret = i2c_add_adapter(&usbvision->i2c_adap)) < 0) { - PDEBUG(DBG_I2C,"could not add I2C adapter %s", usbvision->i2c_adap.name); - return ret; - } + PDEBUG(DBG_I2C,"Adaptername: %s", usbvision->i2c_adap.name); + usbvision->i2c_adap.dev.parent = &usbvision->dev->dev; + + i2c_set_adapdata(&usbvision->i2c_adap, usbvision); + i2c_set_clientdata(&usbvision->i2c_client, usbvision); - /* TODO: use i2c_client for eeprom detection as an example... */ - usbvision->i2c_client = i2c_client_template; usbvision->i2c_client.adapter = &usbvision->i2c_adap; if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) { - printk(KERN_ERR "usbvision_i2c_register: can't write reg\n"); + printk(KERN_ERR "usbvision_register: can't write reg\n"); return -EBUSY; } @@ -274,7 +295,7 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision) } #endif - return 0; + return usbvision_i2c_usb_add_bus(&usbvision->i2c_adap); } int usbvision_i2c_unregister(struct usb_usbvision *usbvision) @@ -297,7 +318,8 @@ static int attach_inform(struct i2c_client *client) { struct usb_usbvision *usbvision; - usbvision = i2c_get_adapdata(client->adapter); + usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter); + switch (client->addr << 1) { case 0x42 << 1: case 0x43 << 1: @@ -350,7 +372,7 @@ static int detach_inform(struct i2c_client *client) { struct usb_usbvision *usbvision; - usbvision = i2c_get_adapdata(client->adapter); + usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter); PDEBUG(DBG_I2C,"usbvision[%d] detaches %s", usbvision->nr, client->name); return 0; @@ -534,8 +556,6 @@ static struct i2c_adapter i2c_adap_template = { #endif .name = "usbvision", .id = I2C_HW_B_BT848, /* FIXME */ - .algo = &usbvision_algo, - .algo_data = NULL, .client_register = attach_inform, .client_unregister = detach_inform, #ifdef I2C_ADAP_CLASS_TV_ANALOG |