The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Carlo Szelinsky <github@szelinsky.de>
To: Oleksij Rempel <o.rempel@pengutronix.de>,
	Kory Maincent <kory.maincent@bootlin.com>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>,
	Jonas Jelonek <jelonek.jonas@gmail.com>,
	Ross Cawston <ross@r-sc.ca>,
	netdev@vger.kernel.org, linux-leds@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH net-next v7 2/2] net: pse-pd: add LED triggers for each PI
Date: Sat,  5 Dec 2026 14:37:42 +0100	[thread overview]
Message-ID: <20261205133742.905114-3-github@szelinsky.de> (raw)
In-Reply-To: <20261205133742.905114-1-github@szelinsky.de>

PoE switches often have one LED per port to show its PoE state. The
PSE core has no way to drive such an LED today.

Add two LED triggers per PI. "delivering" is on while the PI powers a
PD, "enabled" while the PI is admin enabled. The triggers are named
"pse-<dev_name>:pi<N>:delivering" and "...:enabled". Userspace binds an
LED to them in sysfs, or a board with linux,default-trigger, like the
PHY LED triggers.

The triggers need the new option PSE_LED_TRIGGERS, like LED_TRIGGER_PHY
for the PHY LED triggers.

Most PSE drivers report no event when the power of a PI comes on, and
some report no events at all. So while an LED uses "delivering", the
core reads the power state every second. Drivers that report the
power-on still update it at once.

Under software power control, the core keeps a PI off in hardware
until a PD is detected. "enabled" then shows the admin state that the
core keeps, as ethtool does. When a PHY first gets a PI, the core sets
this state. It now does this under pcdev->lock and updates the
"enabled" LED, so the LED is right for a PI that was already on.

Reading the PI state can be slow, pd692x0 for example needs 30 ms or
more per command. So the core only reads it while an LED uses the
trigger.

If a trigger fails to register, the core only warns. LEDs are optional
and must not stop PoE.

The triggers are registered before the PI regulators. The regulator
ops update the LEDs, so devres must remove the triggers only after the
regulators. pse_register_pw_ds() now sets pi[].pw_d under pcdev->lock,
as an LED can be bound before the power domains exist.

Signed-off-by: Carlo Szelinsky <github@szelinsky.de>
---
 drivers/net/pse-pd/Kconfig    |  10 +
 drivers/net/pse-pd/pse_core.c | 397 +++++++++++++++++++++++++++++++++-
 include/linux/pse-pd/pse.h    |  11 +-
 3 files changed, 413 insertions(+), 5 deletions(-)

diff --git a/drivers/net/pse-pd/Kconfig b/drivers/net/pse-pd/Kconfig
index a0f2ae668c67..a78dfa3155e8 100644
--- a/drivers/net/pse-pd/Kconfig
+++ b/drivers/net/pse-pd/Kconfig
@@ -13,6 +13,16 @@ menuconfig PSE_CONTROLLER
 
 if PSE_CONTROLLER
 
+config PSE_LED_TRIGGERS
+	bool "LED triggers for PSE PIs"
+	depends on LEDS_TRIGGERS
+	help
+	  Adds two LED triggers for each PSE PI: "delivering" is on while
+	  the PI powers a PD, "enabled" while the PI is admin enabled.
+	  Userspace binds an LED to them in sysfs.
+
+	  If unsure, say no.
+
 config PSE_REALTEK_MCU
 	tristate
 	help
diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c
index 07cbc585a898..f350e3c567d6 100644
--- a/drivers/net/pse-pd/pse_core.c
+++ b/drivers/net/pse-pd/pse_core.c
@@ -8,6 +8,7 @@
 #include <linux/device.h>
 #include <linux/ethtool.h>
 #include <linux/ethtool_netlink.h>
+#include <linux/leds.h>
 #include <linux/of.h>
 #include <linux/phy.h>
 #include <linux/pse-pd/pse.h>
@@ -22,6 +23,9 @@
 /* Fast enough for PD events, low load on the I2C bus */
 #define PSE_POLL_INTERVAL_MS 500
 
