From nobody Sat Sep 13 07:13:25 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69D7DC05027 for ; Mon, 6 Feb 2023 04:35:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbjBFEfi (ORCPT ); Sun, 5 Feb 2023 23:35:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbjBFEfa (ORCPT ); Sun, 5 Feb 2023 23:35:30 -0500 Received: from kozue.soulik.info (kozue.soulik.info [IPv6:2001:19f0:7000:8404:5054:ff:fe75:428f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D8E81B566; Sun, 5 Feb 2023 20:35:05 -0800 (PST) Received: from misaki.sumomo.pri (unknown [192.168.0.134]) by kozue.soulik.info (Postfix) with ESMTPA id 155A2101CD2; Mon, 6 Feb 2023 13:34:58 +0900 (JST) From: ayaka To: linux-media@vger.kernel.org Cc: randy.li@synaptics.com, Brian.Starkey@arm.com, boris.brezillon@collabora.com, frkoenig@chromium.org, hans.verkuil@cisco.com, hiroh@chromium.org, hverkuil@xs4all.nl, kernel@collabora.com, laurent.pinchart@ideasonboard.com, linux-kernel@vger.kernel.org, mchehab@kernel.org, narmstrong@baylibre.com, nicolas@ndufresne.ca, sakari.ailus@iki.fi, stanimir.varbanov@linaro.org, tfiga@chromium.org, Helen Koike , Randy Li Subject: [PATCH v7 9/9] media: vimc: Convert to v4l2_ext_pix_format Date: Mon, 6 Feb 2023 12:33:08 +0800 Message-Id: <20230206043308.28365-10-ayaka@soulik.info> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206043308.28365-1-ayaka@soulik.info> References: <20230206043308.28365-1-ayaka@soulik.info> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Helen Koike Simplify Multi/Single planer API handling by converting to v4l2_ext_pix_for= mat. Signed-off-by: Boris Brezillon Signed-off-by: Helen Koike Signed-off-by: Randy Li --- Changes in v7: - Refresh and rebase Changes in v6: - Update with new format and buffer structs Changes in v4: - Update with new format and buffer structs - Rebased on top of media/master (post 5.8-rc1) Changes in v3: - Rebased on top of media/master (post 5.4-rc1) Changes in v2: - New patch --- .../media/test-drivers/vimc/vimc-capture.c | 115 ++++++++++-------- drivers/media/test-drivers/vimc/vimc-common.c | 6 +- drivers/media/test-drivers/vimc/vimc-common.h | 2 +- 3 files changed, 68 insertions(+), 55 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media= /test-drivers/vimc/vimc-capture.c index 246d90d1f5ae..5429398bea8d 100644 --- a/drivers/media/test-drivers/vimc/vimc-capture.c +++ b/drivers/media/test-drivers/vimc/vimc-capture.c @@ -16,7 +16,7 @@ struct vimc_capture_device { struct vimc_ent_device ved; struct video_device vdev; - struct v4l2_pix_format format; + struct v4l2_ext_pix_format format; struct vb2_queue queue; struct list_head buf_list; /* @@ -33,7 +33,8 @@ struct vimc_capture_device { struct media_pad pad; }; =20 -static const struct v4l2_pix_format fmt_default =3D { +static const struct v4l2_ext_pix_format fmt_default =3D { + .type =3D V4L2_BUF_TYPE_VIDEO_CAPTURE, .width =3D 640, .height =3D 480, .pixelformat =3D V4L2_PIX_FMT_RGB24, @@ -53,7 +54,7 @@ struct vimc_capture_buffer { }; =20 static int vimc_capture_querycap(struct file *file, void *priv, - struct v4l2_capability *cap) + struct v4l2_capability *cap) { strscpy(cap->driver, VIMC_PDEV_NAME, sizeof(cap->driver)); strscpy(cap->card, KBUILD_MODNAME, sizeof(cap->card)); @@ -64,28 +65,28 @@ static int vimc_capture_querycap(struct file *file, voi= d *priv, } =20 static void vimc_capture_get_format(struct vimc_ent_device *ved, - struct v4l2_pix_format *fmt) + struct v4l2_ext_pix_format *fmt) { - struct vimc_capture_device *vcapture =3D container_of(ved, struct vimc_ca= pture_device, - ved); + struct vimc_capture_device *vcapture =3D + container_of(ved, struct vimc_capture_device, + ved); =20 *fmt =3D vcapture->format; } =20 static int vimc_capture_g_fmt_vid_cap(struct file *file, void *priv, - struct v4l2_format *f) + struct v4l2_ext_pix_format *f) { struct vimc_capture_device *vcapture =3D video_drvdata(file); =20 - f->fmt.pix =3D vcapture->format; + *f =3D vcapture->format; =20 return 0; } =20 static int vimc_capture_try_fmt_vid_cap(struct file *file, void *priv, - struct v4l2_format *f) + struct v4l2_ext_pix_format *format) { - struct v4l2_pix_format *format =3D &f->fmt.pix; const struct vimc_pix_map *vpix; =20 format->width =3D clamp_t(u32, format->width, VIMC_FRAME_MIN_WIDTH, @@ -100,8 +101,10 @@ static int vimc_capture_try_fmt_vid_cap(struct file *f= ile, void *priv, vpix =3D vimc_pix_map_by_pixelformat(format->pixelformat); } /* TODO: Add support for custom bytesperline values */ - format->bytesperline =3D format->width * vpix->bpp; - format->sizeimage =3D format->bytesperline * format->height; + memset(format->plane_fmt, 0, sizeof(format->plane_fmt)); + format->plane_fmt[0].bytesperline =3D format->width * vpix->bpp; + format->plane_fmt[0].sizeimage =3D format->plane_fmt[0].bytesperline * + format->height; =20 if (format->field =3D=3D V4L2_FIELD_ANY) format->field =3D fmt_default.field; @@ -115,7 +118,7 @@ static int vimc_capture_try_fmt_vid_cap(struct file *fi= le, void *priv, } =20 static int vimc_capture_s_fmt_vid_cap(struct file *file, void *priv, - struct v4l2_format *f) + struct v4l2_ext_pix_format *f) { struct vimc_capture_device *vcapture =3D video_drvdata(file); int ret; @@ -137,18 +140,16 @@ static int vimc_capture_s_fmt_vid_cap(struct file *fi= le, void *priv, vcapture->format.quantization, vcapture->format.xfer_func, vcapture->format.ycbcr_enc, /* new */ - f->fmt.pix.width, f->fmt.pix.height, - f->fmt.pix.pixelformat, f->fmt.pix.colorspace, - f->fmt.pix.quantization, f->fmt.pix.xfer_func, - f->fmt.pix.ycbcr_enc); + f->width, f->height, f->pixelformat, f->colorspace, + f->quantization, f->xfer_func, f->ycbcr_enc); =20 - vcapture->format =3D f->fmt.pix; + vcapture->format =3D *f; =20 return 0; } =20 static int vimc_capture_enum_fmt_vid_cap(struct file *file, void *priv, - struct v4l2_fmtdesc *f) + struct v4l2_fmtdesc *f) { const struct vimc_pix_map *vpix; =20 @@ -170,7 +171,7 @@ static int vimc_capture_enum_fmt_vid_cap(struct file *f= ile, void *priv, } =20 static int vimc_capture_enum_framesizes(struct file *file, void *fh, - struct v4l2_frmsizeenum *fsize) + struct v4l2_frmsizeenum *fsize) { const struct vimc_pix_map *vpix; =20 @@ -206,9 +207,9 @@ static const struct v4l2_file_operations vimc_capture_f= ops =3D { static const struct v4l2_ioctl_ops vimc_capture_ioctl_ops =3D { .vidioc_querycap =3D vimc_capture_querycap, =20 - .vidioc_g_fmt_vid_cap =3D vimc_capture_g_fmt_vid_cap, - .vidioc_s_fmt_vid_cap =3D vimc_capture_s_fmt_vid_cap, - .vidioc_try_fmt_vid_cap =3D vimc_capture_try_fmt_vid_cap, + .vidioc_g_ext_pix_fmt_vid_cap =3D vimc_capture_g_fmt_vid_cap, + .vidioc_s_ext_pix_fmt_vid_cap =3D vimc_capture_s_fmt_vid_cap, + .vidioc_try_ext_pix_fmt_vid_cap =3D vimc_capture_try_fmt_vid_cap, .vidioc_enum_fmt_vid_cap =3D vimc_capture_enum_fmt_vid_cap, .vidioc_enum_framesizes =3D vimc_capture_enum_framesizes, =20 @@ -225,8 +226,9 @@ static const struct v4l2_ioctl_ops vimc_capture_ioctl_o= ps =3D { .vidioc_streamoff =3D vb2_ioctl_streamoff, }; =20 -static void vimc_capture_return_all_buffers(struct vimc_capture_device *vc= apture, - enum vb2_buffer_state state) +static void vimc_capture_return_all_buffers(struct vimc_capture_device + *vcapture, + enum vb2_buffer_state state) { struct vimc_capture_buffer *vbuf, *node; =20 @@ -240,7 +242,8 @@ static void vimc_capture_return_all_buffers(struct vimc= _capture_device *vcapture spin_unlock(&vcapture->qlock); } =20 -static int vimc_capture_start_streaming(struct vb2_queue *vq, unsigned int= count) +static int vimc_capture_start_streaming(struct vb2_queue *vq, + unsigned int count) { struct vimc_capture_device *vcapture =3D vb2_get_drv_priv(vq); int ret; @@ -248,7 +251,9 @@ static int vimc_capture_start_streaming(struct vb2_queu= e *vq, unsigned int count vcapture->sequence =3D 0; =20 /* Start the media pipeline */ - ret =3D video_device_pipeline_start(&vcapture->vdev, &vcapture->stream.pi= pe); + ret =3D + video_device_pipeline_start(&vcapture->vdev, + &vcapture->stream.pipe); if (ret) { vimc_capture_return_all_buffers(vcapture, VB2_BUF_STATE_QUEUED); return ret; @@ -283,27 +288,31 @@ static void vimc_capture_stop_streaming(struct vb2_qu= eue *vq) =20 static void vimc_capture_buf_queue(struct vb2_buffer *vb2_buf) { - struct vimc_capture_device *vcapture =3D vb2_get_drv_priv(vb2_buf->vb2_qu= eue); + struct vimc_capture_device *vcapture =3D + vb2_get_drv_priv(vb2_buf->vb2_queue); struct vimc_capture_buffer *buf =3D container_of(vb2_buf, - struct vimc_capture_buffer, - vb2.vb2_buf); + struct + vimc_capture_buffer, + vb2.vb2_buf); =20 spin_lock(&vcapture->qlock); list_add_tail(&buf->list, &vcapture->buf_list); spin_unlock(&vcapture->qlock); } =20 -static int vimc_capture_queue_setup(struct vb2_queue *vq, unsigned int *nb= uffers, - unsigned int *nplanes, unsigned int sizes[], - struct device *alloc_devs[]) +static int vimc_capture_queue_setup(struct vb2_queue *vq, + unsigned int *nbuffers, + unsigned int *nplanes, unsigned int sizes[], + struct device *alloc_devs[]) { struct vimc_capture_device *vcapture =3D vb2_get_drv_priv(vq); =20 if (*nplanes) - return sizes[0] < vcapture->format.sizeimage ? -EINVAL : 0; + return sizes[0] < + vcapture->format.plane_fmt[0].sizeimage ? -EINVAL : 0; /* We don't support multiplanes for now */ *nplanes =3D 1; - sizes[0] =3D vcapture->format.sizeimage; + sizes[0] =3D vcapture->format.plane_fmt[0].sizeimage; =20 return 0; } @@ -311,7 +320,7 @@ static int vimc_capture_queue_setup(struct vb2_queue *v= q, unsigned int *nbuffers static int vimc_capture_buffer_prepare(struct vb2_buffer *vb) { struct vimc_capture_device *vcapture =3D vb2_get_drv_priv(vb->vb2_queue); - unsigned long size =3D vcapture->format.sizeimage; + unsigned long size =3D vcapture->format.plane_fmt[0].sizeimage; =20 if (vb2_plane_size(vb, 0) < size) { dev_err(vcapture->ved.dev, "%s: buffer too small (%lu < %lu)\n", @@ -342,7 +351,7 @@ static const struct media_entity_operations vimc_captur= e_mops =3D { static void vimc_capture_release(struct vimc_ent_device *ved) { struct vimc_capture_device *vcapture =3D - container_of(ved, struct vimc_capture_device, ved); + container_of(ved, struct vimc_capture_device, ved); =20 media_entity_cleanup(vcapture->ved.ent); kfree(vcapture); @@ -351,16 +360,17 @@ static void vimc_capture_release(struct vimc_ent_devi= ce *ved) static void vimc_capture_unregister(struct vimc_ent_device *ved) { struct vimc_capture_device *vcapture =3D - container_of(ved, struct vimc_capture_device, ved); + container_of(ved, struct vimc_capture_device, ved); =20 vb2_video_unregister_device(&vcapture->vdev); } =20 static void *vimc_capture_process_frame(struct vimc_ent_device *ved, - const void *frame) + const void *frame) { - struct vimc_capture_device *vcapture =3D container_of(ved, struct vimc_ca= pture_device, - ved); + struct vimc_capture_device *vcapture =3D + container_of(ved, struct vimc_capture_device, + ved); struct vimc_capture_buffer *vimc_buf; void *vbuf; =20 @@ -386,11 +396,11 @@ static void *vimc_capture_process_frame(struct vimc_e= nt_device *ved, =20 vbuf =3D vb2_plane_vaddr(&vimc_buf->vb2.vb2_buf, 0); =20 - memcpy(vbuf, frame, vcapture->format.sizeimage); + memcpy(vbuf, frame, vcapture->format.plane_fmt[0].sizeimage); =20 /* Set it as ready */ vb2_set_plane_payload(&vimc_buf->vb2.vb2_buf, 0, - vcapture->format.sizeimage); + vcapture->format.plane_fmt[0].sizeimage); vb2_set_pixelformat(&vimc_buf->vb2.vb2_buf, vcapture->format.pixelformat); vb2_buffer_done(&vimc_buf->vb2.vb2_buf, VB2_BUF_STATE_DONE); @@ -398,7 +408,7 @@ static void *vimc_capture_process_frame(struct vimc_ent= _device *ved, } =20 static struct vimc_ent_device *vimc_capture_add(struct vimc_device *vimc, - const char *vcfg_name) + const char *vcfg_name) { struct v4l2_device *v4l2_dev =3D &vimc->v4l2_dev; const struct vimc_pix_map *vpix; @@ -416,8 +426,7 @@ static struct vimc_ent_device *vimc_capture_add(struct = vimc_device *vimc, vcapture->vdev.entity.name =3D vcfg_name; vcapture->vdev.entity.function =3D MEDIA_ENT_F_IO_V4L; vcapture->pad.flags =3D MEDIA_PAD_FL_SINK; - ret =3D media_entity_pads_init(&vcapture->vdev.entity, - 1, &vcapture->pad); + ret =3D media_entity_pads_init(&vcapture->vdev.entity, 1, &vcapture->pad); if (ret) goto err_free_vcapture; =20 @@ -434,7 +443,7 @@ static struct vimc_ent_device *vimc_capture_add(struct = vimc_device *vimc, q->buf_struct_size =3D sizeof(struct vimc_capture_buffer); q->ops =3D &vimc_capture_qops; q->mem_ops =3D vimc_allocator =3D=3D VIMC_ALLOCATOR_DMA_CONTIG - ? &vb2_dma_contig_memops : &vb2_vmalloc_memops; + ? &vb2_dma_contig_memops : &vb2_vmalloc_memops; q->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; q->min_buffers_needed =3D 2; q->lock =3D &vcapture->lock; @@ -454,9 +463,13 @@ static struct vimc_ent_device *vimc_capture_add(struct= vimc_device *vimc, /* Set default frame format */ vcapture->format =3D fmt_default; vpix =3D vimc_pix_map_by_pixelformat(vcapture->format.pixelformat); - vcapture->format.bytesperline =3D vcapture->format.width * vpix->bpp; - vcapture->format.sizeimage =3D vcapture->format.bytesperline * - vcapture->format.height; + memset(vcapture->format.plane_fmt, 0, + sizeof(vcapture->format.plane_fmt)); + vcapture->format.plane_fmt[0].bytesperline =3D + vcapture->format.width * vpix->bpp; + vcapture->format.plane_fmt[0].sizeimage =3D + vcapture->format.plane_fmt[0].bytesperline * + vcapture->format.height; =20 /* Fill the vimc_ent_device struct */ vcapture->ved.ent =3D &vcapture->vdev.entity; @@ -467,7 +480,7 @@ static struct vimc_ent_device *vimc_capture_add(struct = vimc_device *vimc, /* Initialize the video_device struct */ vdev =3D &vcapture->vdev; vdev->device_caps =3D V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING - | V4L2_CAP_IO_MC; + | V4L2_CAP_IO_MC; vdev->entity.ops =3D &vimc_capture_mops; vdev->release =3D video_device_release_empty; vdev->fops =3D &vimc_capture_fops; diff --git a/drivers/media/test-drivers/vimc/vimc-common.c b/drivers/media/= test-drivers/vimc/vimc-common.c index 7b27153c0728..8bbf80f2acb9 100644 --- a/drivers/media/test-drivers/vimc/vimc-common.c +++ b/drivers/media/test-drivers/vimc/vimc-common.c @@ -236,7 +236,7 @@ const struct vimc_pix_map *vimc_pix_map_by_pixelformat(= u32 pixelformat) } =20 static int vimc_get_pix_format(struct media_pad *pad, - struct v4l2_pix_format *fmt) + struct v4l2_ext_pix_format *fmt) { if (is_media_entity_v4l2_subdev(pad->entity)) { struct v4l2_subdev *sd =3D @@ -252,7 +252,7 @@ static int vimc_get_pix_format(struct media_pad *pad, if (ret) return ret; =20 - v4l2_fill_pix_format(fmt, &sd_fmt.format); + v4l2_fill_ext_pix_format_from_mbus(fmt, &sd_fmt.format); pix_map =3D vimc_pix_map_by_code(sd_fmt.format.code); fmt->pixelformat =3D pix_map->pixelformat; } else if (is_media_entity_v4l2_video_device(pad->entity)) { @@ -274,7 +274,7 @@ static int vimc_get_pix_format(struct media_pad *pad, =20 int vimc_vdev_link_validate(struct media_link *link) { - struct v4l2_pix_format source_fmt, sink_fmt; + struct v4l2_ext_pix_format source_fmt, sink_fmt; int ret; =20 ret =3D vimc_get_pix_format(link->source, &source_fmt); diff --git a/drivers/media/test-drivers/vimc/vimc-common.h b/drivers/media/= test-drivers/vimc/vimc-common.h index 7641a101a728..f29429df10dd 100644 --- a/drivers/media/test-drivers/vimc/vimc-common.h +++ b/drivers/media/test-drivers/vimc/vimc-common.h @@ -111,7 +111,7 @@ struct vimc_ent_device { void * (*process_frame)(struct vimc_ent_device *ved, const void *frame); void (*vdev_get_format)(struct vimc_ent_device *ved, - struct v4l2_pix_format *fmt); + struct v4l2_ext_pix_format *fmt); }; =20 /** --=20 2.17.1