Merge branch 'linus' into x86/gart
[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_AUDIO8, 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 static const struct cx18_card *cx18_card_list[] = {
296         &cx18_card_hvr1600_esmt,
297         &cx18_card_hvr1600_samsung,
298         &cx18_card_h900,
299         &cx18_card_mpc718,
300         &cx18_card_cnxt_raptor_pal,
301 };
302
303 const struct cx18_card *cx18_get_card(u16 index)
304 {
305         if (index >= ARRAY_SIZE(cx18_card_list))
306                 return NULL;
307         return cx18_card_list[index];
308 }
309
310 int cx18_get_input(struct cx18 *cx, u16 index, struct v4l2_input *input)
311 {
312         const struct cx18_card_video_input *card_input =
313                 cx->card->video_inputs + index;
314         static const char * const input_strs[] = {
315                 "Tuner 1",
316                 "S-Video 1",
317                 "S-Video 2",
318                 "Composite 1",
319                 "Composite 2",
320                 "Composite 3"
321         };
322
323         memset(input, 0, sizeof(*input));
324         if (index >= cx->nof_inputs)
325                 return -EINVAL;
326         input->index = index;
327         strlcpy(input->name, input_strs[card_input->video_type - 1],
328                         sizeof(input->name));
329         input->type = (card_input->video_type == CX18_CARD_INPUT_VID_TUNER ?
330                         V4L2_INPUT_TYPE_TUNER : V4L2_INPUT_TYPE_CAMERA);
331         input->audioset = (1 << cx->nof_audio_inputs) - 1;
332         input->std = (input->type == V4L2_INPUT_TYPE_TUNER) ?
333                                 cx->tuner_std : V4L2_STD_ALL;
334         return 0;
335 }
336
337 int cx18_get_audio_input(struct cx18 *cx, u16 index, struct v4l2_audio *audio)
338 {
339         const struct cx18_card_audio_input *aud_input =
340                 cx->card->audio_inputs + index;
341         static const char * const input_strs[] = {
342                 "Tuner 1",
343                 "Line In 1",
344                 "Line In 2"
345         };
346
347         memset(audio, 0, sizeof(*audio));
348         if (index >= cx->nof_audio_inputs)
349                 return -EINVAL;
350         strlcpy(audio->name, input_strs[aud_input->audio_type - 1],
351                         sizeof(audio->name));
352         audio->index = index;
353         audio->capability = V4L2_AUDCAP_STEREO;
354         return 0;
355 }