V4L/DVB (11085): au0828/au8522: Codingstyle fixes
[linux-2.6.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 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                 au0828_call_i2c_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
222         }
223 }
224
225 /*
226  * The bridge has between 8 and 12 gpios.
227  * Regs 1 and 0 deal with output enables.
228  * Regs 3 and 2 deal with direction.
229  */
230 void au0828_gpio_setup(struct au0828_dev *dev)
231 {
232         dprintk(1, "%s()\n", __func__);
233
234         switch (dev->boardnr) {
235         case AU0828_BOARD_HAUPPAUGE_HVR850:
236         case AU0828_BOARD_HAUPPAUGE_HVR950Q:
237         case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
238         case AU0828_BOARD_HAUPPAUGE_WOODBURY:
239                 /* GPIO's
240                  * 4 - CS5340
241                  * 5 - AU8522 Demodulator
242                  * 6 - eeprom W/P
243                  * 7 - power supply
244                  * 9 - XC5000 Tuner
245                  */
246
247                 /* Into reset */
248                 au0828_write(dev, REG_003, 0x02);
249                 au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
250                 au0828_write(dev, REG_001, 0x0);
251                 au0828_write(dev, REG_000, 0x0);
252                 msleep(100);
253
254                 /* Out of reset (leave the cs5340 in reset until needed) */
255                 au0828_write(dev, REG_003, 0x02);
256                 au0828_write(dev, REG_001, 0x02);
257                 au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
258                 au0828_write(dev, REG_000, 0x80 | 0x40 | 0x20);
259
260                 msleep(250);
261                 break;
262         case AU0828_BOARD_DVICO_FUSIONHDTV7:
263                 /* GPIO's
264                  * 6 - ?
265                  * 8 - AU8522 Demodulator
266                  * 9 - XC5000 Tuner
267                  */
268
269                 /* Into reset */
270                 au0828_write(dev, REG_003, 0x02);
271                 au0828_write(dev, REG_002, 0xa0);
272                 au0828_write(dev, REG_001, 0x0);
273                 au0828_write(dev, REG_000, 0x0);
274                 msleep(100);
275
276                 /* Out of reset */
277                 au0828_write(dev, REG_003, 0x02);
278                 au0828_write(dev, REG_002, 0xa0);
279                 au0828_write(dev, REG_001, 0x02);
280                 au0828_write(dev, REG_000, 0xa0);
281                 msleep(250);
282                 break;
283         }
284 }
285
286 /* table of devices that work with this driver */
287 struct usb_device_id au0828_usb_id_table[] = {
288         { USB_DEVICE(0x2040, 0x7200),
289                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
290         { USB_DEVICE(0x2040, 0x7240),
291                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 },
292         { USB_DEVICE(0x0fe9, 0xd620),
293                 .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 },
294         { USB_DEVICE(0x2040, 0x7210),
295                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
296         { USB_DEVICE(0x2040, 0x7217),
297                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
298         { USB_DEVICE(0x2040, 0x721b),
299                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
300         { USB_DEVICE(0x2040, 0x721e),
301                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
302         { USB_DEVICE(0x2040, 0x721f),
303                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
304         { USB_DEVICE(0x2040, 0x7280),
305                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
306         { USB_DEVICE(0x0fd9, 0x0008),
307                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
308         { USB_DEVICE(0x2040, 0x7201),
309                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
310         { USB_DEVICE(0x2040, 0x7211),
311                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
312         { USB_DEVICE(0x2040, 0x7281),
313                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
314         { USB_DEVICE(0x2040, 0x8200),
315                 .driver_info = AU0828_BOARD_HAUPPAUGE_WOODBURY },
316         { },
317 };
318
319 MODULE_DEVICE_TABLE(usb, au0828_usb_id_table);