Skip to contentSkip to conversation

Align U-Boot I2C DM bus ID handling with Linux

PATCH Superseded Michal Simek 4 participants 40 messages Jan 31, 2019 – Feb 11, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 1: i2c at ff020000->i2c-mux at 75->i2c at 0
Bus 2: i2c at ff020000->i2c-mux at 75->i2c at 1
Bus 3: i2c at ff020000->i2c-mux at 75->i2c at 2
Bus 4: i2c at ff030000 (active 4)
74: i2c-mux at 74, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0
Bus 6: i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 7: i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 8: i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 9: i2c at ff030000->i2c-mux at 74->i2c at 4
Bus 10: i2c at ff030000->i2c-mux at 75->i2c at 0
Bus 11: i2c at ff030000->i2c-mux at 75->i2c at 1
Bus 12: i2c at ff030000->i2c-mux at 75->i2c at 2
Bus 13: i2c at ff030000->i2c-mux at 75->i2c at 3
Bus 14: i2c at ff030000->i2c-mux at 75->i2c at 4
Bus 15: i2c at ff030000->i2c-mux at 75->i2c at 5
Bus 16: i2c at ff030000->i2c-mux at 75->i2c at 6
Bus 17: i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

Michal Simek (7):
dm: core: Add of_alias_get_highest_id()
fdt: Introduce fdtdec_get_alias_highest_id()
dm: core: Introduce dev_read_alias_highest_id()
dm: core: Add tests for dev_read_alias_highest_id()
i2c: dm: Record maximum id of devices before probing devices
i2c: Fill req_seq in i2c_post_bind()
i2c: mux: Generate longer i2c mux name

 drivers/core/of_access.c           | 18 ++++++++++++++
 drivers/core/read.c                |  8 ++++++
 drivers/i2c/i2c-uclass.c           | 50 +++++++++++++++++++++++++++++++++++---
 drivers/i2c/muxes/i2c-mux-uclass.c | 29 +++++++++++++++++++---
 include/dm/of_access.h             | 10 ++++++++
 include/dm/read.h                  | 16 ++++++++++++
 include/fdtdec.h                   | 13 ++++++++++
 lib/fdtdec.c                       | 33 +++++++++++++++++++++++++
 test/dm/test-fdt.c                 | 23 ++++++++++++++++++
 9 files changed, 194 insertions(+), 6 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/7 dm: core: Add of_alias_get_highest_id()

The same functionality was added to Linux for i2c bus registration with this commit message:

"
of: base: add function to get highest id of an alias stem

I2C supports adding adapters using either a dynamic or fixed id. The latter is provided by aliases in the DT case. To prevent id collisions of those two types, install this function which gives us the highest fixed id, so we can then let the dynamically created ones come after this highest number.

"

Add it also to U-Boot for DM I2C support.

---

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.

 drivers/core/of_access.c | 18 ++++++++++++++++++
 include/dm/of_access.h   | 10 ++++++++++
 2 files changed, 28 insertions(+)
drivers/core/of_access.c +18 -0
index 14c020a687b7..945b81448cce 100644
@@ -812,6 +812,24 @@ int of_alias_get_id(const struct device_node *np, const char *stem)
 	return id;
 }
 
+int of_alias_get_highest_id(const char *stem)
+{
+	struct alias_prop *app;
+	int id = -1;
+
+	mutex_lock(&of_mutex);
+	list_for_each_entry(app, &aliases_lookup, link) {
+		if (strcmp(app->stem, stem) != 0)
+			continue;
+
+		if (app->id > id)
+			id = app->id;
+	}
+	mutex_unlock(&of_mutex);
+
+	return id;
+}
+
 struct device_node *of_get_stdout(void)
 {
 	return of_stdout;
include/dm/of_access.h +10 -0
index 5ed1a0cdb427..13fedb7cf5e6 100644
@@ -425,6 +425,16 @@ int of_alias_scan(void);
 int of_alias_get_id(const struct device_node *np, const char *stem);
 
 /**
+ * of_alias_get_highest_id - Get highest alias id for the given stem
+ * @stem:	Alias stem to be examined
+ *
+ * The function travels the lookup table to get the highest alias id for the
+ * given alias stem.
+ * @return alias ID, if found, else -1
+ */
+int of_alias_get_highest_id(const char *stem);
+
+/**
  * of_get_stdout() - Get node to use for stdout
  *
  * @return node referred to by stdout-path alias, or NULL if none
Signature · 1 line
1.9.1
#2 lore raw

PATCH v2 1/7 dm: core: Add of_alias_get_highest_id()

Hello Michal,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 22 lines

The same functionality was added to Linux for i2c bus registration with this commit message:

"
of: base: add function to get highest id of an alias stem

I2C supports adding adapters using either a dynamic or fixed id. The latter is provided by aliases in the DT case. To prevent id collisions of those two types, install this function which gives us the highest fixed id, so we can then let the dynamically created ones come after this highest number.

"

Add it also to U-Boot for DM I2C support.

---

Quoted 7 lines

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.

  drivers/core/of_access.c | 18 ++++++++++++++++++
  include/dm/of_access.h   | 10 ++++++++++
  2 files changed, 28 insertions(+)

Looks good to me

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#3 lore raw

PATCH v2 1/7 dm: core: Add of_alias_get_highest_id()

Quoted 30 lines · Heiko Schocher

Hello Michal,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 26 lines

The same functionality was added to Linux for i2c bus registration with this commit message:

"
of: base: add function to get highest id of an alias stem

I2C supports adding adapters using either a dynamic or fixed id. The latter is provided by aliases in the DT case. To prevent id collisions of those two types, install this function which gives us the highest fixed id, so we can then let the dynamically created ones come after this highest number.

"

Add it also to U-Boot for DM I2C support.

---

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.

Quoted 7 lines
Quoted 3 lines
  drivers/core/of_access.c | 18 ++++++++++++++++++
  include/dm/of_access.h   | 10 ++++++++++
  2 files changed, 28 insertions(+)

Looks good to me

#4 lore raw

PATCH v2 1/7 dm: core: Add of_alias_get_highest_id()

In reply to Michal Simek

Hello Michal,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 22 lines

The same functionality was added to Linux for i2c bus registration with this commit message:

"
of: base: add function to get highest id of an alias stem

I2C supports adding adapters using either a dynamic or fixed id. The latter is provided by aliases in the DT case. To prevent id collisions of those two types, install this function which gives us the highest fixed id, so we can then let the dynamically created ones come after this highest number.

"

Add it also to U-Boot for DM I2C support.

---

Quoted 7 lines

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.

  drivers/core/of_access.c | 18 ++++++++++++++++++
  include/dm/of_access.h   | 10 ++++++++++
  2 files changed, 28 insertions(+)

Applied to u-boot-i2c.git master

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#5 lore raw

PATCH v2 2/7 fdt: Introduce fdtdec_get_alias_highest_id()

In reply to Michal Simek

Find out the highest alias ID used for certain subsystem. This call will be used for alocating IDs for i2c buses which are not described in DT.

---

Changes in v2: None

 include/fdtdec.h | 13 +++++++++++++
 lib/fdtdec.c     | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
include/fdtdec.h +13 -0
index f1bcbf837ffb..c2dd87ede226 100644
@@ -626,6 +626,19 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int node,
 			 int *seqp);
 
 /**
+ * Get the highest alias number for susbystem.
+ *
+ * It parses all aliases and find out highest recorded alias for subsystem.
+ * Aliases are of the form <base><num> where <num> is the sequence number.
+ *
+ * @param blob		Device tree blob (if NULL, then error is returned)
+ * @param base		Base name for alias susbystem (before the number)
+ *
+ * @return 0 highest alias ID, -1 if not found
+ */
+int fdtdec_get_alias_highest_id(const void *blob, const char *base);
+
+/**
  * Get a property from the /chosen node
  *
  * @param blob		Device tree blob (if NULL, then NULL is returned)
lib/fdtdec.c +33 -0
index 18663ce6bdac..55811975ef54 100644
@@ -549,6 +549,39 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
 	return -ENOENT;
 }
 
+int fdtdec_get_alias_highest_id(const void *blob, const char *base)
+{
+	int base_len = strlen(base);
+	int prop_offset;
+	int aliases;
+	int max = -1;
+
+	debug("Looking for highest alias id for '%s'\n", base);
+
+	aliases = fdt_path_offset(blob, "/aliases");
+	for (prop_offset = fdt_first_property_offset(blob, aliases);
+	     prop_offset > 0;
+	     prop_offset = fdt_next_property_offset(blob, prop_offset)) {
+		const char *prop;
+		const char *name;
+		int len, val;
+
+		prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len);
+		debug("   - %s, %s\n", name, prop);
+		if (*prop != '/' || prop[len - 1] ||
+		    strncmp(name, base, base_len))
+			continue;
+
+		val = trailing_strtol(name);
+		if (val > max) {
+			debug("Found seq %d\n", val);
+			max = val;
+		}
+	}
+
+	return max;
+}
+
 const char *fdtdec_get_chosen_prop(const void *blob, const char *name)
 {
 	int chosen_node;
Signature · 1 line
1.9.1
#6 lore raw

PATCH v2 2/7 fdt: Introduce fdtdec_get_alias_highest_id()

Hello Michal,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 4 lines

Find out the highest alias ID used for certain subsystem. This call will be used for alocating IDs for i2c buses which are not described in DT.

Quoted 8 lines

---

Changes in v2: None

  include/fdtdec.h | 13 +++++++++++++
  lib/fdtdec.c     | 33 +++++++++++++++++++++++++++++++++
  2 files changed, 46 insertions(+)

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#7 lore raw

PATCH v2 2/7 fdt: Introduce fdtdec_get_alias_highest_id()

In reply to Michal Simek
Quoted 5 lines · Michal Simek

Find out the highest alias ID used for certain subsystem. This call will be used for alocating IDs for i2c buses which are not described in DT.

Quoted 8 lines

---

Changes in v2: None

 include/fdtdec.h | 13 +++++++++++++
 lib/fdtdec.c     | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
#8 lore raw

PATCH v2 2/7 fdt: Introduce fdtdec_get_alias_highest_id()

In reply to Michal Simek

Hello Michal,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 4 lines

Find out the highest alias ID used for certain subsystem. This call will be used for alocating IDs for i2c buses which are not described in DT.

Quoted 8 lines

---

Changes in v2: None

  include/fdtdec.h | 13 +++++++++++++
  lib/fdtdec.c     | 33 +++++++++++++++++++++++++++++++++
  2 files changed, 46 insertions(+)

Applied to u-boot-i2c.git master

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#9 lore raw

PATCH v2 3/7 dm: core: Introduce dev_read_alias_highest_id()

In reply to Michal Simek

It is wrapper for calling of_alias_get_highest_id() when live tree is enabled and fdtdec_get_alias_highest_id() if not.

---

Changes in v2:
- New patch

 drivers/core/read.c |  8 ++++++++
 include/dm/read.h   | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)
drivers/core/read.c +8 -0
index 3c46b3674ed6..6bda077a34b9 100644
@@ -264,3 +264,11 @@ u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr)
 {
 	return ofnode_translate_address(dev_ofnode(dev), in_addr);
 }
+
+int dev_read_alias_highest_id(const char *stem)
+{
+	if (of_live_active())
+		return of_alias_get_highest_id(stem);
+
+	return fdtdec_get_alias_highest_id(gd->fdt_blob, stem);
+}
include/dm/read.h +16 -0
index 389e30e7fb44..60b727cbd821 100644
@@ -510,6 +510,17 @@ int dev_read_resource_byname(struct udevice *dev, const char *name,
  * @return the translated address; OF_BAD_ADDR on error
  */
 u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr);
