[U-Boot] [PATCH 3/4] i2c: dm: Record maximum id of devices before probing devices
Simon Glass
sjg at chromium.org
Thu Jan 31 10:04:16 UTC 2019
Hi Michal,
On Fri, 18 Jan 2019 at 08:13, Michal Simek <michal.simek at xilinx.com> wrote:
>
> 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.
>
> Signed-off-by: Michal Simek <michal.simek at xilinx.com>
> ---
>
> drivers/i2c/i2c-uclass.c | 19 +++++++++++++++++++
> include/i2c.h | 3 +++
> 2 files changed, 22 insertions(+)
>
> diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
> index 975318e5f254..aaece115f02f 100644
> --- a/drivers/i2c/i2c-uclass.c
> +++ b/drivers/i2c/i2c-uclass.c
> @@ -23,6 +23,8 @@ enum {
> PIN_COUNT,
> };
>
> +int i2c_highest_id = -1;
> +
> /* Useful debugging function */
> void i2c_dump_msgs(struct i2c_msg *msg, int nmsgs)
> {
> @@ -619,10 +621,27 @@ static int i2c_child_post_bind(struct udevice *dev)
> #endif
> }
>
> +int i2c_uclass_init(struct uclass *class)
> +{
> +#ifdef CONFIG_OF_LIVE
> + int ret;
> +
> + ret = of_alias_get_highest_id("i2c");
> + if (ret >= 0)
> + i2c_highest_id = ret;
> +#else
> + i2c_highest_id = fdtdec_get_alias_highest_id(gd->fdt_blob, "i2c");
> +#endif
This should call dev_read_alias_highest_id() or similar, which does
the logic you have here.
> + debug("%s: i2c highest_id %d\n", __func__, i2c_highest_id);
> +
> + return 0;
> +}
> +
> UCLASS_DRIVER(i2c) = {
> .id = UCLASS_I2C,
> .name = "i2c",
> .flags = DM_UC_FLAG_SEQ_ALIAS,
> + .init = i2c_uclass_init,
> #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
> .post_bind = dm_scan_fdt_dev,
> #endif
> diff --git a/include/i2c.h b/include/i2c.h
> index ccffc1955275..c69e26deaeed 100644
> --- a/include/i2c.h
> +++ b/include/i2c.h
> @@ -16,6 +16,9 @@
> #ifndef _I2C_H_
> #define _I2C_H_
>
> +/* Stores maximum highest i2c alias number */
> +extern int i2c_highest_id;
This should be in uclass-private data, not a global.
But also I feel that the behaviour needs to be consistent for all
U-Boot buses, not just I2C. So can we modify the existing core DM code
instead? I think a change to uclass_resolve_seq() might be enough.
> +
> /*
> * For now there are essentially two parts to this file - driver model
> * here at the top, and the older code below (with CONFIG_SYS_I2C being
> --
> 1.9.1
>
Regards,
Simon
More information about the U-Boot
mailing list