aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/media/video/bt8xx/bttv-i2c.c21
-rw-r--r--drivers/media/video/cx231xx/cx231xx-cards.c11
-rw-r--r--drivers/media/video/cx231xx/cx231xx-i2c.c3
-rw-r--r--drivers/media/video/cx231xx/cx231xx.h1
-rw-r--r--drivers/media/video/cx23885/cx23885-i2c.c12
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c13
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c20
-rw-r--r--drivers/media/video/em28xx/em28xx-i2c.c3
-rw-r--r--drivers/media/video/em28xx/em28xx-input.c6
-rw-r--r--drivers/media/video/em28xx/em28xx.h1
-rw-r--r--drivers/media/video/ir-kbd-i2c.c200
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c31
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c3
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c86
-rw-r--r--drivers/media/video/saa7134/saa7134.h1
-rw-r--r--include/media/ir-kbd-i2c.h2
16 files changed, 220 insertions, 194 deletions
diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c
index a99d92fac3dc..ebd1ee9dc871 100644
--- a/drivers/media/video/bt8xx/bttv-i2c.c
+++ b/drivers/media/video/bt8xx/bttv-i2c.c
@@ -389,6 +389,27 @@ int __devinit init_bttv_i2c(struct bttv *btv)
389 } 389 }
390 if (0 == btv->i2c_rc && i2c_scan) 390 if (0 == btv->i2c_rc && i2c_scan)
391 do_i2c_scan(btv->c.v4l2_dev.name, &btv->i2c_client); 391 do_i2c_scan(btv->c.v4l2_dev.name, &btv->i2c_client);
392
393 /* Instantiate the IR receiver device, if present */
394 if (0 == btv->i2c_rc) {
395 struct i2c_board_info info;
396 /* The external IR receiver is at i2c address 0x34 (0x35 for
397 reads). Future Hauppauge cards will have an internal
398 receiver at 0x30 (0x31 for reads). In theory, both can be
399 fitted, and Hauppauge suggest an external overrides an
400 internal.
401
402 That's why we probe 0x1a (~0x34) first. CB
403 */
404 const unsigned short addr_list[] = {
405 0x1a, 0x18, 0x4b, 0x64, 0x30,
406 I2C_CLIENT_END
407 };
408
409 memset(&info, 0, sizeof(struct i2c_board_info));
410 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
411 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list);
412 }
392 return btv->i2c_rc; 413 return btv->i2c_rc;
393} 414}
394 415
diff --git a/drivers/media/video/cx231xx/cx231xx-cards.c b/drivers/media/video/cx231xx/cx231xx-cards.c
index c8a32b1b5381..734f6eaefd9b 100644
--- a/drivers/media/video/cx231xx/cx231xx-cards.c
+++ b/drivers/media/video/cx231xx/cx231xx-cards.c
@@ -281,13 +281,16 @@ static void cx231xx_config_tuner(struct cx231xx *dev)
281} 281}
282 282
283/* ----------------------------------------------------------------------- */ 283/* ----------------------------------------------------------------------- */
284void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir) 284void cx231xx_register_i2c_ir(struct cx231xx *dev)
285{ 285{
286 if (disable_ir) { 286 if (disable_ir)
287 ir->get_key = NULL;
288 return; 287 return;
289 }
290 288
289 /* REVISIT: instantiate IR device */
290}
291
292void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir)
293{
291 /* detect & configure */ 294 /* detect & configure */
292 switch (dev->model) { 295 switch (dev->model) {
293 296
diff --git a/drivers/media/video/cx231xx/cx231xx-i2c.c b/drivers/media/video/cx231xx/cx231xx-i2c.c
index b4a03d813e00..ac4099a49da0 100644
--- a/drivers/media/video/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/video/cx231xx/cx231xx-i2c.c
@@ -537,6 +537,9 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus)
537 if (0 == bus->i2c_rc) { 537 if (0 == bus->i2c_rc) {
538 if (i2c_scan) 538 if (i2c_scan)
539 cx231xx_do_i2c_scan(dev, &bus->i2c_client); 539 cx231xx_do_i2c_scan(dev, &bus->i2c_client);
540
541 /* Instantiate the IR receiver device, if present */
542 cx231xx_register_i2c_ir(dev);
540 } else 543 } else
541 cx231xx_warn("%s: i2c bus %d register FAILED\n", 544 cx231xx_warn("%s: i2c bus %d register FAILED\n",
542 dev->name, bus->nr); 545 dev->name, bus->nr);
diff --git a/drivers/media/video/cx231xx/cx231xx.h b/drivers/media/video/cx231xx/cx231xx.h
index aa4a23ef491a..8c300f60fdff 100644
--- a/drivers/media/video/cx231xx/cx231xx.h
+++ b/drivers/media/video/cx231xx/cx231xx.h
@@ -738,6 +738,7 @@ extern void cx231xx_card_setup(struct cx231xx *dev);
738extern struct cx231xx_board cx231xx_boards[]; 738extern struct cx231xx_board cx231xx_boards[];
739extern struct usb_device_id cx231xx_id_table[]; 739extern struct usb_device_id cx231xx_id_table[];
740extern const unsigned int cx231xx_bcount; 740extern const unsigned int cx231xx_bcount;
741void cx231xx_register_i2c_ir(struct cx231xx *dev);
741void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir); 742void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir);
742int cx231xx_tuner_callback(void *ptr, int component, int command, int arg); 743int cx231xx_tuner_callback(void *ptr, int component, int command, int arg);
743 744
diff --git a/drivers/media/video/cx23885/cx23885-i2c.c b/drivers/media/video/cx23885/cx23885-i2c.c
index 3421bd12056a..384dec34134f 100644
--- a/drivers/media/video/cx23885/cx23885-i2c.c
+++ b/drivers/media/video/cx23885/cx23885-i2c.c
@@ -357,6 +357,18 @@ int cx23885_i2c_register(struct cx23885_i2c *bus)
357 printk(KERN_WARNING "%s: i2c bus %d register FAILED\n", 357 printk(KERN_WARNING "%s: i2c bus %d register FAILED\n",
358 dev->name, bus->nr); 358 dev->name, bus->nr);
359 359
360 /* Instantiate the IR receiver device, if present */
361 if (0 == bus->i2c_rc) {
362 struct i2c_board_info info;
363 const unsigned short addr_list[] = {
364 0x6b, I2C_CLIENT_END
365 };
366
367 memset(&info, 0, sizeof(struct i2c_board_info));
368 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
369 i2c_new_probed_device(&bus->i2c_adap, &info, addr_list);
370 }
371
360 return bus->i2c_rc; 372 return bus->i2c_rc;
361} 373}
362 374
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index 996b4ed5a4fc..ee1ca39db06a 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -180,6 +180,19 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
180 do_i2c_scan(core->name,&core->i2c_client); 180 do_i2c_scan(core->name,&core->i2c_client);
181 } else 181 } else
182 printk("%s: i2c register FAILED\n", core->name); 182 printk("%s: i2c register FAILED\n", core->name);
183
184 /* Instantiate the IR receiver device, if present */
185 if (0 == core->i2c_rc) {
186 struct i2c_board_info info;
187 const unsigned short addr_list[] = {
188 0x18, 0x6b, 0x71,
189 I2C_CLIENT_END
190 };
191
192 memset(&info, 0, sizeof(struct i2c_board_info));
193 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
194 i2c_new_probed_device(&core->i2c_adap, &info, addr_list);
195 }
183 return core->i2c_rc; 196 return core->i2c_rc;
184} 197}
185 198
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index b2aed29e2d74..edba71115a94 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -1912,13 +1912,23 @@ static int em28xx_hint_board(struct em28xx *dev)
1912} 1912}
1913 1913
1914/* ----------------------------------------------------------------------- */ 1914/* ----------------------------------------------------------------------- */
1915void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir) 1915void em28xx_register_i2c_ir(struct em28xx *dev)
1916{ 1916{
1917 if (disable_ir) { 1917 struct i2c_board_info info;
1918 ir->get_key = NULL; 1918 const unsigned short addr_list[] = {
1919 return ; 1919 0x30, 0x47, I2C_CLIENT_END
1920 } 1920 };
1921
1922 if (disable_ir)
1923 return;
1921 1924
1925 memset(&info, 0, sizeof(struct i2c_board_info));
1926 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
1927 i2c_new_probed_device(&dev->i2c_adap, &info, addr_list);
1928}
1929
1930void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir)
1931{
1922 /* detect & configure */ 1932 /* detect & configure */
1923 switch (dev->model) { 1933 switch (dev->model) {
1924 case (EM2800_BOARD_UNKNOWN): 1934 case (EM2800_BOARD_UNKNOWN):
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c
index f0bf1d960c75..d90294cbb70d 100644
--- a/drivers/media/video/em28xx/em28xx-i2c.c
+++ b/drivers/media/video/em28xx/em28xx-i2c.c
@@ -575,6 +575,9 @@ int em28xx_i2c_register(struct em28xx *dev)
575 if (i2c_scan) 575 if (i2c_scan)
576 em28xx_do_i2c_scan(dev); 576 em28xx_do_i2c_scan(dev);
577 577
578 /* Instantiate the IR receiver device, if present */
579 em28xx_register_i2c_ir(dev);
580
578 return 0; 581 return 0;
579} 582}
580 583
diff --git a/drivers/media/video/em28xx/em28xx-input.c b/drivers/media/video/em28xx/em28xx-input.c
index 7450ba7dee83..7a0fe3816e3d 100644
--- a/drivers/media/video/em28xx/em28xx-input.c
+++ b/drivers/media/video/em28xx/em28xx-input.c
@@ -85,7 +85,7 @@ int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
85 unsigned char b; 85 unsigned char b;
86 86
87 /* poll IR chip */ 87 /* poll IR chip */
88 if (1 != i2c_master_recv(&ir->c, &b, 1)) { 88 if (1 != i2c_master_recv(ir->c, &b, 1)) {
89 i2cdprintk("read error\n"); 89 i2cdprintk("read error\n");
90 return -EIO; 90 return -EIO;
91 } 91 }
@@ -114,7 +114,7 @@ int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
114 unsigned char code; 114 unsigned char code;
115 115
116 /* poll IR chip */ 116 /* poll IR chip */
117 if (2 != i2c_master_recv(&ir->c, buf, 2)) 117 if (2 != i2c_master_recv(ir->c, buf, 2))
118 return -EIO; 118 return -EIO;
119 119
120 /* Does eliminate repeated parity code */ 120 /* Does eliminate repeated parity code */
@@ -147,7 +147,7 @@ int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
147 147
148 /* poll IR chip */ 148 /* poll IR chip */
149 149
150 if (3 != i2c_master_recv(&ir->c, buf, 3)) { 150 if (3 != i2c_master_recv(ir->c, buf, 3)) {
151 i2cdprintk("read error\n"); 151 i2cdprintk("read error\n");
152 return -EIO; 152 return -EIO;
153 } 153 }
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index 58c0ef4a2dce..9c632541df10 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -643,6 +643,7 @@ extern void em28xx_card_setup(struct em28xx *dev);
643extern struct em28xx_board em28xx_boards[]; 643extern struct em28xx_board em28xx_boards[];
644extern struct usb_device_id em28xx_id_table[]; 644extern struct usb_device_id em28xx_id_table[];
645extern const unsigned int em28xx_bcount; 645extern const unsigned int em28xx_bcount;
646void em28xx_register_i2c_ir(struct em28xx *dev);
646void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir); 647void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir);
647int em28xx_tuner_callback(void *ptr, int component, int command, int arg); 648int em28xx_tuner_callback(void *ptr, int component, int command, int arg);
648void em28xx_release_resources(struct em28xx *dev); 649void em28xx_release_resources(struct em28xx *dev);
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index ba341e6fb2da..cb833a63041c 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -74,7 +74,7 @@ static int get_key_haup_common(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
74 int start, range, toggle, dev, code, ircode; 74 int start, range, toggle, dev, code, ircode;
75 75
76 /* poll IR chip */ 76 /* poll IR chip */
77 if (size != i2c_master_recv(&ir->c,buf,size)) 77 if (size != i2c_master_recv(ir->c, buf, size))
78 return -EIO; 78 return -EIO;
79 79
80 /* split rc5 data block ... */ 80 /* split rc5 data block ... */
@@ -137,7 +137,7 @@ static int get_key_pixelview(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
137 unsigned char b; 137 unsigned char b;
138 138
139 /* poll IR chip */ 139 /* poll IR chip */
140 if (1 != i2c_master_recv(&ir->c,&b,1)) { 140 if (1 != i2c_master_recv(ir->c, &b, 1)) {
141 dprintk(1,"read error\n"); 141 dprintk(1,"read error\n");
142 return -EIO; 142 return -EIO;
143 } 143 }
@@ -151,7 +151,7 @@ static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
151 unsigned char b; 151 unsigned char b;
152 152
153 /* poll IR chip */ 153 /* poll IR chip */
154 if (1 != i2c_master_recv(&ir->c,&b,1)) { 154 if (1 != i2c_master_recv(ir->c, &b, 1)) {
155 dprintk(1,"read error\n"); 155 dprintk(1,"read error\n");
156 return -EIO; 156 return -EIO;
157 } 157 }
@@ -171,7 +171,7 @@ static int get_key_fusionhdtv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
171 unsigned char buf[4]; 171 unsigned char buf[4];
172 172
173 /* poll IR chip */ 173 /* poll IR chip */
174 if (4 != i2c_master_recv(&ir->c,buf,4)) { 174 if (4 != i2c_master_recv(ir->c, buf, 4)) {
175 dprintk(1,"read error\n"); 175 dprintk(1,"read error\n");
176 return -EIO; 176 return -EIO;
177 } 177 }
@@ -195,7 +195,7 @@ static int get_key_knc1(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
195 unsigned char b; 195 unsigned char b;
196 196
197 /* poll IR chip */ 197 /* poll IR chip */
198 if (1 != i2c_master_recv(&ir->c,&b,1)) { 198 if (1 != i2c_master_recv(ir->c, &b, 1)) {
199 dprintk(1,"read error\n"); 199 dprintk(1,"read error\n");
200 return -EIO; 200 return -EIO;
201 } 201 }
@@ -222,12 +222,12 @@ static int get_key_avermedia_cardbus(struct IR_i2c *ir,
222 u32 *ir_key, u32 *ir_raw) 222 u32 *ir_key, u32 *ir_raw)
223{ 223{
224 unsigned char subaddr, key, keygroup; 224 unsigned char subaddr, key, keygroup;
225 struct i2c_msg msg[] = { { .addr = ir->c.addr, .flags = 0, 225 struct i2c_msg msg[] = { { .addr = ir->c->addr, .flags = 0,
226 .buf = &subaddr, .len = 1}, 226 .buf = &subaddr, .len = 1},
227 { .addr = ir->c.addr, .flags = I2C_M_RD, 227 { .addr = ir->c->addr, .flags = I2C_M_RD,
228 .buf = &key, .len = 1} }; 228 .buf = &key, .len = 1} };
229 subaddr = 0x0d; 229 subaddr = 0x0d;
230 if (2 != i2c_transfer(ir->c.adapter, msg, 2)) { 230 if (2 != i2c_transfer(ir->c->adapter, msg, 2)) {
231 dprintk(1, "read error\n"); 231 dprintk(1, "read error\n");
232 return -EIO; 232 return -EIO;
233 } 233 }
@@ -237,7 +237,7 @@ static int get_key_avermedia_cardbus(struct IR_i2c *ir,
237 237
238 subaddr = 0x0b; 238 subaddr = 0x0b;
239 msg[1].buf = &keygroup; 239 msg[1].buf = &keygroup;
240 if (2 != i2c_transfer(ir->c.adapter, msg, 2)) { 240 if (2 != i2c_transfer(ir->c->adapter, msg, 2)) {
241 dprintk(1, "read error\n"); 241 dprintk(1, "read error\n");
242 return -EIO; 242 return -EIO;
243 } 243 }
@@ -286,7 +286,7 @@ static void ir_work(struct work_struct *work)
286 286
287 /* MSI TV@nywhere Plus requires more frequent polling 287 /* MSI TV@nywhere Plus requires more frequent polling
288 otherwise it will miss some keypresses */ 288 otherwise it will miss some keypresses */
289 if (ir->c.adapter->id == I2C_HW_SAA7134 && ir->c.addr == 0x30) 289 if (ir->c->adapter->id == I2C_HW_SAA7134 && ir->c->addr == 0x30)
290 polling_interval = 50; 290 polling_interval = 50;
291 291
292 ir_key_poll(ir); 292 ir_key_poll(ir);
@@ -295,34 +295,15 @@ static void ir_work(struct work_struct *work)
295 295
296/* ----------------------------------------------------------------------- */ 296/* ----------------------------------------------------------------------- */
297 297
298static int ir_attach(struct i2c_adapter *adap, int addr, 298static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
299 unsigned short flags, int kind);
300static int ir_detach(struct i2c_client *client);
301static int ir_probe(struct i2c_adapter *adap);
302
303static struct i2c_driver driver = {
304 .driver = {
305 .name = "ir-kbd-i2c",
306 },
307 .id = I2C_DRIVERID_INFRARED,
308 .attach_adapter = ir_probe,
309 .detach_client = ir_detach,
310};
311
312static struct i2c_client client_template =
313{
314 .name = "unset",
315 .driver = &driver
316};
317
318static int ir_attach(struct i2c_adapter *adap, int addr,
319 unsigned short flags, int kind)
320{ 299{
321 IR_KEYTAB_TYPE *ir_codes = NULL; 300 IR_KEYTAB_TYPE *ir_codes = NULL;
322 char *name; 301 char *name;
323 int ir_type; 302 int ir_type;
324 struct IR_i2c *ir; 303 struct IR_i2c *ir;
325 struct input_dev *input_dev; 304 struct input_dev *input_dev;
305 struct i2c_adapter *adap = client->adapter;
306 unsigned short addr = client->addr;
326 int err; 307 int err;
327 308
328 ir = kzalloc(sizeof(struct IR_i2c),GFP_KERNEL); 309 ir = kzalloc(sizeof(struct IR_i2c),GFP_KERNEL);
@@ -332,14 +313,9 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
332 goto err_out_free; 313 goto err_out_free;
333 } 314 }
334 315
335 ir->c = client_template; 316 ir->c = client;
336 ir->input = input_dev; 317 ir->input = input_dev;
337 318 i2c_set_clientdata(client, ir);
338 ir->c.adapter = adap;
339 ir->c.addr = addr;
340 snprintf(ir->c.name, sizeof(ir->c.name), "ir-kbd");
341
342 i2c_set_clientdata(&ir->c, ir);
343 319
344 switch(addr) { 320 switch(addr) {
345 case 0x64: 321 case 0x64:
@@ -414,24 +390,9 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
414 snprintf(ir->name, sizeof(ir->name), "i2c IR (%s)", name); 390 snprintf(ir->name, sizeof(ir->name), "i2c IR (%s)", name);
415 ir->ir_codes = ir_codes; 391 ir->ir_codes = ir_codes;
416 392
417 /* register i2c device
418 * At device register, IR codes may be changed to be
419 * board dependent.
420 */
421 err = i2c_attach_client(&ir->c);
422 if (err)
423 goto err_out_free;
424
425 /* If IR not supported or disabled, unregisters driver */
426 if (ir->get_key == NULL) {
427 err = -ENODEV;
428 goto err_out_detach;
429 }
430
431 /* Phys addr can only be set after attaching (for ir->c.dev) */
432 snprintf(ir->phys, sizeof(ir->phys), "%s/%s/ir0", 393 snprintf(ir->phys, sizeof(ir->phys), "%s/%s/ir0",
433 dev_name(&ir->c.adapter->dev), 394 dev_name(&adap->dev),
434 dev_name(&ir->c.dev)); 395 dev_name(&client->dev));
435 396
436 /* init + register input device */ 397 /* init + register input device */
437 ir_input_init(input_dev, &ir->ir, ir_type, ir->ir_codes); 398 ir_input_init(input_dev, &ir->ir, ir_type, ir->ir_codes);
@@ -441,7 +402,7 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
441 402
442 err = input_register_device(ir->input); 403 err = input_register_device(ir->input);
443 if (err) 404 if (err)
444 goto err_out_detach; 405 goto err_out_free;
445 406
446 printk(DEVNAME ": %s detected at %s [%s]\n", 407 printk(DEVNAME ": %s detected at %s [%s]\n",
447 ir->input->name, ir->input->phys, adap->name); 408 ir->input->name, ir->input->phys, adap->name);
@@ -452,135 +413,42 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
452 413
453 return 0; 414 return 0;
454 415
455 err_out_detach:
456 i2c_detach_client(&ir->c);
457 err_out_free: 416 err_out_free:
458 input_free_device(input_dev); 417 input_free_device(input_dev);
459 kfree(ir); 418 kfree(ir);
460 return err; 419 return err;
461} 420}
462 421
463static int ir_detach(struct i2c_client *client) 422static int ir_remove(struct i2c_client *client)
464{ 423{
465 struct IR_i2c *ir = i2c_get_clientdata(client); 424 struct IR_i2c *ir = i2c_get_clientdata(client);
466 425
467 /* kill outstanding polls */ 426 /* kill outstanding polls */
468 cancel_delayed_work_sync(&ir->work); 427 cancel_delayed_work_sync(&ir->work);
469 428
470 /* unregister devices */ 429 /* unregister device */
471 input_unregister_device(ir->input); 430 input_unregister_device(ir->input);
472 i2c_detach_client(&ir->c);
473 431
474 /* free memory */ 432 /* free memory */
475 kfree(ir); 433 kfree(ir);
476 return 0; 434 return 0;
477} 435}
478 436
479static int ir_probe(struct i2c_adapter *adap) 437static const struct i2c_device_id ir_kbd_id[] = {
480{ 438 /* Generic entry for any IR receiver */
481 439 { "ir_video", 0 },
482 /* The external IR receiver is at i2c address 0x34 (0x35 for 440 /* IR device specific entries could be added here */
483 reads). Future Hauppauge cards will have an internal 441 { }
484 receiver at 0x30 (0x31 for reads). In theory, both can be 442};
485 fitted, and Hauppauge suggest an external overrides an
486 internal.
487
488 That's why we probe 0x1a (~0x34) first. CB
489 */
490
491 static const int probe_bttv[] = { 0x1a, 0x18, 0x4b, 0x64, 0x30, -1};
492 static const int probe_saa7134[] = { 0x7a, 0x47, 0x71, 0x2d, -1 };
493 static const int probe_em28XX[] = { 0x30, 0x47, -1 };
494 static const int probe_cx88[] = { 0x18, 0x6b, 0x71, -1 };
495 static const int probe_cx23885[] = { 0x6b, -1 };
496 const int *probe;
497 struct i2c_msg msg = {
498 .flags = I2C_M_RD,
499 .len = 0,
500 .buf = NULL,
501 };
502 int i, rc;
503
504 switch (adap->id) {
505 case I2C_HW_B_BT848:
506 probe = probe_bttv;
507 break;
508 case I2C_HW_B_CX2341X:
509 probe = probe_bttv;
510 break;
511 case I2C_HW_SAA7134:
512 probe = probe_saa7134;
513 break;
514 case I2C_HW_B_EM28XX:
515 probe = probe_em28XX;
516 break;
517 case I2C_HW_B_CX2388x:
518 probe = probe_cx88;
519 break;
520 case I2C_HW_B_CX23885:
521 probe = probe_cx23885;
522 break;
523 default:
524 return 0;
525 }
526
527 for (i = 0; -1 != probe[i]; i++) {
528 msg.addr = probe[i];
529 rc = i2c_transfer(adap, &msg, 1);
530 dprintk(1,"probe 0x%02x @ %s: %s\n",
531 probe[i], adap->name,
532 (1 == rc) ? "yes" : "no");
533 if (1 == rc) {
534 ir_attach(adap, probe[i], 0, 0);
535 return 0;
536 }
537 }
538
539 /* Special case for MSI TV@nywhere Plus remote */
540 if (adap->id == I2C_HW_SAA7134) {
541 u8 temp;
542
543 /* MSI TV@nywhere Plus controller doesn't seem to
544 respond to probes unless we read something from
545 an existing device. Weird... */
546
547 msg.addr = 0x50;
548 rc = i2c_transfer(adap, &msg, 1);
549 dprintk(1, "probe 0x%02x @ %s: %s\n",
550 msg.addr, adap->name,
551 (1 == rc) ? "yes" : "no");
552
553 /* Now do the probe. The controller does not respond
554 to 0-byte reads, so we use a 1-byte read instead. */
555 msg.addr = 0x30;
556 msg.len = 1;
557 msg.buf = &temp;
558 rc = i2c_transfer(adap, &msg, 1);
559 dprintk(1, "probe 0x%02x @ %s: %s\n",
560 msg.addr, adap->name,
561 (1 == rc) ? "yes" : "no");
562 if (1 == rc)
563 ir_attach(adap, msg.addr, 0, 0);
564 }
565
566 /* Special case for AVerMedia Cardbus remote */
567 if (adap->id == I2C_HW_SAA7134) {
568 unsigned char subaddr, data;
569 struct i2c_msg msg[] = { { .addr = 0x40, .flags = 0,
570 .buf = &subaddr, .len = 1},
571 { .addr = 0x40, .flags = I2C_M_RD,
572 .buf = &data, .len = 1} };
573 subaddr = 0x0d;
574 rc = i2c_transfer(adap, msg, 2);
575 dprintk(1, "probe 0x%02x/0x%02x @ %s: %s\n",
576 msg[0].addr, subaddr, adap->name,
577 (2 == rc) ? "yes" : "no");
578 if (2 == rc)
579 ir_attach(adap, msg[0].addr, 0, 0);
580 }
581 443
582 return 0; 444static struct i2c_driver driver = {
583} 445 .driver = {
446 .name = "ir-kbd-i2c",
447 },
448 .probe = ir_probe,
449 .remove = ir_remove,
450 .id_table = ir_kbd_id,
451};
584 452
585/* ----------------------------------------------------------------------- */ 453/* ----------------------------------------------------------------------- */
586 454
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index 9e3d32b8004c..0ecde9ca05c1 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -579,9 +579,11 @@ static struct i2c_client ivtv_i2c_client_template = {
579 .name = "ivtv internal", 579 .name = "ivtv internal",
580}; 580};
581 581
582/* init + register i2c algo-bit adapter */ 582/* init + register i2c adapter + instantiate IR receiver */
583int init_ivtv_i2c(struct ivtv *itv) 583int init_ivtv_i2c(struct ivtv *itv)
584{ 584{
585 int retval;
586
585 IVTV_DEBUG_I2C("i2c init\n"); 587 IVTV_DEBUG_I2C("i2c init\n");
586 588
587 /* Sanity checks for the I2C hardware arrays. They must be the 589 /* Sanity checks for the I2C hardware arrays. They must be the
@@ -619,9 +621,32 @@ int init_ivtv_i2c(struct ivtv *itv)
619 ivtv_setsda(itv, 1); 621 ivtv_setsda(itv, 1);
620 622
621 if (itv->options.newi2c > 0) 623 if (itv->options.newi2c > 0)
622 return i2c_add_adapter(&itv->i2c_adap); 624 retval = i2c_add_adapter(&itv->i2c_adap);
623 else 625 else
624 return i2c_bit_add_bus(&itv->i2c_adap); 626 retval = i2c_bit_add_bus(&itv->i2c_adap);
627
628 /* Instantiate the IR receiver device, if present */
629 if (retval == 0) {
630 struct i2c_board_info info;
631 /* The external IR receiver is at i2c address 0x34 (0x35 for
632 reads). Future Hauppauge cards will have an internal
633 receiver at 0x30 (0x31 for reads). In theory, both can be
634 fitted, and Hauppauge suggest an external overrides an
635 internal.
636
637 That's why we probe 0x1a (~0x34) first. CB
638 */
639 const unsigned short addr_list[] = {
640 0x1a, 0x18, 0x64, 0x30,
641 I2C_CLIENT_END
642 };
643
644 memset(&info, 0, sizeof(struct i2c_board_info));
645 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
646 i2c_new_probed_device(&itv->i2c_adap, &info, addr_list);
647 }
648
649 return retval;
625} 650}
626 651
627void exit_ivtv_i2c(struct ivtv *itv) 652void exit_ivtv_i2c(struct ivtv *itv)
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index f3e285aa2fb4..a96f75985cba 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -433,6 +433,9 @@ int saa7134_i2c_register(struct saa7134_dev *dev)
433 saa7134_i2c_eeprom(dev,dev->eedata,sizeof(dev->eedata)); 433 saa7134_i2c_eeprom(dev,dev->eedata,sizeof(dev->eedata));
434 if (i2c_scan) 434 if (i2c_scan)
435 do_i2c_scan(dev->name,&dev->i2c_client); 435 do_i2c_scan(dev->name,&dev->i2c_client);
436
437 /* Instantiate the IR receiver device, if present */
438 saa7134_probe_i2c_ir(dev);
436 return 0; 439 return 0;
437} 440}
438 441
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index 6cd693d3b8ed..4144ca9cc7e0 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -134,10 +134,10 @@ static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
134 int gpio; 134 int gpio;
135 135
136 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */ 136 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
137 struct saa7134_dev *dev = ir->c.adapter->algo_data; 137 struct saa7134_dev *dev = ir->c->adapter->algo_data;
138 if (dev == NULL) { 138 if (dev == NULL) {
139 dprintk("get_key_msi_tvanywhere_plus: " 139 dprintk("get_key_msi_tvanywhere_plus: "
140 "gir->c.adapter->algo_data is NULL!\n"); 140 "gir->c->adapter->algo_data is NULL!\n");
141 return -EIO; 141 return -EIO;
142 } 142 }
143 143
@@ -156,7 +156,7 @@ static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
156 156
157 /* GPIO says there is a button press. Get it. */ 157 /* GPIO says there is a button press. Get it. */
158 158
159 if (1 != i2c_master_recv(&ir->c, &b, 1)) { 159 if (1 != i2c_master_recv(ir->c, &b, 1)) {
160 i2cdprintk("read error\n"); 160 i2cdprintk("read error\n");
161 return -EIO; 161 return -EIO;
162 } 162 }
@@ -179,7 +179,7 @@ static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
179 unsigned char b; 179 unsigned char b;
180 180
181 /* poll IR chip */ 181 /* poll IR chip */
182 if (1 != i2c_master_recv(&ir->c,&b,1)) { 182 if (1 != i2c_master_recv(ir->c, &b, 1)) {
183 i2cdprintk("read error\n"); 183 i2cdprintk("read error\n");
184 return -EIO; 184 return -EIO;
185 } 185 }
@@ -202,7 +202,7 @@ static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
202 unsigned char buf[5], cod4, code3, code4; 202 unsigned char buf[5], cod4, code3, code4;
203 203
204 /* poll IR chip */ 204 /* poll IR chip */
205 if (5 != i2c_master_recv(&ir->c,buf,5)) 205 if (5 != i2c_master_recv(ir->c, buf, 5))
206 return -EIO; 206 return -EIO;
207 207
208 cod4 = buf[4]; 208 cod4 = buf[4];
@@ -224,7 +224,7 @@ static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
224 unsigned char data[12]; 224 unsigned char data[12];
225 u32 gpio; 225 u32 gpio;
226 226
227 struct saa7134_dev *dev = ir->c.adapter->algo_data; 227 struct saa7134_dev *dev = ir->c->adapter->algo_data;
228 228
229 /* rising SAA7134_GPIO_GPRESCAN reads the status */ 229 /* rising SAA7134_GPIO_GPRESCAN reads the status */
230 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); 230 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
@@ -235,9 +235,9 @@ static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
235 if (0x400000 & ~gpio) 235 if (0x400000 & ~gpio)
236 return 0; /* No button press */ 236 return 0; /* No button press */
237 237
238 ir->c.addr = 0x5a >> 1; 238 ir->c->addr = 0x5a >> 1;
239 239
240 if (12 != i2c_master_recv(&ir->c, data, 12)) { 240 if (12 != i2c_master_recv(ir->c, data, 12)) {
241 i2cdprintk("read error\n"); 241 i2cdprintk("read error\n");
242 return -EIO; 242 return -EIO;
243 } 243 }
@@ -267,7 +267,7 @@ static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
267 unsigned int start = 0,parity = 0,code = 0; 267 unsigned int start = 0,parity = 0,code = 0;
268 268
269 /* poll IR chip */ 269 /* poll IR chip */
270 if (4 != i2c_master_recv(&ir->c, b, 4)) { 270 if (4 != i2c_master_recv(ir->c, b, 4)) {
271 i2cdprintk("read error\n"); 271 i2cdprintk("read error\n");
272 return -EIO; 272 return -EIO;
273 } 273 }
@@ -682,14 +682,76 @@ void saa7134_input_fini(struct saa7134_dev *dev)
682 dev->remote = NULL; 682 dev->remote = NULL;
683} 683}
684 684
685void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir) 685void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
686{ 686{
687 struct i2c_board_info info;
688 const unsigned short addr_list[] = {
689 0x7a, 0x47, 0x71, 0x2d,
690 I2C_CLIENT_END
691 };
692
693 const unsigned short addr_list_msi[] = {
694 0x30, I2C_CLIENT_END
695 };
696 struct i2c_msg msg_msi = {
697 .addr = 0x50,
698 .flags = I2C_M_RD,
699 .len = 0,
700 .buf = NULL,
701 };
702
703 unsigned char subaddr, data;
704 struct i2c_msg msg_avermedia[] = { {
705 .addr = 0x40,
706 .flags = 0,
707 .len = 1,
708 .buf = &subaddr,
709 }, {
710 .addr = 0x40,
711 .flags = I2C_M_RD,
712 .len = 1,
713 .buf = &data,
714 } };
715
716 struct i2c_client *client;
717 int rc;
718
687 if (disable_ir) { 719 if (disable_ir) {
688 dprintk("Found supported i2c remote, but IR has been disabled\n"); 720 dprintk("IR has been disabled, not probing for i2c remote\n");
689 ir->get_key=NULL;
690 return; 721 return;
691 } 722 }
692 723
724 memset(&info, 0, sizeof(struct i2c_board_info));
725 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
726 client = i2c_new_probed_device(&dev->i2c_adap, &info, addr_list);
727 if (client)
728 return;
729
730 /* MSI TV@nywhere Plus controller doesn't seem to
731 respond to probes unless we read something from
732 an existing device. Weird... */
733 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
734 dprintk(KERN_DEBUG "probe 0x%02x @ %s: %s\n",
735 msg_msi.addr, dev->i2c_adap.name,
736 (1 == rc) ? "yes" : "no");
737 client = i2c_new_probed_device(&dev->i2c_adap, &info, addr_list_msi);
738 if (client)
739 return;
740
741 /* Special case for AVerMedia Cardbus remote */
742 subaddr = 0x0d;
743 rc = i2c_transfer(&dev->i2c_adap, msg_avermedia, 2);
744 dprintk(KERN_DEBUG "probe 0x%02x/0x%02x @ %s: %s\n",
745 msg_avermedia[0].addr, subaddr, dev->i2c_adap.name,
746 (2 == rc) ? "yes" : "no");
747 if (2 == rc) {
748 info.addr = msg_avermedia[0].addr;
749 i2c_new_device(&dev->i2c_adap, &info);
750 }
751}
752
753void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
754{
693 switch (dev->board) { 755 switch (dev->board) {
694 case SAA7134_BOARD_PINNACLE_PCTV_110i: 756 case SAA7134_BOARD_PINNACLE_PCTV_110i:
695 case SAA7134_BOARD_PINNACLE_PCTV_310i: 757 case SAA7134_BOARD_PINNACLE_PCTV_310i:
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 8229ab213223..116534ec33eb 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -799,6 +799,7 @@ void saa7134_irq_oss_done(struct saa7134_dev *dev, unsigned long status);
799int saa7134_input_init1(struct saa7134_dev *dev); 799int saa7134_input_init1(struct saa7134_dev *dev);
800void saa7134_input_fini(struct saa7134_dev *dev); 800void saa7134_input_fini(struct saa7134_dev *dev);
801void saa7134_input_irq(struct saa7134_dev *dev); 801void saa7134_input_irq(struct saa7134_dev *dev);
802void saa7134_probe_i2c_ir(struct saa7134_dev *dev);
802void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir); 803void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir);
803void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir); 804void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir);
804void saa7134_ir_stop(struct saa7134_dev *dev); 805void saa7134_ir_stop(struct saa7134_dev *dev);
diff --git a/include/media/ir-kbd-i2c.h b/include/media/ir-kbd-i2c.h
index 6a9719c8e903..94a77b15a30a 100644
--- a/include/media/ir-kbd-i2c.h
+++ b/include/media/ir-kbd-i2c.h
@@ -7,7 +7,7 @@ struct IR_i2c;
7 7
8struct IR_i2c { 8struct IR_i2c {
9 IR_KEYTAB_TYPE *ir_codes; 9 IR_KEYTAB_TYPE *ir_codes;
10 struct i2c_client c; 10 struct i2c_client *c;
11 struct input_dev *input; 11 struct input_dev *input;
12 struct ir_input_state ir; 12 struct ir_input_state ir;
13 13