+
+/**
+ * dev_read_alias_highest_id - Get highest alias id for the given stem
+ * @stem:	Alias stem to be examined
+ *
+ * The function travels the lookup table to get the highest alias id for the
+ * given alias stem.
+ * @return alias ID, if found, else -1
+ */
+int dev_read_alias_highest_id(const char *stem);
+
 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
 
 static inline int dev_read_u32(struct udevice *dev,
@@ -740,6 +751,11 @@ static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_a
 	return ofnode_translate_address(dev_ofnode(dev), in_addr);
 }
 
+static inline int dev_read_alias_highest_id(const char *stem)
+{
+	return fdtdec_get_alias_highest_id(gd->fdt_blob, stem);
+}
+
 #endif /* CONFIG_DM_DEV_READ_INLINE */
 
 /**
Signature · 1 line
1.9.1
#10 lore raw

PATCH v2 3/7 dm: core: Introduce dev_read_alias_highest_id()

Hello Michal,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 4 lines

It is wrapper for calling of_alias_get_highest_id() when live tree is enabled and fdtdec_get_alias_highest_id() if not.

Quoted 8 lines

---

Changes in v2:
- New patch

  drivers/core/read.c |  8 ++++++++
  include/dm/read.h   | 16 ++++++++++++++++
  2 files changed, 24 insertions(+)

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#11 lore raw

PATCH v2 3/7 dm: core: Introduce dev_read_alias_highest_id()

In reply to Michal Simek
Quoted 5 lines · Michal Simek

It is wrapper for calling of_alias_get_highest_id() when live tree is enabled and fdtdec_get_alias_highest_id() if not.

Quoted 8 lines

---

Changes in v2:
- New patch

 drivers/core/read.c |  8 ++++++++
 include/dm/read.h   | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)
#12 lore raw

PATCH v2 3/7 dm: core: Introduce dev_read_alias_highest_id()

In reply to Michal Simek

Hello Michal,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 4 lines

It is wrapper for calling of_alias_get_highest_id() when live tree is enabled and fdtdec_get_alias_highest_id() if not.

Quoted 8 lines

---

Changes in v2:
- New patch

  drivers/core/read.c |  8 ++++++++
  include/dm/read.h   | 16 ++++++++++++++++
  2 files changed, 24 insertions(+)

Applied to u-boot-i2c.git master

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#13 lore raw

PATCH v2 4/7 dm: core: Add tests for dev_read_alias_highest_id()

In reply to Michal Simek

It is checking the highest alias ID for eth, gpio, pci, i2c and error code on non existing alias.

---

Changes in v2:
- New patch

 test/dm/test-fdt.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
test/dm/test-fdt.c +23 -0
index 984b80c02c81..be16c99e170e 100644
@@ -219,6 +219,29 @@ static int dm_test_fdt(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_fdt, 0);
 
+static int dm_test_alias_highest_id(struct unit_test_state *uts)
+{
+	int ret;
+
+	ret = dev_read_alias_highest_id("eth");
+	ut_asserteq(5, ret);
+
+	ret = dev_read_alias_highest_id("gpio");
+	ut_asserteq(2, ret);
+
+	ret = dev_read_alias_highest_id("pci");
+	ut_asserteq(2, ret);
+
+	ret = dev_read_alias_highest_id("i2c");
+	ut_asserteq(0, ret);
+
+	ret = dev_read_alias_highest_id("deadbeef");
+	ut_asserteq(-1, ret);
+
+	return 0;
+}
+DM_TEST(dm_test_alias_highest_id, 0);
+
 static int dm_test_fdt_pre_reloc(struct unit_test_state *uts)
 {
 	struct uclass *uc;
Signature · 1 line
1.9.1
#14 lore raw

PATCH v2 4/7 dm: core: Add tests for dev_read_alias_highest_id()

Hello Michal,

Am 31.01.2019 um 16:31 schrieb Michal Simek:

Quoted 11 lines

It is checking the highest alias ID for eth, gpio, pci, i2c and error code on non existing alias.

---

Changes in v2:
- New patch

  test/dm/test-fdt.c | 23 +++++++++++++++++++++++
  1 file changed, 23 insertions(+)

Thanks for adding tests

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#16 lore raw

PATCH v2 4/7 dm: core: Add tests for dev_read_alias_highest_id()

In reply to Michal Simek

Hello Michal,

Am 31.01.2019 um 16:31 schrieb Michal Simek:

Quoted 11 lines

It is checking the highest alias ID for eth, gpio, pci, i2c and error code on non existing alias.

---

Changes in v2:
- New patch

  test/dm/test-fdt.c | 23 +++++++++++++++++++++++
  1 file changed, 23 insertions(+)

Applied to u-boot-i2c.git master

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#17 lore raw

PATCH v2 5/7 i2c: dm: Record maximum id of devices before probing devices

In reply to Michal Simek

There is a need to find out the first free i2c ID which can be used for i2s buses (including i2c buses connected to i2c mux). Do it early in init and share this variable with other i2c classes for uniq bus identification.

---

Changes in v2:
- Use dev_read_alias_highest_id()
- Use uclass private data

 drivers/i2c/i2c-uclass.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/i2c/i2c-uclass.c +22 -0
index 975318e5f254..b26602f3de95 100644
@@ -619,6 +619,26 @@ static int i2c_child_post_bind(struct udevice *dev)
 #endif
 }
 
+struct i2c_priv {
+	int max_id;
+};
+
+int i2c_uclass_init(struct uclass *class)
+{
+	struct i2c_priv *priv = class->priv;
+
+	/* Just for sure */
+	if (!priv)
+		return -ENOMEM;
+
+	/* Get the last allocated alias. */
+	priv->max_id = dev_read_alias_highest_id("i2c");
+
+	debug("%s: highest alias id is %d\n", __func__, priv->max_id);
+
+	return 0;
+}
+
 UCLASS_DRIVER(i2c) = {
 	.id		= UCLASS_I2C,
 	.name		= "i2c",
@@ -626,6 +646,8 @@ UCLASS_DRIVER(i2c) = {
 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 	.post_bind	= dm_scan_fdt_dev,
 #endif
+	.init		= i2c_uclass_init,
+	.priv_auto_alloc_size = sizeof(struct i2c_priv),
 	.post_probe	= i2c_post_probe,
 	.per_device_auto_alloc_size = sizeof(struct dm_i2c_bus),
 	.per_child_platdata_auto_alloc_size = sizeof(struct dm_i2c_chip),
Signature · 1 line
1.9.1
#18 lore raw

PATCH v2 5/7 i2c: dm: Record maximum id of devices before probing devices

Hello Michal,

Am 31.01.2019 um 16:31 schrieb Michal Simek:

Quoted 6 lines

There is a need to find out the first free i2c ID which can be used for i2s buses (including i2c buses connected to i2c mux). Do it early in init and share this variable with other i2c classes for uniq bus identification.

Quoted 8 lines

---

Changes in v2:
- Use dev_read_alias_highest_id()
- Use uclass private data

  drivers/i2c/i2c-uclass.c | 22 ++++++++++++++++++++++
  1 file changed, 22 insertions(+)

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#19 lore raw

PATCH v2 5/7 i2c: dm: Record maximum id of devices before probing devices

In reply to Michal Simek

Hello Michal,

Am 31.01.2019 um 16:31 schrieb Michal Simek:

Quoted 6 lines

There is a need to find out the first free i2c ID which can be used for i2s buses (including i2c buses connected to i2c mux). Do it early in init and share this variable with other i2c classes for uniq bus identification.

Quoted 8 lines

---

Changes in v2:
- Use dev_read_alias_highest_id()
- Use uclass private data

  drivers/i2c/i2c-uclass.c | 22 ++++++++++++++++++++++
  1 file changed, 22 insertions(+)

Applied to u-boot-i2c.git master

with a fix for build error for omap based boards as discussed.

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#20 lore raw

PATCH v2 6/7 i2c: Fill req_seq in i2c_post_bind()

In reply to Michal Simek

For i2c controllers which are missing alias in DT there is no req_seq setup. This function is setting up proper ID based on highest found alias ID.

On zcu102 this is the behavior when patch is applied. ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 2: i2c at 0
Bus 3: i2c at 1
Bus 4: i2c at 2
Bus 1: i2c at ff030000 (active 1)
74: i2c-mux at 74, offset len 1, flags 0 75: i2c-mux at 75, offset len 1, flags 0
Bus 5: i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0
Bus 6: i2c at 1
Bus 7: i2c at 2
Bus 8: i2c at 3
Bus 9: i2c at 4
Bus 10: i2c at 0
Bus 11: i2c at 1
Bus 12: i2c at 2
Bus 13: i2c at 3
Bus 14: i2c at 4
Bus 15: i2c at 5
Bus 16: i2c at 6
Bus 17: i2c at 7

Before this patch applied (controllers have -1 ID) ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0 21: gpio at 21, offset len 1, flags 0 75: i2c-mux at 75, offset len 1, flags 0
Bus -1: i2c at 0
Bus -1: i2c at 1
Bus -1: i2c at 2
Bus 1: i2c at ff030000 (active 1)
74: i2c-mux at 74, offset len 1, flags 0 75: i2c-mux at 75, offset len 1, flags 0
Bus -1: i2c at 0 (active 0)
54: eeprom at 54, offset len 1, flags 0
Bus -1: i2c at 1
Bus -1: i2c at 2
Bus -1: i2c at 3
Bus -1: i2c at 4
Bus -1: i2c at 0
Bus -1: i2c at 1
Bus -1: i2c at 2
Bus -1: i2c at 3
Bus -1: i2c at 4
Bus -1: i2c at 5
Bus -1: i2c at 6
Bus -1: i2c at 7

---

Changes in v2:
- Use private uclass data

 drivers/i2c/i2c-uclass.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
drivers/i2c/i2c-uclass.c +25 -3
index b26602f3de95..6f3fca2d2326 100644
@@ -623,6 +623,30 @@ struct i2c_priv {
 	int max_id;
 };
 
+static int i2c_post_bind(struct udevice *dev)
+{
+	struct uclass *class = dev->uclass;
+	struct i2c_priv *priv = class->priv;
+	int ret = 0;
+
+	/* Just for sure */
+	if (!priv)
+		return -ENOMEM;
+
+	debug("%s: %s, req_seq=%d\n", __func__, dev->name, dev->req_seq);
+
+	/* if there is no alias ID, use the first free */
+	if (dev->req_seq == -1)
+		dev->req_seq = ++priv->max_id;
+
+	debug("%s: %s, new req_seq=%d\n", __func__, dev->name, dev->req_seq);
+
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
+	ret = dm_scan_fdt_dev(dev);
+#endif
+	return ret;
+}
+
 int i2c_uclass_init(struct uclass *class)
 {
 	struct i2c_priv *priv = class->priv;
@@ -643,9 +667,7 @@ UCLASS_DRIVER(i2c) = {
 	.id		= UCLASS_I2C,
 	.name		= "i2c",
 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
-#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
-	.post_bind	= dm_scan_fdt_dev,
-#endif
+	.post_bind	= i2c_post_bind,
 	.init		= i2c_uclass_init,
 	.priv_auto_alloc_size = sizeof(struct i2c_priv),
 	.post_probe	= i2c_post_probe,
Signature · 1 line
1.9.1
#21 lore raw

PATCH v2 6/7 i2c: Fill req_seq in i2c_post_bind()

Hello Michal,

Am 31.01.2019 um 16:31 schrieb Michal Simek:

Quoted 58 lines

For i2c controllers which are missing alias in DT there is no req_seq setup. This function is setting up proper ID based on highest found alias ID.

On zcu102 this is the behavior when patch is applied. ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 2: i2c at 0
Bus 3: i2c at 1
Bus 4: i2c at 2
Bus 1: i2c at ff030000 (active 1)

    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0

Bus 5: i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0
Bus 6: i2c at 1
Bus 7: i2c at 2
Bus 8: i2c at 3
Bus 9: i2c at 4
Bus 10: i2c at 0
Bus 11: i2c at 1
Bus 12: i2c at 2
Bus 13: i2c at 3
Bus 14: i2c at 4
Bus 15: i2c at 5
Bus 16: i2c at 6
Bus 17: i2c at 7

Before this patch applied (controllers have -1 ID) ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0 21: gpio at 21, offset len 1, flags 0 75: i2c-mux at 75, offset len 1, flags 0
Bus -1: i2c at 0
Bus -1: i2c at 1
Bus -1: i2c at 2
Bus 1: i2c at ff030000 (active 1)

    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0

Bus -1: i2c at 0 (active 0)
54: eeprom at 54, offset len 1, flags 0
Bus -1: i2c at 1
Bus -1: i2c at 2
Bus -1: i2c at 3
Bus -1: i2c at 4
Bus -1: i2c at 0
Bus -1: i2c at 1
Bus -1: i2c at 2
Bus -1: i2c at 3
Bus -1: i2c at 4
Bus -1: i2c at 5
Bus -1: i2c at 6
Bus -1: i2c at 7

Quoted 8 lines

---

Changes in v2:
- Use private uclass data

  drivers/i2c/i2c-uclass.c | 28 +++++++++++++++++++++++++---
  1 file changed, 25 insertions(+), 3 deletions(-)

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#22 lore raw

PATCH v2 6/7 i2c: Fill req_seq in i2c_post_bind()

In reply to Michal Simek

Hello Michal,

Am 31.01.2019 um 16:31 schrieb Michal Simek:

Quoted 58 lines

For i2c controllers which are missing alias in DT there is no req_seq setup. This function is setting up proper ID based on highest found alias ID.

On zcu102 this is the behavior when patch is applied. ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 2: i2c at 0
Bus 3: i2c at 1
Bus 4: i2c at 2
Bus 1: i2c at ff030000 (active 1)

    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0

Bus 5: i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0
Bus 6: i2c at 1
Bus 7: i2c at 2
Bus 8: i2c at 3
Bus 9: i2c at 4
Bus 10: i2c at 0
Bus 11: i2c at 1
Bus 12: i2c at 2
Bus 13: i2c at 3
Bus 14: i2c at 4
Bus 15: i2c at 5
Bus 16: i2c at 6
Bus 17: i2c at 7

Before this patch applied (controllers have -1 ID) ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0 21: gpio at 21, offset len 1, flags 0 75: i2c-mux at 75, offset len 1, flags 0
Bus -1: i2c at 0
Bus -1: i2c at 1
Bus -1: i2c at 2
Bus 1: i2c at ff030000 (active 1)

    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0

Bus -1: i2c at 0 (active 0)
54: eeprom at 54, offset len 1, flags 0
Bus -1: i2c at 1
Bus -1: i2c at 2
Bus -1: i2c at 3
Bus -1: i2c at 4
Bus -1: i2c at 0
Bus -1: i2c at 1
Bus -1: i2c at 2
Bus -1: i2c at 3
Bus -1: i2c at 4
Bus -1: i2c at 5
Bus -1: i2c at 6
Bus -1: i2c at 7

Quoted 8 lines

---

Changes in v2:
- Use private uclass data

  drivers/i2c/i2c-uclass.c | 28 +++++++++++++++++++++++++---
  1 file changed, 25 insertions(+), 3 deletions(-)

Applied to u-boot-i2c.git master

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#23 lore raw

PATCH v2 7/7 i2c: mux: Generate longer i2c mux name

In reply to Michal Simek

For !DM case busses are listed as
ZynqMP> i2c bus
Bus 0: zynq_0
Bus 1: zynq_0->PCA9544A at 0x75:0
Bus 2: zynq_0->PCA9544A at 0x75:1
Bus 3: zynq_0->PCA9544A at 0x75:2
Bus 4: zynq_1
Bus 5: zynq_1->PCA9548 at 0x74:0
Bus 6: zynq_1->PCA9548 at 0x74:1
Bus 7: zynq_1->PCA9548 at 0x74:2
Bus 8: zynq_1->PCA9548 at 0x74:3
Bus 9: zynq_1->PCA9548 at 0x74:4
Bus 10: zynq_1->PCA9548 at 0x75:0
Bus 11: zynq_1->PCA9548 at 0x75:1
Bus 12: zynq_1->PCA9548 at 0x75:2
Bus 13: zynq_1->PCA9548 at 0x75:3
Bus 14: zynq_1->PCA9548 at 0x75:4
Bus 15: zynq_1->PCA9548 at 0x75:5
Bus 16: zynq_1->PCA9548 at 0x75:6
Bus 17: zynq_1->PCA9548 at 0x75:7

where is exactly describing i2c bus topology.
By moving to DM case i2c mux buses are using names from DT and because i2c-muxes describing sub busses with the same names like i2c at 0, etc it is hard to identify which bus is where.
Linux is adding topology information to i2c-mux busses to identify them better.
This patch is doing the same and composing bus name with topology information.

When patch is applied with topology information on zcu102-revA. ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 2: i2c at ff020000->i2c-mux at 75->i2c at 0
Bus 3: i2c at ff020000->i2c-mux at 75->i2c at 1
Bus 4: i2c at ff020000->i2c-mux at 75->i2c at 2
Bus 1: i2c at ff030000 (active 1)
74: i2c-mux at 74, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0
Bus 6: i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 7: i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 8: i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 9: i2c at ff030000->i2c-mux at 74->i2c at 4
Bus 10: i2c at ff030000->i2c-mux at 75->i2c at 0
Bus 11: i2c at ff030000->i2c-mux at 75->i2c at 1
Bus 12: i2c at ff030000->i2c-mux at 75->i2c at 2
Bus 13: i2c at ff030000->i2c-mux at 75->i2c at 3
Bus 14: i2c at ff030000->i2c-mux at 75->i2c at 4
Bus 15: i2c at ff030000->i2c-mux at 75->i2c at 5
Bus 16: i2c at ff030000->i2c-mux at 75->i2c at 6
Bus 17: i2c at ff030000->i2c-mux at 75->i2c at 7

Behavior before the patch is applied.
ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 2: i2c at 0
Bus 3: i2c at 1
Bus 4: i2c at 2
Bus 1: i2c at ff030000 (active 1)
74: i2c-mux at 74, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 5: i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0
Bus 6: i2c at 1
Bus 7: i2c at 2
Bus 8: i2c at 3
Bus 9: i2c at 4
Bus 10: i2c at 0
Bus 11: i2c at 1
Bus 12: i2c at 2
Bus 13: i2c at 3
Bus 14: i2c at 4
Bus 15: i2c at 5
Bus 16: i2c at 6
Bus 17: i2c at 7

---

Changes in v2:
- Fix headers
- Change patch description to focus only on bus name

 drivers/i2c/muxes/i2c-mux-uclass.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
drivers/i2c/muxes/i2c-mux-uclass.c +26 -3
index a680ee176253..8b1149997a19 100644
@@ -59,11 +59,34 @@ static int i2c_mux_post_bind(struct udevice *mux)
 	dev_for_each_subnode(node, mux) {
 		struct udevice *dev;
 		const char *name;
+		const char *arrow = "->";
+		char *full_name;
+		int parent_name_len, arrow_len, mux_name_len, name_len;
 
 		name = ofnode_get_name(node);
-		ret = device_bind_driver_to_node(mux, "i2c_mux_bus_drv", name,
-						 node, &dev);
-		debug("   - bind ret=%d, %s\n", ret, dev ? dev->name : NULL);
+
+		/* Calculate lenghts of strings */
+		parent_name_len = strlen(mux->parent->name);
+		arrow_len = strlen(arrow);
+		mux_name_len = strlen(mux->name);
+		name_len = strlen(name);
+
+		full_name = calloc(1, parent_name_len + arrow_len +
+				   mux_name_len + arrow_len + name_len + 1);
+		if (!full_name)
+			return -ENOMEM;
+
+		/* Compose bus name */
+		strcat(full_name, mux->parent->name);
+		strcat(full_name, arrow);
+		strcat(full_name, mux->name);
+		strcat(full_name, arrow);
+		strcat(full_name, name);
+
+		ret = device_bind_driver_to_node(mux, "i2c_mux_bus_drv",
+						 full_name, node, &dev);
+		debug("   - bind ret=%d, %s, req_seq %d\n", ret,
+		      dev ? dev->name : NULL, dev->req_seq);
 		if (ret)
 			return ret;
 	}
Signature · 1 line
1.9.1
#24 lore raw

PATCH v2 7/7 i2c: mux: Generate longer i2c mux name

Quoted 86 lines · Michal Simek

For !DM case busses are listed as
ZynqMP> i2c bus

Bus 0:  zynq_0
Bus 1:  zynq_0->PCA9544A at 0x75:0
Bus 2:  zynq_0->PCA9544A at 0x75:1
Bus 3:  zynq_0->PCA9544A at 0x75:2
Bus 4:  zynq_1
Bus 5:  zynq_1->PCA9548 at 0x74:0
Bus 6:  zynq_1->PCA9548 at 0x74:1
Bus 7:  zynq_1->PCA9548 at 0x74:2
Bus 8:  zynq_1->PCA9548 at 0x74:3
Bus 9:  zynq_1->PCA9548 at 0x74:4
Bus 10: zynq_1->PCA9548 at 0x75:0
Bus 11: zynq_1->PCA9548 at 0x75:1
Bus 12: zynq_1->PCA9548 at 0x75:2
Bus 13: zynq_1->PCA9548 at 0x75:3
Bus 14: zynq_1->PCA9548 at 0x75:4
Bus 15: zynq_1->PCA9548 at 0x75:5
Bus 16: zynq_1->PCA9548 at 0x75:6
Bus 17: zynq_1->PCA9548 at 0x75:7

where is exactly describing i2c bus topology.
By moving to DM case i2c mux buses are using names from DT and because i2c-muxes describing sub busses with the same names like i2c at 0, etc it is hard to identify which bus is where.
Linux is adding topology information to i2c-mux busses to identify them better.
This patch is doing the same and composing bus name with topology information.

When patch is applied with topology information on zcu102-revA. ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0

Bus 2:  i2c at ff020000->i2c-mux at 75->i2c at 0
Bus 3:  i2c at ff020000->i2c-mux at 75->i2c at 1
Bus 4:  i2c at ff020000->i2c-mux at 75->i2c at 2
Bus 1:  i2c at ff030000  (active 1)

74: i2c-mux at 74, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0

Bus 6:  i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 7:  i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 8:  i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 9:  i2c at ff030000->i2c-mux at 74->i2c at 4
Bus 10: i2c at ff030000->i2c-mux at 75->i2c at 0
Bus 11: i2c at ff030000->i2c-mux at 75->i2c at 1
Bus 12: i2c at ff030000->i2c-mux at 75->i2c at 2
Bus 13: i2c at ff030000->i2c-mux at 75->i2c at 3
Bus 14: i2c at ff030000->i2c-mux at 75->i2c at 4
Bus 15: i2c at ff030000->i2c-mux at 75->i2c at 5
Bus 16: i2c at ff030000->i2c-mux at 75->i2c at 6
Bus 17: i2c at ff030000->i2c-mux at 75->i2c at 7

Behavior before the patch is applied.
ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0

Bus 2:  i2c at 0
Bus 3:  i2c at 1
Bus 4:  i2c at 2
Bus 1:  i2c at ff030000  (active 1)

74: i2c-mux at 74, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 5: i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0

Bus 6:  i2c at 1
Bus 7:  i2c at 2
Bus 8:  i2c at 3
Bus 9:  i2c at 4
Bus 10: i2c at 0
Bus 11: i2c at 1
Bus 12: i2c at 2
Bus 13: i2c at 3
Bus 14: i2c at 4
Bus 15: i2c at 5
Bus 16: i2c at 6
Bus 17: i2c at 7
Quoted 8 lines

---

Changes in v2:
- Fix headers
- Change patch description to focus only on bus name

 drivers/i2c/muxes/i2c-mux-uclass.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
#25 lore raw

PATCH v2 7/7 i2c: mux: Generate longer i2c mux name

In reply to Michal Simek

Hello Michal,

Am 31.01.2019 um 16:31 schrieb Michal Simek:

Quoted 85 lines

For !DM case busses are listed as
ZynqMP> i2c bus
Bus 0: zynq_0
Bus 1: zynq_0->PCA9544A at 0x75:0
Bus 2: zynq_0->PCA9544A at 0x75:1
Bus 3: zynq_0->PCA9544A at 0x75:2
Bus 4: zynq_1
Bus 5: zynq_1->PCA9548 at 0x74:0
Bus 6: zynq_1->PCA9548 at 0x74:1
Bus 7: zynq_1->PCA9548 at 0x74:2
Bus 8: zynq_1->PCA9548 at 0x74:3
Bus 9: zynq_1->PCA9548 at 0x74:4
Bus 10: zynq_1->PCA9548 at 0x75:0
Bus 11: zynq_1->PCA9548 at 0x75:1
Bus 12: zynq_1->PCA9548 at 0x75:2
Bus 13: zynq_1->PCA9548 at 0x75:3
Bus 14: zynq_1->PCA9548 at 0x75:4
Bus 15: zynq_1->PCA9548 at 0x75:5
Bus 16: zynq_1->PCA9548 at 0x75:6
Bus 17: zynq_1->PCA9548 at 0x75:7

where is exactly describing i2c bus topology.
By moving to DM case i2c mux buses are using names from DT and because i2c-muxes describing sub busses with the same names like i2c at 0, etc it is hard to identify which bus is where.
Linux is adding topology information to i2c-mux busses to identify them better.
This patch is doing the same and composing bus name with topology information.

When patch is applied with topology information on zcu102-revA. ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 2: i2c at ff020000->i2c-mux at 75->i2c at 0
Bus 3: i2c at ff020000->i2c-mux at 75->i2c at 1
Bus 4: i2c at ff020000->i2c-mux at 75->i2c at 2
Bus 1: i2c at ff030000 (active 1)

    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0

Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0
Bus 6: i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 7: i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 8: i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 9: i2c at ff030000->i2c-mux at 74->i2c at 4
Bus 10: i2c at ff030000->i2c-mux at 75->i2c at 0
Bus 11: i2c at ff030000->i2c-mux at 75->i2c at 1
Bus 12: i2c at ff030000->i2c-mux at 75->i2c at 2
Bus 13: i2c at ff030000->i2c-mux at 75->i2c at 3
Bus 14: i2c at ff030000->i2c-mux at 75->i2c at 4
Bus 15: i2c at ff030000->i2c-mux at 75->i2c at 5
Bus 16: i2c at ff030000->i2c-mux at 75->i2c at 6
Bus 17: i2c at ff030000->i2c-mux at 75->i2c at 7

Behavior before the patch is applied.
ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 2: i2c at 0
Bus 3: i2c at 1
Bus 4: i2c at 2
Bus 1: i2c at ff030000 (active 1)

    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0

Bus 5: i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0
Bus 6: i2c at 1
Bus 7: i2c at 2
Bus 8: i2c at 3
Bus 9: i2c at 4
Bus 10: i2c at 0
Bus 11: i2c at 1
Bus 12: i2c at 2
Bus 13: i2c at 3
Bus 14: i2c at 4
Bus 15: i2c at 5
Bus 16: i2c at 6
Bus 17: i2c at 7

Quoted 8 lines

---

Changes in v2:
- Fix headers
- Change patch description to focus only on bus name

  drivers/i2c/muxes/i2c-mux-uclass.c | 29 ++++++++++++++++++++++++++---
  1 file changed, 26 insertions(+), 3 deletions(-)

Much more cleaner output, thanks!

I have no chance to test this on another hardware, so if someone could test it, this would be nice.

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#26 lore raw

PATCH v2 7/7 i2c: mux: Generate longer i2c mux name

In reply to Michal Simek

Hello Michal,

Am 31.01.2019 um 16:31 schrieb Michal Simek:

Quoted 85 lines

For !DM case busses are listed as
ZynqMP> i2c bus
Bus 0: zynq_0
Bus 1: zynq_0->PCA9544A at 0x75:0
Bus 2: zynq_0->PCA9544A at 0x75:1
Bus 3: zynq_0->PCA9544A at 0x75:2
Bus 4: zynq_1
Bus 5: zynq_1->PCA9548 at 0x74:0
Bus 6: zynq_1->PCA9548 at 0x74:1
Bus 7: zynq_1->PCA9548 at 0x74:2
Bus 8: zynq_1->PCA9548 at 0x74:3
Bus 9: zynq_1->PCA9548 at 0x74:4
Bus 10: zynq_1->PCA9548 at 0x75:0
Bus 11: zynq_1->PCA9548 at 0x75:1
Bus 12: zynq_1->PCA9548 at 0x75:2
Bus 13: zynq_1->PCA9548 at 0x75:3
Bus 14: zynq_1->PCA9548 at 0x75:4
Bus 15: zynq_1->PCA9548 at 0x75:5
Bus 16: zynq_1->PCA9548 at 0x75:6
Bus 17: zynq_1->PCA9548 at 0x75:7

where is exactly describing i2c bus topology.
By moving to DM case i2c mux buses are using names from DT and because i2c-muxes describing sub busses with the same names like i2c at 0, etc it is hard to identify which bus is where.
Linux is adding topology information to i2c-mux busses to identify them better.
This patch is doing the same and composing bus name with topology information.

When patch is applied with topology information on zcu102-revA. ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 2: i2c at ff020000->i2c-mux at 75->i2c at 0
Bus 3: i2c at ff020000->i2c-mux at 75->i2c at 1
Bus 4: i2c at ff020000->i2c-mux at 75->i2c at 2
Bus 1: i2c at ff030000 (active 1)

    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0

Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0
Bus 6: i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 7: i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 8: i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 9: i2c at ff030000->i2c-mux at 74->i2c at 4
Bus 10: i2c at ff030000->i2c-mux at 75->i2c at 0
Bus 11: i2c at ff030000->i2c-mux at 75->i2c at 1
Bus 12: i2c at ff030000->i2c-mux at 75->i2c at 2
Bus 13: i2c at ff030000->i2c-mux at 75->i2c at 3
Bus 14: i2c at ff030000->i2c-mux at 75->i2c at 4
Bus 15: i2c at ff030000->i2c-mux at 75->i2c at 5
Bus 16: i2c at ff030000->i2c-mux at 75->i2c at 6
Bus 17: i2c at ff030000->i2c-mux at 75->i2c at 7

Behavior before the patch is applied.
ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 2: i2c at 0
Bus 3: i2c at 1
Bus 4: i2c at 2
Bus 1: i2c at ff030000 (active 1)

    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0

Bus 5: i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0
Bus 6: i2c at 1
Bus 7: i2c at 2
Bus 8: i2c at 3
Bus 9: i2c at 4
Bus 10: i2c at 0
Bus 11: i2c at 1
Bus 12: i2c at 2
Bus 13: i2c at 3
Bus 14: i2c at 4
Bus 15: i2c at 5
Bus 16: i2c at 6
Bus 17: i2c at 7

Quoted 8 lines

---

Changes in v2:
- Fix headers
- Change patch description to focus only on bus name

  drivers/i2c/muxes/i2c-mux-uclass.c | 29 ++++++++++++++++++++++++++---
  1 file changed, 26 insertions(+), 3 deletions(-)

Applied to u-boot-i2c.git master

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#27 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

In reply to Michal Simek

Hi Michal,

Quoted 42 lines · Michal Simek

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0

Bus 1:  i2c at ff020000->i2c-mux at 75->i2c at 0
Bus 2:  i2c at ff020000->i2c-mux at 75->i2c at 1
Bus 3:  i2c at ff020000->i2c-mux at 75->i2c at 2
Bus 4:  i2c at ff030000  (active 4)

74: i2c-mux at 74, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0

Bus 6:  i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 7:  i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 8:  i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 9:  i2c at ff030000->i2c-mux at 74->i2c at 4
Bus 10: i2c at ff030000->i2c-mux at 75->i2c at 0
Bus 11: i2c at ff030000->i2c-mux at 75->i2c at 1
Bus 12: i2c at ff030000->i2c-mux at 75->i2c at 2
Bus 13: i2c at ff030000->i2c-mux at 75->i2c at 3
Bus 14: i2c at ff030000->i2c-mux at 75->i2c at 4
Bus 15: i2c at ff030000->i2c-mux at 75->i2c at 5
Bus 16: i2c at ff030000->i2c-mux at 75->i2c at 6
Bus 17: i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Quoted 10 lines

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

I don't have strong objections to this series, but I'd still like to try a bit harder on the existing req_seq/seq stuff.

I don't think we necessarily need to set the 'seq' before probe, although I suppose we could.

But is there anything to stop us moving some of the logic which sets seq to setting req_seq? We could check the aliases and then set req_seq during bind(), perhaps?

This would be better for code size since it would help all subsystems.

Regards,
Simon

#28 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

Hi Simon,

Quoted 59 lines · Simon Glass

Hi Michal,

Quoted 42 lines · Michal Simek

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0

Bus 1:  i2c at ff020000->i2c-mux at 75->i2c at 0
Bus 2:  i2c at ff020000->i2c-mux at 75->i2c at 1
Bus 3:  i2c at ff020000->i2c-mux at 75->i2c at 2
Bus 4:  i2c at ff030000  (active 4)

74: i2c-mux at 74, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0

Bus 6:  i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 7:  i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 8:  i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 9:  i2c at ff030000->i2c-mux at 74->i2c at 4
Bus 10: i2c at ff030000->i2c-mux at 75->i2c at 0
Bus 11: i2c at ff030000->i2c-mux at 75->i2c at 1
Bus 12: i2c at ff030000->i2c-mux at 75->i2c at 2
Bus 13: i2c at ff030000->i2c-mux at 75->i2c at 3
Bus 14: i2c at ff030000->i2c-mux at 75->i2c at 4
Bus 15: i2c at ff030000->i2c-mux at 75->i2c at 5
Bus 16: i2c at ff030000->i2c-mux at 75->i2c at 6
Bus 17: i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Quoted 10 lines

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

I don't have strong objections to this series, but I'd still like to try a bit harder on the existing req_seq/seq stuff.

Quoted 6 lines

I don't think we necessarily need to set the 'seq' before probe, although I suppose we could.

But is there anything to stop us moving some of the logic which sets seq to setting req_seq? We could check the aliases and then set req_seq during bind(), perhaps?

Let me put this to my TODO list. But it is not a task which you know will be done in some hours. It requires to study the whole logic if this works for all cases.

Quoted 1 line

This would be better for code size since it would help all subsystems.

This approach is used in the linux kernel that's why there is no way to get rid of dev_read_alias_highest_id() as function.
It means only i2c_uclass_init() and little code in i2c_post_bind() could be removed. That's why I don't think we will improve size a lot. If this is copied to other subsystems then yes it will be more useful. If we have just one now we can't save a lot.

Heiko: Can you please take a look at this series? I have another 7 patches on the top of this series which depends on it which cleanup all zynq/zynqmp platforms and I would like to close this to be able to move.

Thanks,
Michal

#29 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

Hello Michal,

Am 05.02.2019 um 08:57 schrieb Michal Simek:

Quoted 65 lines

Hi Simon,

Quoted 62 lines · Simon Glass

Hi Michal,

Quoted 42 lines · Michal Simek

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0

Bus 1:  i2c at ff020000->i2c-mux at 75->i2c at 0
Bus 2:  i2c at ff020000->i2c-mux at 75->i2c at 1
Bus 3:  i2c at ff020000->i2c-mux at 75->i2c at 2
Bus 4:  i2c at ff030000  (active 4)
    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0
Bus 5:  i2c at ff030000->i2c-mux at 74->i2c at 0  (active 5)
    54: eeprom at 54, offset len 1, flags 0
Bus 6:  i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 7:  i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 8:  i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 9:  i2c at ff030000->i2c-mux at 74->i2c at 4
Bus 10: i2c at ff030000->i2c-mux at 75->i2c at 0
Bus 11: i2c at ff030000->i2c-mux at 75->i2c at 1
Bus 12: i2c at ff030000->i2c-mux at 75->i2c at 2
Bus 13: i2c at ff030000->i2c-mux at 75->i2c at 3
Bus 14: i2c at ff030000->i2c-mux at 75->i2c at 4
Bus 15: i2c at ff030000->i2c-mux at 75->i2c at 5
Bus 16: i2c at ff030000->i2c-mux at 75->i2c at 6
Bus 17: i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Quoted 10 lines

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

I don't have strong objections to this series, but I'd still like to try a bit harder on the existing req_seq/seq stuff.

I don't think we necessarily need to set the 'seq' before probe, although I suppose we could.

Quoted 7 lines
Quoted 3 lines

But is there anything to stop us moving some of the logic which sets seq to setting req_seq? We could check the aliases and then set req_seq during bind(), perhaps?

Let me put this to my TODO list. But it is not a task which you know will be done in some hours. It requires to study the whole logic if this works for all cases.

For me it is okay to do this in a second step.

@Simon: Can you give the patcheseries a formal Reviewed-by?

Quoted 9 lines
Quoted 1 line

This would be better for code size since it would help all subsystems.

This approach is used in the linux kernel that's why there is no way to get rid of dev_read_alias_highest_id() as function.
It means only i2c_uclass_init() and little code in i2c_post_bind() could be removed. That's why I don't think we will improve size a lot. If this is copied to other subsystems then yes it will be more useful. If we have just one now we can't save a lot.

Quoted 3 lines

Heiko: Can you please take a look at this series? I have another 7 patches on the top of this series which depends on it which cleanup all zynq/zynqmp platforms and I would like to close this to be able to move.

ASAP as I was ill the last 2 weeks ... sorry, give me some time.

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#30 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

Quoted 74 lines · Heiko Schocher

Hello Michal,

Am 05.02.2019 um 08:57 schrieb Michal Simek:

Quoted 71 lines

Hi Simon,

Quoted 67 lines · Simon Glass

Hi Michal,

Quoted 43 lines · Michal Simek

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which
are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0:  i2c at ff020000
    20: gpio at 20, offset len 1, flags 0
    21: gpio at 21, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0
Bus 1:  i2c at ff020000->i2c-mux at 75->i2c at 0 Bus 2:  i2c at ff020000->i2c-mux at 75->i2c at 1 Bus 3:  i2c at ff020000->i2c-mux at 75->i2c at 2 Bus 4:  i2c at ff030000  (active 4)
    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0
Bus 5:  i2c at ff030000->i2c-mux at 74->i2c at 0  (active 5) 54: eeprom at 54, offset len 1, flags 0
Bus 6:  i2c at ff030000->i2c-mux at 74->i2c at 1 Bus 7:  i2c at ff030000->i2c-mux at 74->i2c at 2 Bus 8:  i2c at ff030000->i2c-mux at 74->i2c at 3 Bus 9:  i2c at ff030000->i2c-mux at 74->i2c at 4 Bus 10: i2c at ff030000->i2c-mux at 75->i2c at 0 Bus 11: i2c at ff030000->i2c-mux at 75->i2c at 1 Bus 12: i2c at ff030000->i2c-mux at 75->i2c at 2 Bus 13: i2c at ff030000->i2c-mux at 75->i2c at 3 Bus 14: i2c at ff030000->i2c-mux at 75->i2c at 4 Bus 15: i2c at ff030000->i2c-mux at 75->i2c at 5 Bus 16: i2c at ff030000->i2c-mux at 75->i2c at 6 Bus 17: i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Quoted 10 lines

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

I don't have strong objections to this series, but I'd still like to try a bit harder on the existing req_seq/seq stuff.

I don't think we necessarily need to set the 'seq' before probe, although I suppose we could.

But is there anything to stop us moving some of the logic which sets seq to setting req_seq? We could check the aliases and then set req_seq during bind(), perhaps?

Quoted 7 lines
Quoted 3 lines

Let me put this to my TODO list. But it is not a task which you know will be done in some hours. It requires to study the whole logic if this works for all cases.

For me it is okay to do this in a second step.

@Simon: Can you give the patcheseries a formal Reviewed-by?

Thanks for this I wanted Simon to ask about it too.

Quoted 9 lines
Quoted 9 lines
Quoted 1 line

This would be better for code size since it would help all subsystems.

This approach is used in the linux kernel that's why there is no way to get rid of dev_read_alias_highest_id() as function.
It means only i2c_uclass_init() and little code in i2c_post_bind() could be removed. That's why I don't think we will improve size a lot. If this is copied to other subsystems then yes it will be more useful. If we have just one now we can't save a lot.

Quoted 5 lines
Quoted 3 lines

Heiko: Can you please take a look at this series? I have another 7 patches on the top of this series which depends on it which cleanup all zynq/zynqmp platforms and I would like to close this to be able to move.

ASAP as I was ill the last 2 weeks ... sorry, give me some time.

Sure.

Thanks,
Michal

#31 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

In reply to Michal Simek

Hi Michal,

Quoted 70 lines · Michal Simek

Hi Simon,

Quoted 59 lines · Simon Glass

Hi Michal,

Quoted 42 lines · Michal Simek

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0

Bus 1:  i2c at ff020000->i2c-mux at 75->i2c at 0
Bus 2:  i2c at ff020000->i2c-mux at 75->i2c at 1
Bus 3:  i2c at ff020000->i2c-mux at 75->i2c at 2
Bus 4:  i2c at ff030000  (active 4)

74: i2c-mux at 74, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0

Bus 6:  i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 7:  i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 8:  i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 9:  i2c at ff030000->i2c-mux at 74->i2c at 4
Bus 10: i2c at ff030000->i2c-mux at 75->i2c at 0
Bus 11: i2c at ff030000->i2c-mux at 75->i2c at 1
Bus 12: i2c at ff030000->i2c-mux at 75->i2c at 2
Bus 13: i2c at ff030000->i2c-mux at 75->i2c at 3
Bus 14: i2c at ff030000->i2c-mux at 75->i2c at 4
Bus 15: i2c at ff030000->i2c-mux at 75->i2c at 5
Bus 16: i2c at ff030000->i2c-mux at 75->i2c at 6
Bus 17: i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Quoted 10 lines

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

I don't have strong objections to this series, but I'd still like to try a bit harder on the existing req_seq/seq stuff.

Quoted 6 lines

I don't think we necessarily need to set the 'seq' before probe, although I suppose we could.

But is there anything to stop us moving some of the logic which sets seq to setting req_seq? We could check the aliases and then set req_seq during bind(), perhaps?

Quoted 8 lines

Let me put this to my TODO list. But it is not a task which you know will be done in some hours. It requires to study the whole logic if this works for all cases.

Quoted 1 line

This would be better for code size since it would help all subsystems.

This approach is used in the linux kernel that's why there is no way to get rid of dev_read_alias_highest_id() as function.

Yes that function seems useful to me.

Quoted 4 lines

It means only i2c_uclass_init() and little code in i2c_post_bind() could be removed. That's why I don't think we will improve size a lot. If this is copied to other subsystems then yes it will be more useful. If we have just one now we can't save a lot.

Well maybe, but of course the problem you are fixing applies to other subsystems too, doesn't it?

Quoted 4 lines

Heiko: Can you please take a look at this series? I have another 7 patches on the top of this series which depends on it which cleanup all zynq/zynqmp platforms and I would like to close this to be able to move.

Regards,
Simon

#32 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

Hi Simon,

Quoted 84 lines · Simon Glass

Hi Michal,

Quoted 70 lines · Michal Simek

Hi Simon,

Quoted 59 lines · Simon Glass

Hi Michal,

Quoted 42 lines · Michal Simek

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0

Bus 1:  i2c at ff020000->i2c-mux at 75->i2c at 0
Bus 2:  i2c at ff020000->i2c-mux at 75->i2c at 1
Bus 3:  i2c at ff020000->i2c-mux at 75->i2c at 2
Bus 4:  i2c at ff030000  (active 4)

74: i2c-mux at 74, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0

Bus 6:  i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 7:  i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 8:  i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 9:  i2c at ff030000->i2c-mux at 74->i2c at 4
Bus 10: i2c at ff030000->i2c-mux at 75->i2c at 0
Bus 11: i2c at ff030000->i2c-mux at 75->i2c at 1
Bus 12: i2c at ff030000->i2c-mux at 75->i2c at 2
Bus 13: i2c at ff030000->i2c-mux at 75->i2c at 3
Bus 14: i2c at ff030000->i2c-mux at 75->i2c at 4
Bus 15: i2c at ff030000->i2c-mux at 75->i2c at 5
Bus 16: i2c at ff030000->i2c-mux at 75->i2c at 6
Bus 17: i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Quoted 10 lines

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

I don't have strong objections to this series, but I'd still like to try a bit harder on the existing req_seq/seq stuff.

Quoted 6 lines

I don't think we necessarily need to set the 'seq' before probe, although I suppose we could.

But is there anything to stop us moving some of the logic which sets seq to setting req_seq? We could check the aliases and then set req_seq during bind(), perhaps?

Quoted 8 lines

Let me put this to my TODO list. But it is not a task which you know will be done in some hours. It requires to study the whole logic if this works for all cases.

Quoted 1 line

This would be better for code size since it would help all subsystems.

This approach is used in the linux kernel that's why there is no way to get rid of dev_read_alias_highest_id() as function.

Yes that function seems useful to me.

Quoted 7 lines
Quoted 4 lines

It means only i2c_uclass_init() and little code in i2c_post_bind() could be removed. That's why I don't think we will improve size a lot. If this is copied to other subsystems then yes it will be more useful. If we have just one now we can't save a lot.

Well maybe, but of course the problem you are fixing applies to other subsystems too, doesn't it?

In Linux i2c came with this solution in connection to DT guys where aliases are stable and even adding overlay can't update it/change it.

If you grep of_alias_get_highest_id you will find out that there is one more which is spi and that's it.

This is commit message from Linux regarding spi.

commit 226584aedd94acd61ffa51fb69bcf6b3309a7b8f

Author:     Lucas Stach <[email protected]>
AuthorDate: Mon Oct 16 12:27:58 2017 +0200
Commit:     Mark Brown <[email protected]>
CommitDate: Mon Oct 16 21:02:54 2017 +0100

spi: fix IDR collision on systems with both fixed and dynamic SPI
bus numbers

On systems where some controllers get a dynamic ID assigned and some
have
a fixed number from DT, the current implemention might run into an IDR collision if the dynamic controllers gets probed first and get an
IDR number,
which is later requested by the controller with the fixed numbering.
When
this happens the fixed controller will fail to register with the SPI
core.

Fix this by skipping all known alias numbers when assigning the
dynamic IDs.

Fixes 9b61e302210e (spi: Pick spi bus number from Linux idr or spi

alias)

Thanks,
Michal

Signature · 14 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190208/f5b0d2ba/attachment.sig>
#33 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

In reply to Michal Simek

Hello Michael,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 61 lines

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0: i2c at ff020000
20: gpio at 20, offset len 1, flags 0
21: gpio at 21, offset len 1, flags 0
75: i2c-mux at 75, offset len 1, flags 0
Bus 1: i2c at ff020000->i2c-mux at 75->i2c at 0
Bus 2: i2c at ff020000->i2c-mux at 75->i2c at 1
Bus 3: i2c at ff020000->i2c-mux at 75->i2c at 2
Bus 4: i2c at ff030000 (active 4)

    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0

Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 5)
54: eeprom at 54, offset len 1, flags 0
Bus 6: i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 7: i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 8: i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 9: i2c at ff030000->i2c-mux at 74->i2c at 4
Bus 10: i2c at ff030000->i2c-mux at 75->i2c at 0
Bus 11: i2c at ff030000->i2c-mux at 75->i2c at 1
Bus 12: i2c at ff030000->i2c-mux at 75->i2c at 2
Bus 13: i2c at ff030000->i2c-mux at 75->i2c at 3
Bus 14: i2c at ff030000->i2c-mux at 75->i2c at 4
Bus 15: i2c at ff030000->i2c-mux at 75->i2c at 5
Bus 16: i2c at ff030000->i2c-mux at 75->i2c at 6
Bus 17: i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

Michal Simek (7):
dm: core: Add of_alias_get_highest_id()
fdt: Introduce fdtdec_get_alias_highest_id()
dm: core: Introduce dev_read_alias_highest_id()
dm: core: Add tests for dev_read_alias_highest_id()
i2c: dm: Record maximum id of devices before probing devices
i2c: Fill req_seq in i2c_post_bind()
i2c: mux: Generate longer i2c mux name

Quoted 11 lines
  drivers/core/of_access.c           | 18 ++++++++++++++
  drivers/core/read.c                |  8 ++++++
  drivers/i2c/i2c-uclass.c           | 50 +++++++++++++++++++++++++++++++++++---
  drivers/i2c/muxes/i2c-mux-uclass.c | 29 +++++++++++++++++++---
  include/dm/of_access.h             | 10 ++++++++
  include/dm/read.h                  | 16 ++++++++++++
  include/fdtdec.h                   | 13 ++++++++++
  lib/fdtdec.c                       | 33 +++++++++++++++++++++++++
  test/dm/test-fdt.c                 | 23 ++++++++++++++++++
  9 files changed, 194 insertions(+), 6 deletions(-)

I just applied your patches and triggered a build on travis:

It shows error for omap boards:

https://travis-ci.org/hsdenx/u-boot-i2c/jobs/490393822

I try to find time to look into it, but may you have time too?

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#34 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

Quoted 77 lines · Heiko Schocher

Hello Michael,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 71 lines

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0:    i2c at ff020000
    20: gpio at 20, offset len 1, flags 0
    21: gpio at 21, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0
Bus 1:    i2c at ff020000->i2c-mux at 75->i2c at 0 Bus 2:    i2c at ff020000->i2c-mux at 75->i2c at 1 Bus 3:    i2c at ff020000->i2c-mux at 75->i2c at 2 Bus 4:    i2c at ff030000  (active 4)
    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0
Bus 5:    i2c at ff030000->i2c-mux at 74->i2c at 0  (active 5) 54: eeprom at 54, offset len 1, flags 0
Bus 6:    i2c at ff030000->i2c-mux at 74->i2c at 1 Bus 7:    i2c at ff030000->i2c-mux at 74->i2c at 2 Bus 8:    i2c at ff030000->i2c-mux at 74->i2c at 3 Bus 9:    i2c at ff030000->i2c-mux at 74->i2c at 4 Bus 10:    i2c at ff030000->i2c-mux at 75->i2c at 0 Bus 11:    i2c at ff030000->i2c-mux at 75->i2c at 1 Bus 12:    i2c at ff030000->i2c-mux at 75->i2c at 2 Bus 13:    i2c at ff030000->i2c-mux at 75->i2c at 3 Bus 14:    i2c at ff030000->i2c-mux at 75->i2c at 4 Bus 15:    i2c at ff030000->i2c-mux at 75->i2c at 5 Bus 16:    i2c at ff030000->i2c-mux at 75->i2c at 6 Bus 17:    i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

Michal Simek (7):
   dm: core: Add of_alias_get_highest_id()
   fdt: Introduce fdtdec_get_alias_highest_id()
   dm: core: Introduce dev_read_alias_highest_id()
   dm: core: Add tests for dev_read_alias_highest_id()
   i2c: dm: Record maximum id of devices before probing devices
   i2c: Fill req_seq in i2c_post_bind()
   i2c: mux: Generate longer i2c mux name

  drivers/core/of_access.c           | 18 ++++++++++++++ drivers/core/read.c                |  8 ++++++ drivers/i2c/i2c-uclass.c           | 50
+++++++++++++++++++++++++++++++++++---
  drivers/i2c/muxes/i2c-mux-uclass.c | 29 +++++++++++++++++++--- include/dm/of_access.h             | 10 ++++++++ include/dm/read.h                  | 16 ++++++++++++ include/fdtdec.h                   | 13 ++++++++++ lib/fdtdec.c                       | 33 +++++++++++++++++++++++++ test/dm/test-fdt.c                 | 23 ++++++++++++++++++

Quoted 2 lines
  9 files changed, 194 insertions(+), 6 deletions(-)
Quoted 8 lines

I just applied your patches and triggered a build on travis:

It shows error for omap boards:

https://travis-ci.org/hsdenx/u-boot-i2c/jobs/490393822

I try to find time to look into it, but may you have time too?

This should be the fix. (I tried that on omap35_logic_somlv_defconfig)

drivers/i2c/i2c-uclass.c +4 -0
index 6f3fca2d2326..391fb1289983 100644
@@ -655,8 +655,12 @@ int i2c_uclass_init(struct uclass *class)
        if (!priv)
                return -ENOMEM;
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
        /* Get the last allocated alias. */
        priv->max_id = dev_read_alias_highest_id("i2c");
+#else
+       priv->max_id = -1;
+#endif
 
        debug("%s: highest alias id is %d\n", __func__, priv->max_id);
 

SPL has no OF_CONTROL and also no LIBFDT that's why it is trying to call it.

Thanks,
Michal

Signature · 14 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190208/7fcd5620/attachment.sig>
#35 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

Quoted 107 lines · Michal Simek
Quoted 77 lines · Heiko Schocher

Hello Michael,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 71 lines

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0:    i2c at ff020000
    20: gpio at 20, offset len 1, flags 0
    21: gpio at 21, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0
Bus 1:    i2c at ff020000->i2c-mux at 75->i2c at 0 Bus 2:    i2c at ff020000->i2c-mux at 75->i2c at 1 Bus 3:    i2c at ff020000->i2c-mux at 75->i2c at 2 Bus 4:    i2c at ff030000  (active 4)
    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0
Bus 5:    i2c at ff030000->i2c-mux at 74->i2c at 0  (active 5) 54: eeprom at 54, offset len 1, flags 0
Bus 6:    i2c at ff030000->i2c-mux at 74->i2c at 1 Bus 7:    i2c at ff030000->i2c-mux at 74->i2c at 2 Bus 8:    i2c at ff030000->i2c-mux at 74->i2c at 3 Bus 9:    i2c at ff030000->i2c-mux at 74->i2c at 4 Bus 10:    i2c at ff030000->i2c-mux at 75->i2c at 0 Bus 11:    i2c at ff030000->i2c-mux at 75->i2c at 1 Bus 12:    i2c at ff030000->i2c-mux at 75->i2c at 2 Bus 13:    i2c at ff030000->i2c-mux at 75->i2c at 3 Bus 14:    i2c at ff030000->i2c-mux at 75->i2c at 4 Bus 15:    i2c at ff030000->i2c-mux at 75->i2c at 5 Bus 16:    i2c at ff030000->i2c-mux at 75->i2c at 6 Bus 17:    i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

Michal Simek (7):
   dm: core: Add of_alias_get_highest_id()
   fdt: Introduce fdtdec_get_alias_highest_id()
   dm: core: Introduce dev_read_alias_highest_id()
   dm: core: Add tests for dev_read_alias_highest_id()
   i2c: dm: Record maximum id of devices before probing devices
   i2c: Fill req_seq in i2c_post_bind()
   i2c: mux: Generate longer i2c mux name

  drivers/core/of_access.c           | 18 ++++++++++++++ drivers/core/read.c                |  8 ++++++ drivers/i2c/i2c-uclass.c           | 50
+++++++++++++++++++++++++++++++++++---
  drivers/i2c/muxes/i2c-mux-uclass.c | 29 +++++++++++++++++++--- include/dm/of_access.h             | 10 ++++++++ include/dm/read.h                  | 16 ++++++++++++ include/fdtdec.h                   | 13 ++++++++++ lib/fdtdec.c                       | 33 +++++++++++++++++++++++++ test/dm/test-fdt.c                 | 23 ++++++++++++++++++

Quoted 2 lines
  9 files changed, 194 insertions(+), 6 deletions(-)
Quoted 8 lines

I just applied your patches and triggered a build on travis:

It shows error for omap boards:

https://travis-ci.org/hsdenx/u-boot-i2c/jobs/490393822

I try to find time to look into it, but may you have time too?

This should be the fix. (I tried that on omap35_logic_somlv_defconfig)

drivers/i2c/i2c-uclass.c +4 -0
index 6f3fca2d2326..391fb1289983 100644
@@ -655,8 +655,12 @@ int i2c_uclass_init(struct uclass *class)
        if (!priv)
                return -ENOMEM;
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
        /* Get the last allocated alias. */
        priv->max_id = dev_read_alias_highest_id("i2c");
+#else
+       priv->max_id = -1;
+#endif
 
        debug("%s: highest alias id is %d\n", __func__, priv->max_id);
 
Quoted 2 lines

SPL has no OF_CONTROL and also no LIBFDT that's why it is trying to call it.

:-) that sentence doesn't make sense. Correction:
...that's why it shouldn't be called.

Maybe it should be enough to have dependency on OF_LIBFDT but Kconfig is saying that OF_LIBFDT is bool setup to y when OF_CONTROL is enabled. And in Makefile fdtdec is enabled

obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += fdtdec.o
or just
obj-$(CONFIG_OF_LIBFDT) += fdtdec.o

Anyway it should be likely enough to have dependency just on OF_LIBFDT.

Thanks,
Michal

Signature · 14 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190208/5933a337/attachment.sig>
#36 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

Hello Michal,

Am 08.02.2019 um 12:24 schrieb Michal Simek:

Quoted 105 lines · Michal Simek
Quoted 104 lines · Heiko Schocher
Quoted 77 lines

Hello Michael,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 61 lines

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0:    i2c at ff020000
    20: gpio at 20, offset len 1, flags 0
    21: gpio at 21, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0
Bus 1:    i2c at ff020000->i2c-mux at 75->i2c at 0 Bus 2:    i2c at ff020000->i2c-mux at 75->i2c at 1 Bus 3:    i2c at ff020000->i2c-mux at 75->i2c at 2 Bus 4:    i2c at ff030000  (active 4)
    74: i2c-mux at 74, offset len 1, flags 0
    75: i2c-mux at 75, offset len 1, flags 0
Bus 5:    i2c at ff030000->i2c-mux at 74->i2c at 0  (active 5)
    54: eeprom at 54, offset len 1, flags 0
Bus 6:    i2c at ff030000->i2c-mux at 74->i2c at 1 Bus 7:    i2c at ff030000->i2c-mux at 74->i2c at 2 Bus 8:    i2c at ff030000->i2c-mux at 74->i2c at 3 Bus 9:    i2c at ff030000->i2c-mux at 74->i2c at 4 Bus 10:    i2c at ff030000->i2c-mux at 75->i2c at 0 Bus 11:    i2c at ff030000->i2c-mux at 75->i2c at 1 Bus 12:    i2c at ff030000->i2c-mux at 75->i2c at 2 Bus 13:    i2c at ff030000->i2c-mux at 75->i2c at 3 Bus 14:    i2c at ff030000->i2c-mux at 75->i2c at 4 Bus 15:    i2c at ff030000->i2c-mux at 75->i2c at 5 Bus 16:    i2c at ff030000->i2c-mux at 75->i2c at 6 Bus 17:    i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

Michal Simek (7):
   dm: core: Add of_alias_get_highest_id()
   fdt: Introduce fdtdec_get_alias_highest_id()
   dm: core: Introduce dev_read_alias_highest_id()
   dm: core: Add tests for dev_read_alias_highest_id()
   i2c: dm: Record maximum id of devices before probing devices
   i2c: Fill req_seq in i2c_post_bind()
   i2c: mux: Generate longer i2c mux name

Quoted 12 lines
   drivers/core/of_access.c           | 18 ++++++++++++++
   drivers/core/read.c                |  8 ++++++
   drivers/i2c/i2c-uclass.c           | 50
+++++++++++++++++++++++++++++++++++---
   drivers/i2c/muxes/i2c-mux-uclass.c | 29 +++++++++++++++++++---
   include/dm/of_access.h             | 10 ++++++++
   include/dm/read.h                  | 16 ++++++++++++
   include/fdtdec.h                   | 13 ++++++++++
   lib/fdtdec.c                       | 33 +++++++++++++++++++++++++
   test/dm/test-fdt.c                 | 23 ++++++++++++++++++
   9 files changed, 194 insertions(+), 6 deletions(-)
Quoted 8 lines

I just applied your patches and triggered a build on travis:

It shows error for omap boards:

https://travis-ci.org/hsdenx/u-boot-i2c/jobs/490393822

I try to find time to look into it, but may you have time too?

This should be the fix. (I tried that on omap35_logic_somlv_defconfig)

drivers/i2c/i2c-uclass.c +4 -0
index 6f3fca2d2326..391fb1289983 100644
@@ -655,8 +655,12 @@ int i2c_uclass_init(struct uclass *class)
         if (!priv)
                 return -ENOMEM;
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
         /* Get the last allocated alias. */
         priv->max_id = dev_read_alias_highest_id("i2c");
+#else
+       priv->max_id = -1;
+#endif
 
Quoted 8 lines
Quoted 5 lines
drivers/i2c/i2c-uclass.c +0 -0
         debug("%s: highest alias id is %d\n", __func__, priv->max_id);
 

SPL has no OF_CONTROL and also no LIBFDT that's why it is trying to call it.

:-) that sentence doesn't make sense. Correction:
...that's why it shouldn't be called.

;-)

