Add syscon of_syscon_register_regmap api
Peter Griffin
maintainerv3 cover Add syscon of_syscon_register_regmap api
Hi Lee, Arnd, Krzysztof, all,
This series adds support to syscon driver for a new of_syscon_register_regmap() api.
Platforms such as gs101 require a special regmap to access PMU registers, which in the existing upstream client drivers are accessed via syscon regmap. This issue was partly solved in [1] whereby a custom regmap is created in exynos-pmu and a new API exynos_get_pmu_regmap_by_phandle() created.
One issue with the approach in [1] is that it required client drivers to be updated from syscon_regmap_lookup_by_phandle() to exynos_get_pmu_regmap_by_phandle() when obtaining the regmap.
Whilst updating to exynos_get_pmu_regmap_by_phandle() was OK for exynos specific drivers, it meant other drivers like syscon-reboot and syscon-poweroff which span multiple SoC architectures could not be easily re-used.
In previous review feedback for USB phy and gs101 poweroff driver Krzysztof requested [2] that we take a more generic approach that other SoCs can also leverage.
The new of_syscon_register_regmap() api overcomes this limitation by allowing a SoC driver like exynos-pmu to register it's SoC specific regmap with the syscon driver. This keeps the SoC complexity out of syscon driver, and allows client drivers to continue using syscon_regmap_lookup_by_phandle() as before. The solution allows more code re-use and can be used by other SoC archs.
Notes on probe ordering
exynos-pmu runs at postcore_initcall, so all but one of the client drivers (ufs phy, usb phy, watchdog) run after the regmap is created and registered.
The one exception to this is pinctrl-samsung driver which is also postcore_initcall level. The exynos_get_pmu_regmap() and exynos_get_pmu_regmap_by_phandle() have been temporarily left to support -EPROBE_DEFER for pinctrl-samsung driver.
The longer term plan to solve that probe ordering issue is to enable fw_devlink for syscon dt properties so they are correctly listed as suppliers in /sys/class/devlink. I tested a PoC patch (see below) for fw_devlink and that seemed to work fine. Once fw_devlink supports syscon I believe exynos_get_pmu_regmap_by_phandle() api could be removed. The main issue currently with fw_devlink syscon support is the wide diversity of dt property naming currently in use. That was discussed previously here [3]
1248a1256,1257
Quoted 2 lines
DEFINE_SUFFIX_PROP(syscon_phandle, "syscon-phandle", NULL)DEFINE_SUFFIX_PROP(pmu_syscon, "pmu-syscon", NULL)
1358a1368,1369
Quoted 2 lines
{ .parse_prop =
parse_syscon_phandle, },
{ .parse_prop =parse_pmu_syscon, },
Note one previous concern from Saravana about syscon potentially probing before exynos-pmu driver and it relying on drivers/Makefile ordering. I tested this and even if mfd is listed before soc in drivers/Makefile exynos-pmu always probes first due to syscon driver not setting a .of_match_table entry.
Once the syscon and exynos-pmu patchs are queued I will send patches for watchdog and ufs phy drivers to switch back to syscon_regmap_lookup_by_phandle()
Many thanks,
Peter.
[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/T/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/all/CAGETcx-CCpaV7R0O0HpDpoX6KxQBuJiMmKdWA8nDE-5Qj2Sa7g@mail.gmail.com/
Changes since v2:
- Move allocation outside spinlock area (Arnd)
Link to v2:
- https://lore.kernel.org/linux-arm-kernel/[email protected]/
Changes since v1:
- Collect by tags
- Keep syscon lock held for check and adding entry (Krzysztof)
- pass pmu_np not np to syscon_node_to_regmap() (William)
Link to v1:
- https://lore.kernel.org/linux-arm-kernel/[email protected]/
Peter Griffin (2):
mfd: syscon: add of_syscon_register_regmap() API
soc: samsung: exynos-pmu: update to use of_syscon_register_regmap()
drivers/mfd/syscon.c | 48 ++++++++++++++++++++++++++++++++ drivers/soc/samsung/exynos-pmu.c | 38 ++++++++++--------------- include/linux/mfd/syscon.h | 8 ++++++ 3 files changed, 70 insertions(+), 24 deletions(-)
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Peter Griffin
maintainerPATCH v3 1/2 mfd: syscon: add of_syscon_register_regmap() API
The of_syscon_register_regmap() API allows an externally created regmap to be registered with syscon. This regmap can then be returned to client drivers using the syscon_regmap_lookup_by_phandle() APIs.
The API is used by platforms where mmio access to the syscon registers is not possible, and a underlying soc driver like exynos-pmu provides a SoC specific regmap that can issue a SMC or hypervisor call to write the register.
This approach keeps the SoC complexities out of syscon, but allows common drivers such as syscon-poweroff, syscon-reboot and friends that are used by many SoCs already to be re-used.
---
Changes in v3:
- Move kzalloc allocation outside of spin lock (Arnd)
- Link to v2 https://lore.kernel.org/linux-arm-kernel/[email protected]/
Changes in v2:
- Keep syscon lock held between checking and adding entry (Krzysztof)
- Link to v1 https://lore.kernel.org/linux-arm-kernel/[email protected]/
--- drivers/mfd/syscon.c | 48 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/syscon.h | 8 +++++++ 2 files changed, 56 insertions(+)
drivers/mfd/syscon.c +48 -0
@@ -192,6 +192,54 @@ static struct regmap *device_node_get_regmap(struct device_node *np,return syscon->regmap; } +/** +* of_syscon_register_regmap() - Register regmap for specified device node +* @np: Device tree node +* @regmap: Pointer to regmap object +* +* Register an externally created regmap object with syscon for the specified +* device tree node. This regmap will then be returned to client drivers using +* the syscon_regmap_lookup_by_phandle() API. +* +* Return: 0 on success, negative error code on failure. +*/ +int of_syscon_register_regmap (struct device_node *np,struct regmap *regmap) +{ +struct syscon *entry, *syscon =NULL ; +int ret; + +if (!np || !regmap) +return -EINVAL ; + + syscon =kzalloc (sizeof (*syscon),GFP_KERNEL ); +if (!syscon) +return -ENOMEM ; + +/* check if syscon entry already exists */ +spin_lock (&syscon_list_slock); + +list_for_each_entry (entry, &syscon_list, list) +if (entry->np == np) { + ret = -EEXIST ; + goto err_unlock; + } + + syscon->regmap = regmap; + syscon->np = np; + +/* register the regmap in syscon list */ +list_add_tail (&syscon->list, &syscon_list); +spin_unlock (&syscon_list_slock); + +return 0 ; + +err_unlock: +spin_unlock (&syscon_list_slock); +kfree (syscon); +return ret; +} +EXPORT_SYMBOL_GPL (of_syscon_register_regmap); +struct regmap *device_node_to_regmap (struct device_node *np) {return device_node_get_regmap (np, false);
include/linux/mfd/syscon.h +8 -0
@@ -28,6 +28,8 @@ struct regmap *syscon_regmap_lookup_by_phandle_args(struct device_node *np, unsigned int *out_args);struct regmap *syscon_regmap_lookup_by_phandle_optional (struct device_node *np,const char *property); +int of_syscon_register_regmap (struct device_node *np, +struct regmap *regmap);#else static inline struct regmap *device_node_to_regmap (struct device_node *np) {
@@ -67,6 +69,12 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle_optional(return NULL ; } +static inline int of_syscon_register_regmap (struct device_node *np, +struct regmap *regmap) +{ +return -EOPNOTSUPP ; +} +#endif #endif /* __LINUX_MFD_SYSCON_H__ */
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Re: [PATCH v3 1/2] mfd: syscon: add of_syscon_register_regmap() API
Quoted 9 lines · Peter Griffin
The
of_syscon_register_regmap()API allows an externally created regmap to be registered with syscon. This regmap can then be returned to client drivers using thesyscon_regmap_lookup_by_phandle()APIs.The API is used by platforms where mmio access to the syscon registers is not possible, and a underlying soc driver like exynos-pmu provides a SoC specific regmap that can issue a SMC or hypervisor call to write the register.
Quoted 7 lines
This approach keeps the SoC complexities out of syscon, but allows common drivers such as syscon-poweroff, syscon-reboot and friends that are used by many SoCs already to be re-used.
Signed-off-by Peter Griffin <[email protected]>Reviewed-by Arnd Bergmann <[email protected]>Reviewed-by Sam Protsenko <[email protected]>
[...]
Thanks Peter! I've tested the patch series on my Pixel 6 Pro and all is working well. I verified all the modularized drivers load and probe successfully:
root@google-gs:~# lsmod Module Size Used by at24 24576 0 dwc3_exynos 12288 0 i2c_exynos5 28672 0 phy_exynos_ufs 20480 1 ufs_exynos 32768 0 phy_exynos5_usbdrd 36864 2 s3c2410_wdt 24576 0 arm_dsu_pmu 24576 0
Thanks,
Will
Re: [PATCH v3 1/2] mfd: syscon: add of_syscon_register_regmap() API
In reply to Peter GriffinQuoted 9 lines · Peter Griffin
The
of_syscon_register_regmap()API allows an externally created regmap to be registered with syscon. This regmap can then be returned to client drivers using thesyscon_regmap_lookup_by_phandle()APIs.The API is used by platforms where mmio access to the syscon registers is not possible, and a underlying soc driver like exynos-pmu provides a SoC specific regmap that can issue a SMC or hypervisor call to write the register.
Quoted 7 lines
This approach keeps the SoC complexities out of syscon, but allows common drivers such as syscon-poweroff, syscon-reboot and friends that are used by many SoCs already to be re-used.
Signed-off-by Peter Griffin <[email protected]>Reviewed-by Arnd Bergmann <[email protected]>Reviewed-by Sam Protsenko <[email protected]>
Lee,
The second patch is for Samsung SoC but it depends on this one. I do not see any conflicting work, so you could take both via MFD tree, but just in case, could you keep both on a separate patchset? That way I could still pull it if there are more patches coming.
Best regards,
Krzysztof
Peter Griffin
maintainerPATCH v3 2/2 soc: samsung: exynos-pmu: update to use of_syscon_register_regmap()
In reply to Peter GriffinFor SoCs like gs101 that need a special regmap, register this with of_syscon_register_regmap api, so it can be returned by syscon_regmap_lookup_by_phandle() and friends.
For SoCs that don't require a custom regmap, revert back to syscon creating the mmio regmap rather than duplicating the logic here.
exynos_get_pmu_regmap_by_phandle() api is also updated to retrieve the regmap via syscon. The exynos_get_pmu_regmap_by_phandle() api is kept around until fw_devlink support for syscon property is added for the pinctrl-samsung driver that also runs at postcore_initcall level.
All other exynos client drivers can revert back to syscon_regmap_lookup_by_phandle().
---
Changes in v2:
- None
- Link to v2: https://lore.kernel.org/linux-arm-kernel/[email protected]/
Changes since v1:
- pass pmu_np (not np) to syscon_node_to_regmap() (reported by William)
- Link to v1: https://lore.kernel.org/linux-arm-kernel/[email protected]/
--- drivers/soc/samsung/exynos-pmu.c | 38 ++++++++++++-------------------- 1 file changed, 14 insertions(+), 24 deletions(-)
drivers/soc/samsung/exynos-pmu.c +14 -24
@@ -204,16 +204,6 @@ static const struct regmap_config regmap_smccfg = { .reg_update_bits = tensor_sec_update_bits, }; -static const struct regmap_config regmap_mmiocfg = { - .name ="pmu_regs" , - .reg_bits =32 , - .reg_stride =4 , - .val_bits =32 , - .fast_io = true, - .use_single_read = true, - .use_single_write = true, -}; -static const struct exynos_pmu_data gs101_pmu_data = { .pmu_secure = true };
@@ -290,7 +280,6 @@ EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap);struct regmap *exynos_get_pmu_regmap_by_phandle (struct device_node *np,const char *propname) { -struct exynos_pmu_context *ctx;struct device_node *pmu_np;struct device *dev;
@@ -316,9 +305,7 @@ struct regmap *exynos_get_pmu_regmap_by_phandle(struct device_node *np,if (!dev)return ERR_PTR (-EPROBE_DEFER ); - ctx =dev_get_drvdata (dev); - -return ctx->pmureg; +return syscon_node_to_regmap (pmu_np); }EXPORT_SYMBOL_GPL (exynos_get_pmu_regmap_by_phandle);
@@ -355,19 +342,22 @@ static int exynos_pmu_probe(struct platform_device *pdev) regmap =devm_regmap_init (dev,NULL , (void *)(uintptr_t )res->start, &pmu_regmcfg); + +if (IS_ERR (regmap)) +return dev_err_probe (&pdev->dev,PTR_ERR (regmap), +"regmap init failed\n" ); + + ret =of_syscon_register_regmap (dev->of_node, regmap); +if (ret) +return ret; }else { -/* All other SoCs use a MMIO regmap */ - pmu_regmcfg = regmap_mmiocfg; - pmu_regmcfg.max_register =resource_size (res) - - pmu_regmcfg.reg_stride; - regmap =devm_regmap_init_mmio (dev, pmu_base_addr, - &pmu_regmcfg); +/* let syscon create mmio regmap */ + regmap =syscon_node_to_regmap (dev->of_node); +if (IS_ERR (regmap)) +return dev_err_probe (&pdev->dev,PTR_ERR (regmap), +"syscon_node_to_regmap failed\n" ); } -if (IS_ERR (regmap)) -return dev_err_probe (&pdev->dev,PTR_ERR (regmap), -"regmap init failed\n" ); - pmu_context->pmureg = regmap; pmu_context->dev = dev;
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Re: [PATCH v3 2/2] soc: samsung: exynos-pmu: update to use of_syscon_register_regmap()
Quoted 13 lines · Peter Griffin
For SoCs like gs101 that need a special regmap, register this with
of_syscon_register_regmapapi, so it can be returned bysyscon_regmap_lookup_by_phandle()and friends.For SoCs that don't require a custom regmap, revert back to syscon creating the mmio regmap rather than duplicating the logic here.
exynos_get_pmu_regmap_by_phandle()api is also updated to retrieve the regmap via syscon. Theexynos_get_pmu_regmap_by_phandle()api is kept around untilfw_devlinksupport for syscon property is added for the pinctrl-samsung driver that also runs atpostcore_initcalllevel.
Quoted 6 lines
All other exynos client drivers can revert back to
syscon_regmap_lookup_by_phandle().Signed-off-by Peter Griffin <[email protected]>Reviewed-by Arnd Bergmann <[email protected]>Reviewed-by Sam Protsenko <[email protected]>
[...]
(Testing details in patch 1)
Thanks,
Will
Re: [PATCH v3 2/2] soc: samsung: exynos-pmu: update to use of_syscon_register_regmap()
In reply to Peter GriffinQuoted 13 lines · Peter Griffin
For SoCs like gs101 that need a special regmap, register this with
of_syscon_register_regmapapi, so it can be returned bysyscon_regmap_lookup_by_phandle()and friends.For SoCs that don't require a custom regmap, revert back to syscon creating the mmio regmap rather than duplicating the logic here.
exynos_get_pmu_regmap_by_phandle()api is also updated to retrieve the regmap via syscon. Theexynos_get_pmu_regmap_by_phandle()api is kept around untilfw_devlinksupport for syscon property is added for the pinctrl-samsung driver that also runs atpostcore_initcalllevel.
Quoted 6 lines
All other exynos client drivers can revert back to
syscon_regmap_lookup_by_phandle().Signed-off-by Peter Griffin <[email protected]>Reviewed-by Arnd Bergmann <[email protected]>Reviewed-by Sam Protsenko <[email protected]>
For Lee/MFD:
Best regards,
Krzysztof
Arnd Bergmann
maintainerQuoted 3 lines · Peter Griffin
Changes since v2:
- Move allocation outside spinlock area (Arnd)
Link to v2:
Looks good to me now.
Arnd
Lee Jones
maintainerQuoted 83 lines · Peter Griffin
Hi Lee, Arnd, Krzysztof, all,
This series adds support to syscon driver for a new
of_syscon_register_regmap()api.Platforms such as gs101 require a special regmap to access PMU registers, which in the existing upstream client drivers are accessed via syscon regmap. This issue was partly solved in [1] whereby a custom regmap is created in exynos-pmu and a new API
exynos_get_pmu_regmap_by_phandle()created.One issue with the approach in [1] is that it required client drivers to be updated from
syscon_regmap_lookup_by_phandle()toexynos_get_pmu_regmap_by_phandle()when obtaining the regmap.Whilst updating to
exynos_get_pmu_regmap_by_phandle()was OK for exynos specific drivers, it meant other drivers like syscon-reboot and syscon-poweroff which span multiple SoC architectures could not be easily re-used.In previous review feedback for USB phy and gs101 poweroff driver Krzysztof requested [2] that we take a more generic approach that other SoCs can also leverage.
The new
of_syscon_register_regmap()api overcomes this limitation by allowing a SoC driver like exynos-pmu to register it's SoC specific regmap with the syscon driver. This keeps the SoC complexity out of syscon driver, and allows client drivers to continue usingsyscon_regmap_lookup_by_phandle()as before. The solution allows more code re-use and can be used by other SoC archs.Notes on probe ordering
exynos-pmu runs at
postcore_initcall, so all but one of the client drivers (ufs phy, usb phy, watchdog) run after the regmap is created and registered.The one exception to this is pinctrl-samsung driver which is also
postcore_initcalllevel. Theexynos_get_pmu_regmap()andexynos_get_pmu_regmap_by_phandle()have been temporarily left to support -EPROBE_DEFER for pinctrl-samsung driver.The longer term plan to solve that probe ordering issue is to enable
fw_devlinkfor syscon dt properties so they are correctly listed as suppliers in/sys/class/devlink. I tested a PoC patch (see below) forfw_devlinkand that seemed to work fine. Oncefw_devlinksupports syscon I believeexynos_get_pmu_regmap_by_phandle()api could be removed. The main issue currently withfw_devlinksyscon support is the wide diversity of dt property naming currently in use. That was discussed previously here [3]1248a1256,1257
Quoted 2 lines
DEFINE_SUFFIX_PROP(syscon_phandle, "syscon-phandle", NULL)DEFINE_SUFFIX_PROP(pmu_syscon, "pmu-syscon", NULL)1358a1368,1369
Quoted 2 lines
{ .parse_prop =
parse_syscon_phandle, },
{ .parse_prop =parse_pmu_syscon, },Note one previous concern from Saravana about syscon potentially probing before exynos-pmu driver and it relying on
drivers/Makefileordering. I tested this and even if mfd is listed before soc indrivers/Makefileexynos-pmu always probes first due to syscon driver not setting a .of_match_table entry.Once the syscon and exynos-pmu patchs are queued I will send patches for watchdog and ufs phy drivers to switch back to
syscon_regmap_lookup_by_phandle()Many thanks,
Peter.
[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/T/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/all/CAGETcx-CCpaV7R0O0HpDpoX6KxQBuJiMmKdWA8nDE-5Qj2Sa7g@mail.gmail.com/Changes since v2:
- Move allocation outside spinlock area (Arnd)
Link to v2:
- https://lore.kernel.org/linux-arm-kernel/[email protected]/Changes since v1:
- Collect by tags
- Keep syscon lock held for check and adding entry (Krzysztof)
- passpmu_npnot np tosyscon_node_to_regmap()(William)Link to v1:
- https://lore.kernel.org/linux-arm-kernel/[email protected]/
Quoted 8 lines
Peter Griffin (2):
mfd: syscon: addof_syscon_register_regmap()API
soc: samsung: exynos-pmu: update to useof_syscon_register_regmap()drivers/mfd/syscon.c | 48 ++++++++++++++++++++++++++++++++ drivers/soc/samsung/exynos-pmu.c | 38 ++++++++++--------------- include/linux/mfd/syscon.h | 8 ++++++ 3 files changed, 70 insertions(+), 24 deletions(-)
Applied and submitted for build testing.
If all is good, I'll send out a PR for the other maintainer(s).
Note to self: ib-mfd-soc-samsung-6.11
Signature · 1 line
Lee Jones [李琼斯]
Lee Jones
maintainer[GIT PULL] Immutable branch between MFD and SoC Samsung due for the v6.11 merge window
In reply to Peter GriffinEnjoy!
The following changes since commit 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0:
Linux 6.10-rc1 (2024-05-26 15:20:12 -0700)
are available in the Git repository at:
ssh://[email protected]/pub/scm/linux/kernel/git/lee/mfd.git tags/ib-mfd-soc-samsung-v6.11
for you to fetch changes up to 35d6b98c625867209bc47df99cf03edf4280799f:
soc: samsung: exynos-pmu: update to use of_syscon_register_regmap() (2024-06-26 16:47:05 +0100)
----------------------------------------------------------------
Immutable branch between MFD and SoC Samsung due for the v6.11 merge window
----------------------------------------------------------------
Peter Griffin (2):
mfd: syscon: Add of_syscon_register_regmap() API
soc: samsung: exynos-pmu: update to use of_syscon_register_regmap()
drivers/mfd/syscon.c | 48 ++++++++++++++++++++++++++++++++++++++++ drivers/soc/samsung/exynos-pmu.c | 38 ++++++++++++------------------- include/linux/mfd/syscon.h | 8 +++++++ 3 files changed, 70 insertions(+), 24 deletions(-)
Signature · 1 line
Lee Jones [李琼斯]