+/* Fast enough for a person looking at an LED */
+#define PSE_LED_REFRESH_MS 1000
+
 /**
  * struct pse_poll - poll state of a PSE controller
  * @pcdev: the polled PSE controller
@@ -369,6 +373,7 @@ pse_pi_is_admin_enable_pending(struct pse_controller_dev *pcdev, int id)
 static int _pse_pi_delivery_power_sw_pw_ctrl(struct pse_controller_dev *pcdev,
 					     int id,
 					     struct netlink_ext_ack *extack);
+static void pse_led_update(struct pse_controller_dev *pcdev, int id);
 
 /**
  * pse_pw_d_retry_power_delivery - Retry power delivery for pending ports in a
@@ -406,6 +411,9 @@ static void pse_pw_d_retry_power_delivery(struct pse_controller_dev *pcdev,
 		ret = _pse_pi_delivery_power_sw_pw_ctrl(pcdev, i, &extack);
 		if (ret == -ERANGE)
 			prio_max = pcdev->pi[i].prio;
+		/* No event comes for this, so update the LEDs here */
+		if (!ret)
+			pse_led_update(pcdev, i);
 	}
 }
 
@@ -520,6 +528,7 @@ static int pse_disable_pi_pol(struct pse_controller_dev *pcdev, int id)
 	ret = _pse_pi_disable(pcdev, id);
 	if (ret)
 		notifs |= ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR;
+	pse_led_update(pcdev, id);
 
 	ntf.notifs = notifs;
 	ntf.id = id;
@@ -697,6 +706,340 @@ static int _pse_pi_delivery_power_sw_pw_ctrl(struct pse_controller_dev *pcdev,
 	return 0;
 }
 
