Commit 1ff16c2091a557f8080eb62c087465a87e4330e9

Authored by Thierry MERLE
Committed by Mauro Carvalho Chehab
1 parent d3df9c4fa1

V4L/DVB (5522): Usbvision: i2c function cleanups

usbvision-i2c function renamings, code cleanup

Signed-off-by: Thierry MERLE <thierry.merle@free.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>

Showing 4 changed files with 66 additions and 90 deletions Side-by-side Diff

drivers/media/video/usbvision/usbvision-core.c
... ... @@ -2238,7 +2238,7 @@
2238 2238 PDEBUG(DBG_FUNC, "");
2239 2239 down_interruptible(&usbvision->lock);
2240 2240 if(usbvision->user == 0) {
2241   - usbvision_i2c_usb_del_bus(&usbvision->i2c_adap);
  2241 + usbvision_i2c_unregister(usbvision);
2242 2242  
2243 2243 usbvision_power_off(usbvision);
2244 2244 usbvision->initialized = 0;
drivers/media/video/usbvision/usbvision-i2c.c
1 1 /*
2   - * I2C_ALGO_USB.C
  2 + * usbvision_i2c.c
3 3 * i2c algorithm for USB-I2C Bridges
4 4 *
5   - * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de>
  5 + * Copyright (c) 1999-2007 Joerg Heckenbach <joerg@heckenbach-aw.de>
6 6 * Dwaine Garden <dwainegarden@rogers.com>
7 7 *
8 8 * This module is part of usbvision driver project.
... ... @@ -39,7 +39,6 @@
39 39 #include "usbvision.h"
40 40  
41 41 #define DBG_I2C 1<<0
42   -#define DBG_ALGO 1<<1
43 42  
44 43 static int i2c_debug = 0;
45 44  
46 45  
47 46  
48 47  
49 48  
... ... @@ -49,22 +48,22 @@
49 48 #define PDEBUG(level, fmt, args...) \
50 49 if (i2c_debug & (level)) info("[%s:%d] " fmt, __PRETTY_FUNCTION__, __LINE__ , ## args)
51 50  
52   -static int usbvision_i2c_write(void *data, unsigned char addr, char *buf,
  51 +static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf,
53 52 short len);
54   -static int usbvision_i2c_read(void *data, unsigned char addr, char *buf,
  53 +static int usbvision_i2c_read(struct usb_usbvision *usbvision, unsigned char addr, char *buf,
55 54 short len);
56 55  
57 56 static inline int try_write_address(struct i2c_adapter *i2c_adap,
58 57 unsigned char addr, int retries)
59 58 {
60   - void *data;
  59 + struct usb_usbvision *usbvision;
61 60 int i, ret = -1;
62 61 char buf[4];
63 62  
64   - data = i2c_get_adapdata(i2c_adap);
  63 + usbvision = i2c_get_adapdata(i2c_adap);
65 64 buf[0] = 0x00;
66 65 for (i = 0; i <= retries; i++) {
67   - ret = (usbvision_i2c_write(data, addr, buf, 1));
  66 + ret = (usbvision_i2c_write(usbvision, addr, buf, 1));
68 67 if (ret == 1)
69 68 break; /* success! */
70 69 udelay(5);
... ... @@ -73,8 +72,8 @@
73 72 udelay(10);
74 73 }
75 74 if (i) {
76   - PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr);
77   - PDEBUG(DBG_ALGO,"Maybe there's no device at this address");
  75 + PDEBUG(DBG_I2C,"Needed %d retries for address %#2x", i, addr);
  76 + PDEBUG(DBG_I2C,"Maybe there's no device at this address");
78 77 }
79 78 return ret;
80 79 }
81 80  
82 81  
... ... @@ -82,13 +81,13 @@
82 81 static inline int try_read_address(struct i2c_adapter *i2c_adap,
83 82 unsigned char addr, int retries)
84 83 {
85   - void *data;
  84 + struct usb_usbvision *usbvision;
86 85 int i, ret = -1;
87 86 char buf[4];
88 87  
89   - data = i2c_get_adapdata(i2c_adap);
  88 + usbvision = i2c_get_adapdata(i2c_adap);
90 89 for (i = 0; i <= retries; i++) {
91   - ret = (usbvision_i2c_read(data, addr, buf, 1));
  90 + ret = (usbvision_i2c_read(usbvision, addr, buf, 1));
92 91 if (ret == 1)
93 92 break; /* success! */
94 93 udelay(5);
... ... @@ -97,8 +96,8 @@
97 96 udelay(10);
98 97 }
99 98 if (i) {
100   - PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr);
101   - PDEBUG(DBG_ALGO,"Maybe there's no device at this address");
  99 + PDEBUG(DBG_I2C,"Needed %d retries for address %#2x", i, addr);
  100 + PDEBUG(DBG_I2C,"Maybe there's no device at this address");
102 101 }
103 102 return ret;
104 103 }
105 104  
106 105  
107 106  
108 107  
109 108  
... ... @@ -152,32 +151,31 @@
152 151 }
153 152  
154 153 static int
155   -usb_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
  154 +usbvision_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
