vp7045.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /* DVB USB compliant Linux driver for the
  2. * - TwinhanDTV Alpha/MagicBoxII USB2.0 DVB-T receiver
  3. * - DigitalNow TinyUSB2 DVB-t receiver
  4. *
  5. * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
  6. *
  7. * Thanks to Twinhan who kindly provided hardware and information.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation, version 2.
  12. *
  13. * see Documentation/dvb/README.dvb-usb for more information
  14. */
  15. #include "vp7045.h"
  16. /* debug */
  17. int dvb_usb_vp7045_debug;
  18. module_param_named(debug,dvb_usb_vp7045_debug, int, 0644);
  19. MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
  20. int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in, int inlen, int msec)
  21. {
  22. int ret = 0;
  23. u8 inbuf[12] = { 0 }, outbuf[20] = { 0 };
  24. outbuf[0] = cmd;
  25. if (outlen > 19)
  26. outlen = 19;
  27. if (inlen > 11)
  28. inlen = 11;
  29. if (out != NULL && outlen > 0)
  30. memcpy(&outbuf[1], out, outlen);
  31. deb_xfer("out buffer: ");
  32. debug_dump(outbuf,outlen+1,deb_xfer);
  33. if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
  34. return ret;
  35. if (usb_control_msg(d->udev,
  36. usb_sndctrlpipe(d->udev,0),
  37. TH_COMMAND_OUT, USB_TYPE_VENDOR | USB_DIR_OUT, 0, 0,
  38. outbuf, 20, 2000) != 20) {
  39. err("USB control message 'out' went wrong.");
  40. ret = -EIO;
  41. goto unlock;
  42. }
  43. msleep(msec);
  44. if (usb_control_msg(d->udev,
  45. usb_rcvctrlpipe(d->udev,0),
  46. TH_COMMAND_IN, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
  47. inbuf, 12, 2000) != 12) {
  48. err("USB control message 'in' went wrong.");
  49. ret = -EIO;
  50. goto unlock;
  51. }
  52. deb_xfer("in buffer: ");
  53. debug_dump(inbuf,12,deb_xfer);
  54. if (in != NULL && inlen > 0)
  55. memcpy(in,&inbuf[1],inlen);
  56. unlock:
  57. mutex_unlock(&d->usb_mutex);
  58. return ret;
  59. }
  60. u8 vp7045_read_reg(struct dvb_usb_device *d, u8 reg)
  61. {
  62. u8 obuf[2] = { 0 },v;
  63. obuf[1] = reg;
  64. vp7045_usb_op(d,TUNER_REG_READ,obuf,2,&v,1,30);
  65. return v;
  66. }
  67. static int vp7045_power_ctrl(struct dvb_usb_device *d, int onoff)
  68. {
  69. u8 v = onoff;
  70. return vp7045_usb_op(d,SET_TUNER_POWER,&v,1,NULL,0,150);
  71. }
  72. /* remote control stuff */
  73. /* The keymapping struct. Somehow this should be loaded to the driver, but
  74. * currently it is hardcoded. */
  75. static struct dvb_usb_rc_key vp7045_rc_keys[] = {
  76. { 0x00, 0x16, KEY_POWER },
  77. { 0x00, 0x10, KEY_MUTE },
  78. { 0x00, 0x03, KEY_1 },
  79. { 0x00, 0x01, KEY_2 },
  80. { 0x00, 0x06, KEY_3 },
  81. { 0x00, 0x09, KEY_4 },
  82. { 0x00, 0x1d, KEY_5 },
  83. { 0x00, 0x1f, KEY_6 },
  84. { 0x00, 0x0d, KEY_7 },
  85. { 0x00, 0x19, KEY_8 },
  86. { 0x00, 0x1b, KEY_9 },
  87. { 0x00, 0x15, KEY_0 },
  88. { 0x00, 0x05, KEY_CHANNELUP },
  89. { 0x00, 0x02, KEY_CHANNELDOWN },
  90. { 0x00, 0x1e, KEY_VOLUMEUP },
  91. { 0x00, 0x0a, KEY_VOLUMEDOWN },
  92. { 0x00, 0x11, KEY_RECORD },
  93. { 0x00, 0x17, KEY_FAVORITES }, /* Heart symbol - Channel list. */
  94. { 0x00, 0x14, KEY_PLAY },
  95. { 0x00, 0x1a, KEY_STOP },
  96. { 0x00, 0x40, KEY_REWIND },
  97. { 0x00, 0x12, KEY_FASTFORWARD },
  98. { 0x00, 0x0e, KEY_PREVIOUS }, /* Recall - Previous channel. */
  99. { 0x00, 0x4c, KEY_PAUSE },
  100. { 0x00, 0x4d, KEY_SCREEN }, /* Full screen mode. */
  101. { 0x00, 0x54, KEY_AUDIO }, /* MTS - Switch to secondary audio. */
  102. { 0x00, 0x0c, KEY_CANCEL }, /* Cancel */
  103. { 0x00, 0x1c, KEY_EPG }, /* EPG */
  104. { 0x00, 0x00, KEY_TAB }, /* Tab */
  105. { 0x00, 0x48, KEY_INFO }, /* Preview */
  106. { 0x00, 0x04, KEY_LIST }, /* RecordList */
  107. { 0x00, 0x0f, KEY_TEXT } /* Teletext */
  108. };
  109. static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
  110. {
  111. u8 key;
  112. int i;
  113. vp7045_usb_op(d,RC_VAL_READ,NULL,0,&key,1,20);
  114. deb_rc("remote query key: %x %d\n",key,key);
  115. if (key == 0x44) {
  116. *state = REMOTE_NO_KEY_PRESSED;
  117. return 0;
  118. }
  119. for (i = 0; i < sizeof(vp7045_rc_keys)/sizeof(struct dvb_usb_rc_key); i++)
  120. if (vp7045_rc_keys[i].data == key) {
  121. *state = REMOTE_KEY_PRESSED;
  122. *event = vp7045_rc_keys[i].event;
  123. break;
  124. }
  125. return 0;
  126. }
  127. static int vp7045_read_eeprom(struct dvb_usb_device *d,u8 *buf, int len, int offset)
  128. {
  129. int i = 0;
  130. u8 v,br[2];
  131. for (i=0; i < len; i++) {
  132. v = offset + i;
  133. vp7045_usb_op(d,GET_EE_VALUE,&v,1,br,2,5);
  134. buf[i] = br[1];
  135. }
  136. deb_info("VP7045 EEPROM read (offs: %d, len: %d) : ",offset, i);
  137. debug_dump(buf,i,deb_info);
  138. return 0;
  139. }
  140. static int vp7045_read_mac_addr(struct dvb_usb_device *d,u8 mac[6])
  141. {
  142. return vp7045_read_eeprom(d,mac, 6, MAC_0_ADDR);
  143. }
  144. static int vp7045_frontend_attach(struct dvb_usb_device *d)
  145. {
  146. u8 buf[255] = { 0 };
  147. vp7045_usb_op(d,VENDOR_STRING_READ,NULL,0,buf,20,0);
  148. buf[10] = '\0';
  149. deb_info("firmware says: %s ",buf);
  150. vp7045_usb_op(d,PRODUCT_STRING_READ,NULL,0,buf,20,0);
  151. buf[10] = '\0';
  152. deb_info("%s ",buf);
  153. vp7045_usb_op(d,FW_VERSION_READ,NULL,0,buf,20,0);
  154. buf[10] = '\0';
  155. deb_info("v%s\n",buf);
  156. /* Dump the EEPROM */
  157. /* vp7045_read_eeprom(d,buf, 255, FX2_ID_ADDR); */
  158. d->fe = vp7045_fe_attach(d);
  159. return 0;
  160. }
  161. static struct dvb_usb_properties vp7045_properties;
  162. static int vp7045_usb_probe(struct usb_interface *intf,
  163. const struct usb_device_id *id)
  164. {
  165. return dvb_usb_device_init(intf,&vp7045_properties,THIS_MODULE,NULL);
  166. }
  167. static struct usb_device_id vp7045_usb_table [] = {
  168. { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7045_COLD) },
  169. { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7045_WARM) },
  170. { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_DNTV_TINYUSB2_COLD) },
  171. { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_DNTV_TINYUSB2_WARM) },
  172. { 0 },
  173. };
  174. MODULE_DEVICE_TABLE(usb, vp7045_usb_table);
  175. static struct dvb_usb_properties vp7045_properties = {
  176. .caps = 0,
  177. .usb_ctrl = CYPRESS_FX2,
  178. .firmware = "dvb-usb-vp7045-01.fw",
  179. .power_ctrl = vp7045_power_ctrl,
  180. .frontend_attach = vp7045_frontend_attach,
  181. .read_mac_address = vp7045_read_mac_addr,
  182. .rc_interval = 400,
  183. .rc_key_map = vp7045_rc_keys,
  184. .rc_key_map_size = ARRAY_SIZE(vp7045_rc_keys),
  185. .rc_query = vp7045_rc_query,
  186. /* parameter for the MPEG2-data transfer */
  187. .urb = {
  188. .type = DVB_USB_BULK,
  189. .count = 7,
  190. .endpoint = 0x02,
  191. .u = {
  192. .bulk = {
  193. .buffersize = 4096,
  194. }
  195. }
  196. },
  197. .num_device_descs = 2,
  198. .devices = {
  199. { .name = "Twinhan USB2.0 DVB-T receiver (TwinhanDTV Alpha/MagicBox II)",
  200. .cold_ids = { &vp7045_usb_table[0], NULL },
  201. .warm_ids = { &vp7045_usb_table[1], NULL },
  202. },
  203. { .name = "DigitalNow TinyUSB 2 DVB-t Receiver",
  204. .cold_ids = { &vp7045_usb_table[2], NULL },
  205. .warm_ids = { &vp7045_usb_table[3], NULL },
  206. },
  207. { NULL },
  208. }
  209. };
  210. /* usb specific object needed to register this driver with the usb subsystem */
  211. static struct usb_driver vp7045_usb_driver = {
  212. .name = "dvb_usb_vp7045",
  213. .probe = vp7045_usb_probe,
  214. .disconnect = dvb_usb_device_exit,
  215. .id_table = vp7045_usb_table,
  216. };
  217. /* module stuff */
  218. static int __init vp7045_usb_module_init(void)
  219. {
  220. int result;
  221. if ((result = usb_register(&vp7045_usb_driver))) {
  222. err("usb_register failed. (%d)",result);
  223. return result;
  224. }
  225. return 0;
  226. }
  227. static void __exit vp7045_usb_module_exit(void)
  228. {
  229. /* deregister this driver from the USB subsystem */
  230. usb_deregister(&vp7045_usb_driver);
  231. }
  232. module_init(vp7045_usb_module_init);
  233. module_exit(vp7045_usb_module_exit);
  234. MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
  235. MODULE_DESCRIPTION("Driver for Twinhan MagicBox/Alpha and DNTV tinyUSB2 DVB-T USB2.0");
  236. MODULE_VERSION("1.0");
  237. MODULE_LICENSE("GPL");