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