au6610.c 5.8 KB

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