nova-t-usb2.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* DVB USB framework compliant Linux driver for the Hauppauge WinTV-NOVA-T usb2
  2. * DVB-T receiver.
  3. *
  4. * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation, version 2.
  9. *
  10. * see Documentation/dvb/README.dvb-usb for more information
  11. */
  12. #include "dibusb.h"
  13. static int debug;
  14. module_param(debug, int, 0644);
  15. MODULE_PARM_DESC(debug, "set debugging level (1=rc,2=eeprom (|-able))." DVB_USB_DEBUG_STATUS);
  16. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  17. #define deb_rc(args...) dprintk(debug,0x01,args)
  18. #define deb_ee(args...) dprintk(debug,0x02,args)
  19. /* Hauppauge NOVA-T USB2 keys */
  20. static struct rc_map_table rc_map_haupp_table[] = {
  21. { 0x1e00, KEY_0 },
  22. { 0x1e01, KEY_1 },
  23. { 0x1e02, KEY_2 },
  24. { 0x1e03, KEY_3 },
  25. { 0x1e04, KEY_4 },
  26. { 0x1e05, KEY_5 },
  27. { 0x1e06, KEY_6 },
  28. { 0x1e07, KEY_7 },
  29. { 0x1e08, KEY_8 },
  30. { 0x1e09, KEY_9 },
  31. { 0x1e0a, KEY_KPASTERISK },
  32. { 0x1e0b, KEY_RED },
  33. { 0x1e0c, KEY_RADIO },
  34. { 0x1e0d, KEY_MENU },
  35. { 0x1e0e, KEY_GRAVE }, /* # */
  36. { 0x1e0f, KEY_MUTE },
  37. { 0x1e10, KEY_VOLUMEUP },
  38. { 0x1e11, KEY_VOLUMEDOWN },
  39. { 0x1e12, KEY_CHANNEL },
  40. { 0x1e14, KEY_UP },
  41. { 0x1e15, KEY_DOWN },
  42. { 0x1e16, KEY_LEFT },
  43. { 0x1e17, KEY_RIGHT },
  44. { 0x1e18, KEY_VIDEO },
  45. { 0x1e19, KEY_AUDIO },
  46. { 0x1e1a, KEY_IMAGES },
  47. { 0x1e1b, KEY_EPG },
  48. { 0x1e1c, KEY_TV },
  49. { 0x1e1e, KEY_NEXT },
  50. { 0x1e1f, KEY_BACK },
  51. { 0x1e20, KEY_CHANNELUP },
  52. { 0x1e21, KEY_CHANNELDOWN },
  53. { 0x1e24, KEY_LAST }, /* Skip backwards */
  54. { 0x1e25, KEY_OK },
  55. { 0x1e29, KEY_BLUE},
  56. { 0x1e2e, KEY_GREEN },
  57. { 0x1e30, KEY_PAUSE },
  58. { 0x1e32, KEY_REWIND },
  59. { 0x1e34, KEY_FASTFORWARD },
  60. { 0x1e35, KEY_PLAY },
  61. { 0x1e36, KEY_STOP },
  62. { 0x1e37, KEY_RECORD },
  63. { 0x1e38, KEY_YELLOW },
  64. { 0x1e3b, KEY_GOTO },
  65. { 0x1e3d, KEY_POWER },
  66. };
  67. /* Firmware bug? sometimes, when a new key is pressed, the previous pressed key
  68. * is delivered. No workaround yet, maybe a new firmware.
  69. */
  70. static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
  71. {
  72. u8 key[5],cmd[2] = { DIBUSB_REQ_POLL_REMOTE, 0x35 }, data,toggle,custom;
  73. u16 raw;
  74. int i;
  75. struct dibusb_device_state *st = d->priv;
  76. dvb_usb_generic_rw(d,cmd,2,key,5,0);
  77. *state = REMOTE_NO_KEY_PRESSED;
  78. switch (key[0]) {
  79. case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED:
  80. raw = ((key[1] << 8) | key[2]) >> 3;
  81. toggle = !!(raw & 0x800);
  82. data = raw & 0x3f;
  83. custom = (raw >> 6) & 0x1f;
  84. deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle);
  85. for (i = 0; i < ARRAY_SIZE(rc_map_haupp_table); i++) {
  86. if (rc5_data(&rc_map_haupp_table[i]) == data &&
  87. rc5_custom(&rc_map_haupp_table[i]) == custom) {
  88. deb_rc("c: %x, d: %x\n", rc5_data(&rc_map_haupp_table[i]),
  89. rc5_custom(&rc_map_haupp_table[i]));
  90. *event = rc_map_haupp_table[i].keycode;
  91. *state = REMOTE_KEY_PRESSED;
  92. if (st->old_toggle == toggle) {
  93. if (st->last_repeat_count++ < 2)
  94. *state = REMOTE_NO_KEY_PRESSED;
  95. } else {
  96. st->last_repeat_count = 0;
  97. st->old_toggle = toggle;
  98. }
  99. break;
  100. }
  101. }
  102. break;
  103. case DIBUSB_RC_HAUPPAUGE_KEY_EMPTY:
  104. default:
  105. break;
  106. }
  107. return 0;
  108. }
  109. static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6])
  110. {
  111. int i;
  112. u8 b;
  113. mac[0] = 0x00;
  114. mac[1] = 0x0d;
  115. mac[2] = 0xfe;
  116. /* this is a complete guess, but works for my box */
  117. for (i = 136; i < 139; i++) {
  118. dibusb_read_eeprom_byte(d,i, &b);
  119. mac[5 - (i - 136)] = b;
  120. }
  121. return 0;
  122. }
  123. /* USB Driver stuff */
  124. static struct dvb_usb_device_properties nova_t_properties;
  125. static int nova_t_probe(struct usb_interface *intf,
  126. const struct usb_device_id *id)
  127. {
  128. return dvb_usb_device_init(intf, &nova_t_properties,
  129. THIS_MODULE, NULL, adapter_nr);
  130. }
  131. /* do not change the order of the ID table */
  132. static struct usb_device_id nova_t_table [] = {
  133. /* 00 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_WINTV_NOVA_T_USB2_COLD) },
  134. /* 01 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_WINTV_NOVA_T_USB2_WARM) },
  135. { } /* Terminating entry */
  136. };
  137. MODULE_DEVICE_TABLE(usb, nova_t_table);
  138. static struct dvb_usb_device_properties nova_t_properties = {
  139. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  140. .usb_ctrl = CYPRESS_FX2,
  141. .firmware = "dvb-usb-nova-t-usb2-02.fw",
  142. .num_adapters = 1,
  143. .adapter = {
  144. {
  145. .num_frontends = 1,
  146. .fe = {{
  147. .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  148. .pid_filter_count = 32,
  149. .streaming_ctrl = dibusb2_0_streaming_ctrl,
  150. .pid_filter = dibusb_pid_filter,
  151. .pid_filter_ctrl = dibusb_pid_filter_ctrl,
  152. .frontend_attach = dibusb_dib3000mc_frontend_attach,
  153. .tuner_attach = dibusb_dib3000mc_tuner_attach,
  154. /* parameter for the MPEG2-data transfer */
  155. .stream = {
  156. .type = USB_BULK,
  157. .count = 7,
  158. .endpoint = 0x06,
  159. .u = {
  160. .bulk = {
  161. .buffersize = 4096,
  162. }
  163. }
  164. },
  165. }},
  166. .size_of_priv = sizeof(struct dibusb_state),
  167. }
  168. },
  169. .size_of_priv = sizeof(struct dibusb_device_state),
  170. .power_ctrl = dibusb2_0_power_ctrl,
  171. .read_mac_address = nova_t_read_mac_address,
  172. .rc.legacy = {
  173. .rc_interval = 100,
  174. .rc_map_table = rc_map_haupp_table,
  175. .rc_map_size = ARRAY_SIZE(rc_map_haupp_table),
  176. .rc_query = nova_t_rc_query,
  177. },
  178. .i2c_algo = &dibusb_i2c_algo,
  179. .generic_bulk_ctrl_endpoint = 0x01,
  180. .num_device_descs = 1,
  181. .devices = {
  182. { "Hauppauge WinTV-NOVA-T usb2",
  183. { &nova_t_table[0], NULL },
  184. { &nova_t_table[1], NULL },
  185. },
  186. { NULL },
  187. }
  188. };
  189. static struct usb_driver nova_t_driver = {
  190. .name = "dvb_usb_nova_t_usb2",
  191. .probe = nova_t_probe,
  192. .disconnect = dvb_usb_device_exit,
  193. .id_table = nova_t_table,
  194. };
  195. module_usb_driver(nova_t_driver);
  196. MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
  197. MODULE_DESCRIPTION("Hauppauge WinTV-NOVA-T usb2");
  198. MODULE_VERSION("1.0");
  199. MODULE_LICENSE("GPL");