Configuring device with I2C mux

Milton Miller II miltonm at us.ibm.com
Thu Jan 9 01:43:20 AEDT 2020


About 01/07/2020 07:14PM in some timezone, Alex Qiu wrote:
>Hi folks,
>
>We have a JSON file configuring I2C devices of a PCIe card which has
>an 8-channel I2C mux for entity-manager. After we properly configure
>the mux of the card, we get 8 new I2C buses in sysfs; however, we
>don't find an arithmetic way to describe the relationship between the
>new buses and their parent buses.
>
>For example, we have a mux on physical BMC I2C bus i2c-8 spawning a
>couple of child buses including i2c-24 and i2c-26, which are the
>buses for each PCIe card. The mux on i2c-24 PCIe card spawned 8 buses
>from i2c-70 to i2c-77, and the mux on i2c-26 PCIe card spawned ones
>from i2c-62 to i2c-69. We have I2C devices on i2c-76 and i2c-68 needs
>to be configured together with the PCIe card on i2c-24 and i2c-26
>separately.
>
>How do we implement this in the JSON file? If that's not possible to
>do it in JSON merely, what's the suggested approach to implement this
>feature? Device tree? Implement code in entity-manager to walk
>through the I2C sysfs?


I would expect the i2c buses provied by the mux to appear in sysfs
under the hierarchy of the parent bus.  Explore the sysfs directory
structure, I'm making this up, but I've now peeked at i2c-mux.c and
have a better chance getting reality.


/sys/bus/i2c/devices/i2c-8 -> /sys/devices/platform/ahb-432000/i2c-8

/sys/bus/i2c/devices/i2c-24 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24
/sys/bus/i2c/devices/i2c-24 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-25
/sys/bus/i2c/devices/i2c-24 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26

/sys/bus/i2c/devices/i2c-62 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-62
/sys/bus/i2c/devices/i2c-63 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-63
/sys/bus/i2c/devices/i2c-64 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-64
/sys/bus/i2c/devices/i2c-65 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-65
/sys/bus/i2c/devices/i2c-66 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-66
/sys/bus/i2c/devices/i2c-67 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-67
/sys/bus/i2c/devices/i2c-68 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-68
/sys/bus/i2c/devices/i2c-69 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-69
/sys/bus/i2c/devices/i2c-70 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-70
/sys/bus/i2c/devices/i2c-71 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-71
/sys/bus/i2c/devices/i2c-72 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-72
/sys/bus/i2c/devices/i2c-73 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-73
/sys/bus/i2c/devices/i2c-74 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-74
/sys/bus/i2c/devices/i2c-75 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-75
/sys/bus/i2c/devices/i2c-76 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-76
/sys/bus/i2c/devices/i2c-77 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-77

/sys/bus/i2c/devices/i2c-24/mux_device -> /sys/devices/platform/ahb-432000/i2c-8/8-52
/sys/bus/i2c/devices/i2c-25/mux_device -> /sys/devices/platform/ahb-432000/i2c-8/8-52
/sys/bus/i2c/devices/i2c-26/mux_device -> /sys/devices/platform/ahb-432000/i2c-8/8-52

/sys/bus/i2c/devices/8-52/channel-0 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24
/sys/bus/i2c/devices/8-52/channel-1 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-25
/sys/bus/i2c/devices/8-52/channel-2 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26

/sys/bus/i2c/devices/24-52/channel-0 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-62
/sys/bus/i2c/devices/24-52/channel-1 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-63
/sys/bus/i2c/devices/24-52/channel-2 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-64
/sys/bus/i2c/devices/24-52/channel-3 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-65
/sys/bus/i2c/devices/24-52/channel-4 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-66
/sys/bus/i2c/devices/24-52/channel-5 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-67
/sys/bus/i2c/devices/24-52/channel-6 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-68
/sys/bus/i2c/devices/24-52/channel-7 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-24/i2c-69
/sys/bus/i2c/devices/26-52/channel-0 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-70
/sys/bus/i2c/devices/26-52/channel-1 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-71
/sys/bus/i2c/devices/26-52/channel-2 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-72
/sys/bus/i2c/devices/26-52/channel-3 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-73
/sys/bus/i2c/devices/26-52/channel-4 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-74
/sys/bus/i2c/devices/26-52/channel-5 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-75
/sys/bus/i2c/devices/26-52/channel-6 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-76
/sys/bus/i2c/devices/26-52/channel-7 -> /sys/devices/platform/ahb-432000/i2c-8/i2c-26/i2c-77

The child bus will have a symlink "mux_device" pointing to the mux.
The mux device node will have n symlinks "channel-1" where 1 is 
the channel id.

Hmm, there is no apparent code to put a "mux_channel" attribute in 
the adapter node.  The adapter name attribute does include the channel 
id, but its long descriptive text.  Regardless, you should be able to 
find the buses from the mux channel-3 symlinks.

Note: I haven't looked at the JSON to see how much it will change once 
your find the bus.  I'm guessing you will have to generate it by taking 
a template and substituting the bus numbers you find to make the slots
common, alhtough you could just go from the 8-52/channel-3 symlink to
the adapter bus (the device name will still have the bus number in it).

I hope this helps you,

milton



More information about the openbmc mailing list