Merge branch 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6
[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 /********************** card configuration *******************************/
31
32 /* usual i2c tuner addresses to probe */
33 static struct cx18_card_tuner_i2c cx18_i2c_std = {
34         .radio = { I2C_CLIENT_END },
35         .demod = { 0x43, I2C_CLIENT_END },
36         .tv    = { 0x61, 0x60, I2C_CLIENT_END },
37 };
38
39 /* Please add new PCI IDs to: http://pci-ids.ucw.cz/iii
40    This keeps the PCI ID database up to date. Note that the entries
41    must be added under vendor 0x4444 (Conexant) as subsystem IDs.
42    New vendor IDs should still be added to the vendor ID list. */
43
44 /* Hauppauge HVR-1600 cards */
45
46 /* Note: for Hauppauge cards the tveeprom information is used instead
47    of PCI IDs */
48 static const struct cx18_card cx18_card_hvr1600_esmt = {
49         .type = CX18_CARD_HVR_1600_ESMT,
50         .name = "Hauppauge HVR-1600",
51         .comment = "VBI is not yet supported\n",
52         .v4l2_capabilities = CX18_CAP_ENCODER,
53         .hw_audio_ctrl = CX18_HW_CX23418,
54         .hw_muxer = CX18_HW_CS5345,
55         .hw_all = CX18_HW_TVEEPROM | CX18_HW_TUNER |
56                   CX18_HW_CS5345 | CX18_HW_DVB,
57         .video_inputs = {
58                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE7 },
59                 { CX18_CARD_INPUT_SVIDEO1,    1, CX18_AV_SVIDEO1    },
60                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE3 },
61                 { CX18_CARD_INPUT_SVIDEO2,    2, CX18_AV_SVIDEO2    },
62                 { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE4 },
63         },
64         .audio_inputs = {
65                 { CX18_CARD_INPUT_AUD_TUNER,
66                   CX18_AV_AUDIO8, CS5345_IN_1 | CS5345_MCLK_1_5 },
67                 { CX18_CARD_INPUT_LINE_IN1,
68                   CX18_AV_AUDIO_SERIAL, CS5345_IN_2 },
69                 { CX18_CARD_INPUT_LINE_IN2,
70                   CX18_AV_AUDIO_SERIAL, CS5345_IN_3 },
71         },
72         .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
73                          CX18_AV_AUDIO_SERIAL, CS5345_IN_4 },
74         .ddr = {
75                 /* ESMT M13S128324A-5B memory */
76                 .chip_config = 0x003,
77                 .refresh = 0x30c,
78                 .timing1 = 0x44220e82,
79                 .timing2 = 0x08,
80                 .tune_lane = 0,
81                 .initial_emrs = 0,
82         },
83         .gpio_init.initial_value = 0x3001,
84         .gpio_init.direction = 0x3001,
85         .gpio_i2c_slave_reset = {
86                 .active_lo_mask = 0x3001,
87                 .msecs_asserted = 10,
88                 .msecs_recovery = 40,
89         },
90         .i2c = &cx18_i2c_std,
91 };
92
93 static const struct cx18_card cx18_card_hvr1600_samsung = {
94         .type = CX18_CARD_HVR_1600_SAMSUNG,
95         .name = "Hauppauge HVR-1600 (Preproduction)",
96         .comment = "VBI is not yet supported\n",
97         .v4l2_capabilities = CX18_CAP_ENCODER,
98         .hw_audio_ctrl = CX18_HW_CX23418,
99         .hw_muxer = CX18_HW_CS5345,
100         .hw_all = CX18_HW_TVEEPROM | CX18_HW_TUNER |
101                   CX18_HW_CS5345 | CX18_HW_DVB,
102         .video_inputs = {
103                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE7 },
104                 { CX18_CARD_INPUT_SVIDEO1,    1, CX18_AV_SVIDEO1    },
105                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE3 },
106                 { CX18_CARD_INPUT_SVIDEO2,    2, CX18_AV_SVIDEO2    },
107                 { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE4 },
108         },
109         .audio_inputs = {
110                 { CX18_CARD_INPUT_AUD_TUNER,
111                   CX18_AV_AUDIO8, CS5345_IN_1 | CS5345_MCLK_1_5 },
112                 { CX18_CARD_INPUT_LINE_IN1,
113                   CX18_AV_AUDIO_SERIAL, CS5345_IN_2 },
114                 { CX18_CARD_INPUT_LINE_IN2,
115                   CX18_AV_AUDIO_SERIAL, CS5345_IN_3 },
116         },
117         .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
118                          CX18_AV_AUDIO_SERIAL, CS5345_IN_4 },
119         .ddr = {
120                 /* Samsung K4D263238G-VC33 memory */
121                 .chip_config = 0x003,
122                 .refresh = 0x30c,
123                 .timing1 = 0x23230b73,
124                 .timing2 = 0x08,
125                 .tune_lane = 0,
126                 .initial_emrs = 2,
127         },
128         .gpio_init.initial_value = 0x3001,
129         .gpio_init.direction = 0x3001,
130         .gpio_i2c_slave_reset = {
131                 .active_lo_mask = 0x3001,
132                 .msecs_asserted = 10,
133                 .msecs_recovery = 40,
134         },
135         .i2c = &cx18_i2c_std,
136 };
137
138 /* ------------------------------------------------------------------------- */
139
140 /* Compro VideoMate H900: note that this card is analog only! */
141
142 static const struct cx18_card_pci_info cx18_pci_h900[] = {
143         { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_COMPRO, 0xe100 },
144         { 0, 0, 0 }
145 };
146
147 static const struct cx18_card cx18_card_h900 = {
148         .type = CX18_CARD_COMPRO_H900,
149         .name = "Compro VideoMate H900",
150         .comment = "VBI is not yet supported\n",
151         .v4l2_capabilities = CX18_CAP_ENCODER,
152         .hw_audio_ctrl = CX18_HW_CX23418,
153         .hw_all = CX18_HW_TUNER,
154         .video_inputs = {
155                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE2 },
156                 { CX18_CARD_INPUT_SVIDEO1,    1,
157                         CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
158                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
159         },
160         .audio_inputs = {
161                 { CX18_CARD_INPUT_AUD_TUNER,
162                   CX18_AV_AUDIO8, 0 },
163                 { CX18_CARD_INPUT_LINE_IN1,
164                   CX18_AV_AUDIO_SERIAL, 0 },
165         },
166         .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
167                          CX18_AV_AUDIO_SERIAL, 0 },
168         .tuners = {
169                 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
170         },
171         .ddr = {
172                 /* EtronTech EM6A9160TS-5G memory */
173                 .chip_config = 0x50003,
174                 .refresh = 0x753,
175                 .timing1 = 0x24330e84,
176                 .timing2 = 0x1f,
177                 .tune_lane = 0,
178                 .initial_emrs = 0,
179         },
180         .xceive_pin = 15,
181         .pci_list = cx18_pci_h900,
182         .i2c = &cx18_i2c_std,
183 };
184
185 /* ------------------------------------------------------------------------- */
186
187 /* Yuan MPC718: not working at the moment! */
188
189 static const struct cx18_card_pci_info cx18_pci_mpc718[] = {
190         { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_YUAN, 0x0718 },
191         { 0, 0, 0 }
192 };
193
194 static const struct cx18_card cx18_card_mpc718 = {
195         .type = CX18_CARD_YUAN_MPC718,
196         .name = "Yuan MPC718",
197         .comment = "Some Composite and S-Video inputs are currently working.\n",
198         .v4l2_capabilities = CX18_CAP_ENCODER,
199         .hw_audio_ctrl = CX18_HW_CX23418,
200         .hw_all = CX18_HW_TUNER,
201         .video_inputs = {
202                 { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE2 },
203                 { CX18_CARD_INPUT_SVIDEO1,    1,
204                                 CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
205                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
206                 { CX18_CARD_INPUT_SVIDEO2,    2,
207                                 CX18_AV_SVIDEO_LUMA7 | CX18_AV_SVIDEO_CHROMA8 },
208                 { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE6 },
209                 { CX18_CARD_INPUT_COMPOSITE3, 2, CX18_AV_COMPOSITE3 },
210         },
211         .audio_inputs = {
212                 { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5,       0 },
213                 { CX18_CARD_INPUT_LINE_IN1,  CX18_AV_AUDIO_SERIAL, 0 },
214                 { CX18_CARD_INPUT_LINE_IN2,  CX18_AV_AUDIO_SERIAL, 0 },
215         },
216         .radio_input = { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO_SERIAL, 0 },
217         .tuners = {
218                 /* XC3028 tuner */
219                 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
220         },
221         .ddr = {
222                 /* Probably Samsung K4D263238G-VC33 memory */
223                 .chip_config = 0x003,
224                 .refresh = 0x30c,
225                 .timing1 = 0x23230b73,
226                 .timing2 = 0x08,
227                 .tune_lane = 0,
228                 .initial_emrs = 2,
229         },
230         .xceive_pin = 15,
231         .pci_list = cx18_pci_mpc718,
232         .i2c = &cx18_i2c_std,
233 };
234
235 static const struct cx18_card *cx18_card_list[] = {
236         &cx18_card_hvr1600_esmt,
237         &cx18_card_hvr1600_samsung,
238         &cx18_card_h900,
239         &cx18_card_mpc718,
240 };
241
242 const struct cx18_card *cx18_get_card(u16 index)
243 {
244         if (index >= ARRAY_SIZE(cx18_card_list))
245                 return NULL;
246         return cx18_card_list[index];
247 }
248
249 int cx18_get_input(struct cx18 *cx, u16 index, struct v4l2_input *input)
250 {
251         const struct cx18_card_video_input *card_input =
252                 cx->card->video_inputs + index;
253         static const char * const input_strs[] = {
254                 "Tuner 1",
255                 "S-Video 1",
256                 "S-Video 2",
257                 "Composite 1",
258                 "Composite 2",
259                 "Composite 3"
260         };
261
262         memset(input, 0, sizeof(*input));
263         if (index >= cx->nof_inputs)
264                 return -EINVAL;
265         input->index = index;
266         strlcpy(input->name, input_strs[card_input->video_type - 1],
267                         sizeof(input->name));
268         input->type = (card_input->video_type == CX18_CARD_INPUT_VID_TUNER ?
269                         V4L2_INPUT_TYPE_TUNER : V4L2_INPUT_TYPE_CAMERA);
270         input->audioset = (1 << cx->nof_audio_inputs) - 1;
271         input->std = (input->type == V4L2_INPUT_TYPE_TUNER) ?
272                                 cx->tuner_std : V4L2_STD_ALL;
273         return 0;
274 }
275
276 int cx18_get_audio_input(struct cx18 *cx, u16 index, struct v4l2_audio *audio)
277 {
278         const struct cx18_card_audio_input *aud_input =
279                 cx->card->audio_inputs + index;
280         static const char * const input_strs[] = {
281                 "Tuner 1",
282                 "Line In 1",
283                 "Line In 2"
284         };
285
286         memset(audio, 0, sizeof(*audio));
287         if (index >= cx->nof_audio_inputs)
288                 return -EINVAL;
289         strlcpy(audio->name, input_strs[aud_input->audio_type - 1],
290                         sizeof(audio->name));
291         audio->index = index;
292         audio->capability = V4L2_AUDCAP_STEREO;
293         return 0;
294 }