au6610.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * DVB USB Linux driver for Alcor Micro AU6610 DVB-T USB2.0.
  3. *
  4. * Copyright (C) 2006 Antti Palosaari <crope@iki.fi>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include "au6610.h"
  21. #include "zl10353.h"
  22. #include "qt1010.h"
  23. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  24. static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr,
  25. u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  26. {
  27. int ret;
  28. u16 index;
  29. u8 *usb_buf;
  30. /*
  31. * allocate enough for all known requests,
  32. * read returns 5 and write 6 bytes
  33. */
  34. usb_buf = kmalloc(6, GFP_KERNEL);
  35. if (!usb_buf)
  36. return -ENOMEM;
  37. switch (wlen) {
  38. case 1:
  39. index = wbuf[0] << 8;
  40. break;
  41. case 2:
  42. index = wbuf[0] << 8;
  43. index += wbuf[1];
  44. break;
  45. default:
  46. dev_err(&d->udev->dev, "%s: wlen=%d, aborting\n",
  47. KBUILD_MODNAME, wlen);
  48. ret = -EINVAL;
  49. goto error;
  50. }
  51. ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), operation,
  52. USB_TYPE_VENDOR|USB_DIR_IN, addr << 1, index,
  53. usb_buf, 6, AU6610_USB_TIMEOUT);
  54. dvb_usb_dbg_usb_control_msg(d->udev, operation,
  55. (USB_TYPE_VENDOR|USB_DIR_IN), addr << 1, index,
  56. usb_buf, 6);
  57. if (ret < 0)
  58. goto error;
  59. switch (operation) {
  60. case AU6610_REQ_I2C_READ:
  61. case AU6610_REQ_USB_READ:
  62. /* requested value is always 5th byte in buffer */
  63. rbuf[0] = usb_buf[4];
  64. }
  65. error:
  66. kfree(usb_buf);
  67. return ret;
  68. }
  69. static int au6610_i2c_msg(struct dvb_usb_device *d, u8 addr,
  70. u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  71. {
  72. u8 request;
  73. u8 wo = (rbuf == NULL || rlen == 0); /* write-only */
  74. if (wo) {
  75. request = AU6610_REQ_I2C_WRITE;
  76. } else { /* rw */
  77. request = AU6610_REQ_I2C_READ;
  78. }
  79. return au6610_usb_msg(d, request, addr, wbuf, wlen, rbuf, rlen);
  80. }
  81. /* I2C */
  82. static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  83. int num)
  84. {
  85. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  86. int i;
  87. if (num > 2)
  88. return -EINVAL;
  89. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  90. return -EAGAIN;
  91. for (i = 0; i < num; i++) {
  92. /* write/read request */
  93. if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
  94. if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
  95. msg[i].len, msg[i+1].buf,
  96. msg[i+1].len) < 0)
  97. break;
  98. i++;
  99. } else if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
  100. msg[i].len, NULL, 0) < 0)
  101. break;
  102. }
  103. mutex_unlock(&d->i2c_mutex);
  104. return i;
  105. }
  106. static u32 au6610_i2c_func(struct i2c_adapter *adapter)
  107. {
  108. return I2C_FUNC_I2C;
  109. }
  110. static struct i2c_algorithm au6610_i2c_algo = {
  111. .master_xfer = au6610_i2c_xfer,
  112. .functionality = au6610_i2c_func,
  113. };
  114. /* Callbacks for DVB USB */
  115. static struct zl10353_config au6610_zl10353_config = {
  116. .demod_address = 0x0f,
  117. .no_tuner = 1,
  118. .parallel_ts = 1,
  119. };
  120. static int au6610_zl10353_frontend_attach(struct dvb_usb_adapter *adap)
  121. {
  122. adap->fe[0] = dvb_attach(zl10353_attach, &au6610_zl10353_config,
  123. &adap_to_d(adap)->i2c_adap);
  124. if (adap->fe[0] == NULL)
  125. return -ENODEV;
  126. return 0;
  127. }
  128. static struct qt1010_config au6610_qt1010_config = {
  129. .i2c_address = 0x62
  130. };
  131. static int au6610_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
  132. {
  133. return dvb_attach(qt1010_attach, adap->fe[0],
  134. &adap_to_d(adap)->i2c_adap,
  135. &au6610_qt1010_config) == NULL ? -ENODEV : 0;
  136. }
  137. static int au6610_init(struct dvb_usb_device *d)
  138. {
  139. /* TODO: this functionality belongs likely to the streaming control */
  140. /* bInterfaceNumber 0, bAlternateSetting 5 */
  141. return usb_set_interface(d->udev, 0, 5);
  142. }
  143. static struct dvb_usb_device_properties au6610_props = {
  144. .driver_name = KBUILD_MODNAME,
  145. .owner = THIS_MODULE,
  146. .adapter_nr = adapter_nr,
  147. .i2c_algo = &au6610_i2c_algo,
  148. .frontend_attach = au6610_zl10353_frontend_attach,
  149. .tuner_attach = au6610_qt1010_tuner_attach,
  150. .init = au6610_init,
  151. .num_adapters = 1,
  152. .adapter = {
  153. {
  154. .stream = DVB_USB_STREAM_ISOC(0x82, 5, 40, 942, 1),
  155. },
  156. },
  157. };
  158. static const struct usb_device_id au6610_id_table[] = {
  159. { DVB_USB_DEVICE(USB_VID_ALCOR_MICRO, USB_PID_SIGMATEK_DVB_110,
  160. &au6610_props, "Sigmatek DVB-110", NULL) },
  161. { }
  162. };
  163. MODULE_DEVICE_TABLE(usb, au6610_id_table);
  164. static struct usb_driver au6610_driver = {
  165. .name = KBUILD_MODNAME,
  166. .id_table = au6610_id_table,
  167. .probe = dvb_usbv2_probe,
  168. .disconnect = dvb_usbv2_disconnect,
  169. .suspend = dvb_usbv2_suspend,
  170. .resume = dvb_usbv2_resume,
  171. .reset_resume = dvb_usbv2_reset_resume,
  172. .no_dynamic_id = 1,
  173. .soft_unbind = 1,
  174. };
  175. module_usb_driver(au6610_driver);
  176. MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
  177. MODULE_DESCRIPTION("Driver for Alcor Micro AU6610 DVB-T USB2.0");
  178. MODULE_VERSION("0.1");
  179. MODULE_LICENSE("GPL");