gp8psk.c 8.6 KB

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