/kern_oII/drivers/media/dvb/dvb-usb/au6610.c

http://omnia2droid.googlecode.com/ · C · 258 lines · 186 code · 44 blank · 28 comment · 25 complexity · b9e22e194c70b2599ce488f4c0bd852b MD5 · raw file

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