em28xx-dvb.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. MODULE_DESCRIPTION("driver for em28xx based DVB cards");
  20. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
  21. MODULE_LICENSE("GPL");
  22. static unsigned int debug;
  23. module_param(debug, int, 0644);
  24. MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
  25. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  26. #define dprintk(level, fmt, arg...) do { \
  27. if (debug >= level) \
  28. printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg) \
  29. } while (0)
  30. static int
  31. buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
  32. {
  33. struct em28xx_fh *fh = vq->priv_data;
  34. struct em28xx *dev = fh->dev;
  35. /* FIXME: The better would be to allocate a smaller buffer */
  36. *size = 16 * fh->dev->width * fh->dev->height >> 3;
  37. if (0 == *count)
  38. *count = EM28XX_DEF_BUF;
  39. if (*count < EM28XX_MIN_BUF)
  40. *count = EM28XX_MIN_BUF;
  41. dev->mode = EM28XX_DIGITAL_MODE;
  42. return 0;
  43. }
  44. /* ------------------------------------------------------------------ */
  45. static struct lgdt330x_config em2880_lgdt3303_dev = {
  46. .demod_address = 0x0e,
  47. .demod_chip = LGDT3303,
  48. };
  49. /* ------------------------------------------------------------------ */
  50. static int attach_xc3028(u8 addr, struct em28xx *dev)
  51. {
  52. struct dvb_frontend *fe;
  53. struct xc2028_ctrl ctl;
  54. struct xc2028_config cfg;
  55. memset (&cfg, 0, sizeof(cfg));
  56. cfg.i2c_adap = &dev->i2c_adap;
  57. cfg.i2c_addr = addr;
  58. cfg.ctrl = &ctl;
  59. cfg.callback = em28xx_tuner_callback;
  60. em28xx_setup_xc3028(dev, &ctl);
  61. if (!dev->dvb.frontend) {
  62. printk(KERN_ERR "%s/2: dvb frontend not attached. "
  63. "Can't attach xc3028\n",
  64. dev->name);
  65. return -EINVAL;
  66. }
  67. fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
  68. if (!fe) {
  69. printk(KERN_ERR "%s/2: xc3028 attach failed\n",
  70. dev->name);
  71. dvb_frontend_detach(dev->dvb.frontend);
  72. dvb_unregister_frontend(dev->dvb.frontend);
  73. dev->dvb.frontend = NULL;
  74. return -EINVAL;
  75. }
  76. printk(KERN_INFO "%s/2: xc3028 attached\n", dev->name);
  77. return 0;
  78. }
  79. static int dvb_init(struct em28xx *dev)
  80. {
  81. /* init struct videobuf_dvb */
  82. dev->dvb.name = dev->name;
  83. dev->qops->buf_setup = buffer_setup;
  84. /* FIXME: Do we need more initialization here? */
  85. memset(&dev->dvb_fh, 0, sizeof (dev->dvb_fh));
  86. dev->dvb_fh.dev = dev;
  87. dev->dvb_fh.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  88. videobuf_queue_vmalloc_init(&dev->dvb.dvbq, dev->qops,
  89. &dev->udev->dev, &dev->slock,
  90. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  91. V4L2_FIELD_ALTERNATE,
  92. sizeof(struct em28xx_buffer), &dev->dvb_fh);
  93. /* init frontend */
  94. switch (dev->model) {
  95. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
  96. /* Enable lgdt330x */
  97. dev->mode = EM28XX_DIGITAL_MODE;
  98. em28xx_tuner_callback(dev, XC2028_TUNER_RESET, 0);
  99. dev->dvb.frontend = dvb_attach(lgdt330x_attach,
  100. &em2880_lgdt3303_dev,
  101. &dev->i2c_adap);
  102. if (attach_xc3028(0x61, dev) < 0)
  103. return -EINVAL;
  104. break;
  105. default:
  106. printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card"
  107. " isn't supported yet\n",
  108. dev->name);
  109. break;
  110. }
  111. if (NULL == dev->dvb.frontend) {
  112. printk(KERN_ERR
  113. "%s/2: frontend initialization failed\n",
  114. dev->name);
  115. return -EINVAL;
  116. }
  117. /* register everything */
  118. return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev,
  119. &dev->udev->dev,
  120. adapter_nr);
  121. }
  122. static int dvb_fini(struct em28xx *dev)
  123. {
  124. if (dev->dvb.frontend)
  125. videobuf_dvb_unregister(&dev->dvb);
  126. return 0;
  127. }
  128. static struct em28xx_ops dvb_ops = {
  129. .id = EM28XX_DVB,
  130. .name = "Em28xx dvb Extension",
  131. .init = dvb_init,
  132. .fini = dvb_fini,
  133. };
  134. static int __init em28xx_dvb_register(void)
  135. {
  136. return em28xx_register_extension(&dvb_ops);
  137. }
  138. static void __exit em28xx_dvb_unregister(void)
  139. {
  140. em28xx_unregister_extension(&dvb_ops);
  141. }
  142. module_init(em28xx_dvb_register);
  143. module_exit(em28xx_dvb_unregister);