linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: i2c-cadence: Don't register the adapter until it's ready
@ 2017-01-05 10:47 Mike Looijmans
  2017-01-06 21:34 ` Vladimir Zapolskiy
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Looijmans @ 2017-01-05 10:47 UTC (permalink / raw)
  To: linux-i2c
  Cc: linux-kernel, linux-arm-kernel, wsa, soren.brinkmann,
	michal.simek, Mike Looijmans

The driver calls i2c_add_adapter before writing to config registers,
resulting in dmesg output like this, where devices fail to initialize:

cdns-i2c ff030000.i2c: timeout waiting on completion
pca953x 1-0041: failed reading register
pca953x: probe of 1-0041 failed with error -110
at24 1-0050: 512 byte 24c04 EEPROM, writable, 1 bytes/write
cdns-i2c ff030000.i2c: 100 kHz mmio ff030000 irq 197

The adapter is being used before it completed the "probe". To fix
this, make "i2c_add_adapter" the last thing it calls in probe.
It also makes sense to show the adapter initialization before
the devices on the bus.

Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
---
 drivers/i2c/busses/i2c-cadence.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 6869712..7793bb8 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -962,10 +962,6 @@ static int cdns_i2c_probe(struct platform_device *pdev)
 		goto err_clk_dis;
 	}
 
-	ret = i2c_add_adapter(&id->adap);
-	if (ret < 0)
-		goto err_clk_dis;
-
 	/*
 	 * Cadence I2C controller has a bug wherein it generates
 	 * invalid read transaction after HW timeout in master receiver mode.
@@ -978,6 +974,10 @@ static int cdns_i2c_probe(struct platform_device *pdev)
 	dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n",
 		 id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq);
 
+	ret = i2c_add_adapter(&id->adap);
+	if (ret < 0)
+		goto err_clk_dis;
+
 	return 0;
 
 err_clk_dis:
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] i2c: i2c-cadence: Don't register the adapter until it's ready
  2017-01-05 10:47 [PATCH] i2c: i2c-cadence: Don't register the adapter until it's ready Mike Looijmans
@ 2017-01-06 21:34 ` Vladimir Zapolskiy
  2017-01-12 19:22   ` Wolfram Sang
  2017-01-13  6:40   ` Mike Looijmans
  0 siblings, 2 replies; 6+ messages in thread
From: Vladimir Zapolskiy @ 2017-01-06 21:34 UTC (permalink / raw)
  To: Mike Looijmans, linux-i2c
  Cc: linux-kernel, linux-arm-kernel, wsa, soren.brinkmann, michal.simek

Hello Mike,

On 01/05/2017 12:47 PM, Mike Looijmans wrote:
> The driver calls i2c_add_adapter before writing to config registers,
> resulting in dmesg output like this, where devices fail to initialize:
> 
> cdns-i2c ff030000.i2c: timeout waiting on completion
> pca953x 1-0041: failed reading register
> pca953x: probe of 1-0041 failed with error -110
> at24 1-0050: 512 byte 24c04 EEPROM, writable, 1 bytes/write
> cdns-i2c ff030000.i2c: 100 kHz mmio ff030000 irq 197
> 
> The adapter is being used before it completed the "probe". To fix
> this, make "i2c_add_adapter" the last thing it calls in probe.
> It also makes sense to show the adapter initialization before
> the devices on the bus.

commonly "it also" in a commit message means a change, which should be done
separately, and this is the case here as well.

Because the adapter registration i2c_add_adapter() can fail, information
about the adapter initialization would be expected only in case of
successful registration.

The information sent to the kernel log buffer here is quite trivial,
probably dev_info() can be just removed, but in any case it should be
a separate change.

> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>