+/**
+ * struct pse_pi_led_triggers - LED triggers of a PSE PI
+ *
+ * @delivering: LED trigger for the power delivering state
+ * @enabled: LED trigger for the admin enabled state
+ * @pcdev: the PSE controller of the PI
+ * @id: PI index
+ * @nr_delivering: number of LEDs bound to @delivering
+ * @nr_enabled: number of LEDs bound to @enabled
+ * @last_delivering: last delivering state, for change detection
+ * @last_enabled: last enabled state, for change detection
+ *
+ * The counters and the last states are changed under pcdev->lock.
+ */
+struct pse_pi_led_triggers {
+	struct led_trigger delivering;
+	struct led_trigger enabled;
+	struct pse_controller_dev *pcdev;
+	int id;
+	unsigned int nr_delivering;
+	unsigned int nr_enabled;
+	bool last_delivering;
+	bool last_enabled;
+};
+
+#if IS_ENABLED(CONFIG_PSE_LED_TRIGGERS)
+/**
+ * pse_pi_get_states - Read the delivering and enabled state of a PI
+ * @pcdev: PSE controller device
+ * @id: PI index
+ * @delivering: out, true if the PI delivers power. NULL to not read it.
+ * @enabled: out, true if the PI is admin enabled, as ethtool reports it.
+ *	     NULL to not read it.
+ *
+ * Reading a state can be slow, so read only the ones asked for.
+ *
+ * Return: 0 on success, negative errno on failure.
+ */
+static int pse_pi_get_states(struct pse_controller_dev *pcdev, int id,
+			     bool *delivering, bool *enabled)
+{
+	struct pse_admin_state admin_state = {};
+	struct pse_pw_status pw_status = {};
+	int ret;
+
+	lockdep_assert_held(&pcdev->lock);
+
+	if (delivering) {
+		ret = pcdev->ops->pi_get_pw_status(pcdev, id, &pw_status);
+		if (ret)
+			return ret;
+
+		*delivering = pw_status.c33_pw_status ==
+			      ETHTOOL_C33_PSE_PW_D_STATUS_DELIVERING ||
+			      pw_status.podl_pw_status ==
+			      ETHTOOL_PODL_PSE_PW_D_STATUS_DELIVERING;
+	}
+
+	if (!enabled)
+		return 0;
+
+	/* Under software power control, the hardware is off until a PD
+	 * is detected, so use the admin state the core keeps.
+	 */
+	if (pse_pw_d_is_sw_pw_control(pcdev, pcdev->pi[id].pw_d)) {
+		*enabled = pcdev->pi[id].admin_state_enabled;
+		return 0;
+	}
+
+	ret = pcdev->ops->pi_get_admin_state(pcdev, id, &admin_state);
+	if (ret)
+		return ret;
+
+	*enabled = admin_state.c33_admin_state ==
+		   ETHTOOL_C33_PSE_ADMIN_STATE_ENABLED ||
+		   admin_state.podl_admin_state ==
+		   ETHTOOL_PODL_PSE_ADMIN_STATE_ENABLED;
+
+	return 0;
+}
+
+/* Fire @trig if @state changed */
+static void pse_led_set(struct led_trigger *trig, bool *last, bool state)
+{
+	if (*last == state)
+		return;
+
+	*last = state;
+	led_trigger_event(trig, state ? LED_FULL : LED_OFF);
+}
+
+/**
+ * pse_led_update - Update the LED triggers of a PI
+ * @pcdev: PSE controller device
+ * @id: PI index
+ *
+ * Reads the state of each trigger that has an LED bound, and fires the
+ * trigger if the state changed. Each state is read on its own, so one
+ * failed read does not stop the other trigger. pse_led_activate() reads
+ * the state when an LED is bound.
+ */
+static void pse_led_update(struct pse_controller_dev *pcdev, int id)
+{
+	struct pse_pi_led_triggers *trigs = pcdev->pi[id].led_trigs;
+	bool state;
+
+	lockdep_assert_held(&pcdev->lock);
+
+	/* No triggers for a PI that is not described */
+	if (!trigs)
+		return;
+
+	if (trigs->nr_delivering &&
+	    !pse_pi_get_states(pcdev, id, &state, NULL))
+		pse_led_set(&trigs->delivering, &trigs->last_delivering,
+			    state);
+
+	if (trigs->nr_enabled &&
+	    !pse_pi_get_states(pcdev, id, NULL, &state))
+		pse_led_set(&trigs->enabled, &trigs->last_enabled, state);
+}
+
+/* An LED was just bound to @trig. Show its state now, pse_led_update()
+ * skipped it while no LED was bound. Read only this state, as reads can
+ * be slow. For "delivering", also start the refresh.
+ */
+static void pse_led_activate(struct pse_pi_led_triggers *trigs,
+			     struct led_trigger *trig, unsigned int *nr,
+			     bool *last, struct led_classdev *led_cdev)
+{
+	struct pse_controller_dev *pcdev = trigs->pcdev;
+	bool is_delivering = trig == &trigs->delivering;
+	bool state = false;
+	int ret;
+
+	mutex_lock(&pcdev->lock);
+	(*nr)++;
+	ret = pse_pi_get_states(pcdev, trigs->id,
+				is_delivering ? &state : NULL,
+				is_delivering ? NULL : &state);
+	/* The last state is old if no other LED was bound */
+	if (ret && *nr == 1)
+		*last = false;
+	if (!ret && *last != state) {
+		*last = state;
+		led_trigger_event(trig, state ? LED_FULL : LED_OFF);
+	} else {
+		led_set_brightness(led_cdev, *last ? LED_FULL : LED_OFF);
+	}
+	if (is_delivering && !pcdev->unregistering)
+		queue_delayed_work(system_freezable_power_efficient_wq,
+				   &pcdev->led_work,
+				   msecs_to_jiffies(PSE_LED_REFRESH_MS));
+	mutex_unlock(&pcdev->lock);
+}
+
+/* Most drivers report no event when the power of a PI comes on. So while
+ * an LED uses "delivering", read it again every second. Take the lock per
+ * PI, as reads can be slow.
+ */
+static void pse_led_refresh_worker(struct work_struct *work)
+{
+	struct pse_controller_dev *pcdev =
+		container_of(work, struct pse_controller_dev, led_work.work);
+	unsigned long start = jiffies;
+	bool bound = false;
+	int i;
+
+	for (i = 0; i < pcdev->nr_lines; i++) {
+		struct pse_pi_led_triggers *trigs;
+		bool delivering;
+
+		mutex_lock(&pcdev->lock);
+		trigs = pcdev->pi[i].led_trigs;
+		if (trigs && trigs->nr_delivering && !pcdev->unregistering) {
+			bound = true;
+			if (!pse_pi_get_states(pcdev, i, &delivering, NULL))
+				pse_led_set(&trigs->delivering,
+					    &trigs->last_delivering,
+					    delivering);
+		}
+		mutex_unlock(&pcdev->lock);
+	}
+
+	/* Stop when no LED uses "delivering". Binding one starts it again. */
+	if (!bound)
+		return;
+
+	/* Wait at least as long as this round took. So on a slow
+	 * controller with many PIs, at most half of the time goes to the
+	 * LEDs.
+	 */
+	queue_delayed_work(system_freezable_power_efficient_wq,
+			   &pcdev->led_work,
+			   max(msecs_to_jiffies(PSE_LED_REFRESH_MS),
+			       jiffies - start));
+}
+
+static int pse_led_delivering_activate(struct led_classdev *led_cdev)
+{
+	struct pse_pi_led_triggers *trigs =
+		container_of(led_cdev->trigger, struct pse_pi_led_triggers,
+			     delivering);
+
+	pse_led_activate(trigs, &trigs->delivering, &trigs->nr_delivering,
+			 &trigs->last_delivering, led_cdev);
+	return 0;
+}
+
+static void pse_led_delivering_deactivate(struct led_classdev *led_cdev)
+{
+	struct pse_pi_led_triggers *trigs =
+		container_of(led_cdev->trigger, struct pse_pi_led_triggers,
+			     delivering);
+
+	mutex_lock(&trigs->pcdev->lock);
+	trigs->nr_delivering--;
+	mutex_unlock(&trigs->pcdev->lock);
+}
+
+static int pse_led_enabled_activate(struct led_classdev *led_cdev)
+{
+	struct pse_pi_led_triggers *trigs =
+		container_of(led_cdev->trigger, struct pse_pi_led_triggers,
+			     enabled);
+
+	pse_led_activate(trigs, &trigs->enabled, &trigs->nr_enabled,
+			 &trigs->last_enabled, led_cdev);
+	return 0;
+}
+
+static void pse_led_enabled_deactivate(struct led_classdev *led_cdev)
+{
+	struct pse_pi_led_triggers *trigs =
+		container_of(led_cdev->trigger, struct pse_pi_led_triggers,
+			     enabled);
+
+	mutex_lock(&trigs->pcdev->lock);
+	trigs->nr_enabled--;
+	mutex_unlock(&trigs->pcdev->lock);
+}
+
+static int pse_led_trigger_register(struct device *dev,
+				    struct led_trigger *trig, int id,
+				    const char *state,
+				    int (*activate)(struct led_classdev *),
+				    void (*deactivate)(struct led_classdev *))
+{
+	trig->name = devm_kasprintf(dev, GFP_KERNEL, "pse-%s:pi%d:%s",
+				    dev_name(dev), id, state);
+	if (!trig->name)
+		return -ENOMEM;
+	trig->activate = activate;
+	trig->deactivate = deactivate;
+
+	return devm_led_trigger_register(dev, trig);
+}
+
+static int pse_led_pi_triggers_register(struct pse_controller_dev *pcdev,
+					int id)
+{
+	struct pse_pi_led_triggers *trigs;
+	struct device *dev = pcdev->dev;
+	int ret;
+
+	trigs = devm_kzalloc(dev, sizeof(*trigs), GFP_KERNEL);
+	if (!trigs)
+		return -ENOMEM;
+
+	trigs->pcdev = pcdev;
+	trigs->id = id;
+	/* Set it before registering, so "delivering" still works if
+	 * "enabled" fails. Take the lock, the refresh may already run.
+	 */
+	mutex_lock(&pcdev->lock);
+	pcdev->pi[id].led_trigs = trigs;
+	mutex_unlock(&pcdev->lock);
+
+	ret = pse_led_trigger_register(dev, &trigs->delivering, id,
+				       "delivering",
+				       pse_led_delivering_activate,
+				       pse_led_delivering_deactivate);
+	if (ret)
+		return ret;
+
+	return pse_led_trigger_register(dev, &trigs->enabled, id,
+					"enabled",
+					pse_led_enabled_activate,
+					pse_led_enabled_deactivate);
+}
+
+static void pse_led_triggers_register(struct pse_controller_dev *pcdev)
+{
+	int i, ret;
+
+	for (i = 0; i < pcdev->nr_lines; i++) {
+		/* Skip PIs not described in device tree */
+		if (!pcdev->no_of_pse_pi && !pcdev->pi[i].np)
+			continue;
+
+		ret = pse_led_pi_triggers_register(pcdev, i);
+		/* LEDs are optional and must not stop PoE */
+		if (ret)
+			dev_warn(pcdev->dev,
+				 "PI %d: LED triggers failed: %pe\n", i,
+				 ERR_PTR(ret));
+	}
+}
+
+/* Software power control has just started for some PIs. Their "enabled"
+ * LED must now show the admin state that the core keeps.
+ */
+static void pse_led_sync_sw_pw_control(struct pse_controller_dev *pcdev)
+{
+	int i;
+
+	/* Not registered yet, so no LED is bound */
+	if (!pcdev->pi)
+		return;
+
+	for (i = 0; i < pcdev->nr_lines; i++) {
+		mutex_lock(&pcdev->lock);
+		if (pse_pw_d_is_sw_pw_control(pcdev, pcdev->pi[i].pw_d))
+			pse_led_update(pcdev, i);
+		mutex_unlock(&pcdev->lock);
+	}
+}
+#else
+static void pse_led_update(struct pse_controller_dev *pcdev, int id) {}
+static void pse_led_refresh_worker(struct work_struct *work) {}
+static void pse_led_triggers_register(struct pse_controller_dev *pcdev) {}
+static void pse_led_sync_sw_pw_control(struct pse_controller_dev *pcdev) {}
+#endif /* CONFIG_PSE_LED_TRIGGERS */
+
 static int pse_pi_enable(struct regulator_dev *rdev)
 {
 	struct pse_controller_dev *pcdev = rdev_get_drvdata(rdev);
@@ -727,6 +1070,7 @@ static int pse_pi_enable(struct regulator_dev *rdev)
 			pcdev->pi[id].admin_state_enabled = 1;
 			ret = 0;
 		}
