diff mbox series

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

Message ID 1538757935-6481-3-git-send-email-jjhiblot@ti.com
State Superseded
Delegated to: Tom Rini
Headers show
Series DM_I2C_COMPAT removal for all ti platforms | expand

Commit Message

Jean-Jacques Hiblot Oct. 5, 2018, 4:45 p.m. UTC
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@ti.com>
---

Changes in v2: None

 drivers/i2c/i2c-uclass.c |  8 ++++++++
 include/i2c.h            | 13 +++++++++++++
 2 files changed, 21 insertions(+)

Comments

Simon Glass Oct. 11, 2018, 3:13 a.m. UTC | #1
Hi Jean-Jacques,

On 5 October 2018 at 10:45, Jean-Jacques Hiblot <jjhiblot@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@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.

Regards,
Simon
Jean-Jacques Hiblot Oct. 11, 2018, 12:01 p.m. UTC | #2
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@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@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.

JJ
>
> Regards,
> Simon
>
Simon Glass Oct. 12, 2018, midnight UTC | #3
Hi Jean-Jacques,

On 11 October 2018 at 06:01, Jean-Jacques Hiblot <jjhiblot@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@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@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);
}

what happens?

Regards,
Simon
Jean-Jacques Hiblot Oct. 18, 2018, 3:23 p.m. UTC | #4
On 12/10/2018 02:00, Simon Glass wrote:
> Hi Jean-Jacques,
>
> On 11 October 2018 at 06:01, Jean-Jacques Hiblot <jjhiblot@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@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@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
>
diff mbox series

Patch

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);
+}
+
 int dm_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
 {
 	struct dm_i2c_ops *ops = i2c_get_ops(bus);
diff --git a/include/i2c.h b/include/i2c.h
index d33f827..3c8fde2 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -167,6 +167,19 @@  int dm_i2c_probe(struct udevice *bus, uint chip_addr, uint chip_flags,
 		 struct udevice **devp);
 
 /**
+ * dm_i2c_probe_dev() - probe the presence of a I2C device
+ *
+ * This can be useful to check for the existence of a chip already probed
+ * (software wise).
+ * It is typically implemented by writing the chip address to the bus
+ * and checking that the chip replies with an ACK.
+ *
+ * @bus:	Device to probe
+ * @return 0 if a chip was found at that address, -ve if not
+ */
+int dm_i2c_probe_device(struct udevice *dev);
+
+/**
  * dm_i2c_reg_read() - Read a value from an I2C register
  *
  * This reads a single value from the given address in an I2C chip