Bruce
Bruce

Reputation: 33

Linux, ARM: Why is gpiochip<num> only created if I2C GPIO Expander is present at boot?

Using Linux 3.14.52 on a imx6sx hardware platform (NXP embedded ARM).

The problem is that PCF8575 I2C GPIO expanders specified in the device tree are not instantiated as devices in the /sys/class/gpio structure unless they are present during kernel boot. The devices are listed in the /sys/bus/i2c/devices/i2c-1 (i2c bus 1) structures but are not given gpiochip 's in the /sys/class/gpio structure.

Is there a way to have these devices assigned as gpiochip after boot once they are added to the system?

On previous (PowerPC) platform, all devices listed in the device tree were assigned gpiochip's regardless of whether they were on during kernel boot. But with our ARM platform, the devices must be available during kernel boot. I have tried changing the kernel i2c/gpio options (via .config) as close to the previous platform as possible but this seems to have no effect.

Upvotes: 3

Views: 2096

Answers (1)

bodangly
bodangly

Reputation: 2624

For sure the kernel worked differently regarding sysfs in the 2.6 kernel branch. I have experienced similar issues as well. It has to do with handling of the device tree. The device tree will get unflattened, but this only kicks off the actual discovery of devices. If the devices do not actual exist, they will not be probed and will not have entries created in sysfs.

Device Tree Usage

Linux board support code calls of_platform_populate(NULL, NULL, NULL, NULL) to kick off discovery of devices at the root of the tree. The parameters are all NULL because when starting from the root of the tree, there is no need to provide a starting node (the first NULL), a parent struct device (the last NULL), and we're not using a match table (yet). For a board that only needs to register devices, .init_machine() can be completely empty except for the of_platform_populate() call.

So the device tree will only tell the kernel what to discover, it will not actually add anything if it is not found.

I can confirm the gpiochip is ONLY added at probe of your device:

gpio-pcf857x.c

Notice the call on line 397 to gpiochip_add

What I would recommend is to try compiling your kernel with the gpio expander set as a module and then insmod it after it has actually been attached.

Upvotes: 1

Related Questions