Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sms-cards.c
Go to the documentation of this file.
1 /*
2  * Card-specific functions for the Siano SMS1xxx USB dongle
3  *
4  * Copyright (c) 2008 Michael Krufky <[email protected]>
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  },
33  .name = "Siano Stellar Digital Receiver",
34  .type = SMS_STELLAR,
35  },
37  .name = "Siano Nova A Digital Receiver",
38  .type = SMS_NOVA_A0,
39  },
41  .name = "Siano Nova B Digital Receiver",
42  .type = SMS_NOVA_B0,
43  },
45  .name = "Siano Vega Digital Receiver",
46  .type = SMS_VEGA,
47  },
49  .name = "Hauppauge Catamount",
50  .type = SMS_STELLAR,
51  .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-stellar-dvbt-01.fw",
52  },
54  .name = "Hauppauge Okemo-A",
55  .type = SMS_NOVA_A0,
56  .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-nova-a-dvbt-01.fw",
57  },
59  .name = "Hauppauge Okemo-B",
60  .type = SMS_NOVA_B0,
61  .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-nova-b-dvbt-01.fw",
62  },
64  .name = "Hauppauge WinTV MiniStick",
65  .type = SMS_NOVA_B0,
66  .fw[DEVICE_MODE_ISDBT_BDA] = "sms1xxx-hcw-55xxx-isdbt-02.fw",
67  .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
68  .rc_codes = RC_MAP_HAUPPAUGE,
69  .board_cfg.leds_power = 26,
70  .board_cfg.led0 = 27,
71  .board_cfg.led1 = 28,
72  .board_cfg.ir = 9,
73  .led_power = 26,
74  .led_lo = 27,
75  .led_hi = 28,
76  },
78  .name = "Hauppauge WinTV MiniCard",
79  .type = SMS_NOVA_B0,
80  .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
81  .lna_ctrl = 29,
82  .board_cfg.foreign_lna0_ctrl = 29,
83  .rf_switch = 17,
84  .board_cfg.rf_switch_uhf = 17,
85  },
87  .name = "Hauppauge WinTV MiniCard",
88  .type = SMS_NOVA_B0,
89  .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
90  .lna_ctrl = -1,
91  },
93  /* 11 */
94  .name = "Siano Nice Digital Receiver",
95  .type = SMS_NOVA_B0,
96  },
98  /* 12 */
99  .name = "Siano Venice Digital Receiver",
100  .type = SMS_VEGA,
101  },
102 };
103 
104 struct sms_board *sms_get_board(unsigned id)
105 {
106  BUG_ON(id >= ARRAY_SIZE(sms_boards));
107 
108  return &sms_boards[id];
109 }
111 static inline void sms_gpio_assign_11xx_default_led_config(
112  struct smscore_gpio_config *pGpioConfig) {
113  pGpioConfig->Direction = SMS_GPIO_DIRECTION_OUTPUT;
114  pGpioConfig->InputCharacteristics =
118  pGpioConfig->PullUpDown = SMS_GPIO_PULL_UP_DOWN_NONE;
119 }
120 
121 int sms_board_event(struct smscore_device_t *coredev,
122  enum SMS_BOARD_EVENTS gevent) {
123  struct smscore_gpio_config MyGpioConfig;
124 
125  sms_gpio_assign_11xx_default_led_config(&MyGpioConfig);
126 
127  switch (gevent) {
128  case BOARD_EVENT_POWER_INIT: /* including hotplug */
129  break; /* BOARD_EVENT_BIND */
130 
132  break; /* BOARD_EVENT_POWER_SUSPEND */
133 
135  break; /* BOARD_EVENT_POWER_RESUME */
136 
137  case BOARD_EVENT_BIND:
138  break; /* BOARD_EVENT_BIND */
139 
141  break; /* BOARD_EVENT_SCAN_PROG */
143  break; /* BOARD_EVENT_SCAN_COMP */
145  break; /* BOARD_EVENT_EMERGENCY_WARNING_SIGNAL */
146  case BOARD_EVENT_FE_LOCK:
147  break; /* BOARD_EVENT_FE_LOCK */
149  break; /* BOARD_EVENT_FE_UNLOCK */
151  break; /* BOARD_EVENT_DEMOD_LOCK */
153  break; /* BOARD_EVENT_DEMOD_UNLOCK */
155  break; /* BOARD_EVENT_RECEPTION_MAX_4 */
157  break; /* BOARD_EVENT_RECEPTION_3 */
159  break; /* BOARD_EVENT_RECEPTION_2 */
161  break; /* BOARD_EVENT_RECEPTION_1 */
163  break; /* BOARD_EVENT_RECEPTION_LOST_0 */
165  break; /* BOARD_EVENT_MULTIPLEX_OK */
167  break; /* BOARD_EVENT_MULTIPLEX_ERRORS */
168 
169  default:
170  sms_err("Unknown SMS board event");
171  break;
172  }
173  return 0;
174 }
176 
177 static int sms_set_gpio(struct smscore_device_t *coredev, int pin, int enable)
178 {
179  int lvl, ret;
180  u32 gpio;
181  struct smscore_config_gpio gpioconfig = {
183  .pullupdown = SMS_GPIO_PULLUPDOWN_NONE,
184  .inputcharacteristics = SMS_GPIO_INPUTCHARACTERISTICS_NORMAL,
185  .outputslewrate = SMS_GPIO_OUTPUTSLEWRATE_FAST,
186  .outputdriving = SMS_GPIO_OUTPUTDRIVING_4mA,
187  };
188 
189  if (pin == 0)
190  return -EINVAL;
191 
192  if (pin < 0) {
193  /* inverted gpio */
194  gpio = pin * -1;
195  lvl = enable ? 0 : 1;
196  } else {
197  gpio = pin;
198  lvl = enable ? 1 : 0;
199  }
200 
201  ret = smscore_configure_gpio(coredev, gpio, &gpioconfig);
202  if (ret < 0)
203  return ret;
204 
205  return smscore_set_gpio(coredev, gpio, lvl);
206 }
207 
208 int sms_board_setup(struct smscore_device_t *coredev)
209 {
210  int board_id = smscore_get_board_id(coredev);
211  struct sms_board *board = sms_get_board(board_id);
212 
213  switch (board_id) {
215  /* turn off all LEDs */
216  sms_set_gpio(coredev, board->led_power, 0);
217  sms_set_gpio(coredev, board->led_hi, 0);
218  sms_set_gpio(coredev, board->led_lo, 0);
219  break;
222  /* turn off LNA */
223  sms_set_gpio(coredev, board->lna_ctrl, 0);
224  break;
225  }
226  return 0;
227 }
229 
230 int sms_board_power(struct smscore_device_t *coredev, int onoff)
231 {
232  int board_id = smscore_get_board_id(coredev);
233  struct sms_board *board = sms_get_board(board_id);
234 
235  switch (board_id) {
237  /* power LED */
238  sms_set_gpio(coredev,
239  board->led_power, onoff ? 1 : 0);
240  break;
243  /* LNA */
244  if (!onoff)
245  sms_set_gpio(coredev, board->lna_ctrl, 0);
246  break;
247  }
248  return 0;
249 }
251 
252 int sms_board_led_feedback(struct smscore_device_t *coredev, int led)
253 {
254  int board_id = smscore_get_board_id(coredev);
255  struct sms_board *board = sms_get_board(board_id);
256 
257  /* dont touch GPIO if LEDs are already set */
258  if (smscore_led_state(coredev, -1) == led)
259  return 0;
260 
261  switch (board_id) {
263  sms_set_gpio(coredev,
264  board->led_lo, (led & SMS_LED_LO) ? 1 : 0);
265  sms_set_gpio(coredev,
266  board->led_hi, (led & SMS_LED_HI) ? 1 : 0);
267 
268  smscore_led_state(coredev, led);
269  break;
270  }
271  return 0;
272 }
274 
276 {
277  int board_id = smscore_get_board_id(coredev);
278  struct sms_board *board = sms_get_board(board_id);
279 
280  sms_debug("%s: LNA %s", __func__, onoff ? "enabled" : "disabled");
281 
282  switch (board_id) {
285  sms_set_gpio(coredev,
286  board->rf_switch, onoff ? 1 : 0);
287  return sms_set_gpio(coredev,
288  board->lna_ctrl, onoff ? 1 : 0);
289  }
290  return -EINVAL;
291 }
293 
295 {
296  switch (id) {
303  request_module("smsdvb");
304  break;
305  default:
306  /* do nothing */
307  break;
308  }
309  return 0;
310 }