em28xx-vbi.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // em28xx-vbi.c - VBI driver for em28xx
  4. //
  5. // Copyright (C) 2009 Devin Heitmueller <[email protected]>
  6. //
  7. // This work was sponsored by EyeMagnet Limited.
  8. #include "em28xx.h"
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/hardirq.h>
  12. #include <linux/init.h>
  13. #include <linux/usb.h>
  14. #include "em28xx-v4l.h"
  15. /* ------------------------------------------------------------------ */
  16. static int vbi_queue_setup(struct vb2_queue *vq,
  17. unsigned int *nbuffers, unsigned int *nplanes,
  18. unsigned int sizes[], struct device *alloc_devs[])
  19. {
  20. struct em28xx *dev = vb2_get_drv_priv(vq);
  21. struct em28xx_v4l2 *v4l2 = dev->v4l2;
  22. unsigned long size = v4l2->vbi_width * v4l2->vbi_height * 2;
  23. if (*nbuffers < 2)
  24. *nbuffers = 2;
  25. if (*nplanes) {
  26. if (sizes[0] < size)
  27. return -EINVAL;
  28. size = sizes[0];
  29. }
  30. *nplanes = 1;
  31. sizes[0] = size;
  32. return 0;
  33. }
  34. static int vbi_buffer_prepare(struct vb2_buffer *vb)
  35. {
  36. struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
  37. struct em28xx_v4l2 *v4l2 = dev->v4l2;
  38. unsigned long size;
  39. size = v4l2->vbi_width * v4l2->vbi_height * 2;
  40. if (vb2_plane_size(vb, 0) < size) {
  41. dev_info(&dev->intf->dev,
  42. "%s data will not fit into plane (%lu < %lu)\n",
  43. __func__, vb2_plane_size(vb, 0), size);
  44. return -EINVAL;
  45. }
  46. vb2_set_plane_payload(vb, 0, size);
  47. return 0;
  48. }
  49. static void
  50. vbi_buffer_queue(struct vb2_buffer *vb)
  51. {
  52. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  53. struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
  54. struct em28xx_buffer *buf =
  55. container_of(vbuf, struct em28xx_buffer, vb);
  56. struct em28xx_dmaqueue *vbiq = &dev->vbiq;
  57. unsigned long flags = 0;
  58. buf->mem = vb2_plane_vaddr(vb, 0);
  59. buf->length = vb2_plane_size(vb, 0);
  60. spin_lock_irqsave(&dev->slock, flags);
  61. list_add_tail(&buf->list, &vbiq->active);
  62. spin_unlock_irqrestore(&dev->slock, flags);
  63. }
  64. const struct vb2_ops em28xx_vbi_qops = {
  65. .queue_setup = vbi_queue_setup,
  66. .buf_prepare = vbi_buffer_prepare,
  67. .buf_queue = vbi_buffer_queue,
  68. .start_streaming = em28xx_start_analog_streaming,
  69. .stop_streaming = em28xx_stop_vbi_streaming,
  70. .wait_prepare = vb2_ops_wait_prepare,
  71. .wait_finish = vb2_ops_wait_finish,
  72. };