Skip to contentSkip to conversation

fw_devlink: consumers are not linked again when a gpiochip is re-added

DISCUSSION Adrian Ambrozewicz 1 participant 1 message Nov 25

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi Saravana,

When a gpiochip is removed and added again for the same DT node, its consumers do not follow it. We hit it with a USB GPIO expander in DT (emulated so far). gpio-sim shows it on v7.3-rc7 (arm64 QEMU virt):

  gpio-sim {
  	compatible = "gpio-simulator";
  	sim: bank0 {
  		gpio-controller;
  		#gpio-cells = <2>;
  		ngpios = <16>;
  		gpio-sim,label = "sim-bank0";
  	};
  };
  leds {
  	compatible = "gpio-leds";
  	power_led { gpios = <&sim 2 GPIO_ACTIVE_LOW>; };
  	fault_led { gpios = <&sim 6 GPIO_ACTIVE_HIGH>; };
  	uid_led { gpios = <&sim 9 GPIO_ACTIVE_HIGH>; };
  };
  regulator-own {
  	compatible = "regulator-fixed";
  	regulator-name = "own_node_consumer";
  	gpio = <&sim 4 GPIO_ACTIVE_HIGH>;
  	regulator-min-microvolt = <1800000>;
  	regulator-max-microvolt = <1800000>;
  	enable-active-high;
  	regulator-always-on;
  	regulator-boot-on;
  };
  # echo gpio-sim > /sys/bus/platform/drivers/gpio-sim/unbind
  # echo gpio-sim > /sys/bus/platform/drivers/gpio-sim/bind

regulator-own has a managed link to the gpiochip. It is unbound with gpio-sim and not probed again: nothing re-queues it, and its fwnode link went with the first device link (drivers/base/core.c:2331, :2373).

leds has no device link to the gpiochip even before the unbind. From the code, references in child nodes get SYNC_STATE_ONLY links (:2221), which are dropped when leds binds (:1440). It stays bound and holds no line on the new chip. Each new link is refused because leds has probed (:851-859):

leds-gpio leds: Failed to create device link (0x180) with supplier gpiochip2 for /leds/uid_led

The leds half does not need the device to go: with the same consumers on QEMU virt's PL061 GPIO controller and only its driver rebound, regulator-own is probed again, but leds holds no line on the new gpiochip. From the code, an I2C expander on a rebound I2C controller hits both halves.

Herve reported the leds case in 2024 and you called it a generic gap for class devices [1]; in August you offered to write class device support for device links [2]. The regulator case matches your 2023 suggestion [3], though from the code a re-queued consumer would have no device link afterwards. I found no later series for either.

Is the class device series still planned, and would it cover a gpiochip that is removed and added again? Herve's leds-gpio link, ported to v7.3-rc7, only gets leds unbound when the GPIO goes; nothing probes it again when the chip returns. Would that be acceptable meanwhile? I can test either with this reproducer.

[1] https://lore.kernel.org/all/CAGETcx_=g1dCH=YMUkc7VquUmLs=bNZMspUxH+V49uhcV0Bx2w@mail.gmail.com/
[2] https://lore.kernel.org/all/CACRMN=fEPoyEk1oi4QRMX0whMEF=xQv=kkd62bueKTKWtxDedA@mail.gmail.com/
[3] https://lore.kernel.org/all/CAGETcx_fXa6Zt_gkTQKw8Wt11EmSt8ZQ6TxKi5P+5ii3EvwsdA@mail.gmail.com/

Thanks,
Adrian