xref: /linux/drivers/media/common/siano/sms-cards.c (revision 27eb2c4b3d3e13f376a359e293c212a2e9407af5)
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 #include "smsir.h"
22 #include <linux/module.h>
23 
24 static int sms_dbg;
25 module_param_named(cards_dbg, sms_dbg, int, 0644);
26 MODULE_PARM_DESC(cards_dbg, "set debug level (info=1, adv=2 (or-able))");
27 
28 static struct sms_board sms_boards[] = {
29 	[SMS_BOARD_UNKNOWN] = {
30 		.name	= "Unknown board",
31 		.type = SMS_UNKNOWN_TYPE,
32 		.default_mode = DEVICE_MODE_NONE,
33 	},
34 	[SMS1XXX_BOARD_SIANO_STELLAR] = {
35 		.name	= "Siano Stellar Digital Receiver",
36 		.type	= SMS_STELLAR,
37 		.default_mode = DEVICE_MODE_DVBT_BDA,
38 	},
39 	[SMS1XXX_BOARD_SIANO_NOVA_A] = {
40 		.name	= "Siano Nova A Digital Receiver",
41 		.type	= SMS_NOVA_A0,
42 		.default_mode = DEVICE_MODE_DVBT_BDA,
43 	},
44 	[SMS1XXX_BOARD_SIANO_NOVA_B] = {
45 		.name	= "Siano Nova B Digital Receiver",
46 		.type	= SMS_NOVA_B0,
47 		.default_mode = DEVICE_MODE_DVBT_BDA,
48 	},
49 	[SMS1XXX_BOARD_SIANO_VEGA] = {
50 		.name	= "Siano Vega Digital Receiver",
51 		.type	= SMS_VEGA,
52 		.default_mode = DEVICE_MODE_CMMB,
53 	},
54 	[SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT] = {
55 		.name	= "Hauppauge Catamount",
56 		.type	= SMS_STELLAR,
57 		.fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_STELLAR,
58 		.default_mode = DEVICE_MODE_DVBT_BDA,
59 	},
60 	[SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A] = {
61 		.name	= "Hauppauge Okemo-A",
62 		.type	= SMS_NOVA_A0,
63 		.fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_NOVA_A,
64 		.default_mode = DEVICE_MODE_DVBT_BDA,
65 	},
66 	[SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B] = {
67 		.name	= "Hauppauge Okemo-B",
68 		.type	= SMS_NOVA_B0,
69 		.fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_NOVA_B,
70 		.default_mode = DEVICE_MODE_DVBT_BDA,
71 	},
72 	[SMS1XXX_BOARD_HAUPPAUGE_WINDHAM] = {
73 		.name	= "Hauppauge WinTV MiniStick",
74 		.type	= SMS_NOVA_B0,
75 		.fw[DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_HCW_55XXX,
76 		.fw[DEVICE_MODE_DVBT_BDA]  = SMS_FW_DVBT_HCW_55XXX,
77 		.default_mode = DEVICE_MODE_DVBT_BDA,
78 		.rc_codes = RC_MAP_HAUPPAUGE,
79 		.board_cfg.leds_power = 26,
80 		.board_cfg.led0 = 27,
81 		.board_cfg.led1 = 28,
82 		.board_cfg.ir = 9,
83 		.led_power = 26,
84 		.led_lo    = 27,
85 		.led_hi    = 28,
86 	},
87 	[SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD] = {
88 		.name	= "Hauppauge WinTV MiniCard",
89 		.type	= SMS_NOVA_B0,
90 		.fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_HCW_55XXX,
91 		.default_mode = DEVICE_MODE_DVBT_BDA,
92 		.lna_ctrl  = 29,
93 		.board_cfg.foreign_lna0_ctrl = 29,
94 		.rf_switch = 17,
95 		.board_cfg.rf_switch_uhf = 17,
96 	},
97 	[SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2] = {
98 		.name	= "Hauppauge WinTV MiniCard",
99 		.type	= SMS_NOVA_B0,
100 		.fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_HCW_55XXX,
101 		.default_mode = DEVICE_MODE_DVBT_BDA,
102 		.lna_ctrl  = -1,
103 	},
104 	[SMS1XXX_BOARD_SIANO_NICE] = {
105 		.name = "Siano Nice Digital Receiver",
106 		.type = SMS_NOVA_B0,
107 		.default_mode = DEVICE_MODE_DVBT_BDA,
108 	},
109 	[SMS1XXX_BOARD_SIANO_VENICE] = {
110 		.name = "Siano Venice Digital Receiver",
111 		.type = SMS_VEGA,
112 		.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,
159 	},
160 };
161 
162 struct sms_board *sms_get_board(unsigned id)
163 {
164 	BUG_ON(id >= ARRAY_SIZE(sms_boards));
165 
166 	return &sms_boards[id];
167 }
168 EXPORT_SYMBOL_GPL(sms_get_board);
169 static inline void sms_gpio_assign_11xx_default_led_config(
170 		struct smscore_config_gpio *p_gpio_config) {
171 	p_gpio_config->direction = SMS_GPIO_DIRECTION_OUTPUT;
172 	p_gpio_config->inputcharacteristics =
173 		SMS_GPIO_INPUTCHARACTERISTICS_NORMAL;
174 	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;
177 }
178 
179 int sms_board_event(struct smscore_device_t *coredev,
180 		    enum SMS_BOARD_EVENTS gevent)
181 {
182 	struct smscore_config_gpio my_gpio_config;
183 
184 	sms_gpio_assign_11xx_default_led_config(&my_gpio_config);
185 
186 	switch (gevent) {
187 	case BOARD_EVENT_POWER_INIT: /* including hotplug */
188 		break; /* BOARD_EVENT_BIND */
189 
190 	case BOARD_EVENT_POWER_SUSPEND:
191 		break; /* BOARD_EVENT_POWER_SUSPEND */
192 
193 	case BOARD_EVENT_POWER_RESUME:
194 		break; /* BOARD_EVENT_POWER_RESUME */
195 
196 	case BOARD_EVENT_BIND:
197 		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:
206 		break; /* BOARD_EVENT_FE_LOCK */
207 	case BOARD_EVENT_FE_UNLOCK:
208 		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:
224 		break; /* BOARD_EVENT_MULTIPLEX_OK */
225 	case BOARD_EVENT_MULTIPLEX_ERRORS:
226 		break; /* BOARD_EVENT_MULTIPLEX_ERRORS */
227 
228 	default:
229 		sms_err("Unknown SMS board event");
230 		break;
231 	}
232 	return 0;
233 }
234 EXPORT_SYMBOL_GPL(sms_board_event);
235 
236 static int sms_set_gpio(struct smscore_device_t *coredev, int pin, int enable)
237 {
238 	int lvl, ret;
239 	u32 gpio;
240 	struct smscore_config_gpio gpioconfig = {
241 		.direction            = SMS_GPIO_DIRECTION_OUTPUT,
242 		.pullupdown           = SMS_GPIO_PULLUPDOWN_NONE,
243 		.inputcharacteristics = SMS_GPIO_INPUTCHARACTERISTICS_NORMAL,
244 		.outputslewrate       = SMS_GPIO_OUTPUT_SLEW_RATE_FAST,
245 		.outputdriving        = SMS_GPIO_OUTPUTDRIVING_S_4mA,
246 	};
247 
248 	if (pin == 0)
249 		return -EINVAL;
250 
251 	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 	}
259 
260 	ret = smscore_configure_gpio(coredev, gpio, &gpioconfig);
261 	if (ret < 0)
262 		return ret;
263 
264 	return smscore_set_gpio(coredev, gpio, lvl);
265 }
266 
267 int 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;
279 	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;
284 	}
285 	return 0;
286 }
287 EXPORT_SYMBOL_GPL(sms_board_setup);
288 
289 int 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;
300 	case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
301 	case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
302 		/* LNA */
303 		if (!onoff)
304 			sms_set_gpio(coredev, board->lna_ctrl, 0);
305 		break;
306 	}
307 	return 0;
308 }
309 EXPORT_SYMBOL_GPL(sms_board_power);
310 
311 int 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 }
332 EXPORT_SYMBOL_GPL(sms_board_led_feedback);
333 
334 int 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 }
351 EXPORT_SYMBOL_GPL(sms_board_lna_control);
352 
353 int sms_board_load_modules(int id)
354 {
355 	request_module("smsdvb");
356 	return 0;
357 }
358 EXPORT_SYMBOL_GPL(sms_board_load_modules);
359