vp7045.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. static 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. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  21. #define deb_info(args...) dprintk(dvb_usb_vp7045_debug,0x01,args)
  22. #define deb_xfer(args...) dprintk(dvb_usb_vp7045_debug,0x02,args)
  23. #define deb_rc(args...) dprintk(dvb_usb_vp7045_debug,0x04,args)
  24. int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in, int inlen, int msec)
  25. {
  26. int ret = 0;
  27. u8 *buf = d->priv;
  28. buf[0] = cmd;
  29. if (outlen > 19)
  30. outlen = 19;
  31. if (inlen > 11)
  32. inlen = 11;
  33. ret = mutex_lock_interruptible(&d->usb_mutex);
  34. if (ret)
  35. return ret;
  36. if (out != NULL && outlen > 0)
  37. memcpy(&buf[1], out, outlen);
  38. deb_xfer("out buffer: ");
  39. debug_dump(buf, outlen+1, deb_xfer);
  40. if (usb_control_msg(d->udev,
  41. usb_sndctrlpipe(d->udev,0),
  42. TH_COMMAND_OUT, USB_TYPE_VENDOR | USB_DIR_OUT, 0, 0,
  43. buf, 20, 2000) != 20) {
  44. err("USB control message 'out' went wrong.");
  45. ret = -EIO;
  46. goto unlock;
  47. }
  48. msleep(msec);
  49. if (usb_control_msg(d->udev,
  50. usb_rcvctrlpipe(d->udev,0),
  51. TH_COMMAND_IN, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
  52. buf, 12, 2000) != 12) {
  53. err("USB control message 'in' went wrong.");
  54. ret = -EIO;
  55. goto unlock;
  56. }
  57. deb_xfer("in buffer: ");
  58. debug_dump(buf, 12, deb_xfer);
  59. if (in != NULL && inlen > 0)
  60. memcpy(in, &buf[1], inlen);
  61. unlock:
  62. mutex_unlock(&d->usb_mutex);
  63. return ret;
  64. }
  65. u8 vp7045_read_reg(struct dvb_usb_device *d, u8 reg)
  66. {
  67. u8 obuf[2] = { 0 },v;
  68. obuf[1] = reg;
  69. vp7045_usb_op(d,TUNER_REG_READ,obuf,2,&v,1,30);
  70. return v;
  71. }
  72. static int vp7045_power_ctrl(struct dvb_usb_device *d, int onoff)
  73. {
  74. u8 v = onoff;
  75. return vp7045_usb_op(d,SET_TUNER_POWER,&v,1,NULL,0,150);
  76. }
  77. /* remote control stuff */
  78. /* The keymapping struct. Somehow this should be loaded to the driver, but
  79. * currently it is hardcoded. */
  80. static struct rc_map_table rc_map_vp7045_table[] = {
  81. { 0x0016, KEY_POWER },
  82. { 0x0010, KEY_MUTE },
  83. { 0x0003, KEY_1 },
  84. { 0x0001, KEY_2 },
  85. { 0x0006, KEY_3 },
  86. { 0x0009, KEY_4 },
  87. { 0x001d, KEY_5 },
  88. { 0x001f, KEY_6 },
  89. { 0x000d, KEY_7 },
  90. { 0x0019, KEY_8 },
  91. { 0x001b, KEY_9 },
  92. { 0x0015, KEY_0 },
  93. { 0x0005, KEY_CHANNELUP },
  94. { 0x0002, KEY_CHANNELDOWN },
  95. { 0x001e, KEY_VOLUMEUP },
  96. { 0x000a, KEY_VOLUMEDOWN },
  97. { 0x0011, KEY_RECORD },
  98. { 0x0017, KEY_FAVORITES }, /* Heart symbol - Channel list. */
  99. { 0x0014, KEY_PLAY },
  100. { 0x001a, KEY_STOP },
  101. { 0x0040, KEY_REWIND },
  102. { 0x0012, KEY_FASTFORWARD },
  103. { 0x000e, KEY_PREVIOUS }, /* Recall - Previous channel. */
  104. { 0x004c, KEY_PAUSE },
  105. { 0x004d, KEY_SCREEN }, /* Full screen mode. */
  106. { 0x0054, KEY_AUDIO }, /* MTS - Switch to secondary audio. */
  107. { 0x000c, KEY_CANCEL }, /* Cancel */
  108. { 0x001c, KEY_EPG }, /* EPG */
  109. { 0x0000, KEY_TAB }, /* Tab */
  110. { 0x0048, KEY_INFO }, /* Preview */
  111. { 0x0004, KEY_LIST }, /* RecordList */
  112. { 0x000f, KEY_TEXT }, /* Teletext */
  113. { 0x0041, KEY_PREVIOUSSONG },
  114. { 0x0042, KEY_NEXTSONG },
  115. { 0x004b, KEY_UP },
  116. { 0x0051, KEY_DOWN },
  117. { 0x004e, KEY_LEFT },
  118. { 0x0052, KEY_RIGHT },
  119. { 0x004f, KEY_ENTER },
  120. { 0x0013, KEY_CANCEL },
  121. { 0x004a, KEY_CLEAR },
  122. { 0x0054, KEY_PRINT }, /* Capture */
  123. { 0x0043, KEY_SUBTITLE }, /* Subtitle/CC */
  124. { 0x0008, KEY_VIDEO }, /* A/V */
  125. { 0x0007, KEY_SLEEP }, /* Hibernate */
  126. { 0x0045, KEY_ZOOM }, /* Zoom+ */
  127. { 0x0018, KEY_RED},
  128. { 0x0053, KEY_GREEN},
  129. { 0x005e, KEY_YELLOW},
  130. { 0x005f, KEY_BLUE}
  131. };
  132. static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
  133. {
  134. u8 key;
  135. int i;
  136. vp7045_usb_op(d,RC_VAL_READ,NULL,0,&key,1,20);
  137. deb_rc("remote query key: %x %d\n",key,key);
  138. if (key == 0x44) {
  139. *state = REMOTE_NO_KEY_PRESSED;
  140. return 0;
  141. }
  142. for (i = 0; i < ARRAY_SIZE(rc_map_vp7045_table); i++)
  143. if (rc5_data(&rc_map_vp7045_table[i]) == key) {
  144. *state = REMOTE_KEY_PRESSED;
  145. *event = rc_map_vp7045_table[i].keycode;
  146. break;
  147. }
  148. return 0;
  149. }
  150. static int vp7045_read_eeprom(struct dvb_usb_device *d,u8 *buf, int len, int offset)
  151. {
  152. int i = 0;
  153. u8 v,br[2];
  154. for (i=0; i < len; i++) {
  155. v = offset + i;
  156. vp7045_usb_op(d,GET_EE_VALUE,&v,1,br,2,5);
  157. buf[i] = br[1];
  158. }
  159. deb_info("VP7045 EEPROM read (offs: %d, len: %d) : ",offset, i);
  160. debug_dump(buf,i,deb_info);
  161. return 0;
  162. }
  163. static int vp7045_read_mac_addr(struct dvb_usb_device *d,u8 mac[6])
  164. {
  165. return vp7045_read_eeprom(d,mac, 6, MAC_0_ADDR);
  166. }
  167. static int vp7045_frontend_attach(struct dvb_usb_adapter *adap)
  168. {
  169. u8 buf[255] = { 0 };
  170. vp7045_usb_op(adap->dev,VENDOR_STRING_READ,NULL,0,buf,20,0);
  171. buf[10] = '\0';
  172. deb_info("firmware says: %s ",buf);
  173. vp7045_usb_op(adap->dev,PRODUCT_STRING_READ,NULL,0,buf,20,0);
  174. buf[10] = '\0';
  175. deb_info("%s ",buf);
  176. vp7045_usb_op(adap->dev,FW_VERSION_READ,NULL,0,buf,20,0);
  177. buf[10] = '\0';
  178. deb_info("v%s\n",buf);
  179. /* Dump the EEPROM */
  180. /* vp7045_read_eeprom(d,buf, 255, FX2_ID_ADDR); */
  181. adap->fe_adap[0].fe = vp7045_fe_attach(adap->dev);
  182. return 0;
  183. }
  184. static struct dvb_usb_device_properties vp7045_properties;
  185. static int vp7045_usb_probe(struct usb_interface *intf,
  186. const struct usb_device_id *id)
  187. {
  188. return dvb_usb_device_init(intf, &vp7045_properties,
  189. THIS_MODULE, NULL, adapter_nr);
  190. }
  191. static struct usb_device_id vp7045_usb_table [] = {
  192. { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7045_COLD) },
  193. { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7045_WARM) },
  194. { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_DNTV_TINYUSB2_COLD) },
  195. { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_DNTV_TINYUSB2_WARM) },
  196. { 0 },
  197. };
  198. MODULE_DEVICE_TABLE(usb, vp7045_usb_table);
  199. static struct dvb_usb_device_properties vp7045_properties = {
  200. .usb_ctrl = CYPRESS_FX2,
  201. .firmware = "dvb-usb-vp7045-01.fw",
  202. .size_of_priv = 20,
  203. .num_adapters = 1,
  204. .adapter = {
  205. {
  206. .num_frontends = 1,
  207. .fe = {{
  208. .frontend_attach = vp7045_frontend_attach,
  209. /* parameter for the MPEG2-data transfer */
  210. .stream = {
  211. .type = USB_BULK,
  212. .count = 7,
  213. .endpoint = 0x02,
  214. .u = {
  215. .bulk = {
  216. .buffersize = 4096,
  217. }
  218. }
  219. },
  220. }},
  221. }
  222. },
  223. .power_ctrl = vp7045_power_ctrl,
  224. .read_mac_address = vp7045_read_mac_addr,
  225. .rc.legacy = {
  226. .rc_interval = 400,
  227. .rc_map_table = rc_map_vp7045_table,
  228. .rc_map_size = ARRAY_SIZE(rc_map_vp7045_table),
  229. .rc_query = vp7045_rc_query,
  230. },
  231. .num_device_descs = 2,
  232. .devices = {
  233. { .name = "Twinhan USB2.0 DVB-T receiver (TwinhanDTV Alpha/MagicBox II)",
  234. .cold_ids = { &vp7045_usb_table[0], NULL },
  235. .warm_ids = { &vp7045_usb_table[1], NULL },
  236. },
  237. { .name = "DigitalNow TinyUSB 2 DVB-t Receiver",
  238. .cold_ids = { &vp7045_usb_table[2], NULL },
  239. .warm_ids = { &vp7045_usb_table[3], NULL },
  240. },
  241. { NULL },
  242. }
  243. };
  244. /* usb specific object needed to register this driver with the usb subsystem */
  245. static struct usb_driver vp7045_usb_driver = {
  246. .name = "dvb_usb_vp7045",
  247. .probe = vp7045_usb_probe,
  248. .disconnect = dvb_usb_device_exit,
  249. .id_table = vp7045_usb_table,
  250. };
  251. module_usb_driver(vp7045_usb_driver);
  252. MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
  253. MODULE_DESCRIPTION("Driver for Twinhan MagicBox/Alpha and DNTV tinyUSB2 DVB-T USB2.0");
  254. MODULE_VERSION("1.0");
  255. MODULE_LICENSE("GPL");