mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Louvel <paul.louvel@bootlin.com>
To: Andrew Lunn <andrew@lunn.ch>, Vladimir Oltean <olteanv@gmail.com>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,  Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>, Frank Li <Frank.Li@nxp.com>,
	 Jerry Ray <jerry.ray@microchip.com>
Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org,
	 linux-kernel@vger.kernel.org, Bo Mellberg <bo.mellberg@se.com>,
	 Pascal Eberhard <pascal.eberhard@se.com>,
	 Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	 Miquel Raynal <miquel.raynal@bootlin.com>,
	 Paul Louvel <paul.louvel@bootlin.com>
Subject: [PATCH net-next 3/3] net: dsa: lan9303: add LED mode configuration
Date: Thu, 26 Nov 2026 15:13:45 +0100	[thread overview]
Message-ID: <20261126-lan9303-leds-v1-3-a96731317859@bootlin.com> (raw)
In-Reply-To: <20261126-lan9303-leds-v1-0-a96731317859@bootlin.com>

The LED function of the LAN9303 and LAN9354 is selected by a single
LED_FUN field that applies to all six LED pins of the two external
ports.

On some boards the LED straps double as configuration straps for other
functions, such as the PHY address or the EEPROM size, so the desired
LED mode cannot be strapped and has to be programmed by the driver.

The LED subsystem is not used here: it models each LED independently,
while this hardware has one function field for all LEDs.

Read the optional "smsc,led-mode", and configure the device accordingly.

Signed-off-by: Paul Louvel (Schneider Electric) <paul.louvel@bootlin.com>
---
 drivers/net/dsa/lan9303-core.c | 74 ++++++++++++++++++++++++++++++++++++++++--
 include/linux/dsa/lan9303.h    |  8 +++++
 2 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c
index 8eeb8953ff24..6a9ade873e42 100644
--- a/drivers/net/dsa/lan9303-core.c
+++ b/drivers/net/dsa/lan9303-core.c
@@ -10,6 +10,7 @@
 #include <linux/mutex.h>
 #include <linux/mii.h>
 #include <linux/of.h>
+#include <linux/property.h>
 #include <linux/phy.h>
 #include <linux/if_bridge.h>
 #include <linux/if_vlan.h>
@@ -63,6 +64,13 @@
 #define LAN9303_SWITCH_CSR_CMD_BUSY BIT(31)
 #define LAN9303_SWITCH_CSR_CMD_RW BIT(30)
 #define LAN9303_SWITCH_CSR_CMD_LANES (BIT(19) | BIT(18) | BIT(17) | BIT(16))
+#define LAN9303_LED_CFG 0x6f
+# define LAN9303_LED_CFG_LED_FUN_MAX_VAL 0x7
+# define LAN9303_LED_CFG_LED_FUN_SHIFT 8
+# define LAN9303_LED_CFG_LED_FUN_MASK GENMASK(9, 8)
+# define LAN9303_LED_CFG_LED_MODES GENMASK(3, 0)
+# define LAN9354_LED_CFG_LED_FUN_MASK GENMASK(10, 8)
+# define LAN9354_LED_CFG_LED_MODES (GENMASK(5, 0) | BIT(7))
 #define LAN9303_VIRT_PHY_BASE 0x70
 #define LAN9303_VIRT_SPECIAL_CTRL 0x77
 #define  LAN9303_VIRT_SPECIAL_TURBO BIT(10) /*Turbo MII Enable*/
@@ -240,6 +248,16 @@ static unsigned int flow_ctl_reg[] = {
 	LAN9303_MANUAL_FC_2
 };
 
+static const struct lan9303_led_info lan9303_led_info = {
+	.fun_mask = LAN9303_LED_CFG_LED_FUN_MASK,
+	.avail_modes = LAN9303_LED_CFG_LED_MODES,
+};
+
+static const struct lan9303_led_info lan9354_led_info = {
+	.fun_mask = LAN9354_LED_CFG_LED_FUN_MASK,
+	.avail_modes = LAN9354_LED_CFG_LED_MODES,
+};
+
 static int lan9303_read(struct regmap *regmap, unsigned int offset, u32 *reg)
 {
 	int ret, i;
@@ -778,6 +796,20 @@ static int lan9303_enable_processing_port(struct lan9303 *chip,
 				LAN9303_MAC_TX_CFG_X_TX_ENABLE);
 }
 
+static int lan9303_setup_leds(struct lan9303 *chip)
+{
+	unsigned int val;
+
+	if (chip->led_sel_mode >= 0) {
+		val = chip->led_sel_mode << LAN9303_LED_CFG_LED_FUN_SHIFT;
+
+		return regmap_update_bits(chip->regmap, LAN9303_LED_CFG, chip->led_info->fun_mask,
+					  val);
+	}
+
+	return 0;
+}
+
 /* forward special tagged packets from port 0 to port 1 *or* port 2 */
 static int lan9303_setup_tagging(struct lan9303 *chip)
 {
@@ -902,8 +934,14 @@ static int lan9303_check_device(struct lan9303 *chip)
 		return ret;
 	}
 
