All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 0/4] Add Linux-compatible syscon_to_regmap API
@ 2018-04-19  3:14 Masahiro Yamada
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 1/4] regmap: clean up regmap allocation Masahiro Yamada
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Masahiro Yamada @ 2018-04-19  3:14 UTC (permalink / raw)
  To: u-boot

The current syscon in U-Boot works differently from Linux.
Therefore, DT files imported from Linux do not work for U-Boot.

The current usage of syscon in U-Boot should be discouraged because
using different DT-binding across projects is a significant problem.


Masahiro Yamada (4):
  regmap: clean up regmap allocation
  dm: ofnode: add ofnode_device_is_compatible() helper
  regmap: change regmap_init_mem() to take ofnode instead udevice
  syscon: add Linux-compatible syscon API

 arch/arm/mach-aspeed/ast2500/sdram_ast2500.c |  2 +-
 drivers/core/device.c                        |  8 +---
 drivers/core/ofnode.c                        | 11 +++++
 drivers/core/regmap.c                        | 42 ++++++------------
 drivers/core/syscon-uclass.c                 | 66 +++++++++++++++++++++++++++-
 drivers/phy/meson-gxl-usb2.c                 |  2 +-
 drivers/phy/meson-gxl-usb3.c                 |  2 +-
 drivers/phy/sti_usb_phy.c                    |  4 +-
 drivers/pinctrl/pinctrl-sti.c                |  4 +-
 drivers/ram/rockchip/dmc-rk3368.c            |  2 +-
 drivers/ram/rockchip/sdram_rk3188.c          |  2 +-
 drivers/ram/rockchip/sdram_rk322x.c          |  2 +-
 drivers/ram/rockchip/sdram_rk3288.c          |  2 +-
 drivers/ram/rockchip/sdram_rk3399.c          |  2 +-
 drivers/ram/stm32mp1/stm32mp1_ram.c          |  2 +-
 drivers/reset/reset-meson.c                  |  2 +-
 drivers/reset/sti-reset.c                    |  2 +-
 drivers/sysreset/sysreset_sti.c              |  2 +-
 drivers/usb/host/dwc3-sti-glue.c             |  2 +-
 include/dm/ofnode.h                          | 11 +++++
 include/regmap.h                             | 11 ++---
 include/syscon.h                             |  8 ++++
 test/dm/regmap.c                             | 13 +++---
 23 files changed, 136 insertions(+), 68 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v2 1/4] regmap: clean up regmap allocation
  2018-04-19  3:14 [U-Boot] [PATCH v2 0/4] Add Linux-compatible syscon_to_regmap API Masahiro Yamada
