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