+		pse_led_update(pcdev, id);
 		mutex_unlock(&pcdev->lock);
 		return ret;
 	}
@@ -734,6 +1078,7 @@ static int pse_pi_enable(struct regulator_dev *rdev)
 	ret = ops->pi_enable(pcdev, id);
 	if (!ret)
 		pcdev->pi[id].admin_state_enabled = 1;
+	pse_led_update(pcdev, id);
 	mutex_unlock(&pcdev->lock);
 
 	return ret;
@@ -751,6 +1096,7 @@ static int pse_pi_disable(struct regulator_dev *rdev)
 	ret = _pse_pi_disable(pcdev, id);
 	if (!ret)
 		pi->admin_state_enabled = 0;
+	pse_led_update(pcdev, id);
 
 	mutex_unlock(&pcdev->lock);
 	return 0;
@@ -929,6 +1275,17 @@ static void pse_pw_d_release(struct kref *kref)
 	kfree(pw_d);
 }
 
+/* Set pi[id].pw_d under pcdev->lock. The PI regulator ops and the LED
+ * triggers can already run and read it under this lock.
+ */
+static void pse_pi_set_pw_d(struct pse_controller_dev *pcdev, int id,
+			    struct pse_power_domain *pw_d)
+{
+	mutex_lock(&pcdev->lock);
+	pcdev->pi[id].pw_d = pw_d;
+	mutex_unlock(&pcdev->lock);
+}
+
 /* Clear pi[id].pw_d before the domain's reference is dropped. The PI
  * regulator ops and the event handler hold pcdev->lock while they use it.
  */
