blob: 82769993eeb7b390cc5441cffc9bf5096b6411a9 [file] [log] [blame]
Michael Krufky1c11d542008-06-18 22:09:55 -03001/*
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
Michael Krufky09a29b72008-09-03 16:48:17 -03007 * it under the terms of the GNU General Public License version 2 as
Michael Krufky1c11d542008-06-18 22:09:55 -03008 * 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"
Uri Shkolnik90f944a2009-05-14 16:32:12 -030021#include "smsir.h"
Paul Gortmaker7a707b82011-07-03 14:03:12 -040022#include <linux/module.h>
Michael Krufky1c11d542008-06-18 22:09:55 -030023
Michael Krufky0d02efe2009-02-27 02:42:16 -030024static int sms_dbg;
25module_param_named(cards_dbg, sms_dbg, int, 0644);
26MODULE_PARM_DESC(cards_dbg, "set debug level (info=1, adv=2 (or-able))");
27
Michael Krufky1c11d542008-06-18 22:09:55 -030028static struct sms_board sms_boards[] = {
29 [SMS_BOARD_UNKNOWN] = {
30 .name = "Unknown board",
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -030031 .type = SMS_UNKNOWN_TYPE,
32 .default_mode = DEVICE_MODE_NONE,
Michael Krufky1c11d542008-06-18 22:09:55 -030033 },
Michael Krufky1c11d542008-06-18 22:09:55 -030034 [SMS1XXX_BOARD_SIANO_STELLAR] = {
Michael Krufkycf1cfe12008-06-28 16:45:36 -030035 .name = "Siano Stellar Digital Receiver",
Michael Krufky1c11d542008-06-18 22:09:55 -030036 .type = SMS_STELLAR,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -030037 .default_mode = DEVICE_MODE_DVBT_BDA,
Michael Krufky1c11d542008-06-18 22:09:55 -030038 },
39 [SMS1XXX_BOARD_SIANO_NOVA_A] = {
Michael Krufkycf1cfe12008-06-28 16:45:36 -030040 .name = "Siano Nova A Digital Receiver",
Michael Krufky1c11d542008-06-18 22:09:55 -030041 .type = SMS_NOVA_A0,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -030042 .default_mode = DEVICE_MODE_DVBT_BDA,
Michael Krufky1c11d542008-06-18 22:09:55 -030043 },
44 [SMS1XXX_BOARD_SIANO_NOVA_B] = {
Michael Krufkycf1cfe12008-06-28 16:45:36 -030045 .name = "Siano Nova B Digital Receiver",
Michael Krufky1c11d542008-06-18 22:09:55 -030046 .type = SMS_NOVA_B0,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -030047 .default_mode = DEVICE_MODE_DVBT_BDA,
Michael Krufky1c11d542008-06-18 22:09:55 -030048 },
49 [SMS1XXX_BOARD_SIANO_VEGA] = {
Michael Krufkycf1cfe12008-06-28 16:45:36 -030050 .name = "Siano Vega Digital Receiver",
Michael Krufky1c11d542008-06-18 22:09:55 -030051 .type = SMS_VEGA,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -030052 .default_mode = DEVICE_MODE_CMMB,
Michael Krufky1c11d542008-06-18 22:09:55 -030053 },
Michael Krufky44f71c32008-06-28 23:55:36 -030054 [SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT] = {
55 .name = "Hauppauge Catamount",
56 .type = SMS_STELLAR,
Mauro Carvalho Chehab11ad03a2013-03-19 17:02:54 -030057 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_STELLAR,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -030058 .default_mode = DEVICE_MODE_DVBT_BDA,
Michael Krufky44f71c32008-06-28 23:55:36 -030059 },
60 [SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A] = {
61 .name = "Hauppauge Okemo-A",
62 .type = SMS_NOVA_A0,
Mauro Carvalho Chehab11ad03a2013-03-19 17:02:54 -030063 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_NOVA_A,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -030064 .default_mode = DEVICE_MODE_DVBT_BDA,
Michael Krufky44f71c32008-06-28 23:55:36 -030065 },
66 [SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B] = {
67 .name = "Hauppauge Okemo-B",
68 .type = SMS_NOVA_B0,
Mauro Carvalho Chehab11ad03a2013-03-19 17:02:54 -030069 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_NOVA_B,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -030070 .default_mode = DEVICE_MODE_DVBT_BDA,
Michael Krufky44f71c32008-06-28 23:55:36 -030071 },
72 [SMS1XXX_BOARD_HAUPPAUGE_WINDHAM] = {
Michael Krufky7a9b5fc2008-09-11 23:02:12 -030073 .name = "Hauppauge WinTV MiniStick",
Michael Krufky44f71c32008-06-28 23:55:36 -030074 .type = SMS_NOVA_B0,
Mauro Carvalho Chehab11ad03a2013-03-19 17:02:54 -030075 .fw[DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_HCW_55XXX,
76 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_HCW_55XXX,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -030077 .default_mode = DEVICE_MODE_DVBT_BDA,
Mauro Carvalho Chehab15195d32011-01-24 12:18:47 -030078 .rc_codes = RC_MAP_HAUPPAUGE,
Uri Shkolnik9504cca2009-05-14 16:34:59 -030079 .board_cfg.leds_power = 26,
80 .board_cfg.led0 = 27,
81 .board_cfg.led1 = 28,
Mauro Carvalho Chehab20d64442010-08-01 13:01:40 -030082 .board_cfg.ir = 9,
Michael Krufky250fa672008-11-16 22:45:42 -030083 .led_power = 26,
84 .led_lo = 27,
85 .led_hi = 28,
Michael Krufky44f71c32008-06-28 23:55:36 -030086 },
Michael Krufky3f7d99f2008-11-22 11:21:02 -030087 [SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD] = {
88 .name = "Hauppauge WinTV MiniCard",
89 .type = SMS_NOVA_B0,
Mauro Carvalho Chehab11ad03a2013-03-19 17:02:54 -030090 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_HCW_55XXX,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -030091 .default_mode = DEVICE_MODE_DVBT_BDA,
Michael Krufky250fa672008-11-16 22:45:42 -030092 .lna_ctrl = 29,
Uri Shkolnik9504cca2009-05-14 16:34:59 -030093 .board_cfg.foreign_lna0_ctrl = 29,
Michael Krufkyd54093a2008-12-16 02:56:08 -030094 .rf_switch = 17,
Uri Shkolnik9504cca2009-05-14 16:34:59 -030095 .board_cfg.rf_switch_uhf = 17,
Michael Krufky250fa672008-11-16 22:45:42 -030096 },
97 [SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2] = {
98 .name = "Hauppauge WinTV MiniCard",
99 .type = SMS_NOVA_B0,
Mauro Carvalho Chehab11ad03a2013-03-19 17:02:54 -0300100 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_HCW_55XXX,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -0300101 .default_mode = DEVICE_MODE_DVBT_BDA,
Michael Krufkyf4c82542008-12-15 17:28:41 -0300102 .lna_ctrl = -1,
Michael Krufky3f7d99f2008-11-22 11:21:02 -0300103 },
Uri Shkolnikd0b661802009-05-19 09:51:41 -0300104 [SMS1XXX_BOARD_SIANO_NICE] = {
Uri Shkolnikd0b661802009-05-19 09:51:41 -0300105 .name = "Siano Nice Digital Receiver",
106 .type = SMS_NOVA_B0,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -0300107 .default_mode = DEVICE_MODE_DVBT_BDA,
Uri Shkolnikd0b661802009-05-19 09:51:41 -0300108 },
109 [SMS1XXX_BOARD_SIANO_VENICE] = {
Uri Shkolnikd0b661802009-05-19 09:51:41 -0300110 .name = "Siano Venice Digital Receiver",
111 .type = SMS_VEGA,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -0300112 .default_mode = DEVICE_MODE_CMMB,
113 },
114 [SMS1XXX_BOARD_SIANO_STELLAR_ROM] = {
115 .name = "Siano Stellar Digital Receiver ROM",
116 .type = SMS_STELLAR,
117 .default_mode = DEVICE_MODE_DVBT_BDA,
118 .intf_num = 1,
119 },
120 [SMS1XXX_BOARD_ZTE_DVB_DATA_CARD] = {
121 .name = "ZTE Data Card Digital Receiver",
122 .type = SMS_NOVA_B0,
123 .default_mode = DEVICE_MODE_DVBT_BDA,
124 .intf_num = 5,
125 .mtu = 15792,
126 },
127 [SMS1XXX_BOARD_ONDA_MDTV_DATA_CARD] = {
128 .name = "ONDA Data Card Digital Receiver",
129 .type = SMS_NOVA_B0,
130 .default_mode = DEVICE_MODE_DVBT_BDA,
131 .intf_num = 6,
132 .mtu = 15792,
133 },
134 [SMS1XXX_BOARD_SIANO_MING] = {
135 .name = "Siano Ming Digital Receiver",
136 .type = SMS_MING,
137 .default_mode = DEVICE_MODE_CMMB,
138 },
139 [SMS1XXX_BOARD_SIANO_PELE] = {
140 .name = "Siano Pele Digital Receiver",
141 .type = SMS_PELE,
142 .default_mode = DEVICE_MODE_ISDBT_BDA,
143 },
144 [SMS1XXX_BOARD_SIANO_RIO] = {
145 .name = "Siano Rio Digital Receiver",
146 .type = SMS_RIO,
147 .default_mode = DEVICE_MODE_ISDBT_BDA,
148 },
149 [SMS1XXX_BOARD_SIANO_DENVER_1530] = {
150 .name = "Siano Denver (ATSC-M/H) Digital Receiver",
151 .type = SMS_DENVER_1530,
152 .default_mode = DEVICE_MODE_ATSC,
153 .crystal = 2400,
154 },
155 [SMS1XXX_BOARD_SIANO_DENVER_2160] = {
156 .name = "Siano Denver (TDMB) Digital Receiver",
157 .type = SMS_DENVER_2160,
158 .default_mode = DEVICE_MODE_DAB_TDMB,
Uri Shkolnikd0b661802009-05-19 09:51:41 -0300159 },
Michael Krufky1c11d542008-06-18 22:09:55 -0300160};
161
Roel Kluin3a054622009-11-17 19:43:40 -0300162struct sms_board *sms_get_board(unsigned id)
Michael Krufky1c11d542008-06-18 22:09:55 -0300163{
164 BUG_ON(id >= ARRAY_SIZE(sms_boards));
165
166 return &sms_boards[id];
167}
Michael Krufkya0beec82009-02-26 18:32:36 -0300168EXPORT_SYMBOL_GPL(sms_get_board);
Uri Shkolnik5b8db892009-05-19 12:18:40 -0300169static inline void sms_gpio_assign_11xx_default_led_config(
Mauro Carvalho Chehabdfef84f2013-03-21 08:49:43 -0300170 struct smscore_config_gpio *p_gpio_config) {
171 p_gpio_config->direction = SMS_GPIO_DIRECTION_OUTPUT;
172 p_gpio_config->inputcharacteristics =
Mauro Carvalho Chehabc31b9fb2013-03-06 08:30:08 -0300173 SMS_GPIO_INPUTCHARACTERISTICS_NORMAL;
Mauro Carvalho Chehabdfef84f2013-03-21 08:49:43 -0300174 p_gpio_config->outputdriving = SMS_GPIO_OUTPUTDRIVING_4mA;
175 p_gpio_config->outputslewrate = SMS_GPIO_OUTPUT_SLEW_RATE_0_45_V_NS;
176 p_gpio_config->pullupdown = SMS_GPIO_PULLUPDOWN_NONE;
Uri Shkolnik5b8db892009-05-19 12:18:40 -0300177}
178
179int sms_board_event(struct smscore_device_t *coredev,
Mauro Carvalho Chehab347d8f12013-03-05 22:35:44 -0300180 enum SMS_BOARD_EVENTS gevent)
181{
Mauro Carvalho Chehab28a59df2013-03-21 09:27:37 -0300182 struct smscore_config_gpio my_gpio_config;
Uri Shkolnik5b8db892009-05-19 12:18:40 -0300183
Mauro Carvalho Chehab28a59df2013-03-21 09:27:37 -0300184 sms_gpio_assign_11xx_default_led_config(&my_gpio_config);
Uri Shkolnik5b8db892009-05-19 12:18:40 -0300185
186 switch (gevent) {
187 case BOARD_EVENT_POWER_INIT: /* including hotplug */
Uri Shkolnik5b8db892009-05-19 12:18:40 -0300188 break; /* BOARD_EVENT_BIND */
189
190 case BOARD_EVENT_POWER_SUSPEND:
Uri Shkolnik5b8db892009-05-19 12:18:40 -0300191 break; /* BOARD_EVENT_POWER_SUSPEND */
192
193 case BOARD_EVENT_POWER_RESUME:
Uri Shkolnik5b8db892009-05-19 12:18:40 -0300194 break; /* BOARD_EVENT_POWER_RESUME */
195
196 case BOARD_EVENT_BIND:
Uri Shkolnik5b8db892009-05-19 12:18:40 -0300197 break; /* BOARD_EVENT_BIND */
198
199 case BOARD_EVENT_SCAN_PROG:
200 break; /* BOARD_EVENT_SCAN_PROG */
201 case BOARD_EVENT_SCAN_COMP:
202 break; /* BOARD_EVENT_SCAN_COMP */
203 case BOARD_EVENT_EMERGENCY_WARNING_SIGNAL:
204 break; /* BOARD_EVENT_EMERGENCY_WARNING_SIGNAL */
205 case BOARD_EVENT_FE_LOCK:
Uri Shkolnik5b8db892009-05-19 12:18:40 -0300206 break; /* BOARD_EVENT_FE_LOCK */
207 case BOARD_EVENT_FE_UNLOCK:
Uri Shkolnik5b8db892009-05-19 12:18:40 -0300208 break; /* BOARD_EVENT_FE_UNLOCK */
209 case BOARD_EVENT_DEMOD_LOCK:
210 break; /* BOARD_EVENT_DEMOD_LOCK */
211 case BOARD_EVENT_DEMOD_UNLOCK:
212 break; /* BOARD_EVENT_DEMOD_UNLOCK */
213 case BOARD_EVENT_RECEPTION_MAX_4:
214 break; /* BOARD_EVENT_RECEPTION_MAX_4 */
215 case BOARD_EVENT_RECEPTION_3:
216 break; /* BOARD_EVENT_RECEPTION_3 */
217 case BOARD_EVENT_RECEPTION_2:
218 break; /* BOARD_EVENT_RECEPTION_2 */
219 case BOARD_EVENT_RECEPTION_1:
220 break; /* BOARD_EVENT_RECEPTION_1 */
221 case BOARD_EVENT_RECEPTION_LOST_0:
222 break; /* BOARD_EVENT_RECEPTION_LOST_0 */
223 case BOARD_EVENT_MULTIPLEX_OK:
Uri Shkolnik5b8db892009-05-19 12:18:40 -0300224 break; /* BOARD_EVENT_MULTIPLEX_OK */
225 case BOARD_EVENT_MULTIPLEX_ERRORS:
Uri Shkolnik5b8db892009-05-19 12:18:40 -0300226 break; /* BOARD_EVENT_MULTIPLEX_ERRORS */
227
228 default:
229 sms_err("Unknown SMS board event");
230 break;
231 }
232 return 0;
233}
234EXPORT_SYMBOL_GPL(sms_board_event);
Michael Krufky1c11d542008-06-18 22:09:55 -0300235
Michael Krufkydd72f312008-11-28 01:02:56 -0300236static int sms_set_gpio(struct smscore_device_t *coredev, int pin, int enable)
Michael Krufky250fa672008-11-16 22:45:42 -0300237{
Michael Krufkydd72f312008-11-28 01:02:56 -0300238 int lvl, ret;
239 u32 gpio;
Uri Shkolnik7c4ca792009-05-19 11:49:19 -0300240 struct smscore_config_gpio gpioconfig = {
Michael Krufky250fa672008-11-16 22:45:42 -0300241 .direction = SMS_GPIO_DIRECTION_OUTPUT,
242 .pullupdown = SMS_GPIO_PULLUPDOWN_NONE,
243 .inputcharacteristics = SMS_GPIO_INPUTCHARACTERISTICS_NORMAL,
Mauro Carvalho Chehabc31b9fb2013-03-06 08:30:08 -0300244 .outputslewrate = SMS_GPIO_OUTPUT_SLEW_RATE_FAST,
Mauro Carvalho Chehabf82757d2013-03-06 07:09:54 -0300245 .outputdriving = SMS_GPIO_OUTPUTDRIVING_S_4mA,
Michael Krufky250fa672008-11-16 22:45:42 -0300246 };
247
248 if (pin == 0)
249 return -EINVAL;
250
Michael Krufkydd72f312008-11-28 01:02:56 -0300251 if (pin < 0) {
252 /* inverted gpio */
253 gpio = pin * -1;
254 lvl = enable ? 0 : 1;
255 } else {
256 gpio = pin;
257 lvl = enable ? 1 : 0;
258 }
Michael Krufky250fa672008-11-16 22:45:42 -0300259
Michael Krufkydd72f312008-11-28 01:02:56 -0300260 ret = smscore_configure_gpio(coredev, gpio, &gpioconfig);
Michael Krufky250fa672008-11-16 22:45:42 -0300261 if (ret < 0)
262 return ret;
263
Michael Krufkydd72f312008-11-28 01:02:56 -0300264 return smscore_set_gpio(coredev, gpio, lvl);
Michael Krufky250fa672008-11-16 22:45:42 -0300265}
266
267int sms_board_setup(struct smscore_device_t *coredev)
268{
269 int board_id = smscore_get_board_id(coredev);
270 struct sms_board *board = sms_get_board(board_id);
271
272 switch (board_id) {
273 case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
274 /* turn off all LEDs */
275 sms_set_gpio(coredev, board->led_power, 0);
276 sms_set_gpio(coredev, board->led_hi, 0);
277 sms_set_gpio(coredev, board->led_lo, 0);
278 break;
Michael Krufkydff65742008-11-22 14:33:00 -0300279 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
280 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
281 /* turn off LNA */
282 sms_set_gpio(coredev, board->lna_ctrl, 0);
283 break;
Michael Krufky250fa672008-11-16 22:45:42 -0300284 }
285 return 0;
286}
Michael Krufkya0beec82009-02-26 18:32:36 -0300287EXPORT_SYMBOL_GPL(sms_board_setup);
Michael Krufky7a6fbed2008-11-22 14:26:37 -0300288
289int sms_board_power(struct smscore_device_t *coredev, int onoff)
290{
291 int board_id = smscore_get_board_id(coredev);
292 struct sms_board *board = sms_get_board(board_id);
293
294 switch (board_id) {
295 case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
296 /* power LED */
297 sms_set_gpio(coredev,
298 board->led_power, onoff ? 1 : 0);
299 break;
Michael Krufkydff65742008-11-22 14:33:00 -0300300 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
301 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
302 /* LNA */
Michael Krufkyd54093a2008-12-16 02:56:08 -0300303 if (!onoff)
304 sms_set_gpio(coredev, board->lna_ctrl, 0);
Michael Krufkydff65742008-11-22 14:33:00 -0300305 break;
Michael Krufky7a6fbed2008-11-22 14:26:37 -0300306 }
307 return 0;
308}
Michael Krufkya0beec82009-02-26 18:32:36 -0300309EXPORT_SYMBOL_GPL(sms_board_power);
Michael Krufky7b29e102008-11-22 15:32:19 -0300310
311int sms_board_led_feedback(struct smscore_device_t *coredev, int led)
312{
313 int board_id = smscore_get_board_id(coredev);
314 struct sms_board *board = sms_get_board(board_id);
315
316 /* dont touch GPIO if LEDs are already set */
317 if (smscore_led_state(coredev, -1) == led)
318 return 0;
319
320 switch (board_id) {
321 case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
322 sms_set_gpio(coredev,
323 board->led_lo, (led & SMS_LED_LO) ? 1 : 0);
324 sms_set_gpio(coredev,
325 board->led_hi, (led & SMS_LED_HI) ? 1 : 0);
326
327 smscore_led_state(coredev, led);
328 break;
329 }
330 return 0;
331}
Michael Krufkya0beec82009-02-26 18:32:36 -0300332EXPORT_SYMBOL_GPL(sms_board_led_feedback);
Michael Krufkyd54093a2008-12-16 02:56:08 -0300333
334int sms_board_lna_control(struct smscore_device_t *coredev, int onoff)
335{
336 int board_id = smscore_get_board_id(coredev);
337 struct sms_board *board = sms_get_board(board_id);
338
339 sms_debug("%s: LNA %s", __func__, onoff ? "enabled" : "disabled");
340
341 switch (board_id) {
342 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
343 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
344 sms_set_gpio(coredev,
345 board->rf_switch, onoff ? 1 : 0);
346 return sms_set_gpio(coredev,
347 board->lna_ctrl, onoff ? 1 : 0);
348 }
349 return -EINVAL;
350}
Michael Krufkya0beec82009-02-26 18:32:36 -0300351EXPORT_SYMBOL_GPL(sms_board_lna_control);
Michael Krufky05860f22008-08-31 17:39:58 -0300352
353int sms_board_load_modules(int id)
354{
Mauro Carvalho Chehab9e915e52013-03-07 11:35:00 -0300355 request_module("smsdvb");
Michael Krufky05860f22008-08-31 17:39:58 -0300356 return 0;
357}
Michael Krufkya0beec82009-02-26 18:32:36 -0300358EXPORT_SYMBOL_GPL(sms_board_load_modules);