Skip to contentSkip to conversation

MT7530 interrupt support

RFC Superseded DENG Qingfang 3 participants 9 messages Apr 8, 2021 – Apr 9, 2021

Subsystems (8)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover MT7530 interrupt support

Add support for MT7530 interrupt controller.

DENG Qingfang (4):
net: phy: add MediaTek PHY driver
net: dsa: mt7530: add interrupt support
dt-bindings: net: dsa: add MT7530 interrupt controller binding
staging: mt7621-dts: enable MT7530 interrupt controller

 .../devicetree/bindings/net/dsa/mt7530.txt    |   5 +
 drivers/net/dsa/Kconfig                       |   1 +
 drivers/net/dsa/mt7530.c                      | 266 ++++++++++++++++--
 drivers/net/dsa/mt7530.h                      |  20 +-
 drivers/net/phy/Kconfig                       |   5 +
 drivers/net/phy/Makefile                      |   1 +
 drivers/net/phy/mediatek.c                    | 112 ++++++++
 drivers/staging/mt7621-dts/mt7621.dtsi        |   3 +
 8 files changed, 384 insertions(+), 29 deletions(-)
 create mode 100644 drivers/net/phy/mediatek.c
Signature · 1 line
2.25.1
#1 lore raw

RFC v3 1/4 net: phy: add MediaTek PHY driver

Add support for MediaTek PHYs found in MT7530 and MT7531 switches. The initialization procedure is from the vendor driver, but due to lack of documentation, the function of some register values remains unknown.

---
RFC v2 -> RFC v3:
- No changes.

 drivers/net/phy/Kconfig    |   5 ++
 drivers/net/phy/Makefile   |   1 +
 drivers/net/phy/mediatek.c | 112 +++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+)
 create mode 100644 drivers/net/phy/mediatek.c
drivers/net/phy/Kconfig +5 -0
index a615b3660b05..edd858cec9ec 100644
@@ -207,6 +207,11 @@ config MARVELL_88X2222_PHY
 	  Support for the Marvell 88X2222 Dual-port Multi-speed Ethernet
 	  Transceiver.
 
+config MEDIATEK_PHY
+	tristate "MediaTek PHYs"
+	help
+	  Supports the MediaTek switch integrated PHYs.
+
 config MICREL_PHY
 	tristate "Micrel PHYs"
 	help
drivers/net/phy/Makefile +1 -0
index de683e3abe63..9ed7dbab7770 100644
@@ -64,6 +64,7 @@ obj-$(CONFIG_LXT_PHY)		+= lxt.o
 obj-$(CONFIG_MARVELL_10G_PHY)	+= marvell10g.o
 obj-$(CONFIG_MARVELL_PHY)	+= marvell.o
 obj-$(CONFIG_MARVELL_88X2222_PHY)	+= marvell-88x2222.o
+obj-$(CONFIG_MEDIATEK_PHY)	+= mediatek.o
 obj-$(CONFIG_MESON_GXL_PHY)	+= meson-gxl.o
 obj-$(CONFIG_MICREL_KS8995MA)	+= spi_ks8995.o
 obj-$(CONFIG_MICREL_PHY)	+= micrel.o
drivers/net/phy/mediatek.c new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

RFC v3 2/4 net: dsa: mt7530: add interrupt support

In reply to DENG Qingfang

Add support for MT7530 interrupt controller to handle internal PHYs. In order to assign an IRQ number to each PHY, the registration of MDIO bus is also done in this driver.

---
RFC v2 -> RFC v3:
- Rework IRQ request and free procedure.
- Add irq_set_nested_thread.
- Move mt753x_phy_{read,write} functions.

 drivers/net/dsa/Kconfig  |   1 +
 drivers/net/dsa/mt7530.c | 266 +++++++++++++++++++++++++++++++++++----
 drivers/net/dsa/mt7530.h |  20 ++-
 3 files changed, 258 insertions(+), 29 deletions(-)
drivers/net/dsa/Kconfig +1 -0
index a5f1aa911fe2..264384449f09 100644
@@ -36,6 +36,7 @@ config NET_DSA_LANTIQ_GSWIP
 config NET_DSA_MT7530
 	tristate "MediaTek MT753x and MT7621 Ethernet switch support"
 	select NET_DSA_TAG_MTK
+	select MEDIATEK_PHY
 	help
 	  This enables support for the MediaTek MT7530, MT7531, and MT7621
 	  Ethernet switch chips.
drivers/net/dsa/mt7530.c +239 -27

332 lines not on this page · raw message

drivers/net/dsa/mt7530.h +18 -2
index ec36ea5dfd57..62fcaabefba1 100644
@@ -7,6 +7,7 @@
 #define __MT7530_H
 
 #define MT7530_NUM_PORTS		7
+#define MT7530_NUM_PHYS			5
 #define MT7530_CPU_PORT			6
 #define MT7530_NUM_FDB_RECORDS		2048
 #define MT7530_ALL_MEMBERS		0xff
