[PATCH 2/2] bootcount: Add driver model I2C driver

Heiko Schocher hs at denx.de
Wed Oct 18 06:31:57 CEST 2023


Hello Simon,

On 18.10.23 05:33, Simon Glass wrote:
> Hi Philip,
> 
> On Tue, 17 Oct 2023 at 06:57, Philip Oberfichtner <pro at denx.de> wrote:
>>
>> Hi Simon,
>>
>> maybe you can give me a hint on how to implement this cleanly in driver
>> model?
>>
>> To sum it up, I'd like to have a phandle pointing to *any* I2C device,
>> not knowing which UCLASS actually fits. Then the device and the parent
>> bus should be probed/prepared such that dm_i2c_read() can be used.
>>
>> Any ideas on this?
> 
> I suggest a phandle to the i2c device.

Yep!

> You can use oftree_get_by_phandle() to get the node and then
> device_find_global_by_ofnode() to get the device.
> 
> This is expensive, although eventually I suspect we will fix that with
> OF_LIVE. I think it should be implemented as a new function in i2c.h
> so we can change the impl later easily.

Yes, please.

> If you want to be more efficient you could do something like:
> 
> int phandle = ??
> 
> struct uclass *uc;
> struct udevice *bus;
> 
> uclass_id_foreach_dev(UCLASS_I2C, bus, uc) {
>    struct udevice *dev;
> 
>    device_foreach_child(dev, bus) {
>       if (!dev_read_u32(dev, "phandle", &val) && val == phandle)
>          return dev;
>    }
> }
> 
> but honestly now I look at it, that is awful. We try to avoid exposing
> the internals of phandle because it allows us to (one day) maintain a
> list of them.

Yes, please not ... a list of phandles would be great we can than
walk through, yes, may in future...

May Philip can use uclass_get_device_by_phandle and try a list of
possible UCLASS candidates, like UCLASS_RTC, UCLASS_I2C_EEPROM,
UCLASS_POWER,... and if found, check if parent is UCLASS_I2C...

may not so expensive ...

bye,
Heiko
-- 
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de


More information about the U-Boot mailing list