summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMichal Simek <michal.simek@xilinx.com>2019-01-31 16:31:01 +0100
committerHeiko Schocher <hs@denx.de>2019-02-11 09:37:27 +0100
commit6bfacc8aadb5d30a13413f337053118559a5ef25 (patch)
tree3cab2784fb68f86dba1f38997c8bb695fbe91fa0 /drivers
parenta93eb577b9ae635ef6f631e8509d113c15f53530 (diff)
i2c: dm: Record maximum id of devices before probing devices
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. add from hs: fix build problem in i2c-uclass.c for omap devices Signed-off-by: Michal Simek <michal.simek@xilinx.com> Reviewed-by: Heiko Schocher <hs@denx.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/i2c/i2c-uclass.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
index 975318e5f2..7595b9b0f9 100644
--- a/drivers/i2c/i2c-uclass.c
+++ b/drivers/i2c/i2c-uclass.c
@@ -619,6 +619,30 @@ 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. */
+#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",
@@ -626,6 +650,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),