I2C

Inter-Integrated Circuit (I2C) Bus commands

I2C

Use the switch chip’s own I2C (SMBus) controller: probe for devices, show the device table, and read or write bus devices directly. The other board commands (NVram, ADC, TEMPerature …) use the device table that i2c probe builds.

On a SONiC switch, the platform’s fans, sensors, EEPROMs and optics are normally on the CPU’s I2C buses, handled by the platform drivers; the switch chip’s bus may have nothing attached, or devices that the platform does not expect to be touched. i2c show is safe: it prints the controller mode and speed and how many bytes it has moved. On a SONiC Trident 3 switch both counters are 0, because nothing in SONiC uses this bus.

Warning

probe and scan address every slave address on the bus, and write/writew write to devices directly. On a bus shared with platform devices this can confuse them. reset resets the controller.

Sub-command keywords may be abbreviated to any prefix (s is show, r is reset), except that read, readb, readw, write and writew must be typed in full. Read and write commands need i2c probe first.

Hardware-validated

drivshell> i2c show
unit 0 i2c  bus: mode=INTR speed=110kbps SOC_address=0x00
unit 0 i2c  bus: received 0 bytes, transmitted 0 bytes
I2C probe [pio | intr] [<speed>] [quiet]

Probe the bus and build the device table, optionally switching the controller to polled (pio) or interrupt mode and to another bus speed. i2c scan [pio|intr] [<saddr>] [quiet] only lists the devices found.

Unvalidated

drivshell> i2c probe quiet
I2C log

Show the controller’s transaction log (backlog in reverse order, clearlog to reset it). i2c speeds lists the supported clock rates. Read-only.

Hardware-validated

drivshell> i2c log
NOTICE: SOC_I2C_EVENT_LOGGING not compiled in.
I2C read <saddr> <comm> <len>

Read <len> bytes from slave <saddr> starting at register <comm>. readw <saddr> <comm> reads one word, readb <saddr> <len> reads without a register address. write <saddr> <comm> [<data>] and writew <saddr> <comm> [<word>] write.

Unvalidated

drivshell> i2c read <saddr> 0 16
I2C device <add | remove> <dev_name> <saddr> <drv_name>

Add a device to, or remove it from, the custom device table that i2c probe uses.

Unvalidated

drivshell> i2c device add <dev_name> <saddr> <drv_name>

Built-in help

Usages:
    i2c probe [pio|intr] [speed] [quiet]
        - probe devices on I2C bus and build device tree.
          If "intr" or "pio" is specified, change to that bus mode.
          If a valid speed is specified, change the bus to that speed.
          If "quiet" is specified, suppresses probe output.
    i2c scan [pio|intr] [saddr] [quiet]
        - Scan devices on I2C bus and display the device list.
    i2c log
        - show I2C bus transaction log.
    i2c backlog
        - show I2C bus transaction log (in reverse order).
    i2c clearlog
        - reset I2C bus transaction log.
    i2c reset
        - reset I2C bus controller core.
    i2c speeds
        - show supported I2C bus controller clock rates.
    i2c show
        - show devices found and their attributes.
    i2c read saddr comm len
        - generic interface to read devices, do probe first
    i2c readw saddr comm
        - generic interface to read one word from devices, do probe first
    i2c readb saddr len
        - generic interface to read devices without register based access, do probe first
    i2c write saddr comm [data]
        - generic interface to write a byte to devices, do probe first
        - comm is data when writing directly otherwise command register
i2c writew saddr comm [word_data]
         - generic interface to write a word to devices, do probe first
        - comm is data when writing directly otherwise command register
i2c device add <dev_name> <saddr> <drv_name>
        - add device to custom device descriptor.
          i2c probe will probe the deivce existed in the custom device
          descriptor
i2c device remove <dev_name> <saddr> <drv_name>
        - remove device to custom device descriptor.

Further reading

BCM_SDK命令.