nova-t-usb2.c 6.0 KB

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