em28xx-dvb.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. DVB device driver for em28xx
  3. (c) 2008 Mauro Carvalho Chehab <mchehab@infradead.org>
  4. (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
  5. - Fixes for the driver to properly work with HVR-950
  6. Based on cx88-dvb and saa7134-dvb originally written by:
  7. (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
  8. (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/usb.h>
  15. #include "em28xx.h"
  16. #include <media/v4l2-common.h>
  17. #include <media/videobuf-vmalloc.h>
  18. #include "lgdt330x.h"
  19. #include "zl10353.h"
  20. MODULE_DESCRIPTION("driver for em28xx based DVB cards");
  21. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
  22. MODULE_LICENSE("GPL");
  23. static unsigned int debug;
  24. module_param(debug, int, 0644);
  25. MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
  26. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  27. #define dprintk(level, fmt, arg...) do { \
  28. if (debug >= level) \
  29. printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg) \
  30. } while (0)
  31. static int
  32. buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
  33. {
  34. struct em28xx_fh *fh = vq->priv_data;
  35. struct em28xx *dev = fh->dev;
  36. /* FIXME: The better would be to allocate a smaller buffer */
  37. *size = 16 * fh->dev->width * fh->dev->height >> 3;
  38. if (0 == *count)
  39. *count = EM28XX_DEF_BUF;
  40. if (*count < EM28XX_MIN_BUF)
  41. *count = EM28XX_MIN_BUF;
  42. dev->mode = EM28XX_DIGITAL_MODE;
  43. return 0;
  44. }
  45. /* ------------------------------------------------------------------ */
  46. static struct lgdt330x_config em2880_lgdt3303_dev = {
  47. .demod_address = 0x0e,
  48. .demod_chip = LGDT3303,
  49. };
  50. static struct zl10353_config em28xx_zl10353_with_xc3028 = {
  51. .demod_address = (0x1e >> 1),
  52. .no_tuner = 1,
  53. .parallel_ts = 1,
  54. .if2 = 45600,
  55. };
  56. /* ------------------------------------------------------------------ */
  57. static int attach_xc3028(u8 addr, struct em28xx *dev)
  58. {
  59. struct dvb_frontend *fe;
  60. struct xc2028_ctrl ctl;
  61. struct xc2028_config cfg;
  62. memset (&cfg, 0, sizeof(cfg));
  63. cfg.i2c_adap = &dev->i2c_adap;
  64. cfg.i2c_addr = addr;
  65. cfg.ctrl = &ctl;
  66. cfg.callback = em28xx_tuner_callback;
  67. em28xx_setup_xc3028(dev, &ctl);
  68. if (!dev->dvb.frontend) {
  69. printk(KERN_ERR "%s/2: dvb frontend not attached. "
  70. "Can't attach xc3028\n",
  71. dev->name);
  72. return -EINVAL;
  73. }
  74. fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
  75. if (!fe) {
  76. printk(KERN_ERR "%s/2: xc3028 attach failed\n",
  77. dev->name);
  78. dvb_frontend_detach(dev->dvb.frontend);
  79. dvb_unregister_frontend(dev->dvb.frontend);
  80. dev->dvb.frontend = NULL;
  81. return -EINVAL;
  82. }
  83. printk(KERN_INFO "%s/2: xc3028 attached\n", dev->name);
  84. return 0;
  85. }
  86. static int dvb_init(struct em28xx *dev)
  87. {
  88. /* init struct videobuf_dvb */
  89. dev->dvb.name = dev->name;
  90. dev->qops->buf_setup = buffer_setup;
  91. /* FIXME: Do we need more initialization here? */
  92. memset(&dev->dvb_fh, 0, sizeof (dev->dvb_fh));
  93. dev->dvb_fh.dev = dev;
  94. dev->dvb_fh.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  95. videobuf_queue_vmalloc_init(&dev->dvb.dvbq, dev->qops,
  96. &dev->udev->dev, &dev->slock,
  97. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  98. V4L2_FIELD_ALTERNATE,
  99. sizeof(struct em28xx_buffer), &dev->dvb_fh);
  100. /* init frontend */
  101. switch (dev->model) {
  102. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
  103. /* Enable lgdt330x */
  104. dev->mode = EM28XX_DIGITAL_MODE;
  105. em28xx_tuner_callback(dev, XC2028_TUNER_RESET, 0);
  106. dev->dvb.frontend = dvb_attach(lgdt330x_attach,
  107. &em2880_lgdt3303_dev,
  108. &dev->i2c_adap);
  109. if (attach_xc3028(0x61, dev) < 0)
  110. return -EINVAL;
  111. break;
  112. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  113. /* Enable zl10353 */
  114. dev->mode = EM28XX_DIGITAL_MODE;
  115. em28xx_tuner_callback(dev, XC2028_TUNER_RESET, 0);
  116. dev->dvb.frontend = dvb_attach(zl10353_attach,
  117. &em28xx_zl10353_with_xc3028,
  118. &dev->i2c_adap);
  119. if (attach_xc3028(0x61, dev) < 0)
  120. return -EINVAL;
  121. break;
  122. default:
  123. printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card"
  124. " isn't supported yet\n",
  125. dev->name);
  126. break;
  127. }
  128. if (NULL == dev->dvb.frontend) {
  129. printk(KERN_ERR
  130. "%s/2: frontend initialization failed\n",
  131. dev->name);
  132. return -EINVAL;
  133. }
  134. /* register everything */
  135. return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev,
  136. &dev->udev->dev,
  137. adapter_nr);
  138. }
  139. static int dvb_fini(struct em28xx *dev)
  140. {
  141. if (dev->dvb.frontend)
  142. videobuf_dvb_unregister(&dev->dvb);
  143. return 0;
  144. }
  145. static struct em28xx_ops dvb_ops = {
  146. .id = EM28XX_DVB,
  147. .name = "Em28xx dvb Extension",
  148. .init = dvb_init,
  149. .fini = dvb_fini,
  150. };
  151. static int __init em28xx_dvb_register(void)
  152. {
  153. return em28xx_register_extension(&dvb_ops);
  154. }
  155. static void __exit em28xx_dvb_unregister(void)
  156. {
  157. em28xx_unregister_extension(&dvb_ops);
  158. }
  159. module_init(em28xx_dvb_register);
  160. module_exit(em28xx_dvb_unregister);