156 155 {
157 156 struct i2c_msg *pmsg;
158   - void *data;
  157 + struct usb_usbvision *usbvision;
159 158 int i, ret;
160 159 unsigned char addr;
161 160  
162   - data = i2c_get_adapdata(i2c_adap);
163   -
  161 + usbvision = i2c_get_adapdata(i2c_adap);
164 162 for (i = 0; i < num; i++) {
165 163 pmsg = &msgs[i];
166 164 ret = usb_find_address(i2c_adap, pmsg, i2c_adap->retries, &addr);
167 165 if (ret != 0) {
168   - PDEBUG(DBG_ALGO,"got NAK from device, message #%d", i);
  166 + PDEBUG(DBG_I2C,"got NAK from device, message #%d", i);
169 167 return (ret < 0) ? ret : -EREMOTEIO;
170 168 }
171 169  
172 170 if (pmsg->flags & I2C_M_RD) {
173 171 /* read bytes into buffer */
174   - ret = (usbvision_i2c_read(data, addr, pmsg->buf, pmsg->len));
  172 + ret = (usbvision_i2c_read(usbvision, addr, pmsg->buf, pmsg->len));
175 173 if (ret < pmsg->len) {
176 174 return (ret < 0) ? ret : -EREMOTEIO;
177 175 }
178 176 } else {
179 177 /* write bytes from buffer */
180   - ret = (usbvision_i2c_write(data, addr, pmsg->buf, pmsg->len));
  178 + ret = (usbvision_i2c_write(usbvision, addr, pmsg->buf, pmsg->len));
181 179 if (ret < pmsg->len) {
182 180 return (ret < 0) ? ret : -EREMOTEIO;
183 181 }
... ... @@ -191,7 +189,7 @@
191 189 return 0;
192 190 }
193 191  
194   -static u32 usb_func(struct i2c_adapter *adap)
  192 +static u32 functionality(struct i2c_adapter *adap)
195 193 {
196 194 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING;
197 195 }
198 196  
199 197  
200 198  
201 199  
202 200  
203 201  
204 202  
205 203  
... ... @@ -199,73 +197,44 @@
199 197  
200 198 /* -----exported algorithm data: ------------------------------------- */
201 199  
202   -static struct i2c_algorithm i2c_usb_algo = {
203   - .master_xfer = usb_xfer,
  200 +static struct i2c_algorithm usbvision_algo = {
  201 + .master_xfer = usbvision_i2c_xfer,
204 202 .smbus_xfer = NULL,
205 203 .algo_control = algo_control,
206   - .functionality = usb_func,
  204 + .functionality = functionality,
207 205 };
208 206  
209 207  
210   -/*
211   - * registering functions to load algorithms at runtime
212   - */
213   -static int usbvision_i2c_usb_add_bus(struct i2c_adapter *adap)
214   -{
215   - PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]");
216   - PDEBUG(DBG_ALGO, "ALGO debugging is enabled [i2c]");
217   -
218   - /* register new adapter to i2c module... */
219   -
220   - adap->algo = &i2c_usb_algo;
221   -
222   - adap->timeout = 100; /* default values, should */
223   - adap->retries = 3; /* be replaced by defines */
224   -
225   - i2c_add_adapter(adap);
226   -
227   - PDEBUG(DBG_ALGO,"i2c bus for %s registered", adap->name);
228   -
229   - return 0;
230   -}
231   -
232   -
233   -int usbvision_i2c_usb_del_bus(struct i2c_adapter *adap)
234   -{
235   -
236   - i2c_del_adapter(adap);
237   -
238   - PDEBUG(DBG_ALGO,"i2c bus for %s unregistered", adap->name);
239   -
240   - return 0;
241   -}
242   -
243   -
244 208 /* ----------------------------------------------------------------------- */
245 209 /* usbvision specific I2C functions */
246 210 /* ----------------------------------------------------------------------- */
247 211 static struct i2c_adapter i2c_adap_template;
248 212 static struct i2c_client i2c_client_template;
249 213  
250   -int usbvision_init_i2c(struct usb_usbvision *usbvision)
  214 +int usbvision_i2c_register(struct usb_usbvision *usbvision)
251 215 {
252   - memcpy(&usbvision->i2c_adap, &i2c_adap_template,
253   - sizeof(struct i2c_adapter));
254   - memcpy(&usbvision->i2c_client, &i2c_client_template,
255   - sizeof(struct i2c_client));
  216 + int ret;
256 217  
257   - sprintf(usbvision->i2c_adap.name + strlen(usbvision->i2c_adap.name),
258   - " #%d", usbvision->vdev->minor & 0x1f);
259   - PDEBUG(DBG_I2C,"Adaptername: %s", usbvision->i2c_adap.name);
  218 + usbvision->i2c_adap = i2c_adap_template;
260 219 usbvision->i2c_adap.dev.parent = &usbvision->dev->dev;
261 220  
262   - i2c_set_adapdata(&usbvision->i2c_adap, usbvision);
263   - i2c_set_clientdata(&usbvision->i2c_client, usbvision);
  221 + PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]");
264 222  
  223 + sprintf(usbvision->i2c_adap.name + strlen(usbvision->i2c_adap.name),
  224 + " #%d", usbvision->vdev->minor & 0x1f);
  225 + PDEBUG(DBG_I2C,"I2C Registering adaptername: %s", usbvision->i2c_adap.name);
  226 + i2c_set_adapdata(&usbvision->i2c_adap,usbvision);
  227 + if ((ret = i2c_add_adapter(&usbvision->i2c_adap)) < 0) {
  228 + PDEBUG(DBG_I2C,"could not add I2C adapter %s", usbvision->i2c_adap.name);
  229 + return ret;
  230 + }
  231 +
  232 + /* TODO: use i2c_client for eeprom detection as an example... */
  233 + usbvision->i2c_client = i2c_client_template;
265 234 usbvision->i2c_client.adapter = &usbvision->i2c_adap;
266 235  
267 236 if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) {
268   - printk(KERN_ERR "usbvision_init_i2c: can't write reg\n");
  237 + printk(KERN_ERR "usbvision_i2c_register: can't write reg\n");
269 238 return -EBUSY;
270 239 }
271 240  
272 241  
... ... @@ -284,9 +253,19 @@
284 253 }
285 254 #endif
286 255  
287   - return usbvision_i2c_usb_add_bus(&usbvision->i2c_adap);
  256 + return 0;
