Enable i2c tracing on Linux

To inspect traffic between Linux and I2C devices, perform the following steps:

cd /sys/kernel/debug/tracing/

echo 1 >  events/i2c/enable
echo 1 > tracing_on

# Then run command that will trigger i2c communication
# in my case it's hwclock
hwclock

## See the data

cat trace

Output sample:

         hwclock-1562  [003] ....   229.699432: i2c_reply: i2c-1 #1 a=052 f=0001 l=1 [10]
         hwclock-1562  [003] ....   229.699435: i2c_result: i2c-1 n=2 ret=2
         hwclock-1562  [003] ....   229.699442: i2c_write: i2c-1 #0 a=052 f=0000 l=1 [00]
         hwclock-1562  [003] ....   229.699444: i2c_read: i2c-1 #1 a=052 f=0001 l=7
         hwclock-1562  [003] ....   229.700446: i2c_reply: i2c-1 #1 a=052 f=0001 l=7 [29-33-08-00-10-06-22]
         hwclock-1562  [003] ....   229.700450: i2c_result: i2c-1 n=2 ret=2
         hwclock-1562  [003] ....   229.700464: i2c_write: i2c-1 #0 a=052 f=0000 l=1 [0e]
         hwclock-1562  [003] ....   229.700467: i2c_read: i2c-1 #1 a=052 f=0001 l=1
         hwclock-1562  [003] ....   229.700900: i2c_reply: i2c-1 #1 a=052 f=0001 l=1 [10]
         hwclock-1562  [003] ....   229.700903: i2c_result: i2c-1 n=2 ret=2
         hwclock-1562  [003] ....   229.700910: i2c_write: i2c-1 #0 a=052 f=0000 l=1 [00]
         hwclock-1562  [003] ....   229.700912: i2c_read: i2c-1 #1 a=052 f=0001 l=7
         hwclock-1562  [003] ....   229.701913: i2c_reply: i2c-1 #1 a=052 f=0001 l=7 [29-33-08-00-10-06-22]
         hwclock-1562  [003] ....   229.701916: i2c_result: i2c-1 n=2 ret=2
         hwclock-1562  [003] ....   229.701930: i2c_write: i2c-1 #0 a=052 f=0000 l=1 [0e]
         hwclock-1562  [003] ....   229.701933: i2c_read: i2c-1 #1 a=052 f=0001 l=1
         hwclock-1562  [003] ....   229.702370: i2c_reply: i2c-1 #1 a=052 f=0001 l=1 [10]
         hwclock-1562  [003] ....   229.702373: i2c_result: i2c-1 n=2 ret=2
         hwclock-1562  [003] ....   229.702380: i2c_write: i2c-1 #0 a=052 f=0000 l=1 [00]
         hwclock-1562  [003] ....   229.702383: i2c_read: i2c-1 #1 a=052 f=0001 l=7
         hwclock-1562  [003] ....   229.703389: i2c_reply: i2c-1 #1 a=052 f=0001 l=7 [29-33-08-00-10-06-22]
         hwclock-1562  [003] ....   229.703392: i2c_result: i2c-1 n=2 ret=2
         hwclock-1562  [003] ....   229.703406: i2c_write: i2c-1 #0 a=052 f=0000 l=1 [0e]
         hwclock-1562  [003] ....   229.703408: i2c_read: i2c-1 #1 a=052 f=0001 l=1
         hwclock-1562  [003] ....   229.703841: i2c_reply: i2c-1 #1 a=052 f=0001 l=1 [10]
         hwclock-1562  [003] ....   229.703844: i2c_result: i2c-1 n=2 ret=2
         hwclock-1562  [003] ....   229.703851: i2c_write: i2c-1 #0 a=052 f=0000 l=1 [00]
         hwclock-1562  [003] ....   229.703853: i2c_read: i2c-1 #1 a=052 f=0001 l=7
         hwclock-1562  [003] ....   229.704853: i2c_reply: i2c-1 #1 a=052 f=0001 l=7 [30-33-08-00-10-06-22]
         hwclock-1562  [003] ....   229.704856: i2c_result: i2c-1 n=2 ret=2

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *