gp8psk.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* DVB USB compliant Linux driver for the
  2. * - GENPIX 8pks/qpsk/DCII USB2.0 DVB-S module
  3. *
  4. * Copyright (C) 2006,2007 Alan Nisota (alannisota@gmail.com)
  5. * Copyright (C) 2006,2007 Genpix Electronics (genpix@genpix-electronics.com)
  6. *
  7. * Thanks to GENPIX for the sample code used to implement this module.
  8. *
  9. * This module is based off the vp7045 and vp702x modules
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the Free
  13. * Software Foundation, version 2.
  14. *
  15. * see Documentation/dvb/README.dvb-usb for more information
  16. */
  17. #include "gp8psk.h"
  18. /* debug */
  19. static char bcm4500_firmware[] = "dvb-usb-gp8psk-02.fw";
  20. int dvb_usb_gp8psk_debug;
  21. module_param_named(debug,dvb_usb_gp8psk_debug, int, 0644);
  22. MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
  23. int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen)
  24. {
  25. int ret = 0,try = 0;
  26. if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
  27. return ret;
  28. while (ret >= 0 && ret != blen && try < 3) {
  29. ret = usb_control_msg(d->udev,
  30. usb_rcvctrlpipe(d->udev,0),
  31. req,
  32. USB_TYPE_VENDOR | USB_DIR_IN,
  33. value,index,b,blen,
  34. 2000);
  35. deb_info("reading number %d (ret: %d)\n",try,ret);
  36. try++;
  37. }
  38. if (ret < 0 || ret != blen) {
  39. warn("usb in %d operation failed.", req);
  40. ret = -EIO;
  41. } else
  42. ret = 0;
  43. deb_xfer("in: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
  44. debug_dump(b,blen,deb_xfer);
  45. mutex_unlock(&d->usb_mutex);
  46. return ret;
  47. }
  48. int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
  49. u16 index, u8 *b, int blen)
  50. {
  51. int ret;
  52. deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
  53. debug_dump(b,blen,deb_xfer);
  54. if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
  55. return ret;
  56. if (usb_control_msg(d->udev,
  57. usb_sndctrlpipe(d->udev,0),
  58. req,
  59. USB_TYPE_VENDOR | USB_DIR_OUT,
  60. value,index,b,blen,
  61. 2000) != blen) {
  62. warn("usb out operation failed.");
  63. ret = -EIO;
  64. } else
  65. ret = 0;
  66. mutex_unlock(&d->usb_mutex);
  67. return ret;
  68. }
  69. static int gp8psk_load_bcm4500fw(struct dvb_usb_device *d)
  70. {
  71. int ret;
  72. const struct firmware *fw = NULL;
  73. u8 *ptr, *buf;
  74. if ((ret = request_firmware(&fw, bcm4500_firmware,
  75. &d->udev->dev)) != 0) {
  76. err("did not find the bcm4500 firmware file. (%s) "
  77. "Please see linux/Documentation/dvb/ for more details on firmware-problems. (%d)",
  78. bcm4500_firmware,ret);
  79. return ret;
  80. }
  81. ret = -EINVAL;
  82. if (gp8psk_usb_out_op(d, LOAD_BCM4500,1,0,NULL, 0))
  83. goto out_rel_fw;
  84. info("downloading bcm4500 firmware from file '%s'",bcm4500_firmware);
  85. ptr = fw->data;
  86. buf = kmalloc(64, GFP_KERNEL | GFP_DMA);
  87. while (ptr[0] != 0xff) {
  88. u16 buflen = ptr[0] + 4;
  89. if (ptr + buflen >= fw->data + fw->size) {
  90. err("failed to load bcm4500 firmware.");
  91. goto out_free;
  92. }
  93. memcpy(buf, ptr, buflen);
  94. if (dvb_usb_generic_write(d, buf, buflen)) {
  95. err("failed to load bcm4500 firmware.");
  96. goto out_free;
  97. }
  98. ptr += buflen;
  99. }
  100. ret = 0;
  101. out_free:
  102. kfree(buf);
  103. out_rel_fw:
  104. release_firmware(fw);
  105. return ret;
  106. }
  107. static int gp8psk_power_ctrl(struct dvb_usb_device *d, int onoff)
  108. {
  109. u8 status, buf;
  110. int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct);
  111. if (onoff) {
  112. gp8psk_usb_in_op(d, GET_8PSK_CONFIG,0,0,&status,1);
  113. if (! (status & bm8pskStarted)) { /* started */
  114. if(gp_product_id == USB_PID_GENPIX_SKYWALKER_CW3K)
  115. gp8psk_usb_out_op(d, CW3K_INIT, 1, 0, NULL, 0);
  116. if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
  117. return -EINVAL;
  118. }
  119. if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
  120. if (! (status & bm8pskFW_Loaded)) /* BCM4500 firmware loaded */
  121. if(gp8psk_load_bcm4500fw(d))
  122. return EINVAL;
  123. if (! (status & bmIntersilOn)) /* LNB Power */
  124. if (gp8psk_usb_in_op(d, START_INTERSIL, 1, 0,
  125. &buf, 1))
  126. return EINVAL;
  127. /* Set DVB mode to 1 */
  128. if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
  129. if (gp8psk_usb_out_op(d, SET_DVB_MODE, 1, 0, NULL, 0))
  130. return EINVAL;
  131. /* Abort possible TS (if previous tune crashed) */
  132. if (gp8psk_usb_out_op(d, ARM_TRANSFER, 0, 0, NULL, 0))
  133. return EINVAL;
  134. } else {
  135. /* Turn off LNB power */
  136. if (gp8psk_usb_in_op(d, START_INTERSIL, 0, 0, &buf, 1))
  137. return EINVAL;
  138. /* Turn off 8psk power */
  139. if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1))
  140. return -EINVAL;
  141. if(gp_product_id == USB_PID_GENPIX_SKYWALKER_CW3K)
  142. gp8psk_usb_out_op(d, CW3K_INIT, 0, 0, NULL, 0);
  143. }
  144. return 0;
  145. }
  146. int gp8psk_bcm4500_reload(struct dvb_usb_device *d)
  147. {
  148. u8 buf;
  149. int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct);
  150. /* Turn off 8psk power */
  151. if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1))
  152. return -EINVAL;
  153. /* Turn On 8psk power */
  154. if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
  155. return -EINVAL;
  156. /* load BCM4500 firmware */
  157. if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
  158. if (gp8psk_load_bcm4500fw(d))
  159. return EINVAL;
  160. return 0;
  161. }
  162. static int gp8psk_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
  163. {
  164. return gp8psk_usb_out_op(adap->dev, ARM_TRANSFER, onoff, 0 , NULL, 0);
  165. }
  166. static int gp8psk_frontend_attach(struct dvb_usb_adapter *adap)
  167. {
  168. adap->fe = gp8psk_fe_attach(adap->dev);
  169. return 0;
  170. }
  171. static struct dvb_usb_device_properties gp8psk_properties;
  172. static int gp8psk_usb_probe(struct usb_interface *intf,
  173. const struct usb_device_id *id)
  174. {
  175. int ret;
  176. struct usb_device *udev = interface_to_usbdev(intf);
  177. ret = dvb_usb_device_init(intf,&gp8psk_properties,THIS_MODULE,NULL);
  178. if (ret == 0) {
  179. info("found Genpix USB device pID = %x (hex)",
  180. le16_to_cpu(udev->descriptor.idProduct));
  181. }
  182. return ret;
  183. }
  184. static struct usb_device_id gp8psk_usb_table [] = {
  185. { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_1_COLD) },
  186. { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_1_WARM) },
  187. { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_2) },
  188. { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_1) },
  189. { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_CW3K) },
  190. { 0 },
  191. };
  192. MODULE_DEVICE_TABLE(usb, gp8psk_usb_table);
  193. static struct dvb_usb_device_properties gp8psk_properties = {
  194. .usb_ctrl = CYPRESS_FX2,
  195. .firmware = "dvb-usb-gp8psk-01.fw",
  196. .num_adapters = 1,
  197. .adapter = {
  198. {
  199. .streaming_ctrl = gp8psk_streaming_ctrl,
  200. .frontend_attach = gp8psk_frontend_attach,
  201. /* parameter for the MPEG2-data transfer */
  202. .stream = {
  203. .type = USB_BULK,
  204. .count = 7,
  205. .endpoint = 0x82,
  206. .u = {
  207. .bulk = {
  208. .buffersize = 8192,
  209. }
  210. }
  211. },
  212. }
  213. },
  214. .power_ctrl = gp8psk_power_ctrl,
  215. .generic_bulk_ctrl_endpoint = 0x01,
  216. .num_device_descs = 4,
  217. .devices = {
  218. { .name = "Genpix 8PSK-to-USB2 Rev.1 DVB-S receiver",
  219. .cold_ids = { &gp8psk_usb_table[0], NULL },
  220. .warm_ids = { &gp8psk_usb_table[1], NULL },
  221. },
  222. { .name = "Genpix 8PSK-to-USB2 Rev.2 DVB-S receiver",
  223. .cold_ids = { NULL },
  224. .warm_ids = { &gp8psk_usb_table[2], NULL },
  225. },
  226. { .name = "Genpix SkyWalker-1 DVB-S receiver",
  227. .cold_ids = { NULL },
  228. .warm_ids = { &gp8psk_usb_table[3], NULL },
  229. },
  230. { .name = "Genpix SkyWalker-CW3K DVB-S receiver",
  231. .cold_ids = { NULL },
  232. .warm_ids = { &gp8psk_usb_table[4], NULL },
  233. },
  234. { NULL },
  235. }
  236. };
  237. /* usb specific object needed to register this driver with the usb subsystem */
  238. static struct usb_driver gp8psk_usb_driver = {
  239. .name = "dvb_usb_gp8psk",
  240. .probe = gp8psk_usb_probe,
  241. .disconnect = dvb_usb_device_exit,
  242. .id_table = gp8psk_usb_table,
  243. };
  244. /* module stuff */
  245. static int __init gp8psk_usb_module_init(void)
  246. {
  247. int result;
  248. if ((result = usb_register(&gp8psk_usb_driver))) {
  249. err("usb_register failed. (%d)",result);
  250. return result;
  251. }
  252. return 0;
  253. }
  254. static void __exit gp8psk_usb_module_exit(void)
  255. {
  256. /* deregister this driver from the USB subsystem */
  257. usb_deregister(&gp8psk_usb_driver);
  258. }
  259. module_init(gp8psk_usb_module_init);
  260. module_exit(gp8psk_usb_module_exit);
  261. MODULE_AUTHOR("Alan Nisota <alannisota@gamil.com>");
  262. MODULE_DESCRIPTION("Driver for Genpix 8psk-to-USB2 DVB-S");
  263. MODULE_VERSION("1.1");
  264. MODULE_LICENSE("GPL");