nova-t-usb2.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. #define deb_rc(args...) dprintk(debug,0x01,args)
  17. #define deb_ee(args...) dprintk(debug,0x02,args)
  18. /* Hauppauge NOVA-T USB2 keys */
  19. static struct dvb_usb_rc_key haupp_rc_keys [] = {
  20. { 0x1e, 0x00, KEY_0 },
  21. { 0x1e, 0x01, KEY_1 },
  22. { 0x1e, 0x02, KEY_2 },
  23. { 0x1e, 0x03, KEY_3 },
  24. { 0x1e, 0x04, KEY_4 },
  25. { 0x1e, 0x05, KEY_5 },
  26. { 0x1e, 0x06, KEY_6 },
  27. { 0x1e, 0x07, KEY_7 },
  28. { 0x1e, 0x08, KEY_8 },
  29. { 0x1e, 0x09, KEY_9 },
  30. { 0x1e, 0x0a, KEY_KPASTERISK },
  31. { 0x1e, 0x0b, KEY_RED },
  32. { 0x1e, 0x0c, KEY_RADIO },
  33. { 0x1e, 0x0d, KEY_MENU },
  34. { 0x1e, 0x0e, KEY_GRAVE }, /* # */
  35. { 0x1e, 0x0f, KEY_MUTE },
  36. { 0x1e, 0x10, KEY_VOLUMEUP },
  37. { 0x1e, 0x11, KEY_VOLUMEDOWN },
  38. { 0x1e, 0x12, KEY_CHANNEL },
  39. { 0x1e, 0x14, KEY_UP },
  40. { 0x1e, 0x15, KEY_DOWN },
  41. { 0x1e, 0x16, KEY_LEFT },
  42. { 0x1e, 0x17, KEY_RIGHT },
  43. { 0x1e, 0x18, KEY_VIDEO },
  44. { 0x1e, 0x19, KEY_AUDIO },
  45. { 0x1e, 0x1a, KEY_MEDIA },
  46. { 0x1e, 0x1b, KEY_EPG },
  47. { 0x1e, 0x1c, KEY_TV },
  48. { 0x1e, 0x1e, KEY_NEXT },
  49. { 0x1e, 0x1f, KEY_BACK },
  50. { 0x1e, 0x20, KEY_CHANNELUP },
  51. { 0x1e, 0x21, KEY_CHANNELDOWN },
  52. { 0x1e, 0x24, KEY_LAST }, /* Skip backwards */
  53. { 0x1e, 0x25, KEY_OK },
  54. { 0x1e, 0x29, KEY_BLUE},
  55. { 0x1e, 0x2e, KEY_GREEN },
  56. { 0x1e, 0x30, KEY_PAUSE },
  57. { 0x1e, 0x32, KEY_REWIND },
  58. { 0x1e, 0x34, KEY_FASTFORWARD },
  59. { 0x1e, 0x35, KEY_PLAY },
  60. { 0x1e, 0x36, KEY_STOP },
  61. { 0x1e, 0x37, KEY_RECORD },
  62. { 0x1e, 0x38, KEY_YELLOW },
  63. { 0x1e, 0x3b, KEY_GOTO },
  64. { 0x1e, 0x3d, KEY_POWER },
  65. };
  66. /* Firmware bug? sometimes, when a new key is pressed, the previous pressed key
  67. * is delivered. No workaround yet, maybe a new firmware.
  68. */
  69. static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
  70. {
  71. u8 key[5],cmd[2] = { DIBUSB_REQ_POLL_REMOTE, 0x35 }, data,toggle,custom;
  72. u16 raw;
  73. int i;
  74. struct dibusb_state *st = d->priv;
  75. dvb_usb_generic_rw(d,cmd,2,key,5,0);
  76. *state = REMOTE_NO_KEY_PRESSED;
  77. switch (key[0]) {
  78. case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED:
  79. raw = ((key[1] << 8) | key[2]) >> 3;
  80. toggle = !!(raw & 0x800);
  81. data = raw & 0x3f;
  82. custom = (raw >> 6) & 0x1f;
  83. 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);
  84. for (i = 0; i < ARRAY_SIZE(haupp_rc_keys); i++) {
  85. deb_rc("c: %x, d: %x\n",haupp_rc_keys[i].data,haupp_rc_keys[i].custom);
  86. if (haupp_rc_keys[i].data == data &&
  87. haupp_rc_keys[i].custom == custom) {
  88. *event = haupp_rc_keys[i].event;
  89. *state = REMOTE_KEY_PRESSED;
  90. if (st->old_toggle == toggle) {
  91. if (st->last_repeat_count++ < 2)
  92. *state = REMOTE_NO_KEY_PRESSED;
  93. } else {
  94. st->last_repeat_count = 0;
  95. st->old_toggle = toggle;
  96. }
  97. break;
  98. }
  99. }
  100. break;
  101. case DIBUSB_RC_HAUPPAUGE_KEY_EMPTY:
  102. default:
  103. break;
  104. }
  105. return 0;
  106. }
  107. static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6])
  108. {
  109. int i;
  110. u8 b;
  111. mac[0] = 0x00;
  112. mac[1] = 0x0d;
  113. mac[2] = 0xfe;
  114. /* this is a complete guess, but works for my box */
  115. for (i = 136; i < 139; i++) {
  116. dibusb_read_eeprom_byte(d,i, &b);
  117. mac[5 - (i - 136)] = b;
  118. }
  119. return 0;
  120. }
  121. /* USB Driver stuff */
  122. static struct dvb_usb_properties nova_t_properties;
  123. static int nova_t_probe(struct usb_interface *intf,
  124. const struct usb_device_id *id)
  125. {
  126. return dvb_usb_device_init(intf,&nova_t_properties,THIS_MODULE,NULL);
  127. }
  128. /* do not change the order of the ID table */
  129. static struct usb_device_id nova_t_table [] = {
  130. /* 00 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_WINTV_NOVA_T_USB2_COLD) },
  131. /* 01 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_WINTV_NOVA_T_USB2_WARM) },
  132. { } /* Terminating entry */
  133. };
  134. MODULE_DEVICE_TABLE(usb, nova_t_table);
  135. static struct dvb_usb_properties nova_t_properties = {
  136. .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_IS_AN_I2C_ADAPTER,
  137. .pid_filter_count = 32,
  138. .usb_ctrl = CYPRESS_FX2,
  139. .firmware = "dvb-usb-nova-t-usb2-01.fw",
  140. .size_of_priv = sizeof(struct dibusb_state),
  141. .streaming_ctrl = dibusb2_0_streaming_ctrl,
  142. .pid_filter = dibusb_pid_filter,
  143. .pid_filter_ctrl = dibusb_pid_filter_ctrl,
  144. .power_ctrl = dibusb2_0_power_ctrl,
  145. .frontend_attach = dibusb_dib3000mc_frontend_attach,
  146. .tuner_attach = dibusb_dib3000mc_tuner_attach,
  147. .read_mac_address = nova_t_read_mac_address,
  148. .rc_interval = 100,
  149. .rc_key_map = haupp_rc_keys,
  150. .rc_key_map_size = ARRAY_SIZE(haupp_rc_keys),
  151. .rc_query = nova_t_rc_query,
  152. .i2c_algo = &dibusb_i2c_algo,
  153. .generic_bulk_ctrl_endpoint = 0x01,
  154. /* parameter for the MPEG2-data transfer */
  155. .urb = {
  156. .type = DVB_USB_BULK,
  157. .count = 7,
  158. .endpoint = 0x06,
  159. .u = {
  160. .bulk = {
  161. .buffersize = 4096,
  162. }
  163. }
  164. },
  165. .num_device_descs = 1,
  166. .devices = {
  167. { "Hauppauge WinTV-NOVA-T usb2",
  168. { &nova_t_table[0], NULL },
  169. { &nova_t_table[1], NULL },
  170. },
  171. { NULL },
  172. }
  173. };
  174. static struct usb_driver nova_t_driver = {
  175. .name = "dvb_usb_nova_t_usb2",
  176. .probe = nova_t_probe,
  177. .disconnect = dvb_usb_device_exit,
  178. .id_table = nova_t_table,
  179. };
  180. /* module stuff */
  181. static int __init nova_t_module_init(void)
  182. {
  183. int result;
  184. if ((result = usb_register(&nova_t_driver))) {
  185. err("usb_register failed. Error number %d",result);
  186. return result;
  187. }
  188. return 0;
  189. }
  190. static void __exit nova_t_module_exit(void)
  191. {
  192. /* deregister this driver from the USB subsystem */
  193. usb_deregister(&nova_t_driver);
  194. }
  195. module_init (nova_t_module_init);
  196. module_exit (nova_t_module_exit);
  197. MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
  198. MODULE_DESCRIPTION("Hauppauge WinTV-NOVA-T usb2");
  199. MODULE_VERSION("1.0");
  200. MODULE_LICENSE("GPL");