-	if (((reg >> 16) != LAN9303_CHIP_ID) &&
-	    ((reg >> 16) != LAN9354_CHIP_ID)) {
+	switch (reg >> 16) {
+	case LAN9303_CHIP_ID:
+		chip->led_info = &lan9303_led_info;
+		break;
+	case LAN9354_CHIP_ID:
+		chip->led_info = &lan9354_led_info;
+		break;
+	default:
 		dev_err(chip->dev, "unexpected device found: LAN%4.4X\n",
 			reg >> 16);
 		return -ENODEV;
@@ -932,6 +970,30 @@ static int lan9303_check_device(struct lan9303 *chip)
 	return 0;
 }
 
+static int lan9303_parse_dt(struct lan9303 *chip)
+{
+	u32 led_mode;
+	int ret;
+
+	if (!device_property_present(chip->dev, "smsc,led-mode")) {
+		chip->led_sel_mode = -1;
+	} else {
+		ret = device_property_read_u32(chip->dev, "smsc,led-mode", &led_mode);
+		if (ret)
+			return ret;
+
+		if (led_mode > LAN9303_LED_CFG_LED_FUN_MAX_VAL ||
+		    !(chip->led_info->avail_modes & BIT(led_mode))) {
+			dev_err(chip->dev, "invalid led mode %u\n", led_mode);
+			return -EINVAL;
+		}
+
+		chip->led_sel_mode = led_mode;
+	}
+
+	return 0;
+}
+
 /* ---------------------------- DSA -----------------------------------*/
 
 static enum dsa_tag_protocol lan9303_get_tag_protocol(struct dsa_switch *ds,
@@ -964,6 +1026,10 @@ static int lan9303_setup(struct dsa_switch *ds)
 		regmap_write(chip->regmap, LAN9303_VIRT_SPECIAL_CTRL, reg);
 	}
 
+	ret = lan9303_setup_leds(chip);
+	if (ret)
+		dev_err(chip->dev, "failed to setup leds %d\n", ret);
+
 	ret = lan9303_setup_tagging(chip);
 	if (ret)
 		dev_err(chip->dev, "failed to setup port tagging %d\n", ret);
@@ -1477,6 +1543,10 @@ int lan9303_probe(struct lan9303 *chip, struct device_node *np)
 	if (ret)
 		return ret;
 
+	ret = lan9303_parse_dt(chip);
+	if (ret)
+		return ret;
+
 	ret = lan9303_register_switch(chip);
 	if (ret) {
 		dev_dbg(chip->dev, "Failed to register switch: %d\n", ret);
diff --git a/include/linux/dsa/lan9303.h b/include/linux/dsa/lan9303.h
index 3ce7cbcc37a3..f0111ad7fb7f 100644
--- a/include/linux/dsa/lan9303.h
+++ b/include/linux/dsa/lan9303.h
@@ -17,6 +17,11 @@ struct lan9303_alr_cache_entry {
 	u8  stp_override;     /* non zero if set LAN9303_ALR_DAT1_AGE_OVERRID */
 };
 
+struct lan9303_led_info {
+	u32 fun_mask;
+	u32 avail_modes;
+};
+
 struct lan9303 {
 	struct device *dev;
 	struct regmap *regmap;
@@ -30,6 +35,9 @@ struct lan9303 {
 	const struct lan9303_phy_ops *ops;
 	bool is_bridged; /* true if port 1 and 2 are bridged */
 
+	const struct lan9303_led_info *led_info;
+	int led_sel_mode;
+
 	/* remember LAN9303_SWE_PORT_STATE while not bridged */
 	u32 swe_port_state;
 	/* LAN9303 do not offer reading specific ALR entry. Cache all

-- 
2.56.1


  parent reply	other threads:[~2026-11-26 14:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 14:13 [PATCH net-next 0/3] " Paul Louvel
2026-11-26 14:13 ` [PATCH net-next 1/3] dt-bindings: net: dsa: lan9303: add Microchip LAN9354 compatible Paul Louvel
2026-11-26 14:13 ` [PATCH net-next 2/3] dt-bindings: net: dsa: lan9303: add smsc,led-mode property Paul Louvel
2026-11-26 14:13 ` Paul Louvel [this message]
2026-11-26 15:04   ` [PATCH net-next 3/3] net: dsa: lan9303: add LED mode configuration Andrew Lunn
2026-11-26 14:52 ` [PATCH net-next 0/3] " Andrew Lunn

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=20261126-lan9303-leds-v1-3-a96731317859@bootlin.com \
    --to=paul.louvel@bootlin.com \
    --cc=Frank.Li@nxp.com \
    --cc=andrew@lunn.ch \
    --cc=bo.mellberg@se.com \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=jerry.ray@microchip.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=pascal.eberhard@se.com \
    --cc=robh@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    /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

all inboxes | Powered by JetHome®