Lines Matching +full:sdtv +full:- +full:standards

1 // SPDX-License-Identifier: GPL-2.0-only
6 * This skeleton PCI driver assumes that the card has an S-Video connector as
21 #include <linux/v4l2-dv-timings.h>
22 #include <media/v4l2-device.h>
23 #include <media/v4l2-dev.h>
24 #include <media/v4l2-ioctl.h>
25 #include <media/v4l2-dv-timings.h>
26 #include <media/v4l2-ctrls.h>
27 #include <media/v4l2-event.h>
28 #include <media/videobuf2-v4l2.h>
29 #include <media/videobuf2-dma-contig.h>
36 * struct skeleton - All internal data for one instance of device
38 * @v4l2_dev: top-level v4l2 device struct
42 * @std: current SDTV standard
45 * @input: current video input (0 = SDTV, 1 = HDTV)
100 V4L2_DV_BT_STD_CEA861, /* Supported standards */
107 * Supported SDTV standards. This does the same job as skel_timings_cap, but
128 spin_lock(&skel->qlock); in skeleton_irq()
129 list_del(&new_buf->list); in skeleton_irq()
130 spin_unlock(&skel->qlock); in skeleton_irq()
131 new_buf->vb.vb2_buf.timestamp = ktime_get_ns(); in skeleton_irq()
132 new_buf->vb.sequence = skel->sequence++; in skeleton_irq()
133 new_buf->vb.field = skel->field; in skeleton_irq()
134 if (skel->format.field == V4L2_FIELD_ALTERNATE) { in skeleton_irq()
135 if (skel->field == V4L2_FIELD_BOTTOM) in skeleton_irq()
136 skel->field = V4L2_FIELD_TOP; in skeleton_irq()
137 else if (skel->field == V4L2_FIELD_TOP) in skeleton_irq()
138 skel->field = V4L2_FIELD_BOTTOM; in skeleton_irq()
140 vb2_buffer_done(&new_buf->vb.vb2_buf, VB2_BUF_STATE_DONE); in skeleton_irq()
159 skel->field = skel->format.field; in queue_setup()
160 if (skel->field == V4L2_FIELD_ALTERNATE) { in queue_setup()
166 return -EINVAL; in queue_setup()
167 skel->field = V4L2_FIELD_TOP; in queue_setup()
170 if (vq->num_buffers + *nbuffers < 3) in queue_setup()
171 *nbuffers = 3 - vq->num_buffers; in queue_setup()
174 return sizes[0] < skel->format.sizeimage ? -EINVAL : 0; in queue_setup()
176 sizes[0] = skel->format.sizeimage; in queue_setup()
186 struct skeleton *skel = vb2_get_drv_priv(vb->vb2_queue); in buffer_prepare()
187 unsigned long size = skel->format.sizeimage; in buffer_prepare()
190 dev_err(&skel->pdev->dev, "buffer too small (%lu < %lu)\n", in buffer_prepare()
192 return -EINVAL; in buffer_prepare()
205 struct skeleton *skel = vb2_get_drv_priv(vb->vb2_queue); in buffer_queue()
209 spin_lock_irqsave(&skel->qlock, flags); in buffer_queue()
210 list_add_tail(&buf->list, &skel->buf_list); in buffer_queue()
214 spin_unlock_irqrestore(&skel->qlock, flags); in buffer_queue()
223 spin_lock_irqsave(&skel->qlock, flags); in return_all_buffers()
224 list_for_each_entry_safe(buf, node, &skel->buf_list, list) { in return_all_buffers()
225 vb2_buffer_done(&buf->vb.vb2_buf, state); in return_all_buffers()
226 list_del(&buf->list); in return_all_buffers()
228 spin_unlock_irqrestore(&skel->qlock, flags); in return_all_buffers()
233 * queued. If not, then return -ENOBUFS and the vb2 framework will call
242 skel->sequence = 0; in start_streaming()
271 * The vb2 queue ops. Note that since q->lock is set we can use the standard
272 * vb2_ops_wait_prepare/finish helper functions. If q->lock would be NULL,
294 strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver)); in skeleton_querycap()
295 strlcpy(cap->card, "V4L2 PCI Skeleton", sizeof(cap->card)); in skeleton_querycap()
296 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s", in skeleton_querycap()
297 pci_name(skel->pdev)); in skeleton_querycap()
303 * not only in VIDIOC_TRY/S_FMT, but also elsewhere if changes to the SDTV
310 pix->pixelformat = V4L2_PIX_FMT_YUYV; in skeleton_fill_pix_format()
311 if (skel->input == 0) { in skeleton_fill_pix_format()
312 /* S-Video input */ in skeleton_fill_pix_format()
313 pix->width = 720; in skeleton_fill_pix_format()
314 pix->height = (skel->std & V4L2_STD_525_60) ? 480 : 576; in skeleton_fill_pix_format()
315 pix->field = V4L2_FIELD_INTERLACED; in skeleton_fill_pix_format()
316 pix->colorspace = V4L2_COLORSPACE_SMPTE170M; in skeleton_fill_pix_format()
319 pix->width = skel->timings.bt.width; in skeleton_fill_pix_format()
320 pix->height = skel->timings.bt.height; in skeleton_fill_pix_format()
321 if (skel->timings.bt.interlaced) { in skeleton_fill_pix_format()
322 pix->field = V4L2_FIELD_ALTERNATE; in skeleton_fill_pix_format()
323 pix->height /= 2; in skeleton_fill_pix_format()
325 pix->field = V4L2_FIELD_NONE; in skeleton_fill_pix_format()
327 pix->colorspace = V4L2_COLORSPACE_REC709; in skeleton_fill_pix_format()
334 pix->bytesperline = pix->width * 2; in skeleton_fill_pix_format()
335 pix->sizeimage = pix->bytesperline * pix->height; in skeleton_fill_pix_format()
336 pix->priv = 0; in skeleton_fill_pix_format()
343 struct v4l2_pix_format *pix = &f->fmt.pix; in skeleton_try_fmt_vid_cap()
347 * pixelformat will return -EINVAL for video receivers. Webcam drivers, in skeleton_try_fmt_vid_cap()
351 if (pix->pixelformat != V4L2_PIX_FMT_YUYV) in skeleton_try_fmt_vid_cap()
352 return -EINVAL; in skeleton_try_fmt_vid_cap()
371 if (vb2_is_busy(&skel->queue)) in skeleton_s_fmt_vid_cap()
372 return -EBUSY; in skeleton_s_fmt_vid_cap()
375 skel->format = f->fmt.pix; in skeleton_s_fmt_vid_cap()
384 f->fmt.pix = skel->format; in skeleton_g_fmt_vid_cap()
391 if (f->index != 0) in skeleton_enum_fmt_vid_cap()
392 return -EINVAL; in skeleton_enum_fmt_vid_cap()
394 f->pixelformat = V4L2_PIX_FMT_YUYV; in skeleton_enum_fmt_vid_cap()
403 if (skel->input) in skeleton_s_std()
404 return -ENODATA; in skeleton_s_std()
411 if (std == skel->std) in skeleton_s_std()
418 if (vb2_is_busy(&skel->queue)) in skeleton_s_std()
419 return -EBUSY; in skeleton_s_std()
423 skel->std = std; in skeleton_s_std()
426 skeleton_fill_pix_format(skel, &skel->format); in skeleton_s_std()
435 if (skel->input) in skeleton_g_std()
436 return -ENODATA; in skeleton_g_std()
438 *std = skel->std; in skeleton_g_std()
446 * supported standards by this input), and this function should just AND
454 if (skel->input) in skeleton_querystd()
455 return -ENODATA; in skeleton_querystd()
467 /* Use signal information to reduce the number of possible standards */ in skeleton_querystd()
481 /* S_DV_TIMINGS is not supported on the S-Video input */ in skeleton_s_dv_timings()
482 if (skel->input == 0) in skeleton_s_dv_timings()
483 return -ENODATA; in skeleton_s_dv_timings()
487 return -EINVAL; in skeleton_s_dv_timings()
489 /* Check if the timings are part of the CEA-861 timings. */ in skeleton_s_dv_timings()
492 return -EINVAL; in skeleton_s_dv_timings()
495 if (v4l2_match_dv_timings(timings, &skel->timings, 0, false)) in skeleton_s_dv_timings()
502 if (vb2_is_busy(&skel->queue)) in skeleton_s_dv_timings()
503 return -EBUSY; in skeleton_s_dv_timings()
508 skel->timings = *timings; in skeleton_s_dv_timings()
511 skeleton_fill_pix_format(skel, &skel->format); in skeleton_s_dv_timings()
520 /* G_DV_TIMINGS is not supported on the S-Video input */ in skeleton_g_dv_timings()
521 if (skel->input == 0) in skeleton_g_dv_timings()
522 return -ENODATA; in skeleton_g_dv_timings()
524 *timings = skel->timings; in skeleton_g_dv_timings()
533 /* ENUM_DV_TIMINGS is not supported on the S-Video input */ in skeleton_enum_dv_timings()
534 if (skel->input == 0) in skeleton_enum_dv_timings()
535 return -ENODATA; in skeleton_enum_dv_timings()
544 * If no signal is detected, then return -ENOLINK. If the hardware cannot
545 * lock to the signal, then return -ENOLCK. If the signal is out of range
548 * pixelclocks above a certain frequency), then -ERANGE is returned.
555 /* QUERY_DV_TIMINGS is not supported on the S-Video input */ in skeleton_query_dv_timings()
556 if (skel->input == 0) in skeleton_query_dv_timings()
557 return -ENODATA; in skeleton_query_dv_timings()
566 return -ENOLINK; in skeleton_query_dv_timings()
568 return -ENOLCK; in skeleton_query_dv_timings()
570 return -ERANGE; in skeleton_query_dv_timings()
573 v4l2_print_dv_timings(skel->v4l2_dev.name, "query_dv_timings:", in skeleton_query_dv_timings()
584 /* DV_TIMINGS_CAP is not supported on the S-Video input */ in skeleton_dv_timings_cap()
585 if (skel->input == 0) in skeleton_dv_timings_cap()
586 return -ENODATA; in skeleton_dv_timings_cap()
594 if (i->index > 1) in skeleton_enum_input()
595 return -EINVAL; in skeleton_enum_input()
597 i->type = V4L2_INPUT_TYPE_CAMERA; in skeleton_enum_input()
598 if (i->index == 0) { in skeleton_enum_input()
599 i->std = SKEL_TVNORMS; in skeleton_enum_input()
600 strlcpy(i->name, "S-Video", sizeof(i->name)); in skeleton_enum_input()
601 i->capabilities = V4L2_IN_CAP_STD; in skeleton_enum_input()
603 i->std = 0; in skeleton_enum_input()
604 strlcpy(i->name, "HDMI", sizeof(i->name)); in skeleton_enum_input()
605 i->capabilities = V4L2_IN_CAP_DV_TIMINGS; in skeleton_enum_input()
615 return -EINVAL; in skeleton_s_input()
621 if (vb2_is_busy(&skel->queue)) in skeleton_s_input()
622 return -EBUSY; in skeleton_s_input()
624 skel->input = i; in skeleton_s_input()
628 * ENUMSTD will return -ENODATA. in skeleton_s_input()
630 skel->vdev.tvnorms = i ? 0 : SKEL_TVNORMS; in skeleton_s_input()
633 skeleton_fill_pix_format(skel, &skel->format); in skeleton_s_input()
641 *i = skel->input; in skeleton_g_input()
649 container_of(ctrl->handler, struct skeleton, ctrl_handler);*/ in skeleton_s_ctrl()
651 switch (ctrl->id) { in skeleton_s_ctrl()
653 /* TODO: set brightness to ctrl->val */ in skeleton_s_ctrl()
656 /* TODO: set contrast to ctrl->val */ in skeleton_s_ctrl()
659 /* TODO: set saturation to ctrl->val */ in skeleton_s_ctrl()
662 /* TODO: set hue to ctrl->val */ in skeleton_s_ctrl()
665 return -EINVAL; in skeleton_s_ctrl()
670 /* ------------------------------------------------------------------
672 ------------------------------------------------------------------*/
683 * receive -EBUSY if they attempt to call the same streaming ioctls).
757 ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); in skeleton_probe()
759 dev_err(&pdev->dev, "no suitable DMA available.\n"); in skeleton_probe()
764 skel = devm_kzalloc(&pdev->dev, sizeof(struct skeleton), GFP_KERNEL); in skeleton_probe()
766 ret = -ENOMEM; in skeleton_probe()
771 ret = devm_request_irq(&pdev->dev, pdev->irq, in skeleton_probe()
774 dev_err(&pdev->dev, "request_irq failed\n"); in skeleton_probe()
777 skel->pdev = pdev; in skeleton_probe()
779 /* Fill in the initial format-related settings */ in skeleton_probe()
780 skel->timings = timings_def; in skeleton_probe()
781 skel->std = V4L2_STD_625_50; in skeleton_probe()
782 skeleton_fill_pix_format(skel, &skel->format); in skeleton_probe()
784 /* Initialize the top-level structure */ in skeleton_probe()
785 ret = v4l2_device_register(&pdev->dev, &skel->v4l2_dev); in skeleton_probe()
789 mutex_init(&skel->lock); in skeleton_probe()
792 hdl = &skel->ctrl_handler; in skeleton_probe()
801 V4L2_CID_HUE, -128, 127, 1, 0); in skeleton_probe()
802 if (hdl->error) { in skeleton_probe()
803 ret = hdl->error; in skeleton_probe()
806 skel->v4l2_dev.ctrl_handler = hdl; in skeleton_probe()
809 q = &skel->queue; in skeleton_probe()
810 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in skeleton_probe()
811 q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ; in skeleton_probe()
812 q->dev = &pdev->dev; in skeleton_probe()
813 q->drv_priv = skel; in skeleton_probe()
814 q->buf_struct_size = sizeof(struct skel_buffer); in skeleton_probe()
815 q->ops = &skel_qops; in skeleton_probe()
816 q->mem_ops = &vb2_dma_contig_memops; in skeleton_probe()
817 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in skeleton_probe()
823 q->min_buffers_needed = 2; in skeleton_probe()
826 * as the main serialization lock, but if some of the non-streaming in skeleton_probe()
833 q->lock = &skel->lock; in skeleton_probe()
835 * Since this driver can only do 32-bit DMA we must make sure that in skeleton_probe()
836 * the vb2 core will allocate the buffers in 32-bit DMA memory. in skeleton_probe()
838 q->gfp_flags = GFP_DMA32; in skeleton_probe()
843 INIT_LIST_HEAD(&skel->buf_list); in skeleton_probe()
844 spin_lock_init(&skel->qlock); in skeleton_probe()
847 vdev = &skel->vdev; in skeleton_probe()
848 strlcpy(vdev->name, KBUILD_MODNAME, sizeof(vdev->name)); in skeleton_probe()
851 * function. The release callback must be non-NULL. in skeleton_probe()
853 vdev->release = video_device_release_empty; in skeleton_probe()
854 vdev->fops = &skel_fops, in skeleton_probe()
855 vdev->ioctl_ops = &skel_ioctl_ops, in skeleton_probe()
856 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | in skeleton_probe()
860 * lock. Exception: if q->lock is set, then the streaming ioctls in skeleton_probe()
863 vdev->lock = &skel->lock; in skeleton_probe()
864 vdev->queue = q; in skeleton_probe()
865 vdev->v4l2_dev = &skel->v4l2_dev; in skeleton_probe()
866 /* Supported SDTV standards, if any */ in skeleton_probe()
867 vdev->tvnorms = SKEL_TVNORMS; in skeleton_probe()
870 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); in skeleton_probe()
874 dev_info(&pdev->dev, "V4L2 PCI Skeleton Driver loaded\n"); in skeleton_probe()
878 v4l2_ctrl_handler_free(&skel->ctrl_handler); in skeleton_probe()
879 v4l2_device_unregister(&skel->v4l2_dev); in skeleton_probe()
890 video_unregister_device(&skel->vdev); in skeleton_remove()
891 v4l2_ctrl_handler_free(&skel->ctrl_handler); in skeleton_remove()
892 v4l2_device_unregister(&skel->v4l2_dev); in skeleton_remove()
893 pci_disable_device(skel->pdev); in skeleton_remove()