2 em28xx-cards.c - driver for Empia EM2800/EM2820/2840 USB video capture devices
4 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
5 Markus Rechberger <mrechberger@gmail.com>
6 Mauro Carvalho Chehab <mchehab@infradead.org>
7 Sascha Sommer <saschasommer@freenet.de>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/init.h>
25 #include <linux/module.h>
26 #include <linux/delay.h>
27 #include <linux/i2c.h>
28 #include <linux/usb.h>
29 #include <media/tuner.h>
30 #include <media/msp3400.h>
31 #include <media/saa7115.h>
32 #include <media/tvp5150.h>
33 #include <media/tveeprom.h>
34 #include <media/audiochip.h>
35 #include <media/v4l2-common.h>
38 #include "tuner-xc2028.h"
40 static int tuner
= -1;
41 module_param(tuner
, int, 0444);
42 MODULE_PARM_DESC(tuner
, "tuner type");
44 struct em28xx_hash_table
{
50 struct em28xx_board em28xx_boards
[] = {
51 [EM2800_BOARD_UNKNOWN
] = {
52 .name
= "Unknown EM2800 video grabber",
55 .norm
= VIDEO_MODE_PAL
,
56 .tda9887_conf
= TDA9887_PRESENT
,
58 .decoder
= EM28XX_SAA7113
,
60 .type
= EM28XX_VMUX_COMPOSITE1
,
61 .vmux
= SAA7115_COMPOSITE0
,
64 .type
= EM28XX_VMUX_SVIDEO
,
65 .vmux
= SAA7115_SVIDEO3
,
69 [EM2820_BOARD_UNKNOWN
] = {
70 .name
= "Unknown EM2750/28xx video grabber",
73 [EM2820_BOARD_KWORLD_PVRTV2800RF
] = {
74 .name
= "Kworld PVR TV 2800 RF",
77 .norm
= VIDEO_MODE_PAL
,
78 .tda9887_conf
= TDA9887_PRESENT
,
80 .decoder
= EM28XX_SAA7113
,
82 .type
= EM28XX_VMUX_COMPOSITE1
,
83 .vmux
= SAA7115_COMPOSITE0
,
86 .type
= EM28XX_VMUX_SVIDEO
,
87 .vmux
= SAA7115_SVIDEO3
,
91 [EM2820_BOARD_TERRATEC_CINERGY_250
] = {
92 .name
= "Terratec Cinergy 250 USB",
94 .norm
= VIDEO_MODE_PAL
,
95 .tuner_type
= TUNER_LG_PAL_NEW_TAPC
,
96 .tda9887_conf
= TDA9887_PRESENT
,
98 .decoder
= EM28XX_SAA7113
,
100 .type
= EM28XX_VMUX_TELEVISION
,
101 .vmux
= SAA7115_COMPOSITE2
,
104 .type
= EM28XX_VMUX_COMPOSITE1
,
105 .vmux
= SAA7115_COMPOSITE0
,
108 .type
= EM28XX_VMUX_SVIDEO
,
109 .vmux
= SAA7115_SVIDEO3
,
113 [EM2820_BOARD_PINNACLE_USB_2
] = {
114 .name
= "Pinnacle PCTV USB 2",
116 .norm
= VIDEO_MODE_PAL
,
117 .tuner_type
= TUNER_LG_PAL_NEW_TAPC
,
118 .tda9887_conf
= TDA9887_PRESENT
,
120 .decoder
= EM28XX_SAA7113
,
122 .type
= EM28XX_VMUX_TELEVISION
,
123 .vmux
= SAA7115_COMPOSITE2
,
126 .type
= EM28XX_VMUX_COMPOSITE1
,
127 .vmux
= SAA7115_COMPOSITE0
,
130 .type
= EM28XX_VMUX_SVIDEO
,
131 .vmux
= SAA7115_SVIDEO3
,
135 [EM2820_BOARD_HAUPPAUGE_WINTV_USB_2
] = {
136 .name
= "Hauppauge WinTV USB 2",
138 .norm
= VIDEO_MODE_NTSC
,
139 .tuner_type
= TUNER_PHILIPS_FM1236_MK3
,
140 .tda9887_conf
= TDA9887_PRESENT
|TDA9887_PORT1_ACTIVE
|TDA9887_PORT2_ACTIVE
,
142 .decoder
= EM28XX_TVP5150
,
144 /*FIXME: S-Video not tested */
146 .type
= EM28XX_VMUX_TELEVISION
,
147 .vmux
= TVP5150_COMPOSITE0
,
148 .amux
= MSP_INPUT_DEFAULT
,
150 .type
= EM28XX_VMUX_SVIDEO
,
151 .vmux
= TVP5150_SVIDEO
,
152 .amux
= MSP_INPUT(MSP_IN_SCART1
, MSP_IN_TUNER1
,
153 MSP_DSP_IN_SCART
, MSP_DSP_IN_SCART
),
156 [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900
] = {
157 .name
= "Hauppauge WinTV HVR 900/950",
159 .norm
= VIDEO_MODE_PAL
,
160 .tda9887_conf
= TDA9887_PRESENT
,
161 .tuner_type
= TUNER_XC2028
,
163 .decoder
= EM28XX_TVP5150
,
165 .type
= EM28XX_VMUX_TELEVISION
,
166 .vmux
= TVP5150_COMPOSITE0
,
169 .type
= EM28XX_VMUX_COMPOSITE1
,
170 .vmux
= TVP5150_COMPOSITE1
,
173 .type
= EM28XX_VMUX_SVIDEO
,
174 .vmux
= TVP5150_SVIDEO
,
178 [EM2880_BOARD_TERRATEC_HYBRID_XS
] = {
179 .name
= "Terratec Hybrid XS",
181 .norm
= VIDEO_MODE_PAL
,
182 .tda9887_conf
= TDA9887_PRESENT
,
184 .tuner_type
= TUNER_XC2028
,
185 .decoder
= EM28XX_TVP5150
,
187 .type
= EM28XX_VMUX_TELEVISION
,
188 .vmux
= TVP5150_COMPOSITE0
,
191 .type
= EM28XX_VMUX_COMPOSITE1
,
192 .vmux
= TVP5150_COMPOSITE1
,
195 .type
= EM28XX_VMUX_SVIDEO
,
196 .vmux
= TVP5150_SVIDEO
,
200 /* maybe there's a reason behind it why Terratec sells the Hybrid XS as Prodigy XS with a
201 * different PID, let's keep it separated for now maybe we'll need it lateron */
202 [EM2880_BOARD_TERRATEC_PRODIGY_XS
] = {
203 .name
= "Terratec Prodigy XS",
205 .norm
= VIDEO_MODE_PAL
,
206 .tda9887_conf
= TDA9887_PRESENT
,
208 .tuner_type
= TUNER_XC2028
,
209 .decoder
= EM28XX_TVP5150
,
211 .type
= EM28XX_VMUX_TELEVISION
,
212 .vmux
= TVP5150_COMPOSITE0
,
215 .type
= EM28XX_VMUX_COMPOSITE1
,
216 .vmux
= TVP5150_COMPOSITE1
,
219 .type
= EM28XX_VMUX_SVIDEO
,
220 .vmux
= TVP5150_SVIDEO
,
224 [EM2820_BOARD_MSI_VOX_USB_2
] = {
225 .name
= "MSI VOX USB 2.0",
227 .norm
= VIDEO_MODE_PAL
,
228 .tuner_type
= TUNER_LG_PAL_NEW_TAPC
,
229 .tda9887_conf
= TDA9887_PRESENT
|TDA9887_PORT1_ACTIVE
|TDA9887_PORT2_ACTIVE
,
231 .decoder
= EM28XX_SAA7114
,
233 .type
= EM28XX_VMUX_TELEVISION
,
234 .vmux
= SAA7115_COMPOSITE4
,
237 .type
= EM28XX_VMUX_COMPOSITE1
,
238 .vmux
= SAA7115_COMPOSITE0
,
241 .type
= EM28XX_VMUX_SVIDEO
,
242 .vmux
= SAA7115_SVIDEO3
,
246 [EM2800_BOARD_TERRATEC_CINERGY_200
] = {
247 .name
= "Terratec Cinergy 200 USB",
250 .norm
= VIDEO_MODE_PAL
,
251 .tuner_type
= TUNER_LG_PAL_NEW_TAPC
,
252 .tda9887_conf
= TDA9887_PRESENT
,
254 .decoder
= EM28XX_SAA7113
,
256 .type
= EM28XX_VMUX_TELEVISION
,
257 .vmux
= SAA7115_COMPOSITE2
,
260 .type
= EM28XX_VMUX_COMPOSITE1
,
261 .vmux
= SAA7115_COMPOSITE0
,
264 .type
= EM28XX_VMUX_SVIDEO
,
265 .vmux
= SAA7115_SVIDEO3
,
269 [EM2800_BOARD_LEADTEK_WINFAST_USBII
] = {
270 .name
= "Leadtek Winfast USB II",
273 .norm
= VIDEO_MODE_PAL
,
274 .tuner_type
= TUNER_LG_PAL_NEW_TAPC
,
275 .tda9887_conf
= TDA9887_PRESENT
,
277 .decoder
= EM28XX_SAA7113
,
279 .type
= EM28XX_VMUX_TELEVISION
,
280 .vmux
= SAA7115_COMPOSITE2
,
283 .type
= EM28XX_VMUX_COMPOSITE1
,
284 .vmux
= SAA7115_COMPOSITE0
,
287 .type
= EM28XX_VMUX_SVIDEO
,
288 .vmux
= SAA7115_SVIDEO3
,
292 [EM2800_BOARD_KWORLD_USB2800
] = {
293 .name
= "Kworld USB2800",
296 .norm
= VIDEO_MODE_PAL
,
297 .tuner_type
= TUNER_PHILIPS_ATSC
,
298 .tda9887_conf
= TDA9887_PRESENT
,
300 .decoder
= EM28XX_SAA7113
,
302 .type
= EM28XX_VMUX_TELEVISION
,
303 .vmux
= SAA7115_COMPOSITE2
,
306 .type
= EM28XX_VMUX_COMPOSITE1
,
307 .vmux
= SAA7115_COMPOSITE0
,
310 .type
= EM28XX_VMUX_SVIDEO
,
311 .vmux
= SAA7115_SVIDEO3
,
315 [EM2820_BOARD_PINNACLE_DVC_90
] = {
316 .name
= "Pinnacle Dazzle DVC 90",
318 .norm
= VIDEO_MODE_PAL
,
320 .decoder
= EM28XX_SAA7113
,
322 .type
= EM28XX_VMUX_COMPOSITE1
,
323 .vmux
= SAA7115_COMPOSITE0
,
326 .type
= EM28XX_VMUX_SVIDEO
,
327 .vmux
= SAA7115_SVIDEO3
,
331 [EM2800_BOARD_VGEAR_POCKETTV
] = {
332 .name
= "V-Gear PocketTV",
335 .norm
= VIDEO_MODE_PAL
,
336 .tuner_type
= TUNER_LG_PAL_NEW_TAPC
,
337 .tda9887_conf
= TDA9887_PRESENT
,
339 .decoder
= EM28XX_SAA7113
,
341 .type
= EM28XX_VMUX_TELEVISION
,
342 .vmux
= SAA7115_COMPOSITE2
,
345 .type
= EM28XX_VMUX_COMPOSITE1
,
346 .vmux
= SAA7115_COMPOSITE0
,
349 .type
= EM28XX_VMUX_SVIDEO
,
350 .vmux
= SAA7115_SVIDEO3
,
354 [EM2820_BOARD_PROLINK_PLAYTV_USB2
] = {
355 .name
= "Pixelview Prolink PlayTV USB 2.0",
357 .tda9887_conf
= TDA9887_PRESENT
,
359 .decoder
= EM28XX_SAA7113
,
361 .type
= EM28XX_VMUX_TELEVISION
,
362 .vmux
= SAA7115_COMPOSITE2
,
365 .type
= EM28XX_VMUX_COMPOSITE1
,
366 .vmux
= SAA7115_COMPOSITE0
,
369 .type
= EM28XX_VMUX_SVIDEO
,
370 .vmux
= SAA7115_SVIDEO3
,
375 const unsigned int em28xx_bcount
= ARRAY_SIZE(em28xx_boards
);
377 /* table of devices that work with this driver */
378 struct usb_device_id em28xx_id_table
[] = {
379 { USB_DEVICE(0xeb1a, 0x2750), .driver_info
= EM2820_BOARD_UNKNOWN
},
380 { USB_DEVICE(0xeb1a, 0x2800), .driver_info
= EM2800_BOARD_UNKNOWN
},
381 { USB_DEVICE(0xeb1a, 0x2820), .driver_info
= EM2820_BOARD_UNKNOWN
},
382 { USB_DEVICE(0xeb1a, 0x2821), .driver_info
= EM2820_BOARD_UNKNOWN
},
383 { USB_DEVICE(0xeb1a, 0x2860), .driver_info
= EM2820_BOARD_UNKNOWN
},
384 { USB_DEVICE(0xeb1a, 0x2861), .driver_info
= EM2820_BOARD_UNKNOWN
},
385 { USB_DEVICE(0xeb1a, 0x2870), .driver_info
= EM2820_BOARD_UNKNOWN
},
386 { USB_DEVICE(0xeb1a, 0x2881), .driver_info
= EM2820_BOARD_UNKNOWN
},
387 { USB_DEVICE(0xeb1a, 0x2883), .driver_info
= EM2820_BOARD_UNKNOWN
},
388 { USB_DEVICE(0x0ccd, 0x0036), .driver_info
= EM2820_BOARD_TERRATEC_CINERGY_250
},
389 { USB_DEVICE(0x2304, 0x0208), .driver_info
= EM2820_BOARD_PINNACLE_USB_2
},
390 { USB_DEVICE(0x2040, 0x4200), .driver_info
= EM2820_BOARD_HAUPPAUGE_WINTV_USB_2
},
391 { USB_DEVICE(0x2304, 0x0207), .driver_info
= EM2820_BOARD_PINNACLE_DVC_90
},
392 { USB_DEVICE(0x2040, 0x6500), .driver_info
= EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900
},
393 { USB_DEVICE(0x2040, 0x6513), .driver_info
= EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900
},
394 { USB_DEVICE(0x0ccd, 0x0042), .driver_info
= EM2880_BOARD_TERRATEC_HYBRID_XS
},
395 { USB_DEVICE(0x0ccd, 0x0047), .driver_info
= EM2880_BOARD_TERRATEC_PRODIGY_XS
},
398 MODULE_DEVICE_TABLE (usb
, em28xx_id_table
);
400 /* EEPROM hash table for devices with generic USB IDs */
401 static struct em28xx_hash_table em28xx_eeprom_hash
[] = {
402 /* P/N: SA 60002070465 Tuner: TVF7533-MF */
403 { 0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2
, TUNER_YMEC_TVF_5533MF
},
406 /* I2C devicelist hash table for devices with generic USB IDs */
407 static struct em28xx_hash_table em28xx_i2c_hash
[] = {
408 { 0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200
, TUNER_LG_PAL_NEW_TAPC
},
409 { 0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV
, TUNER_LG_PAL_NEW_TAPC
},
412 /* Since em28xx_pre_card_setup() requires a proper dev->model,
413 * this won't work for boards with generic PCI IDs
415 void em28xx_pre_card_setup(struct em28xx
*dev
)
417 /* request some modules */
419 case EM2880_BOARD_TERRATEC_PRODIGY_XS
:
420 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900
:
421 case EM2880_BOARD_TERRATEC_HYBRID_XS
:
422 /* reset through GPIO? */
423 em28xx_write_regs_req(dev
, 0x00, 0x08, "\x7d", 1);
428 static int em28xx_tuner_callback(void *ptr
, int command
, int arg
)
431 struct em28xx
*dev
= ptr
;
433 if (dev
->tuner_type
!= TUNER_XC2028
)
437 case XC2028_TUNER_RESET
:
438 /* FIXME: This is device-dependent */
439 dev
->em28xx_write_regs_req(dev
, 0x00, 0x48, "\x00", 1);
440 dev
->em28xx_write_regs_req(dev
, 0x00, 0x12, "\x67", 1);
448 static void em28xx_config_tuner (struct em28xx
*dev
)
450 struct v4l2_priv_tun_config xc2028_cfg
;
451 struct xc2028_ctrl ctl
;
452 struct tuner_setup tun_setup
;
453 struct v4l2_frequency f
;
458 tun_setup
.mode_mask
= T_ANALOG_TV
| T_RADIO
;
459 tun_setup
.type
= dev
->tuner_type
;
460 tun_setup
.addr
= dev
->tuner_addr
;
461 tun_setup
.tuner_callback
= em28xx_tuner_callback
;
463 em28xx_i2c_call_clients(dev
, TUNER_SET_TYPE_ADDR
, &tun_setup
);
465 if (dev
->tuner_type
== TUNER_XC2028
) {
466 memset (&ctl
, 0, sizeof(ctl
));
468 ctl
.fname
= XC2028_DEFAULT_FIRMWARE
;
471 xc2028_cfg
.tuner
= TUNER_XC2028
;
472 xc2028_cfg
.priv
= &ctl
;
474 em28xx_i2c_call_clients(dev
, TUNER_SET_CONFIG
, &xc2028_cfg
);
477 /* configure tuner */
479 f
.type
= V4L2_TUNER_ANALOG_TV
;
480 f
.frequency
= 9076; /* just a magic number */
481 dev
->ctl_freq
= f
.frequency
;
482 em28xx_i2c_call_clients(dev
, VIDIOC_S_FREQUENCY
, &f
);
485 static int em28xx_hint_board(struct em28xx
*dev
)
489 /* HINT method: EEPROM
491 * This method works only for boards with eeprom.
492 * Uses a hash of all eeprom bytes. The hash should be
493 * unique for a vendor/tuner pair.
494 * There are a high chance that tuners for different
495 * video standards produce different hashes.
497 for (i
= 0; i
< ARRAY_SIZE(em28xx_eeprom_hash
); i
++) {
498 if (dev
->hash
== em28xx_eeprom_hash
[i
].hash
) {
499 dev
->model
= em28xx_eeprom_hash
[i
].model
;
500 dev
->tuner_type
= em28xx_eeprom_hash
[i
].tuner
;
502 em28xx_errdev("Your board has no unique USB ID.\n");
503 em28xx_errdev("A hint were successfully done, "
504 "based on eeprom hash.\n");
505 em28xx_errdev("This method is not 100%% failproof.\n");
506 em28xx_errdev("If the board were missdetected, "
507 "please email this log to:\n");
508 em28xx_errdev("\tV4L Mailing List "
509 " <video4linux-list@redhat.com>\n");
510 em28xx_errdev("Board detected as %s\n",
511 em28xx_boards
[dev
->model
].name
);
517 /* HINT method: I2C attached devices
519 * This method works for all boards.
520 * Uses a hash of i2c scanned devices.
521 * Devices with the same i2c attached chips will
522 * be considered equal.
523 * This method is less precise than the eeprom one.
526 /* user did not request i2c scanning => do it now */
528 em28xx_do_i2c_scan(dev
);
530 for (i
= 0; i
< ARRAY_SIZE(em28xx_i2c_hash
); i
++) {
531 if (dev
->i2c_hash
== em28xx_i2c_hash
[i
].hash
) {
532 dev
->model
= em28xx_i2c_hash
[i
].model
;
533 dev
->tuner_type
= em28xx_i2c_hash
[i
].tuner
;
534 em28xx_errdev("Your board has no unique USB ID.\n");
535 em28xx_errdev("A hint were successfully done, "
536 "based on i2c devicelist hash.\n");
537 em28xx_errdev("This method is not 100%% failproof.\n");
538 em28xx_errdev("If the board were missdetected, "
539 "please email this log to:\n");
540 em28xx_errdev("\tV4L Mailing List "
541 " <video4linux-list@redhat.com>\n");
542 em28xx_errdev("Board detected as %s\n",
543 em28xx_boards
[dev
->model
].name
);
549 em28xx_errdev("Your board has no unique USB ID and thus need a "
550 "hint to be detected.\n");
551 em28xx_errdev("You may try to use card=<n> insmod option to "
552 "workaround that.\n");
553 em28xx_errdev("Please send an email with this log to:\n");
554 em28xx_errdev("\tV4L Mailing List <video4linux-list@redhat.com>\n");
555 em28xx_errdev("Board eeprom hash is 0x%08lx\n", dev
->hash
);
556 em28xx_errdev("Board i2c devicelist hash is 0x%08lx\n", dev
->i2c_hash
);
558 em28xx_errdev("Here is a list of valid choices for the card=<n>"
559 " insmod option:\n");
560 for (i
= 0; i
< em28xx_bcount
; i
++) {
561 em28xx_errdev(" card=%d -> %s\n",
562 i
, em28xx_boards
[i
].name
);
568 static void em28xx_set_model(struct em28xx
*dev
)
570 dev
->is_em2800
= em28xx_boards
[dev
->model
].is_em2800
;
571 dev
->has_tuner
= em28xx_boards
[dev
->model
].has_tuner
;
572 dev
->has_msp34xx
= em28xx_boards
[dev
->model
].has_msp34xx
;
573 dev
->tda9887_conf
= em28xx_boards
[dev
->model
].tda9887_conf
;
574 dev
->decoder
= em28xx_boards
[dev
->model
].decoder
;
575 dev
->video_inputs
= em28xx_boards
[dev
->model
].vchannels
;
577 if (!em28xx_boards
[dev
->model
].has_tuner
)
578 dev
->tuner_type
= UNSET
;
581 void em28xx_card_setup(struct em28xx
*dev
)
583 em28xx_set_model(dev
);
585 dev
->tuner_type
= em28xx_boards
[dev
->model
].tuner_type
;
587 /* request some modules */
588 switch (dev
->model
) {
589 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2
:
592 #ifdef CONFIG_MODULES
593 request_module("tveeprom");
594 request_module("ir-kbd-i2c");
596 /* Call first TVeeprom */
598 dev
->i2c_client
.addr
= 0xa0 >> 1;
599 tveeprom_hauppauge_analog(&dev
->i2c_client
, &tv
, dev
->eedata
);
601 dev
->tuner_type
= tv
.tuner_type
;
602 if (tv
.audio_processor
== AUDIO_CHIP_MSP34XX
) {
603 dev
->i2s_speed
= 2048000;
604 dev
->has_msp34xx
= 1;
608 case EM2820_BOARD_KWORLD_PVRTV2800RF
:
609 /* GPIO enables sound on KWORLD PVR TV 2800RF */
610 em28xx_write_regs_req(dev
, 0x00, 0x08, "\xf9", 1);
612 case EM2820_BOARD_UNKNOWN
:
613 case EM2800_BOARD_UNKNOWN
:
614 if (!em28xx_hint_board(dev
))
615 em28xx_set_model(dev
);
618 /* Allow override tuner type by a module parameter */
620 dev
->tuner_type
= tuner
;
622 #ifdef CONFIG_MODULES
623 /* request some modules */
624 if (dev
->has_msp34xx
)
625 request_module("msp3400");
626 if (dev
->decoder
== EM28XX_SAA7113
|| dev
->decoder
== EM28XX_SAA7114
)
627 request_module("saa7115");
628 if (dev
->decoder
== EM28XX_TVP5150
)
629 request_module("tvp5150");
631 request_module("tuner");
634 em28xx_config_tuner (dev
);