em28xx-vbi.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // em28xx-vbi.c - VBI driver for em28xx
  4. //
  5. // Copyright (C) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
  6. //
  7. // This work was sponsored by EyeMagnet Limited.
  8. //
  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, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. #include "em28xx.h"
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/hardirq.h>
  22. #include <linux/init.h>
  23. #include <linux/usb.h>
  24. #include "em28xx-v4l.h"
  25. /* ------------------------------------------------------------------ */
  26. static int vbi_queue_setup(struct vb2_queue *vq,
  27. unsigned int *nbuffers, unsigned int *nplanes,
  28. unsigned int sizes[], struct device *alloc_devs[])
  29. {
  30. struct em28xx *dev = vb2_get_drv_priv(vq);
  31. struct em28xx_v4l2 *v4l2 = dev->v4l2;
  32. unsigned long size = v4l2->vbi_width * v4l2->vbi_height * 2;
  33. if (*nbuffers < 2)
  34. *nbuffers = 2;
  35. if (*nplanes) {
  36. if (sizes[0] < size)
  37. return -EINVAL;
  38. size = sizes[0];
  39. }
  40. *nplanes = 1;
  41. sizes[0] = size;
  42. return 0;
  43. }
  44. static int vbi_buffer_prepare(struct vb2_buffer *vb)
  45. {
  46. struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
  47. struct em28xx_v4l2 *v4l2 = dev->v4l2;
  48. unsigned long size;
  49. size = v4l2->vbi_width * v4l2->vbi_height * 2;
  50. if (vb2_plane_size(vb, 0) < size) {
  51. dev_info(&dev->intf->dev,
  52. "%s data will not fit into plane (%lu < %lu)\n",
  53. __func__, vb2_plane_size(vb, 0), size);
  54. return -EINVAL;
  55. }
  56. vb2_set_plane_payload(vb, 0, size);
  57. return 0;
  58. }
  59. static void
  60. vbi_buffer_queue(struct vb2_buffer *vb)
  61. {
  62. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  63. struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
  64. struct em28xx_buffer *buf =
  65. container_of(vbuf, struct em28xx_buffer, vb);
  66. struct em28xx_dmaqueue *vbiq = &dev->vbiq;
  67. unsigned long flags = 0;
  68. buf->mem = vb2_plane_vaddr(vb, 0);
  69. buf->length = vb2_plane_size(vb, 0);
  70. spin_lock_irqsave(&dev->slock, flags);
  71. list_add_tail(&buf->list, &vbiq->active);
  72. spin_unlock_irqrestore(&dev->slock, flags);
  73. }
  74. const struct vb2_ops em28xx_vbi_qops = {
  75. .queue_setup = vbi_queue_setup,
  76. .buf_prepare = vbi_buffer_prepare,
  77. .buf_queue = vbi_buffer_queue,
  78. .start_streaming = em28xx_start_analog_streaming,
  79. .stop_streaming = em28xx_stop_vbi_streaming,
  80. .wait_prepare = vb2_ops_wait_prepare,
  81. .wait_finish = vb2_ops_wait_finish,
  82. };