Skip to contentSkip to conversation

net: dsa: motorcomm: Add LED support

PATCH Superseded David Yang 2 participants 7 messages Jul 26 – Jul 31

Subsystems (4)

v9 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

David Yang

author maintainer
#0 lore raw

v9 cover net: dsa: motorcomm: Add LED support

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 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}    |  12 +
 drivers/net/dsa/motorcomm/leds.c              | 660 ++++++++++++++++++
 drivers/net/dsa/motorcomm/leds.h              | 121 ++++
 drivers/net/dsa/motorcomm/smi.c               | 157 +++++
 drivers/net/dsa/motorcomm/smi.h               |  88 +++
 11 files changed, 1077 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.h
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH v9 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
index 60cff00953dc..f512467753bc 100644
@@ -18249,7 +18249,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
index 4ab567c5bbaf..98e9bbe47de7 100644
@@ -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
index d2975badffc0..138225baa4d5 100644
@@ -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
new file mode 100644
index 000000000000..1fddd386f866
@@ -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
new file mode 100644
index 000000000000..afd03be9fa35
@@ -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
similarity index 99%
rename from drivers/net/dsa/yt921x.c
rename to drivers/net/dsa/motorcomm/chip.c
index 159b16606f6c..f070732845eb 100644
@@ -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
similarity index 100%
rename from drivers/net/dsa/yt921x.h
rename to drivers/net/dsa/motorcomm/chip.h
Signature · 1 line
2.53.0
author maintainer
#2 lore raw

PATCH v9 2/3 net: dsa: motorcomm: Split SMI module

In reply to David Yang

SMI 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
index afd03be9fa35..6cea5313a444 100644
@@ -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
author maintainer
#3 lore raw

PATCH v9 3/3 net: dsa: motorcomm: Add LED support

In reply to David Yang

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  |   9 +
 drivers/net/dsa/motorcomm/Makefile |   1 +
 drivers/net/dsa/motorcomm/chip.c   |  13 +-
 drivers/net/dsa/motorcomm/chip.h   |  12 +
 drivers/net/dsa/motorcomm/leds.c   | 660 +++++++++++++++++++++++++++++
 drivers/net/dsa/motorcomm/leds.h   | 121 ++++++
 6 files changed, 814 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
index 1fddd386f866..3438e0b14361 100644
@@ -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
index 6cea5313a444..5a63db0029ff 100644
@@ -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
index 6dee25b6754a..553efacd4f5e 100644
@@ -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 +12 -0
index 5f3b99e189c4..e6815cf9cb3c 100644
@@ -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,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 +660 -0

660 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
maintainer
#4 lore raw
Quoted 12 lines · David Yang
drivers/net/dsa/motorcomm/leds.c new file +12 -0
+int yt921x_leds_setup(struct yt921x_priv *priv)
+{
+	struct device *dev = to_device(priv);
+	struct dsa_switch *ds = &priv->ds;
+	struct dsa_port *dp;
+	u32 inv_ctrl = 0;
+	u32 inv_mask = 0;
+	u32 ctrl;
+	u32 mask;
+	int res;
+
+	dsa_switch_for_each_port(dp, ds) {

drivers/net/dsa/motorcomm/leds.c line 630

Quoted 10 lines
drivers/net/dsa/motorcomm/leds.c new file +10 -0
+		int port = dp->index;
+
+		if (!dp->dn)
+			continue;
+
+		res = yt921x_leds_setup_port(priv, port, &inv_mask, &inv_ctrl);
+		if (res)
+			dev_warn(dev, "Failed to setup LEDs for port %d: %d\n",
+				 port, res);
+	}

Sashiko noted that at this point the leds are already exposed to the user-space and settings can be applied before the following take place.

Also please note net-next commit c82ff94592fb

/P

author maintainer
#5 lore raw
Quoted 20 lines · Paolo Abeni
Quoted 18 lines · David Yang
drivers/net/dsa/motorcomm/leds.c new file +18 -0
+int yt921x_leds_setup(struct yt921x_priv *priv)
+{
+     struct device *dev = to_device(priv);
+     struct dsa_switch *ds = &priv->ds;
+     struct dsa_port *dp;
+     u32 inv_ctrl = 0;
+     u32 inv_mask = 0;
+     u32 ctrl;
+     u32 mask;
+     int res;
+
+     dsa_switch_for_each_port(dp, ds) {
+             int port = dp->index;
+
+             if (!dp->dn)
+                     continue;
+
+             res = yt921x_leds_setup_port(priv, port, &inv_mask, &inv_ctrl);
Quoted 8 lines

drivers/net/dsa/motorcomm/leds.c line 630

Quoted 4 lines
drivers/net/dsa/motorcomm/leds.c new file +4 -0
+             if (res)
+                     dev_warn(dev, "Failed to setup LEDs for port %d: %d\n",
+                              port, res);
+     }

Sashiko noted that at this point the leds are already exposed to the user-space and settings can be applied before the following take place.

The register values are correctly latched in the hardware so the leds will behave as expected eventually. Also, the chip will always enable LEDs despite LED_CTRL_EN, see comments in v6.

maintainer
#6 lore raw
In reply to David Yang
Quoted 11 lines · David Yang

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]

Quoted 8 lines

- 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

Please note that the cover-letter must contains some reasonable description of the series, beyond the changelog itself.

/P