diff options
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/i2c-uclass.c | 54 | ||||
-rw-r--r-- | drivers/i2c/muxes/i2c-mux-uclass.c | 29 |
2 files changed, 77 insertions, 6 deletions
diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c index 975318e5f2..49e23a0a4b 100644 --- a/drivers/i2c/i2c-uclass.c +++ b/drivers/i2c/i2c-uclass.c @@ -619,13 +619,61 @@ static int i2c_child_post_bind(struct udevice *dev) #endif } +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; + + /* Just for sure */ + if (!priv) + return -ENOMEM; + + /* Get the last allocated alias. */ +#if CONFIG_IS_ENABLED(OF_CONTROL) + 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); + + return 0; +} + 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, .per_device_auto_alloc_size = sizeof(struct dm_i2c_bus), .per_child_platdata_auto_alloc_size = sizeof(struct dm_i2c_chip), diff --git a/drivers/i2c/muxes/i2c-mux-uclass.c b/drivers/i2c/muxes/i2c-mux-uclass.c index a680ee1762..8b1149997a 100644 --- a/drivers/i2c/muxes/i2c-mux-uclass.c +++ b/drivers/i2c/muxes/i2c-mux-uclass.c @@ -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; } |