aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/usbvision
diff options
context:
space:
mode:
authorThierry MERLE <thierry.merle@free.fr>2007-04-16 17:00:49 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-04-27 14:45:41 -0400
commitbf8b20e190f9878978117e39e9a4e493a2e9d6bd (patch)
treeadd3df0357506fcd2d2e290527e3bf689452bc6d /drivers/media/video/usbvision
parentc42cabefce5a333d8158434f902117d8c8dfd3b0 (diff)
V4L/DVB (5528): Usbvision: reverting some i2c cleanups
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> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/usbvision')
-rw-r--r--drivers/media/video/usbvision/usbvision-i2c.c63
1 files changed, 40 insertions, 23 deletions
diff --git a/drivers/media/video/usbvision/usbvision-i2c.c b/drivers/media/video/usbvision/usbvision-i2c.c
index 846e51bfe3fb..9bf263b52c39 100644
--- a/drivers/media/video/usbvision/usbvision-i2c.c
+++ b/drivers/media/video/usbvision/usbvision-i2c.c
@@ -60,7 +60,7 @@ static inline int try_write_address(struct i2c_adapter *i2c_adap,
60 int i, ret = -1; 60 int i, ret = -1;
61 char buf[4]; 61 char buf[4];
62 62
63 usbvision = i2c_get_adapdata(i2c_adap); 63 usbvision = (struct usb_usbvision *)i2c_get_adapdata(i2c_adap);
64 buf[0] = 0x00; 64 buf[0] = 0x00;
65 for (i = 0; i <= retries; i++) { 65 for (i = 0; i <= retries; i++) {
66 ret = (usbvision_i2c_write(usbvision, addr, buf, 1)); 66 ret = (usbvision_i2c_write(usbvision, addr, buf, 1));
@@ -85,7 +85,7 @@ static inline int try_read_address(struct i2c_adapter *i2c_adap,
85 int i, ret = -1; 85 int i, ret = -1;
86 char buf[4]; 86 char buf[4];
87 87
88 usbvision = i2c_get_adapdata(i2c_adap); 88 usbvision = (struct usb_usbvision *)i2c_get_adapdata(i2c_adap);
89 for (i = 0; i <= retries; i++) { 89 for (i = 0; i <= retries; i++) {
90 ret = (usbvision_i2c_read(usbvision, addr, buf, 1)); 90 ret = (usbvision_i2c_read(usbvision, addr, buf, 1));
91 if (ret == 1) 91 if (ret == 1)
@@ -158,7 +158,8 @@ usbvision_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
158 int i, ret; 158 int i, ret;
159 unsigned char addr; 159 unsigned char addr;
160 160
161 usbvision = i2c_get_adapdata(i2c_adap); 161 usbvision = (struct usb_usbvision *)i2c_get_adapdata(i2c_adap);
162
162 for (i = 0; i < num; i++) { 163 for (i = 0; i < num; i++) {
163 pmsg = &msgs[i]; 164 pmsg = &msgs[i];
164 ret = usb_find_address(i2c_adap, pmsg, i2c_adap->retries, &addr); 165 ret = usb_find_address(i2c_adap, pmsg, i2c_adap->retries, &addr);
@@ -205,6 +206,28 @@ static struct i2c_algorithm usbvision_algo = {
205}; 206};
206 207
207 208
209/*
210 * registering functions to load algorithms at runtime
211 */
212static int usbvision_i2c_usb_add_bus(struct i2c_adapter *adap)
213{
214 PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]");
215 PDEBUG(DBG_I2C, "ALGO debugging is enabled [i2c]");
216
217 /* register new adapter to i2c module... */
218
219 adap->algo = &usbvision_algo;
220
221 adap->timeout = 100; /* default values, should */
222 adap->retries = 3; /* be replaced by defines */
223
224 i2c_add_adapter(adap);
225
226 PDEBUG(DBG_I2C,"i2c bus for %s registered", adap->name);
227
228 return 0;
229}
230
208/* ----------------------------------------------------------------------- */ 231/* ----------------------------------------------------------------------- */
209/* usbvision specific I2C functions */ 232/* usbvision specific I2C functions */
210/* ----------------------------------------------------------------------- */ 233/* ----------------------------------------------------------------------- */
@@ -213,28 +236,23 @@ static struct i2c_client i2c_client_template;
213 236
214int usbvision_i2c_register(struct usb_usbvision *usbvision) 237int usbvision_i2c_register(struct usb_usbvision *usbvision)
215{ 238{
216 int ret; 239 memcpy(&usbvision->i2c_adap, &i2c_adap_template,
217 240 sizeof(struct i2c_adapter));
218 usbvision->i2c_adap = i2c_adap_template; 241 memcpy(&usbvision->i2c_client, &i2c_client_template,
219 usbvision->i2c_adap.dev.parent = &usbvision->dev->dev; 242 sizeof(struct i2c_client));
220
221 PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]");
222 243
223 sprintf(usbvision->i2c_adap.name + strlen(usbvision->i2c_adap.name), 244 sprintf(usbvision->i2c_adap.name + strlen(usbvision->i2c_adap.name),
224 " #%d", usbvision->vdev->minor & 0x1f); 245 " #%d", usbvision->vdev->minor & 0x1f);
225 PDEBUG(DBG_I2C,"I2C Registering adaptername: %s", usbvision->i2c_adap.name); 246 PDEBUG(DBG_I2C,"Adaptername: %s", usbvision->i2c_adap.name);
226 i2c_set_adapdata(&usbvision->i2c_adap,usbvision); 247 usbvision->i2c_adap.dev.parent = &usbvision->dev->dev;
227 if ((ret = i2c_add_adapter(&usbvision->i2c_adap)) < 0) { 248
228 PDEBUG(DBG_I2C,"could not add I2C adapter %s", usbvision->i2c_adap.name); 249 i2c_set_adapdata(&usbvision->i2c_adap, usbvision);
229 return ret; 250 i2c_set_clientdata(&usbvision->i2c_client, usbvision);
230 }
231 251
232 /* TODO: use i2c_client for eeprom detection as an example... */
233 usbvision->i2c_client = i2c_client_template;
234 usbvision->i2c_client.adapter = &usbvision->i2c_adap; 252 usbvision->i2c_client.adapter = &usbvision->i2c_adap;
235 253
236 if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) { 254 if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) {
237 printk(KERN_ERR "usbvision_i2c_register: can't write reg\n"); 255 printk(KERN_ERR "usbvision_register: can't write reg\n");
238 return -EBUSY; 256 return -EBUSY;
239 } 257 }
240 258
@@ -253,7 +271,7 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision)
253 } 271 }
254#endif 272#endif
255 273
256 return 0; 274 return usbvision_i2c_usb_add_bus(&usbvision->i2c_adap);
257} 275}
258 276
259int usbvision_i2c_unregister(struct usb_usbvision *usbvision) 277int usbvision_i2c_unregister(struct usb_usbvision *usbvision)
@@ -276,7 +294,8 @@ static int attach_inform(struct i2c_client *client)
276{ 294{
277 struct usb_usbvision *usbvision; 295 struct usb_usbvision *usbvision;
278 296
279 usbvision = i2c_get_adapdata(client->adapter); 297 usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter);
298
280 switch (client->addr << 1) { 299 switch (client->addr << 1) {
281 case 0x42 << 1: 300 case 0x42 << 1:
282 case 0x43 << 1: 301 case 0x43 << 1:
@@ -329,7 +348,7 @@ static int detach_inform(struct i2c_client *client)
329{ 348{
330 struct usb_usbvision *usbvision; 349 struct usb_usbvision *usbvision;
331 350
332 usbvision = i2c_get_adapdata(client->adapter); 351 usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter);
333 352
334 PDEBUG(DBG_I2C,"usbvision[%d] detaches %s", usbvision->nr, client->name); 353 PDEBUG(DBG_I2C,"usbvision[%d] detaches %s", usbvision->nr, client->name);
335 return 0; 354 return 0;
@@ -508,8 +527,6 @@ static struct i2c_adapter i2c_adap_template = {
508 .owner = THIS_MODULE, 527 .owner = THIS_MODULE,
509 .name = "usbvision", 528 .name = "usbvision",
510 .id = I2C_HW_B_BT848, /* FIXME */ 529 .id = I2C_HW_B_BT848, /* FIXME */
511 .algo = &usbvision_algo,
512 .algo_data = NULL,
513 .client_register = attach_inform, 530 .client_register = attach_inform,
514 .client_unregister = detach_inform, 531 .client_unregister = detach_inform,
515#ifdef I2C_ADAP_CLASS_TV_ANALOG 532#ifdef I2C_ADAP_CLASS_TV_ANALOG