net: dsa: motorcomm: Add LED support
David Yang
maintainerv6 cover net: dsa: motorcomm: Add LED 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 lock
David Yang (3):
net: dsa: motorcomm: Move to subdirectory
net: dsa: motorcomm: Split SMI module
net: dsa: motorcomm: Add LED support
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} | 222 +-----
.../net/dsa/{yt921x.h => motorcomm/chip.h} | 14 +-
drivers/net/dsa/motorcomm/leds.c | 630 ++++++++++++++++++
drivers/net/dsa/motorcomm/leds.h | 121 ++++
drivers/net/dsa/motorcomm/smi.c | 157 +++++
drivers/net/dsa/motorcomm/smi.h | 88 +++
11 files changed, 1048 insertions(+), 220 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 v6 1/3 net: dsa: motorcomm: Move to subdirectory
yt921x 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
@@ -18039,7 +18039,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
@@ -72,6 +72,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"
@@ -158,12 +160,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
@@ -14,11 +14,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: ISC +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: ISC +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 v6 2/3 net: dsa: motorcomm: Split SMI module
In reply to David YangSMI operations are going to be used across different modules.
--- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 207 +---------------------------- drivers/net/dsa/motorcomm/smi.c | 157 ++++++++++++++++++++++ drivers/net/dsa/motorcomm/smi.h | 88 ++++++++++++ 4 files changed, 247 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: ISC 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 +157 -0
157 lines not on this page · raw message
drivers/net/dsa/motorcomm/smi.h new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
2.53.0
David Yang
maintainerPATCH v6 3/3 net: dsa: motorcomm: Add LED support
In reply to David YangLEDs can be described in the device tree using the same format as qca8k. Each port can configure up to 3 LEDs.
Currently, only parallel mode and strict 1:1 mapping are supported.
--- drivers/net/dsa/motorcomm/Kconfig | 9 + drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 13 +- drivers/net/dsa/motorcomm/chip.h | 14 +- drivers/net/dsa/motorcomm/leds.c | 630 +++++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/leds.h | 121 ++++++ 6 files changed, 785 insertions(+), 3 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: ISC 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 +11 -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.
@@ -4581,6 +4580,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 ; }
@@ -4681,6 +4686,10 @@ static void yt921x_mdio_remove(struct mdio_device *mdiodev)if (!priv)return ; +#if IS_ENABLED (CONFIG_NET_DSA_YT921X_LEDS ) +yt921x_leds_remove (priv); +#endif +for (size_t i =ARRAY_SIZE (priv->ports); i-- >0 ; ) {struct yt921x_port *pp = &priv->ports[i];
drivers/net/dsa/motorcomm/chip.h +13 -1
@@ -850,8 +850,13 @@ 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 +/* 8 internal + 2 external + 1 mcu */ -#define YT921X_PORT_NUM 11 +#define YT921X_PORT_NUM 11 +#define YT921X_PORT_MCU 10 + +#define YT921X_NAME "yt921x"#define yt921x_port_is_internal (port) ((port) < 8)#define yt921x_port_is_external (port) (8 <= (port) && (port) < 9)
@@ -938,6 +943,13 @@ 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; + +struct yt921x_led *leds[YT921X_LED_GROUP_NUM ]; +#endif };struct yt921x_reg_ops {
drivers/net/dsa/motorcomm/leds.c new file +630 -0
630 lines not on this page · raw message
drivers/net/dsa/motorcomm/leds.h new file +121 -0
121 lines not on this page · raw message
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerdrivers/net/dsa/motorcomm/Kconfig config NET_DSA_YT921X · line 14
Quoted 10 lines · On Thu, 9 Jul 2026 09:47:47 +0800 David Yang wrote:
LEDs can be described in the device tree using the same format as qca8k. Each port can configure up to 3 LEDs.
Currently, only parallel mode and strict 1:1 mapping are supported.
drivers/net/dsa/motorcomm/Kconfig +5
-0+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
is it really useful to prompt the user with this option? Shouldn't this be a hidden option which gets auto-enabled when dependencies are met?
Quoted 5 lines
drivers/net/dsa/motorcomm/leds.c new file +5
-0+static bool +yt921x_led_trigger_is_supported (const struct yt921x_priv *priv,int port, +int group,unsigned long flags) +{ +if (!flags)
drivers/net/dsa/motorcomm/leds.c line 250
Quoted 10 lines
drivers/net/dsa/motorcomm/leds.c new file +10
-0+return true; + +for (unsigned int i =0 ; i <ARRAY_SIZE (yt921x_led_trigger_maps); i++) { +const struct yt921x_led_trigger_map *map = &yt921x_led_trigger_maps[i]; + +if ((flags & map->flags) == map->flags) { + flags &= ~map->flags; +if (!flags) +return true; + }
Isn't this conditions simply:
if (flags == map->flags) return true;
?
Quoted 8 lines
drivers/net/dsa/motorcomm/leds.h new file +6
-0+ } + +return false; +#if IS_ENABLED (CONFIG_NET_DSA_YT921X_LEDS ) + +void yt921x_leds_remove (struct yt921x_priv *priv);
drivers/net/dsa/motorcomm/leds.h line 117
Quoted 10 lines
drivers/net/dsa/motorcomm/leds.h new file +10
-0+int yt921x_leds_setup (struct yt921x_priv *priv); + +#else + +static inline void yt921x_leds_remove (struct yt921x_priv *priv) {} + +static inline int yt921x_leds_setup (struct yt921x_priv *priv) +{ +return 0 ; +}
There are static inlines but I think you still protect the calls to these functions with itdef?
+#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
Quoted 3 lines
drivers/net/dsa/motorcomm/leds.h new file +3
-0+#endif + +#endif
David Yang
maintainerQuoted 13 lines · Jakub Kicinski
drivers/net/dsa/motorcomm/Kconfig config NET_DSA_YT921X · line 14
Quoted 10 lines · On Thu, 9 Jul 2026 09:47:47 +0800 David Yang wrote:
LEDs can be described in the device tree using the same format as qca8k. Each port can configure up to 3 LEDs.
Currently, only parallel mode and strict 1:1 mapping are supported.
drivers/net/dsa/motorcomm/Kconfig +5
-0+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
Quoted 3 lines
is it really useful to prompt the user with this option? Shouldn't this be a hidden option which gets auto-enabled when dependencies are met?
NET_DSA_MV88E6XXX_LEDS, NET_DSA_QCA8K_LEDS_SUPPORT, and NET_DSA_REALTEK_RTL8366RB_LEDS. Better to align with others.
Quoted 18 lines
Quoted 5 lines
drivers/net/dsa/motorcomm/leds.c new file +5
-0+static bool +yt921x_led_trigger_is_supported (const struct yt921x_priv *priv,int port, +int group,unsigned long flags) +{ +if (!flags)drivers/net/dsa/motorcomm/leds.c line 250
Quoted 10 lines
drivers/net/dsa/motorcomm/leds.c new file +10
-0+return true; + +for (unsigned int i =0 ; i <ARRAY_SIZE (yt921x_led_trigger_maps); i++) { +const struct yt921x_led_trigger_map *map = &yt921x_led_trigger_maps[i]; + +if ((flags & map->flags) == map->flags) { + flags &= ~map->flags; +if (!flags) +return true; + }Isn't this conditions simply:
Quoted 4 lines
if (flags == map->flags) return true;?
LED_PORT_ACT are bit-masks, so we can have any additive combinations of trigger_map.flags.
Quoted 22 lines
Quoted 8 lines
drivers/net/dsa/motorcomm/leds.h new file +6
-0+ } + +return false; +#if IS_ENABLED (CONFIG_NET_DSA_YT921X_LEDS ) + +void yt921x_leds_remove (struct yt921x_priv *priv);drivers/net/dsa/motorcomm/leds.h line 117
Quoted 10 lines
drivers/net/dsa/motorcomm/leds.h new file +10
-0+int yt921x_leds_setup (struct yt921x_priv *priv); + +#else + +static inline void yt921x_leds_remove (struct yt921x_priv *priv) {} + +static inline int yt921x_leds_setup (struct yt921x_priv *priv) +{ +return 0 ; +}There are static inlines but I think you still protect the calls to these functions with itdef?
drivers/net/dsa/motorcomm/chip.c static int yt921x_dsa_setup(struct dsa_switch *ds) · line 4587
Quoted 5 lines
drivers/net/dsa/motorcomm/chip.c +5
-0+#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
Sure, but I want to play it safe since conditional availability of functions is kind of error-prone.
Quoted 4 lines
Quoted 3 lines
drivers/net/dsa/motorcomm/leds.h new file +3
-0+#endif + +#endif
Jakub Kicinski
maintainerThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: motorcomm: Add LED support
This patch adds LED support for the Motorcomm YT9215 DSA switch, allowing up to 3 LEDs per port to be described in the device tree using a format similar to qca8k. Only parallel mode and strict 1:1 mapping are supported.
Quoted 14 lines
drivers/net/dsa/motorcomm/Kconfig +6
-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
[ ... ]
drivers/net/dsa/motorcomm/chip.c static int yt921x_dsa_setup(struct dsa_switch *ds) · line 4587
Quoted 13 lines
drivers/net/dsa/motorcomm/chip.c +5
-0@@ -4581,6 +4580,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
[Medium]
When yt921x_leds_setup() fails, the current handling is a dev_warn plus continue. Looking at the error path inside yt921x_leds_setup():
for_each_child_of_node_scoped(leds_np, led_np) {
res = yt921x_led_setup(priv, port,
of_fwnode_handle(led_np),
&inv_mask, &inv_ctrl);
if (res) {
of_node_put(leds_np);
goto err;
}
}
...
err:
yt921x_leds_remove(priv);A single malformed subnode on any port (for example reg >= 3, both active-high and active-low set, or an LED entry attached to the MCU port) makes yt921x_led_setup() return non-zero, and yt921x_leds_setup() then tears down every LED that was previously registered on every port. From the user's perspective this appears as a single dev_warn followed by a switch that has no working LEDs at all, even on correctly-configured ports.
Would it be preferable to log the failing LED and continue registering the rest, so a single DT typo does not disable the whole LED subsystem?
Quoted 6 lines
drivers/net/dsa/motorcomm/chip.c +1
-0+#endif return 0 ; }@@ -4681,6 +4686,10 @@ static void yt921x_mdio_remove(struct mdio_device *mdiodev)
[ ... ]
Quoted 6 lines
drivers/net/dsa/motorcomm/leds.c new file +0
-0@@ -0,0 +1,630 @@
[ ... ]
Quoted 8 lines
drivers/net/dsa/motorcomm/leds.c new file +8
-0+static const struct yt921x_led_trigger_map yt921x_led_trigger_maps[] = { + {BIT (TRIGGER_NETDEV_LINK ), + YT921X_LEDx_PORT_ACT_DUPLEX_HALF | YT921X_LEDx_PORT_ACT_DUPLEX_FULL}, + {BIT (TRIGGER_NETDEV_LINK_10 ), YT921X_LEDx_PORT_ACT_10M}, + {BIT (TRIGGER_NETDEV_LINK_100 ), YT921X_LEDx_PORT_ACT_100M}, + {BIT (TRIGGER_NETDEV_LINK_1000 ), YT921X_LEDx_PORT_ACT_1000M}, + {BIT (TRIGGER_NETDEV_HALF_DUPLEX ), YT921X_LEDx_PORT_ACT_DUPLEX_HALF}, + {BIT (TRIGGER_NETDEV_FULL_DUPLEX ), YT921X_LEDx_PORT_ACT_DUPLEX_FULL},
[ ... ]
Quoted 4 lines
drivers/net/dsa/motorcomm/leds.c new file +4
-0+static int +yt921x_led_trigger_get (struct yt921x_priv *priv,int port,int group, +unsigned long *flagsp) +{
[ ... ]
drivers/net/dsa/motorcomm/leds.c line 290
Quoted 10 lines
drivers/net/dsa/motorcomm/leds.c new file +10
-0+ *flagsp =0 ; +for (unsigned int i =0 ; i <ARRAY_SIZE (yt921x_led_trigger_maps); i++) { +const struct yt921x_led_trigger_map *map = &yt921x_led_trigger_maps[i]; + +if ((val & map->mask) == map->mask) + *flagsp |= map->flags; + } + +return 0 ; +}
[Medium]
Does this iteration over-report the flags for TRIGGER_NETDEV_LINK?
The LINK entry in yt921x_led_trigger_maps sets both DUPLEX_HALF and DUPLEX_FULL bits. After yt921x_led_trigger_set(LINK) programs the register with those two bits, yt921x_led_trigger_get() scans every map entry without breaking:
/* LINK entry: (val & (HALF|FULL)) == (HALF|FULL) -> match */
/* HALF_DUPLEX entry: (val & HALF) == HALF -> match */
/* FULL_DUPLEX entry: (val & FULL) == FULL -> match */So *flagsp ends up as LINK | HALF_DUPLEX | FULL_DUPLEX rather than just LINK. Should the map entries with overlapping masks be handled specially, or should the loop break/clear after a compound match like yt921x_led_ trigger_set() does with flags &= ~map->flags?
[ ... ]
Quoted 2 lines
drivers/net/dsa/motorcomm/leds.c new file +2
-0+int yt921x_leds_setup (struct yt921x_priv *priv) +{
[ ... ]
Quoted 1 line
drivers/net/dsa/motorcomm/leds.c new file +1
-0+dsa_switch_for_each_port (dp, ds) {
[ ... ]
Quoted 23 lines
drivers/net/dsa/motorcomm/leds.c new file +23
-0+for_each_child_of_node_scoped (leds_np, led_np) { + res =yt921x_led_setup (priv, port, +of_fwnode_handle (led_np), + &inv_mask, &inv_ctrl); +if (res) { +of_node_put (leds_np); + goto err; + } + } + +of_node_put (leds_np); + } + +mutex_lock (&priv->reg_lock); + + mask =YT921X_LED_CTRL_MODE_M |YT921X_LED_CTRL_PORT_NUM_M | +YT921X_LED_CTRL_EN ; + ctrl =YT921X_LED_CTRL_MODE_PARALLEL | +YT921X_LED_CTRL_PORT_NUM (YT921X_PORT_NUM -1 ) | +YT921X_LED_CTRL_EN ; + res =yt921x_reg_update_bits (priv,YT921X_LED_CTRL , mask, ctrl); +if (res) + goto end;
drivers/net/dsa/motorcomm/leds.c line 620
Quoted 10 lines
drivers/net/dsa/motorcomm/leds.c new file +10
-0+ +/* Inversion is internal - force on will give low logic. +* In the rest of the file, treat LEDs as if active-low. +*/ +if (inv_mask) + res =yt921x_reg_update_bits (priv,YT921X_LED_PAR_INV , inv_mask, + inv_ctrl); + +end: +mutex_unlock (&priv->reg_lock);
[Medium]
The commit message says "strict 1:1 mapping". Where is the port-to-LED mapping actually being programmed to identity?
The header defines the field macros for these registers:
#define YT921X_LED_PAR_MAPn(port) (0xd01d0 + 4 * (port))
#define YT921X_LED_PAR_MAP_DSTn_PORT_M(grp) ...
#define YT921X_LED_PAR_MAP_DSTn_PORT(grp, x) ...
#define YT921X_LED_PAR_MAP_DSTn_LED_M(grp) ...
#define YT921X_LED_PAR_MAP_DSTn_LED(grp, x) ...but there is no writer for YT921X_LED_PAR_MAPn anywhere in the driver. The 1:1 mapping seems to rely on the reset / bootloader default. If those values are not identity for some reason, LED operations for port X would end up steering to a different pin.
Should the driver write an identity mapping into YT921X_LED_PAR_MAPn, or should the commit message drop the "strict 1:1 mapping" claim?
[Low]
The order in which the LED controller is enabled versus the inversion register is programmed looks reversed:
/* enables LED controller first */
res = yt921x_reg_update_bits(priv, YT921X_LED_CTRL, mask, ctrl);
...
/* programs inversion after */
if (inv_mask)
res = yt921x_reg_update_bits(priv, YT921X_LED_PAR_INV, ...);Per the comment "force on will give low logic", between LED_CTRL_EN being written and YT921X_LED_PAR_INV being programmed, every active-high LED with default-state=on would be driven low (LED off) and only flip to on once the inversion register is written.
If the second write fails, yt921x_leds_remove() is called, which unregisters classdevs but leaves LED_CTRL_EN set with the wrong polarity on the physical pins.
Would it be cleaner to program per-LED state and YT921X_LED_PAR_INV first, and set YT921X_LED_CTRL_EN last?
[High]
Are Documentation/devicetree/bindings updates missing for this change?
The existing binding at Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml uses
unevaluatedProperties: false and only references dsa.yaml#/$defs/ethernet-ports for the port schema, which does not describe a leds subnode. A device tree that uses the new LED feature would fail make dtbs_check with unevaluated property errors.
Should the YAML be extended to describe the leds subnode and the per-LED properties reg, active-high, active-low, and default-state that the driver consumes here?
[Medium]
The driver reads active-high and active-low as boolean properties on each LED subnode:
force_high = fwnode_property_read_bool(fwnode, "active-high");
force_low = fwnode_property_read_bool(fwnode, "active-low");active-low is a well-established convention used elsewhere (for example as a GPIO flag), and the common LED subnode binding in leds/common.yaml does not define active-high/active-low booleans on an LED node. Since DT properties are ABI once shipped, would it be better to reuse an already-standard property, or to invent a driver-namespaced one, so the naming does not collide with existing conventions?
Signature · 1 line
pw-bot: cr
David Yang
maintainerQuoted 24 lines · Jakub Kicinski
Quoted 4 lines
drivers/net/dsa/motorcomm/leds.c new file +4
-0+static int +yt921x_led_trigger_get (struct yt921x_priv *priv,int port,int group, +unsigned long *flagsp) +{[ ... ]
drivers/net/dsa/motorcomm/leds.c line 290
Quoted 10 lines
drivers/net/dsa/motorcomm/leds.c new file +10
-0+ *flagsp =0 ; +for (unsigned int i =0 ; i <ARRAY_SIZE (yt921x_led_trigger_maps); i++) { +const struct yt921x_led_trigger_map *map = &yt921x_led_trigger_maps[i]; + +if ((val & map->mask) == map->mask) + *flagsp |= map->flags; + } + +return 0 ; +}[Medium]
Does this iteration over-report the flags forTRIGGER_NETDEV_LINK?The LINK entry in
yt921x_led_trigger_mapssets bothDUPLEX_HALFandDUPLEX_FULLbits. Afteryt921x_led_trigger_set(LINK)programs the register with those two bits,yt921x_led_trigger_get()scans every map entry without breaking:
Quoted 8 lines
/* LINK entry: (val & (HALF|FULL)) == (HALF|FULL) -> match */ /* HALF_DUPLEX entry: (val & HALF) == HALF -> match */ /* FULL_DUPLEX entry: (val & FULL) == FULL -> match */So *flagsp ends up as LINK |
HALF_DUPLEX|FULL_DUPLEXrather than just LINK. Should the map entries with overlapping masks be handled specially, or should the loop break/clear after a compound match likeyt921x_led_trigger_set()does with flags &= ~map->flags?
It's semantically consistent. The led will be turned on on LINK or HALF_DUPLEX or FULL_DUPLEX.
Quoted 51 lines
Quoted 2 lines
drivers/net/dsa/motorcomm/leds.c new file +2
-0+int yt921x_leds_setup (struct yt921x_priv *priv) +{[ ... ]
Quoted 1 line
+
dsa_switch_for_each_port(dp, ds){[ ... ]
Quoted 23 lines
drivers/net/dsa/motorcomm/leds.c new file +23
-0+for_each_child_of_node_scoped (leds_np, led_np) { + res =yt921x_led_setup (priv, port, +of_fwnode_handle (led_np), + &inv_mask, &inv_ctrl); +if (res) { +of_node_put (leds_np); + goto err; + } + } + +of_node_put (leds_np); + } + +mutex_lock (&priv->reg_lock); + + mask =YT921X_LED_CTRL_MODE_M |YT921X_LED_CTRL_PORT_NUM_M | +YT921X_LED_CTRL_EN ; + ctrl =YT921X_LED_CTRL_MODE_PARALLEL | +YT921X_LED_CTRL_PORT_NUM (YT921X_PORT_NUM -1 ) | +YT921X_LED_CTRL_EN ; + res =yt921x_reg_update_bits (priv,YT921X_LED_CTRL , mask, ctrl); +if (res) + goto end;drivers/net/dsa/motorcomm/leds.c line 620
Quoted 10 lines
drivers/net/dsa/motorcomm/leds.c new file +10
-0+ +/* Inversion is internal - force on will give low logic. +* In the rest of the file, treat LEDs as if active-low. +*/ +if (inv_mask) + res =yt921x_reg_update_bits (priv,YT921X_LED_PAR_INV , inv_mask, + inv_ctrl); + +end: +mutex_unlock (&priv->reg_lock);[Medium]
The commit message says "strict 1:1 mapping". Where is the port-to-LED mapping actually being programmed to identity?The header defines the field macros for these registers:
#define YT921X_LED_PAR_MAPn(port) (0xd01d0 + 4 * (port)) #define YT921X_LED_PAR_MAP_DSTn_PORT_M(grp) ... #define YT921X_LED_PAR_MAP_DSTn_PORT(grp, x) ... #define YT921X_LED_PAR_MAP_DSTn_LED_M(grp) ... #define YT921X_LED_PAR_MAP_DSTn_LED(grp, x) ...
Quoted 7 lines
but there is no writer for
YT921X_LED_PAR_MAPnanywhere in the driver. The 1:1 mapping seems to rely on the reset / bootloader default. If those values are not identity for some reason, LED operations for port X would end up steering to a different pin.Should the driver write an identity mapping into
YT921X_LED_PAR_MAPn, or should the commit message drop the "strict 1:1 mapping" claim?
It's the HW default, and we always perform a hard reset on device init.
Quoted 16 lines
[Low]
The order in which the LED controller is enabled versus the inversion register is programmed looks reversed:/* enables LED controller first */ res = yt921x_reg_update_bits(priv, YT921X_LED_CTRL, mask, ctrl); ... /* programs inversion after */ if (inv_mask) res = yt921x_reg_update_bits(priv, YT921X_LED_PAR_INV, ...);Per the comment "force on will give low logic", between
LED_CTRL_ENbeing written andYT921X_LED_PAR_INVbeing programmed, every active-high LED with default-state=on would be driven low (LED off) and only flip to on once the inversion register is written.
Quoted 6 lines
If the second write fails,
yt921x_leds_remove()is called, which unregisters classdevs but leavesLED_CTRL_ENset with the wrong polarity on the physical pins.Would it be cleaner to program per-LED state and
YT921X_LED_PAR_INVfirst, and setYT921X_LED_CTRL_ENlast?
LED_CTRL_EN is actually kind of no-op, LEDs are always enabled even if !LED_CTRL_EN.
Quoted 10 lines
[High]
AreDocumentation/devicetree/bindingsupdates missing for this change?The existing binding at
Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yamluses
unevaluatedProperties: false and only references dsa.yaml#/$defs/ethernet-ports for the port schema, which does not describe a leds subnode. A device tree that uses the new LED feature would fail makedtbs_checkwith unevaluated property errors.
Quoted 3 lines
Should the YAML be extended to describe the leds subnode and the per-LED properties reg, active-high, active-low, and default-state that the driver consumes here?
https://elixir.bootlin.com/linux/v7.1.4/source/Documentation/devicetree/bindings/net/ethernet-controller.yaml#L206
, and such leds subnode can pass dt_binding_check.
Quoted 7 lines
[Medium]
The driver reads active-high and active-low as boolean properties on each LED subnode:force_high = fwnode_property_read_bool(fwnode, "active-high"); force_low = fwnode_property_read_bool(fwnode, "active-low");
Quoted 6 lines
active-low is a well-established convention used elsewhere (for example as a GPIO flag), and the common LED subnode binding in
leds/common.yamldoes not define active-high/active-low booleans on an LED node. Since DT properties are ABI once shipped, would it be better to reuse an already-standard property, or to invent a driver-namespaced one, so the naming does not collide with existing conventions?