xref: /linux/drivers/media/common/siano/sms-cards.c (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
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 struct sms_board sms_boards[] = {
25 	[SMS_BOARD_UNKNOWN] = {
26 		.name	= "Unknown board",
27 		.type = SMS_UNKNOWN_TYPE,
28 		.default_mode = DEVICE_MODE_NONE,
29 	},
30 	[SMS1XXX_BOARD_SIANO_STELLAR] = {
31 		.name	= "Siano Stellar Digital Receiver",
32 		.type	= SMS_STELLAR,
33 		.default_mode = DEVICE_MODE_DVBT_BDA,
34 	},
35 	[SMS1XXX_BOARD_SIANO_NOVA_A] = {
36 		.name	= "Siano Nova A Digital Receiver",
37 		.type	= SMS_NOVA_A0,
38 		.default_mode = DEVICE_MODE_DVBT_BDA,
39 	},
40 	[SMS1XXX_BOARD_SIANO_NOVA_B] = {
41 		.name	= "Siano Nova B Digital Receiver",
42 		.type	= SMS_NOVA_B0,
43 		.default_mode = DEVICE_MODE_DVBT_BDA,
44 	},
45 	[SMS1XXX_BOARD_SIANO_VEGA] = {
46 		.name	= "Siano Vega Digital Receiver",
47 		.type	= SMS_VEGA,
48 		.default_mode = DEVICE_MODE_CMMB,
49 	},
50 	[SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT] = {
51 		.name	= "Hauppauge Catamount",
52 		.type	= SMS_STELLAR,
53 		.fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_STELLAR,
54 		.default_mode = DEVICE_MODE_DVBT_BDA,
55 	},
56 	[SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A] = {
57 		.name	= "Hauppauge Okemo-A",
58 		.type	= SMS_NOVA_A0,
59 		.fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_NOVA_A,
60 		.default_mode = DEVICE_MODE_DVBT_BDA,
61 	},
62 	[SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B] = {
63 		.name	= "Hauppauge Okemo-B",
64 		.type	= SMS_NOVA_B0,
65 		.fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_NOVA_B,
66 		.default_mode = DEVICE_MODE_DVBT_BDA,
67 	},
68 	[SMS1XXX_BOARD_HAUPPAUGE_WINDHAM] = {
69 		.name	= "Hauppauge WinTV MiniStick",
70 		.type	= SMS_NOVA_B0,
71 		.fw[DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_HCW_55XXX,
72 		.fw[DEVICE_MODE_DVBT_BDA]  = SMS_FW_DVBT_HCW_55XXX,
73 		.default_mode = DEVICE_MODE_DVBT_BDA,
74 		.rc_codes = RC_MAP_HAUPPAUGE,
75 		.board_cfg.leds_power = 26,
76 		.board_cfg.led0 = 27,
77 		.board_cfg.led1 = 28,
78 		.board_cfg.ir = 9,
79 		.led_power = 26,
80 		.led_lo    = 27,
81 		.led_hi    = 28,
82 	},
83 	[SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD] = {
84 		.name	= "Hauppauge WinTV MiniCard",
85 		.type	= SMS_NOVA_B0,
86 		.fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_HCW_55XXX,
87 		.default_mode = DEVICE_MODE_DVBT_BDA,
88 		.lna_ctrl  = 29,
89 		.board_cfg.foreign_lna0_ctrl = 29,
90 		.rf_switch = 17,
91 		.board_cfg.rf_switch_uhf = 17,
92 	},
93 	[SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2] = {
94 		.name	= "Hauppauge WinTV MiniCard",
95 		.type	= SMS_NOVA_B0,
96 		.fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVBT_HCW_55XXX,
97 		.default_mode = DEVICE_MODE_DVBT_BDA,
98 		.lna_ctrl  = -1,
99 	},
100 	[SMS1XXX_BOARD_SIANO_NICE] = {
101 		.name = "Siano Nice Digital Receiver",
102 		.type = SMS_NOVA_B0,
103 		.default_mode = DEVICE_MODE_DVBT_BDA,
104 	},
105 	[SMS1XXX_BOARD_SIANO_VENICE] = {
106 		.name = "Siano Venice Digital Receiver",
107 		.type = SMS_VEGA,
108 		.default_mode = DEVICE_MODE_CMMB,
109 	},
110 	[SMS1XXX_BOARD_SIANO_STELLAR_ROM] = {
111 		.name = "Siano Stellar Digital Receiver ROM",
112 		.type = SMS_STELLAR,
113 		.default_mode = DEVICE_MODE_DVBT_BDA,
114 		.intf_num = 1,
115 	},
116 	[SMS1XXX_BOARD_ZTE_DVB_DATA_CARD] = {
117 		.name = "ZTE Data Card Digital Receiver",
118 		.type = SMS_NOVA_B0,
119 		.default_mode = DEVICE_MODE_DVBT_BDA,
120 		.intf_num = 5,
121 		.mtu = 15792,
122 	},
123 	[SMS1XXX_BOARD_ONDA_MDTV_DATA_CARD] = {
124 		.name = "ONDA Data Card Digital Receiver",
125 		.type = SMS_NOVA_B0,
126 		.default_mode = DEVICE_MODE_DVBT_BDA,
127 		.intf_num = 6,
128 		.mtu = 15792,
129 	},
130 	[SMS1XXX_BOARD_SIANO_MING] = {
131 		.name = "Siano Ming Digital Receiver",
132 		.type = SMS_MING,
133 		.default_mode = DEVICE_MODE_CMMB,
134 	},
135 	[SMS1XXX_BOARD_SIANO_PELE] = {
136 		.name = "Siano Pele Digital Receiver",
137 		.type = SMS_PELE,
138 		.default_mode = DEVICE_MODE_ISDBT_BDA,
139 	},
140 	[SMS1XXX_BOARD_SIANO_RIO] = {
141 		.name = "Siano Rio Digital Receiver",
142 		.type = SMS_RIO,
143 		.default_mode = DEVICE_MODE_ISDBT_BDA,
144 	},
145 	[SMS1XXX_BOARD_SIANO_DENVER_1530] = {
146 		.name = "Siano Denver (ATSC-M/H) Digital Receiver",
147 		.type = SMS_DENVER_1530,
148 		.default_mode = DEVICE_MODE_ATSC,
149 		.crystal = 2400,
150 	},
151 	[SMS1XXX_BOARD_SIANO_DENVER_2160] = {
152 		.name = "Siano Denver (TDMB) Digital Receiver",
153 		.type = SMS_DENVER_2160,
154 		.default_mode = DEVICE_MODE_DAB_TDMB,
155 	},
156 	[SMS1XXX_BOARD_PCTV_77E] = {
157 		.name	= "Hauppauge microStick 77e",
158 		.type	= SMS_NOVA_B0,
159 		.fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVB_NOVA_12MHZ_B0,
160 		.default_mode = DEVICE_MODE_DVBT_BDA,
161 	},
162 };
163 
164 struct sms_board *sms_get_board(unsigned id)
165 {
166 	BUG_ON(id >= ARRAY_SIZE(sms_boards));
167 
168 	return &sms_boards[id];
169 }
170 EXPORT_SYMBOL_GPL(sms_get_board);
171 static inline void sms_gpio_assign_11xx_default_led_config(
172 		struct smscore_config_gpio *p_gpio_config) {
173 	p_gpio_config->direction = SMS_GPIO_DIRECTION_OUTPUT;
174 	p_gpio_config->inputcharacteristics =
175 		SMS_GPIO_INPUTCHARACTERISTICS_NORMAL;
176 	p_gpio_config->outputdriving = SMS_GPIO_OUTPUTDRIVING_4mA;
177 	p_gpio_config->outputslewrate = SMS_GPIO_OUTPUT_SLEW_RATE_0_45_V_NS;
178 	p_gpio_config->pullupdown = SMS_GPIO_PULLUPDOWN_NONE;
179 }
180 
181 int sms_board_event(struct smscore_device_t *coredev,
182 		    enum SMS_BOARD_EVENTS gevent)
183 {
184 	struct smscore_config_gpio my_gpio_config;
185 
186 	sms_gpio_assign_11xx_default_led_config(&my_gpio_config);
187 
188 	switch (gevent) {
189 	case BOARD_EVENT_POWER_INIT: /* including hotplug */
190 		break; /* BOARD_EVENT_BIND */
191 
192 	case BOARD_EVENT_POWER_SUSPEND:
193 		break; /* BOARD_EVENT_POWER_SUSPEND */
194 
195 	case BOARD_EVENT_POWER_RESUME:
196 		break; /* BOARD_EVENT_POWER_RESUME */
197 
198 	case BOARD_EVENT_BIND:
199 		break; /* BOARD_EVENT_BIND */
200 
201 	case BOARD_EVENT_SCAN_PROG:
202 		break; /* BOARD_EVENT_SCAN_PROG */
203 	case BOARD_EVENT_SCAN_COMP:
204 		break; /* BOARD_EVENT_SCAN_COMP */
205 	case BOARD_EVENT_EMERGENCY_WARNING_SIGNAL:
206 		break; /* BOARD_EVENT_EMERGENCY_WARNING_SIGNAL */
207 	case BOARD_EVENT_FE_LOCK:
208 		break; /* BOARD_EVENT_FE_LOCK */
209 	case BOARD_EVENT_FE_UNLOCK:
210 		break; /* BOARD_EVENT_FE_UNLOCK */
211 	case BOARD_EVENT_DEMOD_LOCK:
212 		break; /* BOARD_EVENT_DEMOD_LOCK */
213 	case BOARD_EVENT_DEMOD_UNLOCK:
214 		break; /* BOARD_EVENT_DEMOD_UNLOCK */
215 	case BOARD_EVENT_RECEPTION_MAX_4:
216 		break; /* BOARD_EVENT_RECEPTION_MAX_4 */
217 	case BOARD_EVENT_RECEPTION_3:
218 		break; /* BOARD_EVENT_RECEPTION_3 */
219 	case BOARD_EVENT_RECEPTION_2:
220 		break; /* BOARD_EVENT_RECEPTION_2 */
221 	case BOARD_EVENT_RECEPTION_1:
222 		break; /* BOARD_EVENT_RECEPTION_1 */
223 	case BOARD_EVENT_RECEPTION_LOST_0:
224 		break; /* BOARD_EVENT_RECEPTION_LOST_0 */
225 	case BOARD_EVENT_MULTIPLEX_OK:
226 		break; /* BOARD_EVENT_MULTIPLEX_OK */
227 	case BOARD_EVENT_MULTIPLEX_ERRORS:
228 		break; /* BOARD_EVENT_MULTIPLEX_ERRORS */
229 
230 	default:
231 		pr_err("Unknown SMS board event\n");
232 		break;
233 	}
234 	return 0;
235 }
236 EXPORT_SYMBOL_GPL(sms_board_event);
237 
238 static int sms_set_gpio(struct smscore_device_t *coredev, int pin, int enable)
239 {
240 	int lvl, ret;
241 	u32 gpio;
242 	struct smscore_config_gpio gpioconfig = {
243 		.direction            = SMS_GPIO_DIRECTION_OUTPUT,
244 		.pullupdown           = SMS_GPIO_PULLUPDOWN_NONE,
245 		.inputcharacteristics = SMS_GPIO_INPUTCHARACTERISTICS_NORMAL,
246 		.outputslewrate       = SMS_GPIO_OUTPUT_SLEW_RATE_FAST,
247 		.outputdriving        = SMS_GPIO_OUTPUTDRIVING_S_4mA,
248 	};
249 
250 	if (pin == 0)
251 		return -EINVAL;
252 
253 	if (pin < 0) {
254 		/* inverted gpio */
255 		gpio = pin * -1;
256 		lvl = enable ? 0 : 1;
257 	} else {
258 		gpio = pin;
259 		lvl = enable ? 1 : 0;
260 	}
261 
262 	ret = smscore_configure_gpio(coredev, gpio, &gpioconfig);
263 	if (ret < 0)
264 		return ret;
265 
266 	return smscore_set_gpio(coredev, gpio, lvl);
267 }
268 
269 int sms_board_setup(struct smscore_device_t *coredev)
270 {
271 	int board_id = smscore_get_board_id(coredev);
272 	struct sms_board *board = sms_get_board(board_id);
273 
274 	switch (board_id) {
275 	case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
276 		/* turn off all LEDs */
277 		sms_set_gpio(coredev, board->led_power, 0);
278 		sms_set_gpio(coredev, board->led_hi, 0);
279 		sms_set_gpio(coredev, board->led_lo, 0);
280 		break;
281 	case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
282 	case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
283 		/* turn off LNA */
284 		sms_set_gpio(coredev, board->lna_ctrl, 0);
285 		break;
286 	}
287 	return 0;
288 }
289 EXPORT_SYMBOL_GPL(sms_board_setup);
290 
291 int sms_board_power(struct smscore_device_t *coredev, int onoff)
292 {
293 	int board_id = smscore_get_board_id(coredev);
294 	struct sms_board *board = sms_get_board(board_id);
295 
296 	switch (board_id) {
297 	case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
298 		/* power LED */
299 		sms_set_gpio(coredev,
300 			     board->led_power, onoff ? 1 : 0);
301 		break;
302 	case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
303 	case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
304 		/* LNA */
305 		if (!onoff)
306 			sms_set_gpio(coredev, board->lna_ctrl, 0);
307 		break;
308 	}
309 	return 0;
310 }
311 EXPORT_SYMBOL_GPL(sms_board_power);
312 
313 int sms_board_led_feedback(struct smscore_device_t *coredev, int led)
314 {
315 	int board_id = smscore_get_board_id(coredev);
316 	struct sms_board *board = sms_get_board(board_id);
317 
318 	/* dont touch GPIO if LEDs are already set */
319 	if (smscore_led_state(coredev, -1) == led)
320 		return 0;
321 
322 	switch (board_id) {
323 	case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
324 		sms_set_gpio(coredev,
325 			     board->led_lo, (led & SMS_LED_LO) ? 1 : 0);
326 		sms_set_gpio(coredev,
327 			     board->led_hi, (led & SMS_LED_HI) ? 1 : 0);
328 
329 		smscore_led_state(coredev, led);
330 		break;
331 	}
332 	return 0;
333 }
334 EXPORT_SYMBOL_GPL(sms_board_led_feedback);
335 
336 int sms_board_lna_control(struct smscore_device_t *coredev, int onoff)
337 {
338 	int board_id = smscore_get_board_id(coredev);
339 	struct sms_board *board = sms_get_board(board_id);
340 
341 	pr_debug("%s: LNA %s\n", __func__, onoff ? "enabled" : "disabled");
342 
343 	switch (board_id) {
344 	case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
345 	case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
346 		sms_set_gpio(coredev,
347 			     board->rf_switch, onoff ? 1 : 0);
348 		return sms_set_gpio(coredev,
349 				    board->lna_ctrl, onoff ? 1 : 0);
350 	}
351 	return -EINVAL;
352 }
353 EXPORT_SYMBOL_GPL(sms_board_lna_control);
354 
355 int sms_board_load_modules(int id)
356 {
357 	request_module("smsdvb");
358 	return 0;
359 }
360 EXPORT_SYMBOL_GPL(sms_board_load_modules);
361