[U-Boot] [PATCH v2 6/7] i2c: Fill req_seq in i2c_post_bind()
Michal Simek
michal.simek at xilinx.com
Thu Jan 31 15:31:02 UTC 2019
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
Signed-off-by: Michal Simek <michal.simek at xilinx.com>
---
Changes in v2:
- Use private uclass data
drivers/i2c/i2c-uclass.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
index b26602f3de95..6f3fca2d2326 100644
--- a/drivers/i2c/i2c-uclass.c
+++ b/drivers/i2c/i2c-uclass.c
@@ -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,
--
1.9.1
More information about the U-Boot
mailing list