Thread View: linux.kernel.netdev
5 messages
5 total messages
Started by Navid Ghahremani
Wed, 14 Oct 2026 07:20
[PATCH v2 16/24] net: phy: Add Sanechips ZX5201 PHY support
Author: Navid Ghahremani
Date: Wed, 14 Oct 2026 07:20
Date: Wed, 14 Oct 2026 07:20
203 lines
14392 bytes
14392 bytes
Initialize the external WAN PHY and its SerDes path; generic PHY support
handles negotiation.
Signed-off-by: Navid Ghahremani <ghahramani.navid@gmail.com>
---
drivers/net/phy/Kconfig | 8 ++
drivers/net/phy/Makefile | 1 +
drivers/net/phy/sanechips.c | 152 ++++++++++++++++++++++++++++++++++++
3 files changed, 161 insertions(+)
create mode 100644 drivers/net/phy/sanechips.c
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index b4ef927fd4..63620fdfc4 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -416,6 +416,14 @@ config ROCKCHIP_PHY
help
Currently supports the integrated Ethernet PHY.
+config SANECHIPS_PHY
+ tristate "Sanechips Ethernet PHYs"
+ help
+ Currently supports the Sanechips ZX5201 PHY, which the ZTE ZXHN
+ H3600 uses for its WAN port. The driver sets the PHY up so that
+ its SerDes interface passes traffic; everything else is handled
+ by the generic PHY code.
+
config SMSC_PHY
tristate "SMSC PHYs"
select CRC16
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index 25c4a3c242..666309f7d0 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -97,6 +97,7 @@ obj-$(CONFIG_QSEMI_PHY) += qsemi.o
obj-$(CONFIG_REALTEK_PHY) += realtek/
obj-$(CONFIG_RENESAS_PHY) += uPD60620.o
obj-$(CONFIG_ROCKCHIP_PHY) += rockchip.o
+obj-$(CONFIG_SANECHIPS_PHY) += sanechips.o
obj-$(CONFIG_SMSC_PHY) += smsc.o
obj-$(CONFIG_STE10XP) += ste10Xp.o
obj-$(CONFIG_TERANETICS_PHY) += teranetics.o
diff --git a/drivers/net/phy/sanechips.c b/drivers/net/phy/sanechips.c
new file mode 100644
index 0000000000..92d6388f7d
--- /dev/null
+++ b/drivers/net/phy/sanechips.c
@@ -0,0 +1,152 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Sanechips ZX5201 Ethernet PHY
+ *
+ * The ZX5201 answers on two MDIO addresses: the copper PHY on its own
+ * address and its MAC-side SerDes interface on the next one. The copper PHY
+ * uses the standard registers and the generic PHY code; this driver only adds
+ * the setup that the PHY needs before it passes traffic. The values come from
+ * the vendor firmware of the ZTE ZXHN H3600, and most of them are not
+ * documented.
+ *
+ * Copyright (C) 2026 Navid Ghahremani <ghahramani.navid@gmail.com>
+ */
+
+#include <linux/module.h>
+#include <linux/phy.h>
+
+#define PHY_ID_ZX5201 0x84b95011
+
+/* Copper PHY vendor registers */
+#define ZX5201_REG18 18
+#define ZX5201_EXT_ADDR 16 /* extended register access: address */
+#define ZX5201_EXT_DATA 17 /* extended register access: data */
+#define ZX5201_REG29 29
+
+/*
+ * SerDes interface registers, at the PHY's MDIO address + 1. The names are
+ * a best guess from the way the vendor firmware uses them.
+ */
+#define ZX5201_SDS_WDATA_LO 16
+#define ZX5201_SDS_WDATA_HI 17
+#define ZX5201_SDS_CMD 18
+#define ZX5201_SDS_RDATA_LO 20
+#define ZX5201_SDS_RDATA_HI 21
+#define ZX5201_SDS_REG22 22
+#define ZX5201_SDS_REG27 27
+
+static int zx5201_sds_read(struct phy_device *phydev, u32 regnum)
+{
+ return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr + 1, regnum);
+}
+
+static int zx5201_sds_write(struct phy_device *phydev, u32 regnum, u16 val)
+{
+ return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr + 1, regnum,
+ val);
+}
+
+static int zx5201_ext_write(struct phy_device *phydev, u16 reg, u16 val)
+{
+ int ret;
+
+ ret = phy_write(phydev, ZX5201_EXT_ADDR, reg);
+ if (ret)
+ return ret;
+
+ return phy_write(phydev, ZX5201_EXT_DATA, val);
+}
+
+static int zx5201_config_init(struct phy_device *phydev)
+{
+ static const u16 led_regs[] = { 0xb409, 0xb407, 0xb406, 0xb408 };
+ int ret, lo, hi, i;
+
+ ret = phy_write(phydev, ZX5201_REG18, 0x8402);
+ if (ret)
+ return ret;
+
+ ret = zx5201_sds_write(phydev, ZX5201_SDS_REG22, 0x0a0f);
+ if (ret)
+ return ret;
+
+ ret = zx5201_sds_write(phydev, ZX5201_SDS_REG27, 0x0800);
+ if (ret)
+ return ret;
+
+ ret = phy_write(phydev, ZX5201_REG29, 0x0355);
+ if (ret)
+ return ret;
+
+ ret = zx5201_ext_write(phydev, 0xb62d, 0x0006);
+ if (ret)
+ return ret;
+
+ /*
+ * This looks like an indirect read-modify-write of SerDes register 4:
+ * read it, set bits 9-13 of its high half (bits 25-29 of the register)
+ * to 0b10100, and write it back.
+ */
+ ret = zx5201_sds_write(phydev, ZX5201_SDS_CMD, 0x0004);
+ if (ret)
+ return ret;
+
+ hi = zx5201_sds_read(phydev, ZX5201_SDS_RDATA_HI);
+ if (hi < 0)
+ return hi;
+
+ lo = zx5201_sds_read(phydev, ZX5201_SDS_RDATA_LO);
+ if (lo < 0)
+ return lo;
+
+ ret = zx5201_sds_write(phydev, ZX5201_SDS_WDATA_HI,
+ (hi & 0xc1ff) | 0x2800);
+ if (ret)
+ return ret;
+
+ ret = zx5201_sds_write(phydev, ZX5201_SDS_WDATA_LO, lo);
+ if (ret)
+ return ret;
+
+ ret = zx5201_sds_write(phydev, ZX5201_SDS_CMD, 0x0204);
+ if (ret)
+ return ret;
+
+ ret = zx5201_sds_read(phydev, ZX5201_SDS_REG22);
+ if (ret < 0)
+ return ret;
+
+ ret = zx5201_sds_write(phydev, ZX5201_SDS_REG22, (ret & 0xfff3) | 0x0004);
+ if (ret)
+ return ret;
+
+ /* LED control registers, all cleared as the vendor firmware does */
+ for (i = 0; i < ARRAY_SIZE(led_regs); i++) {
+ ret = zx5201_ext_write(phydev, led_regs[i], 0);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static struct phy_driver sanechips_phy_driver[] = {
+ {
+ PHY_ID_MATCH_EXACT(PHY_ID_ZX5201),
+ .name = "Sanechips ZX5201",
+ .config_init = zx5201_config_init,
+ .suspend = genphy_suspend,
+ .resume = genphy_resume,
+ },
+};
+module_phy_driver(sanechips_phy_driver);
+
+static const struct mdio_device_id __maybe_unused sanechips_phy_tbl[] = {
+ { PHY_ID_MATCH_EXACT(PHY_ID_ZX5201) },
+ { }
+};
+MODULE_DEVICE_TABLE(mdio, sanechips_phy_tbl);
+
+MODULE_AUTHOR("Navid Ghahremani <ghahramani.navid@gmail.com>");
+MODULE_DESCRIPTION("Sanechips Ethernet PHY driver");
+MODULE_LICENSE("GPL");
--
2.55.0
Re: [PATCH v2 16/24] net: phy: Add Sanechips ZX5201 PHY support
Author: Andrew Lunn
Date: Wed, 14 Oct 2026 12:37
Date: Wed, 14 Oct 2026 12:37
46 lines
7454 bytes
7454 bytes
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Sanechips ZX5201 Ethernet PHY
> + *
> + * The ZX5201 answers on two MDIO addresses: the copper PHY on its own
> + * address and its MAC-side SerDes interface on the next one.
What do you get when you read registers 2 and 3 of the SERDES? Is
there an ID in them?
If the mdio bus is scanned, and there is an ID, phylib will try to
probe a PHY driver on the SERDES.
> +static int zx5201_sds_read(struct phy_device *phydev, u32 regnum)
> +{
> + return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr + 1, regnum);
> +}
I would suggest adding a probe, and validate phydev->mdio.addr is not
31. ENODEV, or EINVAL, to indicate the setup is invalid.
> +static int zx5201_config_init(struct phy_device *phydev)
> +{
> + static const u16 led_regs[] = { 0xb409, 0xb407, 0xb406, 0xb408 };
> + /* LED control registers, all cleared as the vendor firmware does */
> + for (i = 0; i < ARRAY_SIZE(led_regs); i++) {
> + ret = zx5201_ext_write(phydev, led_regs[i], 0);
> + if (ret)
> + return ret;
It would be nice to reverse engineer what these bits do. And then add
proper LED controls. However, that can be later.
Ah, now i'm confused:
https://www.sanechips.com.cn/en/ProductEn/WiredEn/ethernetConnectivityEn/index.html
This says it is an RGMII PHY. Why does it have a SERDES? That suggests
SGMII?
We need to understand this, because if it is an RGMII PHY, we need to
address the RGMII delays, which that page says it can controller.
Andrew
Re: [PATCH v2 16/24] net: phy: Add Sanechips ZX5201 PHY support
Author: Navid Ghahremani
Date: Fri, 13 Nov 2026 00:36
Date: Fri, 13 Nov 2026 00:36
47 lines
13126 bytes
13126 bytes
Hi Andrew, Andrew Lunn wrote: > What do you get when you read registers 2 and 3 of the SERDES? Is > there an ID in them? > > If the mdio bus is scanned, and there is an ID, phylib will try to > probe a PHY driver on the SERDES. I read them on the board. Registers 0 to 3 at address 9 all read 0x0000, while addresses with nothing on them like 7, 20 and 30 read 0xffff. Something does answer at address 9 though, since registers 22 and 27 there hold the values the driver writes. So there is no ID, and no PHY driver would match ID 0. But phylib only treats an ID with all of its low 29 bits set as no device, so a bus scan would still register a PHY device at address 9. On this board the MDIO node lists its PHYs, so of_mdiobus_register() does not scan and no device shows up at address 9. > I would suggest adding a probe, and validate phydev->mdio.addr is not > 31. ENODEV, or EINVAL, to indicate the setup is invalid. Done in my tree, the probe returns -EINVAL for address 31. > It would be nice to reverse engineer what these bits do. And then add > proper LED controls. However, that can be later. OK, I will look at the LEDs later. > This says it is an RGMII PHY. Why does it have a SERDES? That suggests > SGMII? > > We need to understand this, because if it is an RGMII PHY, we need to > address the RGMII delays, which that page says it can controller. That part I still have to find out. My driver has always told phylib gmii and the WAN port runs at 1 Gbs, but I have not worked out yet what the link between the SoC and the ZX5201 really is. SerDes was just the name I gave the registers at the second address, and there is no public documentation for them. I will find out what the interface is, and how the delays are set if it is RGMII, before I send the networking patches again. Best regards, Navid
Re: [PATCH v2 16/24] net: phy: Add Sanechips ZX5201 PHY support
Author: Andrew Lunn
Date: Fri, 13 Nov 2026 01:07
Date: Fri, 13 Nov 2026 01:07
27 lines
9541 bytes
9541 bytes
> > We need to understand this, because if it is an RGMII PHY, we need to
> > address the RGMII delays, which that page says it can controller.
>
> That part I still have to find out. My driver has always told phylib
> gmii and the WAN port runs at 1 Gbs, but I have not worked out yet
> what the link between the SoC and the ZX5201 really is.
https://www.sanechips.com.cn/en/Products/WiredEn/fixedNetworkTerminalEn/1558027080778723330.html
This says it is RGMII.
> SerDes was just the name I gave the registers at the second address,
> and there is no public documentation for them. I will find out what
> the interface is, and how the delays are set if it is RGMII, before
> I send the networking patches again.
So picking SERDES is probably causing some of this confusion. SERDES
implies there is a PCS, and the PCS is doing signalling for SGMII or
1000BaseX. With RGMII, none of that exists. The registers might be
controlling clocks, or regulators etc.
https://www.sanechips.com.cn/en/ProductEn/WiredEn/ethernetConnectivityEn/index.html
Also says RGMII.
Andrew
Re: [PATCH v2 16/24] net: phy: Add Sanechips ZX5201 PHY support
Author: Navid Ghahremani
Date: Fri, 13 Nov 2026 09:56
Date: Fri, 13 Nov 2026 09:56
22 lines
12064 bytes
12064 bytes
Hi Andrew, Andrew Lunn wrote: > https://www.sanechips.com.cn/en/Products/WiredEn/fixedNetworkTerminalEn/1558027080778723330.html > > This says it is RGMII. Thanks for the links, that settles it. I will treat the link to the ZX5201 as RGMII. > So picking SERDES is probably causing some of this confusion. SERDES > implies there is a PCS, and the PCS is doing signalling for SGMII or > 1000BaseX. With RGMII, none of that exists. The registers might be > controlling clocks, or regulators etc. Makes sense. I will drop the SerDes name for those registers, work out what they really control and where the RGMII delays are set, before the networking patches go out again. Best regards, Navid
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads