public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Jean-Jacques Hiblot <jjhiblot@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 02/19] dm: i2c: Make i2c_get_chip_for_busnum() fail if the chip is not detected
Date: Mon, 5 Nov 2018 10:38:10 +0100	[thread overview]
Message-ID: <aad48e02-d532-340a-e13a-a068f428d1c7@ti.com> (raw)
In-Reply-To: <CAPnjgZ0SY=Lk9yNMU2HGSYP+PzChLjo2ZTd2hgOoE1XF_rdxew@mail.gmail.com>

Hi Simon,

On 03/11/2018 07:07, Simon Glass wrote:
> Hi Jean-Jacques,
>
> On 22 October 2018 at 08:12, Jean-Jacques Hiblot <jjhiblot@ti.com> wrote:
>> i2c_get_chip_for_busnum() really should check the presence of the chip on
>> the bus. Most of the users of this function assume that this is done.
>>
>> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
>>
>> ---
>>
>> Changes in v3:
>> - removed commit introducing dm_i2c_probe_device(). Instead probe the
>>    presence of the chip on the I2C bus in i2c_get_chip_for_busnum().
>>
>> Changes in v2: None
>>
>>   drivers/i2c/i2c-uclass.c | 11 +++++++++++
>>   1 file changed, 11 insertions(+)
>>
>> diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
>> index c5a3c4e..975318e 100644
>> --- a/drivers/i2c/i2c-uclass.c
>> +++ b/drivers/i2c/i2c-uclass.c
>> @@ -347,6 +347,17 @@ int i2c_get_chip_for_busnum(int busnum, int chip_addr, uint offset_len,
>>                  debug("Cannot find I2C bus %d\n", busnum);
>>                  return ret;
>>          }
>> +
>> +       /* detect the presence of the chip on the bus */
>> +       ret = i2c_probe_chip(bus, chip_addr, 0);
>> +       debug("%s: bus='%s', address %02x, ret=%d\n", __func__, bus->name,
>> +             chip_addr, ret);
>> +       if (ret) {
>> +               debug("Cannot detect I2C chip %02x on bus %d\n", chip_addr,
>> +                     busnum);
>> +               return ret;
>> +       }
>> +
> I really don't like to keep going on about this, but I think this is
> still not quite right.

That is the development model of many open source projects that made 
their success. So I don't mind.

>
> If the chip is not present that is generally an error, or at least it
> is assumed to be by the callers.
agreed. That is the purpose of the modification
>
> i2c_get_chip() is called just above the code you add. This normally
> probes an existing device at that i2c address, which presumably checks
> that it is present. However if there is no device at the given
> address, it calls device_bind():
>
> debug("%s: Searching bus '%s' for address %02x: ", __func__,
>        bus->name, chip_addr);
> for (device_find_first_child(bus, &dev); dev;
>      device_find_next_child(&dev)) {
>          struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
>          int ret;
>
>          if (chip->chip_addr == chip_addr) {
>              ret = device_probe(dev);
>              debug("found, ret=%d\n", ret);
>              f (ret)
>                  return ret;
>              *devp = dev;
>              return 0;
>          }
>      }
> debug("not found\n");
> return i2c_bind_driver(bus, chip_addr, offset_len, devp);
>
> So I think your new code below should only be used in the case where
> device_bind() was called.

I don't think it hurts to probe the presence of the chip after the 
device_probe() is called.

And I am not sure that the all drivers detect the chip in their probe() 
functions.

>
> What is the case where you:
>
> a) Don't put the I2C device in the device tree
> b) Expect it to be bound
> c) Want to know if it is not present

This is exactly the use case I'm trying to address. There are several 
possible cases:

- Some platforms haven't gone full DM yet and don't put the I2C device 
in the DT.

- Other just don't have a DM I2C driver for the chip and only send a few 
commands to initialize it. Adding a real I2C-driver may be overkill.

- Other platforms rely on the detection of external devices to further 
identify the platform with no need to actually use the external chip.


>
> Looking at it closely, i2c_get_chip() is not consistent. It probes the
> device it is is already bound, but if not, it binds a device and then
> fails to probe it. I think it should call device_prove() after binding
> it.
Calling device_probe() would work only if a DM I2C driver exists for the 
chip and if a description exists in the DT. So I don't think it would 
work for the cases I mentioned above.
>
> Would that be good enough?
>
> Otherwise, perhaps we just need a function like:
>
> i2c_probe_device(struct udevice *dev)
>
> which calls i2c_probe_chip() on the appropriate address?

That works, it was what was done in the first version. But I think this 
version is better as it doesn't introduce a new function and make 
i2c_get_chip_for_busnum() behave as people expect it to behave: fail if 
the chip is not there.  The cost is a systematic and sometimes  
unnecessary I2C probe sequence. That penalty is small.

