em28xx-vbi.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. em28xx-vbi.c - VBI driver for em28xx
  3. Copyright (C) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
  4. This work was sponsored by EyeMagnet Limited.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301, USA.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/hardirq.h>
  21. #include <linux/init.h>
  22. #include "em28xx.h"
  23. static unsigned int vbibufs = 5;
  24. module_param(vbibufs, int, 0644);
  25. MODULE_PARM_DESC(vbibufs, "number of vbi buffers, range 2-32");
  26. static unsigned int vbi_debug;
  27. module_param(vbi_debug, int, 0644);
  28. MODULE_PARM_DESC(vbi_debug, "enable debug messages [vbi]");
  29. #define dprintk(level, fmt, arg...) if (vbi_debug >= level) \
  30. printk(KERN_DEBUG "%s: " fmt, dev->core->name , ## arg)
  31. /* ------------------------------------------------------------------ */
  32. static int vbi_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  33. unsigned int *nbuffers, unsigned int *nplanes,
  34. unsigned int sizes[], void *alloc_ctxs[])
  35. {
  36. struct em28xx *dev = vb2_get_drv_priv(vq);
  37. unsigned long size;
  38. if (fmt)
  39. size = fmt->fmt.pix.sizeimage;
  40. else
  41. size = dev->vbi_width * dev->vbi_height * 2;
  42. if (0 == *nbuffers)
  43. *nbuffers = 32;
  44. if (*nbuffers < 2)
  45. *nbuffers = 2;
  46. if (*nbuffers > 32)
  47. *nbuffers = 32;
  48. *nplanes = 1;
  49. sizes[0] = size;
  50. return 0;
  51. }
  52. static int vbi_buffer_prepare(struct vb2_buffer *vb)
  53. {
  54. struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
  55. struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
  56. unsigned long size;
  57. size = dev->vbi_width * dev->vbi_height * 2;
  58. if (vb2_plane_size(vb, 0) < size) {
  59. printk(KERN_INFO "%s data will not fit into plane (%lu < %lu)\n",
  60. __func__, vb2_plane_size(vb, 0), size);
  61. return -EINVAL;
  62. }
  63. vb2_set_plane_payload(&buf->vb, 0, size);
  64. return 0;
  65. }
  66. static void
  67. vbi_buffer_queue(struct vb2_buffer *vb)
  68. {
  69. struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
  70. struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
  71. struct em28xx_dmaqueue *vbiq = &dev->vbiq;
  72. unsigned long flags = 0;
  73. buf->mem = vb2_plane_vaddr(vb, 0);
  74. buf->length = vb2_plane_size(vb, 0);
  75. spin_lock_irqsave(&dev->slock, flags);
  76. list_add_tail(&buf->list, &vbiq->active);
  77. spin_unlock_irqrestore(&dev->slock, flags);
  78. }
  79. struct vb2_ops em28xx_vbi_qops = {
  80. .queue_setup = vbi_queue_setup,
  81. .buf_prepare = vbi_buffer_prepare,
  82. .buf_queue = vbi_buffer_queue,
  83. .start_streaming = em28xx_start_analog_streaming,
  84. .stop_streaming = em28xx_stop_vbi_streaming,
  85. .wait_prepare = vb2_ops_wait_prepare,
  86. .wait_finish = vb2_ops_wait_finish,
  87. };