Linux i2c mapping

rreignierrreignier New Member Posts: 52 ✭✭

Does some know the mapping of the i2c buses on Linux.

/sys/bus/i2c/devices/ shows 10 i2c buses:

$ ls -l /sys/bus/i2c/devices/
total 0
lrwxrwxrwx 1 root root 0 Jan 20 17:33 i2c-0 -> ../../../devices/pci0000:00/0000:00:16.0/i2c_designware.0/i2c-0
lrwxrwxrwx 1 root root 0 Jan 20 17:33 i2c-1 -> ../../../devices/pci0000:00/0000:00:16.1/i2c_designware.1/i2c-1
lrwxrwxrwx 1 root root 0 Jan 20 17:33 i2c-2 -> ../../../devices/pci0000:00/0000:00:17.0/i2c_designware.2/i2c-2
lrwxrwxrwx 1 root root 0 Jan 20 17:33 i2c-3 -> ../../../devices/pci0000:00/0000:00:02.0/i2c-3
lrwxrwxrwx 1 root root 0 Jan 20 17:33 i2c-4 -> ../../../devices/pci0000:00/0000:00:02.0/i2c-4
lrwxrwxrwx 1 root root 0 Jan 20 17:33 i2c-5 -> ../../../devices/pci0000:00/0000:00:02.0/i2c-5
lrwxrwxrwx 1 root root 0 Jan 20 17:33 i2c-6 -> ../../../devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-1/i2c-6
lrwxrwxrwx 1 root root 0 Jan 20 17:33 i2c-7 -> ../../../devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-2/i2c-7
lrwxrwxrwx 1 root root 0 Jan 20 17:33 i2c-8 -> ../../../devices/pci0000:00/0000:00:17.2/i2c_designware.3/i2c-8
lrwxrwxrwx 1 root root 0 Jan 20 17:33 i2c-9 -> ../../../devices/pci0000:00/0000:00:17.3/i2c_designware.4/i2c-9

The 100-pin connector has I2C0, I2C1 and I2C6. But what are their mapping to Linux buses?

Thanks you.

Comments

  • rreignierrreignier New Member Posts: 52 ✭✭

    Actually, the mapping seem to change upon reboot.
    I have an IMU connected to I2C-1 on 100 pin connector.
    After a cold boot I have:

    [email protected]:~/scripts$ i2cdetect -r -y 6
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- 1c -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- 6a -- -- -- -- --
    70: -- -- -- -- -- -- -- --                        
    [email protected]:~/scripts$ ls -l /sys/class/i2c-adapter/
    total 0
    lrwxrwxrwx 1 root root 0 Mar  6 18:17 i2c-0 -> ../../devices/pci0000:00/0000:00:02.0/i2c-0
    lrwxrwxrwx 1 root root 0 Mar  6 18:17 i2c-1 -> ../../devices/pci0000:00/0000:00:02.0/i2c-1
    lrwxrwxrwx 1 root root 0 Mar  6 18:17 i2c-2 -> ../../devices/pci0000:00/0000:00:02.0/i2c-2
    lrwxrwxrwx 1 root root 0 Mar  6 18:17 i2c-3 -> ../../devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-1/i2c-3
    lrwxrwxrwx 1 root root 0 Mar  6 18:17 i2c-4 -> ../../devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-2/i2c-4
    lrwxrwxrwx 1 root root 0 Mar  6 18:17 i2c-5 -> ../../devices/pci0000:00/0000:00:16.0/i2c_designware.0/i2c-5
    lrwxrwxrwx 1 root root 0 Mar  6 18:17 i2c-6 -> ../../devices/pci0000:00/0000:00:16.1/i2c_designware.1/i2c-6
    lrwxrwxrwx 1 root root 0 Mar  6 18:17 i2c-7 -> ../../devices/pci0000:00/0000:00:17.0/i2c_designware.2/i2c-7
    lrwxrwxrwx 1 root root 0 Mar  6 18:17 i2c-8 -> ../../devices/pci0000:00/0000:00:17.2/i2c_designware.3/i2c-8
    lrwxrwxrwx 1 root root 0 Mar  6 18:17 i2c-9 -> ../../devices/pci0000:00/0000:00:17.3/i2c_designware.4/i2c-9
    

    After a reboot:

    [email protected]:~$ i2cdetect -r -y 6
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    70: -- -- -- -- -- -- -- --                         
    [email protected]:~$ i2cdetect -r -y 1
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
    10: -- -- -- -- -- -- -- -- -- -- -- -- 1c -- -- -- 
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    60: -- -- -- -- -- -- -- -- -- -- 6a -- -- -- -- -- 
    70: -- -- -- -- -- -- -- --                         
    [email protected]:~$ ls -l /sys/class/i2c-adapter/
    total 0
    lrwxrwxrwx 1 root root 0 Mar  6 18:38 i2c-0 -> ../../devices/pci0000:00/0000:00:16.0/i2c_designware.0/i2c-0
    lrwxrwxrwx 1 root root 0 Mar  6 18:38 i2c-1 -> ../../devices/pci0000:00/0000:00:16.1/i2c_designware.1/i2c-1
    lrwxrwxrwx 1 root root 0 Mar  6 18:38 i2c-2 -> ../../devices/pci0000:00/0000:00:17.0/i2c_designware.2/i2c-2
    lrwxrwxrwx 1 root root 0 Mar  6 18:38 i2c-3 -> ../../devices/pci0000:00/0000:00:17.2/i2c_designware.3/i2c-3
    lrwxrwxrwx 1 root root 0 Mar  6 18:38 i2c-4 -> ../../devices/pci0000:00/0000:00:17.3/i2c_designware.4/i2c-4
    lrwxrwxrwx 1 root root 0 Mar  6 18:38 i2c-5 -> ../../devices/pci0000:00/0000:00:02.0/i2c-5
    lrwxrwxrwx 1 root root 0 Mar  6 18:38 i2c-6 -> ../../devices/pci0000:00/0000:00:02.0/i2c-6
    lrwxrwxrwx 1 root root 0 Mar  6 18:38 i2c-7 -> ../../devices/pci0000:00/0000:00:02.0/i2c-7
    lrwxrwxrwx 1 root root 0 Mar  6 18:38 i2c-8 -> ../../devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-1/i2c-8
    lrwxrwxrwx 1 root root 0 Mar  6 18:38 i2c-9 -> ../../devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-2/i2c-9
    

    So the i2c assignment is not predictable. Do you have any workaround?

  • DCleriDCleri Administrator, AAEON Posts: 998 admin

    From Kernel documentation: https://www.kernel.org/doc/Documentation/i2c/dev-interface

    "Now, you have to decide which adapter you want to access. You should
    inspect /sys/class/i2c-dev/ or run "i2cdetect -l" to decide this.
    Adapter numbers are assigned somewhat dynamically, so you can not
    assume much about them. They can even change from one boot to the next."

  • rreignierrreignier New Member Posts: 52 ✭✭

    Thank you @DCleri

    I have ended up with this small script to determine the i2c interface on boot:

    pushd /sys/devices/pci0000\:00/0000\:00\:16.1/i2c_designware.1/ > /dev/null
    I2CDEV=$(ls -1 | grep "i2c-")
    echo "IMU on $I2CDEV"
    popd > /dev/null
    
  • DCleriDCleri Administrator, AAEON Posts: 998 admin

    I am glad that you have found that solution, I am sure it can be helpful to other people too.

Sign In or Register to comment.