Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1234562lqe; Mon, 8 Apr 2024 02:58:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWI0Px+YbLlHXOGteSRbzUpC1ErpcXvIhcOKwYKHvet1nIuWx4v281yduckR++YrktAAK8dF9fbF6v9jeqUVwLwJW4Nl/X67JORz5nKpw== X-Google-Smtp-Source: AGHT+IFAWP5cQJXv6qQ8f6hAS+JvXceO4yRdIitaesaTHyAR1UBfbeBXj4t9kd80KSsH9mNve/a/ X-Received: by 2002:a05:6512:401f:b0:516:d0d5:6f60 with SMTP id br31-20020a056512401f00b00516d0d56f60mr7211414lfb.38.1712570307218; Mon, 08 Apr 2024 02:58:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712570307; cv=pass; d=google.com; s=arc-20160816; b=WGvDxB/5z49cfbtCUn07znIIGbRJM7mdt4GHkID1l9ayC5xBQ+bA0Xg9KCEodfTfc9 7GyRt9sKWUICraPv/7Dw3U63/VVI/vtPjE18pHPz1FIQpf5DGHJRKGHIlUyxBXVczALZ 4guJ3YsYMDyf9oWfKS2cuC0kSsPP8s3Z6mup5qEE98Hp8JxWzn0oAwi3mbnKa+umDjWg yKj5Pd0k5qsz3EiqRKWc0sK0VFr8lp3BeOMJFYsbbguspfxnK8QRa+P+WZj7mhIG3/Kc v05X1yihStNKf9VOX4KMCxzFcNXKappScEwcTjN2VPiFtTTxgkLWEhQzXjo8vWb2X3TP Pzvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id; bh=z9v9DJJZms37s7s9MCuD2p6Eg1MUnNSvt46k+uU8CjM=; fh=ejZKMPXw/wpgIkBgg4R8fhS2jsJTspCs9srLwjcCwrU=; b=RmrraUmG+iQWk4i/l2EsFnuCVwfzBEBhH4G1QDqP82X9w2qJoxOP2fRfLnOSaDU/zx vmvuXvMuFjlbso8s8FpgdD6ZKqHUpWX0tAxcBXY+NaMcXzGdznPtrwZFgaqEnniplUR2 QQYBx26AtK5cXCu/ygytNquo61qxL8vVBUe1KgLYFVS8jht/lx110FDHD/r+aPNrGxjJ 75MODUcSp/kYNosNckdj+aDyIcgC7gECZ2J+jJNLv1Fi6O08XkXWlVNKTjuAY9xXEWa+ Dkun0BwS3Vp3TJDIh+IREiW58M8mKVvarjQxEU5T4hatgUvMuwJdQJ7of8XkuhapiOND 546w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-135188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135188-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a9-20020a1709064a4900b00a4e7713adfbsi3400651ejv.964.2024.04.08.02.58.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 02:58:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-135188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135188-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C175B1F22A59 for ; Mon, 8 Apr 2024 09:58:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E64DB524DB; Mon, 8 Apr 2024 09:58:17 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B992E4D110; Mon, 8 Apr 2024 09:58:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712570296; cv=none; b=IxsGtBw1+ftWhn7JCyWpJx77O33pspB/zxnR3gwIPeJ1EjtyPV/vbVUV8DZ6wCj0bEemLn2DdLsj2qf8BnuoEoHVNXYs68AVUatXEUeHUuGLusNd/+dESJ/fgw39a6FoBfXrYKTLoQ6uBt+IX+bSljzQEtINBtdWcvB2sI6/5vw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712570296; c=relaxed/simple; bh=PDS8X9Y65r/Q+pj1LaSGsu/RIPAG3KpYpYjUQaGRiKk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=X5AtTVfq9DNEy8/IGWEfMzJqZHfT0BjhgdaRJ0okC/hNEZXlJLxRQL3piDqe2Xs5HEMCYO4wH9MFSylbjuuwII/lvavu7ASlHsIVFiZY3HPW2n89XmrlXoVRGSZTd3t2tZFSFLvAZw9vrLhgixYY9u59ja/7doCbnPsIsqcGAbU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11720C433C7; Mon, 8 Apr 2024 09:58:14 +0000 (UTC) Message-ID: <7bd3e051-418b-4b4a-ba57-644f829604c7@xs4all.nl> Date: Mon, 8 Apr 2024 11:58:13 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 1/3] media: mgb4: Add support for YUV image formats Content-Language: en-US, nl To: tumic@gpxsee.org, Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?Q?Martin_T=C5=AFma?= References: <20240322151005.3499-1-tumic@gpxsee.org> <20240322151005.3499-2-tumic@gpxsee.org> From: Hans Verkuil Autocrypt: addr=hverkuil@xs4all.nl; keydata= xsFNBFQ84W0BEAC7EF1iL4s3tY8cRTVkJT/297h0Hz0ypA+ByVM4CdU9sN6ua/YoFlr9k0K4 BFUlg7JzJoUuRbKxkYb8mmqOe722j7N3HO8+ofnio5cAP5W0WwDpM0kM84BeHU0aPSTsWiGR yw55SOK2JBSq7hueotWLfJLobMWhQii0Zd83hGT9SIt9uHaHjgwmtTH7MSTIiaY6N14nw2Ud C6Uykc1va0Wqqc2ov5ihgk/2k2SKa02ookQI3e79laOrbZl5BOXNKR9LguuOZdX4XYR3Zi6/ BsJ7pVCK9xkiVf8svlEl94IHb+sa1KrlgGv3fn5xgzDw8Z222TfFceDL/2EzUyTdWc4GaPMC E/c1B4UOle6ZHg02+I8tZicjzj5+yffv1lB5A1btG+AmoZrgf0X2O1B96fqgHx8w9PIpVERN YsmkfxvhfP3MO3oHh8UY1OLKdlKamMneCLk2up1Zlli347KMjHAVjBAiy8qOguKF9k7HOjif JCLYTkggrRiEiE1xg4tblBNj8WGyKH+u/hwwwBqCd/Px2HvhAsJQ7DwuuB3vBAp845BJYUU3 06kRihFqbO0vEt4QmcQDcbWINeZ2zX5TK7QQ91ldHdqJn6MhXulPKcM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V7TIoweP0RwDrcf5PVvwSWsRQp2LxFCkwnCXOra gYmkrmv0duG1FStpY+IIQn1TOkuXrciTVfZY1cZD0aVxwlxXBnUNZZNslldvXFtndxR0SFat sflovhDxKyhFwXOP0Rv8H378/+14TaykknRBIKEc0+lcr+EMOSUR5eg4aURb8Gc3Uc7fgQ6q UssTXzHPyj1hAyDpfu8DzAwlh4kKFTodxSsKAjI45SLjadSc94/5Gy8645Y1KgBzBPTH7Q== In-Reply-To: <20240322151005.3499-2-tumic@gpxsee.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi Martin, Just a few small comments: On 22/03/2024 16:10, tumic@gpxsee.org wrote: > From: Martin Tůma > > Recent mgb4 firmwares support YUV in addition to the RGB image format. Enable > YUV in the driver when the FW supports it. > > Signed-off-by: Martin Tůma > --- > drivers/media/pci/mgb4/mgb4_io.h | 7 ++ > drivers/media/pci/mgb4/mgb4_vin.c | 116 ++++++++++++++++++++++++----- > drivers/media/pci/mgb4/mgb4_vout.c | 116 ++++++++++++++++++++++++----- > 3 files changed, 203 insertions(+), 36 deletions(-) > > diff --git a/drivers/media/pci/mgb4/mgb4_io.h b/drivers/media/pci/mgb4/mgb4_io.h > index 8698db1be4a9..204613a6685c 100644 > --- a/drivers/media/pci/mgb4/mgb4_io.h > +++ b/drivers/media/pci/mgb4/mgb4_io.h > @@ -30,4 +30,11 @@ static inline struct mgb4_frame_buffer *to_frame_buffer(struct vb2_v4l2_buffer * > return container_of(vbuf, struct mgb4_frame_buffer, vb); > } > > +static inline bool has_yuv(struct mgb4_regs *video) > +{ > + u32 status = mgb4_read_reg(video, 0xD0); > + > + return (status & (1U << 8)); > +} > + > #endif > diff --git a/drivers/media/pci/mgb4/mgb4_vin.c b/drivers/media/pci/mgb4/mgb4_vin.c > index 2cd78c539889..19692e4dfb59 100644 > --- a/drivers/media/pci/mgb4/mgb4_vin.c > +++ b/drivers/media/pci/mgb4/mgb4_vin.c > @@ -186,8 +186,11 @@ static int queue_setup(struct vb2_queue *q, unsigned int *nbuffers, > struct device *alloc_devs[]) > { > struct mgb4_vin_dev *vindev = vb2_get_drv_priv(q); > + struct mgb4_regs *video = &vindev->mgbdev->video; > + u32 config = mgb4_read_reg(video, vindev->config->regs.config); > + u32 pixelsize = (config & (1U << 16)) ? 2 : 4; > unsigned int size = (vindev->timings.bt.width + vindev->padding) > - * vindev->timings.bt.height * 4; > + * vindev->timings.bt.height * pixelsize; > > /* > * If I/O reconfiguration is in process, do not allow to start > @@ -220,9 +223,12 @@ static int buffer_init(struct vb2_buffer *vb) > static int buffer_prepare(struct vb2_buffer *vb) > { > struct mgb4_vin_dev *vindev = vb2_get_drv_priv(vb->vb2_queue); > + struct mgb4_regs *video = &vindev->mgbdev->video; > struct device *dev = &vindev->mgbdev->pdev->dev; > + u32 config = mgb4_read_reg(video, vindev->config->regs.config); > + u32 pixelsize = (config & (1U << 16)) ? 2 : 4; > unsigned int size = (vindev->timings.bt.width + vindev->padding) > - * vindev->timings.bt.height * 4; > + * vindev->timings.bt.height * pixelsize; > > if (vb2_plane_size(vb, 0) < size) { > dev_err(dev, "buffer too small (%lu < %u)\n", > @@ -359,22 +365,33 @@ static int vidioc_querycap(struct file *file, void *priv, > static int vidioc_enum_fmt(struct file *file, void *priv, > struct v4l2_fmtdesc *f) > { > - if (f->index != 0) > - return -EINVAL; > + struct mgb4_vin_dev *vindev = video_drvdata(file); > + struct mgb4_regs *video = &vindev->mgbdev->video; > > - f->pixelformat = V4L2_PIX_FMT_ABGR32; > + if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) > + return -EINVAL; No need to test for this, it is guaranteed to be correct (the v4l2 core handles that). > > - return 0; > + if (f->index == 0) { > + f->pixelformat = V4L2_PIX_FMT_ABGR32; > + return 0; > + } else if (f->index == 1 && has_yuv(video)) { > + f->pixelformat = V4L2_PIX_FMT_YUYV; > + return 0; > + } else { > + return -EINVAL; > + } > } > > static int vidioc_enum_frameintervals(struct file *file, void *priv, > struct v4l2_frmivalenum *ival) > { > struct mgb4_vin_dev *vindev = video_drvdata(file); > + struct mgb4_regs *video = &vindev->mgbdev->video; > > if (ival->index != 0) > return -EINVAL; > - if (ival->pixel_format != V4L2_PIX_FMT_ABGR32) > + if (!(ival->pixel_format == V4L2_PIX_FMT_ABGR32 || > + ((has_yuv(video) && ival->pixel_format == V4L2_PIX_FMT_YUYV)))) > return -EINVAL; > if (ival->width != vindev->timings.bt.width || > ival->height != vindev->timings.bt.height) > @@ -393,13 +410,32 @@ static int vidioc_enum_frameintervals(struct file *file, void *priv, > static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f) > { > struct mgb4_vin_dev *vindev = video_drvdata(file); > + struct mgb4_regs *video = &vindev->mgbdev->video; > + u32 config = mgb4_read_reg(video, vindev->config->regs.config); > + > + if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) > + return -EINVAL; No need for this test. > > - f->fmt.pix.pixelformat = V4L2_PIX_FMT_ABGR32; > f->fmt.pix.width = vindev->timings.bt.width; > f->fmt.pix.height = vindev->timings.bt.height; > f->fmt.pix.field = V4L2_FIELD_NONE; > - f->fmt.pix.colorspace = V4L2_COLORSPACE_RAW; > - f->fmt.pix.bytesperline = (f->fmt.pix.width + vindev->padding) * 4; > + > + if (config & (1U << 16)) { > + f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; > + if (config & (1U << 20)) { > + f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709; > + } else { > + if (config & (1U << 19)) > + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; > + else > + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; > + } > + f->fmt.pix.bytesperline = (f->fmt.pix.width + vindev->padding) * 2; > + } else { > + f->fmt.pix.pixelformat = V4L2_PIX_FMT_ABGR32; > + f->fmt.pix.colorspace = V4L2_COLORSPACE_RAW; > + f->fmt.pix.bytesperline = (f->fmt.pix.width + vindev->padding) * 4; > + } > f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * f->fmt.pix.height; > > return 0; > @@ -408,14 +444,33 @@ static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f) > static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f) > { > struct mgb4_vin_dev *vindev = video_drvdata(file); > + struct mgb4_regs *video = &vindev->mgbdev->video; > + u32 pixelsize; > + > + if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) > + return -EINVAL; No need for this test. > > - f->fmt.pix.pixelformat = V4L2_PIX_FMT_ABGR32; > f->fmt.pix.width = vindev->timings.bt.width; > f->fmt.pix.height = vindev->timings.bt.height; > f->fmt.pix.field = V4L2_FIELD_NONE; > - f->fmt.pix.colorspace = V4L2_COLORSPACE_RAW; > - f->fmt.pix.bytesperline = max(f->fmt.pix.width * 4, > - ALIGN_DOWN(f->fmt.pix.bytesperline, 4)); > + > + if (has_yuv(video) && f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) { > + pixelsize = 2; > + if (!(f->fmt.pix.colorspace == V4L2_COLORSPACE_REC709 || > + f->fmt.pix.colorspace == V4L2_COLORSPACE_SMPTE170M)) > + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; > + } else { > + pixelsize = 4; > + f->fmt.pix.pixelformat = V4L2_PIX_FMT_ABGR32; > + f->fmt.pix.colorspace = V4L2_COLORSPACE_RAW; > + } > + > + if (f->fmt.pix.bytesperline > f->fmt.pix.width * pixelsize > + && f->fmt.pix.bytesperline < f->fmt.pix.width * pixelsize * 2) Put the '&&' at the end of the previous line instead. checkpatch warns on this. > + f->fmt.pix.bytesperline = ALIGN(f->fmt.pix.bytesperline, > + pixelsize); > + else > + f->fmt.pix.bytesperline = f->fmt.pix.width * pixelsize; > f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * f->fmt.pix.height; > > return 0; > @@ -425,13 +480,39 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) > { > struct mgb4_vin_dev *vindev = video_drvdata(file); > struct mgb4_regs *video = &vindev->mgbdev->video; > + u32 config, pixelsize; > + int ret; > > if (vb2_is_busy(&vindev->queue)) > return -EBUSY; > > - vidioc_try_fmt(file, priv, f); > + ret = vidioc_try_fmt(file, priv, f); > + if (ret < 0) > + return ret; It is better to move the 'vb2_is_busy()' call to after the try_fmt. That way, even if the vb2 is busy, the fmt is still updated by the try_fmt call. > + > + config = mgb4_read_reg(video, vindev->config->regs.config); > + if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) { > + pixelsize = 2; > + config |= 1U << 16; > + > + if (f->fmt.pix.colorspace == V4L2_COLORSPACE_REC709) { > + config |= 1U << 20; > + config |= 1U << 19; > + } else if (f->fmt.pix.colorspace == V4L2_COLORSPACE_SMPTE170M) { > + config &= ~(1U << 20); > + config |= 1U << 19; > + } else { > + config &= ~(1U << 20); > + config &= ~(1U << 19); > + } > + } else { > + pixelsize = 4; > + config &= ~(1U << 16); > + } > + mgb4_write_reg(video, vindev->config->regs.config, config); > > - vindev->padding = (f->fmt.pix.bytesperline - (f->fmt.pix.width * 4)) / 4; > + vindev->padding = (f->fmt.pix.bytesperline - (f->fmt.pix.width > + * pixelsize)) / pixelsize; > mgb4_write_reg(video, vindev->config->regs.padding, vindev->padding); > set_loopback_padding(vindev, vindev->padding); > > @@ -467,7 +548,8 @@ static int vidioc_enum_framesizes(struct file *file, void *fh, > { > struct mgb4_vin_dev *vindev = video_drvdata(file); > > - if (fsize->index != 0 || fsize->pixel_format != V4L2_PIX_FMT_ABGR32) > + if (fsize->index != 0 || !(fsize->pixel_format == V4L2_PIX_FMT_ABGR32 || > + fsize->pixel_format == V4L2_PIX_FMT_YUYV)) > return -EINVAL; > > fsize->discrete.width = vindev->timings.bt.width; > diff --git a/drivers/media/pci/mgb4/mgb4_vout.c b/drivers/media/pci/mgb4/mgb4_vout.c > index 241353ee77a5..243fbeaaceb9 100644 > --- a/drivers/media/pci/mgb4/mgb4_vout.c > +++ b/drivers/media/pci/mgb4/mgb4_vout.c > @@ -59,7 +59,11 @@ static int queue_setup(struct vb2_queue *q, unsigned int *nbuffers, > struct device *alloc_devs[]) > { > struct mgb4_vout_dev *voutdev = vb2_get_drv_priv(q); > - unsigned int size; > + struct mgb4_regs *video = &voutdev->mgbdev->video; > + u32 config = mgb4_read_reg(video, voutdev->config->regs.config); > + u32 pixelsize = (config & (1U << 16)) ? 2 : 4; > + unsigned int size = (voutdev->width + voutdev->padding) * voutdev->height > + * pixelsize; > > /* > * If I/O reconfiguration is in process, do not allow to start > @@ -69,8 +73,6 @@ static int queue_setup(struct vb2_queue *q, unsigned int *nbuffers, > if (test_bit(0, &voutdev->mgbdev->io_reconfig)) > return -EBUSY; > > - size = (voutdev->width + voutdev->padding) * voutdev->height * 4; > - > if (*nplanes) > return sizes[0] < size ? -EINVAL : 0; > *nplanes = 1; > @@ -93,9 +95,11 @@ static int buffer_prepare(struct vb2_buffer *vb) > { > struct mgb4_vout_dev *voutdev = vb2_get_drv_priv(vb->vb2_queue); > struct device *dev = &voutdev->mgbdev->pdev->dev; > - unsigned int size; > - > - size = (voutdev->width + voutdev->padding) * voutdev->height * 4; > + struct mgb4_regs *video = &voutdev->mgbdev->video; > + u32 config = mgb4_read_reg(video, voutdev->config->regs.config); > + u32 pixelsize = (config & (1U << 16)) ? 2 : 4; > + unsigned int size = (voutdev->width + voutdev->padding) * voutdev->height > + * pixelsize; > > if (vb2_plane_size(vb, 0) < size) { > dev_err(dev, "buffer too small (%lu < %u)\n", > @@ -194,24 +198,53 @@ static int vidioc_querycap(struct file *file, void *priv, > static int vidioc_enum_fmt(struct file *file, void *priv, > struct v4l2_fmtdesc *f) > { > - if (f->index != 0) > - return -EINVAL; > + struct mgb4_vin_dev *voutdev = video_drvdata(file); > + struct mgb4_regs *video = &voutdev->mgbdev->video; > > - f->pixelformat = V4L2_PIX_FMT_ABGR32; > + if (f->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) > + return -EINVAL; Test is not needed. > > - return 0; > + if (f->index == 0) { > + f->pixelformat = V4L2_PIX_FMT_ABGR32; > + return 0; > + } else if (f->index == 1 && has_yuv(video)) { > + f->pixelformat = V4L2_PIX_FMT_YUYV; > + return 0; > + } else { > + return -EINVAL; > + } > } > > static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f) > { > struct mgb4_vout_dev *voutdev = video_drvdata(file); > + struct mgb4_regs *video = &voutdev->mgbdev->video; > + u32 config = mgb4_read_reg(video, voutdev->config->regs.config); > + > + if (f->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) > + return -EINVAL; Ditto. > > - f->fmt.pix.pixelformat = V4L2_PIX_FMT_ABGR32; > f->fmt.pix.width = voutdev->width; > f->fmt.pix.height = voutdev->height; > f->fmt.pix.field = V4L2_FIELD_NONE; > - f->fmt.pix.colorspace = V4L2_COLORSPACE_RAW; > - f->fmt.pix.bytesperline = (f->fmt.pix.width + voutdev->padding) * 4; > + > + if (config & (1U << 16)) { > + f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; > + if (config & (1U << 20)) { > + f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709; > + } else { > + if (config & (1U << 19)) > + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; > + else > + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; > + } > + f->fmt.pix.bytesperline = (f->fmt.pix.width + voutdev->padding) * 2; > + } else { > + f->fmt.pix.pixelformat = V4L2_PIX_FMT_ABGR32; > + f->fmt.pix.colorspace = V4L2_COLORSPACE_RAW; > + f->fmt.pix.bytesperline = (f->fmt.pix.width + voutdev->padding) * 4; > + } > + > f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * f->fmt.pix.height; > > return 0; > @@ -220,14 +253,33 @@ static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f) > static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f) > { > struct mgb4_vout_dev *voutdev = video_drvdata(file); > + struct mgb4_regs *video = &voutdev->mgbdev->video; > + u32 pixelsize; > + > + if (f->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) > + return -EINVAL; Ditto. > > - f->fmt.pix.pixelformat = V4L2_PIX_FMT_ABGR32; > f->fmt.pix.width = voutdev->width; > f->fmt.pix.height = voutdev->height; > f->fmt.pix.field = V4L2_FIELD_NONE; > - f->fmt.pix.colorspace = V4L2_COLORSPACE_RAW; > - f->fmt.pix.bytesperline = max(f->fmt.pix.width * 4, > - ALIGN_DOWN(f->fmt.pix.bytesperline, 4)); > + > + if (has_yuv(video) && f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) { > + pixelsize = 2; > + if (!(f->fmt.pix.colorspace == V4L2_COLORSPACE_REC709 || > + f->fmt.pix.colorspace == V4L2_COLORSPACE_SMPTE170M)) > + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; > + } else { > + pixelsize = 4; > + f->fmt.pix.pixelformat = V4L2_PIX_FMT_ABGR32; > + f->fmt.pix.colorspace = V4L2_COLORSPACE_RAW; > + } > + > + if (f->fmt.pix.bytesperline > f->fmt.pix.width * pixelsize > + && f->fmt.pix.bytesperline < f->fmt.pix.width * pixelsize * 2) Move '&&' to the end of the previous line. > + f->fmt.pix.bytesperline = ALIGN(f->fmt.pix.bytesperline, > + pixelsize); > + else > + f->fmt.pix.bytesperline = f->fmt.pix.width * pixelsize; > f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * f->fmt.pix.height; > > return 0; > @@ -237,13 +289,39 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) > { > struct mgb4_vout_dev *voutdev = video_drvdata(file); > struct mgb4_regs *video = &voutdev->mgbdev->video; > + u32 config, pixelsize; > + int ret; > > if (vb2_is_busy(&voutdev->queue)) > return -EBUSY; > > - vidioc_try_fmt(file, priv, f); > + ret = vidioc_try_fmt(file, priv, f); > + if (ret < 0) > + return ret; Move vb2_is_busy call to here. > + > + config = mgb4_read_reg(video, voutdev->config->regs.config); > + if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) { > + pixelsize = 2; > + config |= 1U << 16; > + > + if (f->fmt.pix.colorspace == V4L2_COLORSPACE_REC709) { > + config |= 1U << 20; > + config |= 1U << 19; > + } else if (f->fmt.pix.colorspace == V4L2_COLORSPACE_SMPTE170M) { > + config &= ~(1U << 20); > + config |= 1U << 19; > + } else { > + config &= ~(1U << 20); > + config &= ~(1U << 19); > + } > + } else { > + pixelsize = 4; > + config &= ~(1U << 16); > + } > + mgb4_write_reg(video, voutdev->config->regs.config, config); > > - voutdev->padding = (f->fmt.pix.bytesperline - (f->fmt.pix.width * 4)) / 4; > + voutdev->padding = (f->fmt.pix.bytesperline - (f->fmt.pix.width > + * pixelsize)) / pixelsize; > mgb4_write_reg(video, voutdev->config->regs.padding, voutdev->padding); > > return 0; Regards, Hans