2021-05-19 19:07:41

by Qingfang Deng

[permalink] [raw]
Subject: [PATCH net-next v2 0/4] MT7530 interrupt support

Add support for MT7530 interrupt controller.

DENG Qingfang (4):
net: phy: add MediaTek Gigabit Ethernet 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 | 6 +
drivers/net/dsa/mt7530.c | 264 ++++++++++++++++--
drivers/net/dsa/mt7530.h | 20 +-
drivers/net/phy/Kconfig | 5 +
drivers/net/phy/Makefile | 1 +
drivers/net/phy/mediatek-ge.c | 112 ++++++++
drivers/staging/mt7621-dts/mt7621.dtsi | 4 +
7 files changed, 384 insertions(+), 28 deletions(-)
create mode 100644 drivers/net/phy/mediatek-ge.c

--
2.25.1



2021-05-19 19:07:50

by Qingfang Deng

[permalink] [raw]
Subject: [PATCH net-next v2 3/4] dt-bindings: net: dsa: add MT7530 interrupt controller binding

Add device tree binding to support MT7530 interrupt controller.

Signed-off-by: DENG Qingfang <[email protected]>
Reviewed-by: Andrew Lunn <[email protected]>
Reviewed-by: Florian Fainelli <[email protected]>
Acked-by: Rob Herring <[email protected]>
---
v1 -> v2:
Fixed plural (property -> properties)

Documentation/devicetree/bindings/net/dsa/mt7530.txt | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/dsa/mt7530.txt b/Documentation/devicetree/bindings/net/dsa/mt7530.txt
index de04626a8e9d..18247ebfc487 100644
--- a/Documentation/devicetree/bindings/net/dsa/mt7530.txt
+++ b/Documentation/devicetree/bindings/net/dsa/mt7530.txt
@@ -81,6 +81,12 @@ 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 properties are required.
+
+- #interrupt-cells: Must be 1.
+- 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
--
2.25.1


2021-05-19 19:08:35

by Qingfang Deng

[permalink] [raw]
Subject: [PATCH net-next v2 1/4] net: phy: add MediaTek Gigabit Ethernet PHY driver

Add support for MediaTek Gigabit Ethernet 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.

Signed-off-by: DENG Qingfang <[email protected]>
---
v1 -> v2:
Renamed to mediatek-ge.c

drivers/net/phy/Kconfig | 5 ++
drivers/net/phy/Makefile | 1 +
drivers/net/phy/mediatek-ge.c | 112 ++++++++++++++++++++++++++++++++++
3 files changed, 118 insertions(+)
create mode 100644 drivers/net/phy/mediatek-ge.c

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 25511f39b01f..1534e408505b 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -207,6 +207,11 @@ config MARVELL_88X2222_PHY
Support for the Marvell 88X2222 Dual-port Multi-speed Ethernet
Transceiver.

