net: dsa: motorcomm: Add LED support
Subsystems (5)
David Yang
maintainerv12 cover net: dsa: motorcomm: Add LED support
LEDs can be described in the device tree using the standard LED node notation. Currently, only parallel mode and strict 1:1 mapping (i.e. the HW default) are supported.
v11: https://lore.kernel.org/r/[email protected]
- handle one of *delay_on / *delay_off is zero
- fix error path for yt921x_led_setup()
v10: https://lore.kernel.org/r/[email protected]
- new patch to fix lock status check
- LED control block redesigned
v9: https://lore.kernel.org/r/[email protected]
- LED initialization sequence adjusted
- add DT description
v8: https://lore.kernel.org/r/[email protected]
- limit the led port number
v7: https://lore.kernel.org/r/[email protected]
- rebase
v6: https://lore.kernel.org/r/[email protected]
- per-port initialization support
v5: https://lore.kernel.org/r/[email protected]
- improve trigger selection
v4: https://lore.kernel.org/r/[email protected]
- fix some reg op typos
v3: https://lore.kernel.org/r/[email protected]
- fix null pointer dereference
- support polarity auto-configuration
v2: https://lore.kernel.org/r/[email protected]
- allocate LED structures only
- eliminate double locking
v1: https://lore.kernel.org/r/[email protected]
- set up polarity correctly
- do not set up .brightness_get() to prevent dead lo
David Yang (5):
net: dsa: yt921x: Check lock status with lockdep_assert_held_once()
net: dsa: motorcomm: Move to subdirectory
net: dsa: motorcomm: Split SMI module
net: dsa: motorcomm: Add LED support
dt-bindings: net: dsa: yt921x: Add LEDs definition example
.../bindings/net/dsa/motorcomm,yt921x.yaml | 23 +
MAINTAINERS | 2 +-
drivers/net/dsa/Kconfig | 10 +-
drivers/net/dsa/Makefile | 2 +-
drivers/net/dsa/motorcomm/Kconfig | 17 +
drivers/net/dsa/motorcomm/Makefile | 5 +
.../net/dsa/{yt921x.c => motorcomm/chip.c} | 228 +-----
.../net/dsa/{yt921x.h => motorcomm/chip.h} | 15 +
drivers/net/dsa/motorcomm/leds.c | 666 ++++++++++++++++++
drivers/net/dsa/motorcomm/leds.h | 118 ++++
drivers/net/dsa/motorcomm/smi.c | 180 +++++
drivers/net/dsa/motorcomm/smi.h | 61 ++
12 files changed, 1108 insertions(+), 219 deletions(-)
create mode 100644 drivers/net/dsa/motorcomm/Kconfig
create mode 100644 drivers/net/dsa/motorcomm/Makefile
rename drivers/net/dsa/{yt921x.c => motorcomm/chip.c} (96%)
rename drivers/net/dsa/{yt921x.h => motorcomm/chip.h} (99%)
create mode 100644 drivers/net/dsa/motorcomm/leds.c
create mode 100644 drivers/net/dsa/motorcomm/leds.h
create mode 100644 drivers/net/dsa/motorcomm/smi.c
create mode 100644 drivers/net/dsa/motorcomm/smi.hSignature · 1 line
2.53.0
David Yang
maintainerPATCH v12 1/5 net: dsa: yt921x: Check lock status with lockdep_assert_held_once()
mutex_is_locked() was used to check the lock status. While it should not be triggered unless a bug is introduced, it does not warn on lock being held by another thread. Fix it with lockdep helpers.
--- drivers/net/dsa/yt921x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/dsa/yt921x.c +2 -2
@@ -198,14 +198,14 @@ static u32 ethaddr_lo2_to_u32(const unsigned char *addr)static int yt921x_reg_read (struct yt921x_priv *priv,u32 reg,u32 *valp) { -WARN_ON (!mutex_is_locked (&priv->reg_lock)); +lockdep_assert_held_once (&priv->reg_lock);return priv->reg_ops->read (priv->reg_ctx, reg, valp); }static int yt921x_reg_write (struct yt921x_priv *priv,u32 reg,u32 val) { -WARN_ON (!mutex_is_locked (&priv->reg_lock)); +lockdep_assert_held_once (&priv->reg_lock);return priv->reg_ops->write (priv->reg_ctx, reg, val); }
Signature · 1 line
2.53.0
David Yang
maintainerPATCH v12 2/5 net: dsa: motorcomm: Move to subdirectory
In reply to David Yangyt921x is already the longest single-file DSA driver, so it's time to split it into parts.
---
MAINTAINERS | 2 +-
drivers/net/dsa/Kconfig | 10 ++--------
drivers/net/dsa/Makefile | 2 +-
drivers/net/dsa/motorcomm/Kconfig | 8 ++++++++
drivers/net/dsa/motorcomm/Makefile | 3 +++
drivers/net/dsa/{yt921x.c => motorcomm/chip.c} | 2 +-
drivers/net/dsa/{yt921x.h => motorcomm/chip.h} | 0
7 files changed, 16 insertions(+), 11 deletions(-)
create mode 100644 drivers/net/dsa/motorcomm/Kconfig
create mode 100644 drivers/net/dsa/motorcomm/Makefile
rename drivers/net/dsa/{yt921x.c => motorcomm/chip.c} (99%)
rename drivers/net/dsa/{yt921x.h => motorcomm/chip.h} (100%)MAINTAINERS +1 -1
@@ -18422,7 +18422,7 @@ M: David Yang <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml -F: drivers/net/dsa/yt921x.* +F: drivers/net/dsa/motorcomm/ F: net/dsa/tag_yt921x.c MOXA SMARTIO/INDUSTIO/INTELLIO SERIAL CARD
drivers/net/dsa/Kconfig +2 -8
@@ -82,6 +82,8 @@ config NET_DSA_MV88E6060 source "drivers/net/dsa/microchip/Kconfig" +source "drivers/net/dsa/motorcomm/Kconfig" + source "drivers/net/dsa/mv88e6xxx/Kconfig" source "drivers/net/dsa/mxl862xx/Kconfig"
@@ -168,12 +170,4 @@ config NET_DSA_VITESSE_VSC73XX_PLATFORM This enables support for the Vitesse VSC7385, VSC7388, VSC7395 and VSC7398 SparX integrated ethernet switches, connected over a CPU-attached address bus and work in memory-mapped I/O mode. - -config NET_DSA_YT921X - tristate "Motorcomm YT9215 ethernet switch chip support" - select NET_DSA_TAG_YT921X - select NET_IEEE8021Q_HELPERS if DCB - help - This enables support for the Motorcomm YT9215 ethernet switch - chip. endmenu
drivers/net/dsa/Makefile +1 -1
@@ -15,11 +15,11 @@ obj-$(CONFIG_NET_DSA_SMSC_LAN9303_MDIO) += lan9303_mdio.o obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX) += vitesse-vsc73xx-core.o obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX_PLATFORM) += vitesse-vsc73xx-platform.o obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX_SPI) += vitesse-vsc73xx-spi.o -obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o obj-y += b53/ obj-y += hirschmann/ obj-y += lantiq/ obj-y += microchip/ +obj-y += motorcomm/ obj-y += mv88e6xxx/ obj-y += mxl862xx/ obj-y += netc/
drivers/net/dsa/motorcomm/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only +config NET_DSA_YT921X + tristate "Motorcomm YT9215 ethernet switch chip support" + select NET_DSA_TAG_YT921X + select NET_IEEE8021Q_HELPERS if DCB + help + This enables support for the Motorcomm YT9215 ethernet switch + chip.
drivers/net/dsa/motorcomm/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o +yt921x-objs := chip.o
drivers/net/dsa/motorcomm/chip.c renamed from drivers/net/dsa/yt921x.c +1 -1
@@ -26,7 +26,7 @@#include <net/ieee8021q.h> #include <net/pkt_cls.h> -#include "yt921x.h" +#include "chip.h" struct yt921x_mib_desc {unsigned int size;
drivers/net/dsa/motorcomm/chip.h renamed from drivers/net/dsa/yt921x.h +0 -0
Signature · 1 line
2.53.0
David Yang
maintainerPATCH v12 3/5 net: dsa: motorcomm: Split SMI module
In reply to David YangSMI operations are going to be used across different modules. Minor changes are applied to fix build errors.
--- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 207 +---------------------------- drivers/net/dsa/motorcomm/smi.c | 180 +++++++++++++++++++++++++ drivers/net/dsa/motorcomm/smi.h | 61 +++++++++ 4 files changed, 243 insertions(+), 206 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/smi.c create mode 100644 drivers/net/dsa/motorcomm/smi.h
drivers/net/dsa/motorcomm/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o yt921x-objs := chip.o +yt921x-objs += smi.o
drivers/net/dsa/motorcomm/chip.c +1 -206
231 lines not on this page · raw message
drivers/net/dsa/motorcomm/smi.c new file +180 -0
180 lines not on this page · raw message
drivers/net/dsa/motorcomm/smi.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
2.53.0
David Yang
maintainerPATCH v12 4/5 net: dsa: motorcomm: Add LED support
In reply to David YangEach port has at most 3 LEDs connected and can be declared using the standard LEDs structure.
Currently, only parallel mode and strict 1:1 mapping (i.e. the HW default) are supported.
--- drivers/net/dsa/motorcomm/Kconfig | 9 + drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 19 +- drivers/net/dsa/motorcomm/chip.h | 15 + drivers/net/dsa/motorcomm/leds.c | 666 +++++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/leds.h | 118 +++++ 6 files changed, 826 insertions(+), 2 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/leds.c create mode 100644 drivers/net/dsa/motorcomm/leds.h
drivers/net/dsa/motorcomm/Kconfig +9 -0
@@ -6,3 +6,12 @@ config NET_DSA_YT921X help This enables support for the Motorcomm YT9215 ethernet switch chip. + +config NET_DSA_YT921X_LEDS + bool "LED support for Motorcomm YT9215" + default y + depends on NET_DSA_YT921X + depends on LEDS_CLASS=y || LEDS_CLASS=NET_DSA_YT921X + help + This enables support for controlling the LEDs attached to the + Motorcomm YT9215 switch chips.
drivers/net/dsa/motorcomm/Makefile +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o yt921x-objs := chip.o +yt921x-$(CONFIG_NET_DSA_YT921X_LEDS) += leds.o yt921x-objs += smi.o
drivers/net/dsa/motorcomm/chip.c +17 -2
@@ -26,6 +26,7 @@#include <net/pkt_cls.h> #include "chip.h" +#include "leds.h" #include "smi.h" struct yt921x_mib_desc {
@@ -151,8 +152,6 @@ static const struct yt921x_info yt921x_infos[] = { {} }; -#define YT921X_NAME "yt921x" -#define YT921X_VID_UNWARE 4095/* The interval should be small enough to avoid overflow of 32bit MIBs.
@@ -4225,6 +4224,15 @@ static int yt921x_edata_read(struct yt921x_priv *priv, u8 addr, u8 *valp)return yt921x_edata_read_cont (priv, addr, valp); } +static void yt921x_dsa_teardown (struct dsa_switch *ds) +{ +struct yt921x_priv *priv =to_yt921x_priv (ds); + +#if IS_ENABLED (CONFIG_NET_DSA_YT921X_LEDS ) +yt921x_leds_remove (priv); +#endif +} +static int yt921x_chip_detect (struct yt921x_priv *priv) {struct device *dev =to_device (priv);
@@ -4581,6 +4589,12 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)if (res)return res; +#if IS_ENABLED (CONFIG_NET_DSA_YT921X_LEDS ) + res =yt921x_leds_setup (priv); +if (res) +dev_warn (dev,"Failed to setup LEDs: %d\n" , res); +#endif +return 0 ; }
@@ -4661,6 +4675,7 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = { .port_add_dscp_prio = yt921x_dsa_port_add_dscp_prio,#endif /* chip */ + .teardown = yt921x_dsa_teardown, .setup = yt921x_dsa_setup, };
drivers/net/dsa/motorcomm/chip.h +15 -0
@@ -850,9 +850,14 @@ enum yt921x_fdb_entry_status {#define YT921X_ACL_NUM (YT921X_ACL_BLK_NUM * YT921X_ACL_ENT_PER_BLK)#define YT921X_UDF_NUM 8 +#define YT921X_LED_GROUP_NUM 3 +#define YT921X_LED_PORT_NUM 10 +/* 8 internal + 2 external + 1 mcu */ #define YT921X_PORT_NUM 11 +#define YT921X_NAME "yt921x" +#define yt921x_port_is_internal (port) ((port) < 8)#define yt921x_port_is_external (port) ((port) == 8 || (port) == 9)
@@ -938,6 +943,16 @@ struct yt921x_port {struct yt921x_mib mib;u64 rx_frames;u64 tx_frames; + +#if IS_ENABLED (CONFIG_NET_DSA_YT921X_LEDS ) +unsigned char led_duty; +unsigned short led_cycle; + +unsigned char led_duty_mask; +unsigned char led_cycle_mask; + +struct yt921x_led *leds[YT921X_LED_GROUP_NUM ]; +#endif };struct yt921x_reg_ops {
drivers/net/dsa/motorcomm/leds.c new file +666 -0
666 lines not on this page · raw message
drivers/net/dsa/motorcomm/leds.h new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.53.0
David Yang
maintainerPATCH v12 5/5 dt-bindings: net: dsa: yt921x: Add LEDs definition example
In reply to David YangAdd LEDs definition example for yt921x to describe how they should be defined for a correct usage.
--- .../bindings/net/dsa/motorcomm,yt921x.yaml | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+)
Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml +23 -0
@@ -21,6 +21,9 @@ description: | Any port can be used as the CPU port. + Each port has at most 3 LEDs connected and can be declared using the standard + LEDs structure. + properties: compatible: const: motorcomm,yt9215
@@ -59,6 +62,7 @@ unevaluatedProperties: false examples: - | #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/leds/common.h> mdio { #address-cells = <1>;
@@ -113,6 +117,25 @@ examples: label = "lan1"; phy-mode = "internal"; phy-handle = <&sw_phy0>; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = <LED_COLOR_ID_WHITE>; + function = LED_FUNCTION_LAN; + default-state = "keep"; + }; + + led@1 { + reg = <1>; + color = <LED_COLOR_ID_AMBER>; + function = LED_FUNCTION_LAN; + default-state = "keep"; + }; + }; }; ethernet-port@1 {
Signature · 1 line
2.53.0
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 33 lines · On Thu, 3 Sep 2026 11:16:21 +0800 you wrote:
LEDs can be described in the device tree using the standard LED node notation. Currently, only parallel mode and strict 1:1 mapping (i.e. the HW default) are supported.
v11: https://lore.kernel.org/r/[email protected]
- handle one of*delay_on/*delay_offis zero
- fix error path foryt921x_led_setup()
v10: https://lore.kernel.org/r/[email protected]
- new patch to fix lock status check
- LED control block redesigned
v9: https://lore.kernel.org/r/[email protected]
- LED initialization sequence adjusted
- add DT description
v8: https://lore.kernel.org/r/[email protected]
- limit the led port number
v7: https://lore.kernel.org/r/[email protected]
- rebase
v6: https://lore.kernel.org/r/[email protected]
- per-port initialization support
v5: https://lore.kernel.org/r/[email protected]
- improve trigger selection
v4: https://lore.kernel.org/r/[email protected]
- fix some reg op typos
v3: https://lore.kernel.org/r/[email protected]
- fix null pointer dereference
- support polarity auto-configuration
v2: https://lore.kernel.org/r/[email protected]
- allocate LED structures only
- eliminate double locking
v1: https://lore.kernel.org/r/[email protected]
- set up polarity correctly
- do not set up .brightness_get() to prevent dead lo
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v12,1/5] net: dsa: yt921x: Check lock status with lockdep_assert_held_once()
https://git.kernel.org/netdev/net-next/c/b1950d0426aa - [net-next,v12,2/5] net: dsa: motorcomm: Move to subdirectory https://git.kernel.org/netdev/net-next/c/9c472a0d7c38 - [net-next,v12,3/5] net: dsa: motorcomm: Split SMI module https://git.kernel.org/netdev/net-next/c/e9423a64d382 - [net-next,v12,4/5] net: dsa: motorcomm: Add LED support (no matching commit) - [net-next,v12,5/5] dt-bindings: net: dsa: yt921x: Add LEDs definition example https://git.kernel.org/netdev/net-next/c/5f28f63c5d19
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Jakub Kicinski
maintainerQuoted 2 lines · On Thu, 03 Sep 2026 03:30:15 +0000 [email protected] wrote:
- [net-next,v12,4/5] net: dsa: motorcomm: Add LED support (no matching commit)
Sigh, I thought you said all the issues on v11 were false positives. I merged v11, please send an incremental fix.
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Missing mutex unlock on error path causes permanent deadlock - [Low] Build failure due to dynamic…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing mutex unlock on error path causes permanent deadlock
- [Low] Build failure due to dynamic array index in container_of_const
--
commit 6e291330945ad21e3fadada5285deeff7e1563e6
Author: David Yang <[email protected]>
Subject: net: dsa: motorcomm: Add LED support
This patch adds LED support for the Motorcomm YT9215 ethernet switch chips. It introduces standard LED class devices for each port, supporting parallel mode and mapping to the hardware default state.
Quoted 11 lines
drivers/net/dsa/motorcomm/leds.c new file +6
-0@@ -0,0 +1,666 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2026 David Yang +*/ + +#include <linux/uleds.h>
drivers/net/dsa/motorcomm/leds.c line 16
Quoted 10 lines
drivers/net/dsa/motorcomm/leds.c new file +10
-0+ +#include "chip.h" +#include "leds.h" +#include "smi.h" + +#define to_yt921x_led (led_cdev) \ + container_of_const((led_cdev), struct yt921x_led, cdev) +#define to_yt921x_port (led) ((led)->port) +#define to_yt921x_priv (pp) \ + container_of_const((pp), struct yt921x_priv, ports[(pp)->index])
[Severity: Low]
Does this macro definition cause a build failure? container_of_const uses offsetof(), which requires array indices to be integer constant expressions. Since (pp)->index is evaluated at runtime, this might result in a "non-constant integer expression in offsetof" compiler error when compiling with CONFIG_NET_DSA_YT921X_LEDS enabled.
[ ... ]
Quoted 4 lines
drivers/net/dsa/motorcomm/leds.c new file +4
-0+static int +yt921x_led_setup (struct yt921x_priv *priv,int port, +struct fwnode_handle *fwnode) +{
[ ... ]
Quoted 23 lines
drivers/net/dsa/motorcomm/leds.c new file +23
-0+ state =led_init_default_state_get (fwnode); + +mutex_lock (&priv->reg_lock); + +/* Inversion is internal - force on will give low logic. +* In the rest of the file, treat LEDs as if active-low. +*/ + polarity_orig =0 ; +if (polarity) { + res =yt921x_reg_read (priv,YT921X_LED_PAR_INV , &val); +if (res) + goto err_inv; + + mask =YT921X_LED_PAR_INV_INVnm (group, port); + ctrl = polarity >0 ? val | mask : val & ~mask; +if (ctrl != val) { + res =yt921x_reg_write (priv,YT921X_LED_PAR_INV , ctrl); +if (res) + goto err_inv; + + polarity_orig = -polarity; + } + }
[ ... ]
Quoted 5 lines
drivers/net/dsa/motorcomm/leds.c new file +5
-0+err_led2: +if (polarity_orig) { + ret =yt921x_reg_toggle_bits (priv,YT921X_LED_PAR_INV , +YT921X_LED_PAR_INV_INVnm (group, port), + polarity_orig >0 );
drivers/net/dsa/motorcomm/leds.c line 578
Quoted 10 lines
drivers/net/dsa/motorcomm/leds.c new file +10
-0+if (ret) +dev_err (dev, +"Failed to restore %s for LED %02d:%02u: %d\n" , +"LED_PAR_INV" , port, group, ret); + } +mutex_unlock (&priv->reg_lock); + +err_inv: + pp->leds[group] =NULL ; +devm_kfree (dev, led);
[Severity: High]
Can jumping to err_inv cause a permanent deadlock? The lock priv->reg_lock is acquired earlier in yt921x_led_setup(). If the read or write to YT921X_LED_PAR_INV fails, the code jumps to the err_inv label, which is located after the mutex_unlock(&priv->reg_lock) call. This bypasses the unlock entirely and leaves the lock permanently acquired, potentially hanging the device's control path on subsequent operations.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4