au6610.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /* DVB USB compliant linux driver for Sigmatek DVB-110 DVB-T USB2.0 receiver
  2. *
  3. * Copyright (C) 2006 Antti Palosaari <crope@iki.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation, version 2.
  8. *
  9. * see Documentation/dvb/README.dvb-usb for more information
  10. */
  11. #include "au6610.h"
  12. #include "zl10353.h"
  13. #include "qt1010.h"
  14. /* debug */
  15. static int dvb_usb_au6610_debug;
  16. module_param_named(debug, dvb_usb_au6610_debug, int, 0644);
  17. MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))."
  18. DVB_USB_DEBUG_STATUS);
  19. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  20. static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr,
  21. u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  22. {
  23. int ret;
  24. u16 index;
  25. u8 usb_buf[6]; /* enough for all known requests,
  26. read returns 5 and write 6 bytes */
  27. switch (wlen) {
  28. case 1:
  29. index = wbuf[0] << 8;
  30. break;
  31. case 2:
  32. index = wbuf[0] << 8;
  33. index += wbuf[1];
  34. break;
  35. default:
  36. warn("wlen = %x, aborting.", wlen);
  37. return -EINVAL;
  38. }
  39. ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), operation,
  40. USB_TYPE_VENDOR|USB_DIR_IN, addr << 1, index,
  41. usb_buf, sizeof(usb_buf), AU6610_USB_TIMEOUT);
  42. if (ret < 0)
  43. return ret;
  44. switch (operation) {
  45. case AU6610_REQ_I2C_READ:
  46. case AU6610_REQ_USB_READ:
  47. /* requested value is always 5th byte in buffer */
  48. rbuf[0] = usb_buf[4];
  49. }
  50. return ret;
  51. }
  52. static int au6610_i2c_msg(struct dvb_usb_device *d, u8 addr,
  53. u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  54. {
  55. u8 request;
  56. u8 wo = (rbuf == NULL || rlen == 0); /* write-only */
  57. if (wo) {
  58. request = AU6610_REQ_I2C_WRITE;
  59. } else { /* rw */
  60. request = AU6610_REQ_I2C_READ;
  61. }
  62. return au6610_usb_msg(d, request, addr, wbuf, wlen, rbuf, rlen);
  63. }
  64. /* I2C */
  65. static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  66. int num)
  67. {
  68. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  69. int i;
  70. if (num > 2)
  71. return -EINVAL;
  72. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  73. return -EAGAIN;
  74. for (i = 0; i < num; i++) {
  75. /* write/read request */
  76. if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
  77. if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
  78. msg[i].len, msg[i+1].buf,
  79. msg[i+1].len) < 0)
  80. break;
  81. i++;
  82. } else if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
  83. msg[i].len, NULL, 0) < 0)
  84. break;
  85. }
  86. mutex_unlock(&d->i2c_mutex);
  87. return i;
  88. }
  89. static u32 au6610_i2c_func(struct i2c_adapter *adapter)
  90. {
  91. return I2C_FUNC_I2C;
  92. }
  93. static struct i2c_algorithm au6610_i2c_algo = {
  94. .master_xfer = au6610_i2c_xfer,
  95. .functionality = au6610_i2c_func,
  96. };
  97. /* Callbacks for DVB USB */
  98. static struct zl10353_config au6610_zl10353_config = {
  99. .demod_address = 0x0f,
  100. .no_tuner = 1,
  101. .parallel_ts = 1,
  102. };
  103. static int au6610_zl10353_frontend_attach(struct dvb_usb_adapter *adap)
  104. {
  105. adap->fe = dvb_attach(zl10353_attach, &au6610_zl10353_config,
  106. &adap->dev->i2c_adap);
  107. if (adap->fe == NULL)
  108. return -EIO;
  109. return 0;
  110. }
  111. static struct qt1010_config au6610_qt1010_config = {
  112. .i2c_address = 0x62
  113. };
  114. static int au6610_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
  115. {
  116. return dvb_attach(qt1010_attach,
  117. adap->fe, &adap->dev->i2c_adap,
  118. &au6610_qt1010_config) == NULL ? -ENODEV : 0;
  119. }
  120. /* DVB USB Driver stuff */
  121. static struct dvb_usb_device_properties au6610_properties;
  122. static int au6610_probe(struct usb_interface *intf,
  123. const struct usb_device_id *id)
  124. {
  125. struct dvb_usb_device *d;
  126. struct usb_host_interface *alt;
  127. int ret;
  128. if (intf->num_altsetting < AU6610_ALTSETTING_COUNT)
  129. return -ENODEV;
  130. ret = dvb_usb_device_init(intf, &au6610_properties, THIS_MODULE, &d,
  131. adapter_nr);
  132. if (ret == 0) {
  133. alt = usb_altnum_to_altsetting(intf, AU6610_ALTSETTING);
  134. if (alt == NULL) {
  135. deb_rc("no alt found!\n");
  136. return -ENODEV;
  137. }
  138. ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
  139. alt->desc.bAlternateSetting);
  140. }
  141. return ret;
  142. }
  143. static struct usb_device_id au6610_table [] = {
  144. { USB_DEVICE(USB_VID_ALCOR_MICRO, USB_PID_SIGMATEK_DVB_110) },
  145. { } /* Terminating entry */
  146. };
  147. MODULE_DEVICE_TABLE(usb, au6610_table);
  148. static struct dvb_usb_device_properties au6610_properties = {
  149. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  150. .usb_ctrl = DEVICE_SPECIFIC,
  151. .size_of_priv = 0,
  152. .num_adapters = 1,
  153. .adapter = {
  154. {
  155. .frontend_attach = au6610_zl10353_frontend_attach,
  156. .tuner_attach = au6610_qt1010_tuner_attach,
  157. .stream = {
  158. .type = USB_ISOC,
  159. .count = 5,
  160. .endpoint = 0x82,
  161. .u = {
  162. .isoc = {
  163. .framesperurb = 40,
  164. .framesize = 942,
  165. .interval = 1.25, /* 125 us */
  166. }
  167. }
  168. },
  169. }
  170. },
  171. .i2c_algo = &au6610_i2c_algo,
  172. .num_device_descs = 1,
  173. .devices = {
  174. {
  175. .name = "Sigmatek DVB-110 DVB-T USB2.0",
  176. .cold_ids = {NULL},
  177. .warm_ids = {&au6610_table[0], NULL},
  178. },
  179. }
  180. };
  181. static struct usb_driver au6610_driver = {
  182. .name = "dvb_usb_au6610",
  183. .probe = au6610_probe,
  184. .disconnect = dvb_usb_device_exit,
  185. .id_table = au6610_table,
  186. };
  187. /* module stuff */
  188. static int __init au6610_module_init(void)
  189. {
  190. int ret;
  191. ret = usb_register(&au6610_driver);
  192. if (ret)
  193. err("usb_register failed. Error number %d", ret);
  194. return ret;
  195. }
  196. static void __exit au6610_module_exit(void)
  197. {
  198. /* deregister this driver from the USB subsystem */
  199. usb_deregister(&au6610_driver);
  200. }
  201. module_init(au6610_module_init);
  202. module_exit(au6610_module_exit);
  203. MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
  204. MODULE_DESCRIPTION("Driver Sigmatek DVB-110 DVB-T USB2.0 / AU6610");
  205. MODULE_VERSION("0.1");
  206. MODULE_LICENSE("GPL");