+config MEDIATEK_GE_PHY
+ tristate "MediaTek Gigabit Ethernet PHYs"
+ help
+ Supports the MediaTek Gigabit Ethernet PHYs.
+
config MICREL_PHY
tristate "Micrel PHYs"
help
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index bcda7ed2455d..24328d7cf931 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -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_GE_PHY) += mediatek-ge.o
obj-$(CONFIG_MESON_GXL_PHY) += meson-gxl.o
obj-$(CONFIG_MICREL_KS8995MA) += spi_ks8995.o
obj-$(CONFIG_MICREL_PHY) += micrel.o
diff --git a/drivers/net/phy/mediatek-ge.c b/drivers/net/phy/mediatek-ge.c
new file mode 100644
index 000000000000..11ff335d6228
--- /dev/null
+++ b/drivers/net/phy/mediatek-ge.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.0+
+#include <linux/bitfield.h>
+#include <linux/module.h>
+#include <linux/phy.h>
+
+#define MTK_EXT_PAGE_ACCESS 0x1f
+#define MTK_PHY_PAGE_STANDARD 0x0000
+#define MTK_PHY_PAGE_EXTENDED 0x0001
+#define MTK_PHY_PAGE_EXTENDED_2 0x0002
+#define MTK_PHY_PAGE_EXTENDED_3 0x0003
+#define MTK_PHY_PAGE_EXTENDED_2A30 0x2a30
+#define MTK_PHY_PAGE_EXTENDED_52B5 0x52b5
+
+static int mtk_gephy_read_page(struct phy_device *phydev)
+{
+ return __phy_read(phydev, MTK_EXT_PAGE_ACCESS);
+}
+
+static int mtk_gephy_write_page(struct phy_device *phydev, int page)
+{
+ return __phy_write(phydev, MTK_EXT_PAGE_ACCESS, page);
+}
+
+static void mtk_gephy_config_init(struct phy_device *phydev)
+{
+ /* Disable EEE */
+ phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0);
+
+ /* Enable HW auto downshift */
+ phy_modify_paged(phydev, MTK_PHY_PAGE_EXTENDED, 0x14, 0, BIT(4));
+
+ /* Increase SlvDPSready time */
+ phy_select_page(phydev, MTK_PHY_PAGE_EXTENDED_52B5);
+ __phy_write(phydev, 0x10, 0xafae);
+ __phy_write(phydev, 0x12, 0x2f);
+ __phy_write(phydev, 0x10, 0x8fae);
+ phy_restore_page(phydev, MTK_PHY_PAGE_STANDARD, 0);
+
+ /* Adjust 100_mse_threshold */
+ phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x123, 0xffff);
+
+ /* Disable mcc */
+ phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xa6, 0x300);
+}
+
+static int mt7530_phy_config_init(struct phy_device *phydev)
+{
+ mtk_gephy_config_init(phydev);
+
+ /* Increase post_update_timer */
+ phy_write_paged(phydev, MTK_PHY_PAGE_EXTENDED_3, 0x11, 0x4b);
+
+ return 0;
+}
+
+static int mt7531_phy_config_init(struct phy_device *phydev)
+{
+ if (phydev->interface != PHY_INTERFACE_MODE_INTERNAL)
+ return -EINVAL;
+
+ mtk_gephy_config_init(phydev);
+
+ /* PHY link down power saving enable */
+ phy_set_bits(phydev, 0x17, BIT(4));
+ phy_clear_bits_mmd(phydev, MDIO_MMD_VEND1, 0xc6, 0x300);
+
+ /* Set TX Pair delay selection */
+ phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x13, 0x404);
+ phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x14, 0x404);
+
+ return 0;
+}
+
+static struct phy_driver mtk_gephy_driver[] = {
+ {
+ PHY_ID_MATCH_EXACT(0x03a29412),
+ .name = "MediaTek MT7530 PHY",
+ .config_init = mt7530_phy_config_init,
+ /* Interrupts are handled by the switch, not the PHY
+ * itself.
+ */
+ .config_intr = genphy_no_config_intr,
+ .handle_interrupt = genphy_handle_interrupt_no_ack,
+ .read_page = mtk_gephy_read_page,
+ .write_page = mtk_gephy_write_page,
+ },
+ {
+ PHY_ID_MATCH_EXACT(0x03a29441),
+ .name = "MediaTek MT7531 PHY",
+ .config_init = mt7531_phy_config_init,
+ /* Interrupts are handled by the switch, not the PHY
+ * itself.
+ */
+ .config_intr = genphy_no_config_intr,
+ .handle_interrupt = genphy_handle_interrupt_no_ack,
+ .read_page = mtk_gephy_read_page,
+ .write_page = mtk_gephy_write_page,
+ },
+};
+
+module_phy_driver(mtk_gephy_driver);
+
+static struct mdio_device_id __maybe_unused mtk_gephy_tbl[] = {
+ { PHY_ID_MATCH_VENDOR(0x03a29400) },
+ { }
+};
+
+MODULE_DESCRIPTION("MediaTek Gigabit Ethernet PHY driver");
+MODULE_AUTHOR("DENG, Qingfang <[email protected]>");
+MODULE_LICENSE("GPL");
+
+MODULE_DEVICE_TABLE(mdio, mtk_gephy_tbl);
--
2.25.1


