[PATCH] sandbox: i2c: Make sure phandle dependency is probed

Marek Vasut marex at denx.de
Sat Oct 5 16:37:07 CEST 2024


On 10/4/24 7:04 AM, Heiko Schocher wrote:
> Hi Marek!
> 
> On 03.10.24 22:47, Marek Vasut wrote:
>> On 10/3/24 10:37 PM, Marek Vasut wrote:
>>> This driver depends on i2c emulator via DT phandle. Make sure the
>>> dependency is probed before this driver is probed, not when it is
>>> first used during transfer. This fixes the following i2c_emul_find()
>>> error:
>>>
>>> "
>>> $ ./u-boot -Dc ""
>>> ...
>>>         i2c_emul_find() No emulators for device 'sandbox_pmic'
>>>    sandbox_pmic_write() write error to device: 0000000018c568d0 
>>> register: 0x0!
>>>         out_set_value() PMIC write failed: -5
>>>         i2c_emul_find() No emulators for device 'sandbox_pmic'
>>>    sandbox_pmic_write() write error to device: 0000000018c568d0 
>>> register: 0x0!
>>>         out_set_value() PMIC write failed: -5
>>> ...
>>> "
>>>
>>> Signed-off-by: Marek Vasut <marex at denx.de>
>>> ---
>>> Cc: Heiko Schocher <hs at denx.de>
>>> Cc: Simon Glass <sjg at chromium.org>
>>> Cc: Tom Rini <trini at konsulko.com>
>>> Cc: u-boot at lists.denx.de
>>> ---
>>>   drivers/i2c/sandbox_i2c.c | 9 +++++++++
>>>   1 file changed, 9 insertions(+)
>>>
>>> diff --git a/drivers/i2c/sandbox_i2c.c b/drivers/i2c/sandbox_i2c.c
>>> index 74bb5e93397..9a39ac14fb4 100644
>>> --- a/drivers/i2c/sandbox_i2c.c
>>> +++ b/drivers/i2c/sandbox_i2c.c
>>> @@ -80,6 +80,14 @@ static int sandbox_i2c_xfer(struct udevice *bus, 
>>> struct i2c_msg *msg,
>>>       return ops->xfer(emul, msg, nmsgs);
>>>   }
>>> +static int sandbox_i2c_probe(struct udevice *dev)
>>> +{
>>> +    struct udevice *emul;
>>> +
>>> +    return uclass_get_device_by_phandle(UCLASS_I2C_EMUL, dev,
>>> +                        "sandbox,emul", &emul);
>>> +}
>> Hmmm, no, this does not do it, but it does show what the issue is -- 
>> sandbox_i2c_xfer is misused to defer access to this emulator until the 
>> first I2C transfer, so the emulator can hopefully probe in the 
>> meantime. This is fragile and now it broke. What I am not quite sure 
>> about is why this uclass_get_device_by_phandle() returns -2 here 
>> instead of probing the emulator ?
> 
> Hmm... -2 means it does not find such a device ... why, I don;t know ...
> do you have a chance to debug?
It seems I was too hasty with this patch, now superseded by:

[PATCH] sandbox: dts: Add missing sandbox,emul phandle to sandbox-pmic


More information about the U-Boot mailing list