^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * This is a V4L2 PCI Skeleton Driver. It gives an initial skeleton source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * for use with other PCI drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This skeleton PCI driver assumes that the card has an S-Video connector as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * input 0 and an HDMI connector as input 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This program is free software; you may redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * the Free Software Foundation; version 2 of the License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/kmod.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/videodev2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/v4l2-dv-timings.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <media/v4l2-device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <media/v4l2-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <media/v4l2-ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <media/v4l2-dv-timings.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <media/v4l2-ctrls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <media/v4l2-event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <media/videobuf2-v4l2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <media/videobuf2-dma-contig.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) MODULE_DESCRIPTION("V4L2 PCI Skeleton Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) MODULE_AUTHOR("Hans Verkuil");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) MODULE_LICENSE("GPL v2");
^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) * struct skeleton - All internal data for one instance of device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * @pdev: PCI device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @v4l2_dev: top-level v4l2 device struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @vdev: video node structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * @ctrl_handler: control handler structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * @lock: ioctl serialization mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * @std: current SDTV standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @timings: current HDTV timings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * @format: current pix format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * @input: current video input (0 = SDTV, 1 = HDTV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @queue: vb2 video capture queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @qlock: spinlock controlling access to buf_list and sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * @buf_list: list of buffers queued for DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @field: the field (TOP/BOTTOM/other) of the current buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * @sequence: frame sequence counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct skeleton {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct pci_dev *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct v4l2_device v4l2_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct video_device vdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct v4l2_ctrl_handler ctrl_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) v4l2_std_id std;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct v4l2_dv_timings timings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct v4l2_pix_format format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) unsigned input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct vb2_queue queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) spinlock_t qlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct list_head buf_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) unsigned sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct skel_buffer {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct vb2_v4l2_buffer vb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static inline struct skel_buffer *to_skel_buffer(struct vb2_v4l2_buffer *vbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return container_of(vbuf, struct skel_buffer, vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static const struct pci_device_id skeleton_pci_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* { PCI_DEVICE(PCI_VENDOR_ID_, PCI_DEVICE_ID_) }, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) { 0, }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) MODULE_DEVICE_TABLE(pci, skeleton_pci_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * HDTV: this structure has the capabilities of the HDTV receiver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * It is used to constrain the huge list of possible formats based
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * upon the hardware capabilities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static const struct v4l2_dv_timings_cap skel_timings_cap = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .type = V4L2_DV_BT_656_1120,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* keep this initialization for compatibility with GCC < 4.4.6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .reserved = { 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) V4L2_INIT_BT_TIMINGS(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 720, 1920, /* min/max width */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 480, 1080, /* min/max height */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 27000000, 74250000, /* min/max pixelclock*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) V4L2_DV_BT_STD_CEA861, /* Supported standards */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* capabilities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) V4L2_DV_BT_CAP_INTERLACED | V4L2_DV_BT_CAP_PROGRESSIVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * Supported SDTV standards. This does the same job as skel_timings_cap, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * for standard TV formats.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define SKEL_TVNORMS V4L2_STD_ALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * Interrupt handler: typically interrupts happen after a new frame has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * captured. It is the job of the handler to remove the new frame from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * internal list and give it back to the vb2 framework, updating the sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * counter, field and timestamp at the same time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static irqreturn_t skeleton_irq(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #ifdef TODO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct skeleton *skel = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* handle interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* Once a new frame has been captured, mark it as done like this: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (captured_new_frame) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) spin_lock(&skel->qlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) list_del(&new_buf->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) spin_unlock(&skel->qlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) new_buf->vb.vb2_buf.timestamp = ktime_get_ns();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) new_buf->vb.sequence = skel->sequence++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) new_buf->vb.field = skel->field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (skel->format.field == V4L2_FIELD_ALTERNATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (skel->field == V4L2_FIELD_BOTTOM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) skel->field = V4L2_FIELD_TOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) else if (skel->field == V4L2_FIELD_TOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) skel->field = V4L2_FIELD_BOTTOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) vb2_buffer_done(&new_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * Setup the constraints of the queue: besides setting the number of planes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * per buffer and the size and allocation context of each plane, it also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * checks if sufficient buffers have been allocated. Usually 3 is a good
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * minimum number: many DMA engines need a minimum of 2 buffers in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * queue and you need to have another available for userspace processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int queue_setup(struct vb2_queue *vq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) unsigned int *nbuffers, unsigned int *nplanes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) unsigned int sizes[], struct device *alloc_devs[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct skeleton *skel = vb2_get_drv_priv(vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) skel->field = skel->format.field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (skel->field == V4L2_FIELD_ALTERNATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * You cannot use read() with FIELD_ALTERNATE since the field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * information (TOP/BOTTOM) cannot be passed back to the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (vb2_fileio_is_active(vq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) skel->field = V4L2_FIELD_TOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (vq->num_buffers + *nbuffers < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) *nbuffers = 3 - vq->num_buffers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (*nplanes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return sizes[0] < skel->format.sizeimage ? -EINVAL : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *nplanes = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) sizes[0] = skel->format.sizeimage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * Prepare the buffer for queueing to the DMA engine: check and set the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * payload size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static int buffer_prepare(struct vb2_buffer *vb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct skeleton *skel = vb2_get_drv_priv(vb->vb2_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) unsigned long size = skel->format.sizeimage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (vb2_plane_size(vb, 0) < size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) dev_err(&skel->pdev->dev, "buffer too small (%lu < %lu)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) vb2_plane_size(vb, 0), size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) vb2_set_plane_payload(vb, 0, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * Queue this buffer to the DMA engine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static void buffer_queue(struct vb2_buffer *vb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct skeleton *skel = vb2_get_drv_priv(vb->vb2_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct skel_buffer *buf = to_skel_buffer(vbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) spin_lock_irqsave(&skel->qlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) list_add_tail(&buf->list, &skel->buf_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /* TODO: Update any DMA pointers if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) spin_unlock_irqrestore(&skel->qlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static void return_all_buffers(struct skeleton *skel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) enum vb2_buffer_state state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct skel_buffer *buf, *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) spin_lock_irqsave(&skel->qlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) list_for_each_entry_safe(buf, node, &skel->buf_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) vb2_buffer_done(&buf->vb.vb2_buf, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) list_del(&buf->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) spin_unlock_irqrestore(&skel->qlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * Start streaming. First check if the minimum number of buffers have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * queued. If not, then return -ENOBUFS and the vb2 framework will call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * this function again the next time a buffer has been queued until enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * buffers are available to actually start the DMA engine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static int start_streaming(struct vb2_queue *vq, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct skeleton *skel = vb2_get_drv_priv(vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) skel->sequence = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) /* TODO: start DMA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * In case of an error, return all active buffers to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * QUEUED state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return_all_buffers(skel, VB2_BUF_STATE_QUEUED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * Stop the DMA engine. Any remaining buffers in the DMA queue are dequeued
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * and passed on to the vb2 framework marked as STATE_ERROR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static void stop_streaming(struct vb2_queue *vq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct skeleton *skel = vb2_get_drv_priv(vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* TODO: stop DMA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* Release all active buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return_all_buffers(skel, VB2_BUF_STATE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * The vb2 queue ops. Note that since q->lock is set we can use the standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * vb2_ops_wait_prepare/finish helper functions. If q->lock would be NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * then this driver would have to provide these ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static const struct vb2_ops skel_qops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .queue_setup = queue_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) .buf_prepare = buffer_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) .buf_queue = buffer_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) .start_streaming = start_streaming,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .stop_streaming = stop_streaming,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .wait_prepare = vb2_ops_wait_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .wait_finish = vb2_ops_wait_finish,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * Required ioctl querycap. Note that the version field is prefilled with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * the version of the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static int skeleton_querycap(struct file *file, void *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) struct v4l2_capability *cap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) strlcpy(cap->card, "V4L2 PCI Skeleton", sizeof(cap->card));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) pci_name(skel->pdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * Helper function to check and correct struct v4l2_pix_format. It's used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * not only in VIDIOC_TRY/S_FMT, but also elsewhere if changes to the SDTV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * standard, HDTV timings or the video input would require updating the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * current format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static void skeleton_fill_pix_format(struct skeleton *skel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct v4l2_pix_format *pix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) pix->pixelformat = V4L2_PIX_FMT_YUYV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (skel->input == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* S-Video input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) pix->width = 720;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) pix->height = (skel->std & V4L2_STD_525_60) ? 480 : 576;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) pix->field = V4L2_FIELD_INTERLACED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* HDMI input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) pix->width = skel->timings.bt.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) pix->height = skel->timings.bt.height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (skel->timings.bt.interlaced) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) pix->field = V4L2_FIELD_ALTERNATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) pix->height /= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) pix->field = V4L2_FIELD_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) pix->colorspace = V4L2_COLORSPACE_REC709;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * The YUYV format is four bytes for every two pixels, so bytesperline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * is width * 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) pix->bytesperline = pix->width * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) pix->sizeimage = pix->bytesperline * pix->height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) pix->priv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static int skeleton_try_fmt_vid_cap(struct file *file, void *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) struct v4l2_format *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct v4l2_pix_format *pix = &f->fmt.pix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * Due to historical reasons providing try_fmt with an unsupported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * pixelformat will return -EINVAL for video receivers. Webcam drivers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * however, will silently correct the pixelformat. Some video capture
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * applications rely on this behavior...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (pix->pixelformat != V4L2_PIX_FMT_YUYV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) skeleton_fill_pix_format(skel, pix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static int skeleton_s_fmt_vid_cap(struct file *file, void *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct v4l2_format *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ret = skeleton_try_fmt_vid_cap(file, priv, f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * It is not allowed to change the format while buffers for use with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * streaming have already been allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (vb2_is_busy(&skel->queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* TODO: change format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) skel->format = f->fmt.pix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static int skeleton_g_fmt_vid_cap(struct file *file, void *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) struct v4l2_format *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) f->fmt.pix = skel->format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static int skeleton_enum_fmt_vid_cap(struct file *file, void *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct v4l2_fmtdesc *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (f->index != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) f->pixelformat = V4L2_PIX_FMT_YUYV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static int skeleton_s_std(struct file *file, void *priv, v4l2_std_id std)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /* S_STD is not supported on the HDMI input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (skel->input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * No change, so just return. Some applications call S_STD again after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * the buffers for streaming have been set up, so we have to allow for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * this behavior.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (std == skel->std)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * Changing the standard implies a format change, which is not allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * while buffers for use with streaming have already been allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (vb2_is_busy(&skel->queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /* TODO: handle changing std */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) skel->std = std;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) /* Update the internal format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) skeleton_fill_pix_format(skel, &skel->format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static int skeleton_g_std(struct file *file, void *priv, v4l2_std_id *std)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /* G_STD is not supported on the HDMI input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (skel->input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) *std = skel->std;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * Query the current standard as seen by the hardware. This function shall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * never actually change the standard, it just detects and reports.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * The framework will initially set *std to tvnorms (i.e. the set of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * supported standards by this input), and this function should just AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * this value. If there is no signal, then *std should be set to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static int skeleton_querystd(struct file *file, void *priv, v4l2_std_id *std)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /* QUERY_STD is not supported on the HDMI input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (skel->input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) #ifdef TODO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * Query currently seen standard. Initial value of *std is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * V4L2_STD_ALL. This function should look something like this:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) get_signal_info();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if (no_signal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) *std = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /* Use signal information to reduce the number of possible standards */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (signal_has_525_lines)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) *std &= V4L2_STD_525_60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) *std &= V4L2_STD_625_50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static int skeleton_s_dv_timings(struct file *file, void *_fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) struct v4l2_dv_timings *timings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /* S_DV_TIMINGS is not supported on the S-Video input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (skel->input == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /* Quick sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (!v4l2_valid_dv_timings(timings, &skel_timings_cap, NULL, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) /* Check if the timings are part of the CEA-861 timings. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (!v4l2_find_dv_timings_cap(timings, &skel_timings_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 0, NULL, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) /* Return 0 if the new timings are the same as the current timings. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (v4l2_match_dv_timings(timings, &skel->timings, 0, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * Changing the timings implies a format change, which is not allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) * while buffers for use with streaming have already been allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (vb2_is_busy(&skel->queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) /* TODO: Configure new timings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /* Save timings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) skel->timings = *timings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /* Update the internal format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) skeleton_fill_pix_format(skel, &skel->format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) static int skeleton_g_dv_timings(struct file *file, void *_fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) struct v4l2_dv_timings *timings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) /* G_DV_TIMINGS is not supported on the S-Video input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (skel->input == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) *timings = skel->timings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) static int skeleton_enum_dv_timings(struct file *file, void *_fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) struct v4l2_enum_dv_timings *timings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) /* ENUM_DV_TIMINGS is not supported on the S-Video input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (skel->input == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) return v4l2_enum_dv_timings_cap(timings, &skel_timings_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) * Query the current timings as seen by the hardware. This function shall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * never actually change the timings, it just detects and reports.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * If no signal is detected, then return -ENOLINK. If the hardware cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) * lock to the signal, then return -ENOLCK. If the signal is out of range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) * of the capabilities of the system (e.g., it is possible that the receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * can lock but that the DMA engine it is connected to cannot handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) * pixelclocks above a certain frequency), then -ERANGE is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static int skeleton_query_dv_timings(struct file *file, void *_fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) struct v4l2_dv_timings *timings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) /* QUERY_DV_TIMINGS is not supported on the S-Video input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (skel->input == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) #ifdef TODO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * Query currently seen timings. This function should look
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * something like this:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) detect_timings();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (no_signal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) if (cannot_lock_to_signal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) return -ENOLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (signal_out_of_range_of_capabilities)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) /* Useful for debugging */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) v4l2_print_dv_timings(skel->v4l2_dev.name, "query_dv_timings:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) timings, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) static int skeleton_dv_timings_cap(struct file *file, void *fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) struct v4l2_dv_timings_cap *cap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /* DV_TIMINGS_CAP is not supported on the S-Video input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (skel->input == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) *cap = skel_timings_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) static int skeleton_enum_input(struct file *file, void *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) struct v4l2_input *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) if (i->index > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) i->type = V4L2_INPUT_TYPE_CAMERA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (i->index == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) i->std = SKEL_TVNORMS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) strlcpy(i->name, "S-Video", sizeof(i->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) i->capabilities = V4L2_IN_CAP_STD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) i->std = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) strlcpy(i->name, "HDMI", sizeof(i->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) i->capabilities = V4L2_IN_CAP_DV_TIMINGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) static int skeleton_s_input(struct file *file, void *priv, unsigned int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (i > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) * Changing the input implies a format change, which is not allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) * while buffers for use with streaming have already been allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) if (vb2_is_busy(&skel->queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) skel->input = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * Update tvnorms. The tvnorms value is used by the core to implement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) * VIDIOC_ENUMSTD so it has to be correct. If tvnorms == 0, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) * ENUMSTD will return -ENODATA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) skel->vdev.tvnorms = i ? 0 : SKEL_TVNORMS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) /* Update the internal format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) skeleton_fill_pix_format(skel, &skel->format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) static int skeleton_g_input(struct file *file, void *priv, unsigned int *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) struct skeleton *skel = video_drvdata(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) *i = skel->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) /* The control handler. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static int skeleton_s_ctrl(struct v4l2_ctrl *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) /*struct skeleton *skel =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) container_of(ctrl->handler, struct skeleton, ctrl_handler);*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) switch (ctrl->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) case V4L2_CID_BRIGHTNESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) /* TODO: set brightness to ctrl->val */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) case V4L2_CID_CONTRAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* TODO: set contrast to ctrl->val */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) case V4L2_CID_SATURATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) /* TODO: set saturation to ctrl->val */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) case V4L2_CID_HUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) /* TODO: set hue to ctrl->val */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) /* ------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) File operations for the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) ------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) static const struct v4l2_ctrl_ops skel_ctrl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) .s_ctrl = skeleton_s_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) * The set of all supported ioctls. Note that all the streaming ioctls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) * use the vb2 helper functions that take care of all the locking and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) * that also do ownership tracking (i.e. only the filehandle that requested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * the buffers can call the streaming ioctls, all other filehandles will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) * receive -EBUSY if they attempt to call the same streaming ioctls).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) * The last three ioctls also use standard helper functions: these implement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) * standard behavior for drivers with controls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static const struct v4l2_ioctl_ops skel_ioctl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) .vidioc_querycap = skeleton_querycap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) .vidioc_try_fmt_vid_cap = skeleton_try_fmt_vid_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) .vidioc_s_fmt_vid_cap = skeleton_s_fmt_vid_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) .vidioc_g_fmt_vid_cap = skeleton_g_fmt_vid_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) .vidioc_enum_fmt_vid_cap = skeleton_enum_fmt_vid_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) .vidioc_g_std = skeleton_g_std,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) .vidioc_s_std = skeleton_s_std,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) .vidioc_querystd = skeleton_querystd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) .vidioc_s_dv_timings = skeleton_s_dv_timings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) .vidioc_g_dv_timings = skeleton_g_dv_timings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) .vidioc_enum_dv_timings = skeleton_enum_dv_timings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) .vidioc_query_dv_timings = skeleton_query_dv_timings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) .vidioc_dv_timings_cap = skeleton_dv_timings_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) .vidioc_enum_input = skeleton_enum_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) .vidioc_g_input = skeleton_g_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) .vidioc_s_input = skeleton_s_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) .vidioc_reqbufs = vb2_ioctl_reqbufs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) .vidioc_create_bufs = vb2_ioctl_create_bufs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) .vidioc_querybuf = vb2_ioctl_querybuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) .vidioc_qbuf = vb2_ioctl_qbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) .vidioc_dqbuf = vb2_ioctl_dqbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) .vidioc_expbuf = vb2_ioctl_expbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) .vidioc_streamon = vb2_ioctl_streamon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) .vidioc_streamoff = vb2_ioctl_streamoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) .vidioc_log_status = v4l2_ctrl_log_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) * The set of file operations. Note that all these ops are standard core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) * helper functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) static const struct v4l2_file_operations skel_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) .open = v4l2_fh_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) .release = vb2_fop_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) .unlocked_ioctl = video_ioctl2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) .read = vb2_fop_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) .mmap = vb2_fop_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) .poll = vb2_fop_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) * The initial setup of this device instance. Note that the initial state of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) * the driver should be complete. So the initial format, standard, timings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) * and video input should all be initialized to some reasonable value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) static int skeleton_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) /* The initial timings are chosen to be 720p60. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) static const struct v4l2_dv_timings timings_def =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) V4L2_DV_BT_CEA_1280X720P60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) struct skeleton *skel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) struct video_device *vdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) struct v4l2_ctrl_handler *hdl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) struct vb2_queue *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) /* Enable PCI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) ret = pci_enable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) dev_err(&pdev->dev, "no suitable DMA available.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) goto disable_pci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) /* Allocate a new instance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) skel = devm_kzalloc(&pdev->dev, sizeof(struct skeleton), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) if (!skel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) goto disable_pci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) /* Allocate the interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) ret = devm_request_irq(&pdev->dev, pdev->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) skeleton_irq, 0, KBUILD_MODNAME, skel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) dev_err(&pdev->dev, "request_irq failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) goto disable_pci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) skel->pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) /* Fill in the initial format-related settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) skel->timings = timings_def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) skel->std = V4L2_STD_625_50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) skeleton_fill_pix_format(skel, &skel->format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) /* Initialize the top-level structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) ret = v4l2_device_register(&pdev->dev, &skel->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) goto disable_pci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) mutex_init(&skel->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) /* Add the controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) hdl = &skel->ctrl_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) v4l2_ctrl_handler_init(hdl, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) v4l2_ctrl_new_std(hdl, &skel_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) v4l2_ctrl_new_std(hdl, &skel_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) V4L2_CID_CONTRAST, 0, 255, 1, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) v4l2_ctrl_new_std(hdl, &skel_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) V4L2_CID_SATURATION, 0, 255, 1, 127);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) v4l2_ctrl_new_std(hdl, &skel_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) V4L2_CID_HUE, -128, 127, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) if (hdl->error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) ret = hdl->error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) goto free_hdl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) skel->v4l2_dev.ctrl_handler = hdl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) /* Initialize the vb2 queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) q = &skel->queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) q->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) q->drv_priv = skel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) q->buf_struct_size = sizeof(struct skel_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) q->ops = &skel_qops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) q->mem_ops = &vb2_dma_contig_memops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) * Assume that this DMA engine needs to have at least two buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) * available before it can be started. The start_streaming() op
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) * won't be called until at least this many buffers are queued up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) q->min_buffers_needed = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) * The serialization lock for the streaming ioctls. This is the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) * as the main serialization lock, but if some of the non-streaming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) * ioctls could take a long time to execute, then you might want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) * have a different lock here to prevent VIDIOC_DQBUF from being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) * blocked while waiting for another action to finish. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) * generally not needed for PCI devices, but USB devices usually do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) * want a separate lock here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) q->lock = &skel->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) * Since this driver can only do 32-bit DMA we must make sure that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) * the vb2 core will allocate the buffers in 32-bit DMA memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) q->gfp_flags = GFP_DMA32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) ret = vb2_queue_init(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) goto free_hdl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) INIT_LIST_HEAD(&skel->buf_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) spin_lock_init(&skel->qlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) /* Initialize the video_device structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) vdev = &skel->vdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) strlcpy(vdev->name, KBUILD_MODNAME, sizeof(vdev->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) * There is nothing to clean up, so release is set to an empty release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) * function. The release callback must be non-NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) vdev->release = video_device_release_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) vdev->fops = &skel_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) vdev->ioctl_ops = &skel_ioctl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) V4L2_CAP_STREAMING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) * The main serialization lock. All ioctls are serialized by this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * lock. Exception: if q->lock is set, then the streaming ioctls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) * are serialized by that separate lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) vdev->lock = &skel->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) vdev->queue = q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) vdev->v4l2_dev = &skel->v4l2_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) /* Supported SDTV standards, if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) vdev->tvnorms = SKEL_TVNORMS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) video_set_drvdata(vdev, skel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) goto free_hdl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) dev_info(&pdev->dev, "V4L2 PCI Skeleton Driver loaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) free_hdl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) v4l2_ctrl_handler_free(&skel->ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) v4l2_device_unregister(&skel->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) disable_pci:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) pci_disable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) static void skeleton_remove(struct pci_dev *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) struct skeleton *skel = container_of(v4l2_dev, struct skeleton, v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) video_unregister_device(&skel->vdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) v4l2_ctrl_handler_free(&skel->ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) v4l2_device_unregister(&skel->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) pci_disable_device(skel->pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) static struct pci_driver skeleton_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) .name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) .probe = skeleton_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) .remove = skeleton_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) .id_table = skeleton_pci_tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) module_pci_driver(skeleton_driver);