Quoted 9 lines

Maybe it should be enough to have dependency on OF_LIBFDT but Kconfig is saying that OF_LIBFDT is bool setup to y when OF_CONTROL is enabled. And in Makefile fdtdec is enabled

obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += fdtdec.o
or just
obj-$(CONFIG_OF_LIBFDT) += fdtdec.o

Anyway it should be likely enough to have dependency just on OF_LIBFDT.

Ok, do you want to send a v3 of the patch:

dm: core: Add of_alias_get_highest_id()

or is it OK for you, if I add the above fix to this patch directly?

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#37 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

Quoted 128 lines · Heiko Schocher

Hello Michal,

Am 08.02.2019 um 12:24 schrieb Michal Simek:

Quoted 106 lines · Michal Simek
Quoted 105 lines · Heiko Schocher
Quoted 78 lines

Hello Michael,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 72 lines

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which
are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0:    i2c at ff020000
     20: gpio at 20, offset len 1, flags 0
     21: gpio at 21, offset len 1, flags 0
     75: i2c-mux at 75, offset len 1, flags 0
Bus 1:    i2c at ff020000->i2c-mux at 75->i2c at 0 Bus 2:    i2c at ff020000->i2c-mux at 75->i2c at 1 Bus 3:    i2c at ff020000->i2c-mux at 75->i2c at 2 Bus 4:    i2c at ff030000  (active 4)
     74: i2c-mux at 74, offset len 1, flags 0
     75: i2c-mux at 75, offset len 1, flags 0
