[media] au0828: add missing USB ID 2040:7260
[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                 .i2c_clk_divider = AU0828_I2C_CLK_30KHZ,
50                 .input = {
51                         {
52                                 .type = AU0828_VMUX_TELEVISION,
53                                 .vmux = AU8522_COMPOSITE_CH4_SIF,
54                                 .amux = AU8522_AUDIO_SIF,
55                         },
56                         {
57                                 .type = AU0828_VMUX_COMPOSITE,
58                                 .vmux = AU8522_COMPOSITE_CH1,
59                                 .amux = AU8522_AUDIO_NONE,
60                                 .audio_setup = hvr950q_cs5340_audio,
61                         },
62                         {
63                                 .type = AU0828_VMUX_SVIDEO,
64                                 .vmux = AU8522_SVIDEO_CH13,
65                                 .amux = AU8522_AUDIO_NONE,
66                                 .audio_setup = hvr950q_cs5340_audio,
67                         },
68                 },
69         },
70         [AU0828_BOARD_HAUPPAUGE_HVR950Q] = {
71                 .name   = "Hauppauge HVR950Q",
72                 .tuner_type = TUNER_XC5000,
73                 .tuner_addr = 0x61,
74                 /* The au0828 hardware i2c implementation does not properly
75                    support the xc5000's i2c clock stretching.  So we need to
76                    lower the clock frequency enough where the 15us clock
77                    stretch fits inside of a normal clock cycle, or else the
78                    au0828 fails to set the STOP bit.  A 30 KHz clock puts the
79                    clock pulse width at 18us */
80                 .i2c_clk_divider = AU0828_I2C_CLK_30KHZ,
81                 .input = {
82                         {
83                                 .type = AU0828_VMUX_TELEVISION,
84                                 .vmux = AU8522_COMPOSITE_CH4_SIF,
85                                 .amux = AU8522_AUDIO_SIF,
86                         },
87                         {
88                                 .type = AU0828_VMUX_COMPOSITE,
89                                 .vmux = AU8522_COMPOSITE_CH1,
90                                 .amux = AU8522_AUDIO_NONE,
91                                 .audio_setup = hvr950q_cs5340_audio,
92                         },
93                         {
94                                 .type = AU0828_VMUX_SVIDEO,
95                                 .vmux = AU8522_SVIDEO_CH13,
96                                 .amux = AU8522_AUDIO_NONE,
97                                 .audio_setup = hvr950q_cs5340_audio,
98                         },
99                 },
100         },
101         [AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL] = {
102                 .name   = "Hauppauge HVR950Q rev xxF8",
103                 .tuner_type = UNSET,
104                 .tuner_addr = ADDR_UNSET,
105                 .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
106         },
107         [AU0828_BOARD_DVICO_FUSIONHDTV7] = {
108                 .name   = "DViCO FusionHDTV USB",
109                 .tuner_type = UNSET,
110                 .tuner_addr = ADDR_UNSET,
111                 .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
112         },
113         [AU0828_BOARD_HAUPPAUGE_WOODBURY] = {
114                 .name = "Hauppauge Woodbury",
115                 .tuner_type = UNSET,
116                 .tuner_addr = ADDR_UNSET,
117                 .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
118         },
119 };
120
121 /* Tuner callback function for au0828 boards. Currently only needed
122  * for HVR1500Q, which has an xc5000 tuner.
123  */
124 int au0828_tuner_callback(void *priv, int component, int command, int arg)
125 {
126         struct au0828_dev *dev = priv;
127
128         dprintk(1, "%s()\n", __func__);
129
130         switch (dev->boardnr) {
131         case AU0828_BOARD_HAUPPAUGE_HVR850:
132         case AU0828_BOARD_HAUPPAUGE_HVR950Q:
133         case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
134         case AU0828_BOARD_DVICO_FUSIONHDTV7:
135                 if (command == 0) {
136                         /* Tuner Reset Command from xc5000 */
137                         /* Drive the tuner into reset and out */
138                         au0828_clear(dev, REG_001, 2);
139                         mdelay(10);
140                         au0828_set(dev, REG_001, 2);
141                         mdelay(10);
142                         return 0;
143                 } else {
144                         printk(KERN_ERR
145                                 "%s(): Unknown command.\n", __func__);
146                         return -EINVAL;
147                 }
148                 break;
149         }
150
151         return 0; /* Should never be here */
152 }
153
154 static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
155 {
156         struct tveeprom tv;
157
158         tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data);
159         dev->board.tuner_type = tv.tuner_type;
160
161         /* Make sure we support the board model */
162         switch (tv.model) {
163         case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */
164         case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
165         case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
166         case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
167         case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
168         case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
169         case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
170         case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and analog video */
171         case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */
172                 break;
173         default:
174                 printk(KERN_WARNING "%s: warning: "
175                        "unknown hauppauge model #%d\n", __func__, tv.model);
176                 break;
177         }
178
179         printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n",
180                __func__, tv.model);
181 }
182
183 void au0828_card_setup(struct au0828_dev *dev)
184 {
185         static u8 eeprom[256];
186         struct tuner_setup tun_setup;
187         struct v4l2_subdev *sd;
188         unsigned int mode_mask = T_ANALOG_TV;
189
190         dprintk(1, "%s()\n", __func__);
191
192         memcpy(&dev->board, &au0828_boards[dev->boardnr], sizeof(dev->board));
193
194         if (dev->i2c_rc == 0) {
195                 dev->i2c_client.addr = 0xa0 >> 1;
196                 tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom));
197         }
198
199         switch (dev->boardnr) {
200         case AU0828_BOARD_HAUPPAUGE_HVR850:
201         case AU0828_BOARD_HAUPPAUGE_HVR950Q:
202         case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
203         case AU0828_BOARD_HAUPPAUGE_WOODBURY:
204                 if (dev->i2c_rc == 0)
205                         hauppauge_eeprom(dev, eeprom+0xa0);
206                 break;
207         }
208
209         if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) {
210                 /* Load the analog demodulator driver (note this would need to
211                    be abstracted out if we ever need to support a different
212                    demod) */
213                 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
214                                 "au8522", 0x8e >> 1, NULL);
215                 if (sd == NULL)
216                         printk(KERN_ERR "analog subdev registration failed\n");
217         }
218
219         /* Setup tuners */
220         if (dev->board.tuner_type != TUNER_ABSENT) {
221                 /* Load the tuner module, which does the attach */
222                 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
223                                 "tuner", dev->board.tuner_addr, NULL);
224                 if (sd == NULL)
225                         printk(KERN_ERR "tuner subdev registration fail\n");
226
227                 tun_setup.mode_mask      = mode_mask;
228                 tun_setup.type           = dev->board.tuner_type;
229                 tun_setup.addr           = dev->board.tuner_addr;
230                 tun_setup.tuner_callback = au0828_tuner_callback;
231                 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr,
232                                      &tun_setup);
233         }
234 }
235
236 /*
237  * The bridge has between 8 and 12 gpios.
238  * Regs 1 and 0 deal with output enables.
239  * Regs 3 and 2 deal with direction.
240  */
241 void au0828_gpio_setup(struct au0828_dev *dev)
242 {
243         dprintk(1, "%s()\n", __func__);
244
245         switch (dev->boardnr) {
246         case AU0828_BOARD_HAUPPAUGE_HVR850:
247         case AU0828_BOARD_HAUPPAUGE_HVR950Q:
248         case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
249         case AU0828_BOARD_HAUPPAUGE_WOODBURY:
250                 /* GPIO's
251                  * 4 - CS5340
252                  * 5 - AU8522 Demodulator
253                  * 6 - eeprom W/P
254                  * 7 - power supply
255                  * 9 - XC5000 Tuner
256                  */
257
258                 /* Into reset */
259                 au0828_write(dev, REG_003, 0x02);
260                 au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
261                 au0828_write(dev, REG_001, 0x0);
262                 au0828_write(dev, REG_000, 0x0);
263                 msleep(100);
264
265                 /* Out of reset (leave the cs5340 in reset until needed) */
266                 au0828_write(dev, REG_003, 0x02);
267                 au0828_write(dev, REG_001, 0x02);
268                 au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
269                 au0828_write(dev, REG_000, 0x80 | 0x40 | 0x20);
270
271                 msleep(250);
272                 break;
273         case AU0828_BOARD_DVICO_FUSIONHDTV7:
274                 /* GPIO's
275                  * 6 - ?
276                  * 8 - AU8522 Demodulator
277                  * 9 - XC5000 Tuner
278                  */
279
280                 /* Into reset */
281                 au0828_write(dev, REG_003, 0x02);
282                 au0828_write(dev, REG_002, 0xa0);
283                 au0828_write(dev, REG_001, 0x0);
284                 au0828_write(dev, REG_000, 0x0);
285                 msleep(100);
286
287                 /* Out of reset */
288                 au0828_write(dev, REG_003, 0x02);
289                 au0828_write(dev, REG_002, 0xa0);
290                 au0828_write(dev, REG_001, 0x02);
291                 au0828_write(dev, REG_000, 0xa0);
292                 msleep(250);
293                 break;
294         }
295 }
296
297 /* table of devices that work with this driver */
298 struct usb_device_id au0828_usb_id_table[] = {
299         { USB_DEVICE(0x2040, 0x7200),
300                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
301         { USB_DEVICE(0x2040, 0x7240),
302                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 },
303         { USB_DEVICE(0x0fe9, 0xd620),
304                 .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 },
305         { USB_DEVICE(0x2040, 0x7210),
306                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
307         { USB_DEVICE(0x2040, 0x7217),
308                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
309         { USB_DEVICE(0x2040, 0x721b),
310                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
311         { USB_DEVICE(0x2040, 0x721e),
312                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
313         { USB_DEVICE(0x2040, 0x721f),
314                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
315         { USB_DEVICE(0x2040, 0x7280),
316                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
317         { USB_DEVICE(0x0fd9, 0x0008),
318                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
319         { USB_DEVICE(0x2040, 0x7201),
320                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
321         { USB_DEVICE(0x2040, 0x7211),
322                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
323         { USB_DEVICE(0x2040, 0x7281),
324                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
325         { USB_DEVICE(0x2040, 0x8200),
326                 .driver_info = AU0828_BOARD_HAUPPAUGE_WOODBURY },
327         { USB_DEVICE(0x2040, 0x7260),
328                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
329         { },
330 };
331
332 MODULE_DEVICE_TABLE(usb, au0828_usb_id_table);