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