@@ -381,6 +382,12 @@ enum mt7531_sgmii_force_duplex {
 #define  SYS_CTRL_SW_RST		BIT(1)
 #define  SYS_CTRL_REG_RST		BIT(0)
 
+/* Register for system interrupt */
+#define MT7530_SYS_INT_EN		0x7008
+
+/* Register for system interrupt status */
+#define MT7530_SYS_INT_STS		0x700c
+
 /* Register for PHY Indirect Access Control */
 #define MT7531_PHY_IAC			0x701C
 #define  MT7531_PHY_ACS_ST		BIT(31)
@@ -702,6 +709,8 @@ static const char *p5_intf_modes(unsigned int p5_interface)
 	}
 }
 
+struct mt7530_priv;
+
 /* struct mt753x_info -	This is the main data structure for holding the specific
  *			part for each supported device
  * @sw_setup:		Holding the handler to a device initialization
@@ -726,8 +735,8 @@ struct mt753x_info {
 	enum mt753x_id id;
 
 	int (*sw_setup)(struct dsa_switch *ds);
-	int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
-	int (*phy_write)(struct dsa_switch *ds, int port, int regnum, u16 val);
+	int (*phy_read)(struct mt7530_priv *priv, int port, int regnum);
+	int (*phy_write)(struct mt7530_priv *priv, int port, int regnum, u16 val);
 	int (*pad_setup)(struct dsa_switch *ds, phy_interface_t interface);
 	int (*cpu_port_config)(struct dsa_switch *ds, int port);
 	bool (*phy_mode_supported)(struct dsa_switch *ds, int port,
@@ -761,6 +770,10 @@ struct mt753x_info {
  *			registers
  * @p6_interface	Holding the current port 6 interface
  * @p5_intf_sel:	Holding the current port 5 interface select
+ *
+ * @irq:		IRQ number of the switch
+ * @irq_domain:		IRQ domain of the switch irq_chip
+ * @irq_enable:		IRQ enable bits, synced to SYS_INT_EN
  */
 struct mt7530_priv {
 	struct device		*dev;
@@ -782,6 +795,9 @@ struct mt7530_priv {
 	struct mt7530_port	ports[MT7530_NUM_PORTS];
 	/* protect among processes for registers access*/
 	struct mutex reg_mutex;
+	int irq;
+	struct irq_domain *irq_domain;
+	u32 irq_enable;
 };
 
 struct mt7530_hw_vlan_entry {
Signature · 1 line
2.25.1
#3 lore raw

RFC v3 3/4 dt-bindings: net: dsa: add MT7530 interrupt controller binding

In reply to DENG Qingfang

Add device tree binding to support MT7530 interrupt controller.

---
RFC v2 -> RFC v3:
- No changes.

 Documentation/devicetree/bindings/net/dsa/mt7530.txt | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/net/dsa/mt7530.txt +5 -0
index de04626a8e9d..26b34888eb62 100644
@@ -81,6 +81,11 @@ Optional properties:
 - gpio-controller: Boolean; if defined, MT7530's LED controller will run on
 	GPIO mode.
 - #gpio-cells: Must be 2 if gpio-controller is defined.
+- interrupt-controller: Boolean; Enables the internal interrupt controller.
+
+If interrupt-controller is defined, the following property is required.
+
+- interrupts: Parent interrupt for the interrupt controller.
 
 See Documentation/devicetree/bindings/net/dsa/dsa.txt for a list of additional
 required, optional properties and how the integrated switch subnodes must
Signature · 1 line
2.25.1
#4 lore raw

RFC v3 4/4 staging: mt7621-dts: enable MT7530 interrupt controller

In reply to DENG Qingfang

Enable MT7530 interrupt controller in the MT7621 SoC.

---
RFC v2 -> RFC v3:
- No changes.

 drivers/staging/mt7621-dts/mt7621.dtsi | 3 +++
 1 file changed, 3 insertions(+)
drivers/staging/mt7621-dts/mt7621.dtsi +3 -0
index 16fc94f65486..ebf8b0633e88 100644
@@ -447,6 +447,9 @@ switch0: switch0@0 {
 				mediatek,mcm;
 				resets = <&rstctrl 2>;
 				reset-names = "mcm";
+				interrupt-controller;
+				interrupt-parent = <&gic>;
+				interrupts = <GIC_SHARED 23 IRQ_TYPE_LEVEL_HIGH>;
 
 				ports {
 					#address-cells = <1>;
Signature · 1 line
2.25.1
Tested-by on the v3 series
#5 lore raw
In reply to DENG Qingfang

Quoting DENG Qingfang <[email protected]>:

Quoted 19 lines

Add support for MT7530 interrupt controller.

DENG Qingfang (4):
net: phy: add MediaTek PHY driver
net: dsa: mt7530: add interrupt support
dt-bindings: net: dsa: add MT7530 interrupt controller binding
staging: mt7621-dts: enable MT7530 interrupt controller

 .../devicetree/bindings/net/dsa/mt7530.txt    |   5 +
 drivers/net/dsa/Kconfig                       |   1 +
 drivers/net/dsa/mt7530.c                      | 266 ++++++++++++++++--
 drivers/net/dsa/mt7530.h                      |  20 +-
 drivers/net/phy/Kconfig                       |   5 +
 drivers/net/phy/Makefile                      |   1 +
 drivers/net/phy/mediatek.c                    | 112 ++++++++
 drivers/staging/mt7621-dts/mt7621.dtsi        |   3 +
 8 files changed, 384 insertions(+), 29 deletions(-)
 create mode 100644 drivers/net/phy/mediatek.c
Quoted 2 lines

--
2.25.1

I already tested v2 which works fine.
v3 works too.

Tested on Ubiquiti ER-X-SFP (MT7621) with 1 external phy which uses irq=POLL.

See dmesg log:

[   12.045645] mt7530 mdio-bus:1f eth0 (uninitialized): PHY [mt7530-0:00] driver [MediaTek MT7530 PHY] (irq=24)
[   12.425643] mt7530 mdio-bus:1f eth1 (uninitialized): PHY [mt7530-0:01] driver [MediaTek MT7530 PHY] (irq=25)
[   12.745642] mt7530 mdio-bus:1f eth2 (uninitialized): PHY [mt7530-0:02] driver [MediaTek MT7530 PHY] (irq=26)
[   13.065656] mt7530 mdio-bus:1f eth3 (uninitialized): PHY [mt7530-0:03] driver [MediaTek MT7530 PHY] (irq=27)
[   13.445657] mt7530 mdio-bus:1f eth4 (uninitialized): PHY [mt7530-0:04] driver [MediaTek MT7530 PHY] (irq=28)
[   13.785656] mt7530 mdio-bus:1f eth5 (uninitialized): PHY [mdio-bus:07] driver [Qualcomm Atheros AR8031/AR8033] (irq=POLL)

Greats,

René

#6 lore raw

Hi René,

Quoted 3 lines · René van Dorst

Tested on Ubiquiti ER-X-SFP (MT7621) with 1 external phy which uses irq=POLL.

I wonder if the external PHY's IRQ can be registered in the devicetree. Change MT7530_NUM_PHYS to 6, and add the following to ER-X-SFP dts PHY node:

interrupt-parent = <&switch0>;
interrupts = <5>;

maintainer
#7 lore raw
Quoted 9 lines · DENG Qingfang

Hi René,

Quoted 3 lines · René van Dorst

Tested on Ubiquiti ER-X-SFP (MT7621) with 1 external phy which uses irq=POLL.

I wonder if the external PHY's IRQ can be registered in the devicetree. Change MT7530_NUM_PHYS to 6, and add the following to ER-X-SFP dts PHY node:

I don't know this platform. What is the PHYs interrupt pin connected to? A SoC GPIO? There is a generic mechanism to describe PHY interrupts in DT. That should be used, if it is a GPIO.

Andrew

#8 lore raw

Quoting Andrew Lunn <[email protected]>:

Quoted 9 lines · DENG Qingfang
Quoted 8 lines

Hi René,

Quoted 2 lines · René van Dorst

Tested on Ubiquiti ER-X-SFP (MT7621) with 1 external phy which

uses irq=POLL.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

I wonder if the external PHY's IRQ can be registered in the devicetree. Change MT7530_NUM_PHYS to 6, and add the following to ER-X-SFP dts PHY node:

I don't know this platform. What is the PHYs interrupt pin connected to? A SoC GPIO? There is a generic mechanism to describe PHY interrupts in DT. That should be used, if it is a GPIO.

Andrew

Quoting Andrew Lunn <[email protected]>:

Quoted 9 lines · DENG Qingfang
Quoted 8 lines

Hi René,

Quoted 2 lines · René van Dorst

Tested on Ubiquiti ER-X-SFP (MT7621) with 1 external phy which

uses irq=POLL.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

I wonder if the external PHY's IRQ can be registered in the devicetree. Change MT7530_NUM_PHYS to 6, and add the following to ER-X-SFP dts PHY node:

I don't know this platform. What is the PHYs interrupt pin connected to? A SoC GPIO? There is a generic mechanism to describe PHY interrupts in DT. That should be used, if it is a GPIO.

Andrew

Hi Andrew,

I couldn't find if the external phy IRQ is connected to any gpio of the SOC. So External PHY IRQ can't be sensed via a gpio.

The patch used the MT7530 link change interrupt and flags.
Maybe the patch is misusing the these flags as an interrupt?
The same MT7530 register also has the interrupt flags for the internal phys. But in the MT7531 datasheet they don't describe them.

On the other hand I don't have any information about the internal PHY or register settings. So enabling the interrupt on the PHY is currently not possible.

I also forced enabled all the MT7530 PHY interrupts and PHY link change interrupts. I print the interrupt status mt7530.
I don't see any MT7530 interrupt fired when link changing the port 5/external phy. Which was of course as expected. We only have 5 internal phy's for the port 0 to 4. Port 5 and 6 is only have a MAC that is connected to the SOC of an external PHY.

Greats,

René