@ 2018-04-19  3:14 ` Masahiro Yamada
  2018-04-23  4:30   ` Masahiro Yamada
  2018-05-08  0:45   ` [U-Boot] [U-Boot,v2,1/4] " Tom Rini
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 2/4] dm: ofnode: add ofnode_device_is_compatible() helper Masahiro Yamada
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 14+ messages in thread
From: Masahiro Yamada @ 2018-04-19  3:14 UTC (permalink / raw)
  To: u-boot

Putting zero length array at the end of struct is a common technique
to embed arbitrary length of members.  There is no good reason to let
regmap_alloc_count() branch by "if (count <= 1)".

As far as I understood the code, regmap->base is an alias of
regmap->ranges[0].start, but it is not helpful but make the code
just ugly.

Rename regmap_alloc_count() to regmap_alloc() because the _count
suffix seems pointless.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2:
  - Fix up test and sti drivers

 drivers/core/regmap.c            | 31 +++++++++----------------------
 drivers/phy/sti_usb_phy.c        |  4 ++--
 drivers/pinctrl/pinctrl-sti.c    |  4 ++--
 drivers/reset/sti-reset.c        |  2 +-
 drivers/sysreset/sysreset_sti.c  |  2 +-
 drivers/usb/host/dwc3-sti-glue.c |  2 +-
 include/regmap.h                 |  7 ++-----
 test/dm/regmap.c                 | 13 +++++--------
 8 files changed, 23 insertions(+), 42 deletions(-)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 8a0e00f..6c3dbe9 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -18,22 +18,13 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static struct regmap *regmap_alloc_count(int count)
+static struct regmap *regmap_alloc(int count)
 {
 	struct regmap *map;
 
-	map = malloc(sizeof(struct regmap));
+	map = malloc(sizeof(*map) + sizeof(map->ranges[0]) * count);
 	if (!map)
 		return NULL;
-	if (count <= 1) {
-		map->range = &map->base_range;
-	} else {
-		map->range = malloc(count * sizeof(struct regmap_range));
-		if (!map->range) {
-			free(map);
-			return NULL;
-		}
-	}
 	map->range_count = count;
 
 	return map;
@@ -46,12 +37,11 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
 	struct regmap_range *range;
 	struct regmap *map;
 
-	map = regmap_alloc_count(count);
+	map = regmap_alloc(count);
 	if (!map)
 		return -ENOMEM;
 
-	map->base = *reg;
-	for (range = map->range; count > 0; reg += 2, range++, count--) {
+	for (range = map->ranges; count > 0; reg += 2, range++, count--) {
 		range->start = *reg;
 		range->size = reg[1];
 	}
@@ -84,11 +74,11 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp)
 	if (!count)
 		return -EINVAL;
 
-	map = regmap_alloc_count(count);
+	map = regmap_alloc(count);
 	if (!map)
 		return -ENOMEM;
 
-	for (range = map->range, index = 0; count > 0;
+	for (range = map->ranges, index = 0; count > 0;
 	     count--, range++, index++) {
 		fdt_size_t sz;
 		if (of_live_active()) {
@@ -102,7 +92,6 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp)
 			range->size = sz;
 		}
 	}
-	map->base = map->range[0].start;
 
 	*mapp = map;
 
@@ -116,15 +105,13 @@ void *regmap_get_range(struct regmap *map, unsigned int range_num)
 
 	if (range_num >= map->range_count)
 		return NULL;
-	range = &map->range[range_num];
+	range = &map->ranges[range_num];
 
 	return map_sysmem(range->start, range->size);
 }
 
 int regmap_uninit(struct regmap *map)
 {
-	if (map->range_count > 1)
-		free(map->range);
 	free(map);
 
 	return 0;
@@ -132,7 +119,7 @@ int regmap_uninit(struct regmap *map)
 
 int regmap_read(struct regmap *map, uint offset, uint *valp)
 {
-	uint32_t *ptr = map_physmem(map->base + offset, 4, MAP_NOCACHE);
+	u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE);
 
 	*valp = le32_to_cpu(readl(ptr));
 
@@ -141,7 +128,7 @@ int regmap_read(struct regmap *map, uint offset, uint *valp)
 
 int regmap_write(struct regmap *map, uint offset, uint val)
 {
-	uint32_t *ptr = map_physmem(map->base + offset, 4, MAP_NOCACHE);
+	u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE);
 
 	writel(cpu_to_le32(val), ptr);
 
diff --git a/drivers/phy/sti_usb_phy.c b/drivers/phy/sti_usb_phy.c
index 727fb8b..181a338 100644
--- a/drivers/phy/sti_usb_phy.c
+++ b/drivers/phy/sti_usb_phy.c
@@ -65,12 +65,12 @@ static int sti_usb_phy_init(struct phy *usb_phy)
 	void __iomem *reg;
 
 	/* set ctrl picophy value */
-	reg = (void __iomem *)phy->regmap->base + phy->ctrl;
+	reg = (void __iomem *)phy->regmap->ranges[0].start + phy->ctrl;
 	/* CTRL_PORT mask is 0x1f */
 	clrsetbits_le32(reg, 0x1f, STIH407_USB_PICOPHY_CTRL_PORT_CONF);
 
 	/* set ports parameters overriding */
-	reg = (void __iomem *)phy->regmap->base + phy->param;
+	reg = (void __iomem *)phy->regmap->ranges[0].start + phy->param;
 	/* PARAM_DEF mask is 0xffffffff */
 	clrsetbits_le32(reg, 0xffffffff, STIH407_USB_PICOPHY_PARAM_DEF);
 
diff --git a/drivers/pinctrl/pinctrl-sti.c b/drivers/pinctrl/pinctrl-sti.c
index a9c1495..890a7c2 100644
--- a/drivers/pinctrl/pinctrl-sti.c
+++ b/drivers/pinctrl/pinctrl-sti.c
@@ -62,7 +62,7 @@ void sti_alternate_select(struct udevice *dev, struct sti_pin_desc *pin_desc)
 	int bank = pin_desc->bank;
 	int pin = pin_desc->pin;
 
-	sysconfreg = (unsigned long *)plat->regmap->base;
+	sysconfreg = (unsigned long *)plat->regmap->ranges[0].start;
 
 	switch (bank) {
 	case 0 ... 5:		/* in "SBC Bank" */
@@ -96,7 +96,7 @@ void sti_pin_configure(struct udevice *dev, struct sti_pin_desc *pin_desc)
 	unsigned long *sysconfreg;
 	int bank = pin_desc->bank;
 
-	sysconfreg = (unsigned long *)plat->regmap->base + 40;
+	sysconfreg = (unsigned long *)plat->regmap->ranges[0].start + 40;
 
 	/*
 	 * NOTE: The PIO configuration for the PIO pins in the
diff --git a/drivers/reset/sti-reset.c b/drivers/reset/sti-reset.c
index 0fc5a28..41d7db4 100644
--- a/drivers/reset/sti-reset.c
+++ b/drivers/reset/sti-reset.c
@@ -218,7 +218,7 @@ phys_addr_t sti_reset_get_regmap(const char *compatible)
 		return -ENODEV;
 	}
 
-	return regmap->base;
+	return regmap->ranges[0].start;
 }
 
 static int sti_reset_program_hw(struct reset_ctl *reset_ctl, int assert)
diff --git a/drivers/sysreset/sysreset_sti.c b/drivers/sysreset/sysreset_sti.c
index 910f486..4fa7fd5 100644
--- a/drivers/sysreset/sysreset_sti.c
+++ b/drivers/sysreset/sysreset_sti.c
@@ -59,7 +59,7 @@ static int sti_sysreset_probe(struct udevice *dev)
 		return -ENODEV;
 	}
 
-	priv->base = regmap->base;
+	priv->base = regmap->ranges[0].start;
 
 	return 0;
 }
diff --git a/drivers/usb/host/dwc3-sti-glue.c b/drivers/usb/host/dwc3-sti-glue.c
index ce9335e..f505738 100644
--- a/drivers/usb/host/dwc3-sti-glue.c
+++ b/drivers/usb/host/dwc3-sti-glue.c
@@ -134,7 +134,7 @@ static int sti_dwc3_glue_ofdata_to_platdata(struct udevice *dev)
 		pr_err("unable to find regmap\n");
 		return -ENODEV;
 	}
-	plat->syscfg_base = regmap->base;
+	plat->syscfg_base = regmap->ranges[0].start;
 
 	/* get powerdown reset */
 	ret = reset_get_by_name(dev, "powerdown", &plat->powerdown_ctl);
diff --git a/include/regmap.h b/include/regmap.h
index 493a5d8..0d1dc5a 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -22,15 +22,12 @@ struct regmap_range {
 /**
  * struct regmap - a way of accessing hardware/bus registers
  *
- * @base:	Base address of register map
  * @range_count: Number of ranges available within the map
- * @range:	Pointer to the list of ranges, allocated if @range_count > 1
- * @base_range:	If @range_count is <= 1, @range points here
+ * @ranges:	Array of ranges
  */
 struct regmap {
-	phys_addr_t base;
 	int range_count;
-	struct regmap_range *range, base_range;
+	struct regmap_range ranges[0];
 };
 
 /*
diff --git a/test/dm/regmap.c b/test/dm/regmap.c
index 7f66058..8125345 100644
--- a/test/dm/regmap.c
+++ b/test/dm/regmap.c
@@ -26,23 +26,20 @@ static int dm_test_regmap_base(struct unit_test_state *uts)
 	map = syscon_get_regmap(dev);
 	ut_assertok_ptr(map);
 	ut_asserteq(1, map->range_count);
-	ut_asserteq(0x10, map->base);
-	ut_asserteq(0x10, map->range->start);
-	ut_asserteq(4, map->range->size);
-	ut_asserteq_ptr(&map->base_range, map->range);
+	ut_asserteq(0x10, map->ranges[0].start);
+	ut_asserteq(4, map->ranges[0].size);
 	ut_asserteq(0x10, map_to_sysmem(regmap_get_range(map, 0)));
 
 	ut_assertok(uclass_get_device(UCLASS_SYSCON, 1, &dev));
 	map = syscon_get_regmap(dev);
 	ut_assertok_ptr(map);
 	ut_asserteq(4, map->range_count);
-	ut_asserteq(0x20, map->base);
-	ut_assert(&map->base_range != map->range);
+	ut_asserteq(0x20, map->ranges[0].start);
 	for (i = 0; i < 4; i++) {
 		const unsigned long addr = 0x20 + 8 * i;
 
-		ut_asserteq(addr, map->range[i].start);
-		ut_asserteq(5 + i, map->range[i].size);
+		ut_asserteq(addr, map->ranges[i].start);
+		ut_asserteq(5 + i, map->ranges[i].size);
 		ut_asserteq(addr, map_to_sysmem(regmap_get_range(map, i)));
 	}
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v2 2/4] dm: ofnode: add ofnode_device_is_compatible() helper
  2018-04-19  3:14 [U-Boot] [PATCH v2 0/4] Add Linux-compatible syscon_to_regmap API Masahiro Yamada
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 1/4] regmap: clean up regmap allocation Masahiro Yamada
@ 2018-04-19  3:14 ` Masahiro Yamada
  2018-04-26 14:40   ` Simon Glass
  2018-05-08  0:45   ` [U-Boot] [U-Boot, v2, " Tom Rini
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 3/4] regmap: change regmap_init_mem() to take ofnode instead udevice Masahiro Yamada
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 4/4] syscon: add Linux-compatible syscon API Masahiro Yamada
  3 siblings, 2 replies; 14+ messages in thread
