sms-cards.c 9.8 KB

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