@@ -1036,7 +1393,7 @@ static int pse_register_pw_ds(struct pse_controller_dev *pcdev)
 			if (regulator_is_equal(pi->rdev->supply,
 					       rdev->supply)) {
 				present = true;
-				pcdev->pi[i].pw_d = pw_d;
+				pse_pi_set_pw_d(pcdev, i, pw_d);
 				break;
 			}
 		}
@@ -1059,7 +1416,7 @@ static int pse_register_pw_ds(struct pse_controller_dev *pcdev)
 		kref_init(&pw_d->refcnt);
 		INIT_LIST_HEAD(&pw_d->pis);
 		list_add_tail(&pcdev->pi[i].pw_d_node, &pw_d->pis);
-		pcdev->pi[i].pw_d = pw_d;
+		pse_pi_set_pw_d(pcdev, i, pw_d);
 	}
 
 out:
@@ -1133,6 +1490,7 @@ int pse_controller_register(struct pse_controller_dev *pcdev)
 		return ret;
 	}
 	INIT_WORK(&pcdev->ntf_work, pse_send_ntf_worker);
+	INIT_DELAYED_WORK(&pcdev->led_work, pse_led_refresh_worker);
 
 	if (!pcdev->ops->pi_get_admin_state ||
 	    !pcdev->ops->pi_get_pw_status) {
@@ -1173,6 +1531,12 @@ int pse_controller_register(struct pse_controller_dev *pcdev)
 			goto free_kfifo;
 	}
 