Bus 5:    i2c at ff030000->i2c-mux at 74->i2c at 0  (active 5) 54: eeprom at 54, offset len 1, flags 0
Bus 6:    i2c at ff030000->i2c-mux at 74->i2c at 1 Bus 7:    i2c at ff030000->i2c-mux at 74->i2c at 2 Bus 8:    i2c at ff030000->i2c-mux at 74->i2c at 3 Bus 9:    i2c at ff030000->i2c-mux at 74->i2c at 4 Bus 10:    i2c at ff030000->i2c-mux at 75->i2c at 0 Bus 11:    i2c at ff030000->i2c-mux at 75->i2c at 1 Bus 12:    i2c at ff030000->i2c-mux at 75->i2c at 2 Bus 13:    i2c at ff030000->i2c-mux at 75->i2c at 3 Bus 14:    i2c at ff030000->i2c-mux at 75->i2c at 4 Bus 15:    i2c at ff030000->i2c-mux at 75->i2c at 5 Bus 16:    i2c at ff030000->i2c-mux at 75->i2c at 6 Bus 17:    i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

Michal Simek (7):
    dm: core: Add of_alias_get_highest_id()
    fdt: Introduce fdtdec_get_alias_highest_id()
    dm: core: Introduce dev_read_alias_highest_id()
    dm: core: Add tests for dev_read_alias_highest_id()
    i2c: dm: Record maximum id of devices before probing devices
    i2c: Fill req_seq in i2c_post_bind()
    i2c: mux: Generate longer i2c mux name

   drivers/core/of_access.c           | 18 ++++++++++++++ drivers/core/read.c                |  8 ++++++ drivers/i2c/i2c-uclass.c           | 50
