Merge branches 'x86/numa-fixes', 'x86/apic', 'x86/apm', 'x86/bitops', 'x86/build...
[linux-2.6-block.git] / drivers / media / video / au0828 / au0828-cards.c
CommitLineData
265a6510
ST
1/*
2 * Driver for the Auvitek USB bridge
3 *
4 * Copyright (c) 2008 Steven Toth <stoth@hauppauge.com>
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
265a6510
ST
25struct au0828_board au0828_boards[] = {
26 [AU0828_BOARD_UNKNOWN] = {
27 .name = "Unknown board",
28 },
29 [AU0828_BOARD_HAUPPAUGE_HVR850] = {
30 .name = "Hauppauge HVR850",
31 },
32 [AU0828_BOARD_HAUPPAUGE_HVR950Q] = {
33 .name = "Hauppauge HVR950Q",
34 },
35 [AU0828_BOARD_DVICO_FUSIONHDTV7] = {
36 .name = "DViCO FusionHDTV USB",
37 },
38};
265a6510
ST
39
40/* Tuner callback function for au0828 boards. Currently only needed
41 * for HVR1500Q, which has an xc5000 tuner.
42 */
43int au0828_tuner_callback(void *priv, int command, int arg)
44{
45 struct au0828_dev *dev = priv;
46
f07e8e4b 47 dprintk(1, "%s()\n", __func__);
bc3c613c 48
18d73c58 49 switch (dev->board) {
265a6510
ST
50 case AU0828_BOARD_HAUPPAUGE_HVR850:
51 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
52 case AU0828_BOARD_DVICO_FUSIONHDTV7:
a9c36aad 53 if (command == 0) {
265a6510
ST
54 /* Tuner Reset Command from xc5000 */
55 /* Drive the tuner into reset and out */
56 au0828_clear(dev, REG_001, 2);
57 mdelay(200);
58 au0828_set(dev, REG_001, 2);
59 mdelay(50);
60 return 0;
18d73c58 61 } else {
265a6510 62 printk(KERN_ERR
f07e8e4b 63 "%s(): Unknown command.\n", __func__);
265a6510
ST
64 return -EINVAL;
65 }
66 break;
67 }
68
69 return 0; /* Should never be here */
70}
71
28930fa9
ST
72static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
73{
74 struct tveeprom tv;
75
76 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data);
77
78 /* Make sure we support the board model */
a9c36aad 79 switch (tv.model) {
104fe9a2 80 case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */
28930fa9 81 case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */
104fe9a2
MK
82 case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
83 case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
84 case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
85 case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and basic analog video */
805caff5 86 case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and basic analog video */
104fe9a2 87 case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */
28930fa9
ST
88 break;
89 default:
f07e8e4b
MK
90 printk(KERN_WARNING "%s: warning: "
91 "unknown hauppauge model #%d\n", __func__, tv.model);
28930fa9
ST
92 break;
93 }
94
f07e8e4b
MK
95 printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n",
96 __func__, tv.model);
28930fa9
ST
97}
98
28930fa9
ST
99void au0828_card_setup(struct au0828_dev *dev)
100{
28930fa9
ST
101 static u8 eeprom[256];
102
f07e8e4b 103 dprintk(1, "%s()\n", __func__);
bc3c613c 104
28930fa9
ST
105 if (dev->i2c_rc == 0) {
106 dev->i2c_client.addr = 0xa0 >> 1;
107 tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom));
108 }
109
18d73c58 110 switch (dev->board) {
28930fa9
ST
111 case AU0828_BOARD_HAUPPAUGE_HVR850:
112 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
113 if (dev->i2c_rc == 0)
114 hauppauge_eeprom(dev, eeprom+0xa0);
115 break;
116 }
117}
118
265a6510
ST
119/*
120 * The bridge has between 8 and 12 gpios.
121 * Regs 1 and 0 deal with output enables.
a9c36aad 122 * Regs 3 and 2 deal with direction.
265a6510
ST
123 */
124void au0828_gpio_setup(struct au0828_dev *dev)
125{
f07e8e4b 126 dprintk(1, "%s()\n", __func__);
bc3c613c 127
18d73c58 128 switch (dev->board) {
265a6510
ST
129 case AU0828_BOARD_HAUPPAUGE_HVR850:
130 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
131 /* GPIO's
132 * 4 - CS5340
133 * 5 - AU8522 Demodulator
134 * 6 - eeprom W/P
135 * 9 - XC5000 Tuner
136 */
137
138 /* Into reset */
139 au0828_write(dev, REG_003, 0x02);
140 au0828_write(dev, REG_002, 0x88 | 0x20);
141 au0828_write(dev, REG_001, 0x0);
142 au0828_write(dev, REG_000, 0x0);
143 msleep(100);
144
145 /* Out of reset */
146 au0828_write(dev, REG_003, 0x02);
147 au0828_write(dev, REG_001, 0x02);
148 au0828_write(dev, REG_002, 0x88 | 0x20);
149 au0828_write(dev, REG_000, 0x88 | 0x20 | 0x40);
150 msleep(250);
151 break;
152 case AU0828_BOARD_DVICO_FUSIONHDTV7:
153 /* GPIO's
154 * 6 - ?
155 * 8 - AU8522 Demodulator
156 * 9 - XC5000 Tuner
157 */
158
159 /* Into reset */
160 au0828_write(dev, REG_003, 0x02);
161 au0828_write(dev, REG_002, 0xa0);
162 au0828_write(dev, REG_001, 0x0);
163 au0828_write(dev, REG_000, 0x0);
164 msleep(100);
165
166 /* Out of reset */
167 au0828_write(dev, REG_003, 0x02);
168 au0828_write(dev, REG_002, 0xa0);
169 au0828_write(dev, REG_001, 0x02);
170 au0828_write(dev, REG_000, 0xa0);
171 msleep(250);
172 break;
173 }
174}
175
176/* table of devices that work with this driver */
177struct usb_device_id au0828_usb_id_table [] = {
178 { USB_DEVICE(0x2040, 0x7200),
179 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
180 { USB_DEVICE(0x2040, 0x7240),
181 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 },
182 { USB_DEVICE(0x0fe9, 0xd620),
183 .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 },
104fe9a2
MK
184 { USB_DEVICE(0x2040, 0x7210),
185 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
186 { USB_DEVICE(0x2040, 0x7217),
187 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
188 { USB_DEVICE(0x2040, 0x721b),
189 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
190 { USB_DEVICE(0x2040, 0x721f),
191 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
192 { USB_DEVICE(0x2040, 0x7280),
193 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
194 { USB_DEVICE(0x0fd9, 0x0008),
195 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
265a6510
ST
196 { },
197};
198
199MODULE_DEVICE_TABLE(usb, au0828_usb_id_table);