3
votes

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.

1
Has your kernel version changed? It is likely that the newer kernel simply creates the sysfs entries when the device is actually probed. Maybe check the source to see what happens during the probe function for the GPIO expander.bodangly
Yes, kernel has changed. PowerPC was 2.6.37.6 so quite a different version. Agreed that is possibly the reason for the change. I suppose I could try to delve into the kernel source but not sure where the probe is; maybe gpiolib.c? Was hoping there was a post-boot way to handle this without changing the kernel.Bruce
As you can see in my answer, I can confirm it is only added if the device probes.bodangly

1 Answers

1
votes

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.