+++++++++++++++++++++++++++++++++++---
   drivers/i2c/muxes/i2c-mux-uclass.c | 29 +++++++++++++++++++--- include/dm/of_access.h             | 10 ++++++++ include/dm/read.h                  | 16 ++++++++++++ include/fdtdec.h                   | 13 ++++++++++ lib/fdtdec.c                       | 33 +++++++++++++++++++++++++ test/dm/test-fdt.c                 | 23 ++++++++++++++++++

Quoted 2 lines
   9 files changed, 194 insertions(+), 6 deletions(-)
Quoted 8 lines

I just applied your patches and triggered a build on travis:

It shows error for omap boards:

https://travis-ci.org/hsdenx/u-boot-i2c/jobs/490393822

I try to find time to look into it, but may you have time too?

This should be the fix.  (I tried that on omap35_logic_somlv_defconfig)

drivers/i2c/i2c-uclass.c +4 -0
index 6f3fca2d2326..391fb1289983 100644
@@ -655,8 +655,12 @@ int i2c_uclass_init(struct uclass *class)
          if (!priv)
                  return -ENOMEM;
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
          /* Get the last allocated alias. */
          priv->max_id = dev_read_alias_highest_id("i2c");
+#else
+       priv->max_id = -1;
+#endif
 
Quoted 8 lines
Quoted 5 lines
drivers/i2c/i2c-uclass.c +0 -0
          debug("%s: highest alias id is %d\n", __func__, priv->max_id);
 

