[v3,2/8] clk: sunxi-ng: de2: Export register regmap for DE33

Message ID 20261115061102.229680-3-jernej.skrabec@gmail.com (mailing list archive)
State New
Headers
Series drm/sun4i: update DE33 support |

Commit Message

Jernej Skrabec Nov. 15, 2026, 6:10 a.m. UTC
The DE33 clock driver presets the plane mapping, which is not something
that a clock driver should do. Remove that and export the mapping
registers through a regmap instead, so the DRM driver can set them
properly.

Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
---
 drivers/clk/sunxi-ng/ccu-sun8i-de2.c | 43 ++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 3 deletions(-)
  

Comments

sashiko-bot@kernel.org Nov. 15, 2026, 6:27 a.m. UTC | #1
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] clk: sunxi-ng: de2: missing select REGMAP_MMIO for
  SUN8I_DE2_CCU
--

commit d1c006fcc75e6e1facbfb7f265581bef0d4d672a
Author: Jernej Skrabec <jernej.skrabec@gmail.com>

clk: sunxi-ng: de2: Export register regmap for DE33

This commit removes the hardcoded DE33 plane mapping writes from the clock
driver and exports those registers via an MMIO regmap instead.

> diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-de2.c b/drivers/clk/sunxi-ng/ccu-sun8i-de2.c
> index 6ec6c0dc4c261..f17570efafaae 100644
> --- a/drivers/clk/sunxi-ng/ccu-sun8i-de2.c
> +++ b/drivers/clk/sunxi-ng/ccu-sun8i-de2.c

[ ... ]

> @@ -336,13 +367,19 @@ static int sunxi_de2_clk_probe(struct platform_device *pdev)
>  	}
>  
>  	/*
> -	 * The DE33 requires these additional (unknown) registers set
> +	 * The DE33 requires these additional plane mapping registers set
>  	 * during initialisation.
>  	 */
>  	if (of_device_is_compatible(pdev->dev.of_node,
>  				    "allwinner,sun50i-h616-de33-clk")) {
> -		writel(0, reg + 0x24);
> -		writel(0x0000a980, reg + 0x28);
> +		struct regmap *regmap;
> +
> +		regmap = devm_regmap_init_mmio(&pdev->dev, reg,
> +					       &sun8i_de2_ccu_regmap_config);
> +		if (IS_ERR(regmap)) {
> +			ret = PTR_ERR(regmap);
> +			goto err_assert_reset;
> +		}
>  	}

[Severity: Medium]
Should SUN8I_DE2_CCU select REGMAP_MMIO in drivers/clk/sunxi-ng/Kconfig?

Without it, enabling SUN8I_DE2_CCU when REGMAP_MMIO is disabled (for
example under COMPILE_TEST=y with ARCH_SUNXI=n) or built as a module with
SUN8I_DE2_CCU=y breaks compilation on sun8i_de2_ccu_regmap_config or fails
to link __devm_regmap_init_mmio_clk().
  
Chen-Yu Tsai Nov. 15, 2026, 12:07 p.m. UTC | #2
On Sun, Nov 15, 2026 at 2:27 PM <sashiko-bot@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] clk: sunxi-ng: de2: missing select REGMAP_MMIO for
>   SUN8I_DE2_CCU

Added while applying.

