Merge rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6] / drivers / media / video / em28xx / em28xx-cards.c
1 /*
2    em28xx-cards.c - driver for Empia EM2800/EM2820/2840 USB video capture devices
3
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>
8
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.
13
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.
18
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.
22  */
23
24 #include <linux/init.h>
25 #include <linux/module.h>
26 #include <linux/pci.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 struct em28xx_board em28xx_boards[] = {
41         [EM2800_BOARD_UNKNOWN] = {
42                 .name         = "Unknown EM2800 video grabber",
43                 .is_em2800    = 1,
44                 .vchannels    = 2,
45                 .norm         = VIDEO_MODE_PAL,
46                 .tda9887_conf = TDA9887_PRESENT,
47                 .has_tuner    = 1,
48                 .decoder      = EM28XX_SAA7113,
49                 .input           = {{
50                         .type     = EM28XX_VMUX_COMPOSITE1,
51                         .vmux     = SAA7115_COMPOSITE0,
52                         .amux     = 1,
53                 },{
54                         .type     = EM28XX_VMUX_SVIDEO,
55                         .vmux     = SAA7115_SVIDEO3,
56                         .amux     = 1,
57                 }},
58         },
59         [EM2820_BOARD_UNKNOWN] = {
60                 .name         = "Unknown EM2820/2840 video grabber",
61                 .is_em2800    = 0,
62                 .vchannels    = 2,
63                 .norm         = VIDEO_MODE_PAL,
64                 .tda9887_conf = TDA9887_PRESENT,
65                 .has_tuner    = 1,
66                 .decoder      = EM28XX_SAA7113,
67                 .input           = {{
68                         .type     = EM28XX_VMUX_COMPOSITE1,
69                         .vmux     = SAA7115_COMPOSITE0,
70                         .amux     = 1,
71                 },{
72                         .type     = EM28XX_VMUX_SVIDEO,
73                         .vmux     = SAA7115_SVIDEO3,
74                         .amux     = 1,
75                 }},
76         },
77         [EM2820_BOARD_KWORLD_PVRTV2800RF] = {
78                 .name         = "Kworld PVR TV 2800 RF",
79                 .is_em2800    = 0,
80                 .vchannels    = 2,
81                 .norm         = VIDEO_MODE_PAL,
82                 .tda9887_conf = TDA9887_PRESENT,
83                 .has_tuner    = 1,
84                 .decoder      = EM28XX_SAA7113,
85                 .input           = {{
86                         .type     = EM28XX_VMUX_COMPOSITE1,
87                         .vmux     = SAA7115_COMPOSITE0,
88                         .amux     = 1,
89                 },{
90                         .type     = EM28XX_VMUX_SVIDEO,
91                         .vmux     = SAA7115_SVIDEO3,
92                         .amux     = 1,
93                 }},
94         },
95         [EM2820_BOARD_TERRATEC_CINERGY_250] = {
96                 .name         = "Terratec Cinergy 250 USB",
97                 .vchannels    = 3,
98                 .norm         = VIDEO_MODE_PAL,
99                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
100                 .tda9887_conf = TDA9887_PRESENT,
101                 .has_tuner    = 1,
102                 .decoder      = EM28XX_SAA7113,
103                 .input          = {{
104                         .type     = EM28XX_VMUX_TELEVISION,
105                         .vmux     = SAA7115_COMPOSITE2,
106                         .amux     = 1,
107                 },{
108                         .type     = EM28XX_VMUX_COMPOSITE1,
109                         .vmux     = SAA7115_COMPOSITE0,
110                         .amux     = 1,
111                 },{
112                         .type     = EM28XX_VMUX_SVIDEO,
113                         .vmux     = SAA7115_SVIDEO3,
114                         .amux     = 1,
115                 }},
116         },
117         [EM2820_BOARD_PINNACLE_USB_2] = {
118                 .name         = "Pinnacle PCTV USB 2",
119                 .vchannels    = 3,
120                 .norm         = VIDEO_MODE_PAL,
121                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
122                 .tda9887_conf = TDA9887_PRESENT,
123                 .has_tuner    = 1,
124                 .decoder      = EM28XX_SAA7113,
125                 .input          = {{
126                         .type     = EM28XX_VMUX_TELEVISION,
127                         .vmux     = SAA7115_COMPOSITE2,
128                         .amux     = 0,
129                 },{
130                         .type     = EM28XX_VMUX_COMPOSITE1,
131                         .vmux     = SAA7115_COMPOSITE0,
132                         .amux     = 1,
133                 },{
134                         .type     = EM28XX_VMUX_SVIDEO,
135                         .vmux     = SAA7115_SVIDEO3,
136                         .amux     = 1,
137                 }},
138         },
139         [EM2820_BOARD_HAUPPAUGE_WINTV_USB_2] = {
140                 .name         = "Hauppauge WinTV USB 2",
141                 .vchannels    = 3,
142                 .norm         = VIDEO_MODE_NTSC,
143                 .tuner_type   = TUNER_PHILIPS_FM1236_MK3,
144                 .tda9887_conf = TDA9887_PRESENT|TDA9887_PORT1_ACTIVE|TDA9887_PORT2_ACTIVE,
145                 .has_tuner    = 1,
146                 .decoder      = EM28XX_TVP5150,
147                 .has_msp34xx  = 1,
148                 /*FIXME: S-Video not tested */
149                 .input          = {{
150                         .type     = EM28XX_VMUX_TELEVISION,
151                         .vmux     = TVP5150_COMPOSITE0,
152                         .amux     = MSP_INPUT_DEFAULT,
153                 },{
154                         .type     = EM28XX_VMUX_SVIDEO,
155                         .vmux     = TVP5150_SVIDEO,
156                         .amux     = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
157                                         MSP_DSP_IN_SCART, MSP_DSP_IN_SCART),
158                 }},
159         },
160         [EM2820_BOARD_MSI_VOX_USB_2] = {
161                 .name           = "MSI VOX USB 2.0",
162                 .vchannels      = 3,
163                 .norm           = VIDEO_MODE_PAL,
164                 .tuner_type     = TUNER_LG_PAL_NEW_TAPC,
165                 .tda9887_conf   = TDA9887_PRESENT|TDA9887_PORT1_ACTIVE|TDA9887_PORT2_ACTIVE,
166                 .has_tuner      = 1,
167                 .decoder        = EM28XX_SAA7114,
168                 .input          = {{
169                         .type     = EM28XX_VMUX_TELEVISION,
170                         .vmux     = SAA7115_COMPOSITE4,
171                         .amux     = 0,
172                 },{
173                         .type     = EM28XX_VMUX_COMPOSITE1,
174                         .vmux     = SAA7115_COMPOSITE0,
175                         .amux     = 1,
176                 },{
177                         .type     = EM28XX_VMUX_SVIDEO,
178                         .vmux     = SAA7115_SVIDEO3,
179                         .amux     = 1,
180                 }},
181         },
182         [EM2800_BOARD_TERRATEC_CINERGY_200] = {
183                 .name         = "Terratec Cinergy 200 USB",
184                 .is_em2800    = 1,
185                 .vchannels    = 3,
186                 .norm         = VIDEO_MODE_PAL,
187                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
188                 .tda9887_conf = TDA9887_PRESENT,
189                 .has_tuner    = 1,
190                 .decoder      = EM28XX_SAA7113,
191                 .input          = {{
192                         .type     = EM28XX_VMUX_TELEVISION,
193                         .vmux     = SAA7115_COMPOSITE2,
194                         .amux     = 0,
195                 },{
196                         .type     = EM28XX_VMUX_COMPOSITE1,
197                         .vmux     = SAA7115_COMPOSITE0,
198                         .amux     = 1,
199                 },{
200                         .type     = EM28XX_VMUX_SVIDEO,
201                         .vmux     = SAA7115_SVIDEO3,
202                         .amux     = 1,
203                 }},
204         },
205         [EM2800_BOARD_LEADTEK_WINFAST_USBII] = {
206                 .name         = "Leadtek Winfast USB II",
207                 .is_em2800    = 1,
208                 .vchannels    = 3,
209                 .norm         = VIDEO_MODE_PAL,
210                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
211                 .tda9887_conf = TDA9887_PRESENT,
212                 .has_tuner    = 1,
213                 .decoder      = EM28XX_SAA7113,
214                 .input          = {{
215                         .type     = EM28XX_VMUX_TELEVISION,
216                         .vmux     = SAA7115_COMPOSITE2,
217                         .amux     = 0,
218                 },{
219                         .type     = EM28XX_VMUX_COMPOSITE1,
220                         .vmux     = SAA7115_COMPOSITE0,
221                         .amux     = 1,
222                 },{
223                         .type     = EM28XX_VMUX_SVIDEO,
224                         .vmux     = SAA7115_SVIDEO3,
225                         .amux     = 1,
226                 }},
227         },
228         [EM2800_BOARD_KWORLD_USB2800] = {
229                 .name         = "Kworld USB2800",
230                 .is_em2800    = 1,
231                 .vchannels    = 3,
232                 .norm         = VIDEO_MODE_PAL,
233                 .tuner_type   = TUNER_PHILIPS_ATSC,
234                 .tda9887_conf = TDA9887_PRESENT,
235                 .has_tuner    = 1,
236                 .decoder      = EM28XX_SAA7113,
237                 .input          = {{
238                         .type     = EM28XX_VMUX_TELEVISION,
239                         .vmux     = SAA7115_COMPOSITE2,
240                         .amux     = 0,
241                 },{
242                         .type     = EM28XX_VMUX_COMPOSITE1,
243                         .vmux     = SAA7115_COMPOSITE0,
244                         .amux     = 1,
245                 },{
246                         .type     = EM28XX_VMUX_SVIDEO,
247                         .vmux     = SAA7115_SVIDEO3,
248                         .amux     = 1,
249                 }},
250         },
251         [EM2820_BOARD_PINNACLE_DVC_90] = {
252                 .name         = "Pinnacle Dazzle DVC 90",
253                 .vchannels    = 3,
254                 .norm         = VIDEO_MODE_PAL,
255                 .has_tuner    = 0,
256                 .decoder      = EM28XX_SAA7113,
257                 .input          = {{
258                         .type     = EM28XX_VMUX_COMPOSITE1,
259                         .vmux     = SAA7115_COMPOSITE0,
260                         .amux     = 1,
261                 },{
262                         .type     = EM28XX_VMUX_SVIDEO,
263                         .vmux     = SAA7115_SVIDEO3,
264                         .amux     = 1,
265                 }},
266         },
267 };
268 const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
269
270 /* table of devices that work with this driver */
271 struct usb_device_id em28xx_id_table [] = {
272         { USB_DEVICE(0xeb1a, 0x2800), .driver_info = EM2800_BOARD_UNKNOWN },
273         { USB_DEVICE(0xeb1a, 0x2820), .driver_info = EM2820_BOARD_MSI_VOX_USB_2 },
274         { USB_DEVICE(0x0ccd, 0x0036), .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
275         { USB_DEVICE(0x2304, 0x0208), .driver_info = EM2820_BOARD_PINNACLE_USB_2 },
276         { USB_DEVICE(0x2040, 0x4200), .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
277         { USB_DEVICE(0x2304, 0x0207), .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
278         { },
279 };
280
281 void em28xx_pre_card_setup(struct em28xx *dev)
282 {
283         /* request some modules */
284         switch(dev->model){
285                 case EM2880_BOARD_TERRATEC_PRODIGY_XS:
286                 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
287                 case EM2880_BOARD_TERRATEC_HYBRID_XS:
288                         {
289                                 em28xx_write_regs_req(dev, 0x00, 0x08, "\x7d", 1); // reset through GPIO?
290                                 break;
291                         }
292         }
293 }
294
295 void em28xx_card_setup(struct em28xx *dev)
296 {
297         /* request some modules */
298         switch(dev->model){
299                 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
300                         {
301                                 struct tveeprom tv;
302 #ifdef CONFIG_MODULES
303                                 request_module("tveeprom");
304                                 request_module("ir-kbd-i2c");
305                                 request_module("msp3400");
306 #endif
307                                 /* Call first TVeeprom */
308
309                                 dev->i2c_client.addr = 0xa0 >> 1;
310                                 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata);
311
312                                 dev->tuner_type= tv.tuner_type;
313                                 if (tv.audio_processor == AUDIO_CHIP_MSP34XX) {
314                                         dev->i2s_speed=2048000;
315                                         dev->has_msp34xx=1;
316                                 } else
317                                         dev->has_msp34xx=0;
318                                 break;
319                         }
320                 case EM2820_BOARD_KWORLD_PVRTV2800RF:
321                         {
322                                 em28xx_write_regs_req(dev,0x00,0x08, "\xf9", 1); // GPIO enables sound on KWORLD PVR TV 2800RF
323                                 break;
324                         }
325
326         }
327 }
328
329 MODULE_DEVICE_TABLE (usb, em28xx_id_table);