au6610.c 5.7 KB

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