V4L/DVB (8107): cx18: improve support for the Raptor board.
[pandora-kernel.git] / 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_SERIAL, CS5345_IN_2 },
71                 { CX18_CARD_INPUT_LINE_IN2,
72                   CX18_AV_AUDIO_SERIAL, CS5345_IN_3 },
73         },
74         .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
75                          CX18_AV_AUDIO_SERIAL, 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         },
92         .i2c = &cx18_i2c_std,
93 };
94
95 static const struct cx18_card cx18_card_hvr1600_samsung = {
96         .type = CX18_CARD_HVR_1600_SAMSUNG,
97         .name = "Hauppauge HVR-1600 (Preproduction)",
98         .comment = "VBI is not yet supported\n",
99         .v4l2_capabilities = CX18_CAP_ENCODER,
100         .hw_audio_ctrl = CX18_HW_CX23418,
101         .hw_muxer = CX18_HW_CS5345,
102         .hw_all = CX18_HW_TVEEPROM | CX18_HW_TUNER |
103                   CX18_HW_CS5345 | CX18_HW_DVB,
104         .video_inputs = {
105                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE7 },
106                 { CX18_CARD_INPUT_SVIDEO1,    1, CX18_AV_SVIDEO1    },
107                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE3 },
108                 { CX18_CARD_INPUT_SVIDEO2,    2, CX18_AV_SVIDEO2    },
109                 { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE4 },
110         },
111         .audio_inputs = {
112                 { CX18_CARD_INPUT_AUD_TUNER,
113                   CX18_AV_AUDIO8, CS5345_IN_1 | CS5345_MCLK_1_5 },
114                 { CX18_CARD_INPUT_LINE_IN1,
115                   CX18_AV_AUDIO_SERIAL, CS5345_IN_2 },
116                 { CX18_CARD_INPUT_LINE_IN2,
117                   CX18_AV_AUDIO_SERIAL, CS5345_IN_3 },
118         },
119         .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
120                          CX18_AV_AUDIO_SERIAL, CS5345_IN_4 },
121         .ddr = {
122                 /* Samsung K4D263238G-VC33 memory */
123                 .chip_config = 0x003,
124                 .refresh = 0x30c,
125                 .timing1 = 0x23230b73,
126                 .timing2 = 0x08,
127                 .tune_lane = 0,
128                 .initial_emrs = 2,
129         },
130         .gpio_init.initial_value = 0x3001,
131         .gpio_init.direction = 0x3001,
132         .gpio_i2c_slave_reset = {
133                 .active_lo_mask = 0x3001,
134                 .msecs_asserted = 10,
135                 .msecs_recovery = 40,
136         },
137         .i2c = &cx18_i2c_std,
138 };
139
140 /* ------------------------------------------------------------------------- */
141
142 /* Compro VideoMate H900: note that this card is analog only! */
143
144 static const struct cx18_card_pci_info cx18_pci_h900[] = {
145         { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_COMPRO, 0xe100 },
146         { 0, 0, 0 }
147 };
148
149 static const struct cx18_card cx18_card_h900 = {
150         .type = CX18_CARD_COMPRO_H900,
151         .name = "Compro VideoMate H900",
152         .comment = "VBI is not yet supported\n",
153         .v4l2_capabilities = CX18_CAP_ENCODER,
154         .hw_audio_ctrl = CX18_HW_CX23418,
155         .hw_all = CX18_HW_TUNER,
156         .video_inputs = {
157                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE2 },
158                 { CX18_CARD_INPUT_SVIDEO1,    1,
159                         CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
160                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
161         },
162         .audio_inputs = {
163                 { CX18_CARD_INPUT_AUD_TUNER,
164                   CX18_AV_AUDIO8, 0 },
165                 { CX18_CARD_INPUT_LINE_IN1,
166                   CX18_AV_AUDIO_SERIAL, 0 },
167         },
168         .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
169                          CX18_AV_AUDIO_SERIAL, 0 },
170         .tuners = {
171                 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
172         },
173         .ddr = {
174                 /* EtronTech EM6A9160TS-5G memory */
175                 .chip_config = 0x50003,
176                 .refresh = 0x753,
177                 .timing1 = 0x24330e84,
178                 .timing2 = 0x1f,
179                 .tune_lane = 0,
180                 .initial_emrs = 0,
181         },
182         .xceive_pin = 15,
183         .pci_list = cx18_pci_h900,
184         .i2c = &cx18_i2c_std,
185 };
186
187 /* ------------------------------------------------------------------------- */
188
189 /* Yuan MPC718: not working at the moment! */
190
191 static const struct cx18_card_pci_info cx18_pci_mpc718[] = {
192         { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_YUAN, 0x0718 },
193         { 0, 0, 0 }
194 };
195
196 static const struct cx18_card cx18_card_mpc718 = {
197         .type = CX18_CARD_YUAN_MPC718,
198         .name = "Yuan MPC718",
199         .comment = "Some Composite and S-Video inputs are currently working.\n",
200         .v4l2_capabilities = CX18_CAP_ENCODER,
201         .hw_audio_ctrl = CX18_HW_CX23418,
202         .hw_all = CX18_HW_TUNER,
203         .video_inputs = {
204                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE2 },
205                 { CX18_CARD_INPUT_SVIDEO1,    1,
206                                 CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
207                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
208                 { CX18_CARD_INPUT_SVIDEO2,    2,
209                                 CX18_AV_SVIDEO_LUMA7 | CX18_AV_SVIDEO_CHROMA8 },
210                 { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE6 },
211                 { CX18_CARD_INPUT_COMPOSITE3, 2, CX18_AV_COMPOSITE3 },
212         },
213         .audio_inputs = {
214                 { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5,       0 },
215                 { CX18_CARD_INPUT_LINE_IN1,  CX18_AV_AUDIO_SERIAL, 0 },
216                 { CX18_CARD_INPUT_LINE_IN2,  CX18_AV_AUDIO_SERIAL, 0 },
217         },
218         .radio_input = { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO_SERIAL, 0 },
219         .tuners = {
220                 /* XC3028 tuner */
221                 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
222         },
223         .ddr = {
224                 /* Probably Samsung K4D263238G-VC33 memory */
225                 .chip_config = 0x003,
226                 .refresh = 0x30c,
227                 .timing1 = 0x23230b73,
228                 .timing2 = 0x08,
229                 .tune_lane = 0,
230                 .initial_emrs = 2,
231         },
232         .xceive_pin = 15,
233         .pci_list = cx18_pci_mpc718,
234         .i2c = &cx18_i2c_std,
235 };
236
237 /* ------------------------------------------------------------------------- */
238
239 /* Conexant Raptor PAL/SECAM: note that this card is analog only! */
240
241 static const struct cx18_card_pci_info cx18_pci_cnxt_raptor_pal[] = {
242         { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_CONEXANT, 0x0009 },
243         { 0, 0, 0 }
244 };
245
246 static const struct cx18_card cx18_card_cnxt_raptor_pal = {
247         .type = CX18_CARD_CNXT_RAPTOR_PAL,
248         .name = "Conexant Raptor PAL/SECAM",
249         .comment = "VBI is not yet supported\n",
250         .v4l2_capabilities = CX18_CAP_ENCODER,
251         .hw_audio_ctrl = CX18_HW_CX23418,
252         .hw_muxer = CX18_HW_GPIO,
253         .hw_all = CX18_HW_TUNER | CX18_HW_GPIO,
254         .video_inputs = {
255                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE2 },
256                 { CX18_CARD_INPUT_SVIDEO1,    1,
257                         CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
258                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
259                 { CX18_CARD_INPUT_SVIDEO2,    2,
260                         CX18_AV_SVIDEO_LUMA7 | CX18_AV_SVIDEO_CHROMA8 },
261                 { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE6 },
262         },
263         .audio_inputs = {
264                 { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO_SERIAL, 1 },
265                 { CX18_CARD_INPUT_LINE_IN1,  CX18_AV_AUDIO_SERIAL, 0 },
266                 { CX18_CARD_INPUT_LINE_IN2,  CX18_AV_AUDIO_SERIAL, 0 },
267         },
268         .tuners = {
269                 { .std = V4L2_STD_PAL_SECAM, .tuner = TUNER_PHILIPS_FM1216ME_MK3 },
270         },
271         .radio_input = { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO_SERIAL, 0 },
272         .ddr = {
273                 /* MT 46V16M16 memory */
274                 .chip_config = 0x50306,
275                 .refresh = 0x753,
276                 .timing1 = 0x33220953,
277                 .timing2 = 0x09,
278                 .tune_lane = 0,
279                 .initial_emrs = 0,
280         },
281         .gpio_init.initial_value = 0x02,
282         .gpio_init.direction = 0x02,
283         .gpio_audio_input  = { .mask = 0x02, .tuner  = 0x02, .linein = 0x00 },
284         .pci_list = cx18_pci_cnxt_raptor_pal,
285         .i2c = &cx18_i2c_std,
286 };
287
288 /* ------------------------------------------------------------------------- */
289
290 static const struct cx18_card *cx18_card_list[] = {
291         &cx18_card_hvr1600_esmt,
292         &cx18_card_hvr1600_samsung,
293         &cx18_card_h900,
294         &cx18_card_mpc718,
295         &cx18_card_cnxt_raptor_pal,
296 };
297
298 const struct cx18_card *cx18_get_card(u16 index)
299 {
300         if (index >= ARRAY_SIZE(cx18_card_list))
301                 return NULL;
302         return cx18_card_list[index];
303 }
304
305 int cx18_get_input(struct cx18 *cx, u16 index, struct v4l2_input *input)
306 {
307         const struct cx18_card_video_input *card_input =
308                 cx->card->video_inputs + index;
309         static const char * const input_strs[] = {
310                 "Tuner 1",
311                 "S-Video 1",
312                 "S-Video 2",
313                 "Composite 1",
314                 "Composite 2",
315                 "Composite 3"
316         };
317
318         memset(input, 0, sizeof(*input));
319         if (index >= cx->nof_inputs)
320                 return -EINVAL;
321         input->index = index;
322         strlcpy(input->name, input_strs[card_input->video_type - 1],
323                         sizeof(input->name));
324         input->type = (card_input->video_type == CX18_CARD_INPUT_VID_TUNER ?
325                         V4L2_INPUT_TYPE_TUNER : V4L2_INPUT_TYPE_CAMERA);
326         input->audioset = (1 << cx->nof_audio_inputs) - 1;
327         input->std = (input->type == V4L2_INPUT_TYPE_TUNER) ?
328                                 cx->tuner_std : V4L2_STD_ALL;
329         return 0;
330 }
331
332 int cx18_get_audio_input(struct cx18 *cx, u16 index, struct v4l2_audio *audio)
333 {
334         const struct cx18_card_audio_input *aud_input =
335                 cx->card->audio_inputs + index;
336         static const char * const input_strs[] = {
337                 "Tuner 1",
338                 "Line In 1",
339                 "Line In 2"
340         };
341
342         memset(audio, 0, sizeof(*audio));
343         if (index >= cx->nof_audio_inputs)
344                 return -EINVAL;
345         strlcpy(audio->name, input_strs[aud_input->audio_type - 1],
346                         sizeof(audio->name));
347         audio->index = index;
348         audio->capability = V4L2_AUDCAP_STEREO;
349         return 0;
350 }