V4L/DVB (11068): au0828: add analog profile for the HVR-850
[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
26 void hvr950q_cs5340_audio(void *priv, int enable)
27 {
28         /* Because the HVR-950q shares an i2s bus between the cs5340 and the
29            au8522, we need to hold cs5340 in reset when using the au8522 */
30         struct au0828_dev *dev = priv;
31         if (enable == 1)
32                 au0828_set(dev, REG_000, 0x10);
33         else
34                 au0828_clear(dev, REG_000, 0x10);
35 }
36
37 struct au0828_board au0828_boards[] = {
38         [AU0828_BOARD_UNKNOWN] = {
39                 .name   = "Unknown board",
40         },
41         [AU0828_BOARD_HAUPPAUGE_HVR850] = {
42                 .name   = "Hauppauge HVR850",
43                 .input = {
44                         {
45                                 .type = AU0828_VMUX_TELEVISION,
46                                 .vmux = AU8522_COMPOSITE_CH4_SIF,
47                                 .amux = AU8522_AUDIO_SIF,
48                         },
49                         {
50                                 .type = AU0828_VMUX_COMPOSITE,
51                                 .vmux = AU8522_COMPOSITE_CH1,
52                                 .amux = AU8522_AUDIO_NONE,
53                                 .audio_setup = hvr950q_cs5340_audio,
54                         },
55                         {
56                                 .type = AU0828_VMUX_SVIDEO,
57                                 .vmux = AU8522_SVIDEO_CH13,
58                                 .amux = AU8522_AUDIO_NONE,
59                                 .audio_setup = hvr950q_cs5340_audio,
60                         },
61                 },
62         },
63         [AU0828_BOARD_HAUPPAUGE_HVR950Q] = {
64                 .name   = "Hauppauge HVR950Q",
65                 .input = {
66                         {
67                                 .type = AU0828_VMUX_TELEVISION,
68                                 .vmux = AU8522_COMPOSITE_CH4_SIF,
69                                 .amux = AU8522_AUDIO_SIF,
70                         },
71                         {
72                                 .type = AU0828_VMUX_COMPOSITE,
73                                 .vmux = AU8522_COMPOSITE_CH1,
74                                 .amux = AU8522_AUDIO_NONE,
75                                 .audio_setup = hvr950q_cs5340_audio,
76                         },
77                         {
78                                 .type = AU0828_VMUX_SVIDEO,
79                                 .vmux = AU8522_SVIDEO_CH13,
80                                 .amux = AU8522_AUDIO_NONE,
81                                 .audio_setup = hvr950q_cs5340_audio,
82                         },
83                 },
84         },
85         [AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL] = {
86                 .name   = "Hauppauge HVR950Q rev xxF8",
87         },
88         [AU0828_BOARD_DVICO_FUSIONHDTV7] = {
89                 .name   = "DViCO FusionHDTV USB",
90         },
91         [AU0828_BOARD_HAUPPAUGE_WOODBURY] = {
92                 .name = "Hauppauge Woodbury",
93         },
94 };
95
96 /* Tuner callback function for au0828 boards. Currently only needed
97  * for HVR1500Q, which has an xc5000 tuner.
98  */
99 int au0828_tuner_callback(void *priv, int component, int command, int arg)
100 {
101         struct au0828_dev *dev = priv;
102
103         dprintk(1, "%s()\n", __func__);
104
105         switch (dev->board) {
106         case AU0828_BOARD_HAUPPAUGE_HVR850:
107         case AU0828_BOARD_HAUPPAUGE_HVR950Q:
108         case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
109         case AU0828_BOARD_DVICO_FUSIONHDTV7:
110                 if (command == 0) {
111                         /* Tuner Reset Command from xc5000 */
112                         /* Drive the tuner into reset and out */
113                         au0828_clear(dev, REG_001, 2);
114                         mdelay(200);
115                         au0828_set(dev, REG_001, 2);
116                         mdelay(50);
117                         return 0;
118                 } else {
119                         printk(KERN_ERR
120                                 "%s(): Unknown command.\n", __func__);
121                         return -EINVAL;
122                 }
123                 break;
124         }
125
126         return 0; /* Should never be here */
127 }
128
129 static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
130 {
131         struct tveeprom tv;
132
133         tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data);
134
135         /* Make sure we support the board model */
136         switch (tv.model) {
137         case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */
138         case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */
139         case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
140         case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
141         case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
142         case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and basic analog video */
143         case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */
144         case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and basic analog video */
145         case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */
146                 break;
147         default:
148                 printk(KERN_WARNING "%s: warning: "
149                        "unknown hauppauge model #%d\n", __func__, tv.model);
150                 break;
151         }
152
153         printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n",
154                __func__, tv.model);
155 }
156
157 void au0828_card_setup(struct au0828_dev *dev)
158 {
159         static u8 eeprom[256];
160
161         dprintk(1, "%s()\n", __func__);
162
163         if (dev->i2c_rc == 0) {
164                 dev->i2c_client.addr = 0xa0 >> 1;
165                 tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom));
166         }
167
168         switch (dev->board) {
169         case AU0828_BOARD_HAUPPAUGE_HVR850:
170         case AU0828_BOARD_HAUPPAUGE_HVR950Q:
171         case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
172         case AU0828_BOARD_HAUPPAUGE_WOODBURY:
173                 if (dev->i2c_rc == 0)
174                         hauppauge_eeprom(dev, eeprom+0xa0);
175                 break;
176         }
177 }
178
179 /*
180  * The bridge has between 8 and 12 gpios.
181  * Regs 1 and 0 deal with output enables.
182  * Regs 3 and 2 deal with direction.
183  */
184 void au0828_gpio_setup(struct au0828_dev *dev)
185 {
186         dprintk(1, "%s()\n", __func__);
187
188         switch (dev->board) {
189         case AU0828_BOARD_HAUPPAUGE_HVR850:
190         case AU0828_BOARD_HAUPPAUGE_HVR950Q:
191         case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
192         case AU0828_BOARD_HAUPPAUGE_WOODBURY:
193                 /* GPIO's
194                  * 4 - CS5340
195                  * 5 - AU8522 Demodulator
196                  * 6 - eeprom W/P
197                  * 7 - power supply
198                  * 9 - XC5000 Tuner
199                  */
200
201                 /* Into reset */
202                 au0828_write(dev, REG_003, 0x02);
203                 au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
204                 au0828_write(dev, REG_001, 0x0);
205                 au0828_write(dev, REG_000, 0x0);
206                 msleep(100);
207
208                 /* Out of reset (leave the cs5340 in reset until needed) */
209                 au0828_write(dev, REG_003, 0x02);
210                 au0828_write(dev, REG_001, 0x02);
211                 au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
212                 au0828_write(dev, REG_000, 0x80 | 0x40 | 0x20);
213
214                 msleep(250);
215                 break;
216         case AU0828_BOARD_DVICO_FUSIONHDTV7:
217                 /* GPIO's
218                  * 6 - ?
219                  * 8 - AU8522 Demodulator
220                  * 9 - XC5000 Tuner
221                  */
222
223                 /* Into reset */
224                 au0828_write(dev, REG_003, 0x02);
225                 au0828_write(dev, REG_002, 0xa0);
226                 au0828_write(dev, REG_001, 0x0);
227                 au0828_write(dev, REG_000, 0x0);
228                 msleep(100);
229
230                 /* Out of reset */
231                 au0828_write(dev, REG_003, 0x02);
232                 au0828_write(dev, REG_002, 0xa0);
233                 au0828_write(dev, REG_001, 0x02);
234                 au0828_write(dev, REG_000, 0xa0);
235                 msleep(250);
236                 break;
237         }
238 }
239
240 /* table of devices that work with this driver */
241 struct usb_device_id au0828_usb_id_table[] = {
242         { USB_DEVICE(0x2040, 0x7200),
243                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
244         { USB_DEVICE(0x2040, 0x7240),
245                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 },
246         { USB_DEVICE(0x0fe9, 0xd620),
247                 .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 },
248         { USB_DEVICE(0x2040, 0x7210),
249                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
250         { USB_DEVICE(0x2040, 0x7217),
251                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
252         { USB_DEVICE(0x2040, 0x721b),
253                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
254         { USB_DEVICE(0x2040, 0x721e),
255                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
256         { USB_DEVICE(0x2040, 0x721f),
257                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
258         { USB_DEVICE(0x2040, 0x7280),
259                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
260         { USB_DEVICE(0x0fd9, 0x0008),
261                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
262         { USB_DEVICE(0x2040, 0x7201),
263                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
264         { USB_DEVICE(0x2040, 0x7211),
265                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
266         { USB_DEVICE(0x2040, 0x7281),
267                 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
268         { USB_DEVICE(0x2040, 0x8200),
269                 .driver_info = AU0828_BOARD_HAUPPAUGE_WOODBURY },
270         { },
271 };
272
273 MODULE_DEVICE_TABLE(usb, au0828_usb_id_table);