aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2009-04-21 15:47:22 -0400
committerJean Delvare <khali@linux-fr.org>2009-04-21 15:47:22 -0400
commit7400516ab40d8fe55031dc8d614e2b365bd95f1c (patch)
tree33fc8410c9727ca32747ed84832bafb785285f79 /drivers
parenta939b96cccdb65df80a52447ec8e4a6d79c56dbb (diff)
go7007: Convert to the new i2c device binding model
Move the go7007 driver away from the legacy i2c binding model, which is going away really soon now. The I2C addresses of the audio and video chips in s2250-board didn't look quite right, apparently they were left-aligned values when Linux wants right-aligned values, so I fixed them too. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/go7007/go7007-driver.c11
-rw-r--r--drivers/staging/go7007/go7007-i2c.c83
-rw-r--r--drivers/staging/go7007/go7007-priv.h1
-rw-r--r--drivers/staging/go7007/go7007-usb.c14
-rw-r--r--drivers/staging/go7007/s2250-board.c71
-rw-r--r--drivers/staging/go7007/wis-i2c.h9
-rw-r--r--drivers/staging/go7007/wis-ov7640.c56
-rw-r--r--drivers/staging/go7007/wis-saa7113.c60
-rw-r--r--drivers/staging/go7007/wis-saa7115.c60
-rw-r--r--drivers/staging/go7007/wis-sony-tuner.c60
-rw-r--r--drivers/staging/go7007/wis-tw2804.c57
-rw-r--r--drivers/staging/go7007/wis-tw9903.c60
-rw-r--r--drivers/staging/go7007/wis-uda1342.c52
13 files changed, 176 insertions, 418 deletions
diff --git a/drivers/staging/go7007/go7007-driver.c b/drivers/staging/go7007/go7007-driver.c
index f47c0ce2849a..77b1e769ac92 100644
--- a/drivers/staging/go7007/go7007-driver.c
+++ b/drivers/staging/go7007/go7007-driver.c
@@ -191,8 +191,10 @@ int go7007_reset_encoder(struct go7007 *go)
191/* 191/*
192 * Attempt to instantiate an I2C client by ID, probably loading a module. 192 * Attempt to instantiate an I2C client by ID, probably loading a module.
193 */ 193 */
194static int init_i2c_module(struct i2c_adapter *adapter, int id, int addr) 194static int init_i2c_module(struct i2c_adapter *adapter, const char *type,
195 int id, int addr)
195{ 196{
197 struct i2c_board_info info;
196 char *modname; 198 char *modname;
197 199
198 switch (id) { 200 switch (id) {
@@ -226,7 +228,11 @@ static int init_i2c_module(struct i2c_adapter *adapter, int id, int addr)
226 } 228 }
227 if (modname != NULL) 229 if (modname != NULL)
228 request_module(modname); 230 request_module(modname);
229 if (wis_i2c_probe_device(adapter, id, addr) == 1) 231
232 memset(&info, 0, sizeof(struct i2c_board_info));
233 info.addr = addr;
234 strlcpy(info.type, type, I2C_NAME_SIZE);
235 if (!i2c_new_device(adapter, &info))
230 return 0; 236 return 0;
231 if (modname != NULL) 237 if (modname != NULL)
232 printk(KERN_INFO 238 printk(KERN_INFO
@@ -266,6 +272,7 @@ int go7007_register_encoder(struct go7007 *go)
266 if (go->i2c_adapter_online) { 272 if (go->i2c_adapter_online) {
267 for (i = 0; i < go->board_info->num_i2c_devs; ++i) 273 for (i = 0; i < go->board_info->num_i2c_devs; ++i)
268 init_i2c_module(&go->i2c_adapter, 274 init_i2c_module(&go->i2c_adapter,
275 go->board_info->i2c_devs[i].type,
269 go->board_info->i2c_devs[i].id, 276 go->board_info->i2c_devs[i].id,
270 go->board_info->i2c_devs[i].addr); 277 go->board_info->i2c_devs[i].addr);
271 if (go->board_id == GO7007_BOARDID_ADLINK_MPG24) 278 if (go->board_id == GO7007_BOARDID_ADLINK_MPG24)
diff --git a/drivers/staging/go7007/go7007-i2c.c b/drivers/staging/go7007/go7007-i2c.c
index cd55b76eabc7..c82867fdd28d 100644
--- a/drivers/staging/go7007/go7007-i2c.c
+++ b/drivers/staging/go7007/go7007-i2c.c
@@ -31,87 +31,6 @@
31#include "go7007-priv.h" 31#include "go7007-priv.h"
32#include "wis-i2c.h" 32#include "wis-i2c.h"
33 33
34/************** Registration interface for I2C client drivers **************/
35
36/* Since there's no way to auto-probe the I2C devices connected to the I2C
37 * bus on the go7007, we have this silly little registration system that
38 * client drivers can use to register their I2C driver ID and their
39 * detect_client function (the one that's normally passed to i2c_probe).
40 *
41 * When a new go7007 device is connected, we can look up in a board info
42 * table by the USB or PCI vendor/product/revision ID to determine
43 * which I2C client module to load. The client driver module will register
44 * itself here, and then we can call the registered detect_client function
45 * to force-load a new client at the address listed in the board info table.
46 *
47 * Really the I2C subsystem should have a way to force-load I2C client
48 * drivers when we have a priori knowledge of what's on the bus, especially
49 * since the existing I2C auto-probe mechanism is so hokey, but we'll use
50 * our own mechanism for the time being. */
51
52struct wis_i2c_client_driver {
53 unsigned int id;
54 found_proc found_proc;
55 struct list_head list;
56};
57
58static LIST_HEAD(i2c_client_drivers);
59static DECLARE_MUTEX(i2c_client_driver_list_lock);
60
61/* Client drivers register here by their I2C driver ID */
62int wis_i2c_add_driver(unsigned int id, found_proc found_proc)
63{
64 struct wis_i2c_client_driver *driver;
65
66 driver = kmalloc(sizeof(struct wis_i2c_client_driver), GFP_KERNEL);
67 if (driver == NULL)
68 return -ENOMEM;
69 driver->id = id;
70 driver->found_proc = found_proc;
71
72 down(&i2c_client_driver_list_lock);
73 list_add_tail(&driver->list, &i2c_client_drivers);
74 up(&i2c_client_driver_list_lock);
75
76 return 0;
77}
78EXPORT_SYMBOL(wis_i2c_add_driver);
79
80void wis_i2c_del_driver(found_proc found_proc)
81{
82 struct wis_i2c_client_driver *driver, *next;
83
84 down(&i2c_client_driver_list_lock);
85 list_for_each_entry_safe(driver, next, &i2c_client_drivers, list)
86 if (driver->found_proc == found_proc) {
87 list_del(&driver->list);
88 kfree(driver);
89 }
90 up(&i2c_client_driver_list_lock);
91}
92EXPORT_SYMBOL(wis_i2c_del_driver);
93
94/* The main go7007 driver calls this to instantiate a client by driver
95 * ID and bus address, which are both stored in the board info table */
96int wis_i2c_probe_device(struct i2c_adapter *adapter,
97 unsigned int id, int addr)
98{
99 struct wis_i2c_client_driver *driver;
100 int found = 0;
101
102 if (addr < 0 || addr > 0x7f)
103 return -1;
104 down(&i2c_client_driver_list_lock);
105 list_for_each_entry(driver, &i2c_client_drivers, list)
106 if (driver->id == id) {
107 if (driver->found_proc(adapter, addr, 0) == 0)
108 found = 1;
109 break;
110 }
111 up(&i2c_client_driver_list_lock);
112 return found;
113}
114
115/********************* Driver for on-board I2C adapter *********************/ 34/********************* Driver for on-board I2C adapter *********************/
116 35
117/* #define GO7007_I2C_DEBUG */ 36/* #define GO7007_I2C_DEBUG */
@@ -287,9 +206,7 @@ static struct i2c_algorithm go7007_algo = {
287 206
288static struct i2c_adapter go7007_adap_templ = { 207static struct i2c_adapter go7007_adap_templ = {
289 .owner = THIS_MODULE, 208 .owner = THIS_MODULE,
290 .class = I2C_CLASS_TV_ANALOG,
291 .name = "WIS GO7007SB", 209 .name = "WIS GO7007SB",
292 .id = I2C_ALGO_GO7007,
293 .algo = &go7007_algo, 210 .algo = &go7007_algo,
294}; 211};
295 212
diff --git a/drivers/staging/go7007/go7007-priv.h b/drivers/staging/go7007/go7007-priv.h
index 372f1f1c09b2..178d18119faa 100644
--- a/drivers/staging/go7007/go7007-priv.h
+++ b/drivers/staging/go7007/go7007-priv.h
@@ -87,6 +87,7 @@ struct go7007_board_info {
87 int audio_main_div; 87 int audio_main_div;
88 int num_i2c_devs; 88 int num_i2c_devs;
89 struct { 89 struct {
90 const char *type;
90 int id; 91 int id;
91 int addr; 92 int addr;
92 } i2c_devs[4]; 93 } i2c_devs[4];
diff --git a/drivers/staging/go7007/go7007-usb.c b/drivers/staging/go7007/go7007-usb.c
index 83eec920c7d3..aa4a9e0b9954 100644
--- a/drivers/staging/go7007/go7007-usb.c
+++ b/drivers/staging/go7007/go7007-usb.c
@@ -91,6 +91,7 @@ static struct go7007_usb_board board_matrix_ii = {
91 .num_i2c_devs = 1, 91 .num_i2c_devs = 1,
92 .i2c_devs = { 92 .i2c_devs = {
93 { 93 {
94 .type = "wis_saa7115",
94 .id = I2C_DRIVERID_WIS_SAA7115, 95 .id = I2C_DRIVERID_WIS_SAA7115,
95 .addr = 0x20, 96 .addr = 0x20,
96 }, 97 },
@@ -127,6 +128,7 @@ static struct go7007_usb_board board_matrix_reload = {
127 .num_i2c_devs = 1, 128 .num_i2c_devs = 1,
128 .i2c_devs = { 129 .i2c_devs = {
129 { 130 {
131 .type = "wis_saa7113",
130 .id = I2C_DRIVERID_WIS_SAA7113, 132 .id = I2C_DRIVERID_WIS_SAA7113,
131 .addr = 0x25, 133 .addr = 0x25,
132 }, 134 },
@@ -164,6 +166,7 @@ static struct go7007_usb_board board_star_trek = {
164 .num_i2c_devs = 1, 166 .num_i2c_devs = 1,
165 .i2c_devs = { 167 .i2c_devs = {
166 { 168 {
169 .type = "wis_saa7115",
167 .id = I2C_DRIVERID_WIS_SAA7115, 170 .id = I2C_DRIVERID_WIS_SAA7115,
168 .addr = 0x20, 171 .addr = 0x20,
169 }, 172 },
@@ -209,14 +212,17 @@ static struct go7007_usb_board board_px_tv402u = {
209 .num_i2c_devs = 3, 212 .num_i2c_devs = 3,
210 .i2c_devs = { 213 .i2c_devs = {
211 { 214 {
215 .type = "wis_saa7115",
212 .id = I2C_DRIVERID_WIS_SAA7115, 216 .id = I2C_DRIVERID_WIS_SAA7115,
213 .addr = 0x20, 217 .addr = 0x20,
214 }, 218 },
215 { 219 {
220 .type = "wis_uda1342",
216 .id = I2C_DRIVERID_WIS_UDA1342, 221 .id = I2C_DRIVERID_WIS_UDA1342,
217 .addr = 0x1a, 222 .addr = 0x1a,
218 }, 223 },
219 { 224 {
225 .type = "wis_sony_tuner",
220 .id = I2C_DRIVERID_WIS_SONY_TUNER, 226 .id = I2C_DRIVERID_WIS_SONY_TUNER,
221 .addr = 0x60, 227 .addr = 0x60,
222 }, 228 },
@@ -264,6 +270,7 @@ static struct go7007_usb_board board_xmen = {
264 .num_i2c_devs = 1, 270 .num_i2c_devs = 1,
265 .i2c_devs = { 271 .i2c_devs = {
266 { 272 {
273 .type = "wis_ov7640",
267 .id = I2C_DRIVERID_WIS_OV7640, 274 .id = I2C_DRIVERID_WIS_OV7640,
268 .addr = 0x21, 275 .addr = 0x21,
269 }, 276 },
@@ -296,6 +303,7 @@ static struct go7007_usb_board board_matrix_revolution = {
296 .num_i2c_devs = 1, 303 .num_i2c_devs = 1,
297 .i2c_devs = { 304 .i2c_devs = {
298 { 305 {
306 .type = "wis_tw9903",
299 .id = I2C_DRIVERID_WIS_TW9903, 307 .id = I2C_DRIVERID_WIS_TW9903,
300 .addr = 0x44, 308 .addr = 0x44,
301 }, 309 },
@@ -385,6 +393,7 @@ static struct go7007_usb_board board_adlink_mpg24 = {
385 .num_i2c_devs = 1, 393 .num_i2c_devs = 1,
386 .i2c_devs = { 394 .i2c_devs = {
387 { 395 {
396 .type = "wis_twTW2804",
388 .id = I2C_DRIVERID_WIS_TW2804, 397 .id = I2C_DRIVERID_WIS_TW2804,
389 .addr = 0x00, /* yes, really */ 398 .addr = 0x00, /* yes, really */
390 }, 399 },
@@ -415,8 +424,9 @@ static struct go7007_usb_board board_sensoray_2250 = {
415 .num_i2c_devs = 1, 424 .num_i2c_devs = 1,
416 .i2c_devs = { 425 .i2c_devs = {
417 { 426 {
427 .type = "s2250_board",
418 .id = I2C_DRIVERID_S2250, 428 .id = I2C_DRIVERID_S2250,
419 .addr = 0x34, 429 .addr = 0x43,
420 }, 430 },
421 }, 431 },
422 .num_inputs = 2, 432 .num_inputs = 2,
@@ -943,9 +953,7 @@ static struct i2c_algorithm go7007_usb_algo = {
943 953
944static struct i2c_adapter go7007_usb_adap_templ = { 954static struct i2c_adapter go7007_usb_adap_templ = {
945 .owner = THIS_MODULE, 955 .owner = THIS_MODULE,
946 .class = I2C_CLASS_TV_ANALOG,
947 .name = "WIS GO7007SB EZ-USB", 956 .name = "WIS GO7007SB EZ-USB",
948 .id = I2C_ALGO_GO7007_USB,
949 .algo = &go7007_usb_algo, 957 .algo = &go7007_usb_algo,
950}; 958};
951 959
diff --git a/drivers/staging/go7007/s2250-board.c b/drivers/staging/go7007/s2250-board.c
index d333ea2cd774..1706fbf06847 100644
--- a/drivers/staging/go7007/s2250-board.c
+++ b/drivers/staging/go7007/s2250-board.c
@@ -28,7 +28,6 @@ extern int s2250loader_init(void);
28extern void s2250loader_cleanup(void); 28extern void s2250loader_cleanup(void);
29 29
30#define TLV320_ADDRESS 0x34 30#define TLV320_ADDRESS 0x34
31#define S2250_VIDDEC 0x86
32#define VPX322_ADDR_ANALOGCONTROL1 0x02 31#define VPX322_ADDR_ANALOGCONTROL1 0x02
33#define VPX322_ADDR_BRIGHTNESS0 0x0127 32#define VPX322_ADDR_BRIGHTNESS0 0x0127
34#define VPX322_ADDR_BRIGHTNESS1 0x0131 33#define VPX322_ADDR_BRIGHTNESS1 0x0131
@@ -123,6 +122,7 @@ struct s2250 {
123 int hue; 122 int hue;
124 int reg12b_val; 123 int reg12b_val;
125 int audio_input; 124 int audio_input;
125 struct i2c_client *audio;
126}; 126};
127 127
128/* from go7007-usb.c which is Copyright (C) 2005-2006 Micronas USA Inc.*/ 128/* from go7007-usb.c which is Copyright (C) 2005-2006 Micronas USA Inc.*/
@@ -452,16 +452,15 @@ static int s2250_command(struct i2c_client *client,
452 { 452 {
453 struct v4l2_audio *audio = arg; 453 struct v4l2_audio *audio = arg;
454 454
455 client->addr = TLV320_ADDRESS;
456 switch (audio->index) { 455 switch (audio->index) {
457 case 0: 456 case 0:
458 write_reg(client, 0x08, 0x02); /* Line In */ 457 write_reg(dec->audio, 0x08, 0x02); /* Line In */
459 break; 458 break;
460 case 1: 459 case 1:
461 write_reg(client, 0x08, 0x04); /* Mic */ 460 write_reg(dec->audio, 0x08, 0x04); /* Mic */
462 break; 461 break;
463 case 2: 462 case 2:
464 write_reg(client, 0x08, 0x05); /* Mic Boost */ 463 write_reg(dec->audio, 0x08, 0x05); /* Mic Boost */
465 break; 464 break;
466 default: 465 default:
467 return -EINVAL; 466 return -EINVAL;
@@ -477,31 +476,23 @@ static int s2250_command(struct i2c_client *client,
477 return 0; 476 return 0;
478} 477}
479 478
480static struct i2c_driver s2250_driver; 479static int s2250_probe(struct i2c_client *client,
481 480 const struct i2c_device_id *id)
482static struct i2c_client s2250_client_templ = {
483 .name = "Sensoray 2250",
484 .driver = &s2250_driver,
485};
486
487static int s2250_detect(struct i2c_adapter *adapter, int addr, int kind)
488{ 481{
489 struct i2c_client *client; 482 struct i2c_client *audio;
483 struct i2c_adapter *adapter = client->adapter;
490 struct s2250 *dec; 484 struct s2250 *dec;
491 u8 *data; 485 u8 *data;
492 struct go7007 *go = i2c_get_adapdata(adapter); 486 struct go7007 *go = i2c_get_adapdata(adapter);
493 struct go7007_usb *usb = go->hpi_context; 487 struct go7007_usb *usb = go->hpi_context;
494 488
495 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 489 audio = i2c_new_dummy(adapter, TLV320_ADDRESS >> 1);
496 if (client == NULL) 490 if (audio == NULL)
497 return -ENOMEM; 491 return -ENOMEM;
498 memcpy(client, &s2250_client_templ,
499 sizeof(s2250_client_templ));
500 client->adapter = adapter;
501 492
502 dec = kmalloc(sizeof(struct s2250), GFP_KERNEL); 493 dec = kmalloc(sizeof(struct s2250), GFP_KERNEL);
503 if (dec == NULL) { 494 if (dec == NULL) {
504 kfree(client); 495 i2c_unregister_device(audio);
505 return -ENOMEM; 496 return -ENOMEM;
506 } 497 }
507 498
@@ -510,7 +501,7 @@ static int s2250_detect(struct i2c_adapter *adapter, int addr, int kind)
510 dec->contrast = 50; 501 dec->contrast = 50;
511 dec->saturation = 50; 502 dec->saturation = 50;
512 dec->hue = 0; 503 dec->hue = 0;
513 client->addr = TLV320_ADDRESS; 504 dec->audio = audio;
514 i2c_set_clientdata(client, dec); 505 i2c_set_clientdata(client, dec);
515 506
516 printk(KERN_DEBUG 507 printk(KERN_DEBUG
@@ -518,28 +509,25 @@ static int s2250_detect(struct i2c_adapter *adapter, int addr, int kind)
518 adapter->name); 509 adapter->name);
519 510
520 /* initialize the audio */ 511 /* initialize the audio */
521 client->addr = TLV320_ADDRESS; 512 if (write_regs(audio, aud_regs) < 0) {
522 if (write_regs(client, aud_regs) < 0) {
523 printk(KERN_ERR 513 printk(KERN_ERR
524 "s2250: error initializing audio\n"); 514 "s2250: error initializing audio\n");
525 kfree(client); 515 i2c_unregister_device(audio);
526 kfree(dec); 516 kfree(dec);
527 return 0; 517 return 0;
528 } 518 }
529 client->addr = S2250_VIDDEC;
530 i2c_set_clientdata(client, dec);
531 519
532 if (write_regs(client, vid_regs) < 0) { 520 if (write_regs(client, vid_regs) < 0) {
533 printk(KERN_ERR 521 printk(KERN_ERR
534 "s2250: error initializing decoder\n"); 522 "s2250: error initializing decoder\n");
535 kfree(client); 523 i2c_unregister_device(audio);
536 kfree(dec); 524 kfree(dec);
537 return 0; 525 return 0;
538 } 526 }
539 if (write_regs_fp(client, vid_regs_fp) < 0) { 527 if (write_regs_fp(client, vid_regs_fp) < 0) {
540 printk(KERN_ERR 528 printk(KERN_ERR
541 "s2250: error initializing decoder\n"); 529 "s2250: error initializing decoder\n");
542 kfree(client); 530 i2c_unregister_device(audio);
543 kfree(dec); 531 kfree(dec);
544 return 0; 532 return 0;
545 } 533 }
@@ -575,32 +563,33 @@ static int s2250_detect(struct i2c_adapter *adapter, int addr, int kind)
575 up(&usb->i2c_lock); 563 up(&usb->i2c_lock);
576 } 564 }
577 565
578 i2c_attach_client(client);
579 printk("s2250: initialized successfully\n"); 566 printk("s2250: initialized successfully\n");
580 return 0; 567 return 0;
581} 568}
582 569
583static int s2250_detach(struct i2c_client *client) 570static int s2250_remove(struct i2c_client *client)
584{ 571{
585 struct s2250 *dec = i2c_get_clientdata(client); 572 struct s2250 *dec = i2c_get_clientdata(client);
586 int r;
587
588 r = i2c_detach_client(client);
589 if (r < 0)
590 return r;
591 573
592 kfree(client); 574 i2c_set_clientdata(client, NULL);
575 i2c_unregister_device(dec->audio);
593 kfree(dec); 576 kfree(dec);
594 return 0; 577 return 0;
595} 578}
596 579
580static struct i2c_device_id s2250_id[] = {
581 { "s2250_board", 0 },
582 { }
583};
584
597static struct i2c_driver s2250_driver = { 585static struct i2c_driver s2250_driver = {
598 .driver = { 586 .driver = {
599 .name = "Sensoray 2250 board driver", 587 .name = "Sensoray 2250 board driver",
600 }, 588 },
601 .id = I2C_DRIVERID_S2250, 589 .probe = s2250_probe,
602 .detach_client = s2250_detach, 590 .remove = s2250_remove,
603 .command = s2250_command, 591 .command = s2250_command,
592 .id_table = s2250_id,
604}; 593};
605 594
606static int __init s2250_init(void) 595static int __init s2250_init(void)
@@ -613,13 +602,13 @@ static int __init s2250_init(void)
613 602
614 r = i2c_add_driver(&s2250_driver); 603 r = i2c_add_driver(&s2250_driver);
615 if (r < 0) 604 if (r < 0)
616 return r; 605 s2250loader_cleanup();
617 return wis_i2c_add_driver(s2250_driver.id, s2250_detect); 606
607 return r;
618} 608}
619 609
620static void __exit s2250_cleanup(void) 610static void __exit s2250_cleanup(void)
621{ 611{
622 wis_i2c_del_driver(s2250_detect);
623 i2c_del_driver(&s2250_driver); 612 i2c_del_driver(&s2250_driver);
624 613
625 s2250loader_cleanup(); 614 s2250loader_cleanup();
diff --git a/drivers/staging/go7007/wis-i2c.h b/drivers/staging/go7007/wis-i2c.h
index 431f41dd3966..3c2b9be455df 100644
--- a/drivers/staging/go7007/wis-i2c.h
+++ b/drivers/staging/go7007/wis-i2c.h
@@ -24,21 +24,12 @@
24#define I2C_DRIVERID_WIS_OV7640 0xf0f5 24#define I2C_DRIVERID_WIS_OV7640 0xf0f5
25#define I2C_DRIVERID_WIS_TW2804 0xf0f6 25#define I2C_DRIVERID_WIS_TW2804 0xf0f6
26#define I2C_DRIVERID_S2250 0xf0f7 26#define I2C_DRIVERID_S2250 0xf0f7
27#define I2C_ALGO_GO7007 0xf00000
28#define I2C_ALGO_GO7007_USB 0xf10000
29 27
30/* Flag to indicate that the client needs to be accessed with SCCB semantics */ 28/* Flag to indicate that the client needs to be accessed with SCCB semantics */
31/* We re-use the I2C_M_TEN value so the flag passes through the masks in the 29/* We re-use the I2C_M_TEN value so the flag passes through the masks in the
32 * core I2C code. Major kludge, but the I2C layer ain't exactly flexible. */ 30 * core I2C code. Major kludge, but the I2C layer ain't exactly flexible. */
33#define I2C_CLIENT_SCCB 0x10 31#define I2C_CLIENT_SCCB 0x10
34 32
35typedef int (*found_proc) (struct i2c_adapter *, int, int);
36int wis_i2c_add_driver(unsigned int id, found_proc found_proc);
37void wis_i2c_del_driver(found_proc found_proc);
38
39int wis_i2c_probe_device(struct i2c_adapter *adapter,
40 unsigned int id, int addr);
41
42/* Definitions for new video decoder commands */ 33/* Definitions for new video decoder commands */
43 34
44struct video_decoder_resolution { 35struct video_decoder_resolution {
diff --git a/drivers/staging/go7007/wis-ov7640.c b/drivers/staging/go7007/wis-ov7640.c
index 2f9efca04606..04d6d3a498a3 100644
--- a/drivers/staging/go7007/wis-ov7640.c
+++ b/drivers/staging/go7007/wis-ov7640.c
@@ -50,76 +50,54 @@ static int write_regs(struct i2c_client *client, u8 *regs)
50 return 0; 50 return 0;
51} 51}
52 52
53static struct i2c_driver wis_ov7640_driver; 53static int wis_ov7640_probe(struct i2c_client *client,
54 54 const struct i2c_device_id *id)
55static struct i2c_client wis_ov7640_client_templ = {
56 .name = "OV7640 (WIS)",
57 .driver = &wis_ov7640_driver,
58};
59
60static int wis_ov7640_detect(struct i2c_adapter *adapter, int addr, int kind)
61{ 55{
62 struct i2c_client *client; 56 struct i2c_adapter *adapter = client->adapter;
63 57
64 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 58 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
65 return 0; 59 return -ENODEV;
66 60
67 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
68 if (client == NULL)
69 return -ENOMEM;
70 memcpy(client, &wis_ov7640_client_templ,
71 sizeof(wis_ov7640_client_templ));
72 client->adapter = adapter;
73 client->addr = addr;
74 client->flags = I2C_CLIENT_SCCB; 61 client->flags = I2C_CLIENT_SCCB;
75 62
76 printk(KERN_DEBUG 63 printk(KERN_DEBUG
77 "wis-ov7640: initializing OV7640 at address %d on %s\n", 64 "wis-ov7640: initializing OV7640 at address %d on %s\n",
78 addr, adapter->name); 65 client->addr, adapter->name);
79 66
80 if (write_regs(client, initial_registers) < 0) { 67 if (write_regs(client, initial_registers) < 0) {
81 printk(KERN_ERR "wis-ov7640: error initializing OV7640\n"); 68 printk(KERN_ERR "wis-ov7640: error initializing OV7640\n");
82 kfree(client); 69 return -ENODEV;
83 return 0;
84 } 70 }
85 71
86 i2c_attach_client(client);
87 return 0; 72 return 0;
88} 73}
89 74
90static int wis_ov7640_detach(struct i2c_client *client) 75static int wis_ov7640_remove(struct i2c_client *client)
91{ 76{
92 int r;
93
94 r = i2c_detach_client(client);
95 if (r < 0)
96 return r;
97
98 kfree(client);
99 return 0; 77 return 0;
100} 78}
101 79
80static struct i2c_device_id wis_ov7640_id[] = {
81 { "wis_ov7640", 0 },
82 { }
83};
84
102static struct i2c_driver wis_ov7640_driver = { 85static struct i2c_driver wis_ov7640_driver = {
103 .driver = { 86 .driver = {
104 .name = "WIS OV7640 I2C driver", 87 .name = "WIS OV7640 I2C driver",
105 }, 88 },
106 .id = I2C_DRIVERID_WIS_OV7640, 89 .probe = wis_ov7640_probe,
107 .detach_client = wis_ov7640_detach, 90 .remove = wis_ov7640_remove,
91 .id_table = wis_ov7640_id,
108}; 92};
109 93
110static int __init wis_ov7640_init(void) 94static int __init wis_ov7640_init(void)
111{ 95{
112 int r; 96 return i2c_add_driver(&wis_ov7640_driver);
113
114 r = i2c_add_driver(&wis_ov7640_driver);
115 if (r < 0)
116 return r;
117 return wis_i2c_add_driver(wis_ov7640_driver.id, wis_ov7640_detect);
118} 97}
119 98
120static void __exit wis_ov7640_cleanup(void) 99static void __exit wis_ov7640_cleanup(void)
121{ 100{
122 wis_i2c_del_driver(wis_ov7640_detect);
123 i2c_del_driver(&wis_ov7640_driver); 101 i2c_del_driver(&wis_ov7640_driver);
124} 102}
125 103
diff --git a/drivers/staging/go7007/wis-saa7113.c b/drivers/staging/go7007/wis-saa7113.c
index 11689723945e..9ab893bd204e 100644
--- a/drivers/staging/go7007/wis-saa7113.c
+++ b/drivers/staging/go7007/wis-saa7113.c
@@ -261,34 +261,19 @@ static int wis_saa7113_command(struct i2c_client *client,
261 return 0; 261 return 0;
262} 262}
263 263
264static struct i2c_driver wis_saa7113_driver; 264static int wis_saa7113_probe(struct i2c_client *client,
265 265 const struct i2c_device_id *id)
266static struct i2c_client wis_saa7113_client_templ = {
267 .name = "SAA7113 (WIS)",
268 .driver = &wis_saa7113_driver,
269};
270
271static int wis_saa7113_detect(struct i2c_adapter *adapter, int addr, int kind)
272{ 266{
273 struct i2c_client *client; 267 struct i2c_adapter *adapter = client->adapter;
274 struct wis_saa7113 *dec; 268 struct wis_saa7113 *dec;
275 269
276 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 270 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
277 return 0; 271 return -ENODEV;
278
279 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
280 if (client == NULL)
281 return -ENOMEM;
282 memcpy(client, &wis_saa7113_client_templ,
283 sizeof(wis_saa7113_client_templ));
284 client->adapter = adapter;
285 client->addr = addr;
286 272
287 dec = kmalloc(sizeof(struct wis_saa7113), GFP_KERNEL); 273 dec = kmalloc(sizeof(struct wis_saa7113), GFP_KERNEL);
288 if (dec == NULL) { 274 if (dec == NULL)
289 kfree(client);
290 return -ENOMEM; 275 return -ENOMEM;
291 } 276
292 dec->norm = V4L2_STD_NTSC; 277 dec->norm = V4L2_STD_NTSC;
293 dec->brightness = 128; 278 dec->brightness = 128;
294 dec->contrast = 71; 279 dec->contrast = 71;
@@ -298,56 +283,49 @@ static int wis_saa7113_detect(struct i2c_adapter *adapter, int addr, int kind)
298 283
299 printk(KERN_DEBUG 284 printk(KERN_DEBUG
300 "wis-saa7113: initializing SAA7113 at address %d on %s\n", 285 "wis-saa7113: initializing SAA7113 at address %d on %s\n",
301 addr, adapter->name); 286 client->addr, adapter->name);
302 287
303 if (write_regs(client, initial_registers) < 0) { 288 if (write_regs(client, initial_registers) < 0) {
304 printk(KERN_ERR 289 printk(KERN_ERR
305 "wis-saa7113: error initializing SAA7113\n"); 290 "wis-saa7113: error initializing SAA7113\n");
306 kfree(client);
307 kfree(dec); 291 kfree(dec);
308 return 0; 292 return -ENODEV;
309 } 293 }
310 294
311 i2c_attach_client(client);
312 return 0; 295 return 0;
313} 296}
314 297
315static int wis_saa7113_detach(struct i2c_client *client) 298static int wis_saa7113_remove(struct i2c_client *client)
316{ 299{
317 struct wis_saa7113 *dec = i2c_get_clientdata(client); 300 struct wis_saa7113 *dec = i2c_get_clientdata(client);
318 int r;
319
320 r = i2c_detach_client(client);
321 if (r < 0)
322 return r;
323 301
324 kfree(client); 302 i2c_set_clientdata(client, NULL);
325 kfree(dec); 303 kfree(dec);
326 return 0; 304 return 0;
327} 305}
328 306
307static struct i2c_device_id wis_saa7113_id[] = {
308 { "wis_saa7113", 0 },
309 { }
310};
311
329static struct i2c_driver wis_saa7113_driver = { 312static struct i2c_driver wis_saa7113_driver = {
330 .driver = { 313 .driver = {
331 .name = "WIS SAA7113 I2C driver", 314 .name = "WIS SAA7113 I2C driver",
332 }, 315 },
333 .id = I2C_DRIVERID_WIS_SAA7113, 316 .probe = wis_saa7113_probe,
334 .detach_client = wis_saa7113_detach, 317 .remove = wis_saa7113_remove,
335 .command = wis_saa7113_command, 318 .command = wis_saa7113_command,
319 .id_table = wis_saa7113_id,
336}; 320};
337 321
338static int __init wis_saa7113_init(void) 322static int __init wis_saa7113_init(void)
339{ 323{
340 int r; 324 return i2c_add_driver(&wis_saa7113_driver);
341
342 r = i2c_add_driver(&wis_saa7113_driver);
343 if (r < 0)
344 return r;
345 return wis_i2c_add_driver(wis_saa7113_driver.id, wis_saa7113_detect);
346} 325}
347 326
348static void __exit wis_saa7113_cleanup(void) 327static void __exit wis_saa7113_cleanup(void)
349{ 328{
350 wis_i2c_del_driver(wis_saa7113_detect);
351 i2c_del_driver(&wis_saa7113_driver); 329 i2c_del_driver(&wis_saa7113_driver);
352} 330}
353 331
diff --git a/drivers/staging/go7007/wis-saa7115.c b/drivers/staging/go7007/wis-saa7115.c
index 59417a7174d7..8687ad2de761 100644
--- a/drivers/staging/go7007/wis-saa7115.c
+++ b/drivers/staging/go7007/wis-saa7115.c
@@ -394,34 +394,19 @@ static int wis_saa7115_command(struct i2c_client *client,
394 return 0; 394 return 0;
395} 395}
396 396
397static struct i2c_driver wis_saa7115_driver; 397static int wis_saa7115_probe(struct i2c_client *client,
398 398 const struct i2c_device_id *id)
399static struct i2c_client wis_saa7115_client_templ = {
400 .name = "SAA7115 (WIS)",
401 .driver = &wis_saa7115_driver,
402};
403
404static int wis_saa7115_detect(struct i2c_adapter *adapter, int addr, int kind)
405{ 399{
406 struct i2c_client *client; 400 struct i2c_adapter *adapter = client->adapter;
407 struct wis_saa7115 *dec; 401 struct wis_saa7115 *dec;
408 402
409 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 403 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
410 return 0; 404 return -ENODEV;
411
412 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
413 if (client == NULL)
414 return -ENOMEM;
415 memcpy(client, &wis_saa7115_client_templ,
416 sizeof(wis_saa7115_client_templ));
417 client->adapter = adapter;
418 client->addr = addr;
419 405
420 dec = kmalloc(sizeof(struct wis_saa7115), GFP_KERNEL); 406 dec = kmalloc(sizeof(struct wis_saa7115), GFP_KERNEL);
421 if (dec == NULL) { 407 if (dec == NULL)
422 kfree(client);
423 return -ENOMEM; 408 return -ENOMEM;
424 } 409
425 dec->norm = V4L2_STD_NTSC; 410 dec->norm = V4L2_STD_NTSC;
426 dec->brightness = 128; 411 dec->brightness = 128;
427 dec->contrast = 64; 412 dec->contrast = 64;
@@ -431,56 +416,49 @@ static int wis_saa7115_detect(struct i2c_adapter *adapter, int addr, int kind)
431 416
432 printk(KERN_DEBUG 417 printk(KERN_DEBUG
433 "wis-saa7115: initializing SAA7115 at address %d on %s\n", 418 "wis-saa7115: initializing SAA7115 at address %d on %s\n",
434 addr, adapter->name); 419 client->addr, adapter->name);
435 420
436 if (write_regs(client, initial_registers) < 0) { 421 if (write_regs(client, initial_registers) < 0) {
437 printk(KERN_ERR 422 printk(KERN_ERR
438 "wis-saa7115: error initializing SAA7115\n"); 423 "wis-saa7115: error initializing SAA7115\n");
439 kfree(client);
440 kfree(dec); 424 kfree(dec);
441 return 0; 425 return -ENODEV;
442 } 426 }
443 427
444 i2c_attach_client(client);
445 return 0; 428 return 0;
446} 429}
447 430
448static int wis_saa7115_detach(struct i2c_client *client) 431static int wis_saa7115_remove(struct i2c_client *client)
449{ 432{
450 struct wis_saa7115 *dec = i2c_get_clientdata(client); 433 struct wis_saa7115 *dec = i2c_get_clientdata(client);
451 int r;
452
453 r = i2c_detach_client(client);
454 if (r < 0)
455 return r;
456 434
457 kfree(client); 435 i2c_set_clientdata(client, NULL);
458 kfree(dec); 436 kfree(dec);
459 return 0; 437 return 0;
460} 438}
461 439
440static struct i2c_device_id wis_saa7115_id[] = {
441 { "wis_saa7115", 0 },
442 { }
443};
444
462static struct i2c_driver wis_saa7115_driver = { 445static struct i2c_driver wis_saa7115_driver = {
463 .driver = { 446 .driver = {
464 .name = "WIS SAA7115 I2C driver", 447 .name = "WIS SAA7115 I2C driver",
465 }, 448 },
466 .id = I2C_DRIVERID_WIS_SAA7115, 449 .probe = wis_saa7115_probe,
467 .detach_client = wis_saa7115_detach, 450 .remove = wis_saa7115_remove,
468 .command = wis_saa7115_command, 451 .command = wis_saa7115_command,
452 .id_table = wis_saa7115_id,
469}; 453};
470 454
471static int __init wis_saa7115_init(void) 455static int __init wis_saa7115_init(void)
472{ 456{
473 int r; 457 return i2c_add_driver(&wis_saa7115_driver);
474
475 r = i2c_add_driver(&wis_saa7115_driver);
476 if (r < 0)
477 return r;
478 return wis_i2c_add_driver(wis_saa7115_driver.id, wis_saa7115_detect);
479} 458}
480 459
481static void __exit wis_saa7115_cleanup(void) 460static void __exit wis_saa7115_cleanup(void)
482{ 461{
483 wis_i2c_del_driver(wis_saa7115_detect);
484 i2c_del_driver(&wis_saa7115_driver); 462 i2c_del_driver(&wis_saa7115_driver);
485} 463}
486 464
diff --git a/drivers/staging/go7007/wis-sony-tuner.c b/drivers/staging/go7007/wis-sony-tuner.c
index 0a7eeef7c008..c965c601ac90 100644
--- a/drivers/staging/go7007/wis-sony-tuner.c
+++ b/drivers/staging/go7007/wis-sony-tuner.c
@@ -653,35 +653,19 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
653 return 0; 653 return 0;
654} 654}
655 655
656static struct i2c_driver wis_sony_tuner_driver; 656static int wis_sony_tuner_probe(struct i2c_client *client,
657 657 const struct i2c_device_id *id)
658static struct i2c_client wis_sony_tuner_client_templ = {
659 .name = "Sony TV Tuner (WIS)",
660 .driver = &wis_sony_tuner_driver,
661};
662
663static int wis_sony_tuner_detect(struct i2c_adapter *adapter,
664 int addr, int kind)
665{ 658{
666 struct i2c_client *client; 659 struct i2c_adapter *adapter = client->adapter;
667 struct wis_sony_tuner *t; 660 struct wis_sony_tuner *t;
668 661
669 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) 662 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
670 return 0; 663 return -ENODEV;
671
672 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
673 if (client == NULL)
674 return -ENOMEM;
675 memcpy(client, &wis_sony_tuner_client_templ,
676 sizeof(wis_sony_tuner_client_templ));
677 client->adapter = adapter;
678 client->addr = addr;
679 664
680 t = kmalloc(sizeof(struct wis_sony_tuner), GFP_KERNEL); 665 t = kmalloc(sizeof(struct wis_sony_tuner), GFP_KERNEL);
681 if (t == NULL) { 666 if (t == NULL)
682 kfree(client);
683 return -ENOMEM; 667 return -ENOMEM;
684 } 668
685 t->type = -1; 669 t->type = -1;
686 t->freq = 0; 670 t->freq = 0;
687 t->mpxmode = 0; 671 t->mpxmode = 0;
@@ -690,50 +674,42 @@ static int wis_sony_tuner_detect(struct i2c_adapter *adapter,
690 674
691 printk(KERN_DEBUG 675 printk(KERN_DEBUG
692 "wis-sony-tuner: initializing tuner at address %d on %s\n", 676 "wis-sony-tuner: initializing tuner at address %d on %s\n",
693 addr, adapter->name); 677 client->addr, adapter->name);
694
695 i2c_attach_client(client);
696 678
697 return 0; 679 return 0;
698} 680}
699 681
700static int wis_sony_tuner_detach(struct i2c_client *client) 682static int wis_sony_tuner_remove(struct i2c_client *client)
701{ 683{
702 struct wis_sony_tuner *t = i2c_get_clientdata(client); 684 struct wis_sony_tuner *t = i2c_get_clientdata(client);
703 int r;
704
705 r = i2c_detach_client(client);
706 if (r < 0)
707 return r;
708 685
686 i2c_set_clientdata(client, NULL);
709 kfree(t); 687 kfree(t);
710 kfree(client);
711 return 0; 688 return 0;
712} 689}
713 690
691static struct i2c_device_id wis_sony_tuner_id[] = {
692 { "wis_sony_tuner", 0 },
693 { }
694};
695
714static struct i2c_driver wis_sony_tuner_driver = { 696static struct i2c_driver wis_sony_tuner_driver = {
715 .driver = { 697 .driver = {
716 .name = "WIS Sony TV Tuner I2C driver", 698 .name = "WIS Sony TV Tuner I2C driver",
717 }, 699 },
718 .id = I2C_DRIVERID_WIS_SONY_TUNER, 700 .probe = wis_sony_tuner_probe,
719 .detach_client = wis_sony_tuner_detach, 701 .remove = wis_sony_tuner_remove,
720 .command = tuner_command, 702 .command = tuner_command,
703 .id_table = wis_sony_tuner_id,
721}; 704};
722 705
723static int __init wis_sony_tuner_init(void) 706static int __init wis_sony_tuner_init(void)
724{ 707{
725 int r; 708 return i2c_add_driver(&wis_sony_tuner_driver);
726
727 r = i2c_add_driver(&wis_sony_tuner_driver);
728 if (r < 0)
729 return r;
730 return wis_i2c_add_driver(wis_sony_tuner_driver.id,
731 wis_sony_tuner_detect);
732} 709}
733 710
734static void __exit wis_sony_tuner_cleanup(void) 711static void __exit wis_sony_tuner_cleanup(void)
735{ 712{
736 wis_i2c_del_driver(wis_sony_tuner_detect);
737 i2c_del_driver(&wis_sony_tuner_driver); 713 i2c_del_driver(&wis_sony_tuner_driver);
738} 714}
739 715
diff --git a/drivers/staging/go7007/wis-tw2804.c b/drivers/staging/go7007/wis-tw2804.c
index 57b8f2b1caa3..e15794a2a0ae 100644
--- a/drivers/staging/go7007/wis-tw2804.c
+++ b/drivers/staging/go7007/wis-tw2804.c
@@ -291,34 +291,19 @@ static int wis_tw2804_command(struct i2c_client *client,
291 return 0; 291 return 0;
292} 292}
293 293
294static struct i2c_driver wis_tw2804_driver; 294static int wis_tw2804_probe(struct i2c_client *client,
295 295 const struct i2c_device_id *id)
296static struct i2c_client wis_tw2804_client_templ = {
297 .name = "TW2804 (WIS)",
298 .driver = &wis_tw2804_driver,
299};
300
301static int wis_tw2804_detect(struct i2c_adapter *adapter, int addr, int kind)
302{ 296{
303 struct i2c_client *client; 297 struct i2c_adapter *adapter = client->adapter;
304 struct wis_tw2804 *dec; 298 struct wis_tw2804 *dec;
305 299
306 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 300 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
307 return 0; 301 return -ENODEV;
308
309 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
310 if (client == NULL)
311 return -ENOMEM;
312 memcpy(client, &wis_tw2804_client_templ,
313 sizeof(wis_tw2804_client_templ));
314 client->adapter = adapter;
315 client->addr = addr;
316 302
317 dec = kmalloc(sizeof(struct wis_tw2804), GFP_KERNEL); 303 dec = kmalloc(sizeof(struct wis_tw2804), GFP_KERNEL);
318 if (dec == NULL) { 304 if (dec == NULL)
319 kfree(client);
320 return -ENOMEM; 305 return -ENOMEM;
321 } 306
322 dec->channel = -1; 307 dec->channel = -1;
323 dec->norm = V4L2_STD_NTSC; 308 dec->norm = V4L2_STD_NTSC;
324 dec->brightness = 128; 309 dec->brightness = 128;
@@ -328,48 +313,42 @@ static int wis_tw2804_detect(struct i2c_adapter *adapter, int addr, int kind)
328 i2c_set_clientdata(client, dec); 313 i2c_set_clientdata(client, dec);
329 314
330 printk(KERN_DEBUG "wis-tw2804: creating TW2804 at address %d on %s\n", 315 printk(KERN_DEBUG "wis-tw2804: creating TW2804 at address %d on %s\n",
331 addr, adapter->name); 316 client->addr, adapter->name);
332 317
333 i2c_attach_client(client);
334 return 0; 318 return 0;
335} 319}
336 320
337static int wis_tw2804_detach(struct i2c_client *client) 321static int wis_tw2804_remove(struct i2c_client *client)
338{ 322{
339 struct wis_tw2804 *dec = i2c_get_clientdata(client); 323 struct wis_tw2804 *dec = i2c_get_clientdata(client);
340 int r;
341
342 r = i2c_detach_client(client);
343 if (r < 0)
344 return r;
345 324
346 kfree(client); 325 i2c_set_clientdata(client, NULL);
347 kfree(dec); 326 kfree(dec);
348 return 0; 327 return 0;
349} 328}
350 329
330static struct i2c_device_id wis_tw2804_id[] = {
331 { "wis_tw2804", 0 },
332 { }
333};
334
351static struct i2c_driver wis_tw2804_driver = { 335static struct i2c_driver wis_tw2804_driver = {
352 .driver = { 336 .driver = {
353 .name = "WIS TW2804 I2C driver", 337 .name = "WIS TW2804 I2C driver",
354 }, 338 },
355 .id = I2C_DRIVERID_WIS_TW2804, 339 .probe = wis_tw2804_probe,
356 .detach_client = wis_tw2804_detach, 340 .remove = wis_tw2804_remove,
357 .command = wis_tw2804_command, 341 .command = wis_tw2804_command,
342 .id_table = wis_tw2804_id,
358}; 343};
359 344
360static int __init wis_tw2804_init(void) 345static int __init wis_tw2804_init(void)
361{ 346{
362 int r; 347 return i2c_add_driver(&wis_tw2804_driver);
363
364 r = i2c_add_driver(&wis_tw2804_driver);
365 if (r < 0)
366 return r;
367 return wis_i2c_add_driver(wis_tw2804_driver.id, wis_tw2804_detect);
368} 348}
369 349
370static void __exit wis_tw2804_cleanup(void) 350static void __exit wis_tw2804_cleanup(void)
371{ 351{
372 wis_i2c_del_driver(wis_tw2804_detect);
373 i2c_del_driver(&wis_tw2804_driver); 352 i2c_del_driver(&wis_tw2804_driver);
374} 353}
375 354
diff --git a/drivers/staging/go7007/wis-tw9903.c b/drivers/staging/go7007/wis-tw9903.c
index 40627b282cb4..6c3427bb6f4c 100644
--- a/drivers/staging/go7007/wis-tw9903.c
+++ b/drivers/staging/go7007/wis-tw9903.c
@@ -267,34 +267,19 @@ static int wis_tw9903_command(struct i2c_client *client,
267 return 0; 267 return 0;
268} 268}
269 269
270static struct i2c_driver wis_tw9903_driver; 270static int wis_tw9903_probe(struct i2c_client *client,
271 271 const struct i2c_device_id *id)
272static struct i2c_client wis_tw9903_client_templ = {
273 .name = "TW9903 (WIS)",
274 .driver = &wis_tw9903_driver,
275};
276
277static int wis_tw9903_detect(struct i2c_adapter *adapter, int addr, int kind)
278{ 272{
279 struct i2c_client *client; 273 struct i2c_adapter *adapter = client->adapter;
280 struct wis_tw9903 *dec; 274 struct wis_tw9903 *dec;
281 275
282 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 276 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
283 return 0; 277 return -ENODEV;
284
285 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
286 if (client == NULL)
287 return -ENOMEM;
288 memcpy(client, &wis_tw9903_client_templ,
289 sizeof(wis_tw9903_client_templ));
290 client->adapter = adapter;
291 client->addr = addr;
292 278
293 dec = kmalloc(sizeof(struct wis_tw9903), GFP_KERNEL); 279 dec = kmalloc(sizeof(struct wis_tw9903), GFP_KERNEL);
294 if (dec == NULL) { 280 if (dec == NULL)
295 kfree(client);
296 return -ENOMEM; 281 return -ENOMEM;
297 } 282
298 dec->norm = V4L2_STD_NTSC; 283 dec->norm = V4L2_STD_NTSC;
299 dec->brightness = 0; 284 dec->brightness = 0;
300 dec->contrast = 0x60; 285 dec->contrast = 0x60;
@@ -303,55 +288,48 @@ static int wis_tw9903_detect(struct i2c_adapter *adapter, int addr, int kind)
303 288
304 printk(KERN_DEBUG 289 printk(KERN_DEBUG
305 "wis-tw9903: initializing TW9903 at address %d on %s\n", 290 "wis-tw9903: initializing TW9903 at address %d on %s\n",
306 addr, adapter->name); 291 client->addr, adapter->name);
307 292
308 if (write_regs(client, initial_registers) < 0) { 293 if (write_regs(client, initial_registers) < 0) {
309 printk(KERN_ERR "wis-tw9903: error initializing TW9903\n"); 294 printk(KERN_ERR "wis-tw9903: error initializing TW9903\n");
310 kfree(client);
311 kfree(dec); 295 kfree(dec);
312 return 0; 296 return -ENODEV;
313 } 297 }
314 298
315 i2c_attach_client(client);
316 return 0; 299 return 0;
317} 300}
318 301
319static int wis_tw9903_detach(struct i2c_client *client) 302static int wis_tw9903_remove(struct i2c_client *client)
320{ 303{
321 struct wis_tw9903 *dec = i2c_get_clientdata(client); 304 struct wis_tw9903 *dec = i2c_get_clientdata(client);
322 int r;
323
324 r = i2c_detach_client(client);
325 if (r < 0)
326 return r;
327 305
328 kfree(client); 306 i2c_set_clientdata(client, NULL);
329 kfree(dec); 307 kfree(dec);
330 return 0; 308 return 0;
331} 309}
332 310
311static struct i2c_device_id wis_tw9903_id[] = {
312 { "wis_tw9903", 0 },
313 { }
314};
315
333static struct i2c_driver wis_tw9903_driver = { 316static struct i2c_driver wis_tw9903_driver = {
334 .driver = { 317 .driver = {
335 .name = "WIS TW9903 I2C driver", 318 .name = "WIS TW9903 I2C driver",
336 }, 319 },
337 .id = I2C_DRIVERID_WIS_TW9903, 320 .probe = wis_tw9903_probe,
338 .detach_client = wis_tw9903_detach, 321 .remove = wis_tw9903_remove,
339 .command = wis_tw9903_command, 322 .command = wis_tw9903_command,
323 .id_table = wis_tw9903_id,
340}; 324};
341 325
342static int __init wis_tw9903_init(void) 326static int __init wis_tw9903_init(void)
343{ 327{
344 int r; 328 return i2c_add_driver(&wis_tw9903_driver);
345
346 r = i2c_add_driver(&wis_tw9903_driver);
347 if (r < 0)
348 return r;
349 return wis_i2c_add_driver(wis_tw9903_driver.id, wis_tw9903_detect);
350} 329}
351 330
352static void __exit wis_tw9903_cleanup(void) 331static void __exit wis_tw9903_cleanup(void)
353{ 332{
354 wis_i2c_del_driver(wis_tw9903_detect);
355 i2c_del_driver(&wis_tw9903_driver); 333 i2c_del_driver(&wis_tw9903_driver);
356} 334}
357 335
diff --git a/drivers/staging/go7007/wis-uda1342.c b/drivers/staging/go7007/wis-uda1342.c
index 555645c0cc1a..739c7ae8913f 100644
--- a/drivers/staging/go7007/wis-uda1342.c
+++ b/drivers/staging/go7007/wis-uda1342.c
@@ -59,73 +59,51 @@ static int wis_uda1342_command(struct i2c_client *client,
59 return 0; 59 return 0;
60} 60}
61 61
62static struct i2c_driver wis_uda1342_driver; 62static int wis_uda1342_probe(struct i2c_client *client,
63 63 const struct i2c_device_id *id)
64static struct i2c_client wis_uda1342_client_templ = {
65 .name = "UDA1342 (WIS)",
66 .driver = &wis_uda1342_driver,
67};
68
69static int wis_uda1342_detect(struct i2c_adapter *adapter, int addr, int kind)
70{ 64{
71 struct i2c_client *client; 65 struct i2c_adapter *adapter = client->adapter;
72 66
73 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) 67 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
74 return 0; 68 return -ENODEV;
75
76 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
77 if (client == NULL)
78 return -ENOMEM;
79 memcpy(client, &wis_uda1342_client_templ,
80 sizeof(wis_uda1342_client_templ));
81 client->adapter = adapter;
82 client->addr = addr;
83 69
84 printk(KERN_DEBUG 70 printk(KERN_DEBUG
85 "wis-uda1342: initializing UDA1342 at address %d on %s\n", 71 "wis-uda1342: initializing UDA1342 at address %d on %s\n",
86 addr, adapter->name); 72 client->addr, adapter->name);
87 73
88 write_reg(client, 0x00, 0x8000); /* reset registers */ 74 write_reg(client, 0x00, 0x8000); /* reset registers */
89 write_reg(client, 0x00, 0x1241); /* select input 1 */ 75 write_reg(client, 0x00, 0x1241); /* select input 1 */
90 76
91 i2c_attach_client(client);
92 return 0; 77 return 0;
93} 78}
94 79
95static int wis_uda1342_detach(struct i2c_client *client) 80static int wis_uda1342_remove(struct i2c_client *client)
96{ 81{
97 int r;
98
99 r = i2c_detach_client(client);
100 if (r < 0)
101 return r;
102
103 kfree(client);
104 return 0; 82 return 0;
105} 83}
106 84
85static struct i2c_device_id wis_uda1342_id[] = {
86 { "wis_uda1342", 0 },
87 { }
88};
89
107static struct i2c_driver wis_uda1342_driver = { 90static struct i2c_driver wis_uda1342_driver = {
108 .driver = { 91 .driver = {
109 .name = "WIS UDA1342 I2C driver", 92 .name = "WIS UDA1342 I2C driver",
110 }, 93 },
111 .id = I2C_DRIVERID_WIS_UDA1342, 94 .probe = wis_uda1342_probe,
112 .detach_client = wis_uda1342_detach, 95 .remove = wis_uda1342_remove,
113 .command = wis_uda1342_command, 96 .command = wis_uda1342_command,
97 .id_table = wis_uda1342_id,
114}; 98};
115 99
116static int __init wis_uda1342_init(void) 100static int __init wis_uda1342_init(void)
117{ 101{
118 int r; 102 return i2c_add_driver(&wis_uda1342_driver);
119
120 r = i2c_add_driver(&wis_uda1342_driver);
121 if (r < 0)
122 return r;
123 return wis_i2c_add_driver(wis_uda1342_driver.id, wis_uda1342_detect);
124} 103}
125 104
126static void __exit wis_uda1342_cleanup(void) 105static void __exit wis_uda1342_cleanup(void)
127{ 106{
128 wis_i2c_del_driver(wis_uda1342_detect);
129 i2c_del_driver(&wis_uda1342_driver); 107 i2c_del_driver(&wis_uda1342_driver);
130} 108}
131 109