Merge branch 'master' of git://git.kernel.org/pub/scm/fs/xfs/xfs
[linux-2.6] / 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 analog video */
154         case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
155         case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
156         case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
157         case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
158         case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
159         case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and 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(KERN_ERR "analog subdev registration failed\n");
207         }
208
209         /* Setup tuners */
210         if (dev->board.tuner_type != TUNER_ABSENT) {
211                 /* Load the tuner module, which does the attach */
212                 sd = v4l2_i2c_new_subdev(&dev->i2c_adap, "tuner", "tuner",
213                                          dev->board.tuner_addr);
214                 if (sd == NULL)
215                         printk(KERN_ERR "tuner subdev registration fail\n");
216
217                 tun_setup.mode_mask      = mode_mask;
218                 tun_setup.type           = dev->board.tuner_type;
219                 tun_setup.addr           = dev->board.tuner_addr;
220                 tun_setup.tuner_callback = au0828_tuner_callback;
221                 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr,
222                                      &tun_setup);
223         }
224 }
225
226 /*
227  * The bridge has between 8 and 12 gpios.
228  * Regs 1 and 0 deal with output enables.
229  * Regs 3 and 2 deal with direction.
230  */
231 void au0828_gpio_setup(struct au0828_dev *dev)
232 {
233         dprintk(1, "%s()\n", __func__);
234
235         switch (dev->boardnr) {
236         case AU0828_BOARD_HAUPPAUGE_HVR850:
237         case AU0828_BOARD_HAUPPAUGE_HVR950Q:
238         case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
239         case AU0828_BOARD_HAUPPAUGE_WOODBURY:
240                 /* GPIO's
241                  * 4 - CS5340
242                  * 5 - AU8522 Demodulator
243                  * 6 - eeprom W/P
244                  * 7 - power supply
245                  * 9 - XC5000 Tuner
246                  */
247
248                 /* Into reset */
249                 au0828_write(dev, REG_003, 0x02);
250                 au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
251                 au0828_write(dev, REG_001, 0x0);
252                 au0828_write(dev, REG_000, 0x0);
253                 msleep(100);
254
255                 /* Out of reset (leave the cs5340 in reset until needed) */
256                 au0828_write(dev, REG_003, 0x02);
257                 au0828_write(dev, REG_001, 0x02);
258                 au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
259                 au0828_write(dev, REG_000, 0x80 | 0x40 | 0x20);
260
261                 msleep(250);
262                 break;
263         case AU0828_BOARD_DVICO_FUSIONHDTV7:
264                 /* GPIO's
265                  * 6 - ?
266                  * 8 - AU8522 Demodulator
267                  * 9 - XC5000 Tuner
268                  */
269
270                 /* Into reset */
271                 au0828_write(dev, REG_003, 0x02);
272                 au0828_write(dev, REG_002, 0xa0);
273                 au0828_write(dev, REG_001, 0x0);
274                 au0828_write(dev, REG_000, 0x0);
275                 msleep(100);
276
277                 /* Out of reset */
278                 au0828_write(dev, REG_003, 0x02);
279                 au0828_write(dev, REG_002, 0xa0);
280                 au0828_write(dev, REG_001, 0x02);
281                 au0828_write(dev, REG_000, 0xa0);
282                 msleep(250);
283                 break;
284         }
285 }
286
287 /* table of devices that work with this driver */
288 struct usb_device_id au0828_usb_id_table[] = {
289         { USB_DEVICE(0x2040, 0x7200),
290                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
291         { USB_DEVICE(0x2040, 0x7240),
292                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 },
293         { USB_DEVICE(0x0fe9, 0xd620),
294                 .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 },
295         { USB_DEVICE(0x2040, 0x7210),
296                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
297         { USB_DEVICE(0x2040, 0x7217),
298                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
299         { USB_DEVICE(0x2040, 0x721b),
300                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
301         { USB_DEVICE(0x2040, 0x721e),
302                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
303         { USB_DEVICE(0x2040, 0x721f),
304                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
305         { USB_DEVICE(0x2040, 0x7280),
306                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
307         { USB_DEVICE(0x0fd9, 0x0008),
308                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
309         { USB_DEVICE(0x2040, 0x7201),
310                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
311         { USB_DEVICE(0x2040, 0x7211),
312                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
313         { USB_DEVICE(0x2040, 0x7281),
314                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
315         { USB_DEVICE(0x2040, 0x8200),
316                 .driver_info = AU0828_BOARD_HAUPPAUGE_WOODBURY },
317         { },
318 };
319
320 MODULE_DEVICE_TABLE(usb, au0828_usb_id_table);