]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
soc: renesas: rz-sysc: Add syscon/regmap support
authorJohn Madieu <john.madieu.xa@bp.renesas.com>
Mon, 18 Aug 2025 16:28:47 +0000 (18:28 +0200)
committerGeert Uytterhoeven <geert+renesas@glider.be>
Wed, 20 Aug 2025 06:35:55 +0000 (08:35 +0200)
The RZ/G3E system controller has various registers that control or report
some properties specific to individual IPs. The regmap is registered as a
syscon device to allow these IP drivers to access the registers through the
regmap API.

As other RZ SoCs might have custom read/write callbacks or max-offsets,
register a custom regmap configuration.

[claudiu.beznea:
 - do not check the match->data validity in rz_sysc_probe() as it is
   always valid
 - dinamically allocate regmap_cfg]

Signed-off-by: John Madieu <john.madieu.xa@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Reviewed-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> # on RZ/G3S
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/20250818162859.9661-2-john.madieu.xa@bp.renesas.com
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
drivers/soc/renesas/Kconfig
drivers/soc/renesas/r9a08g045-sysc.c
drivers/soc/renesas/r9a09g047-sys.c
drivers/soc/renesas/r9a09g057-sys.c
drivers/soc/renesas/rz-sysc.c
drivers/soc/renesas/rz-sysc.h

index 719b7f4f376f0596d8d5b0deb90281e75ee87f58..c97e2a183388f2b00a17887af2451a75904ea17e 100644 (file)
@@ -449,6 +449,7 @@ config RST_RCAR
 
 config SYSC_RZ
        bool "System controller for RZ SoCs" if COMPILE_TEST
+       select MFD_SYSCON
 
 config SYSC_R9A08G045
        bool "Renesas System controller support for R9A08G045 (RZ/G3S)" if COMPILE_TEST
index f4db1431e03678e2fbb523572360139c3b78ef73..0504d4e6876169ede8ff07797e1616b20479dc39 100644 (file)
@@ -20,4 +20,5 @@ static const struct rz_sysc_soc_id_init_data rzg3s_sysc_soc_id_init_data __initc
 
 const struct rz_sysc_init_data rzg3s_sysc_init_data __initconst = {
        .soc_id_init_data = &rzg3s_sysc_soc_id_init_data,
+       .max_register = 0xe20,
 };
index cd2eb7782cfe6a15adc500e1c8a44be7d0b62307..2e8426c030504966dbbf579134474f4d4ff0959e 100644 (file)
@@ -64,4 +64,5 @@ static const struct rz_sysc_soc_id_init_data rzg3e_sys_soc_id_init_data __initco
 
 const struct rz_sysc_init_data rzg3e_sys_init_data = {
        .soc_id_init_data = &rzg3e_sys_soc_id_init_data,
+       .max_register = 0x170c,
 };
index 4c21cc29edbc389e9b27c29604e4bdfdfbd19945..e3390e7c7fe516d6ce67f87f341bfd3884fa062d 100644 (file)
@@ -64,4 +64,5 @@ static const struct rz_sysc_soc_id_init_data rzv2h_sys_soc_id_init_data __initco
 
 const struct rz_sysc_init_data rzv2h_sys_init_data = {
        .soc_id_init_data = &rzv2h_sys_soc_id_init_data,
+       .max_register = 0x170c,
 };
index ffa65fb4dade8dc9ff46b429de4b5677e19da16c..9f79e299e6f416413e1ec6cd274a193312c494ba 100644 (file)
@@ -5,9 +5,13 @@
  * Copyright (C) 2024 Renesas Electronics Corp.
  */
 
+#include <linux/cleanup.h>
 #include <linux/io.h>
+#include <linux/mfd/syscon.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
 #include <linux/sys_soc.h>
 
 #include "rz-sysc.h"
@@ -100,14 +104,23 @@ MODULE_DEVICE_TABLE(of, rz_sysc_match);
 
 static int rz_sysc_probe(struct platform_device *pdev)
 {
+       const struct rz_sysc_init_data *data;
        const struct of_device_id *match;
        struct device *dev = &pdev->dev;
+       struct regmap *regmap;
        struct rz_sysc *sysc;
+       int ret;
+
+       struct regmap_config *regmap_cfg __free(kfree) = kzalloc(sizeof(*regmap_cfg), GFP_KERNEL);
+       if (!regmap_cfg)
+               return -ENOMEM;
 
        match = of_match_node(rz_sysc_match, dev->of_node);
        if (!match)
                return -ENODEV;
 
+       data = match->data;
+
        sysc = devm_kzalloc(dev, sizeof(*sysc), GFP_KERNEL);
        if (!sysc)
                return -ENOMEM;
@@ -117,7 +130,22 @@ static int rz_sysc_probe(struct platform_device *pdev)
                return PTR_ERR(sysc->base);
 
        sysc->dev = dev;
-       return rz_sysc_soc_init(sysc, match);
+       ret = rz_sysc_soc_init(sysc, match);
+       if (ret)
+               return ret;
+
+       regmap_cfg->name = "rz_sysc_regs";
+       regmap_cfg->reg_bits = 32;
+       regmap_cfg->reg_stride = 4;
+       regmap_cfg->val_bits = 32;
+       regmap_cfg->fast_io = true;
+       regmap_cfg->max_register = data->max_register;
+
+       regmap = devm_regmap_init_mmio(dev, sysc->base, regmap_cfg);
+       if (IS_ERR(regmap))
+               return PTR_ERR(regmap);
+
+       return of_syscon_register_regmap(dev->of_node, regmap);
 }
 
 static struct platform_driver rz_sysc_driver = {
index 56bc047a1bff46f799b8856dfddfbb9d7a23b1a7..8eec355d5d5620673d223841b0c0bbaec18b0b46 100644 (file)
@@ -34,9 +34,11 @@ struct rz_sysc_soc_id_init_data {
 /**
  * struct rz_sysc_init_data - RZ SYSC initialization data
  * @soc_id_init_data: RZ SYSC SoC ID initialization data
+ * @max_register: Maximum SYSC register offset to be used by the regmap config
  */
 struct rz_sysc_init_data {
        const struct rz_sysc_soc_id_init_data *soc_id_init_data;
+       u32 max_register;
 };
 
 extern const struct rz_sysc_init_data rzg3e_sys_init_data;