There is another solution: add a probe() function to the 
i2c_generic_chip_drv driver that fails if it doesn't detect the chip. It 
would do the job.

>
>>          ret = i2c_get_chip(bus, chip_addr, offset_len, devp);
>>          if (ret) {
>>                  debug("Cannot find I2C chip %02x on bus %d\n", chip_addr,
>> --
>> 2.7.4
>>
> Again I'm sorry for all the back and forth. I think it would help to
> have more information in the commit message about the circumstances in
> which this change is needed.

>
> Regards,
> Simon
>

  reply	other threads:[~2018-11-05  9:38 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-22 14:12 [U-Boot] [PATCH v3 00/19] DM_I2C_COMPAT removal for all ti platforms Jean-Jacques Hiblot
2018-10-22 14:12 ` [U-Boot] [PATCH v3 01/19] cmd: Kconfig: Do not include EEPROM if DM_I2C is used without DM_I2C_COMPAT Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-25  3:30   ` Simon Glass
2018-10-22 14:12 ` [U-Boot] [PATCH v3 02/19] dm: i2c: Make i2c_get_chip_for_busnum() fail if the chip is not detected Jean-Jacques Hiblot
2018-11-03  6:07   ` Simon Glass
2018-11-05  9:38     ` Jean-Jacques Hiblot [this message]
2018-11-13 19:53       ` Simon Glass
2018-10-22 14:12 ` [U-Boot] [PATCH v3 03/19] dm: device: Allow using uclass_find_device_by_seq() without OF_CONTROL Jean-Jacques Hiblot
2018-10-22 14:12 ` [U-Boot] [PATCH v3 04/19] configs: am335x: am57x: dra7x: Enable CONFIG_SPL_DM_SEQ_ALIAS Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-22 14:12 ` [U-Boot] [PATCH v3 05/19] i2c: omap24xx_i2c: Move away from SoC specific headers for reg offset Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-22 14:12 ` [U-Boot] [PATCH v3 06/19] i2c: omap24xx_i2c: Use platdata to probe the device Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-22 14:12 ` [U-Boot] [PATCH v3 07/19] am335x: Register the I2C controllers if DM_I2C is used Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-22 14:12 ` [U-Boot] [PATCH v3 08/19] dts: am43x: omap5: Add node for I2C in SPL Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-22 14:12 ` [U-Boot] [PATCH v3 09/19] omap: detect the board after DM is available Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-22 14:12 ` [U-Boot] [PATCH v3 10/19] power: make most tps drivers and the twl4030 driver compatible with DM_I2C Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-22 14:12 ` [U-Boot] [PATCH v3 11/19] ti: common: board_detect: Allow DM I2C without CONFIG_DM_I2C_COMPAT Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-22 14:12 ` [U-Boot] [PATCH v3 12/19] configs: am335x_pdu001: remove CONFIG_DM_I2C_COMPAT Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-22 14:12 ` [U-Boot] [PATCH v3 13/19] ti: remove usage of DM_I2C_COMPAT and don't disable DM_I2C in SPL Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-22 14:12 ` [U-Boot] [PATCH v3 14/19] am57xx: remove non-DM I2C code Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-22 14:12 ` [U-Boot] [PATCH v3 15/19] configs: dra7xx-evm: increase the size of the malloc's pool before relocation Jean-Jacques Hiblot
2018-10-22 16:43   ` Tom Rini
2018-10-22 14:12 ` [U-Boot] [PATCH v3 16/19] lib: fdtdec: Add function re-setup the fdt more effeciently Jean-Jacques Hiblot
2018-11-03  6:07   ` Simon Glass
2018-10-22 14:12 ` [U-Boot] [PATCH v3 17/19] drivers: core: Add the option SPL_DM_DEVICE_REMOVE to the Kconfig Jean-Jacques Hiblot
2018-10-22 16:44   ` Tom Rini
2018-10-25  3:30   ` Simon Glass
2018-10-22 14:12 ` [U-Boot] [PATCH v3 18/19] drivers: core: nullify gd->dm_root after dm_uninit() Jean-Jacques Hiblot
2018-10-22 14:12 ` [U-Boot] [PATCH v3 19/19] dra7: Allow selecting a new dtb after board detection Jean-Jacques Hiblot
2018-10-22 16:44   ` Tom Rini
2018-10-27 21:46 ` [U-Boot] [PATCH v3 00/19] DM_I2C_COMPAT removal for all ti platforms Adam Ford
2018-11-26 19:18   ` Adam Ford
2018-11-28  5:04     ` Heiko Schocher
2018-12-06 18:40       ` Adam Ford
2018-12-07 13:50         ` Jean-Jacques Hiblot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aad48e02-d532-340a-e13a-a068f428d1c7@ti.com \
    --to=jjhiblot@ti.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox