au6610.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. /* debug */
  24. static int dvb_usb_au6610_debug;
  25. module_param_named(debug, dvb_usb_au6610_debug, int, 0644);
  26. MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
  27. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  28. static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr,
  29. u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  30. {
  31. int ret;
  32. u16 index;
  33. u8 *usb_buf;
  34. /*
  35. * allocate enough for all known requests,
  36. * read returns 5 and write 6 bytes
  37. */
  38. usb_buf = kmalloc(6, GFP_KERNEL);
  39. if (!usb_buf)
  40. return -ENOMEM;
  41. switch (wlen) {
  42. case 1:
  43. index = wbuf[0] << 8;
  44. break;
  45. case 2:
  46. index = wbuf[0] << 8;
  47. index += wbuf[1];
  48. break;
  49. default:
  50. warn("wlen = %x, aborting.", wlen);
  51. ret = -EINVAL;
  52. goto error;
  53. }
  54. ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), operation,
  55. USB_TYPE_VENDOR|USB_DIR_IN, addr << 1, index,
  56. usb_buf, 6, AU6610_USB_TIMEOUT);
  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 = dvb_attach(zl10353_attach, &au6610_zl10353_config,
  123. &adap->dev->i2c_adap);
  124. if (adap->fe == 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,
  134. adap->fe, &adap->dev->i2c_adap,
  135. &au6610_qt1010_config) == NULL ? -ENODEV : 0;
  136. }
  137. /* DVB USB Driver stuff */
  138. static struct dvb_usb_device_properties au6610_properties;
  139. static int au6610_probe(struct usb_interface *intf,
  140. const struct usb_device_id *id)
  141. {
  142. struct dvb_usb_device *d;
  143. struct usb_host_interface *alt;
  144. int ret;
  145. if (intf->num_altsetting < AU6610_ALTSETTING_COUNT)
  146. return -ENODEV;
  147. ret = dvb_usb_device_init(intf, &au6610_properties, THIS_MODULE, &d,
  148. adapter_nr);
  149. if (ret == 0) {
  150. alt = usb_altnum_to_altsetting(intf, AU6610_ALTSETTING);
  151. if (alt == NULL) {
  152. deb_info("%s: no alt found!\n", __func__);
  153. return -ENODEV;
  154. }
  155. ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
  156. alt->desc.bAlternateSetting);
  157. }
  158. return ret;
  159. }
  160. static struct usb_device_id au6610_table [] = {
  161. { USB_DEVICE(USB_VID_ALCOR_MICRO, USB_PID_SIGMATEK_DVB_110) },
  162. { } /* Terminating entry */
  163. };
  164. MODULE_DEVICE_TABLE(usb, au6610_table);
  165. static struct dvb_usb_device_properties au6610_properties = {
  166. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  167. .usb_ctrl = DEVICE_SPECIFIC,
  168. .size_of_priv = 0,
  169. .num_adapters = 1,
  170. .adapter = {
  171. {
  172. .frontend_attach = au6610_zl10353_frontend_attach,
  173. .tuner_attach = au6610_qt1010_tuner_attach,
  174. .stream = {
  175. .type = USB_ISOC,
  176. .count = 5,
  177. .endpoint = 0x82,
  178. .u = {
  179. .isoc = {
  180. .framesperurb = 40,
  181. .framesize = 942,
  182. .interval = 1,
  183. }
  184. }
  185. },
  186. }
  187. },
  188. .i2c_algo = &au6610_i2c_algo,
  189. .num_device_descs = 1,
  190. .devices = {
  191. {
  192. .name = "Sigmatek DVB-110 DVB-T USB2.0",
  193. .cold_ids = {NULL},
  194. .warm_ids = {&au6610_table[0], NULL},
  195. },
  196. }
  197. };
  198. static struct usb_driver au6610_driver = {
  199. .name = "dvb_usb_au6610",
  200. .probe = au6610_probe,
  201. .disconnect = dvb_usb_device_exit,
  202. .id_table = au6610_table,
  203. };
  204. /* module stuff */
  205. static int __init au6610_module_init(void)
  206. {
  207. int ret;
  208. ret = usb_register(&au6610_driver);
  209. if (ret)
  210. err("usb_register failed. Error number %d", ret);
  211. return ret;
  212. }
  213. static void __exit au6610_module_exit(void)
  214. {
  215. /* deregister this driver from the USB subsystem */
  216. usb_deregister(&au6610_driver);
  217. }
  218. module_init(au6610_module_init);
  219. module_exit(au6610_module_exit);
  220. MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
  221. MODULE_DESCRIPTION("Driver for Alcor Micro AU6610 DVB-T USB2.0");
  222. MODULE_VERSION("0.1");
  223. MODULE_LICENSE("GPL");