em28xx-dvb.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. DVB device driver for em28xx
  3. (c) 2008 Mauro Carvalho Chehab <mchehab@infradead.org>
  4. Based on cx88-dvb and saa7134-dvb originally written by:
  5. (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
  6. (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/usb.h>
  13. #include "em28xx.h"
  14. #include <media/v4l2-common.h>
  15. #include <media/videobuf-vmalloc.h>
  16. #include "lgdt330x.h"
  17. #include "tuner-xc2028.h"
  18. #include "tuner-xc2028-types.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. *size = 16 * fh->dev->width * fh->dev->height >> 3;
  36. if (0 == *count)
  37. *count = EM28XX_DEF_BUF;
  38. if (*count < EM28XX_MIN_BUF)
  39. *count = EM28XX_MIN_BUF;
  40. dev->mode = EM28XX_DIGITAL_MODE;
  41. return 0;
  42. }
  43. /* ------------------------------------------------------------------ */
  44. /* Add demods here */
  45. /* ------------------------------------------------------------------ */
  46. static int attach_xc3028(u8 addr, struct em28xx *dev)
  47. {
  48. struct dvb_frontend *fe;
  49. struct xc2028_ctrl ctl;
  50. struct xc2028_config cfg = {
  51. .i2c_adap = &dev->i2c_adap,
  52. .i2c_addr = addr,
  53. .ctrl = &ctl,
  54. };
  55. if (!dev->dvb.frontend) {
  56. printk(KERN_ERR "%s/2: dvb frontend not attached. "
  57. "Can't attach xc3028\n",
  58. dev->name);
  59. return -EINVAL;
  60. }
  61. fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
  62. if (!fe) {
  63. printk(KERN_ERR "%s/2: xc3028 attach failed\n",
  64. dev->name);
  65. dvb_frontend_detach(dev->dvb.frontend);
  66. dvb_unregister_frontend(dev->dvb.frontend);
  67. dev->dvb.frontend = NULL;
  68. return -EINVAL;
  69. }
  70. printk(KERN_INFO "%s/2: xc3028 attached\n", dev->name);
  71. return 0;
  72. }
  73. static int dvb_init(struct em28xx *dev)
  74. {
  75. /* init struct videobuf_dvb */
  76. dev->dvb.name = dev->name;
  77. dev->qops->buf_setup = buffer_setup;
  78. videobuf_queue_vmalloc_init(&dev->dvb.dvbq, dev->qops,
  79. &dev->udev->dev, &dev->slock,
  80. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  81. V4L2_FIELD_ALTERNATE,
  82. sizeof(struct em28xx_buffer), dev);
  83. /* init frontend */
  84. switch (dev->model) {
  85. default:
  86. printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card"
  87. " isn't supported yet\n",
  88. dev->name);
  89. break;
  90. }
  91. if (NULL == dev->dvb.frontend) {
  92. printk(KERN_ERR
  93. "%s/2: frontend initialization failed\n",
  94. dev->name);
  95. return -EINVAL;
  96. }
  97. /* register everything */
  98. return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev,
  99. &dev->udev->dev,
  100. adapter_nr);
  101. }
  102. static int dvb_fini(struct em28xx *dev)
  103. {
  104. if (dev->dvb.frontend)
  105. videobuf_dvb_unregister(&dev->dvb);
  106. return 0;
  107. }
  108. static struct em28xx_ops dvb_ops = {
  109. .id = EM28XX_DVB,
  110. .name = "Em28xx dvb Extension",
  111. .init = dvb_init,
  112. .fini = dvb_fini,
  113. };
  114. static int __init em28xx_dvb_register(void)
  115. {
  116. return em28xx_register_extension(&dvb_ops);
  117. }
  118. static void __exit em28xx_dvb_unregister(void)
  119. {
  120. em28xx_unregister_extension(&dvb_ops);
  121. }
  122. module_init(em28xx_dvb_register);
  123. module_exit(em28xx_dvb_unregister);