]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/media/video/au0828/au0828-cards.c
a12c92c037460afa77a5b3663521f57353a011df
[linux-2.6-omap-h63xx.git] / drivers / media / video / au0828 / au0828-cards.c
1 /*
2  *  Driver for the Auvitek USB bridge
3  *
4  *  Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #include "au0828.h"
23 #include "au0828-cards.h"
24 #include "au8522.h"
25 #include "media/tuner.h"
26 #include "media/v4l2-common.h"
27
28 void hvr950q_cs5340_audio(void *priv, int enable)
29 {
30         /* Because the HVR-950q shares an i2s bus between the cs5340 and the
31            au8522, we need to hold cs5340 in reset when using the au8522 */
32         struct au0828_dev *dev = priv;
33         if (enable == 1)
34                 au0828_set(dev, REG_000, 0x10);
35         else
36                 au0828_clear(dev, REG_000, 0x10);
37 }
38
39 struct au0828_board au0828_boards[] = {
40         [AU0828_BOARD_UNKNOWN] = {
41                 .name   = "Unknown board",
42                 .tuner_type = UNSET,
43                 .tuner_addr = ADDR_UNSET,
44         },
45         [AU0828_BOARD_HAUPPAUGE_HVR850] = {
46                 .name   = "Hauppauge HVR850",
47                 .tuner_type = TUNER_XC5000,
48                 .tuner_addr = 0x61,
49                 .input = {
50                         {
51                                 .type = AU0828_VMUX_TELEVISION,
52                                 .vmux = AU8522_COMPOSITE_CH4_SIF,
53                                 .amux = AU8522_AUDIO_SIF,
54                         },
55                         {
56                                 .type = AU0828_VMUX_COMPOSITE,
57                                 .vmux = AU8522_COMPOSITE_CH1,
58                                 .amux = AU8522_AUDIO_NONE,
59                                 .audio_setup = hvr950q_cs5340_audio,
60                         },
61                         {
62                                 .type = AU0828_VMUX_SVIDEO,
63                                 .vmux = AU8522_SVIDEO_CH13,
64                                 .amux = AU8522_AUDIO_NONE,
65                                 .audio_setup = hvr950q_cs5340_audio,
66                         },
67                 },
68         },
69         [AU0828_BOARD_HAUPPAUGE_HVR950Q] = {
70                 .name   = "Hauppauge HVR950Q",
71                 .tuner_type = TUNER_XC5000,
72                 .tuner_addr = 0x61,
73                 .input = {
74                         {
75                                 .type = AU0828_VMUX_TELEVISION,
76                                 .vmux = AU8522_COMPOSITE_CH4_SIF,
77                                 .amux = AU8522_AUDIO_SIF,
78                         },
79                         {
80                                 .type = AU0828_VMUX_COMPOSITE,
81                                 .vmux = AU8522_COMPOSITE_CH1,
82                                 .amux = AU8522_AUDIO_NONE,
83                                 .audio_setup = hvr950q_cs5340_audio,
84                         },
85                         {
86                                 .type = AU0828_VMUX_SVIDEO,
87                                 .vmux = AU8522_SVIDEO_CH13,
88                                 .amux = AU8522_AUDIO_NONE,
89                                 .audio_setup = hvr950q_cs5340_audio,
90                         },
91                 },
92         },
93         [AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL] = {
94                 .name   = "Hauppauge HVR950Q rev xxF8",
95                 .tuner_type = UNSET,
96                 .tuner_addr = ADDR_UNSET,
97         },
98         [AU0828_BOARD_DVICO_FUSIONHDTV7] = {
99                 .name   = "DViCO FusionHDTV USB",
100                 .tuner_type = UNSET,
101                 .tuner_addr = ADDR_UNSET,
102         },
103         [AU0828_BOARD_HAUPPAUGE_WOODBURY] = {
104                 .name = "Hauppauge Woodbury",
105                 .tuner_type = UNSET,
106                 .tuner_addr = ADDR_UNSET,
107         },
108 };
109
110 /* Tuner callback function for au0828 boards. Currently only needed
111  * for HVR1500Q, which has an xc5000 tuner.
112  */
113 int au0828_tuner_callback(void *priv, int component, int command, int arg)
114 {
115         struct au0828_dev *dev = priv;
116
117         dprintk(1, "%s()\n", __func__);
118
119         switch (dev->boardnr) {
120         case AU0828_BOARD_HAUPPAUGE_HVR850:
121         case AU0828_BOARD_HAUPPAUGE_HVR950Q:
122         case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
123         case AU0828_BOARD_DVICO_FUSIONHDTV7:
124                 if (command == 0) {
125                         /* Tuner Reset Command from xc5000 */
126                         /* Drive the tuner into reset and out */
127                         au0828_clear(dev, REG_001, 2);
128                         mdelay(200);
129                         au0828_set(dev, REG_001, 2);
130                         mdelay(50);
131                         return 0;
132                 } else {
133                         printk(KERN_ERR
134                                 "%s(): Unknown command.\n", __func__);
135                         return -EINVAL;
136                 }
137                 break;
138         }
139
140         return 0; /* Should never be here */
141 }
142
143 static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
144 {
145         struct tveeprom tv;
146
147         tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data);
148         dev->board.tuner_type = tv.tuner_type;
149
150         /* Make sure we support the board model */
151         switch (tv.model) {
152         case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */
153         case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */
154         case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
155         case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
156         case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
157         case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and basic analog video */
158         case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */
159         case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and basic analog video */
160         case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */
161                 break;
162         default:
163                 printk(KERN_WARNING "%s: warning: "
164                        "unknown hauppauge model #%d\n", __func__, tv.model);
165                 break;
166         }
167
168         printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n",
169                __func__, tv.model);
170 }
171
172 void au0828_card_setup(struct au0828_dev *dev)
173 {
174         static u8 eeprom[256];
175         struct tuner_setup tun_setup;
176         struct v4l2_subdev *sd;
177         unsigned int mode_mask = T_ANALOG_TV |
178                                  T_DIGITAL_TV;
179
180         dprintk(1, "%s()\n", __func__);
181
182         memcpy(&dev->board, &au0828_boards[dev->boardnr], sizeof(dev->board));
183
184         if (dev->i2c_rc == 0) {
185                 dev->i2c_client.addr = 0xa0 >> 1;
186                 tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom));
187         }
188
189         switch (dev->boardnr) {
190         case AU0828_BOARD_HAUPPAUGE_HVR850:
191         case AU0828_BOARD_HAUPPAUGE_HVR950Q:
192         case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
193         case AU0828_BOARD_HAUPPAUGE_WOODBURY:
194                 if (dev->i2c_rc == 0)
195                         hauppauge_eeprom(dev, eeprom+0xa0);
196                 break;
197         }
198
199         if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) {
200                 /* Load the analog demodulator driver (note this would need to
201                    be abstracted out if we ever need to support a different
202                    demod) */
203                 sd = v4l2_i2c_new_subdev(&dev->i2c_adap, "au8522", "au8522",
204                                          0x8e >> 1);
205                 if (sd == NULL) {
206                         printk("analog subdev registration failure\n");
207                 }
208         }
209
210         /* Setup tuners */
211         if (dev->board.tuner_type != TUNER_ABSENT) {
212                 /* Load the tuner module, which does the attach */
213                 sd = v4l2_i2c_new_subdev(&dev->i2c_adap, "tuner", "tuner",
214                                          dev->board.tuner_addr);
215                 if (sd == NULL) {
216                         printk("analog tuner subdev registration failure\n");
217                 }
218
219                 tun_setup.mode_mask      = mode_mask;
220                 tun_setup.type           = dev->board.tuner_type;
221                 tun_setup.addr           = dev->board.tuner_addr;
222                 tun_setup.tuner_callback = au0828_tuner_callback;
223                 au0828_call_i2c_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
224         }
225 }
226
227 /*
228  * The bridge has between 8 and 12 gpios.
229  * Regs 1 and 0 deal with output enables.
230  * Regs 3 and 2 deal with direction.
231  */
232 void au0828_gpio_setup(struct au0828_dev *dev)
233 {
234         dprintk(1, "%s()\n", __func__);
235
236         switch (dev->boardnr) {
237         case AU0828_BOARD_HAUPPAUGE_HVR850:
238         case AU0828_BOARD_HAUPPAUGE_HVR950Q:
239         case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
240         case AU0828_BOARD_HAUPPAUGE_WOODBURY:
241                 /* GPIO's
242                  * 4 - CS5340
243                  * 5 - AU8522 Demodulator
244                  * 6 - eeprom W/P
245                  * 7 - power supply
246                  * 9 - XC5000 Tuner
247                  */
248
249                 /* Into reset */
250                 au0828_write(dev, REG_003, 0x02);
251                 au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
252                 au0828_write(dev, REG_001, 0x0);
253                 au0828_write(dev, REG_000, 0x0);
254                 msleep(100);
255
256                 /* Out of reset (leave the cs5340 in reset until needed) */
257                 au0828_write(dev, REG_003, 0x02);
258                 au0828_write(dev, REG_001, 0x02);
259                 au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
260                 au0828_write(dev, REG_000, 0x80 | 0x40 | 0x20);
261
262                 msleep(250);
263                 break;
264         case AU0828_BOARD_DVICO_FUSIONHDTV7:
265                 /* GPIO's
266                  * 6 - ?
267                  * 8 - AU8522 Demodulator
268                  * 9 - XC5000 Tuner
269                  */
270
271                 /* Into reset */
272                 au0828_write(dev, REG_003, 0x02);
273                 au0828_write(dev, REG_002, 0xa0);
274                 au0828_write(dev, REG_001, 0x0);
275                 au0828_write(dev, REG_000, 0x0);
276                 msleep(100);
277
278                 /* Out of reset */
279                 au0828_write(dev, REG_003, 0x02);
280                 au0828_write(dev, REG_002, 0xa0);
281                 au0828_write(dev, REG_001, 0x02);
282                 au0828_write(dev, REG_000, 0xa0);
283                 msleep(250);
284                 break;
285         }
286 }
287
288 /* table of devices that work with this driver */
289 struct usb_device_id au0828_usb_id_table[] = {
290         { USB_DEVICE(0x2040, 0x7200),
291                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
292         { USB_DEVICE(0x2040, 0x7240),
293                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 },
294         { USB_DEVICE(0x0fe9, 0xd620),
295                 .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 },
296         { USB_DEVICE(0x2040, 0x7210),
297                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
298         { USB_DEVICE(0x2040, 0x7217),
299                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
300         { USB_DEVICE(0x2040, 0x721b),
301                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
302         { USB_DEVICE(0x2040, 0x721e),
303                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
304         { USB_DEVICE(0x2040, 0x721f),
305                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
306         { USB_DEVICE(0x2040, 0x7280),
307                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
308         { USB_DEVICE(0x0fd9, 0x0008),
309                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
310         { USB_DEVICE(0x2040, 0x7201),
311                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
312         { USB_DEVICE(0x2040, 0x7211),
313                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
314         { USB_DEVICE(0x2040, 0x7281),
315                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
316         { USB_DEVICE(0x2040, 0x8200),
317                 .driver_info = AU0828_BOARD_HAUPPAUGE_WOODBURY },
318         { },
319 };
320
321 MODULE_DEVICE_TABLE(usb, au0828_usb_id_table);