[PATCH] i2c: add dm_i2c_probe_chip() to detect chip presence

Simon Glass sjg at chromium.org
Thu Dec 22 21:23:48 CET 2022


Hi Johan,

On Mon, 19 Dec 2022 at 12:57, Johan Korsnes <johan.korsnes at remarkable.no> wrote:
>
> Add function to determine whether a chip is present. This check is
> typically implemented by writing the chip address to the bus and
> checking that the chip replies with an ACK.
>
> The already existing dm_i2c_probe() will attempt to bind/probe the
> relevant driver if the chip is present. This makes it unsuitable for
> situations where one only wants to know the presence of a chip.
>
> Signed-off-by: Johan Korsnes <johan.korsnes at remarkable.no>
> Cc: Eirik Schultz <schultzern at gmail.com>
> Cc: Heiko Schocher <hs at denx.de>
> Cc: Simon Glass <sjg at chromium.org>
>
> ---
> Previously, I've used i2c_probe() to determine whether or not an i2c
> chip is present on an i2c bus. With the introduction of the driver model
> this function is deprecated. Fortunately, I found dm_i2c_probe(), which
> I expected to perform the same check, it was even documented to be
> suitable for this purpose:
>
> ```
> dm_i2c_probe() - probe a particular chip address
>
> This can be useful to check for the existence of a chip on the bus.
> It is typically implemented by writing the chip address to the bus
> and checking that the chip replies with an ACK.
> ```
>
> Unfortunately, it does not seem to be a replacement. It seems
> dm_i2c_probe() will attempt to bind/probe a driver if the chip is
> present, and will in turn return the return value from the driver
> probe/bind attempt.
> ---
>  drivers/i2c/i2c-uclass.c | 11 +++++++++++
>  include/i2c.h            | 16 +++++++++++++---
>  2 files changed, 24 insertions(+), 3 deletions(-)

This looks OK but please add a test to dm/test/i2c.c for your new function.

https://u-boot.readthedocs.io/en/latest/develop/testing.html

Regards,
Simon


More information about the U-Boot mailing list