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()
160 skel->field = skel->format.field; in queue_setup()
161 if (skel->field == V4L2_FIELD_ALTERNATE) { in queue_setup()
167 return -EINVAL; in queue_setup()
168 skel->field = V4L2_FIELD_TOP; in queue_setup()
172 *nbuffers = 3 - q_num_bufs; in queue_setup()
175 return sizes[0] < skel->format.sizeimage ? -EINVAL : 0; in queue_setup()
177 sizes[0] = skel->format.sizeimage; in queue_setup()
187 struct skeleton *skel = vb2_get_drv_priv(vb->vb2_queue); in buffer_prepare()
188 unsigned long size = skel->format.sizeimage; in buffer_prepare()
191 dev_err(&skel->pdev->dev, "buffer too small (%lu < %lu)\n", in buffer_prepare()
193 return -EINVAL; in buffer_prepare()
206 struct skeleton *skel = vb2_get_drv_priv(vb->vb2_queue); in buffer_queue()
210 spin_lock_irqsave(&skel->qlock, flags); in buffer_queue()
211 list_add_tail(&buf->list, &skel->buf_list); in buffer_queue()
215 spin_unlock_irqrestore(&skel->qlock, flags); in buffer_queue()
224 spin_lock_irqsave(&skel->qlock, flags); in return_all_buffers()
225 list_for_each_entry_safe(buf, node, &skel->buf_list, list) { in return_all_buffers()
226 vb2_buffer_done(&buf->vb.vb2_buf, state); in return_all_buffers()
227 list_del(&buf->list); in return_all_buffers()
229 spin_unlock_irqrestore(&skel->qlock, flags); in return_all_buffers()
234 * queued. If not, then return -ENOBUFS and the vb2 framework will call
243 skel->sequence = 0; in start_streaming()
272 * The vb2 queue ops. Note that since q->lock is set we can use the standard
273 * vb2_ops_wait_prepare/finish helper functions. If q->lock would be NULL,
295 strscpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver)); in skeleton_querycap()
296 strscpy(cap->card, "V4L2 PCI Skeleton", sizeof(cap->card)); in skeleton_querycap()
297 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s", in skeleton_querycap()
298 pci_name(skel->pdev)); in skeleton_querycap()
304 * not only in VIDIOC_TRY/S_FMT, but also elsewhere if changes to the SDTV
311 pix->pixelformat = V4L2_PIX_FMT_YUYV; in skeleton_fill_pix_format()
312 if (skel->input == 0) { in skeleton_fill_pix_format()
313 /* S-Video input */ in skeleton_fill_pix_format()
314 pix->width = 720; in skeleton_fill_pix_format()
315 pix->height = (skel->std & V4L2_STD_525_60) ? 480 : 576; in skeleton_fill_pix_format()
316 pix->field = V4L2_FIELD_INTERLACED; in skeleton_fill_pix_format()
317 pix->colorspace = V4L2_COLORSPACE_SMPTE170M; in skeleton_fill_pix_format()
320 pix->width = skel->timings.bt.width; in skeleton_fill_pix_format()
321 pix->height = skel->timings.bt.height; in skeleton_fill_pix_format()
322 if (skel->timings.bt.interlaced) { in skeleton_fill_pix_format()
323 pix->field = V4L2_FIELD_ALTERNATE; in skeleton_fill_pix_format()
324 pix->height /= 2; in skeleton_fill_pix_format()
326 pix->field = V4L2_FIELD_NONE; in skeleton_fill_pix_format()
328 pix->colorspace = V4L2_COLORSPACE_REC709; in skeleton_fill_pix_format()
335 pix->bytesperline = pix->width * 2; in skeleton_fill_pix_format()
336 pix->sizeimage = pix->bytesperline * pix->height; in skeleton_fill_pix_format()
337 pix->priv = 0; in skeleton_fill_pix_format()
344 struct v4l2_pix_format *pix = &f->fmt.pix; in skeleton_try_fmt_vid_cap()
348 * pixelformat will return -EINVAL for video receivers. Webcam drivers, in skeleton_try_fmt_vid_cap()
352 if (pix->pixelformat != V4L2_PIX_FMT_YUYV) in skeleton_try_fmt_vid_cap()
353 return -EINVAL; in skeleton_try_fmt_vid_cap()
372 if (vb2_is_busy(&skel->queue)) in skeleton_s_fmt_vid_cap()
373 return -EBUSY; in skeleton_s_fmt_vid_cap()
376 skel->format = f->fmt.pix; in skeleton_s_fmt_vid_cap()
385 f->fmt.pix = skel->format; in skeleton_g_fmt_vid_cap()
392 if (f->index != 0) in skeleton_enum_fmt_vid_cap()
393 return -EINVAL; in skeleton_enum_fmt_vid_cap()
395 f->pixelformat = V4L2_PIX_FMT_YUYV; in skeleton_enum_fmt_vid_cap()
404 if (skel->input) in skeleton_s_std()
405 return -ENODATA; in skeleton_s_std()
412 if (std == skel->std) in skeleton_s_std()
419 if (vb2_is_busy(&skel->queue)) in skeleton_s_std()
420 return -EBUSY; in skeleton_s_std()
424 skel->std = std; in skeleton_s_std()
427 skeleton_fill_pix_format(skel, &skel->format); in skeleton_s_std()
436 if (skel->input) in skeleton_g_std()
437 return -ENODATA; in skeleton_g_std()
439 *std = skel->std; in skeleton_g_std()
447 * supported standards by this input), and this function should just AND
455 if (skel->input) in skeleton_querystd()
456 return -ENODATA; in skeleton_querystd()
468 /* Use signal information to reduce the number of possible standards */ in skeleton_querystd()
482 /* S_DV_TIMINGS is not supported on the S-Video input */ in skeleton_s_dv_timings()
483 if (skel->input == 0) in skeleton_s_dv_timings()
484 return -ENODATA; in skeleton_s_dv_timings()
488 return -EINVAL; in skeleton_s_dv_timings()
490 /* Check if the timings are part of the CEA-861 timings. */ in skeleton_s_dv_timings()
493 return -EINVAL; in skeleton_s_dv_timings()
496 if (v4l2_match_dv_timings(timings, &skel->timings, 0, false)) in skeleton_s_dv_timings()
503 if (vb2_is_busy(&skel->queue)) in skeleton_s_dv_timings()
504 return -EBUSY; in skeleton_s_dv_timings()
509 skel->timings = *timings; in skeleton_s_dv_timings()
512 skeleton_fill_pix_format(skel, &skel->format); in skeleton_s_dv_timings()
521 /* G_DV_TIMINGS is not supported on the S-Video input */ in skeleton_g_dv_timings()
522 if (skel->input == 0) in skeleton_g_dv_timings()
523 return -ENODATA; in skeleton_g_dv_timings()
525 *timings = skel->timings; in skeleton_g_dv_timings()
534 /* ENUM_DV_TIMINGS is not supported on the S-Video input */ in skeleton_enum_dv_timings()
535 if (skel->input == 0) in skeleton_enum_dv_timings()
536 return -ENODATA; in skeleton_enum_dv_timings()
545 * If no signal is detected, then return -ENOLINK. If the hardware cannot
546 * lock to the signal, then return -ENOLCK. If the signal is out of range
549 * pixelclocks above a certain frequency), then -ERANGE is returned.
556 /* QUERY_DV_TIMINGS is not supported on the S-Video input */ in skeleton_query_dv_timings()
557 if (skel->input == 0) in skeleton_query_dv_timings()
558 return -ENODATA; in skeleton_query_dv_timings()
567 return -ENOLINK; in skeleton_query_dv_timings()
569 return -ENOLCK; in skeleton_query_dv_timings()
571 return -ERANGE; in skeleton_query_dv_timings()
574 v4l2_print_dv_timings(skel->v4l2_dev.name, "query_dv_timings:", in skeleton_query_dv_timings()
585 /* DV_TIMINGS_CAP is not supported on the S-Video input */ in skeleton_dv_timings_cap()
586 if (skel->input == 0) in skeleton_dv_timings_cap()
587 return -ENODATA; in skeleton_dv_timings_cap()
595 if (i->index > 1) in skeleton_enum_input()
596 return -EINVAL; in skeleton_enum_input()
598 i->type = V4L2_INPUT_TYPE_CAMERA; in skeleton_enum_input()
599 if (i->index == 0) { in skeleton_enum_input()
600 i->std = SKEL_TVNORMS; in skeleton_enum_input()
601 strscpy(i->name, "S-Video", sizeof(i->name)); in skeleton_enum_input()
602 i->capabilities = V4L2_IN_CAP_STD; in skeleton_enum_input()
604 i->std = 0; in skeleton_enum_input()
605 strscpy(i->name, "HDMI", sizeof(i->name)); in skeleton_enum_input()
606 i->capabilities = V4L2_IN_CAP_DV_TIMINGS; in skeleton_enum_input()
616 return -EINVAL; in skeleton_s_input()
622 if (vb2_is_busy(&skel->queue)) in skeleton_s_input()
623 return -EBUSY; in skeleton_s_input()
625 skel->input = i; in skeleton_s_input()
629 * ENUMSTD will return -ENODATA. in skeleton_s_input()
631 skel->vdev.tvnorms = i ? 0 : SKEL_TVNORMS; in skeleton_s_input()
634 skeleton_fill_pix_format(skel, &skel->format); in skeleton_s_input()
642 *i = skel->input; in skeleton_g_input()
650 container_of(ctrl->handler, struct skeleton, ctrl_handler);*/ in skeleton_s_ctrl()
652 switch (ctrl->id) { in skeleton_s_ctrl()
654 /* TODO: set brightness to ctrl->val */ in skeleton_s_ctrl()
657 /* TODO: set contrast to ctrl->val */ in skeleton_s_ctrl()
660 /* TODO: set saturation to ctrl->val */ in skeleton_s_ctrl()
663 /* TODO: set hue to ctrl->val */ in skeleton_s_ctrl()
666 return -EINVAL; in skeleton_s_ctrl()
671 /* ------------------------------------------------------------------
673 ------------------------------------------------------------------*/
684 * receive -EBUSY if they attempt to call the same streaming ioctls).
758 ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); in skeleton_probe()
760 dev_err(&pdev->dev, "no suitable DMA available.\n"); in skeleton_probe()
765 skel = devm_kzalloc(&pdev->dev, sizeof(struct skeleton), GFP_KERNEL); in skeleton_probe()
767 ret = -ENOMEM; in skeleton_probe()
772 ret = devm_request_irq(&pdev->dev, pdev->irq, in skeleton_probe()
775 dev_err(&pdev->dev, "request_irq failed\n"); in skeleton_probe()
778 skel->pdev = pdev; in skeleton_probe()
780 /* Fill in the initial format-related settings */ in skeleton_probe()
781 skel->timings = timings_def; in skeleton_probe()
782 skel->std = V4L2_STD_625_50; in skeleton_probe()
783 skeleton_fill_pix_format(skel, &skel->format); in skeleton_probe()
785 /* Initialize the top-level structure */ in skeleton_probe()
786 ret = v4l2_device_register(&pdev->dev, &skel->v4l2_dev); in skeleton_probe()
790 mutex_init(&skel->lock); in skeleton_probe()
793 hdl = &skel->ctrl_handler; in skeleton_probe()
802 V4L2_CID_HUE, -128, 127, 1, 0); in skeleton_probe()
803 if (hdl->error) { in skeleton_probe()
804 ret = hdl->error; in skeleton_probe()
807 skel->v4l2_dev.ctrl_handler = hdl; in skeleton_probe()
810 q = &skel->queue; in skeleton_probe()
811 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in skeleton_probe()
812 q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ; in skeleton_probe()
813 q->dev = &pdev->dev; in skeleton_probe()
814 q->drv_priv = skel; in skeleton_probe()
815 q->buf_struct_size = sizeof(struct skel_buffer); in skeleton_probe()
816 q->ops = &skel_qops; in skeleton_probe()
817 q->mem_ops = &vb2_dma_contig_memops; in skeleton_probe()
818 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in skeleton_probe()
824 q->min_queued_buffers = 2; in skeleton_probe()
827 * as the main serialization lock, but if some of the non-streaming in skeleton_probe()
834 q->lock = &skel->lock; in skeleton_probe()
836 * Since this driver can only do 32-bit DMA we must make sure that in skeleton_probe()
837 * the vb2 core will allocate the buffers in 32-bit DMA memory. in skeleton_probe()
839 q->gfp_flags = GFP_DMA32; in skeleton_probe()
844 INIT_LIST_HEAD(&skel->buf_list); in skeleton_probe()
845 spin_lock_init(&skel->qlock); in skeleton_probe()
848 vdev = &skel->vdev; in skeleton_probe()
849 strscpy(vdev->name, KBUILD_MODNAME, sizeof(vdev->name)); in skeleton_probe()
852 * function. The release callback must be non-NULL. in skeleton_probe()
854 vdev->release = video_device_release_empty; in skeleton_probe()
855 vdev->fops = &skel_fops, in skeleton_probe()
856 vdev->ioctl_ops = &skel_ioctl_ops, in skeleton_probe()
857 vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | in skeleton_probe()
861 * lock. Exception: if q->lock is set, then the streaming ioctls in skeleton_probe()
864 vdev->lock = &skel->lock; in skeleton_probe()
865 vdev->queue = q; in skeleton_probe()
866 vdev->v4l2_dev = &skel->v4l2_dev; in skeleton_probe()
867 /* Supported SDTV standards, if any */ in skeleton_probe()
868 vdev->tvnorms = SKEL_TVNORMS; in skeleton_probe()
871 ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); in skeleton_probe()
875 dev_info(&pdev->dev, "V4L2 PCI Skeleton Driver loaded\n"); in skeleton_probe()
879 v4l2_ctrl_handler_free(&skel->ctrl_handler); in skeleton_probe()
880 v4l2_device_unregister(&skel->v4l2_dev); in skeleton_probe()
891 video_unregister_device(&skel->vdev); in skeleton_remove()
892 v4l2_ctrl_handler_free(&skel->ctrl_handler); in skeleton_remove()
893 v4l2_device_unregister(&skel->v4l2_dev); in skeleton_remove()
894 pci_disable_device(skel->pdev); in skeleton_remove()