Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[wrt350n-kernel.git] / drivers / media / video / em28xx / em28xx-cards.c
blobaae7753fef117d1c7b12f0bcc30a83a1f018c19e
1 /*
2 em28xx-cards.c - driver for Empia EM2800/EM2820/2840 USB
3 video capture devices
5 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
6 Markus Rechberger <mrechberger@gmail.com>
7 Mauro Carvalho Chehab <mchehab@infradead.org>
8 Sascha Sommer <saschasommer@freenet.de>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/init.h>
26 #include <linux/module.h>
27 #include <linux/delay.h>
28 #include <linux/i2c.h>
29 #include <linux/usb.h>
30 #include <media/tuner.h>
31 #include <media/msp3400.h>
32 #include <media/saa7115.h>
33 #include <media/tvp5150.h>
34 #include <media/tveeprom.h>
35 #include <media/audiochip.h>
36 #include <media/v4l2-common.h>
38 #include "em28xx.h"
39 #include "tuner-xc2028.h"
41 static int tuner = -1;
42 module_param(tuner, int, 0444);
43 MODULE_PARM_DESC(tuner, "tuner type");
45 static unsigned int disable_ir;
46 module_param(disable_ir, int, 0444);
47 MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
49 struct em28xx_hash_table {
50 unsigned long hash;
51 unsigned int model;
52 unsigned int tuner;
55 /* Boards supported by driver */
57 #define EM2800_BOARD_UNKNOWN 0
58 #define EM2820_BOARD_UNKNOWN 1
59 #define EM2820_BOARD_TERRATEC_CINERGY_250 2
60 #define EM2820_BOARD_PINNACLE_USB_2 3
61 #define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4
62 #define EM2820_BOARD_MSI_VOX_USB_2 5
63 #define EM2800_BOARD_TERRATEC_CINERGY_200 6
64 #define EM2800_BOARD_LEADTEK_WINFAST_USBII 7
65 #define EM2800_BOARD_KWORLD_USB2800 8
66 #define EM2820_BOARD_PINNACLE_DVC_90 9
67 #define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10
68 #define EM2880_BOARD_TERRATEC_HYBRID_XS 11
69 #define EM2820_BOARD_KWORLD_PVRTV2800RF 12
70 #define EM2880_BOARD_TERRATEC_PRODIGY_XS 13
71 #define EM2820_BOARD_PROLINK_PLAYTV_USB2 14
72 #define EM2800_BOARD_VGEAR_POCKETTV 15
73 #define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 16
75 struct em28xx_board em28xx_boards[] = {
76 [EM2800_BOARD_UNKNOWN] = {
77 .name = "Unknown EM2800 video grabber",
78 .is_em2800 = 1,
79 .vchannels = 2,
80 .tda9887_conf = TDA9887_PRESENT,
81 .decoder = EM28XX_SAA7113,
82 .input = { {
83 .type = EM28XX_VMUX_COMPOSITE1,
84 .vmux = SAA7115_COMPOSITE0,
85 .amux = 1,
86 }, {
87 .type = EM28XX_VMUX_SVIDEO,
88 .vmux = SAA7115_SVIDEO3,
89 .amux = 1,
90 } },
92 [EM2820_BOARD_UNKNOWN] = {
93 .name = "Unknown EM2750/28xx video grabber",
94 .is_em2800 = 0,
95 .tuner_type = TUNER_ABSENT,
97 [EM2820_BOARD_KWORLD_PVRTV2800RF] = {
98 .name = "Kworld PVR TV 2800 RF",
99 .is_em2800 = 0,
100 .vchannels = 2,
101 .tuner_type = TUNER_TEMIC_PAL,
102 .tda9887_conf = TDA9887_PRESENT,
103 .decoder = EM28XX_SAA7113,
104 .input = { {
105 .type = EM28XX_VMUX_COMPOSITE1,
106 .vmux = SAA7115_COMPOSITE0,
107 .amux = 1,
108 }, {
109 .type = EM28XX_VMUX_SVIDEO,
110 .vmux = SAA7115_SVIDEO3,
111 .amux = 1,
112 } },
114 [EM2820_BOARD_TERRATEC_CINERGY_250] = {
115 .name = "Terratec Cinergy 250 USB",
116 .vchannels = 3,
117 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
118 .tda9887_conf = TDA9887_PRESENT,
119 .decoder = EM28XX_SAA7113,
120 .input = { {
121 .type = EM28XX_VMUX_TELEVISION,
122 .vmux = SAA7115_COMPOSITE2,
123 .amux = 1,
124 }, {
125 .type = EM28XX_VMUX_COMPOSITE1,
126 .vmux = SAA7115_COMPOSITE0,
127 .amux = 1,
128 }, {
129 .type = EM28XX_VMUX_SVIDEO,
130 .vmux = SAA7115_SVIDEO3,
131 .amux = 1,
132 } },
134 [EM2820_BOARD_PINNACLE_USB_2] = {
135 .name = "Pinnacle PCTV USB 2",
136 .vchannels = 3,
137 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
138 .tda9887_conf = TDA9887_PRESENT,
139 .decoder = EM28XX_SAA7113,
140 .input = { {
141 .type = EM28XX_VMUX_TELEVISION,
142 .vmux = SAA7115_COMPOSITE2,
143 .amux = 0,
144 }, {
145 .type = EM28XX_VMUX_COMPOSITE1,
146 .vmux = SAA7115_COMPOSITE0,
147 .amux = 1,
148 }, {
149 .type = EM28XX_VMUX_SVIDEO,
150 .vmux = SAA7115_SVIDEO3,
151 .amux = 1,
152 } },
154 [EM2820_BOARD_HAUPPAUGE_WINTV_USB_2] = {
155 .name = "Hauppauge WinTV USB 2",
156 .vchannels = 3,
157 .tuner_type = TUNER_PHILIPS_FM1236_MK3,
158 .tda9887_conf = TDA9887_PRESENT |
159 TDA9887_PORT1_ACTIVE|
160 TDA9887_PORT2_ACTIVE,
161 .decoder = EM28XX_TVP5150,
162 .has_msp34xx = 1,
163 /*FIXME: S-Video not tested */
164 .input = { {
165 .type = EM28XX_VMUX_TELEVISION,
166 .vmux = TVP5150_COMPOSITE0,
167 .amux = MSP_INPUT_DEFAULT,
168 }, {
169 .type = EM28XX_VMUX_SVIDEO,
170 .vmux = TVP5150_SVIDEO,
171 .amux = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
172 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART),
173 } },
175 [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900] = {
176 .name = "Hauppauge WinTV HVR 900",
177 .vchannels = 3,
178 .tda9887_conf = TDA9887_PRESENT,
179 .tuner_type = TUNER_XC2028,
180 .mts_firmware = 1,
181 .decoder = EM28XX_TVP5150,
182 .input = { {
183 .type = EM28XX_VMUX_TELEVISION,
184 .vmux = TVP5150_COMPOSITE0,
185 .amux = 0,
186 }, {
187 .type = EM28XX_VMUX_COMPOSITE1,
188 .vmux = TVP5150_COMPOSITE1,
189 .amux = 1,
190 }, {
191 .type = EM28XX_VMUX_SVIDEO,
192 .vmux = TVP5150_SVIDEO,
193 .amux = 1,
194 } },
196 [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950] = {
197 .name = "Hauppauge WinTV HVR 950",
198 .vchannels = 3,
199 .tda9887_conf = TDA9887_PRESENT,
200 .tuner_type = TUNER_XC2028,
201 .mts_firmware = 1,
202 .has_12mhz_i2s = 1,
203 .decoder = EM28XX_TVP5150,
204 .input = { {
205 .type = EM28XX_VMUX_TELEVISION,
206 .vmux = TVP5150_COMPOSITE0,
207 .amux = 0,
208 }, {
209 .type = EM28XX_VMUX_COMPOSITE1,
210 .vmux = TVP5150_COMPOSITE1,
211 .amux = 1,
212 }, {
213 .type = EM28XX_VMUX_SVIDEO,
214 .vmux = TVP5150_SVIDEO,
215 .amux = 1,
216 } },
218 /* gpio's 4, 1, 0 */
219 .analog_gpio = 0x003d2d,
221 [EM2880_BOARD_TERRATEC_HYBRID_XS] = {
222 .name = "Terratec Hybrid XS",
223 .vchannels = 3,
224 .tda9887_conf = TDA9887_PRESENT,
225 .tuner_type = TUNER_XC2028,
226 .decoder = EM28XX_TVP5150,
227 .input = { {
228 .type = EM28XX_VMUX_TELEVISION,
229 .vmux = TVP5150_COMPOSITE0,
230 .amux = 0,
231 }, {
232 .type = EM28XX_VMUX_COMPOSITE1,
233 .vmux = TVP5150_COMPOSITE1,
234 .amux = 1,
235 }, {
236 .type = EM28XX_VMUX_SVIDEO,
237 .vmux = TVP5150_SVIDEO,
238 .amux = 1,
239 } },
241 /* maybe there's a reason behind it why Terratec sells the Hybrid XS
242 as Prodigy XS with a different PID, let's keep it separated for now
243 maybe we'll need it lateron */
244 [EM2880_BOARD_TERRATEC_PRODIGY_XS] = {
245 .name = "Terratec Prodigy XS",
246 .vchannels = 3,
247 .tda9887_conf = TDA9887_PRESENT,
248 .tuner_type = TUNER_XC2028,
249 .decoder = EM28XX_TVP5150,
250 .input = { {
251 .type = EM28XX_VMUX_TELEVISION,
252 .vmux = TVP5150_COMPOSITE0,
253 .amux = 0,
254 }, {
255 .type = EM28XX_VMUX_COMPOSITE1,
256 .vmux = TVP5150_COMPOSITE1,
257 .amux = 1,
258 }, {
259 .type = EM28XX_VMUX_SVIDEO,
260 .vmux = TVP5150_SVIDEO,
261 .amux = 1,
262 } },
264 [EM2820_BOARD_MSI_VOX_USB_2] = {
265 .name = "MSI VOX USB 2.0",
266 .vchannels = 3,
267 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
268 .tda9887_conf = TDA9887_PRESENT |
269 TDA9887_PORT1_ACTIVE |
270 TDA9887_PORT2_ACTIVE,
271 .max_range_640_480 = 1,
273 .decoder = EM28XX_SAA7114,
274 .input = { {
275 .type = EM28XX_VMUX_TELEVISION,
276 .vmux = SAA7115_COMPOSITE4,
277 .amux = 0,
278 }, {
279 .type = EM28XX_VMUX_COMPOSITE1,
280 .vmux = SAA7115_COMPOSITE0,
281 .amux = 1,
282 }, {
283 .type = EM28XX_VMUX_SVIDEO,
284 .vmux = SAA7115_SVIDEO3,
285 .amux = 1,
286 } },
288 [EM2800_BOARD_TERRATEC_CINERGY_200] = {
289 .name = "Terratec Cinergy 200 USB",
290 .is_em2800 = 1,
291 .vchannels = 3,
292 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
293 .tda9887_conf = TDA9887_PRESENT,
294 .decoder = EM28XX_SAA7113,
295 .input = { {
296 .type = EM28XX_VMUX_TELEVISION,
297 .vmux = SAA7115_COMPOSITE2,
298 .amux = 0,
299 }, {
300 .type = EM28XX_VMUX_COMPOSITE1,
301 .vmux = SAA7115_COMPOSITE0,
302 .amux = 1,
303 }, {
304 .type = EM28XX_VMUX_SVIDEO,
305 .vmux = SAA7115_SVIDEO3,
306 .amux = 1,
307 } },
309 [EM2800_BOARD_LEADTEK_WINFAST_USBII] = {
310 .name = "Leadtek Winfast USB II",
311 .is_em2800 = 1,
312 .vchannels = 3,
313 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
314 .tda9887_conf = TDA9887_PRESENT,
315 .decoder = EM28XX_SAA7113,
316 .input = { {
317 .type = EM28XX_VMUX_TELEVISION,
318 .vmux = SAA7115_COMPOSITE2,
319 .amux = 0,
320 }, {
321 .type = EM28XX_VMUX_COMPOSITE1,
322 .vmux = SAA7115_COMPOSITE0,
323 .amux = 1,
324 }, {
325 .type = EM28XX_VMUX_SVIDEO,
326 .vmux = SAA7115_SVIDEO3,
327 .amux = 1,
328 } },
330 [EM2800_BOARD_KWORLD_USB2800] = {
331 .name = "Kworld USB2800",
332 .is_em2800 = 1,
333 .vchannels = 3,
334 .tuner_type = TUNER_PHILIPS_ATSC,
335 .tda9887_conf = TDA9887_PRESENT,
336 .decoder = EM28XX_SAA7113,
337 .input = { {
338 .type = EM28XX_VMUX_TELEVISION,
339 .vmux = SAA7115_COMPOSITE2,
340 .amux = 0,
341 }, {
342 .type = EM28XX_VMUX_COMPOSITE1,
343 .vmux = SAA7115_COMPOSITE0,
344 .amux = 1,
345 }, {
346 .type = EM28XX_VMUX_SVIDEO,
347 .vmux = SAA7115_SVIDEO3,
348 .amux = 1,
349 } },
351 [EM2820_BOARD_PINNACLE_DVC_90] = {
352 .name = "Pinnacle Dazzle DVC 90/DVC 100",
353 .vchannels = 3,
354 .tuner_type = TUNER_ABSENT,
355 .decoder = EM28XX_SAA7113,
356 .input = { {
357 .type = EM28XX_VMUX_COMPOSITE1,
358 .vmux = SAA7115_COMPOSITE0,
359 .amux = 1,
360 }, {
361 .type = EM28XX_VMUX_SVIDEO,
362 .vmux = SAA7115_SVIDEO3,
363 .amux = 1,
364 } },
366 [EM2800_BOARD_VGEAR_POCKETTV] = {
367 .name = "V-Gear PocketTV",
368 .is_em2800 = 1,
369 .vchannels = 3,
370 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
371 .tda9887_conf = TDA9887_PRESENT,
372 .decoder = EM28XX_SAA7113,
373 .input = { {
374 .type = EM28XX_VMUX_TELEVISION,
375 .vmux = SAA7115_COMPOSITE2,
376 .amux = 0,
377 }, {
378 .type = EM28XX_VMUX_COMPOSITE1,
379 .vmux = SAA7115_COMPOSITE0,
380 .amux = 1,
381 }, {
382 .type = EM28XX_VMUX_SVIDEO,
383 .vmux = SAA7115_SVIDEO3,
384 .amux = 1,
385 } },
387 [EM2820_BOARD_PROLINK_PLAYTV_USB2] = {
388 .name = "Pixelview Prolink PlayTV USB 2.0",
389 .vchannels = 3,
390 .tda9887_conf = TDA9887_PRESENT,
391 .tuner_type = TUNER_YMEC_TVF_5533MF,
392 .decoder = EM28XX_SAA7113,
393 .input = { {
394 .type = EM28XX_VMUX_TELEVISION,
395 .vmux = SAA7115_COMPOSITE2,
396 .amux = EM28XX_AMUX_LINE_IN,
397 }, {
398 .type = EM28XX_VMUX_COMPOSITE1,
399 .vmux = SAA7115_COMPOSITE0,
400 .amux = EM28XX_AMUX_LINE_IN,
401 }, {
402 .type = EM28XX_VMUX_SVIDEO,
403 .vmux = SAA7115_SVIDEO3,
404 .amux = EM28XX_AMUX_LINE_IN,
405 } },
408 const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
410 /* table of devices that work with this driver */
411 struct usb_device_id em28xx_id_table [] = {
412 { USB_DEVICE(0xeb1a, 0x2750),
413 .driver_info = EM2820_BOARD_UNKNOWN },
414 { USB_DEVICE(0xeb1a, 0x2800),
415 .driver_info = EM2800_BOARD_UNKNOWN },
416 { USB_DEVICE(0xeb1a, 0x2820),
417 .driver_info = EM2820_BOARD_UNKNOWN },
418 { USB_DEVICE(0xeb1a, 0x2821),
419 .driver_info = EM2820_BOARD_UNKNOWN },
420 { USB_DEVICE(0xeb1a, 0x2860),
421 .driver_info = EM2820_BOARD_UNKNOWN },
422 { USB_DEVICE(0xeb1a, 0x2861),
423 .driver_info = EM2820_BOARD_UNKNOWN },
424 { USB_DEVICE(0xeb1a, 0x2870),
425 .driver_info = EM2820_BOARD_UNKNOWN },
426 { USB_DEVICE(0xeb1a, 0x2881),
427 .driver_info = EM2820_BOARD_UNKNOWN },
428 { USB_DEVICE(0xeb1a, 0x2883),
429 .driver_info = EM2820_BOARD_UNKNOWN },
430 { USB_DEVICE(0x0ccd, 0x0036),
431 .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
432 { USB_DEVICE(0x2304, 0x0208),
433 .driver_info = EM2820_BOARD_PINNACLE_USB_2 },
434 { USB_DEVICE(0x2040, 0x4200),
435 .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
436 { USB_DEVICE(0x2040, 0x4201),
437 .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
438 { USB_DEVICE(0x2304, 0x0207),
439 .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
440 { USB_DEVICE(0x2304, 0x021a),
441 .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
442 { USB_DEVICE(0x2040, 0x6500),
443 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
444 { USB_DEVICE(0x2040, 0x6502),
445 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
446 { USB_DEVICE(0x2040, 0x6513),
447 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 },
448 { USB_DEVICE(0x0ccd, 0x0042),
449 .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS },
450 { USB_DEVICE(0x0ccd, 0x0047),
451 .driver_info = EM2880_BOARD_TERRATEC_PRODIGY_XS },
452 { },
454 MODULE_DEVICE_TABLE(usb, em28xx_id_table);
456 /* EEPROM hash table for devices with generic USB IDs */
457 static struct em28xx_hash_table em28xx_eeprom_hash [] = {
458 /* P/N: SA 60002070465 Tuner: TVF7533-MF */
459 {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF},
462 /* I2C devicelist hash table for devices with generic USB IDs */
463 static struct em28xx_hash_table em28xx_i2c_hash[] = {
464 {0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC},
465 {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC},
468 /* Since em28xx_pre_card_setup() requires a proper dev->model,
469 * this won't work for boards with generic PCI IDs
471 void em28xx_pre_card_setup(struct em28xx *dev)
473 /* request some modules */
474 switch (dev->model) {
475 case EM2880_BOARD_TERRATEC_PRODIGY_XS:
476 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
477 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
478 case EM2880_BOARD_TERRATEC_HYBRID_XS:
479 em28xx_write_regs(dev, XCLK_REG, "\x27", 1);
480 em28xx_write_regs(dev, I2C_CLK_REG, "\x40", 1);
481 em28xx_write_regs(dev, 0x08, "\xff", 1);
482 em28xx_write_regs(dev, 0x04, "\x00", 1);
483 msleep(100);
484 em28xx_write_regs(dev, 0x04, "\x08", 1);
485 msleep(100);
486 em28xx_write_regs(dev, 0x08, "\xff", 1);
487 msleep(50);
488 em28xx_write_regs(dev, 0x08, "\x2d", 1);
489 msleep(50);
490 em28xx_write_regs(dev, 0x08, "\x3d", 1);
491 break;
495 static int em28xx_tuner_callback(void *ptr, int command, int arg)
497 int rc = 0;
498 struct em28xx *dev = ptr;
500 if (dev->tuner_type != TUNER_XC2028)
501 return 0;
503 switch (command) {
504 case XC2028_TUNER_RESET:
506 /* GPIO and initialization codes for analog TV and radio
507 This code should be complemented for DTV, since reset
508 codes are different.
511 dev->em28xx_write_regs_req(dev, 0x00, 0x48, "\x00", 1);
512 dev->em28xx_write_regs_req(dev, 0x00, 0x12, "\x67", 1);
514 if (dev->analog_gpio) {
515 char gpio0 = dev->analog_gpio & 0xff;
516 char gpio1 = (dev->analog_gpio >> 8) & 0xff;
517 char gpio4 = dev->analog_gpio >> 24;
519 if (gpio4) {
520 dev->em28xx_write_regs(dev, 0x04, &gpio4, 1);
521 msleep(140);
524 msleep(6);
525 dev->em28xx_write_regs(dev, 0x08, &gpio0, 1);
526 msleep(10);
527 dev->em28xx_write_regs(dev, 0x08, &gpio1, 1);
528 msleep(5);
531 break;
534 return rc;
537 static void em28xx_config_tuner(struct em28xx *dev)
539 struct v4l2_priv_tun_config xc2028_cfg;
540 struct xc2028_ctrl ctl;
541 struct tuner_setup tun_setup;
542 struct v4l2_frequency f;
544 if (dev->tuner_type == TUNER_ABSENT)
545 return;
547 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
548 tun_setup.type = dev->tuner_type;
549 tun_setup.addr = dev->tuner_addr;
550 tun_setup.tuner_callback = em28xx_tuner_callback;
552 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
554 if (dev->tuner_type == TUNER_XC2028) {
555 memset(&ctl, 0, sizeof(ctl));
557 ctl.fname = XC2028_DEFAULT_FIRMWARE;
558 ctl.max_len = 64;
559 ctl.mts = em28xx_boards[dev->model].mts_firmware;
561 xc2028_cfg.tuner = TUNER_XC2028;
562 xc2028_cfg.priv = &ctl;
564 em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG, &xc2028_cfg);
567 /* configure tuner */
568 f.tuner = 0;
569 f.type = V4L2_TUNER_ANALOG_TV;
570 f.frequency = 9076; /* just a magic number */
571 dev->ctl_freq = f.frequency;
572 em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
575 static int em28xx_hint_board(struct em28xx *dev)
577 int i;
579 /* HINT method: EEPROM
581 * This method works only for boards with eeprom.
582 * Uses a hash of all eeprom bytes. The hash should be
583 * unique for a vendor/tuner pair.
584 * There are a high chance that tuners for different
585 * video standards produce different hashes.
587 for (i = 0; i < ARRAY_SIZE(em28xx_eeprom_hash); i++) {
588 if (dev->hash == em28xx_eeprom_hash[i].hash) {
589 dev->model = em28xx_eeprom_hash[i].model;
590 dev->tuner_type = em28xx_eeprom_hash[i].tuner;
592 em28xx_errdev("Your board has no unique USB ID.\n");
593 em28xx_errdev("A hint were successfully done, "
594 "based on eeprom hash.\n");
595 em28xx_errdev("This method is not 100%% failproof.\n");
596 em28xx_errdev("If the board were missdetected, "
597 "please email this log to:\n");
598 em28xx_errdev("\tV4L Mailing List "
599 " <video4linux-list@redhat.com>\n");
600 em28xx_errdev("Board detected as %s\n",
601 em28xx_boards[dev->model].name);
603 return 0;
607 /* HINT method: I2C attached devices
609 * This method works for all boards.
610 * Uses a hash of i2c scanned devices.
611 * Devices with the same i2c attached chips will
612 * be considered equal.
613 * This method is less precise than the eeprom one.
616 /* user did not request i2c scanning => do it now */
617 if (!dev->i2c_hash)
618 em28xx_do_i2c_scan(dev);
620 for (i = 0; i < ARRAY_SIZE(em28xx_i2c_hash); i++) {
621 if (dev->i2c_hash == em28xx_i2c_hash[i].hash) {
622 dev->model = em28xx_i2c_hash[i].model;
623 dev->tuner_type = em28xx_i2c_hash[i].tuner;
624 em28xx_errdev("Your board has no unique USB ID.\n");
625 em28xx_errdev("A hint were successfully done, "
626 "based on i2c devicelist hash.\n");
627 em28xx_errdev("This method is not 100%% failproof.\n");
628 em28xx_errdev("If the board were missdetected, "
629 "please email this log to:\n");
630 em28xx_errdev("\tV4L Mailing List "
631 " <video4linux-list@redhat.com>\n");
632 em28xx_errdev("Board detected as %s\n",
633 em28xx_boards[dev->model].name);
635 return 0;
639 em28xx_errdev("Your board has no unique USB ID and thus need a "
640 "hint to be detected.\n");
641 em28xx_errdev("You may try to use card=<n> insmod option to "
642 "workaround that.\n");
643 em28xx_errdev("Please send an email with this log to:\n");
644 em28xx_errdev("\tV4L Mailing List <video4linux-list@redhat.com>\n");
645 em28xx_errdev("Board eeprom hash is 0x%08lx\n", dev->hash);
646 em28xx_errdev("Board i2c devicelist hash is 0x%08lx\n", dev->i2c_hash);
648 em28xx_errdev("Here is a list of valid choices for the card=<n>"
649 " insmod option:\n");
650 for (i = 0; i < em28xx_bcount; i++) {
651 em28xx_errdev(" card=%d -> %s\n",
652 i, em28xx_boards[i].name);
654 return -1;
658 static void em28xx_set_model(struct em28xx *dev)
660 dev->is_em2800 = em28xx_boards[dev->model].is_em2800;
661 dev->has_msp34xx = em28xx_boards[dev->model].has_msp34xx;
662 dev->tda9887_conf = em28xx_boards[dev->model].tda9887_conf;
663 dev->decoder = em28xx_boards[dev->model].decoder;
664 dev->video_inputs = em28xx_boards[dev->model].vchannels;
665 dev->analog_gpio = em28xx_boards[dev->model].analog_gpio;
666 dev->has_12mhz_i2s = em28xx_boards[dev->model].has_12mhz_i2s;
667 dev->max_range_640_480 = em28xx_boards[dev->model].max_range_640_480;
670 /* ----------------------------------------------------------------------- */
671 void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir)
673 if (disable_ir) {
674 ir->get_key = NULL;
675 return ;
678 /* detect & configure */
679 switch (dev->model) {
680 case (EM2800_BOARD_UNKNOWN):
681 break;
682 case (EM2820_BOARD_UNKNOWN):
683 break;
684 case (EM2800_BOARD_TERRATEC_CINERGY_200):
685 case (EM2820_BOARD_TERRATEC_CINERGY_250):
686 ir->ir_codes = ir_codes_em_terratec;
687 ir->get_key = em28xx_get_key_terratec;
688 snprintf(ir->c.name, sizeof(ir->c.name),
689 "i2c IR (EM28XX Terratec)");
690 break;
691 case (EM2820_BOARD_PINNACLE_USB_2):
692 ir->ir_codes = ir_codes_pinnacle_grey;
693 ir->get_key = em28xx_get_key_pinnacle_usb_grey;
694 snprintf(ir->c.name, sizeof(ir->c.name),
695 "i2c IR (EM28XX Pinnacle PCTV)");
696 break;
697 case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
698 ir->ir_codes = ir_codes_hauppauge_new;
699 ir->get_key = em28xx_get_key_em_haup;
700 snprintf(ir->c.name, sizeof(ir->c.name),
701 "i2c IR (EM2840 Hauppauge)");
702 break;
703 case (EM2820_BOARD_MSI_VOX_USB_2):
704 break;
705 case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
706 break;
707 case (EM2800_BOARD_KWORLD_USB2800):
708 break;
712 void em28xx_card_setup(struct em28xx *dev)
714 em28xx_set_model(dev);
716 dev->tuner_type = em28xx_boards[dev->model].tuner_type;
718 /* request some modules */
719 switch (dev->model) {
720 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
721 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
722 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
724 struct tveeprom tv;
725 #ifdef CONFIG_MODULES
726 request_module("tveeprom");
727 #endif
728 /* Call first TVeeprom */
730 dev->i2c_client.addr = 0xa0 >> 1;
731 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata);
733 dev->tuner_type = tv.tuner_type;
735 if (tv.audio_processor == AUDIO_CHIP_MSP34XX) {
736 dev->i2s_speed = 2048000;
737 dev->has_msp34xx = 1;
739 #ifdef CONFIG_MODULES
740 if (tv.has_ir)
741 request_module("ir-kbd-i2c");
742 #endif
743 break;
745 case EM2820_BOARD_KWORLD_PVRTV2800RF:
746 /* GPIO enables sound on KWORLD PVR TV 2800RF */
747 em28xx_write_regs_req(dev, 0x00, 0x08, "\xf9", 1);
748 break;
749 case EM2820_BOARD_UNKNOWN:
750 case EM2800_BOARD_UNKNOWN:
751 if (!em28xx_hint_board(dev))
752 em28xx_set_model(dev);
755 /* Allow override tuner type by a module parameter */
756 if (tuner >= 0)
757 dev->tuner_type = tuner;
759 #ifdef CONFIG_MODULES
760 /* request some modules */
761 if (dev->has_msp34xx)
762 request_module("msp3400");
763 if (dev->decoder == EM28XX_SAA7113 || dev->decoder == EM28XX_SAA7114)
764 request_module("saa7115");
765 if (dev->decoder == EM28XX_TVP5150)
766 request_module("tvp5150");
767 if (dev->tuner_type != TUNER_ABSENT)
768 request_module("tuner");
769 #endif
771 em28xx_config_tuner(dev);