blob: a2a6983444fa0d8fe146ceadcaabab3378e6d28f [file] [log] [blame]
Steven Toth265a6512008-04-18 21:34:00 -03001/*
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
Steven Toth265a6512008-04-18 21:34:00 -030025struct 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};
Steven Toth265a6512008-04-18 21:34:00 -030039
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
Michael Krufkyf07e8e42008-04-18 21:42:30 -030047 dprintk(1, "%s()\n", __func__);
Steven Tothbc3c6132008-04-18 21:39:11 -030048
Mauro Carvalho Chehab18d73c52008-04-18 22:12:52 -030049 switch (dev->board) {
Steven Toth265a6512008-04-18 21:34:00 -030050 case AU0828_BOARD_HAUPPAUGE_HVR850:
51 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
52 case AU0828_BOARD_DVICO_FUSIONHDTV7:
Steven Totha9c36aa2008-04-17 21:41:28 -030053 if (command == 0) {
Steven Toth265a6512008-04-18 21:34:00 -030054 /* 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;
Mauro Carvalho Chehab18d73c52008-04-18 22:12:52 -030061 } else {
Steven Toth265a6512008-04-18 21:34:00 -030062 printk(KERN_ERR
Michael Krufkyf07e8e42008-04-18 21:42:30 -030063 "%s(): Unknown command.\n", __func__);
Steven Toth265a6512008-04-18 21:34:00 -030064 return -EINVAL;
65 }
66 break;
67 }
68
69 return 0; /* Should never be here */
70}
71
Steven Toth28930fa2008-03-29 19:53:07 -030072static 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 */
Steven Totha9c36aa2008-04-17 21:41:28 -030079 switch (tv.model) {
Steven Toth28930fa2008-03-29 19:53:07 -030080 case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */
Steven Toth805caff2008-04-17 21:47:11 -030081 case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and basic analog video */
Steven Toth28930fa2008-03-29 19:53:07 -030082 break;
83 default:
Michael Krufkyf07e8e42008-04-18 21:42:30 -030084 printk(KERN_WARNING "%s: warning: "
85 "unknown hauppauge model #%d\n", __func__, tv.model);
Steven Toth28930fa2008-03-29 19:53:07 -030086 break;
87 }
88
Michael Krufkyf07e8e42008-04-18 21:42:30 -030089 printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n",
90 __func__, tv.model);
Steven Toth28930fa2008-03-29 19:53:07 -030091}
92
Steven Toth28930fa2008-03-29 19:53:07 -030093void au0828_card_setup(struct au0828_dev *dev)
94{
Steven Toth28930fa2008-03-29 19:53:07 -030095 static u8 eeprom[256];
96
Michael Krufkyf07e8e42008-04-18 21:42:30 -030097 dprintk(1, "%s()\n", __func__);
Steven Tothbc3c6132008-04-18 21:39:11 -030098
Steven Toth28930fa2008-03-29 19:53:07 -030099 if (dev->i2c_rc == 0) {
100 dev->i2c_client.addr = 0xa0 >> 1;
101 tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom));
102 }
103
Mauro Carvalho Chehab18d73c52008-04-18 22:12:52 -0300104 switch (dev->board) {
Steven Toth28930fa2008-03-29 19:53:07 -0300105 case AU0828_BOARD_HAUPPAUGE_HVR850:
106 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
107 if (dev->i2c_rc == 0)
108 hauppauge_eeprom(dev, eeprom+0xa0);
109 break;
110 }
111}
112
Steven Toth265a6512008-04-18 21:34:00 -0300113/*
114 * The bridge has between 8 and 12 gpios.
115 * Regs 1 and 0 deal with output enables.
Steven Totha9c36aa2008-04-17 21:41:28 -0300116 * Regs 3 and 2 deal with direction.
Steven Toth265a6512008-04-18 21:34:00 -0300117 */
118void au0828_gpio_setup(struct au0828_dev *dev)
119{
Michael Krufkyf07e8e42008-04-18 21:42:30 -0300120 dprintk(1, "%s()\n", __func__);
Steven Tothbc3c6132008-04-18 21:39:11 -0300121
Mauro Carvalho Chehab18d73c52008-04-18 22:12:52 -0300122 switch (dev->board) {
Steven Toth265a6512008-04-18 21:34:00 -0300123 case AU0828_BOARD_HAUPPAUGE_HVR850:
124 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
125 /* GPIO's
126 * 4 - CS5340
127 * 5 - AU8522 Demodulator
128 * 6 - eeprom W/P
129 * 9 - XC5000 Tuner
130 */
131
132 /* Into reset */
133 au0828_write(dev, REG_003, 0x02);
134 au0828_write(dev, REG_002, 0x88 | 0x20);
135 au0828_write(dev, REG_001, 0x0);
136 au0828_write(dev, REG_000, 0x0);
137 msleep(100);
138
139 /* Out of reset */
140 au0828_write(dev, REG_003, 0x02);
141 au0828_write(dev, REG_001, 0x02);
142 au0828_write(dev, REG_002, 0x88 | 0x20);
143 au0828_write(dev, REG_000, 0x88 | 0x20 | 0x40);
144 msleep(250);
145 break;
146 case AU0828_BOARD_DVICO_FUSIONHDTV7:
147 /* GPIO's
148 * 6 - ?
149 * 8 - AU8522 Demodulator
150 * 9 - XC5000 Tuner
151 */
152
153 /* Into reset */
154 au0828_write(dev, REG_003, 0x02);
155 au0828_write(dev, REG_002, 0xa0);
156 au0828_write(dev, REG_001, 0x0);
157 au0828_write(dev, REG_000, 0x0);
158 msleep(100);
159
160 /* Out of reset */
161 au0828_write(dev, REG_003, 0x02);
162 au0828_write(dev, REG_002, 0xa0);
163 au0828_write(dev, REG_001, 0x02);
164 au0828_write(dev, REG_000, 0xa0);
165 msleep(250);
166 break;
167 }
168}
169
170/* table of devices that work with this driver */
171struct usb_device_id au0828_usb_id_table [] = {
172 { USB_DEVICE(0x2040, 0x7200),
173 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
174 { USB_DEVICE(0x2040, 0x7240),
175 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 },
176 { USB_DEVICE(0x0fe9, 0xd620),
177 .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 },
178 { },
179};
180
181MODULE_DEVICE_TABLE(usb, au0828_usb_id_table);