288 257 }
289 258  
  259 +int usbvision_i2c_unregister(struct usb_usbvision *usbvision)
  260 +{
  261 +
  262 + i2c_del_adapter(&(usbvision->i2c_adap));
  263 +
  264 + PDEBUG(DBG_I2C,"i2c bus for %s unregistered", usbvision->i2c_adap.name);
  265 +
  266 + return 0;
  267 +}
  268 +
290 269 void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,
291 270 void *arg)
292 271 {
... ... @@ -297,8 +276,7 @@
297 276 {
298 277 struct usb_usbvision *usbvision;
299 278  
300   - usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter);
301   -
  279 + usbvision = i2c_get_adapdata(client->adapter);
302 280 switch (client->addr << 1) {
303 281 case 0x43:
304 282 case 0x4b:
... ... @@ -349,7 +327,7 @@
349 327 {
350 328 struct usb_usbvision *usbvision;
351 329  
352   - usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter);
  330 + usbvision = i2c_get_adapdata(client->adapter);
353 331  
354 332 PDEBUG(DBG_I2C,"usbvision[%d] detaches %s", usbvision->nr, client->name);
355 333 return 0;
... ... @@ -480,7 +458,7 @@
480 458 return len;
481 459 }
482 460  
483   -static int usbvision_i2c_write(void *data, unsigned char addr, char *buf,
  461 +static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf,
484 462 short len)
485 463 {
486 464 char *bufPtr = buf;
... ... @@ -488,7 +466,6 @@
488 466 int wrcount = 0;
489 467 int count;
490 468 int maxLen = 4;
491   - struct usb_usbvision *usbvision = (struct usb_usbvision *) data;
492 469  
493 470 while (len > 0) {
494 471 count = (len > maxLen) ? maxLen : len;
495 472  
... ... @@ -503,14 +480,13 @@
503 480 return wrcount;
504 481 }
505 482  
506   -static int usbvision_i2c_read(void *data, unsigned char addr, char *buf,
  483 +static int usbvision_i2c_read(struct usb_usbvision *usbvision, unsigned char addr, char *buf,
507 484 short len)
508 485 {
509 486 char temp[4];
510 487 int retval, i;
511 488 int rdcount = 0;
512 489 int count;
513   - struct usb_usbvision *usbvision = (struct usb_usbvision *) data;
514 490  
515 491 while (len > 0) {
516 492 count = (len > 3) ? 4 : len;
... ... @@ -530,6 +506,8 @@
530 506 .owner = THIS_MODULE,
531 507 .name = "usbvision",
532 508 .id = I2C_HW_B_BT848, /* FIXME */
  509 + .algo = &usbvision_algo,
  510 + .algo_data = NULL,
533 511 .client_register = attach_inform,
534 512 .client_unregister = detach_inform,
535 513 #ifdef I2C_ADAP_CLASS_TV_ANALOG
drivers/media/video/usbvision/usbvision-video.c
... ... @@ -410,7 +410,7 @@
410 410 down(&usbvision->lock);
411 411 if (usbvision->power == 0) {
412 412 usbvision_power_on(usbvision);
413   - usbvision_init_i2c(usbvision);
  413 + usbvision_i2c_register(usbvision);
414 414 }
415 415  
416 416 /* Send init sequence only once, it's large! */
... ... @@ -432,7 +432,7 @@
432 432 }
433 433 else {
434 434 if (PowerOnAtOpen) {
435   - usbvision_i2c_usb_del_bus(&usbvision->i2c_adap);
  435 + usbvision_i2c_unregister(usbvision);
436 436 usbvision_power_off(usbvision);
437 437 usbvision->initialized = 0;
438 438 }
... ... @@ -1240,7 +1240,7 @@
1240 1240 usbvision_reset_powerOffTimer(usbvision);
1241 1241 if (usbvision->power == 0) {
1242 1242 usbvision_power_on(usbvision);
1243   - usbvision_init_i2c(usbvision);
  1243 + usbvision_i2c_register(usbvision);
1244 1244 }
1245 1245 }
1246 1246  
... ... @@ -1262,7 +1262,7 @@
1262 1262  
1263 1263 if (errCode) {
1264 1264 if (PowerOnAtOpen) {
1265   - usbvision_i2c_usb_del_bus(&usbvision->i2c_adap);
  1265 + usbvision_i2c_unregister(usbvision);
1266 1266 usbvision_power_off(usbvision);
1267 1267 usbvision->initialized = 0;
1268 1268 }
... ... @@ -1765,7 +1765,7 @@
1765 1765 usbvision_audio_off(usbvision); //first switch off audio
1766 1766 if (!PowerOnAtOpen) {
1767 1767 usbvision_power_on(usbvision); //and then power up the noisy tuner
1768   - usbvision_init_i2c(usbvision);
  1768 + usbvision_i2c_register(usbvision);
1769 1769 }
1770 1770 }
1771 1771  
... ... @@ -1913,7 +1913,7 @@
1913 1913 usbvision_stop_isoc(usbvision);
1914 1914  
1915 1915 if (usbvision->power) {
1916   - usbvision_i2c_usb_del_bus(&usbvision->i2c_adap);
  1916 + usbvision_i2c_unregister(usbvision);
1917 1917 usbvision_power_off(usbvision);
1918 1918 }
1919 1919 usbvision->remove_pending = 1; // Now all ISO data will be ignored
drivers/media/video/usbvision/usbvision.h
... ... @@ -482,13 +482,11 @@
482 482 /* i2c-algo-usb declaration */
483 483 /* --------------------------------------------------------------- */
484 484  
485   -int usbvision_i2c_usb_del_bus(struct i2c_adapter *);
486   -
487   -
488 485 /* ----------------------------------------------------------------------- */
489 486 /* usbvision specific I2C functions */
490 487 /* ----------------------------------------------------------------------- */
491   -int usbvision_init_i2c(struct usb_usbvision *usbvision);
  488 +int usbvision_i2c_register(struct usb_usbvision *usbvision);
  489 +int usbvision_i2c_unregister(struct usb_usbvision *usbvision);
492 490 void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,void *arg);
493 491  
494 492 /* defined in usbvision-core.c */