Add new reg_update_bits() support
Subsystems (5)
Baolin Wang
maintainercover Add new reg_update_bits() support
The Spreadtrum platform uses a special set/clear method to update registers' bits, thus this patch set introduces a new reg_update_bits() callback, as well as adding a helper in syscon driver to support this feature.
Any comments are welcome. Thanks.
Baolin Wang (3):
mfd: syscon: Add reg_update_bits() callback support
regmap: Add reg_update_bits() support
soc: sprd: Add Spreadtrum special bits updating support
drivers/base/regmap/regmap-mmio.c | 29 +++++++++++++++++++++- drivers/base/regmap/regmap.c | 1 + drivers/mfd/syscon.c | 10 ++++++++ drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/sprd/Kconfig | 16 ++++++++++++ drivers/soc/sprd/Makefile | 2 ++ drivers/soc/sprd/sprd_syscon.c | 51 +++++++++++++++++++++++++++++++++++++++ include/linux/mfd/syscon.h | 8 ++++++ include/linux/regmap.h | 4 +++ 10 files changed, 122 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
1.9.1
Baolin Wang
maintainerRFC PATCH 1/3 mfd: syscon: Add reg_update_bits() callback support
Some platforms such as Spreadtrum platform, define a special method to update bits of the registers instead of reading and writing, thus add a new reg_update_bits() callback for struct regmap_config and a helper for syscon driver to support this new feature.
--- drivers/mfd/syscon.c | 10 ++++++++++ include/linux/mfd/syscon.h | 8 ++++++++ include/linux/regmap.h | 4 ++++ 3 files changed, 22 insertions(+)
drivers/mfd/syscon.c +10 -0
@@ -34,6 +34,8 @@ struct syscon {struct list_head list; }; +static regmap_hw_reg_update_bits reg_update_bits; +static const struct regmap_config syscon_regmap_config = { .reg_bits =32 , .val_bits =32 ,
@@ -105,6 +107,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) syscon_config.reg_stride = reg_io_width; syscon_config.val_bits = reg_io_width *8 ; syscon_config.max_register =resource_size (&res) - reg_io_width; + syscon_config.reg_update_bits = reg_update_bits; regmap =regmap_init_mmio (NULL , base, &syscon_config);if (IS_ERR (regmap)) {
@@ -172,6 +175,13 @@ static struct regmap *device_node_get_regmap(struct device_node *np,return syscon->regmap; } +void syscon_register_reg_update_bits (regmap_hw_reg_update_bits hw_reg_update_bits) +{ +if (hw_reg_update_bits) + reg_update_bits = hw_reg_update_bits; +} +EXPORT_SYMBOL_GPL (syscon_register_reg_update_bits); +struct regmap *device_node_to_regmap (struct device_node *np) {return device_node_get_regmap (np, false);
include/linux/mfd/syscon.h +8 -0
@@ -13,6 +13,7 @@#include <linux/err.h> #include <linux/errno.h> +#include <linux/regmap.h> struct device_node ;
@@ -28,6 +29,8 @@ extern struct regmap *syscon_regmap_lookup_by_phandle_args(const char *property, int arg_count, unsigned int *out_args); +extern void +syscon_register_reg_update_bits (regmap_hw_reg_update_bits hw_reg_update_bits);#else static inline struct regmap *device_node_to_regmap (struct device_node *np) {
@@ -59,6 +62,11 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle_args( {return ERR_PTR (-ENOTSUPP ); } + +static inline void +syscon_register_reg_update_bits (regmap_hw_reg_update_bits hw_reg_update_bits) +{ +}#endif #endif /* __LINUX_MFD_SYSCON_H__ */
include/linux/regmap.h +4 -0
@@ -340,6 +340,8 @@ struct regmap_access_table {* read operation on a bus such as SPI, I2C, etc. Most of the * devices do not need this. * @reg_write: Same as above for writing. +* @reg_update_bits: Optional, should only be provided for devices whose update +* operation cannot be represented as read and write. * @fast_io: Register IO is fast. Use a spinlock instead of a mutex * to perform locking. This field is ignored if custom lock/unlock * functions are used (see fields lock/unlock of struct regmap_config).
@@ -416,6 +418,8 @@ struct regmap_config {int (*reg_read)(void *context,unsigned int reg,unsigned int *val);int (*reg_write)(void *context,unsigned int reg,unsigned int val); +int (*reg_update_bits)(void *context,unsigned int reg, +unsigned int mask,unsigned int val);bool fast_io;
Signature · 1 line
1.9.1
Mark Brown
maintainerRe: [RFC PATCH 1/3] mfd: syscon: Add reg_update_bits() callback support
Quoted 12 lines · Baolin Wang
include/linux/regmap.h +2
-0@@ -340,6 +340,8 @@ struct regmap_access_table {* read operation on a bus such as SPI, I2C, etc. Most of the * devices do not need this. * @reg_write: Same as above for writing. +* @reg_update_bits: Optional, should only be provided for devices whose update +* operation cannot be represented as read and write. * @fast_io: Register IO is fast. Use a spinlock instead of a mutex * to perform locking. This field is ignored if custom lock/unlock * functions are used (see fields lock/unlock of struct regmap_config).
include/linux/regmap.h struct regmap_config { · line 422
Quoted 5 lines
include/linux/regmap.h +2
-0@@ -416,6 +418,8 @@ struct regmap_config {int (*reg_read)(void *context,unsigned int reg,unsigned int *val);int (*reg_write)(void *context,unsigned int reg,unsigned int val); +int (*reg_update_bits)(void *context,unsigned int reg, +unsigned int mask,unsigned int val);
This is fine, we already have this operation for buses, but why is this munged in with the MFD patch?
Baolin Wang
maintainerRe: [RFC PATCH 1/3] mfd: syscon: Add reg_update_bits() callback support
Quoted 16 lines · Mark Brown
Quoted 13 lines · Baolin Wang
include/linux/regmap.h +2
-0@@ -340,6 +340,8 @@ struct regmap_access_table {* read operation on a bus such as SPI, I2C, etc. Most of the * devices do not need this. * @reg_write: Same as above for writing. +* @reg_update_bits: Optional, should only be provided for devices whose update +* operation cannot be represented as read and write. * @fast_io: Register IO is fast. Use a spinlock instead of a mutex * to perform locking. This field is ignored if custom lock/unlock * functions are used (see fields lock/unlock of struct regmap_config). @@ -416,6 +418,8 @@ struct regmap_config {
Quoted 7 lines
include/linux/regmap.h struct regmap_config { · line 422
Quoted 4 lines
include/linux/regmap.h +2
-0int (*reg_read)(void *context,unsigned int reg,unsigned int *val);int (*reg_write)(void *context,unsigned int reg,unsigned int val); +int (*reg_update_bits)(void *context,unsigned int reg, +unsigned int mask,unsigned int val);This is fine, we already have this operation for buses, but why is this munged in with the MFD patch?
Originally I want to show a example usage of the new callback, but I can spilt them into 2 patches as you suggested. Thanks.
Signature · 1 line
Baolin Wang
Mark Brown
maintainerRe: [RFC PATCH 1/3] mfd: syscon: Add reg_update_bits() callback support
Quoted 10 lines · Baolin Wang
Quoted 5 lines · Mark Brown
include/linux/regmap.h struct regmap_config { · line 422
Quoted 2 lines
include/linux/regmap.h +2
-0+int (*reg_update_bits)(void *context,unsigned int reg, +unsigned int mask,unsigned int val);This is fine, we already have this operation for buses, but why is this munged in with the MFD patch?
Originally I want to show a example usage of the new callback, but I can spilt them into 2 patches as you suggested. Thanks.
Yes, it's good to have an example user - just not as part of the same patch!
Baolin Wang
maintainerRe: [RFC PATCH 1/3] mfd: syscon: Add reg_update_bits() callback support
Quoted 7 lines · Mark Brown
Quoted 4 lines · Baolin Wang
Quoted 2 lines · Mark Brown
Quoted 2 lines
include/linux/regmap.h +2
-0+int (*reg_update_bits)(void *context,unsigned int reg, +unsigned int mask,unsigned int val);
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
This is fine, we already have this operation for buses, but why is this munged in with the MFD patch?
Originally I want to show a example usage of the new callback, but I can spilt them into 2 patches as you suggested. Thanks.
Yes, it's good to have an example user - just not as part of the same patch!
Yes, make sense.
Signature · 1 line
Baolin Wang
kbuild test robot
build botRe: [RFC PATCH 1/3] mfd: syscon: Add reg_update_bits() callback support
In reply to Baolin Wang[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…
Hi Baolin,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on ljones-mfd/for-mfd-next]
[also build test ERROR on regmap/for-next arm-soc/for-next linus/master v5.6 next-20200409] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Baolin-Wang/Add-new-reg_update_bits-support/20200409-222737 base: https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git for-mfd-next config: arm-tango4_defconfig (attached as .config) compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.3.0 make.cross ARCH=arm
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from drivers/mmc/host/sdhci-of-arasan.c:19:
>> include/linux/mfd/syscon.h:67:33: error: unknown type name 'regmap_hw_reg_update_bits'; did you mean 'regmap_field_update_bits'?
67 | syscon_register_reg_update_bits(regmap_hw_reg_update_bits hw_reg_update_bits)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
| regmap_field_update_bitsvim +67 include/linux/mfd/syscon.h
65
66 static inline void
> 67 syscon_register_reg_update_bits(regmap_hw_reg_update_bits hw_reg_update_bits)
68 {
69 }
70 #endif
71 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Baolin Wang
maintainerRFC PATCH 2/3 regmap: Add reg_update_bits() support
In reply to Baolin WangAdd reg_update_bits() support in case some platforms use a special method to update bits of registers.
--- drivers/base/regmap/regmap-mmio.c | 29 ++++++++++++++++++++++++++++- drivers/base/regmap/regmap.c | 1 + 2 files changed, 29 insertions(+), 1 deletion(-)
drivers/base/regmap/regmap-mmio.c +28 -1
@@ -24,6 +24,8 @@ struct regmap_mmio_context { unsigned int reg, unsigned int val);unsigned int (*reg_read)(struct regmap_mmio_context *ctx,unsigned int reg); +int (*reg_update_bits)(void *ctx,unsigned int reg, +unsigned int mask,unsigned int val); };static int regmap_mmio_regbits_check (size_t reg_bits)
@@ -188,6 +190,26 @@ static int regmap_mmio_read(void *context, unsigned int reg, unsigned int *val)return 0 ; } +static int regmap_mmio_update_bits (void *context,unsigned int reg, +unsigned int mask,unsigned int val) +{ +struct regmap_mmio_context *ctx = context; +int ret; + +if (!IS_ERR (ctx->clk)) { + ret =clk_enable (ctx->clk); +if (ret <0 ) +return ret; + } + + ctx->reg_update_bits (ctx->regs, reg, mask, val); + +if (!IS_ERR (ctx->clk)) +clk_disable (ctx->clk); + +return 0 ; +} +static void regmap_mmio_free_context (void *context) {struct regmap_mmio_context *ctx = context;
@@ -200,7 +222,7 @@ static void regmap_mmio_free_context(void *context)kfree (context); } -static const struct regmap_bus regmap_mmio = { +static struct regmap_bus regmap_mmio = { .fast_io = true, .reg_write = regmap_mmio_write, .reg_read = regmap_mmio_read,
@@ -239,6 +261,11 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev, ctx->val_bytes = config->val_bits /8 ; ctx->clk =ERR_PTR (-ENODEV ); +if (config->reg_update_bits) { + ctx->reg_update_bits = config->reg_update_bits; + regmap_mmio.reg_update_bits = regmap_mmio_update_bits; + } +switch (regmap_get_val_endian (dev, ®map_mmio, config)) {case REGMAP_ENDIAN_DEFAULT :case REGMAP_ENDIAN_LITTLE :
drivers/base/regmap/regmap.c +1 -0
@@ -827,6 +827,7 @@ struct regmap *__regmap_init(struct device *dev, }else if (!bus->read || !bus->write) { map->reg_read = _regmap_bus_reg_read; map->reg_write = _regmap_bus_reg_write; + map->reg_update_bits = bus->reg_update_bits; map->defer_caching = false; goto skip_format_initialization;
Signature · 1 line
1.9.1
Mark Brown
maintainerRe: [RFC PATCH 2/3] regmap: Add reg_update_bits() support
Quoted 7 lines · Baolin Wang
Add
reg_update_bits()support in case some platforms use a special method to update bits of registers.Signed-off-by Baolin Wang <[email protected]>--- drivers/base/regmap/regmap-mmio.c | 29 ++++++++++++++++++++++++++++- drivers/base/regmap/regmap.c | 1 +
MMIO devices clearly don't physically have an update_bits() operation so this should be implemented further up the stack where it applies to all buses without physical support.
Baolin Wang
maintainerRe: [RFC PATCH 2/3] regmap: Add reg_update_bits() support
Hi Mark,
Quoted 5 lines · Mark Brown
Quoted 3 lines · Baolin Wang
Add
reg_update_bits()support in case some platforms use a special method to update bits of registers.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Baolin Wang <[email protected]>--- drivers/base/regmap/regmap-mmio.c | 29 ++++++++++++++++++++++++++++- drivers/base/regmap/regmap.c | 1 +MMIO devices clearly don't physically have an
update_bits()operation so this should be implemented further up the stack where it applies to all buses without physical support.
I understood your concern. But the syscon driver need use the MMIO devices' resources (such as address mapping, clock management and so on), if move this to further up stack, I am afraid the update_bits() can not use the resources in 'struct regmap_mmio_context'. Do you have any good suggestion? Thanks.
Signature · 1 line
Baolin Wang
Mark Brown
maintainerRe: [RFC PATCH 2/3] regmap: Add reg_update_bits() support
Quoted 11 lines · Baolin Wang
Quoted 3 lines · Mark Brown
MMIO devices clearly don't physically have an
update_bits()operation so this should be implemented further up the stack where it applies to all buses without physical support.I understood your concern. But the syscon driver need use the MMIO devices' resources (such as address mapping, clock management and so on), if move this to further up stack, I am afraid the
update_bits()can not use the resources in 'structregmap_mmio_context'. Do you have any good suggestion? Thanks.
If the syscon driver needs to be peering into the regmap implementation that seems like there's a serious abstraction problem - users of the regmap shouldn't be looking at the implmentation at all. Why do you think this is needed?
Baolin Wang
maintainerRe: [RFC PATCH 2/3] regmap: Add reg_update_bits() support
Quoted 14 lines · Mark Brown
Quoted 11 lines · Baolin Wang
Quoted 3 lines · Mark Brown
MMIO devices clearly don't physically have an
update_bits()operation so this should be implemented further up the stack where it applies to all buses without physical support.I understood your concern. But the syscon driver need use the MMIO devices' resources (such as address mapping, clock management and so on), if move this to further up stack, I am afraid the
update_bits()can not use the resources in 'structregmap_mmio_context'. Do you have any good suggestion? Thanks.
Quoted 4 lines
If the syscon driver needs to be peering into the regmap implementation that seems like there's a serious abstraction problem - users of the regmap shouldn't be looking at the implmentation at all. Why do you think this is needed?
Sorry for confusing, that's not what I mean. My point is the syscon driver will call the regmap_init_mmio() to use the MMIO regmap_bus, but as you said, MMIO bus should not a physical bus, so I suppose the syscon driver should create a new phycical regmap bus for our special case, but the problem is the phycical regmap bus implementation will be similar with the MMIO bus except adding a reg_update_bits() callback, which will introduce more duplicated code. What do you think?
Signature · 1 line
Baolin Wang
Baolin Wang
maintainerRFC PATCH 3/3 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.
--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/sprd/Kconfig | 16 +++++++++++++ drivers/soc/sprd/Makefile | 2 ++ drivers/soc/sprd/sprd_syscon.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 71 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
@@ -22,5 +22,6 @@ source "drivers/soc/ux500/Kconfig" source "drivers/soc/versatile/Kconfig" source "drivers/soc/xilinx/Kconfig" source "drivers/soc/zte/Kconfig" +source "drivers/soc/sprd/Kconfig" endmenu
drivers/soc/Makefile +1 -0
@@ -28,3 +28,4 @@ obj-$(CONFIG_ARCH_U8500) += ux500/ obj-$(CONFIG_PLAT_VERSATILE) += versatile/ obj-y += xilinx/ obj-$(CONFIG_ARCH_ZX) += zte/ +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 +51 -0
51 lines not on this page · raw message
Signature · 1 line
1.9.1
Arnd Bergmann
maintainerQuoted 7 lines · Baolin Wang
The Spreadtrum platform uses a special set/clear method to update registers' bits, thus this patch set introduces a new
reg_update_bits()callback, as well as adding a helper in syscon driver to support this feature.Any comments are welcome. Thanks.
This looks like a good idea to me, both the concept and the implementation.
The one thing I'd note is that we have a similar mechanism for devices made by Sigmatel and later Freescale after they acquired them. include/linux/stmp_device.h only holds a couple of definitions, so it's much less abstract than your approach, but the idea is similar.
It would be nice in theory to move the sigmatel devices over to reg_update_bits() in theory, but this seems unlikely to actually happen, given that these are mostly obsolete drivers at this point.
Arnd
Baolin Wang
maintainerQuoted 11 lines · Arnd Bergmann
Quoted 7 lines · Baolin Wang
The Spreadtrum platform uses a special set/clear method to update registers' bits, thus this patch set introduces a new
reg_update_bits()callback, as well as adding a helper in syscon driver to support this feature.Any comments are welcome. Thanks.
This looks like a good idea to me, both the concept and the implementation.
Thanks for your quick response :)
Quoted 5 lines
The one thing I'd note is that we have a similar mechanism for devices made by Sigmatel and later Freescale after they acquired them.
include/linux/stmp_device.honly holds a couple of definitions, so it's much less abstract than your approach, but the idea is similar.
Ah, yes, sigmatel devices' idea is similar with ours.
Quoted 4 lines
It would be nice in theory to move the sigmatel devices over to
reg_update_bits()in theory, but this seems unlikely to actually happen, given that these are mostly obsolete drivers at this point.
I checked all sigmatel devices (about 10 drivers), I think there will be more work to change them to use syscon/regmap when changing to reg_update_bits(). I am afraid I can not thelp to convert them without a hardware, and as you said, some drivers are already dead. So I think it would be nice if the driver owners can help to convert these drivers, if we get a consensus about the reg_update_bits() implementation at last.
Signature · 1 line
Baolin Wang
Arnd Bergmann
maintainerQuoted 11 lines · Baolin Wang
Quoted 3 lines
It would be nice in theory to move the sigmatel devices over to
reg_update_bits()in theory, but this seems unlikely to actually happen, given that these are mostly obsolete drivers at this point.I checked all sigmatel devices (about 10 drivers), I think there will be more work to change them to use syscon/regmap when changing to
reg_update_bits(). I am afraid I can not thelp to convert them without a hardware, and as you said, some drivers are already dead. So I think it would be nice if the driver owners can help to convert these drivers, if we get a consensus about thereg_update_bits()implementation at last.
Thanks for taking a closer look. I didn't want to imply that you should fix them, just saying that it might have been nice if they had been done like this in the first place. Of course, when the drivers were written, we did not even have the regmap-mmio helpers at all.
Arnd
Baolin Wang
maintainerQuoted 15 lines · Arnd Bergmann
Quoted 11 lines · Baolin Wang
Quoted 3 lines
It would be nice in theory to move the sigmatel devices over to
reg_update_bits()in theory, but this seems unlikely to actually happen, given that these are mostly obsolete drivers at this point.I checked all sigmatel devices (about 10 drivers), I think there will be more work to change them to use syscon/regmap when changing to
reg_update_bits(). I am afraid I can not thelp to convert them without a hardware, and as you said, some drivers are already dead. So I think it would be nice if the driver owners can help to convert these drivers, if we get a consensus about thereg_update_bits()implementation at last.
Quoted 4 lines
Thanks for taking a closer look. I didn't want to imply that you should fix them, just saying that it might have been nice if they had been done like this in the first place. Of course, when the drivers were written, we did not even have the regmap-mmio helpers at all.
Make sense. Thanks.
Signature · 1 line
Baolin Wang