Hi Philip, On Tue, 17 Oct 2023 at 06:57, Philip Oberfichtner <p...@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. 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. 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. [..] Regards, Simon