SPL has no OF_CONTROL and also no LIBFDT that's why it is trying to call it.

:-) that sentence doesn't make sense. Correction:
...that's why it shouldn't be called.

;-)

Quoted 8 lines

Maybe it should be enough to have dependency on OF_LIBFDT but Kconfig is saying that OF_LIBFDT is bool setup to y when OF_CONTROL is enabled. And in Makefile fdtdec is enabled

obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += fdtdec.o
or just
obj-$(CONFIG_OF_LIBFDT) += fdtdec.o

Quoted 7 lines
Quoted 1 line

Anyway it should be likely enough to have dependency just on OF_LIBFDT.

Ok, do you want to send a v3 of the patch:

dm: core: Add of_alias_get_highest_id()

or is it OK for you, if I add the above fix to this patch directly?

Please take it directly.

M

#38 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

Hello Michal,

Am 11.02.2019 um 07:58 schrieb Michal Simek:

Quoted 131 lines · Heiko Schocher
Quoted 130 lines

Hello Michal,

Am 08.02.2019 um 12:24 schrieb Michal Simek:

Quoted 106 lines · Michal Simek
Quoted 105 lines · Heiko Schocher
Quoted 78 lines

Hello Michael,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 62 lines

U-Boot with I2C_DM enabled is not capable to list i2c busses connected to i2c mux. For getting this work there is a need to find out highest alias ID and use this uniq number for new buses connected to I2C mux. This series is making this happen.

There is only one missing piece which is that also i2c controllers which
are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0:    i2c at ff020000
     20: gpio at 20, offset len 1, flags 0
     21: gpio at 21, offset len 1, flags 0
     75: i2c-mux at 75, offset len 1, flags 0
Bus 1:    i2c at ff020000->i2c-mux at 75->i2c at 0 Bus 2:    i2c at ff020000->i2c-mux at 75->i2c at 1 Bus 3:    i2c at ff020000->i2c-mux at 75->i2c at 2 Bus 4:    i2c at ff030000  (active 4)
     74: i2c-mux at 74, offset len 1, flags 0
     75: i2c-mux at 75, offset len 1, flags 0
Bus 5:    i2c at ff030000->i2c-mux at 74->i2c at 0  (active 5)
     54: eeprom at 54, offset len 1, flags 0
Bus 6:    i2c at ff030000->i2c-mux at 74->i2c at 1 Bus 7:    i2c at ff030000->i2c-mux at 74->i2c at 2 Bus 8:    i2c at ff030000->i2c-mux at 74->i2c at 3 Bus 9:    i2c at ff030000->i2c-mux at 74->i2c at 4 Bus 10:    i2c at ff030000->i2c-mux at 75->i2c at 0 Bus 11:    i2c at ff030000->i2c-mux at 75->i2c at 1 Bus 12:    i2c at ff030000->i2c-mux at 75->i2c at 2 Bus 13:    i2c at ff030000->i2c-mux at 75->i2c at 3 Bus 14:    i2c at ff030000->i2c-mux at 75->i2c at 4 Bus 15:    i2c at ff030000->i2c-mux at 75->i2c at 5 Bus 16:    i2c at ff030000->i2c-mux at 75->i2c at 6 Bus 17:    i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

