gl861.c 4.1 KB

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