gl861.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* DVB USB compliant linux driver for GL861 USB2.0 devices.
  2. *
  3. * This program is free software; you can redistribute it and/or modify it
  4. * under the terms of the GNU General Public License as published by the Free
  5. * Software Foundation, version 2.
  6. *
  7. * see Documentation/dvb/README.dvb-usb for more information
  8. */
  9. #include "gl861.h"
  10. #include "zl10353.h"
  11. #include "qt1010.h"
  12. /* debug */
  13. static int dvb_usb_gl861_debug;
  14. module_param_named(debug,dvb_usb_gl861_debug, int, 0644);
  15. MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
  16. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  17. static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr,
  18. u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  19. {
  20. u16 index;
  21. u16 value = addr << (8 + 1);
  22. int wo = (rbuf == NULL || rlen == 0); /* write-only */
  23. u8 req, type;
  24. if (wo) {
  25. req = GL861_REQ_I2C_WRITE;
  26. type = GL861_WRITE;
  27. } else { /* rw */
  28. req = GL861_REQ_I2C_READ;
  29. type = GL861_READ;
  30. }
  31. switch (wlen) {
  32. case 1:
  33. index = wbuf[0];
  34. break;
  35. case 2:
  36. index = wbuf[0];
  37. value = value + wbuf[1];
  38. break;
  39. default:
  40. warn("wlen = %x, aborting.", wlen);
  41. return -EINVAL;
  42. }
  43. return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
  44. value, index, rbuf, rlen, 2000);
  45. }
  46. /* I2C */
  47. static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  48. int num)
  49. {
  50. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  51. int i;
  52. if (num > 2)
  53. return -EINVAL;
  54. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  55. return -EAGAIN;
  56. for (i = 0; i < num; i++) {
  57. /* write/read request */
  58. if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
  59. if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf,
  60. msg[i].len, msg[i+1].buf, msg[i+1].len) < 0)
  61. break;
  62. i++;
  63. } else
  64. if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf,
  65. msg[i].len, NULL, 0) < 0)
  66. break;
  67. }
  68. mutex_unlock(&d->i2c_mutex);
  69. return i;
  70. }
  71. static u32 gl861_i2c_func(struct i2c_adapter *adapter)
  72. {
  73. return I2C_FUNC_I2C;
  74. }
  75. static struct i2c_algorithm gl861_i2c_algo = {
  76. .master_xfer = gl861_i2c_xfer,
  77. .functionality = gl861_i2c_func,
  78. };
  79. /* Callbacks for DVB USB */
  80. static int gl861_identify_state(struct usb_device *udev,
  81. struct dvb_usb_device_properties *props,
  82. struct dvb_usb_device_description **desc,
  83. int *cold)
  84. {
  85. *cold = 0;
  86. return 0;
  87. }
  88. static struct zl10353_config gl861_zl10353_config = {
  89. .demod_address = 0x0f,
  90. .no_tuner = 1,
  91. .parallel_ts = 1,
  92. };
  93. static int gl861_frontend_attach(struct dvb_usb_adapter *adap)
  94. {
  95. if ((adap->fe = dvb_attach(zl10353_attach, &gl861_zl10353_config,
  96. &adap->dev->i2c_adap)) != NULL) {
  97. return 0;
  98. }
  99. return -EIO;
  100. }
  101. static struct qt1010_config gl861_qt1010_config = {
  102. .i2c_address = 0x62
  103. };
  104. static int gl861_tuner_attach(struct dvb_usb_adapter *adap)
  105. {
  106. return dvb_attach(qt1010_attach,
  107. adap->fe, &adap->dev->i2c_adap,
  108. &gl861_qt1010_config) == NULL ? -ENODEV : 0;
  109. }
  110. /* DVB USB Driver stuff */
  111. static struct dvb_usb_device_properties gl861_properties;
  112. static int gl861_probe(struct usb_interface *intf,
  113. const struct usb_device_id *id)
  114. {
  115. struct dvb_usb_device *d;
  116. struct usb_host_interface *alt;
  117. int ret;
  118. if (intf->num_altsetting < 2)
  119. return -ENODEV;
  120. ret = dvb_usb_device_init(intf, &gl861_properties, THIS_MODULE, &d,
  121. adapter_nr);
  122. if (ret == 0) {
  123. alt = usb_altnum_to_altsetting(intf, 0);
  124. if (alt == NULL) {
  125. deb_rc("not alt found!\n");
  126. return -ENODEV;
  127. }
  128. ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
  129. alt->desc.bAlternateSetting);
  130. }
  131. return ret;
  132. }
  133. static struct usb_device_id gl861_table [] = {
  134. { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580_55801) },
  135. { USB_DEVICE(USB_VID_ALINK, USB_VID_ALINK_DTU) },
  136. { } /* Terminating entry */
  137. };
  138. MODULE_DEVICE_TABLE (usb, gl861_table);
  139. static struct dvb_usb_device_properties gl861_properties = {
  140. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  141. .usb_ctrl = DEVICE_SPECIFIC,
  142. .size_of_priv = 0,
  143. .identify_state = gl861_identify_state,
  144. .num_adapters = 1,
  145. .adapter = {{
  146. .frontend_attach = gl861_frontend_attach,
  147. .tuner_attach = gl861_tuner_attach,
  148. .stream = {
  149. .type = USB_BULK,
  150. .count = 7,
  151. .endpoint = 0x81,
  152. .u = {
  153. .bulk = {
  154. .buffersize = 512,
  155. }
  156. }
  157. },
  158. }},
  159. .i2c_algo = &gl861_i2c_algo,
  160. .num_device_descs = 2,
  161. .devices = {
  162. { "MSI Mega Sky 55801 DVB-T USB2.0",
  163. { &gl861_table[0], NULL },
  164. { NULL },
  165. },
  166. { "A-LINK DTU DVB-T USB2.0",
  167. { &gl861_table[1], NULL },
  168. { NULL },
  169. },
  170. }
  171. };
  172. static struct usb_driver gl861_driver = {
  173. .name = "dvb_usb_gl861",
  174. .probe = gl861_probe,
  175. .disconnect = dvb_usb_device_exit,
  176. .id_table = gl861_table,
  177. };
  178. /* module stuff */
  179. static int __init gl861_module_init(void)
  180. {
  181. int ret;
  182. if ((ret = usb_register(&gl861_driver))) {
  183. err("usb_register failed. Error number %d", ret);
  184. return ret;
  185. }
  186. return 0;
  187. }
  188. static void __exit gl861_module_exit(void)
  189. {
  190. /* deregister this driver from the USB subsystem */
  191. usb_deregister(&gl861_driver);
  192. }
  193. module_init (gl861_module_init);
  194. module_exit (gl861_module_exit);
  195. MODULE_AUTHOR("Carl Lundqvist <comabug@gmail.com>");
  196. MODULE_DESCRIPTION("Driver MSI Mega Sky 580 DVB-T USB2.0 / GL861");
  197. MODULE_VERSION("0.1");
  198. MODULE_LICENSE("GPL");