nova-t-usb2.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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@posteo.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 *buf, data, toggle, custom;
  73. u16 raw;
  74. int i, ret;
  75. struct dibusb_device_state *st = d->priv;
  76. buf = kmalloc(5, GFP_KERNEL);
  77. if (!buf)
  78. return -ENOMEM;
  79. buf[0] = DIBUSB_REQ_POLL_REMOTE;
  80. buf[1] = 0x35;
  81. ret = dvb_usb_generic_rw(d, buf, 2, buf, 5, 0);
  82. if (ret < 0)
  83. goto ret;
  84. *state = REMOTE_NO_KEY_PRESSED;
  85. switch (buf[0]) {
  86. case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED:
  87. raw = ((buf[1] << 8) | buf[2]) >> 3;
  88. toggle = !!(raw & 0x800);
  89. data = raw & 0x3f;
  90. custom = (raw >> 6) & 0x1f;
  91. deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",
  92. buf[1], buf[2], buf[3], custom, data, toggle);
  93. for (i = 0; i < ARRAY_SIZE(rc_map_haupp_table); i++) {
  94. if (rc5_data(&rc_map_haupp_table[i]) == data &&
  95. rc5_custom(&rc_map_haupp_table[i]) == custom) {
  96. deb_rc("c: %x, d: %x\n", rc5_data(&rc_map_haupp_table[i]),
  97. rc5_custom(&rc_map_haupp_table[i]));
  98. *event = rc_map_haupp_table[i].keycode;
  99. *state = REMOTE_KEY_PRESSED;
  100. if (st->old_toggle == toggle) {
  101. if (st->last_repeat_count++ < 2)
  102. *state = REMOTE_NO_KEY_PRESSED;
  103. } else {
  104. st->last_repeat_count = 0;
  105. st->old_toggle = toggle;
  106. }
  107. break;
  108. }
  109. }
  110. break;
  111. case DIBUSB_RC_HAUPPAUGE_KEY_EMPTY:
  112. default:
  113. break;
  114. }
  115. ret:
  116. kfree(buf);
  117. return ret;
  118. }
  119. static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6])
  120. {
  121. int i;
  122. u8 b;
  123. mac[0] = 0x00;
  124. mac[1] = 0x0d;
  125. mac[2] = 0xfe;
  126. /* this is a complete guess, but works for my box */
  127. for (i = 136; i < 139; i++) {
  128. dibusb_read_eeprom_byte(d,i, &b);
  129. mac[5 - (i - 136)] = b;
  130. }
  131. return 0;
  132. }
  133. /* USB Driver stuff */
  134. static struct dvb_usb_device_properties nova_t_properties;
  135. static int nova_t_probe(struct usb_interface *intf,
  136. const struct usb_device_id *id)
  137. {
  138. return dvb_usb_device_init(intf, &nova_t_properties,
  139. THIS_MODULE, NULL, adapter_nr);
  140. }
  141. /* do not change the order of the ID table */
  142. static struct usb_device_id nova_t_table [] = {
  143. /* 00 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_WINTV_NOVA_T_USB2_COLD) },
  144. /* 01 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_WINTV_NOVA_T_USB2_WARM) },
  145. { } /* Terminating entry */
  146. };
  147. MODULE_DEVICE_TABLE(usb, nova_t_table);
  148. static struct dvb_usb_device_properties nova_t_properties = {
  149. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  150. .usb_ctrl = CYPRESS_FX2,
  151. .firmware = "/*(DEBLOBBED)*/",
  152. .num_adapters = 1,
  153. .adapter = {
  154. {
  155. .num_frontends = 1,
  156. .fe = {{
  157. .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  158. .pid_filter_count = 32,
  159. .streaming_ctrl = dibusb2_0_streaming_ctrl,
  160. .pid_filter = dibusb_pid_filter,
  161. .pid_filter_ctrl = dibusb_pid_filter_ctrl,
  162. .frontend_attach = dibusb_dib3000mc_frontend_attach,
  163. .tuner_attach = dibusb_dib3000mc_tuner_attach,
  164. /* parameter for the MPEG2-data transfer */
  165. .stream = {
  166. .type = USB_BULK,
  167. .count = 7,
  168. .endpoint = 0x06,
  169. .u = {
  170. .bulk = {
  171. .buffersize = 4096,
  172. }
  173. }
  174. },
  175. }},
  176. .size_of_priv = sizeof(struct dibusb_state),
  177. }
  178. },
  179. .size_of_priv = sizeof(struct dibusb_device_state),
  180. .power_ctrl = dibusb2_0_power_ctrl,
  181. .read_mac_address = nova_t_read_mac_address,
  182. .rc.legacy = {
  183. .rc_interval = 100,
  184. .rc_map_table = rc_map_haupp_table,
  185. .rc_map_size = ARRAY_SIZE(rc_map_haupp_table),
  186. .rc_query = nova_t_rc_query,
  187. },
  188. .i2c_algo = &dibusb_i2c_algo,
  189. .generic_bulk_ctrl_endpoint = 0x01,
  190. .num_device_descs = 1,
  191. .devices = {
  192. { "Hauppauge WinTV-NOVA-T usb2",
  193. { &nova_t_table[0], NULL },
  194. { &nova_t_table[1], NULL },
  195. },
  196. { NULL },
  197. }
  198. };
  199. static struct usb_driver nova_t_driver = {
  200. .name = "dvb_usb_nova_t_usb2",
  201. .probe = nova_t_probe,
  202. .disconnect = dvb_usb_device_exit,
  203. .id_table = nova_t_table,
  204. };
  205. module_usb_driver(nova_t_driver);
  206. MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>");
  207. MODULE_DESCRIPTION("Hauppauge WinTV-NOVA-T usb2");
  208. MODULE_VERSION("1.0");
  209. MODULE_LICENSE("GPL");