Skip to contentSkip to conversation

regmap: Separate memory-based operations

PATCH New Alexey Brodkin 2 participants 6 messages May 24, 2018 – May 30, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regmap: Separate memory-based operations

One of important features of regmap [at least in Linux kernel] is an ability to seamlessly communicate to devices connected via different buses like: MMIO, SPI, I2C and many others.

Current implementation in U-Boot only supports memory-mapped registers which is a vere valid case but we'll need more in the future.

This change paves the way for support of other buses. Still all existing users of regmap in U-Boot shouldn't be affected because for now we don't change API which might be required once we start adding support of more complicated cases like 8/16/32/64-bit accessors, big- and little-endian flavours etc.

It was inspired by discussion [1] of addition of even more accessors to a standard 16550 UART.

[1] https://lists.denx.de/pipermail/u-boot/2018-March/322322.html

---
 drivers/core/Makefile                   |  2 +-
 drivers/core/{regmap.c => regmap-mem.c} | 79 ++++++-----------------
 drivers/core/regmap.c                   | 85 +------------------------
 include/regmap.h                        |  9 +++
 4 files changed, 31 insertions(+), 144 deletions(-)
 copy drivers/core/{regmap.c => regmap-mem.c} (60%)
drivers/core/Makefile +1 -1
index a5039c5bd311..ce9b32600e97 100644
@@ -9,7 +9,7 @@ obj-$(CONFIG_DEVRES) += devres.o
 obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE)	+= device-remove.o
 obj-$(CONFIG_$(SPL_)SIMPLE_BUS)	+= simple-bus.o
 obj-$(CONFIG_DM)	+= dump.o
-obj-$(CONFIG_$(SPL_TPL_)REGMAP)	+= regmap.o
+obj-$(CONFIG_$(SPL_TPL_)REGMAP)	+= regmap.o regmap-mem.o
 obj-$(CONFIG_$(SPL_TPL_)SYSCON)	+= syscon-uclass.o
 obj-$(CONFIG_OF_LIVE) += of_access.o of_addr.o
 ifndef CONFIG_DM_DEV_READ_INLINE
drivers/core/regmap-mem.c renamed from drivers/core/regmap.c +18 -61

113 lines not on this page · raw message

drivers/core/regmap.c +3 -82

105 lines not on this page · raw message

include/regmap.h +9 -0
index 493a5d8eff84..f01c5733afac 100644
@@ -31,6 +31,8 @@ struct regmap {
 	phys_addr_t base;
 	int range_count;
 	struct regmap_range *range, base_range;
+	int (*reg_read)(struct regmap *map, uint reg, uint *val);
+	int (*reg_write)(struct regmap *map, uint reg, uint val);
 };
 
 /*
@@ -80,6 +82,13 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
  */
 void *regmap_get_range(struct regmap *map, unsigned int range_num);
 
+/**
+ * regmap_alloc_count() - Allocate specified amount of regmap ranges
+ *
+ * @count:	Amount of regmap ranges to allocate
+ */
+struct regmap *regmap_alloc_count(int count);
+
 /**
  * regmap_uninit() - free a previously inited regmap
  */
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/1 regmap: Separate memory-based operations

Hi Alexey,

Quoted 20 lines · Alexey Brodkin

One of important features of regmap [at least in Linux kernel] is an ability to seamlessly communicate to devices connected via different buses like: MMIO, SPI, I2C and many others.

Current implementation in U-Boot only supports memory-mapped registers which is a vere valid case but we'll need more in the future.

This change paves the way for support of other buses. Still all existing users of regmap in U-Boot shouldn't be affected because for now we don't change API which might be required once we start adding support of more complicated cases like 8/16/32/64-bit accessors, big- and little-endian flavours etc.

It was inspired by discussion [1] of addition of even more accessors to a standard 16550 UART.

[1] https://lists.denx.de/pipermail/u-boot/2018-March/322322.html

Quoted 8 lines
---
 drivers/core/Makefile                   |  2 +-
 drivers/core/{regmap.c => regmap-mem.c} | 79 ++++++-----------------
 drivers/core/regmap.c                   | 85 +------------------------
 include/regmap.h                        |  9 +++
 4 files changed, 31 insertions(+), 144 deletions(-)
 copy drivers/core/{regmap.c => regmap-mem.c} (60%)

Are there any changes needed to the regmap test with this?

[..]

include/regmap.h struct regmap { · line 35

Quoted 10 lines
include/regmap.h +2 -0
index 493a5d8eff84..f01c5733afac 100644
@@ -31,6 +31,8 @@ struct regmap {
        phys_addr_t base;
        int range_count;
        struct regmap_range *range, base_range;
+       int (*reg_read)(struct regmap *map, uint reg, uint *val);
+       int (*reg_write)(struct regmap *map, uint reg, uint val);

Can we use driver model for these somehow? E.g. we could create a UCLASS_SIMPLE_REG driver for each of memory, i2c, SPI, etc.

When we want to use a particular I2C bus via regmap, we could bind the I2C -> regmap driver as a child of the I2C bus driver.

Regards,
Simon

#2 lore raw

PATCH 1/1 regmap: Separate memory-based operations

Hi Simon,

Quoted 33 lines · Simon Glass

Hi Alexey,

Quoted 21 lines · Alexey Brodkin

One of important features of regmap [at least in Linux kernel] is an ability to seamlessly communicate to devices connected via different buses like: MMIO, SPI, I2C and many others.

Current implementation in U-Boot only supports memory-mapped registers which is a vere valid case but we'll need more in the future.

This change paves the way for support of other buses. Still all existing users of regmap in U-Boot shouldn't be affected because for now we don't change API which might be required once we start adding support of more complicated cases like 8/16/32/64-bit accessors, big- and little-endian flavours etc.

It was inspired by discussion [1] of addition of even more accessors to a standard 16550 UART.

[1] https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.denx.de_pipermail_u-2Dboot_2018-2DMarch_322322.html&d=DwIBaQ&c=DPL6_X_6JkXFx7AXWqB0
tg&r=lqdeeSSEes0GFDDl656eViXO7breS55ytWkhpk5R81I&m=JMITUQeA5TvqyeIBTH0jtI2TOsSfOS-0qPz4kntF5Hc&s=yadG7Ir9EqQaMUpUychW3TY3B7acDOog8IQYDKvOI-8&e=

Quoted 8 lines
---
 drivers/core/Makefile                   |  2 +-
 drivers/core/{regmap.c => regmap-mem.c} | 79 ++++++-----------------
 drivers/core/regmap.c                   | 85 +------------------------
 include/regmap.h                        |  9 +++
 4 files changed, 31 insertions(+), 144 deletions(-)
 copy drivers/core/{regmap.c => regmap-mem.c} (60%)
Quoted 1 line

Are there any changes needed to the regmap test with this?

Given this change doesn't touch API I'm not sure what can we test more than it's currently done. Any thoughts?

Quoted 15 lines

[..]

include/regmap.h struct regmap { · line 35

Quoted 10 lines
include/regmap.h +2 -0
index 493a5d8eff84..f01c5733afac 100644
@@ -31,6 +31,8 @@ struct regmap {
        phys_addr_t base;
        int range_count;
        struct regmap_range *range, base_range;
+       int (*reg_read)(struct regmap *map, uint reg, uint *val);
+       int (*reg_write)(struct regmap *map, uint reg, uint val);

Can we use driver model for these somehow? E.g. we could create a UCLASS_SIMPLE_REG driver for each of memory, i2c, SPI, etc.

Probably we can do it here in U-Boot.
But at least in Linux kernel I see users of regmap (i.e. particular drivers) initialize required regmap instance "manually", see for example:
https://elixir.bootlin.com/linux/latest/source/drivers/media/dvb-frontends/af9033.c#L1105

Quoted 2 lines

When we want to use a particular I2C bus via regmap, we could bind the I2C -> regmap driver as a child of the I2C bus driver.

I guess that will require us to do corresponding changes in Device Tree descriptions, right? And that will deviate those .dts-es from their kernel counterparts [if they exist for a particular board].

-Alexey

#3 lore raw

PATCH 1/1 regmap: Separate memory-based operations

Hi Alexey,

Quoted 62 lines · Alexey Brodkin

Hi Simon,

Quoted 33 lines · Simon Glass

Hi Alexey,

Quoted 21 lines · Alexey Brodkin

One of important features of regmap [at least in Linux kernel] is an ability to seamlessly communicate to devices connected via different buses like: MMIO, SPI, I2C and many others.

Current implementation in U-Boot only supports memory-mapped registers which is a vere valid case but we'll need more in the future.

This change paves the way for support of other buses. Still all existing users of regmap in U-Boot shouldn't be affected because for now we don't change API which might be required once we start adding support of more complicated cases like 8/16/32/64-bit accessors, big- and little-endian flavours etc.

It was inspired by discussion [1] of addition of even more accessors to a standard 16550 UART.

[1] https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.denx.de_pipermail_u-2Dboot_2018-2DMarch_322322.html&d=DwIBaQ&c=DPL6_X_6JkXFx7AXWqB0
tg&r=lqdeeSSEes0GFDDl656eViXO7breS55ytWkhpk5R81I&m=JMITUQeA5TvqyeIBTH0jtI2TOsSfOS-0qPz4kntF5Hc&s=yadG7Ir9EqQaMUpUychW3TY3B7acDOog8IQYDKvOI-8&e=

Quoted 8 lines
---
 drivers/core/Makefile                   |  2 +-
 drivers/core/{regmap.c => regmap-mem.c} | 79 ++++++-----------------
 drivers/core/regmap.c                   | 85 +------------------------
 include/regmap.h                        |  9 +++
 4 files changed, 31 insertions(+), 144 deletions(-)
 copy drivers/core/{regmap.c => regmap-mem.c} (60%)
Quoted 1 line

Are there any changes needed to the regmap test with this?

Given this change doesn't touch API I'm not sure what can we test more than it's currently done. Any thoughts?

Quoted 15 lines

[..]

include/regmap.h struct regmap { · line 35

Quoted 10 lines
include/regmap.h +2 -0
index 493a5d8eff84..f01c5733afac 100644
@@ -31,6 +31,8 @@ struct regmap {
        phys_addr_t base;
        int range_count;
        struct regmap_range *range, base_range;
+       int (*reg_read)(struct regmap *map, uint reg, uint *val);
+       int (*reg_write)(struct regmap *map, uint reg, uint val);

Can we use driver model for these somehow? E.g. we could create a UCLASS_SIMPLE_REG driver for each of memory, i2c, SPI, etc.

Probably we can do it here in U-Boot.
But at least in Linux kernel I see users of regmap (i.e. particular drivers) initialize required regmap instance "manually", see for example:
https://elixir.bootlin.com/linux/latest/source/drivers/media/dvb-frontends/af9033.c#L1105

Quoted 6 lines
Quoted 2 lines

When we want to use a particular I2C bus via regmap, we could bind the I2C -> regmap driver as a child of the I2C bus driver.

I guess that will require us to do corresponding changes in Device Tree descriptions, right? And that will deviate those .dts-es from their kernel counterparts [if they exist for a particular board].

Actually I don't think so. You can have a helper function that you call to bind the regmap to an I2C device, for example. That can be called from code, without needing any DT changes.

My objection is mostly to using function pointers to call what look like driver functions. The design of DM in U-Boot is supposed to support child drivers for exactly this purpose. So we should try to use it, unless we hit some terrible design flaw.

Regards,
Simon

#4 lore raw

PATCH 1/1 regmap: Separate memory-based operations

Hi Simon,

Quoted 7 lines · Simon Glass

Hi Alexey,

Quoted 4 lines · Alexey Brodkin

Hi Simon,

Quoted 1 line · Simon Glass

Hi Alexey,

[snip]

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

When we want to use a particular I2C bus via regmap, we could bind the I2C -> regmap driver as a child of the I2C bus driver.

I guess that will require us to do corresponding changes in Device Tree descriptions, right? And that will deviate those .dts-es from their kernel counterparts [if they exist for a particular board].

Actually I don't think so. You can have a helper function that you call to bind the regmap to an I2C device, for example. That can be called from code, without needing any DT changes.

So this helper function will be regmap_init_i2c(), right?

Quoted 4 lines

My objection is mostly to using function pointers to call what look like driver functions. The design of DM in U-Boot is supposed to support child drivers for exactly this purpose. So we should try to use it, unless we hit some terrible design flaw.

Ok that makes sense. As you proposed we'll have new UCLASS like UCLASS_SIMPLE_REG and within that class we'll have drivers that access registers via memory, i2c, spi etc... that's quite clear.

But what is not very obvious for me is that part about binding with "master" devices. Could you please sketch something so I may get a better picture?

-Alexey

#5 lore raw

PATCH 1/1 regmap: Separate memory-based operations

Hi Alexey,

Quoted 31 lines · Alexey Brodkin

Hi Simon,

Quoted 7 lines · Simon Glass

Hi Alexey,

Quoted 4 lines · Alexey Brodkin

Hi Simon,

Quoted 1 line · Simon Glass

Hi Alexey,

[snip]

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

When we want to use a particular I2C bus via regmap, we could bind the I2C -> regmap driver as a child of the I2C bus driver.

I guess that will require us to do corresponding changes in Device Tree descriptions, right? And that will deviate those .dts-es from their kernel counterparts [if they exist for a particular board].

Actually I don't think so. You can have a helper function that you call to bind the regmap to an I2C device, for example. That can be called from code, without needing any DT changes.

So this helper function will be regmap_init_i2c(), right?

Quoted 4 lines

My objection is mostly to using function pointers to call what look like driver functions. The design of DM in U-Boot is supposed to support child drivers for exactly this purpose. So we should try to use it, unless we hit some terrible design flaw.

Quoted 7 lines

Ok that makes sense. As you proposed we'll have new UCLASS like UCLASS_SIMPLE_REG and within that class we'll have drivers that access registers via memory, i2c, spi etc... that's quite clear.

But what is not very obvious for me is that part about binding with "master" devices. Could you please sketch something so I may get a better picture?

Yes that sounds right. Basically this interface defines the operations in your UCLASS_SIMPLE_REG uclass:

+ int (*reg_read)(struct regmap *map, uint reg, uint *val);
+ int (*reg_write)(struct regmap *map, uint reg, uint val);

Then you have different drivers that implement that uclass as you say (i2c, spi).

The I2C simple_reg driver will require an I2C device to work with. This can be its parent device. To bind the device you'll need to call a function like:

int simple_reg_i2c_bind(struct udevice *i2c_dev, struct udevice **devp)

which calls device_bind(), or similar, to bind a new device as a child of i2c_dev, with uclass UCLASS_SIMPLE_REG. Then the device can be probed,

The I2C simple_reg driver can implement the reg_read() method by calling dm_i2c_read() on its parent.

You can put simple_reg_i2c_bind() in the regmap code perhaps, or maybe there is a better place for it.

You should make sure there is a sandbox test which creates a device and checks that it can read and write a few registers.

Does that explain it?

Regards,
Simon