gp8psk.c 7.6 KB

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