Add new physical regmap bus support
Baolin Wang
maintainerv4 cover Add new physical regmap bus support
The Spreadtrum platform uses a special set/clear method to update registers' bits, thus this patch set exports a weak function to allow to register a physical regmap bus to support this feature instead of using the MMIO bus, which is not a physical regmap bus.
Any comments are welcome. Thanks.
Changes from v3:
- Remove vendor specific support from the syscon driver, and export a weak function to support physical regmap bus.
Changes from v2:
- Fix building errors without enabling CONFIG_ARCH_SPRD.
Changes from v1:
- Add WARN_ONCE() for seting bits and clearing bits at the same time.
- Remove the Spreadtrum SoC syscon driver, instead moving the regmap_bus instance into syscon.c driver.
Changes from RFC v2:
- Drop regmap change, which was applied by Mark.
- Add more information about how to use set/clear.
- Add checking to ensure the platform is compatible with using a new physical regmap bus.
Changes from RFC v1:
- Add new helper to registers a physical regmap bus instead of using the MMIO bus.
Baolin Wang (2):
mfd: syscon: Support physical regmap bus
soc: sprd: Add Spreadtrum special bits updating support
drivers/mfd/syscon.c | 9 +++- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/sprd/Kconfig | 16 +++++++ drivers/soc/sprd/Makefile | 2 + drivers/soc/sprd/sprd_syscon.c | 86 ++++++++++++++++++++++++++++++++++ include/linux/mfd/syscon.h | 11 +++++ 7 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/sprd/Kconfig create mode 100644 drivers/soc/sprd/Makefile create mode 100644 drivers/soc/sprd/sprd_syscon.c
Signature · 1 line
2.17.1
Baolin Wang
maintainerPATCH v4 1/2 mfd: syscon: Support physical regmap bus
Some platforms such as Spreadtrum platform, define a special method to update bits of the registers instead of reading and writing, which means we should use a physical regmap bus to define the reg_update_bits() operation instead of the MMIO regmap bus.
Thus add a a __weak function for the syscon driver to allow to register a physical regmap bus to support this new requirement.
--- drivers/mfd/syscon.c | 9 ++++++++- include/linux/mfd/syscon.h | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-)
drivers/mfd/syscon.c +8 -1
@@ -40,6 +40,13 @@ static const struct regmap_config syscon_regmap_config = { .reg_stride = 4, }; +struct regmap *__weak syscon_regmap_init (struct device_node *np, +void __iomem *base, +struct regmap_config *syscon_config) +{ +return regmap_init_mmio (NULL , base, syscon_config); +} +static struct syscon *of_syscon_register (struct device_node *np,bool check_clk) {struct clk *clk;
@@ -106,7 +113,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) syscon_config.val_bits = reg_io_width *8 ; syscon_config.max_register =resource_size (&res) - reg_io_width; - regmap =regmap_init_mmio (NULL , base, &syscon_config); + regmap =syscon_regmap_init (np, base, &syscon_config);if (IS_ERR (regmap)) {pr_err ("regmap init failed\n" ); ret =PTR_ERR (regmap);
include/linux/mfd/syscon.h +11 -0
@@ -13,6 +13,7 @@#include <linux/err.h> #include <linux/errno.h> +#include <linux/regmap.h> struct device_node ;
@@ -28,6 +29,9 @@ extern struct regmap *syscon_regmap_lookup_by_phandle_args(const char *property, int arg_count, unsigned int *out_args); +extern struct regmap *syscon_regmap_init (struct device_node *np, +void __iomem *base, +struct regmap_config *syscon_config);#else static inline struct regmap *device_node_to_regmap (struct device_node *np) {
@@ -59,6 +63,13 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle_args( {return ERR_PTR (-ENOTSUPP ); } + +static inline struct regmap *syscon_regmap_init (struct device_node *np, +void __iomem *base, +struct regmap_config *syscon_config) +{ +return ERR_PTR (-ENOTSUPP ); +}#endif #endif /* __LINUX_MFD_SYSCON_H__ */
Signature · 1 line
2.17.1
Orson Zhai
maintainerRe: [PATCH v4 1/2] mfd: syscon: Support physical regmap bus
Quoted 7 lines · Baolin Wang
Some platforms such as Spreadtrum platform, define a special method to update bits of the registers instead of reading and writing, which means we should use a physical regmap bus to define the
reg_update_bits()operation instead of the MMIO regmap bus.Thus add a a
__weakfunction for the syscon driver to allow to register
Typo -- duplicated "a".
It seems to be a better idea than before.
-Orson
Quoted 74 lines
a physical regmap bus to support this new requirement.
Signed-off-by Baolin Wang <[email protected]>--- drivers/mfd/syscon.c | 9 ++++++++- include/linux/mfd/syscon.h | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-)drivers/mfd/syscon.c +8
-1@@ -40,6 +40,13 @@ static const struct regmap_config syscon_regmap_config = { .reg_stride = 4, }; +struct regmap *__weak syscon_regmap_init (struct device_node *np, +void __iomem *base, +struct regmap_config *syscon_config) +{ +return regmap_init_mmio (NULL , base, syscon_config); +} +static struct syscon *of_syscon_register (struct device_node *np,bool check_clk) {struct clk *clk;@@ -106,7 +113,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) syscon_config.val_bits = reg_io_width *8 ; syscon_config.max_register =resource_size (&res) - reg_io_width; - regmap =regmap_init_mmio (NULL , base, &syscon_config); + regmap =syscon_regmap_init (np, base, &syscon_config);if (IS_ERR (regmap)) {pr_err ("regmap init failed\n" ); ret =PTR_ERR (regmap);include/linux/mfd/syscon.h +11
-1@@ -13,6 +13,7 @@#include <linux/err.h> #include <linux/errno.h> +#include <linux/regmap.h> struct device_node ;@@ -28,6 +29,9 @@ extern struct regmap *syscon_regmap_lookup_by_phandle_args(const char *property, int arg_count, unsigned int *out_args); +extern struct regmap *syscon_regmap_init (struct device_node *np, +void __iomem *base, +struct regmap_config *syscon_config);#else static inline struct regmap *device_node_to_regmap (struct device_node *np) {@@ -59,6 +63,13 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle_args( {return ERR_PTR (-ENOTSUPP ); } + +static inline struct regmap *syscon_regmap_init (struct device_node *np, +void __iomem *base, +struct regmap_config *syscon_config) +{ +return ERR_PTR (-ENOTSUPP ); +}#endif #endif /* __LINUX_MFD_SYSCON_H__ */ --2.17.1
Baolin Wang
maintainerRe: [PATCH v4 1/2] mfd: syscon: Support physical regmap bus
Quoted 11 lines · Orson Zhai
Quoted 7 lines · Baolin Wang
Some platforms such as Spreadtrum platform, define a special method to update bits of the registers instead of reading and writing, which means we should use a physical regmap bus to define the
reg_update_bits()operation instead of the MMIO regmap bus.Thus add a a
__weakfunction for the syscon driver to allow to registerTypo -- duplicated "a".
Ah, right, will fix.
Quoted 2 lines
It seems to be a better idea than before.
Let's see Arnd and Lee's opinion.
Quoted 77 lines
-Orson
Quoted 74 lines
a physical regmap bus to support this new requirement.
Signed-off-by Baolin Wang <[email protected]>--- drivers/mfd/syscon.c | 9 ++++++++- include/linux/mfd/syscon.h | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-)drivers/mfd/syscon.c +8
-1@@ -40,6 +40,13 @@ static const struct regmap_config syscon_regmap_config = { .reg_stride = 4, }; +struct regmap *__weak syscon_regmap_init (struct device_node *np, +void __iomem *base, +struct regmap_config *syscon_config) +{ +return regmap_init_mmio (NULL , base, syscon_config); +} +static struct syscon *of_syscon_register (struct device_node *np,bool check_clk) {struct clk *clk;@@ -106,7 +113,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) syscon_config.val_bits = reg_io_width *8 ; syscon_config.max_register =resource_size (&res) - reg_io_width; - regmap =regmap_init_mmio (NULL , base, &syscon_config); + regmap =syscon_regmap_init (np, base, &syscon_config);if (IS_ERR (regmap)) {pr_err ("regmap init failed\n" ); ret =PTR_ERR (regmap);include/linux/mfd/syscon.h +11
-1@@ -13,6 +13,7 @@#include <linux/err.h> #include <linux/errno.h> +#include <linux/regmap.h> struct device_node ;@@ -28,6 +29,9 @@ extern struct regmap *syscon_regmap_lookup_by_phandle_args(const char *property, int arg_count, unsigned int *out_args); +extern struct regmap *syscon_regmap_init (struct device_node *np, +void __iomem *base, +struct regmap_config *syscon_config);#else static inline struct regmap *device_node_to_regmap (struct device_node *np) {@@ -59,6 +63,13 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle_args( {return ERR_PTR (-ENOTSUPP ); } + +static inline struct regmap *syscon_regmap_init (struct device_node *np, +void __iomem *base, +struct regmap_config *syscon_config) +{ +return ERR_PTR (-ENOTSUPP ); +}#endif #endif /* __LINUX_MFD_SYSCON_H__ */ --2.17.1
Signature · 1 line
Baolin Wang
Arnd Bergmann
maintainerRe: [PATCH v4 1/2] mfd: syscon: Support physical regmap bus
In reply to Baolin WangQuoted 11 lines · Baolin Wang
Some platforms such as Spreadtrum platform, define a special method to update bits of the registers instead of reading and writing, which means we should use a physical regmap bus to define the
reg_update_bits()operation instead of the MMIO regmap bus.Thus add a a
__weakfunction for the syscon driver to allow to register a physical regmap bus to support this new requirement.};
drivers/mfd/syscon.c static const struct regmap_config syscon_regmap_config = { · line 49
Quoted 7 lines
drivers/mfd/syscon.c +7
-0+struct regmap *__weak syscon_regmap_init (struct device_node *np, +void __iomem *base, +struct regmap_config *syscon_config) +{ +return regmap_init_mmio (NULL , base, syscon_config); +} +
Sorry, I don't think the __weak function is going to help here. I'm not sure whether it actually does what you want when both syscon and sprd_syscon are loadable modules (I would guess not), but it clearly won't work when syscon is built-in and sprd_syscon is a module, and even if the module loader knows how to resolve __weak symbols, I would not want to rely on module load ordering to make it behave the right way.
Arnd
Orson Zhai
maintainerRe: [PATCH v4 1/2] mfd: syscon: Support physical regmap bus
Quoted 13 lines · Arnd Bergmann
Quoted 11 lines · Baolin Wang
Some platforms such as Spreadtrum platform, define a special method to update bits of the registers instead of reading and writing, which means we should use a physical regmap bus to define the
reg_update_bits()operation instead of the MMIO regmap bus.Thus add a a
__weakfunction for the syscon driver to allow to register a physical regmap bus to support this new requirement.};
Quoted 13 lines
drivers/mfd/syscon.c static const struct regmap_config syscon_regmap_config = { · line 49
Quoted 7 lines
drivers/mfd/syscon.c +7
-0+struct regmap *__weak syscon_regmap_init (struct device_node *np, +void __iomem *base, +struct regmap_config *syscon_config) +{ +return regmap_init_mmio (NULL , base, syscon_config); +} +Sorry, I don't think the
__weakfunction is going to help here. I'm not sure whether it actually does what you want when both syscon andsprd_sysconare loadable modules (I would guess not), but it clearly won't work when syscon is built-in andsprd_sysconis a module, and even if the module loader knows how to resolve__weaksymbols,
I happened to see module.c last week. It seems there's some code to handle weak symbols by checking about STB_WEAK. But it is not in this case. When syscon.c is built-in and sprd_syscon is module, this would not work because the__weak one has been built into kernel already. Maybe live patch feature may work it out.
But it seems over expensive to do things like this.
Quoted 2 lines
I would not want to rely on module load ordering to make it behave the right way.
Agree. All other sprd modules would must be loaded behind sprd_syscon and this will not be
handled by modprobe.
Thanks to pointing out this.
Best,
Orson
Quoted 2 lines
Arnd
Baolin Wang
maintainerPATCH v4 2/2 soc: sprd: Add Spreadtrum special bits updating support
In reply to Baolin WangThe spreadtrum platform uses a special set/clear method to update registers' bits, which can remove the race of updating the global registers between the multiple subsystems. Thus we can register a physical regmap bus into syscon core to support this.
--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/sprd/Kconfig | 16 +++++++ drivers/soc/sprd/Makefile | 2 + drivers/soc/sprd/sprd_syscon.c | 86 ++++++++++++++++++++++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 drivers/soc/sprd/Kconfig create mode 100644 drivers/soc/sprd/Makefile create mode 100644 drivers/soc/sprd/sprd_syscon.c
drivers/soc/Kconfig +1 -0
@@ -23,5 +23,6 @@ source "drivers/soc/versatile/Kconfig" source "drivers/soc/xilinx/Kconfig" source "drivers/soc/zte/Kconfig" source "drivers/soc/kendryte/Kconfig" +source "drivers/soc/sprd/Kconfig" endmenu
drivers/soc/Makefile +1 -0
@@ -29,3 +29,4 @@ obj-$(CONFIG_PLAT_VERSATILE) += versatile/ obj-y += xilinx/ obj-$(CONFIG_ARCH_ZX) += zte/ obj-$(CONFIG_SOC_KENDRYTE) += kendryte/ +obj-$(CONFIG_ARCH_SPRD) += sprd/
drivers/soc/sprd/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# SPRD SoC drivers +# + +menu "Spreadtrum SoC drivers" + depends on ARCH_SPRD || COMPILE_TEST + +config SPRD_SYSCON + tristate "Spreadtrum syscon support" + depends on ARCH_SPRD || COMPILE_TEST + help + Say yes here to add support for the Spreadtrum syscon driver, + which is used to implement the atomic method of bits updating. + +endmenu
drivers/soc/sprd/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_SPRD_SYSCON) += sprd_syscon.o
drivers/soc/sprd/sprd_syscon.c new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.17.1