+	/* Register the LED triggers before the regulators: the regulator
+	 * ops update the LEDs, so devres must remove the triggers after
+	 * the regulators.
+	 */
+	pse_led_triggers_register(pcdev);
+
 	/* Each regulator name len is pcdev dev name + 7 char +
 	 * int max digit number (10) + 1
 	 */
@@ -1204,6 +1568,9 @@ int pse_controller_register(struct pse_controller_dev *pcdev)
 	if (ret)
 		goto free_kfifo;
 
+	/* LEDs bound so far did not know the power domains yet */
+	pse_led_sync_sw_pw_control(pcdev);
+
 	mutex_lock(&pse_list_mutex);
 	list_add(&pcdev->list, &pse_controller_list);
 	mutex_unlock(&pse_list_mutex);
@@ -1216,6 +1583,11 @@ int pse_controller_register(struct pse_controller_dev *pcdev)
 	return 0;
 
 free_kfifo:
+	/* An LED may be bound already and has started the refresh */
+	mutex_lock(&pcdev->lock);
+	pcdev->unregistering = true;
+	mutex_unlock(&pcdev->lock);
+	cancel_delayed_work_sync(&pcdev->led_work);
 	cancel_work_sync(&pcdev->ntf_work);
 	kfifo_free(&pcdev->ntf_fifo);
 	return ret;
@@ -1240,6 +1612,7 @@ void pse_controller_unregister(struct pse_controller_dev *pcdev)
 		disable_irq(pcdev->irq);
 	if (pcdev->poll)
 		cancel_delayed_work_sync(&pcdev->poll->work);
+	cancel_delayed_work_sync(&pcdev->led_work);
 	/* Unlink before the PI array is freed: of_pse_control_get() walks
 	 * the list and reads pcdev->pi[].
 	 */
@@ -1398,6 +1771,9 @@ static void pse_handle_events(struct pse_controller_dev *pcdev,
 				notifs |= ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR;
 		}
 
+		/* After pse_set_config_isr(), which can switch the PI */
+		pse_led_update(pcdev, i);
+
 		dev_dbg(pcdev->dev,
 			"Sending PSE notification EVT 0x%lx\n", notifs);
 
@@ -1535,6 +1911,11 @@ int devm_pse_irq_helper(struct pse_controller_dev *pcdev, int irq,
 		return ret;
 	}
 
