gp8psk.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. static int gp8psk_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
  147. {
  148. return gp8psk_usb_out_op(adap->dev, ARM_TRANSFER, onoff, 0 , NULL, 0);
  149. }
  150. static int gp8psk_frontend_attach(struct dvb_usb_adapter *adap)
  151. {
  152. adap->fe = gp8psk_fe_attach(adap->dev);
  153. return 0;
  154. }
  155. static struct dvb_usb_device_properties gp8psk_properties;
  156. static int gp8psk_usb_probe(struct usb_interface *intf,
  157. const struct usb_device_id *id)
  158. {
  159. int ret;
  160. struct usb_device *udev = interface_to_usbdev(intf);
  161. ret = dvb_usb_device_init(intf,&gp8psk_properties,THIS_MODULE,NULL);
  162. if (ret == 0) {
  163. info("found Genpix USB device pID = %x (hex)",
  164. le16_to_cpu(udev->descriptor.idProduct));
  165. }
  166. return ret;
  167. }
  168. static struct usb_device_id gp8psk_usb_table [] = {
  169. { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_1_COLD) },
  170. { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_1_WARM) },
  171. { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_2) },
  172. { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_1) },
  173. { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_CW3K) },
  174. { 0 },
  175. };
  176. MODULE_DEVICE_TABLE(usb, gp8psk_usb_table);
  177. static struct dvb_usb_device_properties gp8psk_properties = {
  178. .usb_ctrl = CYPRESS_FX2,
  179. .firmware = "dvb-usb-gp8psk-01.fw",
  180. .num_adapters = 1,
  181. .adapter = {
  182. {
  183. .streaming_ctrl = gp8psk_streaming_ctrl,
  184. .frontend_attach = gp8psk_frontend_attach,
  185. /* parameter for the MPEG2-data transfer */
  186. .stream = {
  187. .type = USB_BULK,
  188. .count = 7,
  189. .endpoint = 0x82,
  190. .u = {
  191. .bulk = {
  192. .buffersize = 8192,
  193. }
  194. }
  195. },
  196. }
  197. },
  198. .power_ctrl = gp8psk_power_ctrl,
  199. .generic_bulk_ctrl_endpoint = 0x01,
  200. .num_device_descs = 4,
  201. .devices = {
  202. { .name = "Genpix 8PSK-to-USB2 Rev.1 DVB-S receiver",
  203. .cold_ids = { &gp8psk_usb_table[0], NULL },
  204. .warm_ids = { &gp8psk_usb_table[1], NULL },
  205. },
  206. { .name = "Genpix 8PSK-to-USB2 Rev.2 DVB-S receiver",
  207. .cold_ids = { NULL },
  208. .warm_ids = { &gp8psk_usb_table[2], NULL },
  209. },
  210. { .name = "Genpix SkyWalker-1 DVB-S receiver",
  211. .cold_ids = { NULL },
  212. .warm_ids = { &gp8psk_usb_table[3], NULL },
  213. },
  214. { .name = "Genpix SkyWalker-CW3K DVB-S receiver",
  215. .cold_ids = { NULL },
  216. .warm_ids = { &gp8psk_usb_table[4], NULL },
  217. },
  218. { NULL },
  219. }
  220. };
  221. /* usb specific object needed to register this driver with the usb subsystem */
  222. static struct usb_driver gp8psk_usb_driver = {
  223. .name = "dvb_usb_gp8psk",
  224. .probe = gp8psk_usb_probe,
  225. .disconnect = dvb_usb_device_exit,
  226. .id_table = gp8psk_usb_table,
  227. };
  228. /* module stuff */
  229. static int __init gp8psk_usb_module_init(void)
  230. {
  231. int result;
  232. if ((result = usb_register(&gp8psk_usb_driver))) {
  233. err("usb_register failed. (%d)",result);
  234. return result;
  235. }
  236. return 0;
  237. }
  238. static void __exit gp8psk_usb_module_exit(void)
  239. {
  240. /* deregister this driver from the USB subsystem */
  241. usb_deregister(&gp8psk_usb_driver);
  242. }
  243. module_init(gp8psk_usb_module_init);
  244. module_exit(gp8psk_usb_module_exit);
  245. MODULE_AUTHOR("Alan Nisota <alannisota@gamil.com>");
  246. MODULE_DESCRIPTION("Driver for Genpix 8psk-to-USB2 DVB-S");
  247. MODULE_VERSION("1.1");
  248. MODULE_LICENSE("GPL");