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 [SMS1XXX_BOARD_PCTV_77E] = { 161 .name = "Hauppauge microStick 77e", 162 .type = SMS_NOVA_B0, 163 .fw[DEVICE_MODE_DVBT_BDA] = SMS_FW_DVB_NOVA_12MHZ_B0, 164 .default_mode = DEVICE_MODE_DVBT_BDA, 165 }, 166 }; 167 168 struct sms_board *sms_get_board(unsigned id) 169 { 170 BUG_ON(id >= ARRAY_SIZE(sms_boards)); 171 172 return &sms_boards[id]; 173 } 174 EXPORT_SYMBOL_GPL(sms_get_board); 175 static inline void sms_gpio_assign_11xx_default_led_config( 176 struct smscore_config_gpio *p_gpio_config) { 177 p_gpio_config->direction = SMS_GPIO_DIRECTION_OUTPUT; 178 p_gpio_config->inputcharacteristics = 179 SMS_GPIO_INPUTCHARACTERISTICS_NORMAL; 180 p_gpio_config->outputdriving = SMS_GPIO_OUTPUTDRIVING_4mA; 181 p_gpio_config->outputslewrate = SMS_GPIO_OUTPUT_SLEW_RATE_0_45_V_NS; 182 p_gpio_config->pullupdown = SMS_GPIO_PULLUPDOWN_NONE; 183 } 184 185 int sms_board_event(struct smscore_device_t *coredev, 186 enum SMS_BOARD_EVENTS gevent) 187 { 188 struct smscore_config_gpio my_gpio_config; 189 190 sms_gpio_assign_11xx_default_led_config(&my_gpio_config); 191 192 switch (gevent) { 193 case BOARD_EVENT_POWER_INIT: /* including hotplug */ 194 break; /* BOARD_EVENT_BIND */ 195 196 case BOARD_EVENT_POWER_SUSPEND: 197 break; /* BOARD_EVENT_POWER_SUSPEND */ 198 199 case BOARD_EVENT_POWER_RESUME: 200 break; /* BOARD_EVENT_POWER_RESUME */ 201 202 case BOARD_EVENT_BIND: 203 break; /* BOARD_EVENT_BIND */ 204 205 case BOARD_EVENT_SCAN_PROG: 206 break; /* BOARD_EVENT_SCAN_PROG */ 207 case BOARD_EVENT_SCAN_COMP: 208 break; /* BOARD_EVENT_SCAN_COMP */ 209 case BOARD_EVENT_EMERGENCY_WARNING_SIGNAL: 210 break; /* BOARD_EVENT_EMERGENCY_WARNING_SIGNAL */ 211 case BOARD_EVENT_FE_LOCK: 212 break; /* BOARD_EVENT_FE_LOCK */ 213 case BOARD_EVENT_FE_UNLOCK: 214 break; /* BOARD_EVENT_FE_UNLOCK */ 215 case BOARD_EVENT_DEMOD_LOCK: 216 break; /* BOARD_EVENT_DEMOD_LOCK */ 217 case BOARD_EVENT_DEMOD_UNLOCK: 218 break; /* BOARD_EVENT_DEMOD_UNLOCK */ 219 case BOARD_EVENT_RECEPTION_MAX_4: 220 break; /* BOARD_EVENT_RECEPTION_MAX_4 */ 221 case BOARD_EVENT_RECEPTION_3: 222 break; /* BOARD_EVENT_RECEPTION_3 */ 223 case BOARD_EVENT_RECEPTION_2: 224 break; /* BOARD_EVENT_RECEPTION_2 */ 225 case BOARD_EVENT_RECEPTION_1: 226 break; /* BOARD_EVENT_RECEPTION_1 */ 227 case BOARD_EVENT_RECEPTION_LOST_0: 228 break; /* BOARD_EVENT_RECEPTION_LOST_0 */ 229 case BOARD_EVENT_MULTIPLEX_OK: 230 break; /* BOARD_EVENT_MULTIPLEX_OK */ 231 case BOARD_EVENT_MULTIPLEX_ERRORS: 232 break; /* BOARD_EVENT_MULTIPLEX_ERRORS */ 233 234 default: 235 sms_err("Unknown SMS board event"); 236 break; 237 } 238 return 0; 239 } 240 EXPORT_SYMBOL_GPL(sms_board_event); 241 242 static int sms_set_gpio(struct smscore_device_t *coredev, int pin, int enable) 243 { 244 int lvl, ret; 245 u32 gpio; 246 struct smscore_config_gpio gpioconfig = { 247 .direction = SMS_GPIO_DIRECTION_OUTPUT, 248 .pullupdown = SMS_GPIO_PULLUPDOWN_NONE, 249 .inputcharacteristics = SMS_GPIO_INPUTCHARACTERISTICS_NORMAL, 250 .outputslewrate = SMS_GPIO_OUTPUT_SLEW_RATE_FAST, 251 .outputdriving = SMS_GPIO_OUTPUTDRIVING_S_4mA, 252 }; 253 254 if (pin == 0) 255 return -EINVAL; 256 257 if (pin < 0) { 258 /* inverted gpio */ 259 gpio = pin * -1; 260 lvl = enable ? 0 : 1; 261 } else { 262 gpio = pin; 263 lvl = enable ? 1 : 0; 264 } 265 266 ret = smscore_configure_gpio(coredev, gpio, &gpioconfig); 267 if (ret < 0) 268 return ret; 269 270 return smscore_set_gpio(coredev, gpio, lvl); 271 } 272 273 int sms_board_setup(struct smscore_device_t *coredev) 274 { 275 int board_id = smscore_get_board_id(coredev); 276 struct sms_board *board = sms_get_board(board_id); 277 278 switch (board_id) { 279 case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM: 280 /* turn off all LEDs */ 281 sms_set_gpio(coredev, board->led_power, 0); 282 sms_set_gpio(coredev, board->led_hi, 0); 283 sms_set_gpio(coredev, board->led_lo, 0); 284 break; 285 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2: 286 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD: 287 /* turn off LNA */ 288 sms_set_gpio(coredev, board->lna_ctrl, 0); 289 break; 290 } 291 return 0; 292 } 293 EXPORT_SYMBOL_GPL(sms_board_setup); 294 295 int sms_board_power(struct smscore_device_t *coredev, int onoff) 296 { 297 int board_id = smscore_get_board_id(coredev); 298 struct sms_board *board = sms_get_board(board_id); 299 300 switch (board_id) { 301 case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM: 302 /* power LED */ 303 sms_set_gpio(coredev, 304 board->led_power, onoff ? 1 : 0); 305 break; 306 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2: 307 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD: 308 /* LNA */ 309 if (!onoff) 310 sms_set_gpio(coredev, board->lna_ctrl, 0); 311 break; 312 } 313 return 0; 314 } 315 EXPORT_SYMBOL_GPL(sms_board_power); 316 317 int sms_board_led_feedback(struct smscore_device_t *coredev, int led) 318 { 319 int board_id = smscore_get_board_id(coredev); 320 struct sms_board *board = sms_get_board(board_id); 321 322 /* dont touch GPIO if LEDs are already set */ 323 if (smscore_led_state(coredev, -1) == led) 324 return 0; 325 326 switch (board_id) { 327 case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM: 328 sms_set_gpio(coredev, 329 board->led_lo, (led & SMS_LED_LO) ? 1 : 0); 330 sms_set_gpio(coredev, 331 board->led_hi, (led & SMS_LED_HI) ? 1 : 0); 332 333 smscore_led_state(coredev, led); 334 break; 335 } 336 return 0; 337 } 338 EXPORT_SYMBOL_GPL(sms_board_led_feedback); 339 340 int sms_board_lna_control(struct smscore_device_t *coredev, int onoff) 341 { 342 int board_id = smscore_get_board_id(coredev); 343 struct sms_board *board = sms_get_board(board_id); 344 345 sms_debug("%s: LNA %s", __func__, onoff ? "enabled" : "disabled"); 346 347 switch (board_id) { 348 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2: 349 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD: 350 sms_set_gpio(coredev, 351 board->rf_switch, onoff ? 1 : 0); 352 return sms_set_gpio(coredev, 353 board->lna_ctrl, onoff ? 1 : 0); 354 } 355 return -EINVAL; 356 } 357 EXPORT_SYMBOL_GPL(sms_board_lna_control); 358 359 int sms_board_load_modules(int id) 360 { 361 request_module("smsdvb"); 362 return 0; 363 } 364 EXPORT_SYMBOL_GPL(sms_board_load_modules); 365