gl861.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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
  5. * Free 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))."
  16. DVB_USB_DEBUG_STATUS);
  17. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  18. static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr,
  19. u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  20. {
  21. u16 index;
  22. u16 value = addr << (8 + 1);
  23. int wo = (rbuf == NULL || rlen == 0); /* write-only */
  24. u8 req, type;
  25. if (wo) {
  26. req = GL861_REQ_I2C_WRITE;
  27. type = GL861_WRITE;
  28. } else { /* rw */
  29. req = GL861_REQ_I2C_READ;
  30. type = GL861_READ;
  31. }
  32. switch (wlen) {
  33. case 1:
  34. index = wbuf[0];
  35. break;
  36. case 2:
  37. index = wbuf[0];
  38. value = value + wbuf[1];
  39. break;
  40. default:
  41. warn("wlen = %x, aborting.", wlen);
  42. return -EINVAL;
  43. }
  44. msleep(1); /* avoid I2C errors */
  45. return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
  46. value, index, rbuf, rlen, 2000);
  47. }
  48. /* I2C */
  49. static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  50. int num)
  51. {
  52. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  53. int i;
  54. if (num > 2)
  55. return -EINVAL;
  56. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  57. return -EAGAIN;
  58. for (i = 0; i < num; i++) {
  59. /* write/read request */
  60. if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
  61. if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf,
  62. msg[i].len, msg[i+1].buf, msg[i+1].len) < 0)
  63. break;
  64. i++;
  65. } else
  66. if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf,
  67. msg[i].len, NULL, 0) < 0)
  68. break;
  69. }
  70. mutex_unlock(&d->i2c_mutex);
  71. return i;
  72. }
  73. static u32 gl861_i2c_func(struct i2c_adapter *adapter)
  74. {
  75. return I2C_FUNC_I2C;
  76. }
  77. static struct i2c_algorithm gl861_i2c_algo = {
  78. .master_xfer = gl861_i2c_xfer,
  79. .functionality = gl861_i2c_func,
  80. };
  81. /* Callbacks for DVB USB */
  82. static struct zl10353_config gl861_zl10353_config = {
  83. .demod_address = 0x0f,
  84. .no_tuner = 1,
  85. .parallel_ts = 1,
  86. };
  87. static int gl861_frontend_attach(struct dvb_usb_adapter *adap)
  88. {
  89. adap->fe_adap[0].fe = dvb_attach(zl10353_attach, &gl861_zl10353_config,
  90. &adap->dev->i2c_adap);
  91. if (adap->fe_adap[0].fe == NULL)
  92. return -EIO;
  93. return 0;
  94. }
  95. static struct qt1010_config gl861_qt1010_config = {
  96. .i2c_address = 0x62
  97. };
  98. static int gl861_tuner_attach(struct dvb_usb_adapter *adap)
  99. {
  100. return dvb_attach(qt1010_attach,
  101. adap->fe_adap[0].fe, &adap->dev->i2c_adap,
  102. &gl861_qt1010_config) == NULL ? -ENODEV : 0;
  103. }
  104. /* DVB USB Driver stuff */
  105. static struct dvb_usb_device_properties gl861_properties;
  106. static int gl861_probe(struct usb_interface *intf,
  107. const struct usb_device_id *id)
  108. {
  109. struct dvb_usb_device *d;
  110. struct usb_host_interface *alt;
  111. int ret;
  112. if (intf->num_altsetting < 2)
  113. return -ENODEV;
  114. ret = dvb_usb_device_init(intf, &gl861_properties, THIS_MODULE, &d,
  115. adapter_nr);
  116. if (ret == 0) {
  117. alt = usb_altnum_to_altsetting(intf, 0);
  118. if (alt == NULL) {
  119. deb_rc("not alt found!\n");
  120. return -ENODEV;
  121. }
  122. ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
  123. alt->desc.bAlternateSetting);
  124. }
  125. return ret;
  126. }
  127. static struct usb_device_id gl861_table [] = {
  128. { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580_55801) },
  129. { USB_DEVICE(USB_VID_ALINK, USB_VID_ALINK_DTU) },
  130. { } /* Terminating entry */
  131. };
  132. MODULE_DEVICE_TABLE(usb, gl861_table);
  133. static struct dvb_usb_device_properties gl861_properties = {
  134. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  135. .usb_ctrl = DEVICE_SPECIFIC,
  136. .size_of_priv = 0,
  137. .num_adapters = 1,
  138. .adapter = {{
  139. .num_frontends = 1,
  140. .fe = {{
  141. .frontend_attach = gl861_frontend_attach,
  142. .tuner_attach = gl861_tuner_attach,
  143. .stream = {
  144. .type = USB_BULK,
  145. .count = 7,
  146. .endpoint = 0x81,
  147. .u = {
  148. .bulk = {
  149. .buffersize = 512,
  150. }
  151. }
  152. },
  153. }},
  154. } },
  155. .i2c_algo = &gl861_i2c_algo,
  156. .num_device_descs = 2,
  157. .devices = {
  158. {
  159. .name = "MSI Mega Sky 55801 DVB-T USB2.0",
  160. .cold_ids = { NULL },
  161. .warm_ids = { &gl861_table[0], NULL },
  162. },
  163. {
  164. .name = "A-LINK DTU DVB-T USB2.0",
  165. .cold_ids = { NULL },
  166. .warm_ids = { &gl861_table[1], NULL },
  167. },
  168. }
  169. };
  170. static struct usb_driver gl861_driver = {
  171. .name = "dvb_usb_gl861",
  172. .probe = gl861_probe,
  173. .disconnect = dvb_usb_device_exit,
  174. .id_table = gl861_table,
  175. };
  176. module_usb_driver(gl861_driver);
  177. MODULE_AUTHOR("Carl Lundqvist <comabug@gmail.com>");
  178. MODULE_DESCRIPTION("Driver MSI Mega Sky 580 DVB-T USB2.0 / GL861");
  179. MODULE_VERSION("0.1");
  180. MODULE_LICENSE("GPL");