Merge branches 'core/debug', 'core/futexes', 'core/locking', 'core/rcu', 'core/signal...
[linux-2.6] / drivers / media / video / cx18 / cx18-cards.c
1 /*
2  *  cx18 functions to query card hardware
3  *
4  *  Derived from ivtv-cards.c
5  *
6  *  Copyright (C) 2007  Hans Verkuil <hverkuil@xs4all.nl>
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  *  02111-1307  USA
22  */
23
24 #include "cx18-driver.h"
25 #include "cx18-cards.h"
26 #include "cx18-av-core.h"
27 #include "cx18-i2c.h"
28 #include <media/cs5345.h>
29
30 #define V4L2_STD_PAL_SECAM (V4L2_STD_PAL|V4L2_STD_SECAM)
31
32 /********************** card configuration *******************************/
33
34 /* usual i2c tuner addresses to probe */
35 static struct cx18_card_tuner_i2c cx18_i2c_std = {
36         .radio = { I2C_CLIENT_END },
37         .demod = { 0x43, I2C_CLIENT_END },
38         .tv    = { 0x61, 0x60, I2C_CLIENT_END },
39 };
40
41 /* Please add new PCI IDs to: http://pci-ids.ucw.cz/iii
42    This keeps the PCI ID database up to date. Note that the entries
43    must be added under vendor 0x4444 (Conexant) as subsystem IDs.
44    New vendor IDs should still be added to the vendor ID list. */
45
46 /* Hauppauge HVR-1600 cards */
47
48 /* Note: for Hauppauge cards the tveeprom information is used instead
49    of PCI IDs */
50 static const struct cx18_card cx18_card_hvr1600_esmt = {
51         .type = CX18_CARD_HVR_1600_ESMT,
52         .name = "Hauppauge HVR-1600",
53         .comment = "VBI is not yet supported\n",
54         .v4l2_capabilities = CX18_CAP_ENCODER,
55         .hw_audio_ctrl = CX18_HW_CX23418,
56         .hw_muxer = CX18_HW_CS5345,
57         .hw_all = CX18_HW_TVEEPROM | CX18_HW_TUNER |
58                   CX18_HW_CS5345 | CX18_HW_DVB,
59         .video_inputs = {
60                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE7 },
61                 { CX18_CARD_INPUT_SVIDEO1,    1, CX18_AV_SVIDEO1    },
62                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE3 },
63                 { CX18_CARD_INPUT_SVIDEO2,    2, CX18_AV_SVIDEO2    },
64                 { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE4 },
65         },
66         .audio_inputs = {
67                 { CX18_CARD_INPUT_AUD_TUNER,
68                   CX18_AV_AUDIO8, CS5345_IN_1 | CS5345_MCLK_1_5 },
69                 { CX18_CARD_INPUT_LINE_IN1,
70                   CX18_AV_AUDIO_SERIAL1, CS5345_IN_2 },
71                 { CX18_CARD_INPUT_LINE_IN2,
72                   CX18_AV_AUDIO_SERIAL1, CS5345_IN_3 },
73         },
74         .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
75                          CX18_AV_AUDIO_SERIAL1, CS5345_IN_4 },
76         .ddr = {
77                 /* ESMT M13S128324A-5B memory */
78                 .chip_config = 0x003,
79                 .refresh = 0x30c,
80                 .timing1 = 0x44220e82,
81                 .timing2 = 0x08,
82                 .tune_lane = 0,
83                 .initial_emrs = 0,
84         },
85         .gpio_init.initial_value = 0x3001,
86         .gpio_init.direction = 0x3001,
87         .gpio_i2c_slave_reset = {
88                 .active_lo_mask = 0x3001,
89                 .msecs_asserted = 10,
90                 .msecs_recovery = 40,
91                 .ir_reset_mask  = 0x0001,
92         },
93         .i2c = &cx18_i2c_std,
94 };
95
96 static const struct cx18_card cx18_card_hvr1600_samsung = {
97         .type = CX18_CARD_HVR_1600_SAMSUNG,
98         .name = "Hauppauge HVR-1600 (Preproduction)",
99         .comment = "VBI is not yet supported\n",
100         .v4l2_capabilities = CX18_CAP_ENCODER,
101         .hw_audio_ctrl = CX18_HW_CX23418,
102         .hw_muxer = CX18_HW_CS5345,
103         .hw_all = CX18_HW_TVEEPROM | CX18_HW_TUNER |
104                   CX18_HW_CS5345 | CX18_HW_DVB,
105         .video_inputs = {
106                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE7 },
107                 { CX18_CARD_INPUT_SVIDEO1,    1, CX18_AV_SVIDEO1    },
108                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE3 },
109                 { CX18_CARD_INPUT_SVIDEO2,    2, CX18_AV_SVIDEO2    },
110                 { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE4 },
111         },
112         .audio_inputs = {
113                 { CX18_CARD_INPUT_AUD_TUNER,
114                   CX18_AV_AUDIO8, CS5345_IN_1 | CS5345_MCLK_1_5 },
115                 { CX18_CARD_INPUT_LINE_IN1,
116                   CX18_AV_AUDIO_SERIAL1, CS5345_IN_2 },
117                 { CX18_CARD_INPUT_LINE_IN2,
118                   CX18_AV_AUDIO_SERIAL1, CS5345_IN_3 },
119         },
120         .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
121                          CX18_AV_AUDIO_SERIAL1, CS5345_IN_4 },
122         .ddr = {
123                 /* Samsung K4D263238G-VC33 memory */
124                 .chip_config = 0x003,
125                 .refresh = 0x30c,
126                 .timing1 = 0x23230b73,
127                 .timing2 = 0x08,
128                 .tune_lane = 0,
129                 .initial_emrs = 2,
130         },
131         .gpio_init.initial_value = 0x3001,
132         .gpio_init.direction = 0x3001,
133         .gpio_i2c_slave_reset = {
134                 .active_lo_mask = 0x3001,
135                 .msecs_asserted = 10,
136                 .msecs_recovery = 40,
137                 .ir_reset_mask  = 0x0001,
138         },
139         .i2c = &cx18_i2c_std,
140 };
141
142 /* ------------------------------------------------------------------------- */
143
144 /* Compro VideoMate H900: note that this card is analog only! */
145
146 static const struct cx18_card_pci_info cx18_pci_h900[] = {
147         { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_COMPRO, 0xe100 },
148         { 0, 0, 0 }
149 };
150
151 static const struct cx18_card cx18_card_h900 = {
152         .type = CX18_CARD_COMPRO_H900,
153         .name = "Compro VideoMate H900",
154         .comment = "VBI is not yet supported\n",
155         .v4l2_capabilities = CX18_CAP_ENCODER,
156         .hw_audio_ctrl = CX18_HW_CX23418,
157         .hw_all = CX18_HW_TUNER,
158         .video_inputs = {
159                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE2 },
160                 { CX18_CARD_INPUT_SVIDEO1,    1,
161                         CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
162                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
163         },
164         .audio_inputs = {
165                 { CX18_CARD_INPUT_AUD_TUNER,
166                   CX18_AV_AUDIO5, 0 },
167                 { CX18_CARD_INPUT_LINE_IN1,
168                   CX18_AV_AUDIO_SERIAL1, 0 },
169         },
170         .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
171                          CX18_AV_AUDIO_SERIAL1, 0 },
172         .tuners = {
173                 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
174         },
175         .ddr = {
176                 /* EtronTech EM6A9160TS-5G memory */
177                 .chip_config = 0x50003,
178                 .refresh = 0x753,
179                 .timing1 = 0x24330e84,
180                 .timing2 = 0x1f,
181                 .tune_lane = 0,
182                 .initial_emrs = 0,
183         },
184         .xceive_pin = 15,
185         .pci_list = cx18_pci_h900,
186         .i2c = &cx18_i2c_std,
187 };
188
189 /* ------------------------------------------------------------------------- */
190
191 /* Yuan MPC718: not working at the moment! */
192
193 static const struct cx18_card_pci_info cx18_pci_mpc718[] = {
194         { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_YUAN, 0x0718 },
195         { 0, 0, 0 }
196 };
197
198 static const struct cx18_card cx18_card_mpc718 = {
199         .type = CX18_CARD_YUAN_MPC718,
200         .name = "Yuan MPC718",
201         .comment = "Analog video capture works; some audio line in may not.\n",
202         .v4l2_capabilities = CX18_CAP_ENCODER,
203         .hw_audio_ctrl = CX18_HW_CX23418,
204         .hw_all = CX18_HW_TUNER,
205         .video_inputs = {
206                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE2 },
207                 { CX18_CARD_INPUT_SVIDEO1,    1,
208                                 CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
209                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
210                 { CX18_CARD_INPUT_SVIDEO2,    2,
211                                 CX18_AV_SVIDEO_LUMA7 | CX18_AV_SVIDEO_CHROMA8 },
212                 { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE6 },
213                 { CX18_CARD_INPUT_COMPOSITE3, 2, CX18_AV_COMPOSITE3 },
214         },
215         .audio_inputs = {
216                 { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5,        0 },
217                 { CX18_CARD_INPUT_LINE_IN1,  CX18_AV_AUDIO_SERIAL1, 0 },
218                 { CX18_CARD_INPUT_LINE_IN2,  CX18_AV_AUDIO_SERIAL1, 0 },
219         },
220         .radio_input = { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO_SERIAL1, 0 },
221         .tuners = {
222                 /* XC3028 tuner */
223                 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
224         },
225         .ddr = {
226                 /* Probably Samsung K4D263238G-VC33 memory */
227                 .chip_config = 0x003,
228                 .refresh = 0x30c,
229                 .timing1 = 0x23230b73,
230                 .timing2 = 0x08,
231                 .tune_lane = 0,
232                 .initial_emrs = 2,
233         },
234         .xceive_pin = 0,
235         .pci_list = cx18_pci_mpc718,
236         .i2c = &cx18_i2c_std,
237 };
238
239 /* ------------------------------------------------------------------------- */
240
241 /* Conexant Raptor PAL/SECAM: note that this card is analog only! */
242
243 static const struct cx18_card_pci_info cx18_pci_cnxt_raptor_pal[] = {
244         { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_CONEXANT, 0x0009 },
245         { 0, 0, 0 }
246 };
247
248 static const struct cx18_card cx18_card_cnxt_raptor_pal = {
249         .type = CX18_CARD_CNXT_RAPTOR_PAL,
250         .name = "Conexant Raptor PAL/SECAM",
251         .comment = "VBI is not yet supported\n",
252         .v4l2_capabilities = CX18_CAP_ENCODER,
253         .hw_audio_ctrl = CX18_HW_CX23418,
254         .hw_muxer = CX18_HW_GPIO,
255         .hw_all = CX18_HW_TUNER | CX18_HW_GPIO,
256         .video_inputs = {
257                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE2 },
258                 { CX18_CARD_INPUT_SVIDEO1,    1,
259                         CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
260                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
261                 { CX18_CARD_INPUT_SVIDEO2,    2,
262                         CX18_AV_SVIDEO_LUMA7 | CX18_AV_SVIDEO_CHROMA8 },
263                 { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE6 },
264         },
265         .audio_inputs = {
266                 { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5,        0 },
267                 { CX18_CARD_INPUT_LINE_IN1,  CX18_AV_AUDIO_SERIAL1, 1 },
268                 { CX18_CARD_INPUT_LINE_IN2,  CX18_AV_AUDIO_SERIAL2, 1 },
269         },
270         .tuners = {
271                 { .std = V4L2_STD_PAL_SECAM, .tuner = TUNER_PHILIPS_FM1216ME_MK3 },
272         },
273         .radio_input = { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO_SERIAL1, 2 },
274         .ddr = {
275                 /* MT 46V16M16 memory */
276                 .chip_config = 0x50306,
277                 .refresh = 0x753,
278                 .timing1 = 0x33220953,
279                 .timing2 = 0x09,
280                 .tune_lane = 0,
281                 .initial_emrs = 0,
282         },
283         .gpio_init.initial_value = 0x1002,
284         .gpio_init.direction = 0xf002,
285         .gpio_audio_input = { .mask   = 0xf002,
286                               .tuner  = 0x1002,   /* LED D1  Tuner AF  */
287                               .linein = 0x2000,   /* LED D2  Line In 1 */
288                               .radio  = 0x4002 }, /* LED D3  Tuner AF  */
289         .pci_list = cx18_pci_cnxt_raptor_pal,
290         .i2c = &cx18_i2c_std,
291 };
292
293 /* ------------------------------------------------------------------------- */
294
295 /* Toshiba Qosmio laptop internal DVB-T/Analog Hybrid Tuner */
296
297 static const struct cx18_card_pci_info cx18_pci_toshiba_qosmio_dvbt[] = {
298         { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_TOSHIBA, 0x0110 },
299         { 0, 0, 0 }
300 };
301
302 static const struct cx18_card cx18_card_toshiba_qosmio_dvbt = {
303         .type = CX18_CARD_TOSHIBA_QOSMIO_DVBT,
304         .name = "Toshiba Qosmio DVB-T/Analog",
305         .comment = "Experimenters and photos needed for device to work well.\n"
306                   "\tTo help, mail the ivtv-devel list (www.ivtvdriver.org).\n",
307         .v4l2_capabilities = CX18_CAP_ENCODER,
308         .hw_audio_ctrl = CX18_HW_CX23418,
309         .hw_all = CX18_HW_TUNER,
310         .video_inputs = {
311                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE6 },
312                 { CX18_CARD_INPUT_SVIDEO1,    1,
313                         CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
314                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
315         },
316         .audio_inputs = {
317                 { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5,        0 },
318                 { CX18_CARD_INPUT_LINE_IN1,  CX18_AV_AUDIO_SERIAL1, 1 },
319         },
320         .tuners = {
321                 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
322         },
323         .ddr = {
324                 .chip_config = 0x202,
325                 .refresh = 0x3bb,
326                 .timing1 = 0x33320a63,
327                 .timing2 = 0x0a,
328                 .tune_lane = 0,
329                 .initial_emrs = 0x42,
330         },
331         .xceive_pin = 15,
332         .pci_list = cx18_pci_toshiba_qosmio_dvbt,
333         .i2c = &cx18_i2c_std,
334 };
335
336 /* ------------------------------------------------------------------------- */
337
338 /* Leadtek WinFast PVR2100 */
339
340 static const struct cx18_card_pci_info cx18_pci_leadtek_pvr2100[] = {
341         { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_LEADTEK, 0x6f27 },
342         { 0, 0, 0 }
343 };
344
345 static const struct cx18_card cx18_card_leadtek_pvr2100 = {
346         .type = CX18_CARD_LEADTEK_PVR2100,
347         .name = "Leadtek WinFast PVR2100",
348         .comment = "Experimenters and photos needed for device to work well.\n"
349                   "\tTo help, mail the ivtv-devel list (www.ivtvdriver.org).\n",
350         .v4l2_capabilities = CX18_CAP_ENCODER,
351         .hw_audio_ctrl = CX18_HW_CX23418,
352         .hw_muxer = CX18_HW_GPIO,
353         .hw_all = CX18_HW_TUNER | CX18_HW_GPIO,
354         .video_inputs = {
355                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE2 },
356                 { CX18_CARD_INPUT_SVIDEO1,    1,
357                         CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
358                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE7 },
359         },
360         .audio_inputs = {
361                 { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5,        0 },
362                 { CX18_CARD_INPUT_LINE_IN1,  CX18_AV_AUDIO_SERIAL1, 1 },
363         },
364         .tuners = {
365                 /* XC3028 tuner */
366                 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
367         },
368         .radio_input = { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5, 2 },
369         .ddr = {
370                 /*
371                  * Pointer to proper DDR config values provided by
372                  * Terry Wu <terrywu at leadtek.com.tw>
373                  */
374                 .chip_config = 0x303,
375                 .refresh = 0x3bb,
376                 .timing1 = 0x24220e83,
377                 .timing2 = 0x1f,
378                 .tune_lane = 0,
379                 .initial_emrs = 0x2,
380         },
381         .gpio_init.initial_value = 0x6,
382         .gpio_init.direction = 0x7,
383         .gpio_audio_input = { .mask   = 0x7,
384                               .tuner  = 0x6, .linein = 0x2, .radio  = 0x2 },
385         .xceive_pin = 15,
386         .pci_list = cx18_pci_leadtek_pvr2100,
387         .i2c = &cx18_i2c_std,
388 };
389
390 /* ------------------------------------------------------------------------- */
391
392 static const struct cx18_card *cx18_card_list[] = {
393         &cx18_card_hvr1600_esmt,
394         &cx18_card_hvr1600_samsung,
395         &cx18_card_h900,
396         &cx18_card_mpc718,
397         &cx18_card_cnxt_raptor_pal,
398         &cx18_card_toshiba_qosmio_dvbt,
399         &cx18_card_leadtek_pvr2100,
400 };
401
402 const struct cx18_card *cx18_get_card(u16 index)
403 {
404         if (index >= ARRAY_SIZE(cx18_card_list))
405                 return NULL;
406         return cx18_card_list[index];
407 }
408
409 int cx18_get_input(struct cx18 *cx, u16 index, struct v4l2_input *input)
410 {
411         const struct cx18_card_video_input *card_input =
412                 cx->card->video_inputs + index;
413         static const char * const input_strs[] = {
414                 "Tuner 1",
415                 "S-Video 1",
416                 "S-Video 2",
417                 "Composite 1",
418                 "Composite 2",
419                 "Composite 3"
420         };
421
422         memset(input, 0, sizeof(*input));
423         if (index >= cx->nof_inputs)
424                 return -EINVAL;
425         input->index = index;
426         strlcpy(input->name, input_strs[card_input->video_type - 1],
427                         sizeof(input->name));
428         input->type = (card_input->video_type == CX18_CARD_INPUT_VID_TUNER ?
429                         V4L2_INPUT_TYPE_TUNER : V4L2_INPUT_TYPE_CAMERA);
430         input->audioset = (1 << cx->nof_audio_inputs) - 1;
431         input->std = (input->type == V4L2_INPUT_TYPE_TUNER) ?
432                                 cx->tuner_std : V4L2_STD_ALL;
433         return 0;
434 }
435
436 int cx18_get_audio_input(struct cx18 *cx, u16 index, struct v4l2_audio *audio)
437 {
438         const struct cx18_card_audio_input *aud_input =
439                 cx->card->audio_inputs + index;
440         static const char * const input_strs[] = {
441                 "Tuner 1",
442                 "Line In 1",
443                 "Line In 2"
444         };
445
446         memset(audio, 0, sizeof(*audio));
447         if (index >= cx->nof_audio_inputs)
448                 return -EINVAL;
449         strlcpy(audio->name, input_strs[aud_input->audio_type - 1],
450                         sizeof(audio->name));
451         audio->index = index;
452         audio->capability = V4L2_AUDCAP_STEREO;
453         return 0;
454 }