em28xx-vbi.c 2.8 KB

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