--
With best wishes,
Vladimir

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] i2c: i2c-cadence: Don't register the adapter until it's ready
  2017-01-06 21:34 ` Vladimir Zapolskiy
@ 2017-01-12 19:22   ` Wolfram Sang
  2017-01-13  6:40   ` Mike Looijmans
  1 sibling, 0 replies; 6+ messages in thread
From: Wolfram Sang @ 2017-01-12 19:22 UTC (permalink / raw)
  To: Vladimir Zapolskiy
  Cc: Mike Looijmans, linux-i2c, linux-kernel, linux-arm-kernel,
	soren.brinkmann, michal.simek


> Because the adapter registration i2c_add_adapter() can fail, information
> about the adapter initialization would be expected only in case of
> successful registration.

Exactly.

> 
> The information sent to the kernel log buffer here is quite trivial,
> probably dev_info() can be just removed, but in any case it should be
> a separate change.

I am not sure I get you here, but to not have false positive success
messages, I'd think that should be all in one patch.

Regards,

   Wolfram

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] i2c: i2c-cadence: Don't register the adapter until it's ready
  2017-01-06 21:34 ` Vladimir Zapolskiy
  2017-01-12 19:22   ` Wolfram Sang
@ 2017-01-13  6:40   ` Mike Looijmans
  2017-01-13  8:37     ` Wolfram Sang
  1 sibling, 1 reply; 6+ messages in thread
From: Mike Looijmans @ 2017-01-13  6:40 UTC (permalink / raw)
  To: Vladimir Zapolskiy, linux-i2c
  Cc: linux-kernel, linux-arm-kernel, wsa, soren.brinkmann, michal.simek

On 06-01-17 22:34, Vladimir Zapolskiy wrote:
> Hello Mike,
>
> On 01/05/2017 12:47 PM, Mike Looijmans wrote:
>> The driver calls i2c_add_adapter before writing to config registers,
>> resulting in dmesg output like this, where devices fail to initialize:
>>
>> cdns-i2c ff030000.i2c: timeout waiting on completion
>> pca953x 1-0041: failed reading register
>> pca953x: probe of 1-0041 failed with error -110
>> at24 1-0050: 512 byte 24c04 EEPROM, writable, 1 bytes/write
>> cdns-i2c ff030000.i2c: 100 kHz mmio ff030000 irq 197
>>
>> The adapter is being used before it completed the "probe". To fix
>> this, make "i2c_add_adapter" the last thing it calls in probe.
>> It also makes sense to show the adapter initialization before
>> the devices on the bus.
>
> commonly "it also" in a commit message means a change, which should be done
> separately, and this is the case here as well.
>
> Because the adapter registration i2c_add_adapter() can fail, information
> about the adapter initialization would be expected only in case of
> successful registration.

I would argue that the "info" message means "the I2C adapter is ready for 
transaction now, and we'll start initializing devices on the bus". That is the 
case before it calls i2c_add_adapter().

When i2c_add_adapter() runs, it will start probing devices on the bus. This 
yields very confusing output, as it will output things in a reversed order:

- device X on I2C bus
- device Y on I2C bus
- cdns-i2c ff030000.i2c: 100 kHz mmio ff030000 irq 197

This is especially confusing if there are multiple I2C adapters with muxes 
behind them, the order then becomes like this:

- Device X on bus 0
- Mux A on bus 0 registering bus 2, 3 and 4
- I2C controller for bus 0
- Device Y on bus 1
- I2C controller for bus 1
- Device Z on bus 2
- etc..

> The information sent to the kernel log buffer here is quite trivial,
> probably dev_info() can be just removed, but in any case it should be
> a separate change.

Fine with me too.

>
>> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
>
> --
> With best wishes,
> Vladimir
>



Kind regards,

Mike Looijmans
System Expert

TOPIC Products
Materiaalweg 4, NL-5681 RJ Best
Postbus 440, NL-5680 AK Best
Telefoon: +31 (0) 499 33 69 79
E-mail: mike.looijmans@topicproducts.com
Website: www.topicproducts.com

Please consider the environment before printing this e-mail

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] i2c: i2c-cadence: Don't register the adapter until it's ready
  2017-01-13  6:40   ` Mike Looijmans
@ 2017-01-13  8:37     ` Wolfram Sang
  2017-01-13 14:52       ` Mike Looijmans
  0 siblings, 1 reply; 6+ messages in thread
From: Wolfram Sang @ 2017-01-13  8:37 UTC (permalink / raw)
  To: Mike Looijmans
  Cc: Vladimir Zapolskiy, linux-i2c, linux-kernel, linux-arm-kernel,
	soren.brinkmann, michal.simek

[-- Attachment #1: Type: text/plain, Size: 912 bytes --]


> I would argue that the "info" message means "the I2C adapter is ready for
> transaction now, and we'll start initializing devices on the bus". That is
> the case before it calls i2c_add_adapter().

I know what you mean, but i2c_add_adapter does more, and it can fail
because the adapter is *not* ready to transfer. Seeing the success
message before is also confusing.

> When i2c_add_adapter() runs, it will start probing devices on the bus. This
> yields very confusing output, as it will output things in a reversed order:
> 
> - device X on I2C bus
> - device Y on I2C bus
> - cdns-i2c ff030000.i2c: 100 kHz mmio ff030000 irq 197

I agree. That being said, somewhen I started working on moving such
messages into the core to save string space and have consistent output.
Then, we can print at the proper time.

So, until then, we should be consistent with the other driver, I'd say.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] i2c: i2c-cadence: Don't register the adapter until it's ready
  2017-01-13  8:37     ` Wolfram Sang
@ 2017-01-13 14:52       ` Mike Looijmans
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Looijmans @ 2017-01-13 14:52 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Vladimir Zapolskiy, linux-i2c, linux-kernel, linux-arm-kernel,
	soren.brinkmann, michal.simek

On 13-01-17 09:37, Wolfram Sang wrote:
>
>> I would argue that the "info" message means "the I2C adapter is ready for
>> transaction now, and we'll start initializing devices on the bus". That is
>> the case before it calls i2c_add_adapter().
>
> I know what you mean, but i2c_add_adapter does more, and it can fail
> because the adapter is *not* ready to transfer. Seeing the success
> message before is also confusing.
>
>> When i2c_add_adapter() runs, it will start probing devices on the bus. This
>> yields very confusing output, as it will output things in a reversed order:
>>
>> - device X on I2C bus
>> - device Y on I2C bus
>> - cdns-i2c ff030000.i2c: 100 kHz mmio ff030000 irq 197
>
> I agree. That being said, somewhen I started working on moving such
> messages into the core to save string space and have consistent output.
> Then, we can print at the proper time.
>
> So, until then, we should be consistent with the other driver, I'd say.

Makes sense.

I'll create a v2 patch to just move the i2c_add_adapter to after writing the 
configuration registers, and leave the dmesg output as is.

Thanks for reviewing,
Mike.


Kind regards,

Mike Looijmans
System Expert

TOPIC Products
Materiaalweg 4, NL-5681 RJ Best
Postbus 440, NL-5680 AK Best
Telefoon: +31 (0) 499 33 69 79
E-mail: mike.looijmans@topicproducts.com
Website: www.topicproducts.com

Please consider the environment before printing this e-mail

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-01-13 17:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-05 10:47 [PATCH] i2c: i2c-cadence: Don't register the adapter until it's ready Mike Looijmans
2017-01-06 21:34 ` Vladimir Zapolskiy
2017-01-12 19:22   ` Wolfram Sang
2017-01-13  6:40   ` Mike Looijmans
2017-01-13  8:37     ` Wolfram Sang
2017-01-13 14:52       ` Mike Looijmans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).