Michal Simek (7):
    dm: core: Add of_alias_get_highest_id()
    fdt: Introduce fdtdec_get_alias_highest_id()
    dm: core: Introduce dev_read_alias_highest_id()
    dm: core: Add tests for dev_read_alias_highest_id()
    i2c: dm: Record maximum id of devices before probing devices
    i2c: Fill req_seq in i2c_post_bind()
    i2c: mux: Generate longer i2c mux name

Quoted 12 lines
    drivers/core/of_access.c           | 18 ++++++++++++++
    drivers/core/read.c                |  8 ++++++
    drivers/i2c/i2c-uclass.c           | 50
+++++++++++++++++++++++++++++++++++---
    drivers/i2c/muxes/i2c-mux-uclass.c | 29 +++++++++++++++++++---
    include/dm/of_access.h             | 10 ++++++++
    include/dm/read.h                  | 16 ++++++++++++
    include/fdtdec.h                   | 13 ++++++++++
    lib/fdtdec.c                       | 33 +++++++++++++++++++++++++
    test/dm/test-fdt.c                 | 23 ++++++++++++++++++
    9 files changed, 194 insertions(+), 6 deletions(-)
Quoted 8 lines

I just applied your patches and triggered a build on travis:

It shows error for omap boards:

https://travis-ci.org/hsdenx/u-boot-i2c/jobs/490393822

I try to find time to look into it, but may you have time too?

This should be the fix.  (I tried that on omap35_logic_somlv_defconfig)

drivers/i2c/i2c-uclass.c +4 -0
index 6f3fca2d2326..391fb1289983 100644
@@ -655,8 +655,12 @@ int i2c_uclass_init(struct uclass *class)
          if (!priv)
                  return -ENOMEM;
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
          /* Get the last allocated alias. */
          priv->max_id = dev_read_alias_highest_id("i2c");
+#else
+       priv->max_id = -1;
+#endif
 
Quoted 8 lines
Quoted 5 lines
drivers/i2c/i2c-uclass.c +0 -0
          debug("%s: highest alias id is %d\n", __func__, priv->max_id);
 

SPL has no OF_CONTROL and also no LIBFDT that's why it is trying to call it.

:-) that sentence doesn't make sense. Correction:
...that's why it shouldn't be called.

;-)

Quoted 9 lines

Maybe it should be enough to have dependency on OF_LIBFDT but Kconfig is saying that OF_LIBFDT is bool setup to y when OF_CONTROL is enabled. And in Makefile fdtdec is enabled

obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += fdtdec.o
or just
obj-$(CONFIG_OF_LIBFDT) += fdtdec.o

Anyway it should be likely enough to have dependency just on OF_LIBFDT.

Quoted 7 lines
Quoted 5 lines

Ok, do you want to send a v3 of the patch:

dm: core: Add of_alias_get_highest_id()

or is it OK for you, if I add the above fix to this patch directly?

Please take it directly.

Ok, done. If all builds fine now, I make a pull request for Tom, thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#39 lore raw

v2 cover Align U-Boot I2C DM bus ID handling with Linux

Quoted 145 lines · Heiko Schocher

Hello Michal,

Am 11.02.2019 um 07:58 schrieb Michal Simek:

Quoted 142 lines · Heiko Schocher
Quoted 141 lines

Hello Michal,

Am 08.02.2019 um 12:24 schrieb Michal Simek:

Quoted 116 lines · Michal Simek
Quoted 115 lines · Heiko Schocher
Quoted 83 lines

Hello Michael,

Am 31.01.2019 um 16:30 schrieb Michal Simek:

Quoted 77 lines

U-Boot with I2C_DM enabled is not capable to list i2c busses connected
to i2c mux. For getting this work there is a need to find out highest
alias ID and use this uniq number for new buses connected to I2C mux.
This series is making this happen.

There is only one missing piece which is that also i2c controllers which
are not listed in DT are not using this feature.

Removing setting up aliases from i2c mux code and unifying it in the same code ensures that numbering schema is proper if no alias is specified.

ZynqMP> i2c bus
Bus 0:    i2c at ff020000
      20: gpio at 20, offset len 1, flags 0
      21: gpio at 21, offset len 1, flags 0
      75: i2c-mux at 75, offset len 1, flags 0
Bus 1:    i2c at ff020000->i2c-mux at 75->i2c at 0 Bus 2:    i2c at ff020000->i2c-mux at 75->i2c at 1 Bus 3:    i2c at ff020000->i2c-mux at 75->i2c at 2 Bus 4:    i2c at ff030000  (active 4)
      74: i2c-mux at 74, offset len 1, flags 0
      75: i2c-mux at 75, offset len 1, flags 0
Bus 5:    i2c at ff030000->i2c-mux at 74->i2c at 0  (active 5) 54: eeprom at 54, offset len 1, flags 0
Bus 6:    i2c at ff030000->i2c-mux at 74->i2c at 1 Bus 7:    i2c at ff030000->i2c-mux at 74->i2c at 2 Bus 8:    i2c at ff030000->i2c-mux at 74->i2c at 3 Bus 9:    i2c at ff030000->i2c-mux at 74->i2c at 4 Bus 10:    i2c at ff030000->i2c-mux at 75->i2c at 0 Bus 11:    i2c at ff030000->i2c-mux at 75->i2c at 1 Bus 12:    i2c at ff030000->i2c-mux at 75->i2c at 2 Bus 13:    i2c at ff030000->i2c-mux at 75->i2c at 3 Bus 14:    i2c at ff030000->i2c-mux at 75->i2c at 4 Bus 15:    i2c at ff030000->i2c-mux at 75->i2c at 5 Bus 16:    i2c at ff030000->i2c-mux at 75->i2c at 6 Bus 17:    i2c at ff030000->i2c-mux at 75->i2c at 7

Thanks,
Michal

Changes in v2:
- Update kernel-doc binding
- Return -1 in case of error. -1 means that the next free alias is 0.
- New patch
- New patch
- Use dev_read_alias_highest_id()
- Use uclass private data
- Use private uclass data
- Fix headers
- Change patch description to focus only on bus name

Michal Simek (7):
     dm: core: Add of_alias_get_highest_id()
     fdt: Introduce fdtdec_get_alias_highest_id()
     dm: core: Introduce dev_read_alias_highest_id()
     dm: core: Add tests for dev_read_alias_highest_id()
     i2c: dm: Record maximum id of devices before probing devices
     i2c: Fill req_seq in i2c_post_bind()
     i2c: mux: Generate longer i2c mux name

    drivers/core/of_access.c           | 18 ++++++++++++++ drivers/core/read.c                |  8 ++++++ drivers/i2c/i2c-uclass.c           | 50
+++++++++++++++++++++++++++++++++++---
    drivers/i2c/muxes/i2c-mux-uclass.c | 29 +++++++++++++++++++--- include/dm/of_access.h             | 10 ++++++++ include/dm/read.h                  | 16 ++++++++++++ include/fdtdec.h                   | 13 ++++++++++ lib/fdtdec.c                       | 33
+++++++++++++++++++++++++
    test/dm/test-fdt.c                 | 23 ++++++++++++++++++

Quoted 2 lines
    9 files changed, 194 insertions(+), 6 deletions(-)
Quoted 8 lines

I just applied your patches and triggered a build on travis:

It shows error for omap boards:

https://travis-ci.org/hsdenx/u-boot-i2c/jobs/490393822

I try to find time to look into it, but may you have time too?

This should be the fix.  (I tried that on
omap35_logic_somlv_defconfig)

drivers/i2c/i2c-uclass.c +4 -0
index 6f3fca2d2326..391fb1289983 100644
@@ -655,8 +655,12 @@ int i2c_uclass_init(struct uclass *class)
           if (!priv)
                   return -ENOMEM;
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
           /* Get the last allocated alias. */
           priv->max_id = dev_read_alias_highest_id("i2c");
+#else
+       priv->max_id = -1;
+#endif
 
           debug("%s: highest alias id is %d\n", __func__,
 priv->max_id);
Quoted 6 lines
Quoted 3 lines

SPL has no OF_CONTROL and also no LIBFDT that's why it is trying to call
it.

:-) that sentence doesn't make sense. Correction:
...that's why it shouldn't be called.

;-)

Quoted 10 lines

Maybe it should be enough to have dependency on OF_LIBFDT but Kconfig is
saying that OF_LIBFDT is bool setup to y when OF_CONTROL is enabled. And in Makefile fdtdec is enabled

obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += fdtdec.o
or just
obj-$(CONFIG_OF_LIBFDT) += fdtdec.o

Anyway it should be likely enough to have dependency just on OF_LIBFDT.

Ok, do you want to send a v3 of the patch:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

dm: core: Add of_alias_get_highest_id()

or is it OK for you, if I add the above fix to this patch directly?

Please take it directly.

Ok, done. If all builds fine now, I make a pull request for Tom, thanks!

great.

Thanks.
Michal