au0828-vbi.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. au0828-vbi.c - VBI driver for au0828
  4. Copyright (C) 2010 Devin Heitmueller <[email protected]>
  5. This work was sponsored by GetWellNetwork Inc.
  6. */
  7. #include "au0828.h"
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/slab.h>
  12. /* ------------------------------------------------------------------ */
  13. static int vbi_queue_setup(struct vb2_queue *vq,
  14. unsigned int *nbuffers, unsigned int *nplanes,
  15. unsigned int sizes[], struct device *alloc_devs[])
  16. {
  17. struct au0828_dev *dev = vb2_get_drv_priv(vq);
  18. unsigned long size = dev->vbi_width * dev->vbi_height * 2;
  19. if (*nplanes)
  20. return sizes[0] < size ? -EINVAL : 0;
  21. *nplanes = 1;
  22. sizes[0] = size;
  23. return 0;
  24. }
  25. static int vbi_buffer_prepare(struct vb2_buffer *vb)
  26. {
  27. struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  28. unsigned long size;
  29. size = dev->vbi_width * dev->vbi_height * 2;
  30. if (vb2_plane_size(vb, 0) < size) {
  31. pr_err("%s data will not fit into plane (%lu < %lu)\n",
  32. __func__, vb2_plane_size(vb, 0), size);
  33. return -EINVAL;
  34. }
  35. vb2_set_plane_payload(vb, 0, size);
  36. return 0;
  37. }
  38. static void
  39. vbi_buffer_queue(struct vb2_buffer *vb)
  40. {
  41. struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  42. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  43. struct au0828_buffer *buf =
  44. container_of(vbuf, struct au0828_buffer, vb);
  45. struct au0828_dmaqueue *vbiq = &dev->vbiq;
  46. unsigned long flags = 0;
  47. buf->mem = vb2_plane_vaddr(vb, 0);
  48. buf->length = vb2_plane_size(vb, 0);
  49. spin_lock_irqsave(&dev->slock, flags);
  50. list_add_tail(&buf->list, &vbiq->active);
  51. spin_unlock_irqrestore(&dev->slock, flags);
  52. }
  53. const struct vb2_ops au0828_vbi_qops = {
  54. .queue_setup = vbi_queue_setup,
  55. .buf_prepare = vbi_buffer_prepare,
  56. .buf_queue = vbi_buffer_queue,
  57. .start_streaming = au0828_start_analog_streaming,
  58. .stop_streaming = au0828_stop_vbi_streaming,
  59. .wait_prepare = vb2_ops_wait_prepare,
  60. .wait_finish = vb2_ops_wait_finish,
  61. };