Merge branches 'fixes', 'cleanups' and 'boards'
[linux-2.6] / drivers / media / dvb / siano / sms-cards.c
1 /*
2  *  Card-specific functions for the Siano SMS1xxx USB dongle
3  *
4  *  Copyright (c) 2008 Michael Krufky <mkrufky@linuxtv.org>
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 version 2 as
8  *  published by the Free Software Foundation;
9  *
10  *  Software distributed under the License is distributed on an "AS IS"
11  *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
12  *
13  *  See the GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #include "sms-cards.h"
21
22 struct usb_device_id smsusb_id_table[] = {
23 #ifdef CONFIG_DVB_SIANO_SMS1XXX_SMS_IDS
24         { USB_DEVICE(0x187f, 0x0010),
25                 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
26         { USB_DEVICE(0x187f, 0x0100),
27                 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
28         { USB_DEVICE(0x187f, 0x0200),
29                 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_A },
30         { USB_DEVICE(0x187f, 0x0201),
31                 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_B },
32         { USB_DEVICE(0x187f, 0x0300),
33                 .driver_info = SMS1XXX_BOARD_SIANO_VEGA },
34 #endif
35         { USB_DEVICE(0x2040, 0x1700),
36                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT },
37         { USB_DEVICE(0x2040, 0x1800),
38                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A },
39         { USB_DEVICE(0x2040, 0x1801),
40                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B },
41         { USB_DEVICE(0x2040, 0x2000),
42                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
43         { USB_DEVICE(0x2040, 0x2009),
44                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2 },
45         { USB_DEVICE(0x2040, 0x200a),
46                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
47         { USB_DEVICE(0x2040, 0x2010),
48                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
49         { USB_DEVICE(0x2040, 0x2019),
50                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
51         { USB_DEVICE(0x2040, 0x5500),
52                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
53         { USB_DEVICE(0x2040, 0x5510),
54                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
55         { USB_DEVICE(0x2040, 0x5520),
56                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
57         { USB_DEVICE(0x2040, 0x5530),
58                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
59         { USB_DEVICE(0x2040, 0x5580),
60                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
61         { USB_DEVICE(0x2040, 0x5590),
62                 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
63         { }             /* Terminating entry */
64 };
65 MODULE_DEVICE_TABLE(usb, smsusb_id_table);
66
67 static struct sms_board sms_boards[] = {
68         [SMS_BOARD_UNKNOWN] = {
69                 .name   = "Unknown board",
70         },
71         [SMS1XXX_BOARD_SIANO_STELLAR] = {
72                 .name   = "Siano Stellar Digital Receiver",
73                 .type   = SMS_STELLAR,
74                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-stellar-dvbt-01.fw",
75         },
76         [SMS1XXX_BOARD_SIANO_NOVA_A] = {
77                 .name   = "Siano Nova A Digital Receiver",
78                 .type   = SMS_NOVA_A0,
79                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-nova-a-dvbt-01.fw",
80         },
81         [SMS1XXX_BOARD_SIANO_NOVA_B] = {
82                 .name   = "Siano Nova B Digital Receiver",
83                 .type   = SMS_NOVA_B0,
84                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-nova-b-dvbt-01.fw",
85         },
86         [SMS1XXX_BOARD_SIANO_VEGA] = {
87                 .name   = "Siano Vega Digital Receiver",
88                 .type   = SMS_VEGA,
89         },
90         [SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT] = {
91                 .name   = "Hauppauge Catamount",
92                 .type   = SMS_STELLAR,
93                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-stellar-dvbt-01.fw",
94         },
95         [SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A] = {
96                 .name   = "Hauppauge Okemo-A",
97                 .type   = SMS_NOVA_A0,
98                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-nova-a-dvbt-01.fw",
99         },
100         [SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B] = {
101                 .name   = "Hauppauge Okemo-B",
102                 .type   = SMS_NOVA_B0,
103                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-nova-b-dvbt-01.fw",
104         },
105         [SMS1XXX_BOARD_HAUPPAUGE_WINDHAM] = {
106                 .name   = "Hauppauge WinTV MiniStick",
107                 .type   = SMS_NOVA_B0,
108                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
109                 .led_power = 26,
110                 .led_lo    = 27,
111                 .led_hi    = 28,
112         },
113         [SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD] = {
114                 .name   = "Hauppauge WinTV MiniCard",
115                 .type   = SMS_NOVA_B0,
116                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
117                 .lna_ctrl  = 29,
118         },
119         [SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2] = {
120                 .name   = "Hauppauge WinTV MiniCard",
121                 .type   = SMS_NOVA_B0,
122                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
123                 .lna_ctrl  = -1,
124         },
125 };
126
127 struct sms_board *sms_get_board(int id)
128 {
129         BUG_ON(id >= ARRAY_SIZE(sms_boards));
130
131         return &sms_boards[id];
132 }
133
134 static int sms_set_gpio(struct smscore_device_t *coredev, int pin, int enable)
135 {
136         int lvl, ret;
137         u32 gpio;
138         struct smscore_gpio_config gpioconfig = {
139                 .direction            = SMS_GPIO_DIRECTION_OUTPUT,
140                 .pullupdown           = SMS_GPIO_PULLUPDOWN_NONE,
141                 .inputcharacteristics = SMS_GPIO_INPUTCHARACTERISTICS_NORMAL,
142                 .outputslewrate       = SMS_GPIO_OUTPUTSLEWRATE_FAST,
143                 .outputdriving        = SMS_GPIO_OUTPUTDRIVING_4mA,
144         };
145
146         if (pin == 0)
147                 return -EINVAL;
148
149         if (pin < 0) {
150                 /* inverted gpio */
151                 gpio = pin * -1;
152                 lvl = enable ? 0 : 1;
153         } else {
154                 gpio = pin;
155                 lvl = enable ? 1 : 0;
156         }
157
158         ret = smscore_configure_gpio(coredev, gpio, &gpioconfig);
159         if (ret < 0)
160                 return ret;
161
162         return smscore_set_gpio(coredev, gpio, lvl);
163 }
164
165 int sms_board_setup(struct smscore_device_t *coredev)
166 {
167         int board_id = smscore_get_board_id(coredev);
168         struct sms_board *board = sms_get_board(board_id);
169
170         switch (board_id) {
171         case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
172                 /* turn off all LEDs */
173                 sms_set_gpio(coredev, board->led_power, 0);
174                 sms_set_gpio(coredev, board->led_hi, 0);
175                 sms_set_gpio(coredev, board->led_lo, 0);
176                 break;
177         case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
178         case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
179                 /* turn off LNA */
180                 sms_set_gpio(coredev, board->lna_ctrl, 0);
181                 break;
182         }
183         return 0;
184 }
185
186 int sms_board_power(struct smscore_device_t *coredev, int onoff)
187 {
188         int board_id = smscore_get_board_id(coredev);
189         struct sms_board *board = sms_get_board(board_id);
190
191         switch (board_id) {
192         case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
193                 /* power LED */
194                 sms_set_gpio(coredev,
195                              board->led_power, onoff ? 1 : 0);
196                 break;
197         case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
198         case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
199                 /* LNA */
200                 sms_set_gpio(coredev,
201                              board->lna_ctrl, onoff ? 1 : 0);
202                 break;
203         }
204         return 0;
205 }
206
207 int sms_board_led_feedback(struct smscore_device_t *coredev, int led)
208 {
209         int board_id = smscore_get_board_id(coredev);
210         struct sms_board *board = sms_get_board(board_id);
211
212         /* dont touch GPIO if LEDs are already set */
213         if (smscore_led_state(coredev, -1) == led)
214                 return 0;
215
216         switch (board_id) {
217         case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
218                 sms_set_gpio(coredev,
219                              board->led_lo, (led & SMS_LED_LO) ? 1 : 0);
220                 sms_set_gpio(coredev,
221                              board->led_hi, (led & SMS_LED_HI) ? 1 : 0);
222
223                 smscore_led_state(coredev, led);
224                 break;
225         }
226         return 0;
227 }