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