+	/* With the "disabled" strategy, the IRQ starts software power
+	 * control
+	 */
+	pse_led_sync_sw_pw_control(pcdev);
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(devm_pse_irq_helper);
@@ -1661,11 +2042,21 @@ pse_control_get_internal(struct pse_controller_dev *pcdev, unsigned int index,
 	 * aims to have the right value reported in the first is_enabled
 	 * call in case of control managed by software.
 	 */
+	mutex_lock(&pcdev->lock);
 	ret = pse_pi_is_hw_enabled(pcdev, index);
+	if (ret >= 0) {
+		pcdev->pi[index].admin_state_enabled = ret;
+		/* The "enabled" LED shows this value only under software
+		 * power control. Otherwise it reads the hardware, which did
+		 * not change here.
+		 */
+		if (pse_pw_d_is_sw_pw_control(pcdev, pcdev->pi[index].pw_d))
+			pse_led_update(pcdev, index);
+	}
+	mutex_unlock(&pcdev->lock);
 	if (ret < 0)
 		goto put_module;
 
-	pcdev->pi[index].admin_state_enabled = ret;
 	psec->ps = regulator_get_exclusive(pcdev->dev,
 					   rdev_get_name(pcdev->pi[index].rdev));
 	if (IS_ERR(psec->ps)) {
diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h
index 008e16b7f72d..b8f30d9eceaf 100644
--- a/include/linux/pse-pd/pse.h
+++ b/include/linux/pse-pd/pse.h
@@ -222,6 +222,7 @@ struct device_node;
 struct of_phandle_args;
 struct pse_control;
 struct pse_poll;
+struct pse_pi_led_triggers;
 struct ethtool_pse_control_status;
 
 /* PSE PI pairset pinout can either be Alternative A or Alternative B */
@@ -259,6 +260,7 @@ struct pse_pi_pairset {
  *		     budget evaluation strategy.
  * @pw_allocated_mW: Power allocated to a PSE PI to manage power budget in
  *		     static budget evaluation strategy.
+ * @led_trigs: LED triggers of the PI, only used by the PSE core
  */
 struct pse_pi {
 	struct pse_pi_pairset pairset[2];
@@ -270,6 +272,7 @@ struct pse_pi {
 	int prio;
 	bool isr_pd_detected;
 	int pw_allocated_mW;
+	struct pse_pi_led_triggers *led_trigs;
 };
 
 /**
@@ -303,10 +306,13 @@ struct pse_ntf {
  * @supp_budget_eval_strategies: budget evaluation strategies supported
  *				 by the PSE
  * @ntf_work: workqueue for PSE notification management
+ * @led_work: reads "delivering" again while an LED uses it, only used by
+ *	      the core
  * @ntf_fifo: PSE notifications FIFO
  * @ntf_fifo_lock: protect @ntf_fifo writer
- * @unregistering: set under @lock when unregistering starts; the PSE
- *		   core switches no PI on after that
+ * @unregistering: set under @lock when unregistering starts or
+ *		   registering fails; the PSE core then switches no PI on
+ *		   and stops the LED refresh
  */
 struct pse_controller_dev {
 	const struct pse_controller_ops *ops;
@@ -325,6 +331,7 @@ struct pse_controller_dev {
 	unsigned int pis_prio_max;
 	u32 supp_budget_eval_strategies;
 	struct work_struct ntf_work;
+	struct delayed_work led_work;
 	DECLARE_KFIFO_PTR(ntf_fifo, struct pse_ntf);
 	spinlock_t ntf_fifo_lock; /* Protect @ntf_fifo writer */
 	bool unregistering;
-- 
2.43.0


      parent reply	other threads:[~2026-12-05 13:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 13:37 [PATCH net-next v7 0/2] net: pse-pd: add poll path and LED trigger support Carlo Szelinsky
2026-12-05 13:37 ` [PATCH net-next v7 1/2] net: pse-pd: add devm_pse_poll_helper() Carlo Szelinsky
2026-12-05 13:37 ` Carlo Szelinsky [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261205133742.905114-3-github@szelinsky.de \
    --to=github@szelinsky.de \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jelonek.jonas@gmail.com \
    --cc=kory.maincent@bootlin.com \
    --cc=kuba@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=pabeni@redhat.com \
    --cc=pavel@kernel.org \
    --cc=ross@r-sc.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox