[U-Boot] [PATCH 3/4] i2c: dm: Record maximum id of devices before probing devices
Michal Simek
michal.simek at xilinx.com
Thu Jan 31 11:03:07 UTC 2019
On 31. 01. 19 11:04, Simon Glass wrote:
> 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.
not a problem with this.
>
>> + 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.
In this case there are two uclasses. UCLASS_I2C and UCLASS_I2C_MUX which
has to share the same numbers. I would expect that private data will be
private just for one not for both.
Reading
>
> 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.
I need to check calling sequence to see if this is properly timed or not.
Thanks,
Michal
More information about the U-Boot
mailing list