From: Masahiro Yamada @ 2018-04-19  3:14 UTC (permalink / raw)
  To: u-boot

device_is_compatible() takes udevice, but there is no such a helper
that takes ofnode.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2: None

 drivers/core/device.c |  8 +-------
 drivers/core/ofnode.c | 11 +++++++++++
 include/dm/ofnode.h   | 11 +++++++++++
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 940a153..8d95787 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -709,13 +709,7 @@ int device_set_name(struct udevice *dev, const char *name)
 
 bool device_is_compatible(struct udevice *dev, const char *compat)
 {
-	const void *fdt = gd->fdt_blob;
-	ofnode node = dev_ofnode(dev);
-
-	if (ofnode_is_np(node))
-		return of_device_is_compatible(ofnode_to_np(node), compat, NULL, NULL);
-	else
-		return !fdt_node_check_compatible(fdt, ofnode_to_offset(node), compat);
+	return ofnode_device_is_compatible(dev_ofnode(dev), compat);
 }
 
 bool of_machine_is_compatible(const char *compat)
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 5909a25..ee2109b 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -687,3 +687,14 @@ u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr)
 	else
 		return fdt_translate_address(gd->fdt_blob, ofnode_to_offset(node), in_addr);
 }
+
+int ofnode_device_is_compatible(ofnode node, const char *compat)
+{
+	if (ofnode_is_np(node))
+		return of_device_is_compatible(ofnode_to_np(node), compat,
+					       NULL, NULL);
+	else
+		return !fdt_node_check_compatible(gd->fdt_blob,
+						  ofnode_to_offset(node),
+						  compat);
+}
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 0d00840..a2c6a50 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -681,4 +681,15 @@ int ofnode_read_resource_byname(ofnode node, const char *name,
  * @return the translated address; OF_BAD_ADDR on error
  */
 u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
+
+/**
+ * ofnode_device_is_compatible() - check if the node is compatible with compat
+ *
+ * This allows to check whether the node is comaptible with the compat.
+ *
+ * @node:	Device tree node for which compatible needs to be verified.
+ * @compat:	Compatible string which needs to verified in the given node.
+ * @return true if OK, false if the compatible is not found
+ */
+int ofnode_device_is_compatible(ofnode node, const char *compat);
 #endif
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v2 3/4] regmap: change regmap_init_mem() to take ofnode instead udevice
  2018-04-19  3:14 [U-Boot] [PATCH v2 0/4] Add Linux-compatible syscon_to_regmap API Masahiro Yamada
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 1/4] regmap: clean up regmap allocation Masahiro Yamada
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 2/4] dm: ofnode: add ofnode_device_is_compatible() helper Masahiro Yamada
@ 2018-04-19  3:14 ` Masahiro Yamada
  2018-04-26 14:40   ` Simon Glass
  2018-05-08  0:45   ` [U-Boot] [U-Boot, v2, " Tom Rini
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 4/4] syscon: add Linux-compatible syscon API Masahiro Yamada
  3 siblings, 2 replies; 14+ messages in thread
From: Masahiro Yamada @ 2018-04-19  3:14 UTC (permalink / raw)
  To: u-boot

Currently, regmap_init_mem() takes a udevice. This requires the node
has already been associated with a device. It prevents syscon/regmap
from behaving like those in Linux.

Change the first argumenet to take a device node.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Neil Armstrong <narmstrong@baylibre.com>
---

Changes in v2: None

 arch/arm/mach-aspeed/ast2500/sdram_ast2500.c |  2 +-
 drivers/core/regmap.c                        | 11 +++++------
 drivers/core/syscon-uclass.c                 |  2 +-
 drivers/phy/meson-gxl-usb2.c                 |  2 +-
 drivers/phy/meson-gxl-usb3.c                 |  2 +-
 drivers/ram/rockchip/dmc-rk3368.c            |  2 +-
 drivers/ram/rockchip/sdram_rk3188.c          |  2 +-
 drivers/ram/rockchip/sdram_rk322x.c          |  2 +-
 drivers/ram/rockchip/sdram_rk3288.c          |  2 +-
 drivers/ram/rockchip/sdram_rk3399.c          |  2 +-
 drivers/ram/stm32mp1/stm32mp1_ram.c          |  2 +-
 drivers/reset/reset-meson.c                  |  2 +-
 include/regmap.h                             |  4 ++--
 13 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/arch/arm/mach-aspeed/ast2500/sdram_ast2500.c b/arch/arm/mach-aspeed/ast2500/sdram_ast2500.c
index 6383f72..f267c58 100644
--- a/arch/arm/mach-aspeed/ast2500/sdram_ast2500.c
+++ b/arch/arm/mach-aspeed/ast2500/sdram_ast2500.c
@@ -392,7 +392,7 @@ static int ast2500_sdrammc_ofdata_to_platdata(struct udevice *dev)
 	struct regmap *map;
 	int ret;
 
-	ret = regmap_init_mem(dev, &map);
+	ret = regmap_init_mem(dev_ofnode(dev), &map);
 	if (ret)
 		return ret;
 
diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 6c3dbe9..1185a44 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -51,7 +51,7 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
 	return 0;
 }
 #else
-int regmap_init_mem(struct udevice *dev, struct regmap **mapp)
+int regmap_init_mem(ofnode node, struct regmap **mapp)
 {
 	struct regmap_range *range;
 	struct regmap *map;
@@ -59,14 +59,13 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp)
 	int addr_len, size_len, both_len;
 	int len;
 	int index;
-	ofnode node = dev_ofnode(dev);
 	struct resource r;
 
-	addr_len = dev_read_simple_addr_cells(dev->parent);
-	size_len = dev_read_simple_size_cells(dev->parent);
+	addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node));
+	size_len = ofnode_read_simple_size_cells(ofnode_get_parent(node));
 	both_len = addr_len + size_len;
 
-	len = dev_read_size(dev, "reg");
+	len = ofnode_read_size(node, "reg");
 	if (len < 0)
 		return len;
 	len /= sizeof(fdt32_t);
@@ -87,7 +86,7 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp)
 			range->size = r.end - r.start + 1;
 		} else {
 			range->start = fdtdec_get_addr_size_fixed(gd->fdt_blob,
-					dev_of_offset(dev), "reg", index,
+					ofnode_to_offset(node), "reg", index,
 					addr_len, size_len, &sz, true);
 			range->size = sz;
 		}
diff --git a/drivers/core/syscon-uclass.c b/drivers/core/syscon-uclass.c
index a69937e..c99409b 100644
--- a/drivers/core/syscon-uclass.c
+++ b/drivers/core/syscon-uclass.c
@@ -41,7 +41,7 @@ static int syscon_pre_probe(struct udevice *dev)
 	return regmap_init_mem_platdata(dev, plat->reg, ARRAY_SIZE(plat->reg),
 					&priv->regmap);
 #else
-	return regmap_init_mem(dev, &priv->regmap);
+	return regmap_init_mem(dev_ofnode(dev), &priv->regmap);
 #endif
 }
 
diff --git a/drivers/phy/meson-gxl-usb2.c b/drivers/phy/meson-gxl-usb2.c
index 15c9c89..7242bf6 100644
--- a/drivers/phy/meson-gxl-usb2.c
+++ b/drivers/phy/meson-gxl-usb2.c
@@ -195,7 +195,7 @@ int meson_gxl_usb2_phy_probe(struct udevice *dev)
 	struct phy_meson_gxl_usb2_priv *priv = dev_get_priv(dev);
 	int ret;
 
-	ret = regmap_init_mem(dev, &priv->regmap);
+	ret = regmap_init_mem(dev_ofnode(dev), &priv->regmap);
 	if (ret)
 		return ret;
 
diff --git a/drivers/phy/meson-gxl-usb3.c b/drivers/phy/meson-gxl-usb3.c
index a385fbd..47a41fd 100644
--- a/drivers/phy/meson-gxl-usb3.c
+++ b/drivers/phy/meson-gxl-usb3.c
@@ -166,7 +166,7 @@ int meson_gxl_usb3_phy_probe(struct udevice *dev)
 	struct phy_meson_gxl_usb3_priv *priv = dev_get_priv(dev);
 	int ret;
 
-	ret = regmap_init_mem(dev, &priv->regmap);
+	ret = regmap_init_mem(dev_ofnode(dev), &priv->regmap);
 	if (ret)
 		return ret;
 	
diff --git a/drivers/ram/rockchip/dmc-rk3368.c b/drivers/ram/rockchip/dmc-rk3368.c
index bfcb1dd..9bf64bf 100644
--- a/drivers/ram/rockchip/dmc-rk3368.c
+++ b/drivers/ram/rockchip/dmc-rk3368.c
@@ -880,7 +880,7 @@ static int rk3368_dmc_ofdata_to_platdata(struct udevice *dev)
 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
 	struct rk3368_sdram_params *plat = dev_get_platdata(dev);
 
-	ret = regmap_init_mem(dev, &plat->map);
+	ret = regmap_init_mem(dev_ofnode(dev), &plat->map);
 	if (ret)
 		return ret;
 #endif
diff --git a/drivers/ram/rockchip/sdram_rk3188.c b/drivers/ram/rockchip/sdram_rk3188.c
index 365d00e..c0a2618 100644
--- a/drivers/ram/rockchip/sdram_rk3188.c
+++ b/drivers/ram/rockchip/sdram_rk3188.c
@@ -842,7 +842,7 @@ static int rk3188_dmc_ofdata_to_platdata(struct udevice *dev)
 		printf("%s: Cannot read rockchip,sdram-params\n", __func__);
 		return -EINVAL;
 	}
-	ret = regmap_init_mem(dev, &params->map);
+	ret = regmap_init_mem(dev_ofnode(dev), &params->map);
 	if (ret)
 		return ret;
 #endif
diff --git a/drivers/ram/rockchip/sdram_rk322x.c b/drivers/ram/rockchip/sdram_rk322x.c
index cc3138b..dca07db 100644
--- a/drivers/ram/rockchip/sdram_rk322x.c
+++ b/drivers/ram/rockchip/sdram_rk322x.c
@@ -744,7 +744,7 @@ static int rk322x_dmc_ofdata_to_platdata(struct udevice *dev)
 		printf("%s: Cannot read rockchip,sdram-params\n", __func__);
 		return -EINVAL;
 	}
-	ret = regmap_init_mem(dev, &params->map);
+	ret = regmap_init_mem(dev_ofnode(dev), &params->map);
 	if (ret)
 		return ret;
 #endif
diff --git a/drivers/ram/rockchip/sdram_rk3288.c b/drivers/ram/rockchip/sdram_rk3288.c
index 95efb11..ffb663c 100644
--- a/drivers/ram/rockchip/sdram_rk3288.c
+++ b/drivers/ram/rockchip/sdram_rk3288.c
@@ -1003,7 +1003,7 @@ static int rk3288_dmc_ofdata_to_platdata(struct udevice *dev)
 
 	priv->is_veyron = !fdt_node_check_compatible(blob, 0, "google,veyron");
 #endif
-	ret = regmap_init_mem(dev, &params->map);
+	ret = regmap_init_mem(dev_ofnode(dev), &params->map);
 	if (ret)
 		return ret;
 #endif
diff --git a/drivers/ram/rockchip/sdram_rk3399.c b/drivers/ram/rockchip/sdram_rk3399.c
index 5cb470c..6e2a39e 100644
--- a/drivers/ram/rockchip/sdram_rk3399.c
+++ b/drivers/ram/rockchip/sdram_rk3399.c
@@ -1100,7 +1100,7 @@ static int rk3399_dmc_ofdata_to_platdata(struct udevice *dev)
 		       __func__, ret);
 		return ret;
 	}
-	ret = regmap_init_mem(dev, &plat->map);
+	ret = regmap_init_mem(dev_ofnode(dev), &plat->map);
 	if (ret)
 		printf("%s: regmap failed %d\n", __func__, ret);
 
diff --git a/drivers/ram/stm32mp1/stm32mp1_ram.c b/drivers/ram/stm32mp1/stm32mp1_ram.c
index 9599444..a4d5906 100644
--- a/drivers/ram/stm32mp1/stm32mp1_ram.c
+++ b/drivers/ram/stm32mp1/stm32mp1_ram.c
@@ -149,7 +149,7 @@ static int stm32mp1_ddr_probe(struct udevice *dev)
 	debug("STM32MP1 DDR probe\n");
 	priv->dev = dev;
 
-	ret = regmap_init_mem(dev, &map);
+	ret = regmap_init_mem(dev_ofnode(dev), &map);
 	if (ret)
 		return ret;
 
diff --git a/drivers/reset/reset-meson.c b/drivers/reset/reset-meson.c
index 5324f86..c41d176 100644
--- a/drivers/reset/reset-meson.c
+++ b/drivers/reset/reset-meson.c
@@ -77,7 +77,7 @@ static int meson_reset_probe(struct udevice *dev)
 {
 	struct meson_reset_priv *priv = dev_get_priv(dev);
 	
-	return regmap_init_mem(dev, &priv->regmap);
+	return regmap_init_mem(dev_ofnode(dev), &priv->regmap);
 }
 
 U_BOOT_DRIVER(meson_reset) = {
diff --git a/include/regmap.h b/include/regmap.h
index 0d1dc5a..a5a4646 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -48,10 +48,10 @@ int regmap_read(struct regmap *map, uint offset, uint *valp);
  *
  * Use regmap_uninit() to free it.
  *
- * @dev:	Device that uses this map
+ * @node:	Device node that uses this map
  * @mapp:	Returns allocated map
  */
-int regmap_init_mem(struct udevice *dev, struct regmap **mapp);
+int regmap_init_mem(ofnode node, struct regmap **mapp);
 
 /**
  * regmap_init_mem_platdata() - Set up a new memory register map for of-platdata
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v2 4/4] syscon: add Linux-compatible syscon API
  2018-04-19  3:14 [U-Boot] [PATCH v2 0/4] Add Linux-compatible syscon_to_regmap API Masahiro Yamada
                   ` (2 preceding siblings ...)
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 3/4] regmap: change regmap_init_mem() to take ofnode instead udevice Masahiro Yamada
@ 2018-04-19  3:14 ` Masahiro Yamada
  2018-05-08  0:45   ` [U-Boot] [U-Boot, v2, " Tom Rini
  3 siblings, 1 reply; 14+ messages in thread
From: Masahiro Yamada @ 2018-04-19  3:14 UTC (permalink / raw)
  To: u-boot

The syscon implementation in U-Boot is different from that in Linux.
Thus, DT files imported from Linux do not work for U-Boot.

In U-Boot driver model, each node is bound to a dedicated driver
that is the most compatible to it.  This design gets along with the
concept of DT, and the syscon in Linux originally worked like that.

However, Linux commit bdb0066df96e ("mfd: syscon: Decouple syscon
interface from platform devices") changed the behavior because it is
useful to let a device bind to another driver, but still work as a
syscon provider.

That change had happened before U-Boot initially supported the syscon
driver by commit 6f98b7504f70 ("dm: Add support for generic system
controllers (syscon)").  So, the U-Boot's syscon works differently
from the beginning.  I'd say this is mis-implementation given that
DT is not oriented to a particular project, but Linux is the canon
of DT in practice.

The problem typically arises in the combination of "syscon" and
"simple-mfd" compatibles.

In Linux, they are orthogonal, i.e., the order between "syscon" and
"simple-mfd" does not matter at all.

Assume the following compatible.

   compatible = "foo,bar-syscon", "syscon", "simple-mfd";

In U-Boot, this device node is bound to the syscon driver
(driver/core/syscon-uclass.c) since the "syscon" is found to be the
most compatible.  Then, syscon_get_regmap() succeeds.

However,

   compatible = "foo,bar-syscon", "simple-mfd", "syscon";

does not work because this node is bound to the simple-bus driver
(drivers/core/simple-bus.c) in favor of "simple-mfd" compatible.
The compatible string "syscon" is just dismissed.

Moreover,

   compatible = "foo,bar-syscon", "syscon";

works like the first case because the syscon driver populates the
child devices.  This is wrong because populating children is the job
of "simple-mfd" (or "simple-bus").

This commit ports syscon_node_to_regmap() from Linux.  This API
does not require the given node to be bound to a driver in any way.

Reported-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2: None

 drivers/core/syscon-uclass.c | 64 ++++++++++++++++++++++++++++++++++++++++++++
 include/syscon.h             |  8 ++++++
 2 files changed, 72 insertions(+)

diff --git a/drivers/core/syscon-uclass.c b/drivers/core/syscon-uclass.c
index c99409b..6f2c5e3 100644
--- a/drivers/core/syscon-uclass.c
+++ b/drivers/core/syscon-uclass.c
@@ -15,6 +15,15 @@
 #include <dm/root.h>
 #include <linux/err.h>
 
+/*
+ * Caution:
+ * This API requires the given device has alerady been bound to syscon driver.
+ * For example,
+ *    compatible = "syscon", "simple-mfd";
+ * works, but
+ *    compatible = "simple-mfd", "syscon";
+ * does not.  The behavior is different from Linux.
+ */
 struct regmap *syscon_get_regmap(struct udevice *dev)
 {
 	struct syscon_uc_info *priv;
@@ -109,3 +118,58 @@ U_BOOT_DRIVER(generic_syscon) = {
 #endif
 	.of_match = generic_syscon_ids,
 };
+
+/*
+ * Linux-compatible syscon-to-regmap
+ * The syscon node can be bound to another driver, but still works
+ * as a syscon provider.
+ */
+static LIST_HEAD(syscon_list);
+
+struct syscon {
+	ofnode node;
+	struct regmap *regmap;
+	struct list_head list;
+};
+
+static struct syscon *of_syscon_register(ofnode node)
+{
+	struct syscon *syscon;
+	int ret;
+
+	if (!ofnode_device_is_compatible(node, "syscon"))
+		return ERR_PTR(-EINVAL);
+
+	syscon = malloc(sizeof(*syscon));
+	if (!syscon)
+		return ERR_PTR(-ENOMEM);
+
+	ret = regmap_init_mem(node, &syscon->regmap);
+	if (ret) {
+		free(syscon);
+		return ERR_PTR(ret);
+	}
+
+	list_add_tail(&syscon->list, &syscon_list);
+
+	return syscon;
+}
+
+struct regmap *syscon_node_to_regmap(ofnode node)
+{
+	struct syscon *entry, *syscon = NULL;
+
+	list_for_each_entry(entry, &syscon_list, list)
+		if (ofnode_equal(entry->node, node)) {
+			syscon = entry;
+			break;
+		}
+
+	if (!syscon)
+		syscon = of_syscon_register(node);
+
+	if (IS_ERR(syscon))
+		return ERR_CAST(syscon);
+
+	return syscon->regmap;
+}
diff --git a/include/syscon.h b/include/syscon.h
index 5d52b1c..f4b9cb0 100644
--- a/include/syscon.h
+++ b/include/syscon.h
@@ -8,6 +8,7 @@
 #ifndef __SYSCON_H
 #define __SYSCON_H
 
+#include <dm/ofnode.h>
 #include <fdtdec.h>
 
 /**
@@ -82,4 +83,11 @@ struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data);
  */
 void *syscon_get_first_range(ulong driver_data);
 
+/**
+ * syscon_node_to_regmap - get regmap from syscon
+ *
+ * @node:		Device node of syscon
+ */
+struct regmap *syscon_node_to_regmap(ofnode node);
+
 #endif
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v2 1/4] regmap: clean up regmap allocation
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 1/4] regmap: clean up regmap allocation Masahiro Yamada
@ 2018-04-23  4:30   ` Masahiro Yamada
  2018-05-08  0:45   ` [U-Boot] [U-Boot,v2,1/4] " Tom Rini
  1 sibling, 0 replies; 14+ messages in thread
From: Masahiro Yamada @ 2018-04-23  4:30 UTC (permalink / raw)
  To: u-boot

2018-04-19 12:14 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
> Putting zero length array at the end of struct is a common technique
> to embed arbitrary length of members.  There is no good reason to let
> regmap_alloc_count() branch by "if (count <= 1)".
>
> As far as I understood the code, regmap->base is an alias of
> regmap->ranges[0].start, but it is not helpful but make the code
> just ugly.
>
> Rename regmap_alloc_count() to regmap_alloc() because the _count
> suffix seems pointless.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---

Simon gave r-b to v1.
Copy-pasting it to v2.

Reviewed-by: Simon Glass <sjg@chromium.org>


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v2 3/4] regmap: change regmap_init_mem() to take ofnode instead udevice
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 3/4] regmap: change regmap_init_mem() to take ofnode instead udevice Masahiro Yamada
@ 2018-04-26 14:40   ` Simon Glass
  2018-05-08  0:45   ` [U-Boot] [U-Boot, v2, " Tom Rini
  1 sibling, 0 replies; 14+ messages in thread
From: Simon Glass @ 2018-04-26 14:40 UTC (permalink / raw)
  To: u-boot

On 18 April 2018 at 21:14, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> Currently, regmap_init_mem() takes a udevice. This requires the node
> has already been associated with a device. It prevents syscon/regmap
> from behaving like those in Linux.
>
> Change the first argumenet to take a device node.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Acked-by: Neil Armstrong <narmstrong@baylibre.com>
> ---
>
> Changes in v2: None
>
>  arch/arm/mach-aspeed/ast2500/sdram_ast2500.c |  2 +-
>  drivers/core/regmap.c                        | 11 +++++------
>  drivers/core/syscon-uclass.c                 |  2 +-
>  drivers/phy/meson-gxl-usb2.c                 |  2 +-
>  drivers/phy/meson-gxl-usb3.c                 |  2 +-
>  drivers/ram/rockchip/dmc-rk3368.c            |  2 +-
>  drivers/ram/rockchip/sdram_rk3188.c          |  2 +-
>  drivers/ram/rockchip/sdram_rk322x.c          |  2 +-
>  drivers/ram/rockchip/sdram_rk3288.c          |  2 +-
>  drivers/ram/rockchip/sdram_rk3399.c          |  2 +-
>  drivers/ram/stm32mp1/stm32mp1_ram.c          |  2 +-
>  drivers/reset/reset-meson.c                  |  2 +-
>  include/regmap.h                             |  4 ++--
>  13 files changed, 18 insertions(+), 19 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v2 2/4] dm: ofnode: add ofnode_device_is_compatible() helper
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 2/4] dm: ofnode: add ofnode_device_is_compatible() helper Masahiro Yamada
@ 2018-04-26 14:40   ` Simon Glass
  2018-04-26 16:03     ` Masahiro Yamada
  2018-05-08  0:45   ` [U-Boot] [U-Boot, v2, " Tom Rini
  1 sibling, 1 reply; 14+ messages in thread
From: Simon Glass @ 2018-04-26 14:40 UTC (permalink / raw)
  To: u-boot

Hi Masahiro,

On 18 April 2018 at 21:14, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> device_is_compatible() takes udevice, but there is no such a helper
> that takes ofnode.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
> Changes in v2: None
>
>  drivers/core/device.c |  8 +-------
>  drivers/core/ofnode.c | 11 +++++++++++
>  include/dm/ofnode.h   | 11 +++++++++++
>  3 files changed, 23 insertions(+), 7 deletions(-)
>

Please can you add a simple test for this?

Regards,
Simon

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v2 2/4] dm: ofnode: add ofnode_device_is_compatible() helper
  2018-04-26 14:40   ` Simon Glass