2021-05-20 01:02:39

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH net-next v2 1/4] net: phy: add MediaTek Gigabit Ethernet PHY driver

> +static void mtk_gephy_config_init(struct phy_device *phydev)
> +{
> + /* Disable EEE */
> + phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0);

Is EEE broken on this PHY? Or is this just to get it into a defined
state?

Otherwise

Reviewed-by: Andrew Lunn <[email protected]>

Andrew

2021-05-20 02:40:08

by Qingfang Deng

[permalink] [raw]
Subject: Re: [PATCH net-next v2 1/4] net: phy: add MediaTek Gigabit Ethernet PHY driver

On Thu, May 20, 2021 at 02:59:21AM +0200, Andrew Lunn wrote:
> > +static void mtk_gephy_config_init(struct phy_device *phydev)
> > +{
> > + /* Disable EEE */
> > + phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0);
>
> Is EEE broken on this PHY? Or is this just to get it into a defined
> state?

As I said in commit message, the initialization (including EEE) is
from the vendor driver.
I have also tested it with EEE enabled by default on one of my APs,
and got occasional link drops.

>
> Otherwise
>
> Reviewed-by: Andrew Lunn <[email protected]>
>
> Andrew

2021-05-20 07:25:23

by Landen Chao (趙皎宏)

[permalink] [raw]
Subject: Re: [PATCH net-next v2 1/4] net: phy: add MediaTek Gigabit Ethernet PHY driver

On Thu, 2021-05-20 at 10:38 +0800, DENG Qingfang wrote:
> On Thu, May 20, 2021 at 02:59:21AM +0200, Andrew Lunn wrote:
> > > +static void mtk_gephy_config_init(struct phy_device *phydev)
> > > +{
> > > + /* Disable EEE */
> > > + phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0);
> >
> > Is EEE broken on this PHY? Or is this just to get it into a defined
> > state?
>
> As I said in commit message, the initialization (including EEE) is
> from the vendor driver.
> I have also tested it with EEE enabled by default on one of my APs,
> and got occasional link drops.
>

EEE of the 10-year-old MT7530 internal gephy has many IOT problems, so
it is recommended to disable its EEE.
EEE of the MT7531 internal gephy has been updated, but it is not yet
widely used.
Therefore, EEE is disabled in vendor driver.

Landen
> > Otherwise
> >
> > Reviewed-by: Andrew Lunn <[email protected]>
> >
> > Andrew

2021-05-21 19:37:40

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net-next v2 0/4] MT7530 interrupt support

Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

On Wed, 19 May 2021 11:31:58 +0800 you wrote:
> Add support for MT7530 interrupt controller.
>
> DENG Qingfang (4):
> net: phy: add MediaTek Gigabit Ethernet PHY driver
> net: dsa: mt7530: add interrupt support
> dt-bindings: net: dsa: add MT7530 interrupt controller binding
> staging: mt7621-dts: enable MT7530 interrupt controller
>
> [...]

Here is the summary with links:
- [net-next,v2,1/4] net: phy: add MediaTek Gigabit Ethernet PHY driver
https://git.kernel.org/netdev/net-next/c/e40d2cca0189
- [net-next,v2,2/4] net: dsa: mt7530: add interrupt support
https://git.kernel.org/netdev/net-next/c/ba751e28d442
- [net-next,v2,3/4] dt-bindings: net: dsa: add MT7530 interrupt controller binding
https://git.kernel.org/netdev/net-next/c/4006f986c091
- [net-next,v2,4/4] staging: mt7621-dts: enable MT7530 interrupt controller
https://git.kernel.org/netdev/net-next/c/f494f0935ffb

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html