au0828-vbi.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. au0828-vbi.c - VBI driver for au0828
  3. Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
  4. This work was sponsored by GetWellNetwork Inc.
  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 "au0828.h"
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/slab.h>
  23. /* ------------------------------------------------------------------ */
  24. static int vbi_queue_setup(struct vb2_queue *vq, const void *parg,
  25. unsigned int *nbuffers, unsigned int *nplanes,
  26. unsigned int sizes[], void *alloc_ctxs[])
  27. {
  28. const struct v4l2_format *fmt = parg;
  29. struct au0828_dev *dev = vb2_get_drv_priv(vq);
  30. unsigned long img_size = dev->vbi_width * dev->vbi_height * 2;
  31. unsigned long size;
  32. size = fmt ? (fmt->fmt.vbi.samples_per_line *
  33. (fmt->fmt.vbi.count[0] + fmt->fmt.vbi.count[1])) : img_size;
  34. if (size < img_size)
  35. return -EINVAL;
  36. *nplanes = 1;
  37. sizes[0] = size;
  38. return 0;
  39. }
  40. static int vbi_buffer_prepare(struct vb2_buffer *vb)
  41. {
  42. struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  43. unsigned long size;
  44. size = dev->vbi_width * dev->vbi_height * 2;
  45. if (vb2_plane_size(vb, 0) < size) {
  46. pr_err("%s data will not fit into plane (%lu < %lu)\n",
  47. __func__, vb2_plane_size(vb, 0), size);
  48. return -EINVAL;
  49. }
  50. vb2_set_plane_payload(vb, 0, size);
  51. return 0;
  52. }
  53. static void
  54. vbi_buffer_queue(struct vb2_buffer *vb)
  55. {
  56. struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  57. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  58. struct au0828_buffer *buf =
  59. container_of(vbuf, struct au0828_buffer, vb);
  60. struct au0828_dmaqueue *vbiq = &dev->vbiq;
  61. unsigned long flags = 0;
  62. buf->mem = vb2_plane_vaddr(vb, 0);
  63. buf->length = vb2_plane_size(vb, 0);
  64. spin_lock_irqsave(&dev->slock, flags);
  65. list_add_tail(&buf->list, &vbiq->active);
  66. spin_unlock_irqrestore(&dev->slock, flags);
  67. }
  68. struct vb2_ops au0828_vbi_qops = {
  69. .queue_setup = vbi_queue_setup,
  70. .buf_prepare = vbi_buffer_prepare,
  71. .buf_queue = vbi_buffer_queue,
  72. .start_streaming = au0828_start_analog_streaming,
  73. .stop_streaming = au0828_stop_vbi_streaming,
  74. .wait_prepare = vb2_ops_wait_prepare,
  75. .wait_finish = vb2_ops_wait_finish,
  76. };