> --
>
> commit d1c006fcc75e6e1facbfb7f265581bef0d4d672a
> Author: Jernej Skrabec <jernej.skrabec@gmail.com>
>
> clk: sunxi-ng: de2: Export register regmap for DE33
>
> This commit removes the hardcoded DE33 plane mapping writes from the clock
> driver and exports those registers via an MMIO regmap instead.
>
> > diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-de2.c b/drivers/clk/sunxi-ng/ccu-sun8i-de2.c
> > index 6ec6c0dc4c261..f17570efafaae 100644
> > --- a/drivers/clk/sunxi-ng/ccu-sun8i-de2.c
> > +++ b/drivers/clk/sunxi-ng/ccu-sun8i-de2.c
>
> [ ... ]
>
> > @@ -336,13 +367,19 @@ static int sunxi_de2_clk_probe(struct platform_device *pdev)
> >       }
> >
> >       /*
> > -      * The DE33 requires these additional (unknown) registers set
> > +      * The DE33 requires these additional plane mapping registers set
> >        * during initialisation.
> >        */
> >       if (of_device_is_compatible(pdev->dev.of_node,
> >                                   "allwinner,sun50i-h616-de33-clk")) {
> > -             writel(0, reg + 0x24);
> > -             writel(0x0000a980, reg + 0x28);
> > +             struct regmap *regmap;
> > +
> > +             regmap = devm_regmap_init_mmio(&pdev->dev, reg,
> > +                                            &sun8i_de2_ccu_regmap_config);
> > +             if (IS_ERR(regmap)) {
> > +                     ret = PTR_ERR(regmap);
> > +                     goto err_assert_reset;
> > +             }
> >       }
>
> [Severity: Medium]
> Should SUN8I_DE2_CCU select REGMAP_MMIO in drivers/clk/sunxi-ng/Kconfig?
>
> Without it, enabling SUN8I_DE2_CCU when REGMAP_MMIO is disabled (for
> example under COMPILE_TEST=y with ARCH_SUNXI=n) or built as a module with
> SUN8I_DE2_CCU=y breaks compilation on sun8i_de2_ccu_regmap_config or fails
> to link __devm_regmap_init_mmio_clk().
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261115061102.229680-1-jernej.skrabec@gmail.com?part=2
>
  

Patch

diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-de2.c b/drivers/clk/sunxi-ng/ccu-sun8i-de2.c
index 6ec6c0dc4c26..f17570efafaa 100644
--- a/drivers/clk/sunxi-ng/ccu-sun8i-de2.c
+++ b/drivers/clk/sunxi-ng/ccu-sun8i-de2.c
@@ -9,6 +9,7 @@ 
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/regmap.h>
 #include <linux/reset.h>
 
 #include "ccu_common.h"
@@ -283,6 +284,36 @@  static const struct sunxi_ccu_desc sun50i_h616_de33_clk_desc = {
 	.num_resets	= ARRAY_SIZE(sun50i_h616_de33_resets),
 };
 
+/*
+ * Add a regmap for the DE33 plane driver to access plane
+ * mapping registers.
+ * Only these registers are allowed to be written, to prevent
+ * overriding clock and reset configuration.
+ */
+
+#define SUN50I_DE33_CHN2CORE_REG 0x24
+#define SUN50I_DE33_PORT12CHN_REG 0x2c
+
+static const struct regmap_range sun8i_de2_ccu_regmap_accessible_ranges[] = {
+	regmap_reg_range(SUN50I_DE33_CHN2CORE_REG, SUN50I_DE33_PORT12CHN_REG),
+};
+
+static const struct regmap_access_table sun8i_de2_ccu_regmap_accessible_table = {
+	.yes_ranges = sun8i_de2_ccu_regmap_accessible_ranges,
+	.n_yes_ranges = ARRAY_SIZE(sun8i_de2_ccu_regmap_accessible_ranges),
+};
+
+static const struct regmap_config sun8i_de2_ccu_regmap_config = {
+	.reg_bits	= 32,
+	.val_bits	= 32,
+	.reg_stride	= 4,
+	.max_register	= SUN50I_DE33_PORT12CHN_REG,
+
+	/* other devices have no business accessing other registers */
+	.wr_table	= &sun8i_de2_ccu_regmap_accessible_table,
+	.rd_table	= &sun8i_de2_ccu_regmap_accessible_table,
+};
+
 static int sunxi_de2_clk_probe(struct platform_device *pdev)
 {
 	struct clk *bus_clk, *mod_clk;
@@ -336,13 +367,19 @@  static int sunxi_de2_clk_probe(struct platform_device *pdev)
 	}
 
 	/*
-	 * The DE33 requires these additional (unknown) registers set
+	 * The DE33 requires these additional plane mapping registers set
 	 * during initialisation.
 	 */
 	if (of_device_is_compatible(pdev->dev.of_node,
 				    "allwinner,sun50i-h616-de33-clk")) {
-		writel(0, reg + 0x24);
-		writel(0x0000a980, reg + 0x28);
+		struct regmap *regmap;
+
+		regmap = devm_regmap_init_mmio(&pdev->dev, reg,
+					       &sun8i_de2_ccu_regmap_config);
+		if (IS_ERR(regmap)) {
+			ret = PTR_ERR(regmap);
+			goto err_assert_reset;
+		}
 	}
 
 	ret = devm_sunxi_ccu_probe(&pdev->dev, reg, ccu_desc);