[U-Boot] [PATCH v2 02/19] dm: i2c: Add dm_i2c_probe_device() to test the presence of a chip

Jean-Jacques Hiblot jjhiblot at ti.com
Thu Oct 18 15:23:54 UTC 2018


On 12/10/2018 02:00, Simon Glass wrote:
> Hi Jean-Jacques,
>
> On 11 October 2018 at 06:01, Jean-Jacques Hiblot <jjhiblot at ti.com> wrote:
>> Hi Simon,
>>
>> thanks for the reviews.
>>
>>
>>
>> On 11/10/2018 05:13, Simon Glass wrote:
>>> Hi Jean-Jacques,
>>>
>>> On 5 October 2018 at 10:45, Jean-Jacques Hiblot <jjhiblot at ti.com> wrote:
>>>> In a non-DM environment, it is possible to test the presence of a chip
>>>> using i2c_probe(chip_addr).
>>>> dm_i2c_probe_device() brings the same functionality with a DM interface.
>>>> The intent is to be able to test the presence of a chip for the device
>>>> has
>>>> been created with i2c_get_chip_for_busnum(bus_num, chip_addr, ...)
>>>>
>>>> Signed-off-by: Jean-Jacques Hiblot <jjhiblot at ti.com>
>>>> ---
>>>>
>>>> Changes in v2: None
>>>>
>>>>    drivers/i2c/i2c-uclass.c |  8 ++++++++
>>>>    include/i2c.h            | 13 +++++++++++++
>>>>    2 files changed, 21 insertions(+)
>>>>
>>>> diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
>>>> index c5a3c4e..ec88168 100644
>>>> --- a/drivers/i2c/i2c-uclass.c
>>>> +++ b/drivers/i2c/i2c-uclass.c
>>>> @@ -378,6 +378,14 @@ int dm_i2c_probe(struct udevice *bus, uint
>>>> chip_addr, uint chip_flags,
>>>>           return ret;
>>>>    }
>>>>
>>>> +int dm_i2c_probe_device(struct udevice *dev)
>>>> +{
>>>> +       struct udevice *bus = dev_get_parent(dev);
>>>> +       struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
>>>> +
>>>> +       return i2c_probe_chip(bus, chip->chip_addr, chip->flags);
>>>> +}
>>> Why not just probe the device? That should have the same effect.
>> The device itself is not probed when using i2c_get_chip_for_busnum(). I
>> could have changed it there but was sure about possible side-effects on all
>> boards.
>> The code that uses the non-DM API usually calls I2C_probe() at some point,
>> this function is the equivalent in the DM world.
> So if you change your above function to:
>
> int dm_i2c_probe_device(struct udevice *dev)
> {
>      return device_probe(dev);
If the chip is not present on the bus, it is quite happy to probe the 
device anyway.

I have had a harder look at the usage of i2c_get_chip_for_busnum() and 
all of the platforms should be ok if this function fails if the chip is 
not detected. In fact most of the platform expect it to fail if the chip 
is not detected.
So instead of adding a new function, I'll modify 
i2c_get_chip_for_busnum() to fail if the device is not detected on the bus.

JJ

> }
>
> what happens?
>
> Regards,
> Simon
>



More information about the U-Boot mailing list