Difference between revisions of "Tests:I2C-bus-recovery"

From eLinux.org
Jump to: navigation, search
(first half of first rc)
 
(two thirds of rc1)
Line 39: Line 39:
  
 
=Testing I2C bus recovery=
 
=Testing I2C bus recovery=
You should go to the i2c fault injector directory and see the following files:
+
After booting, we activate the I2C GPIO fault injector:
 +
<pre>
 +
# echo 2 > /sys/devices/platform/i2c-11/current_master
 +
i2c-gpio i2c-8: using lines 979 (SDA) and 978 (SCL)
 +
</pre>
 +
 
 +
Then, we switch I2C2 from the IIC to the I2C IP core, where bus recovery was implemented:
 +
<pre>
 +
# echo 1 > /sys/devices/platform/i2c-12/current_master
 +
i2c-rcar e6530000.i2c: probed
 +
</pre>
 +
 
 +
Now, we create the stalled SDA case again using the [[Tests:I2C-fault-injection|I2C fault injector]]:
 
<pre>
 
<pre>
 
# cd /sys/kernel/debug/i2c-fault-injector/i2c-8/
 
# cd /sys/kernel/debug/i2c-fault-injector/i2c-8/
# ls -1
+
# echo 0x12 > incomplete_transfer
incomplete_transfer
+
</pre>
scl
+
 
sda
+
Using a scope, we verify that SDA is stuck low:
 +
[[File:wsa-i2c_fi-device-keeps.png|800x428px|Incomplete transfer on Lager, device does not react]]
 +
 
 +
Now, we try to read register 8 from the audio codec via the stalled I2C bus:
 +
<pre>
 +
# i2cget -y -f 2 0x12 8
 +
0xe1
 
</pre>
 
</pre>
  
Please refer to the documentation file in ''Documentation/i2c/gpio-fault-injection'' about the meaning of the files.
+
So, we got a valid response from this read request. Using a scope, we see the following happening:

Revision as of 05:54, 3 December 2017

!DRAFT! This document describes how to test if I2C bus recovery from the Linux I2C core was applied. A Renesas I2C IP core used on a Renesas Lager board serves as an example platform here.

Setup

Kernel Version and Configuration

Support for this feature is expected to land upstream in v4.16. It is currently available in a topic branch:

git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git renesas/topic/rcar-i2c-recovery

The following kernel options need to be set in addition to the defconfig:

CONFIG_I2C_GPIO=y
CONFIG_I2C_GPIO_FAULT_INJECTOR=y

Hardware Environment

Lager/r8a7790 (R-Car H2 SoC)

You need to connect the pins:

EXIO_C 78 <-> EXIO_A 58 (for SCL)
EXIO_C 80 <-> EXIO_A 60 (for SDA)

This will connect the I2C1 and the I2C2 bus. We will use the I2C demultiplexer at runtime to switch I2C1 to GPIO:

# echo 2 > /sys/devices/platform/i2c-11/current_master

Software Environment

Only a busybox with standard commands like cd, cat, echo is needed.

Previous state

As documented in the test page for I2C fault injection, an incomplete transfer to the audio codec resulted in the SDA line stuck low. It was concluded that "the audio codec does not have any timeout detection and there is no external chip to reactivate the bus. It is now the I2C bus masters turn to detect this condition and to recover the bus by toggling SCL."

Testing I2C bus recovery

After booting, we activate the I2C GPIO fault injector:

# echo 2 > /sys/devices/platform/i2c-11/current_master
i2c-gpio i2c-8: using lines 979 (SDA) and 978 (SCL)

Then, we switch I2C2 from the IIC to the I2C IP core, where bus recovery was implemented:

# echo 1 > /sys/devices/platform/i2c-12/current_master
i2c-rcar e6530000.i2c: probed

Now, we create the stalled SDA case again using the I2C fault injector:

# cd /sys/kernel/debug/i2c-fault-injector/i2c-8/
# echo 0x12 > incomplete_transfer

Using a scope, we verify that SDA is stuck low: Incomplete transfer on Lager, device does not react

Now, we try to read register 8 from the audio codec via the stalled I2C bus:

# i2cget -y -f 2 0x12 8
0xe1

So, we got a valid response from this read request. Using a scope, we see the following happening: