Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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