riscv: dts: sophgo: Add mdio multiplexer for cv18xx
Subsystems (6)
Inochi Amaoto
maintainercover riscv: dts: sophgo: Add mdio multiplexer for cv18xx
Add mdio multiplexer support for CV18XX series SoC.
Inochi Amaoto (2):
dt-bindings: net: Add Sophgo CV1800 MDIO multiplexer
net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs
.../bindings/net/sophgo,cv1800b-mdio-mux.yaml | 47 +++++++ drivers/net/mdio/Kconfig | 10 ++ drivers/net/mdio/Makefile | 1 + drivers/net/mdio/mdio-mux-cv1800b.c | 119 ++++++++++++++++++ 4 files changed, 177 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/sophgo,cv1800b-mdio-mux.yaml create mode 100644 drivers/net/mdio/mdio-mux-cv1800b.c
--
2.49.0
Inochi Amaoto
maintainerPATCH 1/2 dt-bindings: net: Add Sophgo CV1800 MDIO multiplexer
The Sophgo CV1800 uses an internal MDIO bus multiplexer to handle the internal phy and external phy. The internal phy is always on MDIO bus address 0, and the external bus can be configured with different MDIO address.
Add documentation and compatible string for the MDIO multiplexer on CV1800 Series SoC.
--- .../bindings/net/sophgo,cv1800b-mdio-mux.yaml | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/sophgo,cv1800b-mdio-mux.yaml
Documentation/devicetree/bindings/net/sophgo,cv1800b-mdio-mux.yaml new file +47 -0
@@ -0,0 +1,47 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/sophgo,cv1800b-mdio-mux.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sophgo CV1800B MDIO bus multiplexer + +maintainers: + - Inochi Amaoto <[email protected]> + +description: + This MDIO bus multiplexer defines buses that could be internal as well as + external to SoCs. The external mdio bus can be configured at different + bus address. + +allOf: + - $ref: mdio-mux.yaml# + +properties: + compatible: + const: sophgo,cv1800b-mdio-mux + + reg: + maxItems: 1 + +required: + - compatible + - reg + +unevaluatedProperties: false + +examples: + - | + mdio@3009000 { + compatible = "sophgo,cv1800b-mdio-mux"; + reg = <0x3009000 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + mdio-parent-bus = <&gmac0_mdio>; + + mdio@0 { + #address-cells = <1>; + #size-cells = <0>; + reg = <0>; + }; + };
Signature · 1 line
2.49.0
Inochi Amaoto
maintainerPATCH 2/2 net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs
In reply to Inochi AmaotoAdd device driver for the mux driver for Sophgo CV18XX/SG200X series SoCs.
--- drivers/net/mdio/Kconfig | 10 +++ drivers/net/mdio/Makefile | 1 + drivers/net/mdio/mdio-mux-cv1800b.c | 119 ++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 drivers/net/mdio/mdio-mux-cv1800b.c
drivers/net/mdio/Kconfig +10 -0
@@ -278,5 +278,15 @@ config MDIO_BUS_MUX_MMIOREG Currently, only 8/16/32 bits registers are supported. +config MDIO_BUS_MUX_SOPHGO_CV1800B + tristate "Sophgo CV1800 MDIO multiplexer driver" + depends on ARCH_SOPHGO || COMPILE_TEST + depends on OF_MDIO && HAS_IOMEM + select MDIO_BUS_MUX + default m if ARCH_SOPHGO + help + This module provides a driver for the MDIO multiplexer/glue of + the Sophgo CV1800 series SoC. The multiplexer connects either + the external or the internal MDIO bus to the parent bus. endif
drivers/net/mdio/Makefile +1 -0
@@ -33,3 +33,4 @@ obj-$(CONFIG_MDIO_BUS_MUX_MESON_G12A) += mdio-mux-meson-g12a.o obj-$(CONFIG_MDIO_BUS_MUX_MESON_GXL) += mdio-mux-meson-gxl.o obj-$(CONFIG_MDIO_BUS_MUX_MMIOREG) += mdio-mux-mmioreg.o obj-$(CONFIG_MDIO_BUS_MUX_MULTIPLEXER) += mdio-mux-multiplexer.o +obj-$(CONFIG_MDIO_BUS_MUX_SOPHGO_CV1800B) += mdio-mux-cv1800b.o
drivers/net/mdio/mdio-mux-cv1800b.c new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
2.49.0
Andrew Lunn
maintainerRe: [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs
Quoted 21 lines · Inochi Amaoto
Add device driver for the mux driver for Sophgo CV18XX/SG200X series SoCs.
drivers/net/mdio/mdio-mux-cv1800b.c new file +17
-0@@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Sophgo CV1800 MDIO multiplexer driver +* +* Copyright (C) 2025 Inochi Amaoto <[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/delay.h> +#include <linux/clk.h> +#include <linux/io.h> +#include <linux/mdio-mux.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define EPHY_PAGE_SELECT 0x07c
drivers/net/mdio/mdio-mux-cv1800b.c line 27
Quoted 10 lines
drivers/net/mdio/mdio-mux-cv1800b.c new file +10
-0+#define EPHY_CTRL 0x800 +#define EPHY_REG_SELECT 0x804 + +#define EPHY_PAGE_SELECT_SRC GENMASK(12, 8) + +#define EPHY_CTRL_ANALOG_SHUTDOWN BIT(0) +#define EPHY_CTRL_USE_EXTPHY BIT(7) +#define EPHY_CTRL_PHYMODE BIT(8) +#define EPHY_CTRL_PHYMODE_SMI_RMII 1 +#define EPHY_CTRL_EXTPHY_ID GENMASK(15, 11)
There are a lot of defines here which are not used, but as far as i see, there is one 8bit register, where bit 7 controls the mux.
It looks like you can throw this driver away and just use mdio-mux-mmioreg.c. This is from the binding documentation with a few tweaks:
mdio-mux@3009000 {
compatible = "mdio-mux-mmioreg", "mdio-mux";
mdio-parent-bus = <&xmdio0>;
#address-cells = <1>;
#size-cells = <0>;
reg = <0x3009000 1>;
mux-mask = <128>; mdio@0 {
reg = <0>;
#address-cells = <1>;
#size-cells = <0>;
phy_xgmii_slot1: ethernet-phy@4 {
compatible = "ethernet-phy-ieee802.3-c45";
reg = <4>;
};
};
mdio@128 {
reg = <128>;
#address-cells = <1>;
#size-cells = <0>;
ethernet-phy@4 {
compatible = "ethernet-phy-ieee802.3-c45";
reg = <4>;
};
};
};
AndrewInochi Amaoto
maintainerRe: [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs
Quoted 27 lines · Andrew Lunn
Quoted 26 lines · Inochi Amaoto
Add device driver for the mux driver for Sophgo CV18XX/SG200X series SoCs.
drivers/net/mdio/mdio-mux-cv1800b.c new file +22
-0@@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Sophgo CV1800 MDIO multiplexer driver +* +* Copyright (C) 2025 Inochi Amaoto <[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/delay.h> +#include <linux/clk.h> +#include <linux/io.h> +#include <linux/mdio-mux.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define EPHY_PAGE_SELECT 0x07c +#define EPHY_CTRL 0x800 +#define EPHY_REG_SELECT 0x804 + +#define EPHY_PAGE_SELECT_SRC GENMASK(12, 8) +
Quoted 9 lines
drivers/net/mdio/mdio-mux-cv1800b.c line 27
Quoted 5 lines
drivers/net/mdio/mdio-mux-cv1800b.c new file +5
-0+#define EPHY_CTRL_ANALOG_SHUTDOWN BIT(0) +#define EPHY_CTRL_USE_EXTPHY BIT(7) +#define EPHY_CTRL_PHYMODE BIT(8) +#define EPHY_CTRL_PHYMODE_SMI_RMII 1 +#define EPHY_CTRL_EXTPHY_ID GENMASK(15, 11)There are a lot of defines here which are not used, but as far as i see, there is one 8bit register, where bit 7 controls the mux.
You are true. Only bit 7 control the mux.
Quoted 26 lines
It looks like you can throw this driver away and just use
mdio-mux-mmioreg.c. This is from the binding documentation with a few tweaks:mdio-mux@3009000 { compatible = "mdio-mux-mmioreg", "mdio-mux"; mdio-parent-bus = <&xmdio0>; #address-cells = <1>; #size-cells = <0>; reg = <0x3009000 1>; mux-mask = <128>;mdio@0 { reg = <0>; #address-cells = <1>; #size-cells = <0>; phy_xgmii_slot1: ethernet-phy@4 { compatible = "ethernet-phy-ieee802.3-c45"; reg = <4>; }; }; mdio@128 { reg = <128>; #address-cells = <1>;
Quoted 9 lines
#size-cells = <0>;
ethernet-phy@4 {
compatible = "ethernet-phy-ieee802.3-c45";
reg = <4>;
};
};
};It is good for me to use this. I will have a try. Thanks.
Regards,
Inochi
Re: [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs
In reply to Inochi AmaotoHi Inochi!
Quoted 92 lines · Inochi Amaoto
Add device driver for the mux driver for Sophgo CV18XX/SG200X series SoCs.
Signed-off-by Inochi Amaoto <[email protected]>---
drivers/net/mdio/Kconfig | 10 +++ drivers/net/mdio/Makefile | 1 +drivers/net/mdio/mdio-mux-cv1800b.c| 119 ++++++++++++++++++++++++++++3 files changed, 130 insertions(+)create mode 100644
drivers/net/mdio/mdio-mux-cv1800b.cdrivers/net/mdio/Kconfig +0
-0@@ -278,5 +278,15 @@ config MDIO_BUS_MUX_MMIOREG
Currently, only 8/16/32 bits registers are supported.drivers/net/mdio/Kconfig +10
-0+config MDIO_BUS_MUX_SOPHGO_CV1800B + tristate "Sophgo CV1800 MDIO multiplexer driver" + depends on ARCH_SOPHGO || COMPILE_TEST + depends on OF_MDIO && HAS_IOMEM + select MDIO_BUS_MUX + default m if ARCH_SOPHGO + help + This module provides a driver for the MDIO multiplexer/glue of + the Sophgo CV1800 series SoC. The multiplexer connects either + the external or the internal MDIO bus to the parent bus.
endifdrivers/net/mdio/Makefile +0
-0@@ -33,3 +33,4 @@ obj-$(CONFIG_MDIO_BUS_MUX_MESON_G12A) += mdio-mux-meson-g12a.oobj-$(CONFIG_MDIO_BUS_MUX_MESON_GXL) += mdio-mux-meson-gxl.o
obj-$(CONFIG_MDIO_BUS_MUX_MMIOREG) += mdio-mux-mmioreg.o
obj-$(CONFIG_MDIO_BUS_MUX_MULTIPLEXER) += mdio-mux-multiplexer.odrivers/net/mdio/Makefile +1
-0+obj-$(CONFIG_MDIO_BUS_MUX_SOPHGO_CV1800B) += mdio-mux-cv1800b.odrivers/net/mdio/mdio-mux-cv1800b.c new file +46
-0@@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Sophgo CV1800 MDIO multiplexer driver +* +* Copyright (C) 2025 Inochi Amaoto <[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/delay.h> +#include <linux/clk.h> +#include <linux/io.h> +#include <linux/mdio-mux.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define EPHY_PAGE_SELECT 0x07c +#define EPHY_CTRL 0x800 +#define EPHY_REG_SELECT 0x804 + +#define EPHY_PAGE_SELECT_SRC GENMASK(12, 8) + +#define EPHY_CTRL_ANALOG_SHUTDOWN BIT(0) +#define EPHY_CTRL_USE_EXTPHY BIT(7) +#define EPHY_CTRL_PHYMODE BIT(8) +#define EPHY_CTRL_PHYMODE_SMI_RMII 1 +#define EPHY_CTRL_EXTPHY_ID GENMASK(15, 11) + +#define EPHY_REG_SELECT_MDIO 0 +#define EPHY_REG_SELECT_APB 1 + +#define CV1800B_MDIO_INTERNAL_ID 1 +#define CV1800B_MDIO_EXTERNAL_ID 0 + +struct cv1800b_mdio_mux { +void __iomem *regs; +void *mux_handle; +}; + +static int cv1800b_enable_mdio (struct cv1800b_mdio_mux *mdmux,bool internal_phy) +{ +u32 val; + + val =readl (mdmux->regs +EPHY_CTRL ); + +if (internal_phy)
drivers/net/mdio/mdio-mux-cv1800b.c line 56
Quoted 10 lines
drivers/net/mdio/mdio-mux-cv1800b.c new file +10
-0+ val &= ~EPHY_CTRL_USE_EXTPHY ; + else + val |= EPHY_CTRL_USE_EXTPHY; + +writel (val, mdmux->regs +EPHY_CTRL ); + +writel (EPHY_REG_SELECT_MDIO , mdmux->regs +EPHY_REG_SELECT ); + +return 0 ; +}
Seems that it actually doesn't multiplex the buses? As seen on SG2000:
# mdio mdio_mux-0.0 DEV PHY-ID LINK 0x00 0x00435649 up 0x01 0x00435649 up 0x02 0x00000000 down ... # mdio mdio_mux-0.1 DEV PHY-ID LINK 0x00 0x00435649 up 0x01 0x00435649 up ...
The single internal PHY appears on two addresses (0 and 1) and on both buses. Maybe it just switches the external MDIO master on/off?
Seems that we need the documentation for this thing ;-)
BTW, above LINK up is unfortunately without any cable attached...
Signature · 1 line
Alexander Sverdlin.
Inochi Amaoto
maintainerRe: [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs
Quoted 99 lines · Alexander Sverdlin
Hi Inochi!
Quoted 96 lines · Inochi Amaoto
Add device driver for the mux driver for Sophgo CV18XX/SG200X series SoCs.
Signed-off-by Inochi Amaoto <[email protected]>---
drivers/net/mdio/Kconfig | 10 +++ drivers/net/mdio/Makefile | 1 +drivers/net/mdio/mdio-mux-cv1800b.c| 119 ++++++++++++++++++++++++++++3 files changed, 130 insertions(+)create mode 100644
drivers/net/mdio/mdio-mux-cv1800b.cdrivers/net/mdio/Kconfig +0
-0@@ -278,5 +278,15 @@ config MDIO_BUS_MUX_MMIOREG
Currently, only 8/16/32 bits registers are supported.drivers/net/mdio/Kconfig +10
-0+config MDIO_BUS_MUX_SOPHGO_CV1800B + tristate "Sophgo CV1800 MDIO multiplexer driver" + depends on ARCH_SOPHGO || COMPILE_TEST + depends on OF_MDIO && HAS_IOMEM + select MDIO_BUS_MUX + default m if ARCH_SOPHGO + help + This module provides a driver for the MDIO multiplexer/glue of + the Sophgo CV1800 series SoC. The multiplexer connects either + the external or the internal MDIO bus to the parent bus.
endifdrivers/net/mdio/Makefile +0
-0@@ -33,3 +33,4 @@ obj-$(CONFIG_MDIO_BUS_MUX_MESON_G12A) += mdio-mux-meson-g12a.oobj-$(CONFIG_MDIO_BUS_MUX_MESON_GXL) += mdio-mux-meson-gxl.o
obj-$(CONFIG_MDIO_BUS_MUX_MMIOREG) += mdio-mux-mmioreg.o
obj-$(CONFIG_MDIO_BUS_MUX_MULTIPLEXER) += mdio-mux-multiplexer.odrivers/net/mdio/Makefile +1
-0+obj-$(CONFIG_MDIO_BUS_MUX_SOPHGO_CV1800B) += mdio-mux-cv1800b.odrivers/net/mdio/mdio-mux-cv1800b.c new file +50
-0@@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Sophgo CV1800 MDIO multiplexer driver +* +* Copyright (C) 2025 Inochi Amaoto <[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/delay.h> +#include <linux/clk.h> +#include <linux/io.h> +#include <linux/mdio-mux.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define EPHY_PAGE_SELECT 0x07c +#define EPHY_CTRL 0x800 +#define EPHY_REG_SELECT 0x804 + +#define EPHY_PAGE_SELECT_SRC GENMASK(12, 8) + +#define EPHY_CTRL_ANALOG_SHUTDOWN BIT(0) +#define EPHY_CTRL_USE_EXTPHY BIT(7) +#define EPHY_CTRL_PHYMODE BIT(8) +#define EPHY_CTRL_PHYMODE_SMI_RMII 1 +#define EPHY_CTRL_EXTPHY_ID GENMASK(15, 11) + +#define EPHY_REG_SELECT_MDIO 0 +#define EPHY_REG_SELECT_APB 1 + +#define CV1800B_MDIO_INTERNAL_ID 1 +#define CV1800B_MDIO_EXTERNAL_ID 0 + +struct cv1800b_mdio_mux { +void __iomem *regs; +void *mux_handle; +}; + +static int cv1800b_enable_mdio (struct cv1800b_mdio_mux *mdmux,bool internal_phy) +{ +u32 val; + + val =readl (mdmux->regs +EPHY_CTRL ); + +if (internal_phy) + val &= ~EPHY_CTRL_USE_EXTPHY ; +else + val |=EPHY_CTRL_USE_EXTPHY ; +
Quoted 9 lines
drivers/net/mdio/mdio-mux-cv1800b.c line 56
Quoted 6 lines
drivers/net/mdio/mdio-mux-cv1800b.c new file +6
-0+writel (val, mdmux->regs +EPHY_CTRL ); + +writel (EPHY_REG_SELECT_MDIO , mdmux->regs +EPHY_REG_SELECT ); + +return 0 ; +}Seems that it actually doesn't multiplex the buses? As seen on SG2000:
A switch is also a multiplexer.
Quoted 12 lines
# mdio mdio_mux-0.0 DEV PHY-ID LINK 0x00 0x00435649 up 0x01 0x00435649 up 0x02 0x00000000 down ... # mdio mdio_mux-0.1 DEV PHY-ID LINK 0x00 0x00435649 up 0x01 0x00435649 up ...
Quoted 1 line
The single internal PHY appears on two addresses (0 and 1) and on both buses.
Only address 1 is right, all phy will respond address 0. And you should not probe bus 1 when using internal bus, it is not existed.
Quoted 1 line
Maybe it just switches the external MDIO master on/off?
Yes
Quoted 2 lines
Seems that we need the documentation for this thing ;-)
Please ask for the vendor.
Quoted 1 line
BTW, above LINK up is unfortunately without any cable attached...
I have repeat the led problem. After setting the right pinctrl, It is always light and not blink. I guess there may be a internal bug for it. I will ignore this problem as it is not the driver issue.
Regards,
Inochi