public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Heiko Stübner" <heiko@sntech.de>
To: Andy Yan <andyshrk@163.com>
Cc: hjc@rock-chips.com, krzk+dt@kernel.org,
	devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org,
	derek.foreman@collabora.com, detlev.casanova@collabora.com,
	daniel@fooishbar.org, Andy Yan <andy.yan@rock-chips.com>,
	Michael Riesch <michael.riesch@wolfvision.net>
Subject: Re: [PATCH v8 2/9] drm/rockchip: vop2: Add platform specific callback
Date: Sun, 05 Jan 2025 22:50:30 +0100	[thread overview]
Message-ID: <17026630.geO5KgaWL5@diego> (raw)
In-Reply-To: <20241231090802.251787-3-andyshrk@163.com>

Hi Andy,

Am Dienstag, 31. Dezember 2024, 10:07:45 CET schrieb Andy Yan:
> From: Andy Yan <andy.yan@rock-chips.com>
> 
> The VOP interface mux, overlay, background delay cycle configuration
> of different SOC are much different. Add platform specific callback
> ops to let the core driver look cleaner and more refined.
> 
> Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
> Tested-by: Michael Riesch <michael.riesch@wolfvision.net> # on RK3568
> Tested-by: Detlev Casanova <detlev.casanova@collabora.com>

>  static int vop2_cluster_init(struct vop2_win *win)
>  {
>  	struct vop2 *vop2 = win->vop2;
>  	struct reg_field *cluster_regs;
>  	int ret, i;
>  
> -	cluster_regs = kmemdup(vop2_cluster_regs, sizeof(vop2_cluster_regs),
> +	cluster_regs = kmemdup(vop2->data->cluster_reg,
> +			       sizeof(struct reg_field) * vop2->data->nr_cluster_regs,
>  			       GFP_KERNEL);
>  	if (!cluster_regs)
>  		return -ENOMEM;
>  
> -	for (i = 0; i < ARRAY_SIZE(vop2_cluster_regs); i++)
> +	for (i = 0; i < vop2->data->nr_cluster_regs; i++)
>  		if (cluster_regs[i].reg != 0xffffffff)
>  			cluster_regs[i].reg += win->offset;
>  
>  	ret = devm_regmap_field_bulk_alloc(vop2->dev, vop2->map, win->reg,
>  					   cluster_regs,
> -					   ARRAY_SIZE(vop2_cluster_regs));
> -
> +					   vop2->data->nr_cluster_regs);
>  	kfree(cluster_regs);
>  
>  	return ret;
>  };

Even the original code, makes checkpatch really unhappy nowadays :-( .

As per
https://lore.kernel.org/all/20240706-regmap-const-structs-v1-1-d08c776da787@weissschuh.net/
reg_field should be considered const, so copying the original struct and
then modifying it causes checkpatch warnings now.

I've tried to adapt the function as in the patch below. This should
contain the same functionality as before, just with keeping the reg_field
const.

As it's the weekend, I didn't have time to test that change, so it's more
meant as an idea on how to proceed.


> +	/* afbc regs */
> +	[VOP2_WIN_AFBC_FORMAT] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 2, 6),
> +	[VOP2_WIN_AFBC_RB_SWAP] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 9, 9),
> +	[VOP2_WIN_AFBC_UV_SWAP] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 10, 10),
> +	[VOP2_WIN_AFBC_AUTO_GATING_EN] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_OUTPUT_CTRL, 4, 4),
> +	[VOP2_WIN_AFBC_HALF_BLOCK_EN] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 7, 7),
> +	[VOP2_WIN_AFBC_BLOCK_SPLIT_EN] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 8, 8),
> +	[VOP2_WIN_AFBC_HDR_PTR] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_HDR_PTR, 0, 31),
> +	[VOP2_WIN_AFBC_PIC_SIZE] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_PIC_SIZE, 0, 31),
> +	[VOP2_WIN_AFBC_PIC_VIR_WIDTH] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_VIR_WIDTH, 0, 15),
> +	[VOP2_WIN_AFBC_TILE_NUM] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_VIR_WIDTH, 16, 31),
> +	[VOP2_WIN_AFBC_PIC_OFFSET] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_PIC_OFFSET, 0, 31),
> +	[VOP2_WIN_AFBC_DSP_OFFSET] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_DSP_OFFSET, 0, 31),
> +	[VOP2_WIN_AFBC_TRANSFORM_OFFSET] = REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_TRANSFORM_OFFSET, 0, 31),

exceeds the 100 char line length, so I think we should have a line break
after RK3568_CLUSTER_WIN_AFBCD_TRANSFORM_OFFSET


Thanks
Heiko

---------------- 8< ---------------
From: Heiko Stuebner <heiko@sntech.de>
Date: Sun, 5 Jan 2025 17:38:31 +0100
Subject: [PATCH] drm/rockchip: vop2: use devm_regmap_field_alloc for cluster-regs

Right now vop2_cluster_init() copies the base vop2_cluster_regs and adapts
the reg value with the current window's offset before adding the fields to
the regmap.

This conflicts with the notion of reg_fields being const, see
https://lore.kernel.org/all/20240706-regmap-const-structs-v1-1-d08c776da787@weissschuh.net/
for reference, which now causes checkpatch to actually warn about that.

So instead of creating one big copy and changing it afterwards, add the
reg_fields individually using devm_regmap_field_alloc().

Functional it is the same, just that the reg_field we're handling
can stay const.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 30 +++++++++-----------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
index 17a98845fd31..c8da1ebb6013 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
@@ -3443,25 +3443,23 @@ static struct reg_field vop2_cluster_regs[VOP2_WIN_MAX_REG] = {
 static int vop2_cluster_init(struct vop2_win *win)
 {
 	struct vop2 *vop2 = win->vop2;
-	struct reg_field *cluster_regs;
-	int ret, i;
-
-	cluster_regs = kmemdup(vop2_cluster_regs, sizeof(vop2_cluster_regs),
-			       GFP_KERNEL);
-	if (!cluster_regs)
-		return -ENOMEM;
+	int i;
 
-	for (i = 0; i < ARRAY_SIZE(vop2_cluster_regs); i++)
-		if (cluster_regs[i].reg != 0xffffffff)
-			cluster_regs[i].reg += win->offset;
+	for (i = 0; i < ARRAY_SIZE(vop2_cluster_regs); i++) {
+		const struct reg_field field = {
+			.reg = (vop2_cluster_regs[i].reg != 0xffffffff) ?
+					vop2_cluster_regs[i].reg + win->offset :
+					vop2_cluster_regs[i].reg,
+			.lsb = vop2_cluster_regs[i].lsb,
+			.msb = vop2_cluster_regs[i].msb
+		};
 
-	ret = devm_regmap_field_bulk_alloc(vop2->dev, vop2->map, win->reg,
-					   cluster_regs,
-					   ARRAY_SIZE(vop2_cluster_regs));
-
-	kfree(cluster_regs);
+		win->reg[i] = devm_regmap_field_alloc(vop2->dev, vop2->map, field);
+		if (IS_ERR(win->reg[i]))
+			return PTR_ERR(win->reg[i]);
+	}
 
-	return ret;
+	return 0;
 };
 
 static struct reg_field vop2_esmart_regs[VOP2_WIN_MAX_REG] = {
-- 
2.45.2






  reply	other threads:[~2025-01-05 21:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-31  9:07 [PATCH v8 0/9] VOP Support for rk3576 Andy Yan
2024-12-31  9:07 ` [PATCH v8 1/9] drm/rockchip: vop2: Support 32x8 superblock afbc Andy Yan
2024-12-31  9:07 ` [PATCH v8 2/9] drm/rockchip: vop2: Add platform specific callback Andy Yan
2025-01-05 21:50   ` Heiko Stübner [this message]
2025-01-06  1:54     ` Andy Yan
2024-12-31  9:07 ` [PATCH v8 3/9] drm/rockchip: vop2: Support for different layer select configuration between VPs Andy Yan
2024-12-31  9:07 ` [PATCH v8 4/9] drm/rockchip: vop2: Introduce vop hardware version Andy Yan
2024-12-31  9:07 ` [PATCH v8 5/9] drm/rockchip: vop2: Register the primary plane and overlay plane separately Andy Yan
2024-12-31  9:07 ` [PATCH v8 6/9] drm/rockchip: vop2: Set plane possible crtcs by possible vp mask Andy Yan
2024-12-31  9:07 ` [PATCH v8 7/9] drm/rockchip: vop2: Add uv swap for cluster window Andy Yan
2024-12-31  9:07 ` [PATCH v8 8/9] dt-bindings: display: vop2: Add rk3576 support Andy Yan
2025-01-03 16:34   ` Rob Herring
2025-01-06  8:28     ` Andy Yan
2024-12-31  9:07 ` [PATCH v8 9/9] drm/rockchip: vop2: Add support for rk3576 Andy Yan
2025-01-05 16:06 ` (subset) [PATCH v8 0/9] VOP Support " Heiko Stuebner

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=17026630.geO5KgaWL5@diego \
    --to=heiko@sntech.de \
    --cc=andy.yan@rock-chips.com \
    --cc=andyshrk@163.com \
    --cc=daniel@fooishbar.org \
    --cc=derek.foreman@collabora.com \
    --cc=detlev.casanova@collabora.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hjc@rock-chips.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=michael.riesch@wolfvision.net \
    /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