devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Sven Püschel" <s.pueschel@pengutronix.de>
To: Nicolas Dufresne <nicolas@ndufresne.ca>,
	Jacob Chen <jacob-chen@iotwrt.com>,
	Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Heiko Stuebner <heiko@sntech.de>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-rockchip@lists.infradead.org, kernel@pengutronix.de,
	linux-arm-kernel@lists.infradead.org,
	linux-media@vger.kernel.org
Subject: Re: [PATCH 03/16] media: rockchip: rga: align stride to 16 bytes
Date: Tue, 2 Dec 2025 15:36:33 +0100	[thread overview]
Message-ID: <2dc6c675-9c69-40a1-b2ed-ff1d22157228@pengutronix.de> (raw)
In-Reply-To: <db7030790063d0ebe6d254c7053e758184b9d7cc.camel@ndufresne.ca>

Hi Nicolas,

On 10/7/25 8:19 PM, Nicolas Dufresne wrote:
> Hi,
>
>
> Le mardi 07 octobre 2025 à 10:31 +0200, Sven Püschel a écrit :
>> Align the stride to a multiple of 16 according to the RGA3 requirements
>> mentioned in the datasheet. This also ensures that the stride of the RGA2
>> is aligned to 4 bytes, as it needs to divide the value by 4 (one word)
>> before storing it in the register.
>>
>> Increasing the stride for the alignment also requires to increase the
>> sizeimage value. This is usually handled by v4l2_fill_pixfmt_mp, but
>> it doesn't allow to set a stride alignment. Therefore use the generated
>> values to calculate the total number of lines to properly update the
>> sizeimage value after the bytesperline has been aligned.
>>
>> Signed-off-by: Sven Püschel <s.pueschel@pengutronix.de>
>> ---
>>   drivers/media/platform/rockchip/rga/rga.c | 21 +++++++++++++++++++++
>>   1 file changed, 21 insertions(+)
>>
>> diff --git a/drivers/media/platform/rockchip/rga/rga.c
>> b/drivers/media/platform/rockchip/rga/rga.c
>> index
>> 6438119a6c7aeff1e89e7aa95dcd5d2921fefa08..3cb7ce470c47e39d694e8176875a75fad271
>> 7f96 100644
>> --- a/drivers/media/platform/rockchip/rga/rga.c
>> +++ b/drivers/media/platform/rockchip/rga/rga.c
>> @@ -459,6 +459,25 @@ static int vidioc_enum_fmt(struct file *file, void *priv,
>> struct v4l2_fmtdesc *f
>>   	return 0;
>>   }
>>   
>> +static void align_pixfmt(struct v4l2_pix_format_mplane *pix_fmt)
>> +{
>> +	int lines;
>> +	struct v4l2_plane_pix_format *fmt;
>> +
>> +	/*
>> +	 * Align stride to 16 for the RGA3 (based on the datasheet)
>> +	 * To not dismiss the v4l2_fill_pixfmt_mp helper
>> +	 * (and manually write it again), we're approximating the new
>> sizeimage
>> +	 */
>> +	for (fmt = pix_fmt->plane_fmt;
>> +	     fmt < pix_fmt->plane_fmt + pix_fmt->num_planes;
>> +	     fmt++) {
>> +		lines = DIV_ROUND_UP(fmt->sizeimage, fmt->bytesperline);
>> +		fmt->bytesperline = (fmt->bytesperline + 0xf) & ~0xf;
>> +		fmt->sizeimage = fmt->bytesperline * lines;
> Instead of open coding this, describe this with struct v4l2_frmsize_stepwise and
> then use v4l2_apply_frmsize_constraints().
Looking into v4l2_frmsize_stepwise, it only applies to the width/height 
values, whereas I'm interested to control the stride 
byte-alignment/stepping (allowing free range widths/heights).

Do you intent that I (mis)use it like this: 
v4l2_apply_frmsize_constraints(&fmt->bytesperline, &lines, &constraints)  ?

This only replaces one of the three lines in the for loop (where i 
manually do the alignment with & ~0xf) and would also look odd, as i use 
a value in bytes as a width parameter (expected to be in pixels).

Technically the core problem is that the v4l2_fill_pixfmt_mp helper 
doesn't allow to specify a stride byte alignment and just aligns the 
stride based on the format requirements. Therefore I think that maybe 
creating a new v4l2_fill_pixfmt_mp_aligned helper would probably be the 
better solution to get the correct bytesperline value right from the 
start instead of adjusting it afterwards.

Sincerely
     Sven
>
> Nicolas
>
>> +	}
>> +}
>> +
>>   static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
>>   {
>>   	struct v4l2_pix_format_mplane *pix_fmt = &f->fmt.pix_mp;
>> @@ -474,6 +493,7 @@ static int vidioc_g_fmt(struct file *file, void *priv,
>> struct v4l2_format *f)
>>   		return PTR_ERR(frm);
>>   
>>   	v4l2_fill_pixfmt_mp(pix_fmt, frm->fmt->fourcc, frm->width, frm-
>>> height);
>> +	align_pixfmt(pix_fmt);
>>   
>>   	pix_fmt->field = V4L2_FIELD_NONE;
>>   	pix_fmt->colorspace = frm->colorspace;
>> @@ -496,6 +516,7 @@ static int vidioc_try_fmt(struct file *file, void *priv,
>> struct v4l2_format *f)
>>   				(u32)MIN_HEIGHT, (u32)MAX_HEIGHT);
>>   
>>   	v4l2_fill_pixfmt_mp(pix_fmt, fmt->fourcc, pix_fmt->width, pix_fmt-
>>> height);
>> +	align_pixfmt(pix_fmt);
>>   	pix_fmt->field = V4L2_FIELD_NONE;
>>   
>>   	return 0;

  reply	other threads:[~2025-12-02 14:36 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07  8:31 [PATCH 00/16] media: platform: rga: Add RGA3 support Sven Püschel
2025-10-07  8:31 ` [PATCH 01/16] media: rockchip: rga: use clk_bulk api Sven Püschel
2025-10-07  8:31 ` [PATCH 02/16] media: rockchip: rga: use stride for offset calculation Sven Püschel
2025-10-07  8:31 ` [PATCH 03/16] media: rockchip: rga: align stride to 16 bytes Sven Püschel
2025-10-07 18:19   ` Nicolas Dufresne
2025-12-02 14:36     ` Sven Püschel [this message]
2025-10-07  8:31 ` [PATCH 04/16] media: rockchip: rga: move hw specific parts to a dedicated struct Sven Püschel
2025-10-07  8:31 ` [PATCH 05/16] media: rockchip: rga: use card type to specify rga type Sven Püschel
2025-10-07  8:31 ` [PATCH 06/16] media: rockchip: rga: change offset to dma_addresses Sven Püschel
2025-10-07  8:32 ` [PATCH 07/16] media: rockchip: rga: support external iommus Sven Püschel
2025-10-07  8:32 ` [PATCH 08/16] media: rockchip: rga: remove size from rga_frame Sven Püschel
2025-10-07  8:32 ` [PATCH 09/16] media: rockchip: rga: remove stride " Sven Püschel
2025-10-07  8:32 ` [PATCH 10/16] media: rockchip: rga: move rga_fmt to rga-hw.h Sven Püschel
2025-10-07  8:32 ` [PATCH 11/16] media: rockchip: rga: add iommu restore function Sven Püschel
2025-10-07 18:30   ` Nicolas Dufresne
2025-10-10  8:45     ` Sven Püschel
2025-10-10 13:10       ` Nicolas Dufresne
2025-10-07  8:32 ` [PATCH 12/16] media: rockchip: rga: handle error interrupt Sven Püschel
2025-10-07 18:47   ` Nicolas Dufresne
2025-10-07  8:32 ` [PATCH 13/16] media: dt-bindings: media: rockchip-rga: add rockchip,rk3588-rga3 Sven Püschel
2025-10-07  8:38   ` Krzysztof Kozlowski
2025-10-07 18:12     ` Nicolas Dufresne
2025-10-07  8:32 ` [PATCH 14/16] arm64: dts: rockchip: add rga3 dt nodes Sven Püschel
2025-10-07  8:32 ` [PATCH 15/16] arm64: dts: rockchip: increase rga3 clock speed Sven Püschel
2025-10-07  8:39   ` Krzysztof Kozlowski
2025-10-07  8:32 ` [PATCH 16/16] media: rockchip: rga: add rga3 support Sven Püschel
2025-10-07  8:39   ` Krzysztof Kozlowski
2025-10-07 16:05     ` Sven Püschel
2025-10-08  1:55       ` Krzysztof Kozlowski
2025-10-07 18:54     ` Nicolas Dufresne
2025-10-07 19:41   ` Nicolas Dufresne
2025-10-10  9:21     ` Sven Püschel
2025-12-03  9:49     ` Sven Püschel
2025-12-03 18:17       ` Nicolas Dufresne
2025-10-11  5:32   ` kernel test robot
2025-10-07 18:06 ` [PATCH 00/16] media: platform: rga: Add RGA3 support Nicolas Dufresne
2025-10-10  8:33   ` Sven Püschel
2025-10-10 13:05     ` Nicolas Dufresne
2025-10-09 22:03 ` Rob Herring (Arm)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2dc6c675-9c69-40a1-b2ed-ff1d22157228@pengutronix.de \
    --to=s.pueschel@pengutronix.de \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=heiko@sntech.de \
    --cc=jacob-chen@iotwrt.com \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas@ndufresne.ca \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).