em28xx-vbi.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #include "em28xx-v4l.h"
  24. /* ------------------------------------------------------------------ */
  25. static int vbi_queue_setup(struct vb2_queue *vq, const void *parg,
  26. unsigned int *nbuffers, unsigned int *nplanes,
  27. unsigned int sizes[], void *alloc_ctxs[])
  28. {
  29. const struct v4l2_format *fmt = parg;
  30. struct em28xx *dev = vb2_get_drv_priv(vq);
  31. struct em28xx_v4l2 *v4l2 = dev->v4l2;
  32. unsigned long size;
  33. if (fmt)
  34. size = fmt->fmt.pix.sizeimage;
  35. else
  36. size = v4l2->vbi_width * v4l2->vbi_height * 2;
  37. if (0 == *nbuffers)
  38. *nbuffers = 32;
  39. if (*nbuffers < 2)
  40. *nbuffers = 2;
  41. if (*nbuffers > 32)
  42. *nbuffers = 32;
  43. *nplanes = 1;
  44. sizes[0] = size;
  45. return 0;
  46. }
  47. static int vbi_buffer_prepare(struct vb2_buffer *vb)
  48. {
  49. struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
  50. struct em28xx_v4l2 *v4l2 = dev->v4l2;
  51. unsigned long size;
  52. size = v4l2->vbi_width * v4l2->vbi_height * 2;
  53. if (vb2_plane_size(vb, 0) < size) {
  54. printk(KERN_INFO "%s data will not fit into plane (%lu < %lu)\n",
  55. __func__, vb2_plane_size(vb, 0), size);
  56. return -EINVAL;
  57. }
  58. vb2_set_plane_payload(vb, 0, size);
  59. return 0;
  60. }
  61. static void
  62. vbi_buffer_queue(struct vb2_buffer *vb)
  63. {
  64. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  65. struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
  66. struct em28xx_buffer *buf =
  67. container_of(vbuf, struct em28xx_buffer, vb);
  68. struct em28xx_dmaqueue *vbiq = &dev->vbiq;
  69. unsigned long flags = 0;
  70. buf->mem = vb2_plane_vaddr(vb, 0);
  71. buf->length = vb2_plane_size(vb, 0);
  72. spin_lock_irqsave(&dev->slock, flags);
  73. list_add_tail(&buf->list, &vbiq->active);
  74. spin_unlock_irqrestore(&dev->slock, flags);
  75. }
  76. struct vb2_ops em28xx_vbi_qops = {
  77. .queue_setup = vbi_queue_setup,
  78. .buf_prepare = vbi_buffer_prepare,
  79. .buf_queue = vbi_buffer_queue,
  80. .start_streaming = em28xx_start_analog_streaming,
  81. .stop_streaming = em28xx_stop_vbi_streaming,
  82. .wait_prepare = vb2_ops_wait_prepare,
  83. .wait_finish = vb2_ops_wait_finish,
  84. };