@ 2018-04-26 16:03     ` Masahiro Yamada
  2018-04-30 23:12       ` Simon Glass
  0 siblings, 1 reply; 14+ messages in thread
From: Masahiro Yamada @ 2018-04-26 16:03 UTC (permalink / raw)
  To: u-boot

Hi Simon,


2018-04-26 23:40 GMT+09:00 Simon Glass <sjg@chromium.org>:
> Hi Masahiro,
>
> On 18 April 2018 at 21:14, Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
>> device_is_compatible() takes udevice, but there is no such a helper
>> that takes ofnode.
>>
>> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
>> ---
>>
>> Changes in v2: None
>>
>>  drivers/core/device.c |  8 +-------
>>  drivers/core/ofnode.c | 11 +++++++++++
>>  include/dm/ofnode.h   | 11 +++++++++++
>>  3 files changed, 23 insertions(+), 7 deletions(-)
>>
>
> Please can you add a simple test for this?

I wrote a simple test:

http://patchwork.ozlabs.org/patch/905181/

-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [PATCH v2 2/4] dm: ofnode: add ofnode_device_is_compatible() helper
  2018-04-26 16:03     ` Masahiro Yamada
@ 2018-04-30 23:12       ` Simon Glass
  0 siblings, 0 replies; 14+ messages in thread
From: Simon Glass @ 2018-04-30 23:12 UTC (permalink / raw)
  To: u-boot

On 26 April 2018 at 10:03, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> Hi Simon,
>
>
> 2018-04-26 23:40 GMT+09:00 Simon Glass <sjg@chromium.org>:
>> Hi Masahiro,
>>
>> On 18 April 2018 at 21:14, Masahiro Yamada
>> <yamada.masahiro@socionext.com> wrote:
>>> device_is_compatible() takes udevice, but there is no such a helper
>>> that takes ofnode.
>>>
>>> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
>>> ---
>>>
>>> Changes in v2: None
>>>
>>>  drivers/core/device.c |  8 +-------
>>>  drivers/core/ofnode.c | 11 +++++++++++
>>>  include/dm/ofnode.h   | 11 +++++++++++
>>>  3 files changed, 23 insertions(+), 7 deletions(-)
>>>
>>
>> Please can you add a simple test for this?
>
> I wrote a simple test:
>
> http://patchwork.ozlabs.org/patch/905181/

Thanks!

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [U-Boot,v2,1/4] regmap: clean up regmap allocation
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 1/4] regmap: clean up regmap allocation Masahiro Yamada
  2018-04-23  4:30   ` Masahiro Yamada
@ 2018-05-08  0:45   ` Tom Rini
  1 sibling, 0 replies; 14+ messages in thread
From: Tom Rini @ 2018-05-08  0:45 UTC (permalink / raw)
  To: u-boot

On Thu, Apr 19, 2018 at 12:14:01PM +0900, Masahiro Yamada wrote:

> Putting zero length array at the end of struct is a common technique
> to embed arbitrary length of members.  There is no good reason to let
> regmap_alloc_count() branch by "if (count <= 1)".
> 
> As far as I understood the code, regmap->base is an alias of
> regmap->ranges[0].start, but it is not helpful but make the code
> just ugly.
> 
> Rename regmap_alloc_count() to regmap_alloc() because the _count
> suffix seems pointless.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180507/a7a194ef/attachment.sig>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [U-Boot, v2, 2/4] dm: ofnode: add ofnode_device_is_compatible() helper
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 2/4] dm: ofnode: add ofnode_device_is_compatible() helper Masahiro Yamada
  2018-04-26 14:40   ` Simon Glass
@ 2018-05-08  0:45   ` Tom Rini
  1 sibling, 0 replies; 14+ messages in thread
From: Tom Rini @ 2018-05-08  0:45 UTC (permalink / raw)
  To: u-boot

On Thu, Apr 19, 2018 at 12:14:02PM +0900, Masahiro Yamada wrote:

> device_is_compatible() takes udevice, but there is no such a helper
> that takes ofnode.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180507/baf6c11d/attachment.sig>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [U-Boot, v2, 3/4] regmap: change regmap_init_mem() to take ofnode instead udevice
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 3/4] regmap: change regmap_init_mem() to take ofnode instead udevice Masahiro Yamada
  2018-04-26 14:40   ` Simon Glass
@ 2018-05-08  0:45   ` Tom Rini
  1 sibling, 0 replies; 14+ messages in thread
From: Tom Rini @ 2018-05-08  0:45 UTC (permalink / raw)
  To: u-boot

On Thu, Apr 19, 2018 at 12:14:03PM +0900, Masahiro Yamada wrote:

> Currently, regmap_init_mem() takes a udevice. This requires the node
> has already been associated with a device. It prevents syscon/regmap
> from behaving like those in Linux.
> 
> Change the first argumenet to take a device node.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Acked-by: Neil Armstrong <narmstrong@baylibre.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180507/4cc9ba74/attachment.sig>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [U-Boot] [U-Boot, v2, 4/4] syscon: add Linux-compatible syscon API
  2018-04-19  3:14 ` [U-Boot] [PATCH v2 4/4] syscon: add Linux-compatible syscon API Masahiro Yamada
@ 2018-05-08  0:45   ` Tom Rini
  0 siblings, 0 replies; 14+ messages in thread
From: Tom Rini @ 2018-05-08  0:45 UTC (permalink / raw)
  To: u-boot

On Thu, Apr 19, 2018 at 12:14:04PM +0900, Masahiro Yamada wrote:

> The syscon implementation in U-Boot is different from that in Linux.
> Thus, DT files imported from Linux do not work for U-Boot.
> 
> In U-Boot driver model, each node is bound to a dedicated driver
> that is the most compatible to it.  This design gets along with the
> concept of DT, and the syscon in Linux originally worked like that.
> 
> However, Linux commit bdb0066df96e ("mfd: syscon: Decouple syscon
> interface from platform devices") changed the behavior because it is
> useful to let a device bind to another driver, but still work as a
> syscon provider.
> 
> That change had happened before U-Boot initially supported the syscon
> driver by commit 6f98b7504f70 ("dm: Add support for generic system
> controllers (syscon)").  So, the U-Boot's syscon works differently
> from the beginning.  I'd say this is mis-implementation given that
> DT is not oriented to a particular project, but Linux is the canon
> of DT in practice.
> 
> The problem typically arises in the combination of "syscon" and
> "simple-mfd" compatibles.
> 
> In Linux, they are orthogonal, i.e., the order between "syscon" and
> "simple-mfd" does not matter at all.
> 
> Assume the following compatible.
> 
>    compatible = "foo,bar-syscon", "syscon", "simple-mfd";
> 
> In U-Boot, this device node is bound to the syscon driver
> (driver/core/syscon-uclass.c) since the "syscon" is found to be the
> most compatible.  Then, syscon_get_regmap() succeeds.
> 
> However,
> 
>    compatible = "foo,bar-syscon", "simple-mfd", "syscon";
> 
> does not work because this node is bound to the simple-bus driver
> (drivers/core/simple-bus.c) in favor of "simple-mfd" compatible.
> The compatible string "syscon" is just dismissed.
> 
> Moreover,
> 
>    compatible = "foo,bar-syscon", "syscon";
> 
> works like the first case because the syscon driver populates the
> child devices.  This is wrong because populating children is the job
> of "simple-mfd" (or "simple-bus").
> 
> This commit ports syscon_node_to_regmap() from Linux.  This API
> does not require the given node to be bound to a driver in any way.
> 
> Reported-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180507/366579f7/attachment.sig>

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-05-08  0:45 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-19  3:14 [U-Boot] [PATCH v2 0/4] Add Linux-compatible syscon_to_regmap API Masahiro Yamada
2018-04-19  3:14 ` [U-Boot] [PATCH v2 1/4] regmap: clean up regmap allocation Masahiro Yamada
2018-04-23  4:30   ` Masahiro Yamada
2018-05-08  0:45   ` [U-Boot] [U-Boot,v2,1/4] " Tom Rini
2018-04-19  3:14 ` [U-Boot] [PATCH v2 2/4] dm: ofnode: add ofnode_device_is_compatible() helper Masahiro Yamada
2018-04-26 14:40   ` Simon Glass
2018-04-26 16:03     ` Masahiro Yamada
2018-04-30 23:12       ` Simon Glass
2018-05-08  0:45   ` [U-Boot] [U-Boot, v2, " Tom Rini
2018-04-19  3:14 ` [U-Boot] [PATCH v2 3/4] regmap: change regmap_init_mem() to take ofnode instead udevice Masahiro Yamada
2018-04-26 14:40   ` Simon Glass
2018-05-08  0:45   ` [U-Boot] [U-Boot, v2, " Tom Rini
2018-04-19  3:14 ` [U-Boot] [PATCH v2 4/4] syscon: add Linux-compatible syscon API Masahiro Yamada
2018-05-08  0:45   ` [U-Boot] [U-Boot, v2, " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.