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