Merge branch 'for-linus' of git://linux-nfs.org/~bfields/linux
[linux-2.6] / drivers / media / video / em28xx / em28xx-cards.c
1 /*
2    em28xx-cards.c - driver for Empia EM2800/EM2820/2840 USB
3                     video capture devices
4
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>
9
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.
14
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.
19
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.
23  */
24
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>
37
38 #include "em28xx.h"
39
40 static int tuner = -1;
41 module_param(tuner, int, 0444);
42 MODULE_PARM_DESC(tuner, "tuner type");
43
44 static unsigned int disable_ir;
45 module_param(disable_ir, int, 0444);
46 MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
47
48 struct em28xx_hash_table {
49         unsigned long hash;
50         unsigned int  model;
51         unsigned int  tuner;
52 };
53
54 struct em28xx_board em28xx_boards[] = {
55         [EM2800_BOARD_UNKNOWN] = {
56                 .name         = "Unknown EM2800 video grabber",
57                 .is_em2800    = 1,
58                 .vchannels    = 2,
59                 .tda9887_conf = TDA9887_PRESENT,
60                 .decoder      = EM28XX_SAA7113,
61                 .input           = { {
62                         .type     = EM28XX_VMUX_COMPOSITE1,
63                         .vmux     = SAA7115_COMPOSITE0,
64                         .amux     = 1,
65                 }, {
66                         .type     = EM28XX_VMUX_SVIDEO,
67                         .vmux     = SAA7115_SVIDEO3,
68                         .amux     = 1,
69                 } },
70         },
71         [EM2820_BOARD_UNKNOWN] = {
72                 .name         = "Unknown EM2750/28xx video grabber",
73                 .is_em2800    = 0,
74                 .tuner_type   = TUNER_ABSENT,
75         },
76         [EM2820_BOARD_KWORLD_PVRTV2800RF] = {
77                 .name         = "Kworld PVR TV 2800 RF",
78                 .is_em2800    = 0,
79                 .vchannels    = 2,
80                 .tuner_type   = TUNER_TEMIC_PAL,
81                 .tda9887_conf = TDA9887_PRESENT,
82                 .decoder      = EM28XX_SAA7113,
83                 .input           = { {
84                         .type     = EM28XX_VMUX_COMPOSITE1,
85                         .vmux     = SAA7115_COMPOSITE0,
86                         .amux     = 1,
87                 }, {
88                         .type     = EM28XX_VMUX_SVIDEO,
89                         .vmux     = SAA7115_SVIDEO3,
90                         .amux     = 1,
91                 } },
92         },
93         [EM2820_BOARD_TERRATEC_CINERGY_250] = {
94                 .name         = "Terratec Cinergy 250 USB",
95                 .vchannels    = 3,
96                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
97                 .tda9887_conf = TDA9887_PRESENT,
98                 .decoder      = EM28XX_SAA7113,
99                 .input          = { {
100                         .type     = EM28XX_VMUX_TELEVISION,
101                         .vmux     = SAA7115_COMPOSITE2,
102                         .amux     = 1,
103                 }, {
104                         .type     = EM28XX_VMUX_COMPOSITE1,
105                         .vmux     = SAA7115_COMPOSITE0,
106                         .amux     = 1,
107                 }, {
108                         .type     = EM28XX_VMUX_SVIDEO,
109                         .vmux     = SAA7115_SVIDEO3,
110                         .amux     = 1,
111                 } },
112         },
113         [EM2820_BOARD_PINNACLE_USB_2] = {
114                 .name         = "Pinnacle PCTV USB 2",
115                 .vchannels    = 3,
116                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
117                 .tda9887_conf = TDA9887_PRESENT,
118                 .decoder      = EM28XX_SAA7113,
119                 .input          = { {
120                         .type     = EM28XX_VMUX_TELEVISION,
121                         .vmux     = SAA7115_COMPOSITE2,
122                         .amux     = 0,
123                 }, {
124                         .type     = EM28XX_VMUX_COMPOSITE1,
125                         .vmux     = SAA7115_COMPOSITE0,
126                         .amux     = 1,
127                 }, {
128                         .type     = EM28XX_VMUX_SVIDEO,
129                         .vmux     = SAA7115_SVIDEO3,
130                         .amux     = 1,
131                 } },
132         },
133         [EM2820_BOARD_HAUPPAUGE_WINTV_USB_2] = {
134                 .name         = "Hauppauge WinTV USB 2",
135                 .vchannels    = 3,
136                 .tuner_type   = TUNER_PHILIPS_FM1236_MK3,
137                 .tda9887_conf = TDA9887_PRESENT |
138                                 TDA9887_PORT1_ACTIVE|
139                                 TDA9887_PORT2_ACTIVE,
140                 .decoder      = EM28XX_TVP5150,
141                 .has_msp34xx  = 1,
142                 /*FIXME: S-Video not tested */
143                 .input          = { {
144                         .type     = EM28XX_VMUX_TELEVISION,
145                         .vmux     = TVP5150_COMPOSITE0,
146                         .amux     = MSP_INPUT_DEFAULT,
147                 }, {
148                         .type     = EM28XX_VMUX_SVIDEO,
149                         .vmux     = TVP5150_SVIDEO,
150                         .amux     = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
151                                         MSP_DSP_IN_SCART, MSP_DSP_IN_SCART),
152                 } },
153         },
154         [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900] = {
155                 .name         = "Hauppauge WinTV HVR 900",
156                 .vchannels    = 3,
157                 .tda9887_conf = TDA9887_PRESENT,
158                 .tuner_type   = TUNER_XC2028,
159                 .mts_firmware = 1,
160                 .decoder      = EM28XX_TVP5150,
161                 .input          = { {
162                         .type     = EM28XX_VMUX_TELEVISION,
163                         .vmux     = TVP5150_COMPOSITE0,
164                         .amux     = 0,
165                 }, {
166                         .type     = EM28XX_VMUX_COMPOSITE1,
167                         .vmux     = TVP5150_COMPOSITE1,
168                         .amux     = 1,
169                 }, {
170                         .type     = EM28XX_VMUX_SVIDEO,
171                         .vmux     = TVP5150_SVIDEO,
172                         .amux     = 1,
173                 } },
174         },
175         [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950] = {
176                 .name           = "Hauppauge WinTV HVR 950",
177                 .vchannels      = 3,
178                 .tda9887_conf   = TDA9887_PRESENT,
179                 .tuner_type     = TUNER_XC2028,
180                 .mts_firmware   = 1,
181                 .has_12mhz_i2s  = 1,
182                 .has_dvb        = 1,
183                 .decoder        = EM28XX_TVP5150,
184                 .input          = { {
185                         .type     = EM28XX_VMUX_TELEVISION,
186                         .vmux     = TVP5150_COMPOSITE0,
187                         .amux     = 0,
188                 }, {
189                         .type     = EM28XX_VMUX_COMPOSITE1,
190                         .vmux     = TVP5150_COMPOSITE1,
191                         .amux     = 1,
192                 }, {
193                         .type     = EM28XX_VMUX_SVIDEO,
194                         .vmux     = TVP5150_SVIDEO,
195                         .amux     = 1,
196                 } },
197         },
198         [EM2880_BOARD_TERRATEC_HYBRID_XS] = {
199                 .name         = "Terratec Hybrid XS",
200                 .vchannels    = 3,
201                 .tda9887_conf = TDA9887_PRESENT,
202                 .tuner_type   = TUNER_XC2028,
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                 } },
217         },
218         /* maybe there's a reason behind it why Terratec sells the Hybrid XS
219            as Prodigy XS with a different PID, let's keep it separated for now
220            maybe we'll need it lateron */
221         [EM2880_BOARD_TERRATEC_PRODIGY_XS] = {
222                 .name         = "Terratec Prodigy 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                 } },
240         },
241         [EM2820_BOARD_MSI_VOX_USB_2] = {
242                 .name              = "MSI VOX USB 2.0",
243                 .vchannels         = 3,
244                 .tuner_type        = TUNER_LG_PAL_NEW_TAPC,
245                 .tda9887_conf      = TDA9887_PRESENT      |
246                                      TDA9887_PORT1_ACTIVE |
247                                      TDA9887_PORT2_ACTIVE,
248                 .max_range_640_480 = 1,
249
250                 .decoder           = EM28XX_SAA7114,
251                 .input             = { {
252                         .type      = EM28XX_VMUX_TELEVISION,
253                         .vmux      = SAA7115_COMPOSITE4,
254                         .amux      = 0,
255                 }, {
256                         .type      = EM28XX_VMUX_COMPOSITE1,
257                         .vmux      = SAA7115_COMPOSITE0,
258                         .amux      = 1,
259                 }, {
260                         .type      = EM28XX_VMUX_SVIDEO,
261                         .vmux      = SAA7115_SVIDEO3,
262                         .amux      = 1,
263                 } },
264         },
265         [EM2800_BOARD_TERRATEC_CINERGY_200] = {
266                 .name         = "Terratec Cinergy 200 USB",
267                 .is_em2800    = 1,
268                 .vchannels    = 3,
269                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
270                 .tda9887_conf = TDA9887_PRESENT,
271                 .decoder      = EM28XX_SAA7113,
272                 .input          = { {
273                         .type     = EM28XX_VMUX_TELEVISION,
274                         .vmux     = SAA7115_COMPOSITE2,
275                         .amux     = 0,
276                 }, {
277                         .type     = EM28XX_VMUX_COMPOSITE1,
278                         .vmux     = SAA7115_COMPOSITE0,
279                         .amux     = 1,
280                 }, {
281                         .type     = EM28XX_VMUX_SVIDEO,
282                         .vmux     = SAA7115_SVIDEO3,
283                         .amux     = 1,
284                 } },
285         },
286         [EM2800_BOARD_LEADTEK_WINFAST_USBII] = {
287                 .name         = "Leadtek Winfast USB II",
288                 .is_em2800    = 1,
289                 .vchannels    = 3,
290                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
291                 .tda9887_conf = TDA9887_PRESENT,
292                 .decoder      = EM28XX_SAA7113,
293                 .input          = { {
294                         .type     = EM28XX_VMUX_TELEVISION,
295                         .vmux     = SAA7115_COMPOSITE2,
296                         .amux     = 0,
297                 }, {
298                         .type     = EM28XX_VMUX_COMPOSITE1,
299                         .vmux     = SAA7115_COMPOSITE0,
300                         .amux     = 1,
301                 }, {
302                         .type     = EM28XX_VMUX_SVIDEO,
303                         .vmux     = SAA7115_SVIDEO3,
304                         .amux     = 1,
305                 } },
306         },
307         [EM2800_BOARD_KWORLD_USB2800] = {
308                 .name         = "Kworld USB2800",
309                 .is_em2800    = 1,
310                 .vchannels    = 3,
311                 .tuner_type   = TUNER_PHILIPS_FCV1236D,
312                 .tda9887_conf = TDA9887_PRESENT,
313                 .decoder      = EM28XX_SAA7113,
314                 .input          = { {
315                         .type     = EM28XX_VMUX_TELEVISION,
316                         .vmux     = SAA7115_COMPOSITE2,
317                         .amux     = 0,
318                 }, {
319                         .type     = EM28XX_VMUX_COMPOSITE1,
320                         .vmux     = SAA7115_COMPOSITE0,
321                         .amux     = 1,
322                 }, {
323                         .type     = EM28XX_VMUX_SVIDEO,
324                         .vmux     = SAA7115_SVIDEO3,
325                         .amux     = 1,
326                 } },
327         },
328         [EM2820_BOARD_PINNACLE_DVC_90] = {
329                 .name         = "Pinnacle Dazzle DVC 90/DVC 100",
330                 .vchannels    = 3,
331                 .tuner_type   = TUNER_ABSENT,
332                 .decoder      = EM28XX_SAA7113,
333                 .input          = { {
334                         .type     = EM28XX_VMUX_COMPOSITE1,
335                         .vmux     = SAA7115_COMPOSITE0,
336                         .amux     = 1,
337                 }, {
338                         .type     = EM28XX_VMUX_SVIDEO,
339                         .vmux     = SAA7115_SVIDEO3,
340                         .amux     = 1,
341                 } },
342         },
343         [EM2800_BOARD_VGEAR_POCKETTV] = {
344                 .name         = "V-Gear PocketTV",
345                 .is_em2800    = 1,
346                 .vchannels    = 3,
347                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
348                 .tda9887_conf = TDA9887_PRESENT,
349                 .decoder      = EM28XX_SAA7113,
350                 .input          = { {
351                         .type     = EM28XX_VMUX_TELEVISION,
352                         .vmux     = SAA7115_COMPOSITE2,
353                         .amux     = 0,
354                 }, {
355                         .type     = EM28XX_VMUX_COMPOSITE1,
356                         .vmux     = SAA7115_COMPOSITE0,
357                         .amux     = 1,
358                 }, {
359                         .type     = EM28XX_VMUX_SVIDEO,
360                         .vmux     = SAA7115_SVIDEO3,
361                         .amux     = 1,
362                 } },
363         },
364         [EM2820_BOARD_PROLINK_PLAYTV_USB2] = {
365                 .name         = "Pixelview Prolink PlayTV USB 2.0",
366                 .vchannels    = 3,
367                 .tda9887_conf = TDA9887_PRESENT,
368                 .tuner_type   = TUNER_YMEC_TVF_5533MF,
369                 .decoder      = EM28XX_SAA7113,
370                 .input          = { {
371                         .type     = EM28XX_VMUX_TELEVISION,
372                         .vmux     = SAA7115_COMPOSITE2,
373                         .amux     = EM28XX_AMUX_LINE_IN,
374                 }, {
375                         .type     = EM28XX_VMUX_COMPOSITE1,
376                         .vmux     = SAA7115_COMPOSITE0,
377                         .amux     = EM28XX_AMUX_LINE_IN,
378                 }, {
379                         .type     = EM28XX_VMUX_SVIDEO,
380                         .vmux     = SAA7115_SVIDEO3,
381                         .amux     = EM28XX_AMUX_LINE_IN,
382                 } },
383         },
384 };
385 const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
386
387 /* table of devices that work with this driver */
388 struct usb_device_id em28xx_id_table [] = {
389         { USB_DEVICE(0xeb1a, 0x2750),
390                         .driver_info = EM2820_BOARD_UNKNOWN },
391         { USB_DEVICE(0xeb1a, 0x2800),
392                         .driver_info = EM2800_BOARD_UNKNOWN },
393         { USB_DEVICE(0xeb1a, 0x2820),
394                         .driver_info = EM2820_BOARD_UNKNOWN },
395         { USB_DEVICE(0xeb1a, 0x2821),
396                         .driver_info = EM2820_BOARD_UNKNOWN },
397         { USB_DEVICE(0xeb1a, 0x2860),
398                         .driver_info = EM2820_BOARD_UNKNOWN },
399         { USB_DEVICE(0xeb1a, 0x2861),
400                         .driver_info = EM2820_BOARD_UNKNOWN },
401         { USB_DEVICE(0xeb1a, 0x2870),
402                         .driver_info = EM2820_BOARD_UNKNOWN },
403         { USB_DEVICE(0xeb1a, 0x2881),
404                         .driver_info = EM2820_BOARD_UNKNOWN },
405         { USB_DEVICE(0xeb1a, 0x2883),
406                         .driver_info = EM2820_BOARD_UNKNOWN },
407         { USB_DEVICE(0x0ccd, 0x0036),
408                         .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
409         { USB_DEVICE(0x2304, 0x0208),
410                         .driver_info = EM2820_BOARD_PINNACLE_USB_2 },
411         { USB_DEVICE(0x2040, 0x4200),
412                         .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
413         { USB_DEVICE(0x2040, 0x4201),
414                         .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
415         { USB_DEVICE(0x2304, 0x0207),
416                         .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
417         { USB_DEVICE(0x2304, 0x021a),
418                         .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
419         { USB_DEVICE(0x2040, 0x6500),
420                         .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
421         { USB_DEVICE(0x2040, 0x6502),
422                         .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
423         { USB_DEVICE(0x2040, 0x6513),
424                         .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 },
425         { USB_DEVICE(0x0ccd, 0x0042),
426                         .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS },
427         { USB_DEVICE(0x0ccd, 0x0047),
428                         .driver_info = EM2880_BOARD_TERRATEC_PRODIGY_XS },
429         { },
430 };
431 MODULE_DEVICE_TABLE(usb, em28xx_id_table);
432
433 /*
434  *  Reset sequences for analog/digital modes
435  */
436
437 /* Board Hauppauge WinTV HVR 900 analog */
438 static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = {
439         {EM28XX_R08_GPIO,       0x2d,   ~EM_GPIO_4,     10},
440         {0x05,                  0xff,   0x10,           10},
441         {  -1,                  -1,     -1,             -1},
442 };
443
444 /* Board Hauppauge WinTV HVR 900 digital */
445 static struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = {
446         {EM28XX_R08_GPIO,       0x2e,   ~EM_GPIO_4,     10},
447         {EM2880_R04_GPO,        0x04,   0x0f,           10},
448         {EM2880_R04_GPO,        0x0c,   0x0f,           10},
449         { -1,                   -1,     -1,             -1},
450 };
451
452 /* Board Hauppauge WinTV HVR 900 tuner_callback */
453 static struct em28xx_reg_seq hauppauge_wintv_hvr_900_tuner_callback[] = {
454         {EM28XX_R08_GPIO,       EM_GPIO_4,      EM_GPIO_4,      10},
455         {EM28XX_R08_GPIO,       0,              EM_GPIO_4,      10},
456         {EM28XX_R08_GPIO,       EM_GPIO_4,      EM_GPIO_4,      10},
457         {  -1,                  -1,             -1,             -1},
458 };
459
460 /*
461  * EEPROM hash table for devices with generic USB IDs
462  */
463 static struct em28xx_hash_table em28xx_eeprom_hash [] = {
464         /* P/N: SA 60002070465 Tuner: TVF7533-MF */
465         {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF},
466 };
467
468 /* I2C devicelist hash table for devices with generic USB IDs */
469 static struct em28xx_hash_table em28xx_i2c_hash[] = {
470         {0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC},
471         {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC},
472 };
473
474 int em28xx_tuner_callback(void *ptr, int command, int arg)
475 {
476         int rc = 0;
477         struct em28xx *dev = ptr;
478
479         if (dev->tuner_type != TUNER_XC2028)
480                 return 0;
481
482         if (command != XC2028_TUNER_RESET)
483                 return 0;
484
485         if (dev->mode == EM28XX_ANALOG_MODE)
486                 rc = em28xx_gpio_set(dev, dev->tun_analog_gpio);
487         else
488                 rc = em28xx_gpio_set(dev, dev->tun_digital_gpio);
489
490         return rc;
491 }
492 EXPORT_SYMBOL_GPL(em28xx_tuner_callback);
493
494 static void em28xx_set_model(struct em28xx *dev)
495 {
496         dev->is_em2800 = em28xx_boards[dev->model].is_em2800;
497         dev->has_msp34xx = em28xx_boards[dev->model].has_msp34xx;
498         dev->tda9887_conf = em28xx_boards[dev->model].tda9887_conf;
499         dev->decoder = em28xx_boards[dev->model].decoder;
500         dev->video_inputs = em28xx_boards[dev->model].vchannels;
501         dev->has_12mhz_i2s = em28xx_boards[dev->model].has_12mhz_i2s;
502         dev->max_range_640_480 = em28xx_boards[dev->model].max_range_640_480;
503         dev->has_dvb = em28xx_boards[dev->model].has_dvb;
504 }
505
506 /* Since em28xx_pre_card_setup() requires a proper dev->model,
507  * this won't work for boards with generic PCI IDs
508  */
509 void em28xx_pre_card_setup(struct em28xx *dev)
510 {
511         int rc;
512
513         rc = em28xx_read_reg(dev, EM2880_R04_GPO);
514         if (rc >= 0)
515                 dev->reg_gpo = rc;
516
517         dev->wait_after_write = 5;
518         rc = em28xx_read_reg(dev, EM28XX_R0A_CHIPID);
519         if (rc > 0) {
520                 switch (rc) {
521                 case CHIP_ID_EM2883:
522                         em28xx_info("chip ID is em2882/em2883\n");
523                         dev->wait_after_write = 0;
524                         break;
525                 default:
526                         em28xx_info("em28xx chip ID = %d\n", rc);
527                 }
528         }
529         em28xx_set_model(dev);
530
531         /* request some modules */
532         switch (dev->model) {
533         case EM2880_BOARD_TERRATEC_PRODIGY_XS:
534         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
535         case EM2880_BOARD_TERRATEC_HYBRID_XS:
536         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
537                 em28xx_write_regs(dev, EM28XX_R0F_XCLK,    "\x27", 1);
538                 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
539                 msleep(50);
540
541                 /* Sets GPO/GPIO sequences for this device */
542                 dev->analog_gpio      = hauppauge_wintv_hvr_900_analog;
543                 dev->digital_gpio     = hauppauge_wintv_hvr_900_digital;
544                 dev->tun_analog_gpio  = hauppauge_wintv_hvr_900_tuner_callback;
545                 dev->tun_digital_gpio = hauppauge_wintv_hvr_900_tuner_callback;
546
547                 break;
548         }
549
550         em28xx_gpio_set(dev, dev->tun_analog_gpio);
551         em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
552
553         /* Unlock device */
554         em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED);
555 }
556
557 static void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl)
558 {
559         memset(ctl, 0, sizeof(*ctl));
560
561         ctl->fname   = XC2028_DEFAULT_FIRMWARE;
562         ctl->max_len = 64;
563         ctl->mts = em28xx_boards[dev->model].mts_firmware;
564
565         switch (dev->model) {
566         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
567                 ctl->demod = XC3028_FE_ZARLINK456;
568                 break;
569         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
570                 /* FIXME: Better to specify the needed IF */
571                 ctl->demod = XC3028_FE_DEFAULT;
572                 break;
573         default:
574                 ctl->demod = XC3028_FE_OREN538;
575         }
576 }
577
578 static void em28xx_config_tuner(struct em28xx *dev)
579 {
580         struct v4l2_priv_tun_config  xc2028_cfg;
581         struct tuner_setup           tun_setup;
582         struct v4l2_frequency        f;
583
584         if (dev->tuner_type == TUNER_ABSENT)
585                 return;
586
587         tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
588         tun_setup.type = dev->tuner_type;
589         tun_setup.addr = dev->tuner_addr;
590         tun_setup.tuner_callback = em28xx_tuner_callback;
591
592         em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
593
594         if (dev->tuner_type == TUNER_XC2028) {
595                 struct xc2028_ctrl           ctl;
596
597                 em28xx_setup_xc3028(dev, &ctl);
598
599                 xc2028_cfg.tuner = TUNER_XC2028;
600                 xc2028_cfg.priv  = &ctl;
601
602                 em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG, &xc2028_cfg);
603         }
604
605         /* configure tuner */
606         f.tuner = 0;
607         f.type = V4L2_TUNER_ANALOG_TV;
608         f.frequency = 9076;     /* just a magic number */
609         dev->ctl_freq = f.frequency;
610         em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
611 }
612
613 static int em28xx_hint_board(struct em28xx *dev)
614 {
615         int i;
616
617         /* HINT method: EEPROM
618          *
619          * This method works only for boards with eeprom.
620          * Uses a hash of all eeprom bytes. The hash should be
621          * unique for a vendor/tuner pair.
622          * There are a high chance that tuners for different
623          * video standards produce different hashes.
624          */
625         for (i = 0; i < ARRAY_SIZE(em28xx_eeprom_hash); i++) {
626                 if (dev->hash == em28xx_eeprom_hash[i].hash) {
627                         dev->model = em28xx_eeprom_hash[i].model;
628                         dev->tuner_type = em28xx_eeprom_hash[i].tuner;
629
630                         em28xx_errdev("Your board has no unique USB ID.\n");
631                         em28xx_errdev("A hint were successfully done, "
632                                       "based on eeprom hash.\n");
633                         em28xx_errdev("This method is not 100%% failproof.\n");
634                         em28xx_errdev("If the board were missdetected, "
635                                       "please email this log to:\n");
636                         em28xx_errdev("\tV4L Mailing List "
637                                       " <video4linux-list@redhat.com>\n");
638                         em28xx_errdev("Board detected as %s\n",
639                                       em28xx_boards[dev->model].name);
640
641                         return 0;
642                 }
643         }
644
645         /* HINT method: I2C attached devices
646          *
647          * This method works for all boards.
648          * Uses a hash of i2c scanned devices.
649          * Devices with the same i2c attached chips will
650          * be considered equal.
651          * This method is less precise than the eeprom one.
652          */
653
654         /* user did not request i2c scanning => do it now */
655         if (!dev->i2c_hash)
656                 em28xx_do_i2c_scan(dev);
657
658         for (i = 0; i < ARRAY_SIZE(em28xx_i2c_hash); i++) {
659                 if (dev->i2c_hash == em28xx_i2c_hash[i].hash) {
660                         dev->model = em28xx_i2c_hash[i].model;
661                         dev->tuner_type = em28xx_i2c_hash[i].tuner;
662                         em28xx_errdev("Your board has no unique USB ID.\n");
663                         em28xx_errdev("A hint were successfully done, "
664                                       "based on i2c devicelist hash.\n");
665                         em28xx_errdev("This method is not 100%% failproof.\n");
666                         em28xx_errdev("If the board were missdetected, "
667                                       "please email this log to:\n");
668                         em28xx_errdev("\tV4L Mailing List "
669                                       " <video4linux-list@redhat.com>\n");
670                         em28xx_errdev("Board detected as %s\n",
671                                       em28xx_boards[dev->model].name);
672
673                         return 0;
674                 }
675         }
676
677         em28xx_errdev("Your board has no unique USB ID and thus need a "
678                       "hint to be detected.\n");
679         em28xx_errdev("You may try to use card=<n> insmod option to "
680                       "workaround that.\n");
681         em28xx_errdev("Please send an email with this log to:\n");
682         em28xx_errdev("\tV4L Mailing List <video4linux-list@redhat.com>\n");
683         em28xx_errdev("Board eeprom hash is 0x%08lx\n", dev->hash);
684         em28xx_errdev("Board i2c devicelist hash is 0x%08lx\n", dev->i2c_hash);
685
686         em28xx_errdev("Here is a list of valid choices for the card=<n>"
687                       " insmod option:\n");
688         for (i = 0; i < em28xx_bcount; i++) {
689                 em28xx_errdev("    card=%d -> %s\n",
690                                 i, em28xx_boards[i].name);
691         }
692         return -1;
693 }
694
695 /* ----------------------------------------------------------------------- */
696 void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir)
697 {
698         if (disable_ir) {
699                 ir->get_key = NULL;
700                 return ;
701         }
702
703         /* detect & configure */
704         switch (dev->model) {
705         case (EM2800_BOARD_UNKNOWN):
706                 break;
707         case (EM2820_BOARD_UNKNOWN):
708                 break;
709         case (EM2800_BOARD_TERRATEC_CINERGY_200):
710         case (EM2820_BOARD_TERRATEC_CINERGY_250):
711                 ir->ir_codes = ir_codes_em_terratec;
712                 ir->get_key = em28xx_get_key_terratec;
713                 snprintf(ir->c.name, sizeof(ir->c.name),
714                          "i2c IR (EM28XX Terratec)");
715                 break;
716         case (EM2820_BOARD_PINNACLE_USB_2):
717                 ir->ir_codes = ir_codes_pinnacle_grey;
718                 ir->get_key = em28xx_get_key_pinnacle_usb_grey;
719                 snprintf(ir->c.name, sizeof(ir->c.name),
720                          "i2c IR (EM28XX Pinnacle PCTV)");
721                 break;
722         case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
723                 ir->ir_codes = ir_codes_hauppauge_new;
724                 ir->get_key = em28xx_get_key_em_haup;
725                 snprintf(ir->c.name, sizeof(ir->c.name),
726                          "i2c IR (EM2840 Hauppauge)");
727                 break;
728         case (EM2820_BOARD_MSI_VOX_USB_2):
729                 break;
730         case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
731                 break;
732         case (EM2800_BOARD_KWORLD_USB2800):
733                 break;
734         }
735 }
736
737 void em28xx_card_setup(struct em28xx *dev)
738 {
739         em28xx_set_model(dev);
740
741         dev->tuner_type = em28xx_boards[dev->model].tuner_type;
742
743         /* request some modules */
744         switch (dev->model) {
745         case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
746         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
747         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
748         {
749                 struct tveeprom tv;
750 #ifdef CONFIG_MODULES
751                 request_module("tveeprom");
752 #endif
753                 /* Call first TVeeprom */
754
755                 dev->i2c_client.addr = 0xa0 >> 1;
756                 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata);
757
758                 dev->tuner_type = tv.tuner_type;
759
760                 if (tv.audio_processor == AUDIO_CHIP_MSP34XX) {
761                         dev->i2s_speed = 2048000;
762                         dev->has_msp34xx = 1;
763                 }
764 #ifdef CONFIG_MODULES
765                 if (tv.has_ir)
766                         request_module("ir-kbd-i2c");
767 #endif
768                 break;
769         }
770         case EM2820_BOARD_KWORLD_PVRTV2800RF:
771                 /* GPIO enables sound on KWORLD PVR TV 2800RF */
772                 em28xx_write_regs_req(dev, 0x00, 0x08, "\xf9", 1);
773                 break;
774         case EM2820_BOARD_UNKNOWN:
775         case EM2800_BOARD_UNKNOWN:
776                 if (!em28xx_hint_board(dev))
777                         em28xx_set_model(dev);
778         }
779
780         /* Allow override tuner type by a module parameter */
781         if (tuner >= 0)
782                 dev->tuner_type = tuner;
783
784 #ifdef CONFIG_MODULES
785         /* request some modules */
786         if (dev->has_msp34xx)
787                 request_module("msp3400");
788         if (dev->decoder == EM28XX_SAA7113 || dev->decoder == EM28XX_SAA7114)
789                 request_module("saa7115");
790         if (dev->decoder == EM28XX_TVP5150)
791                 request_module("tvp5150");
792         if (dev->tuner_type != TUNER_ABSENT)
793                 request_module("tuner");
794 #endif
795
796         em28xx_config_tuner(dev);
797 }