au6610.c 4.9 KB

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