Merge branch 'next' into for-linus
[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 static int sms_dbg;
23 module_param_named(cards_dbg, sms_dbg, int, 0644);
24 MODULE_PARM_DESC(cards_dbg, "set debug level (info=1, adv=2 (or-able))");
25
26 static struct sms_board sms_boards[] = {
27         [SMS_BOARD_UNKNOWN] = {
28                 .name   = "Unknown board",
29         },
30         [SMS1XXX_BOARD_SIANO_STELLAR] = {
31                 .name   = "Siano Stellar Digital Receiver",
32                 .type   = SMS_STELLAR,
33                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-stellar-dvbt-01.fw",
34         },
35         [SMS1XXX_BOARD_SIANO_NOVA_A] = {
36                 .name   = "Siano Nova A Digital Receiver",
37                 .type   = SMS_NOVA_A0,
38                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-nova-a-dvbt-01.fw",
39         },
40         [SMS1XXX_BOARD_SIANO_NOVA_B] = {
41                 .name   = "Siano Nova B Digital Receiver",
42                 .type   = SMS_NOVA_B0,
43                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-nova-b-dvbt-01.fw",
44         },
45         [SMS1XXX_BOARD_SIANO_VEGA] = {
46                 .name   = "Siano Vega Digital Receiver",
47                 .type   = SMS_VEGA,
48         },
49         [SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT] = {
50                 .name   = "Hauppauge Catamount",
51                 .type   = SMS_STELLAR,
52                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-stellar-dvbt-01.fw",
53         },
54         [SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A] = {
55                 .name   = "Hauppauge Okemo-A",
56                 .type   = SMS_NOVA_A0,
57                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-nova-a-dvbt-01.fw",
58         },
59         [SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B] = {
60                 .name   = "Hauppauge Okemo-B",
61                 .type   = SMS_NOVA_B0,
62                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-nova-b-dvbt-01.fw",
63         },
64         [SMS1XXX_BOARD_HAUPPAUGE_WINDHAM] = {
65                 .name   = "Hauppauge WinTV MiniStick",
66                 .type   = SMS_NOVA_B0,
67                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
68                 .led_power = 26,
69                 .led_lo    = 27,
70                 .led_hi    = 28,
71         },
72         [SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD] = {
73                 .name   = "Hauppauge WinTV MiniCard",
74                 .type   = SMS_NOVA_B0,
75                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
76                 .lna_ctrl  = 29,
77                 .rf_switch = 17,
78         },
79         [SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2] = {
80                 .name   = "Hauppauge WinTV MiniCard",
81                 .type   = SMS_NOVA_B0,
82                 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
83                 .lna_ctrl  = -1,
84         },
85 };
86
87 struct sms_board *sms_get_board(int id)
88 {
89         BUG_ON(id >= ARRAY_SIZE(sms_boards));
90
91         return &sms_boards[id];
92 }
93 EXPORT_SYMBOL_GPL(sms_get_board);
94
95 static int sms_set_gpio(struct smscore_device_t *coredev, int pin, int enable)
96 {
97         int lvl, ret;
98         u32 gpio;
99         struct smscore_gpio_config gpioconfig = {
100                 .direction            = SMS_GPIO_DIRECTION_OUTPUT,
101                 .pullupdown           = SMS_GPIO_PULLUPDOWN_NONE,
102                 .inputcharacteristics = SMS_GPIO_INPUTCHARACTERISTICS_NORMAL,
103                 .outputslewrate       = SMS_GPIO_OUTPUTSLEWRATE_FAST,
104                 .outputdriving        = SMS_GPIO_OUTPUTDRIVING_4mA,
105         };
106
107         if (pin == 0)
108                 return -EINVAL;
109
110         if (pin < 0) {
111                 /* inverted gpio */
112                 gpio = pin * -1;
113                 lvl = enable ? 0 : 1;
114         } else {
115                 gpio = pin;
116                 lvl = enable ? 1 : 0;
117         }
118
119         ret = smscore_configure_gpio(coredev, gpio, &gpioconfig);
120         if (ret < 0)
121                 return ret;
122
123         return smscore_set_gpio(coredev, gpio, lvl);
124 }
125
126 int sms_board_setup(struct smscore_device_t *coredev)
127 {
128         int board_id = smscore_get_board_id(coredev);
129         struct sms_board *board = sms_get_board(board_id);
130
131         switch (board_id) {
132         case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
133                 /* turn off all LEDs */
134                 sms_set_gpio(coredev, board->led_power, 0);
135                 sms_set_gpio(coredev, board->led_hi, 0);
136                 sms_set_gpio(coredev, board->led_lo, 0);
137                 break;
138         case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
139         case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
140                 /* turn off LNA */
141                 sms_set_gpio(coredev, board->lna_ctrl, 0);
142                 break;
143         }
144         return 0;
145 }
146 EXPORT_SYMBOL_GPL(sms_board_setup);
147
148 int sms_board_power(struct smscore_device_t *coredev, int onoff)
149 {
150         int board_id = smscore_get_board_id(coredev);
151         struct sms_board *board = sms_get_board(board_id);
152
153         switch (board_id) {
154         case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
155                 /* power LED */
156                 sms_set_gpio(coredev,
157                              board->led_power, onoff ? 1 : 0);
158                 break;
159         case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
160         case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
161                 /* LNA */
162                 if (!onoff)
163                         sms_set_gpio(coredev, board->lna_ctrl, 0);
164                 break;
165         }
166         return 0;
167 }
168 EXPORT_SYMBOL_GPL(sms_board_power);
169
170 int sms_board_led_feedback(struct smscore_device_t *coredev, int led)
171 {
172         int board_id = smscore_get_board_id(coredev);
173         struct sms_board *board = sms_get_board(board_id);
174
175         /* dont touch GPIO if LEDs are already set */
176         if (smscore_led_state(coredev, -1) == led)
177                 return 0;
178
179         switch (board_id) {
180         case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
181                 sms_set_gpio(coredev,
182                              board->led_lo, (led & SMS_LED_LO) ? 1 : 0);
183                 sms_set_gpio(coredev,
184                              board->led_hi, (led & SMS_LED_HI) ? 1 : 0);
185
186                 smscore_led_state(coredev, led);
187                 break;
188         }
189         return 0;
190 }
191 EXPORT_SYMBOL_GPL(sms_board_led_feedback);
192
193 int sms_board_lna_control(struct smscore_device_t *coredev, int onoff)
194 {
195         int board_id = smscore_get_board_id(coredev);
196         struct sms_board *board = sms_get_board(board_id);
197
198         sms_debug("%s: LNA %s", __func__, onoff ? "enabled" : "disabled");
199
200         switch (board_id) {
201         case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
202         case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
203                 sms_set_gpio(coredev,
204                              board->rf_switch, onoff ? 1 : 0);
205                 return sms_set_gpio(coredev,
206                                     board->lna_ctrl, onoff ? 1 : 0);
207         }
208         return -EINVAL;
209 }
210 EXPORT_SYMBOL_GPL(sms_board_lna_control);
211
212 int sms_board_load_modules(int id)
213 {
214         switch (id) {
215         case SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT:
216         case SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A:
217         case SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B:
218         case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
219                 request_module("smsdvb");
220                 break;
221         default:
222                 /* do nothing */
223                 break;
224         }
225         return 0;
226 }
227 EXPORT_SYMBOL_GPL(sms_board_load_modules);