V4L/DVB (8068): cx18: Add I2C slave reset via GPIO upon initialization
[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 /********************** 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 = "Not yet supported!\n",
198         .v4l2_capabilities = 0,
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_COMPOSITE7 },
203                 { CX18_CARD_INPUT_SVIDEO1,    1, CX18_AV_SVIDEO1    },
204                 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE3 },
205         },
206         .audio_inputs = {
207                 { CX18_CARD_INPUT_AUD_TUNER,
208                   CX18_AV_AUDIO8, 0 },
209                 { CX18_CARD_INPUT_LINE_IN1,
210                   CX18_AV_AUDIO_SERIAL, 0 },
211         },
212         .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
213                          CX18_AV_AUDIO_SERIAL, 0 },
214         .tuners = {
215                 /* XC3028 tuner */
216                 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
217         },
218         .ddr = {
219                 /* Probably Samsung K4D263238G-VC33 memory */
220                 .chip_config = 0x003,
221                 .refresh = 0x30c,
222                 .timing1 = 0x23230b73,
223                 .timing2 = 0x08,
224                 .tune_lane = 0,
225                 .initial_emrs = 2,
226         },
227         .xceive_pin = 15,
228         .pci_list = cx18_pci_mpc718,
229         .i2c = &cx18_i2c_std,
230 };
231
232 static const struct cx18_card *cx18_card_list[] = {
233         &cx18_card_hvr1600_esmt,
234         &cx18_card_hvr1600_samsung,
235         &cx18_card_h900,
236         &cx18_card_mpc718,
237 };
238
239 const struct cx18_card *cx18_get_card(u16 index)
240 {
241         if (index >= ARRAY_SIZE(cx18_card_list))
242                 return NULL;
243         return cx18_card_list[index];
244 }
245
246 int cx18_get_input(struct cx18 *cx, u16 index, struct v4l2_input *input)
247 {
248         const struct cx18_card_video_input *card_input =
249                 cx->card->video_inputs + index;
250         static const char * const input_strs[] = {
251                 "Tuner 1",
252                 "S-Video 1",
253                 "S-Video 2",
254                 "Composite 1",
255                 "Composite 2",
256                 "Composite 3"
257         };
258
259         memset(input, 0, sizeof(*input));
260         if (index >= cx->nof_inputs)
261                 return -EINVAL;
262         input->index = index;
263         strlcpy(input->name, input_strs[card_input->video_type - 1],
264                         sizeof(input->name));
265         input->type = (card_input->video_type == CX18_CARD_INPUT_VID_TUNER ?
266                         V4L2_INPUT_TYPE_TUNER : V4L2_INPUT_TYPE_CAMERA);
267         input->audioset = (1 << cx->nof_audio_inputs) - 1;
268         input->std = (input->type == V4L2_INPUT_TYPE_TUNER) ?
269                                 cx->tuner_std : V4L2_STD_ALL;
270         return 0;
271 }
272
273 int cx18_get_audio_input(struct cx18 *cx, u16 index, struct v4l2_audio *audio)
274 {
275         const struct cx18_card_audio_input *aud_input =
276                 cx->card->audio_inputs + index;
277         static const char * const input_strs[] = {
278                 "Tuner 1",
279                 "Line In 1",
280                 "Line In 2"
281         };
282
283         memset(audio, 0, sizeof(*audio));
284         if (index >= cx->nof_audio_inputs)
285                 return -EINVAL;
286         strlcpy(audio->name, input_strs[aud_input->audio_type - 1],
287                         sizeof(audio->name));
288         audio->index = index;
289         audio->capability = V4L2_AUDCAP_STEREO;
290         return 0;
291 }