au6610.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. pr_err("%s: wlen = %d, aborting\n", KBUILD_MODNAME, wlen);
  47. ret = -EINVAL;
  48. goto error;
  49. }
  50. ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), operation,
  51. USB_TYPE_VENDOR|USB_DIR_IN, addr << 1, index,
  52. usb_buf, 6, AU6610_USB_TIMEOUT);
  53. dvb_usb_dbg_usb_control_msg(d->udev, operation,
  54. (USB_TYPE_VENDOR|USB_DIR_IN), addr << 1, index,
  55. usb_buf, 6);
  56. if (ret < 0)
  57. goto error;
  58. switch (operation) {
  59. case AU6610_REQ_I2C_READ:
  60. case AU6610_REQ_USB_READ:
  61. /* requested value is always 5th byte in buffer */
  62. rbuf[0] = usb_buf[4];
  63. }
  64. error:
  65. kfree(usb_buf);
  66. return ret;
  67. }
  68. static int au6610_i2c_msg(struct dvb_usb_device *d, u8 addr,
  69. u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  70. {
  71. u8 request;
  72. u8 wo = (rbuf == NULL || rlen == 0); /* write-only */
  73. if (wo) {
  74. request = AU6610_REQ_I2C_WRITE;
  75. } else { /* rw */
  76. request = AU6610_REQ_I2C_READ;
  77. }
  78. return au6610_usb_msg(d, request, addr, wbuf, wlen, rbuf, rlen);
  79. }
  80. /* I2C */
  81. static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  82. int num)
  83. {
  84. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  85. int i;
  86. if (num > 2)
  87. return -EINVAL;
  88. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  89. return -EAGAIN;
  90. for (i = 0; i < num; i++) {
  91. /* write/read request */
  92. if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
  93. if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
  94. msg[i].len, msg[i+1].buf,
  95. msg[i+1].len) < 0)
  96. break;
  97. i++;
  98. } else if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
  99. msg[i].len, NULL, 0) < 0)
  100. break;
  101. }
  102. mutex_unlock(&d->i2c_mutex);
  103. return i;
  104. }
  105. static u32 au6610_i2c_func(struct i2c_adapter *adapter)
  106. {
  107. return I2C_FUNC_I2C;
  108. }
  109. static struct i2c_algorithm au6610_i2c_algo = {
  110. .master_xfer = au6610_i2c_xfer,
  111. .functionality = au6610_i2c_func,
  112. };
  113. /* Callbacks for DVB USB */
  114. static struct zl10353_config au6610_zl10353_config = {
  115. .demod_address = 0x0f,
  116. .no_tuner = 1,
  117. .parallel_ts = 1,
  118. };
  119. static int au6610_zl10353_frontend_attach(struct dvb_usb_adapter *adap)
  120. {
  121. adap->fe[0] = dvb_attach(zl10353_attach, &au6610_zl10353_config,
  122. &adap_to_d(adap)->i2c_adap);
  123. if (adap->fe[0] == NULL)
  124. return -ENODEV;
  125. return 0;
  126. }
  127. static struct qt1010_config au6610_qt1010_config = {
  128. .i2c_address = 0x62
  129. };
  130. static int au6610_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
  131. {
  132. return dvb_attach(qt1010_attach, adap->fe[0],
  133. &adap_to_d(adap)->i2c_adap,
  134. &au6610_qt1010_config) == NULL ? -ENODEV : 0;
  135. }
  136. static int au6610_init(struct dvb_usb_device *d)
  137. {
  138. /* TODO: this functionality belongs likely to the streaming control */
  139. /* bInterfaceNumber 0, bAlternateSetting 5 */
  140. return usb_set_interface(d->udev, 0, 5);
  141. }
  142. static struct dvb_usb_device_properties au6610_props = {
  143. .driver_name = KBUILD_MODNAME,
  144. .owner = THIS_MODULE,
  145. .adapter_nr = adapter_nr,
  146. .i2c_algo = &au6610_i2c_algo,
  147. .frontend_attach = au6610_zl10353_frontend_attach,
  148. .tuner_attach = au6610_qt1010_tuner_attach,
  149. .init = au6610_init,
  150. .num_adapters = 1,
  151. .adapter = {
  152. {
  153. .stream = DVB_USB_STREAM_ISOC(0x82, 5, 40, 942, 1),
  154. },
  155. },
  156. };
  157. static const struct usb_device_id au6610_id_table[] = {
  158. { DVB_USB_DEVICE(USB_VID_ALCOR_MICRO, USB_PID_SIGMATEK_DVB_110,
  159. &au6610_props, "Sigmatek DVB-110", NULL) },
  160. { }
  161. };
  162. MODULE_DEVICE_TABLE(usb, au6610_id_table);
  163. static struct usb_driver au6610_driver = {
  164. .name = KBUILD_MODNAME,
  165. .id_table = au6610_id_table,
  166. .probe = dvb_usbv2_probe,
  167. .disconnect = dvb_usbv2_disconnect,
  168. .suspend = dvb_usbv2_suspend,
  169. .resume = dvb_usbv2_resume,
  170. .reset_resume = dvb_usbv2_reset_resume,
  171. .no_dynamic_id = 1,
  172. .soft_unbind = 1,
  173. };
  174. module_usb_driver(au6610_driver);
  175. MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
  176. MODULE_DESCRIPTION("Driver for Alcor Micro AU6610 DVB-T USB2.0");
  177. MODULE_VERSION("0.1");
  178. MODULE_LICENSE("GPL");