gl861.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  13. static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr,
  14. u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  15. {
  16. u16 index;
  17. u16 value = addr << (8 + 1);
  18. int wo = (rbuf == NULL || rlen == 0); /* write-only */
  19. u8 req, type;
  20. if (wo) {
  21. req = GL861_REQ_I2C_WRITE;
  22. type = GL861_WRITE;
  23. } else { /* rw */
  24. req = GL861_REQ_I2C_READ;
  25. type = GL861_READ;
  26. }
  27. switch (wlen) {
  28. case 1:
  29. index = wbuf[0];
  30. break;
  31. case 2:
  32. index = wbuf[0];
  33. value = value + wbuf[1];
  34. break;
  35. default:
  36. dev_err(&d->udev->dev, "%s: wlen=%d, aborting\n",
  37. KBUILD_MODNAME, wlen);
  38. return -EINVAL;
  39. }
  40. msleep(1); /* avoid I2C errors */
  41. return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
  42. value, index, rbuf, rlen, 2000);
  43. }
  44. /* I2C */
  45. static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  46. int num)
  47. {
  48. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  49. int i;
  50. if (num > 2)
  51. return -EINVAL;
  52. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  53. return -EAGAIN;
  54. for (i = 0; i < num; i++) {
  55. /* write/read request */
  56. if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
  57. if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf,
  58. msg[i].len, msg[i+1].buf, msg[i+1].len) < 0)
  59. break;
  60. i++;
  61. } else
  62. if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf,
  63. msg[i].len, NULL, 0) < 0)
  64. break;
  65. }
  66. mutex_unlock(&d->i2c_mutex);
  67. return i;
  68. }
  69. static u32 gl861_i2c_func(struct i2c_adapter *adapter)
  70. {
  71. return I2C_FUNC_I2C;
  72. }
  73. static struct i2c_algorithm gl861_i2c_algo = {
  74. .master_xfer = gl861_i2c_xfer,
  75. .functionality = gl861_i2c_func,
  76. };
  77. /* Callbacks for DVB USB */
  78. static struct zl10353_config gl861_zl10353_config = {
  79. .demod_address = 0x0f,
  80. .no_tuner = 1,
  81. .parallel_ts = 1,
  82. };
  83. static int gl861_frontend_attach(struct dvb_usb_adapter *adap)
  84. {
  85. adap->fe[0] = dvb_attach(zl10353_attach, &gl861_zl10353_config,
  86. &adap_to_d(adap)->i2c_adap);
  87. if (adap->fe[0] == NULL)
  88. return -EIO;
  89. return 0;
  90. }
  91. static struct qt1010_config gl861_qt1010_config = {
  92. .i2c_address = 0x62
  93. };
  94. static int gl861_tuner_attach(struct dvb_usb_adapter *adap)
  95. {
  96. return dvb_attach(qt1010_attach,
  97. adap->fe[0], &adap_to_d(adap)->i2c_adap,
  98. &gl861_qt1010_config) == NULL ? -ENODEV : 0;
  99. }
  100. static int gl861_init(struct dvb_usb_device *d)
  101. {
  102. /*
  103. * There is 2 interfaces. Interface 0 is for TV and interface 1 is
  104. * for HID remote controller. Interface 0 has 2 alternate settings.
  105. * For some reason we need to set interface explicitly, defaulted
  106. * as alternate setting 1?
  107. */
  108. return usb_set_interface(d->udev, 0, 0);
  109. }
  110. /* DVB USB Driver stuff */
  111. static struct dvb_usb_device_properties gl861_props = {
  112. .driver_name = KBUILD_MODNAME,
  113. .owner = THIS_MODULE,
  114. .adapter_nr = adapter_nr,
  115. .i2c_algo = &gl861_i2c_algo,
  116. .frontend_attach = gl861_frontend_attach,
  117. .tuner_attach = gl861_tuner_attach,
  118. .init = gl861_init,
  119. .num_adapters = 1,
  120. .adapter = {
  121. {
  122. .stream = DVB_USB_STREAM_BULK(0x81, 7, 512),
  123. }
  124. }
  125. };
  126. static const struct usb_device_id gl861_id_table[] = {
  127. { DVB_USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580_55801,
  128. &gl861_props, "MSI Mega Sky 55801 DVB-T USB2.0", NULL) },
  129. { DVB_USB_DEVICE(USB_VID_ALINK, USB_VID_ALINK_DTU,
  130. &gl861_props, "A-LINK DTU DVB-T USB2.0", NULL) },
  131. { }
  132. };
  133. MODULE_DEVICE_TABLE(usb, gl861_id_table);
  134. static struct usb_driver gl861_usb_driver = {
  135. .name = KBUILD_MODNAME,
  136. .id_table = gl861_id_table,
  137. .probe = dvb_usbv2_probe,
  138. .disconnect = dvb_usbv2_disconnect,
  139. .suspend = dvb_usbv2_suspend,
  140. .resume = dvb_usbv2_resume,
  141. .reset_resume = dvb_usbv2_reset_resume,
  142. .no_dynamic_id = 1,
  143. .soft_unbind = 1,
  144. };
  145. module_usb_driver(gl861_usb_driver);
  146. MODULE_AUTHOR("Carl Lundqvist <comabug@gmail.com>");
  147. MODULE_DESCRIPTION("Driver MSI Mega Sky 580 DVB-T USB2.0 / GL861");
  148. MODULE_VERSION("0.1");
  149. MODULE_LICENSE("GPL");