Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] riscv: dts: sophgo: Add mdio multiplexer for cv18xx
@ 2025-06-11  8:01 Inochi Amaoto
  2025-06-11  8:01 ` [PATCH net-next 1/2] dt-bindings: net: Add Sophgo CV1800 MDIO multiplexer Inochi Amaoto
  2025-06-11  8:02 ` [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs Inochi Amaoto
  0 siblings, 2 replies; 7+ messages in thread
From: Inochi Amaoto @ 2025-06-11  8:01 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Inochi Amaoto, Heiner Kallweit, Russell King,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
  Cc: netdev, devicetree, sophgo, linux-kernel, linux-riscv, Yixun Lan,
	Longbin Li

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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next 1/2] dt-bindings: net: Add Sophgo CV1800 MDIO multiplexer
  2025-06-11  8:01 [PATCH net-next 0/2] riscv: dts: sophgo: Add mdio multiplexer for cv18xx Inochi Amaoto
@ 2025-06-11  8:01 ` Inochi Amaoto
  2025-06-11  8:02 ` [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs Inochi Amaoto
  1 sibling, 0 replies; 7+ messages in thread
From: Inochi Amaoto @ 2025-06-11  8:01 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Inochi Amaoto, Heiner Kallweit, Russell King,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
  Cc: netdev, devicetree, sophgo, linux-kernel, linux-riscv, Yixun Lan,
	Longbin Li

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.

Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
 .../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

diff --git a/Documentation/devicetree/bindings/net/sophgo,cv1800b-mdio-mux.yaml b/Documentation/devicetree/bindings/net/sophgo,cv1800b-mdio-mux.yaml
new file mode 100644
index 000000000000..abe0004c8b6e
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/sophgo,cv1800b-mdio-mux.yaml
@@ -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 <inochiama@gmail.com>
+
+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>;
+      };
+    };
-- 
2.49.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs
  2025-06-11  8:01 [PATCH net-next 0/2] riscv: dts: sophgo: Add mdio multiplexer for cv18xx Inochi Amaoto
  2025-06-11  8:01 ` [PATCH net-next 1/2] dt-bindings: net: Add Sophgo CV1800 MDIO multiplexer Inochi Amaoto
@ 2025-06-11  8:02 ` Inochi Amaoto
  2025-06-11 16:13   ` Andrew Lunn
  2025-06-30 21:08   ` Alexander Sverdlin
  1 sibling, 2 replies; 7+ messages in thread
From: Inochi Amaoto @ 2025-06-11  8:02 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Inochi Amaoto, Heiner Kallweit, Russell King,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
  Cc: netdev, devicetree, sophgo, linux-kernel, linux-riscv, Yixun Lan,
	Longbin Li

Add device driver for the mux driver for Sophgo CV18XX/SG200X
series SoCs.

Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
 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

diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig
index 7db40aaa079d..fe553016b77d 100644
--- a/drivers/net/mdio/Kconfig
+++ b/drivers/net/mdio/Kconfig
@@ -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
diff --git a/drivers/net/mdio/Makefile b/drivers/net/mdio/Makefile
index c23778e73890..a67be2abc343 100644
--- a/drivers/net/mdio/Makefile
+++ b/drivers/net/mdio/Makefile
@@ -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
diff --git a/drivers/net/mdio/mdio-mux-cv1800b.c b/drivers/net/mdio/mdio-mux-cv1800b.c
new file mode 100644
index 000000000000..6c69e83c3dcd
--- /dev/null
+++ b/drivers/net/mdio/mdio-mux-cv1800b.c
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Sophgo CV1800 MDIO multiplexer driver
+ *
+ * Copyright (C) 2025 Inochi Amaoto <inochiama@gmail.com>
+ */
+
+#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;
+
+	writel(val, mdmux->regs + EPHY_CTRL);
+
+	writel(EPHY_REG_SELECT_MDIO, mdmux->regs + EPHY_REG_SELECT);
+
+	return 0;
+}
+
+static int cv1800b_mdio_switch_fn(int current_child, int desired_child,
+				  void *data)
+{
+	struct cv1800b_mdio_mux *mdmux = dev_get_drvdata(data);
+
+	if (current_child == desired_child)
+		return 0;
+
+	switch (desired_child) {
+	case CV1800B_MDIO_EXTERNAL_ID:
+		return cv1800b_enable_mdio(mdmux, false);
+	case CV1800B_MDIO_INTERNAL_ID:
+		return cv1800b_enable_mdio(mdmux, true);
+	default:
+		return -EINVAL;
+	}
+}
+
+static int cv1800b_mdio_mux_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct cv1800b_mdio_mux *mdmux;
+
+	mdmux = devm_kzalloc(dev, sizeof(*mdmux), GFP_KERNEL);
+	if (!mdmux)
+		return -ENOMEM;
+	platform_set_drvdata(pdev, mdmux);
+
+	mdmux->regs = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(mdmux->regs))
+		return PTR_ERR(mdmux->regs);
+
+	return mdio_mux_init(dev, dev->of_node, cv1800b_mdio_switch_fn,
+			     &mdmux->mux_handle, dev, NULL);
+}
+
+static void cv1800b_mdio_mux_remove(struct platform_device *pdev)
+{
+	struct cv1800b_mdio_mux *mdmux = platform_get_drvdata(pdev);
+
+	mdio_mux_uninit(mdmux->mux_handle);
+}
+
+static const struct of_device_id cv1800b_mdio_mux_match[] = {
+	{ .compatible = "sophgo,cv1800b-mdio-mux", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, cv1800b_mdio_mux_match);
+
+static struct platform_driver cv1800b_mdio_mux_driver = {
+	.probe		= cv1800b_mdio_mux_probe,
+	.remove		= cv1800b_mdio_mux_remove,
+	.driver		= {
+		.name	= "cv1800b-mdio-mux",
+		.of_match_table = cv1800b_mdio_mux_match,
+	},
+};
+module_platform_driver(cv1800b_mdio_mux_driver);
+
+MODULE_DESCRIPTION("Sophgo CV1800 MDIO multiplexer driver");
+MODULE_AUTHOR("Inochi Amaoto <inochiama@gmail.com>");
+MODULE_LICENSE("GPL");
-- 
2.49.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs
  2025-06-11  8:02 ` [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs Inochi Amaoto
@ 2025-06-11 16:13   ` Andrew Lunn
  2025-06-12  0:33     ` Inochi Amaoto
  2025-06-30 21:08   ` Alexander Sverdlin
  1 sibling, 1 reply; 7+ messages in thread
From: Andrew Lunn @ 2025-06-11 16:13 UTC (permalink / raw)
  To: Inochi Amaoto
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Heiner Kallweit, Russell King, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Alexandre Ghiti, netdev, devicetree,
	sophgo, linux-kernel, linux-riscv, Yixun Lan, Longbin Li

On Wed, Jun 11, 2025 at 04:02:00PM +0800, Inochi Amaoto wrote:
> Add device driver for the mux driver for Sophgo CV18XX/SG200X
> series SoCs.
> 
> @@ -0,0 +1,119 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Sophgo CV1800 MDIO multiplexer driver
> + *
> + * Copyright (C) 2025 Inochi Amaoto <inochiama@gmail.com>
> + */
> +
> +#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)

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>;
            };
        };
    };

    Andrew

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs
  2025-06-11 16:13   ` Andrew Lunn
@ 2025-06-12  0:33     ` Inochi Amaoto
  0 siblings, 0 replies; 7+ messages in thread
From: Inochi Amaoto @ 2025-06-12  0:33 UTC (permalink / raw)
  To: Andrew Lunn, Inochi Amaoto
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Chen Wang, Heiner Kallweit, Russell King, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Alexandre Ghiti, netdev, devicetree,
	sophgo, linux-kernel, linux-riscv, Yixun Lan, Longbin Li

On Wed, Jun 11, 2025 at 06:13:00PM +0200, Andrew Lunn wrote:
> On Wed, Jun 11, 2025 at 04:02:00PM +0800, Inochi Amaoto wrote:
> > Add device driver for the mux driver for Sophgo CV18XX/SG200X
> > series SoCs.
> > 
> > @@ -0,0 +1,119 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Sophgo CV1800 MDIO multiplexer driver
> > + *
> > + * Copyright (C) 2025 Inochi Amaoto <inochiama@gmail.com>
> > + */
> > +
> > +#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)
> 
> 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.

> 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>;
>             };
>         };
>     };
> 

It is good for me to use this. I will have a try. Thanks.

Regards,
Inochi

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs
  2025-06-11  8:02 ` [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs Inochi Amaoto
  2025-06-11 16:13   ` Andrew Lunn
@ 2025-06-30 21:08   ` Alexander Sverdlin
  2025-07-01  0:36     ` Inochi Amaoto
  1 sibling, 1 reply; 7+ messages in thread
From: Alexander Sverdlin @ 2025-06-30 21:08 UTC (permalink / raw)
  To: Inochi Amaoto, Andrew Lunn
  Cc: netdev, devicetree, sophgo, linux-kernel, linux-riscv, Yixun Lan,
	Longbin Li

Hi Inochi!

On Wed, 2025-06-11 at 16:02 +0800, Inochi Amaoto wrote:
> Add device driver for the mux driver for Sophgo CV18XX/SG200X
> series SoCs.
> 
> Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
> ---
>  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
> 
> diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig
> index 7db40aaa079d..fe553016b77d 100644
> --- a/drivers/net/mdio/Kconfig
> +++ b/drivers/net/mdio/Kconfig
> @@ -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
> diff --git a/drivers/net/mdio/Makefile b/drivers/net/mdio/Makefile
> index c23778e73890..a67be2abc343 100644
> --- a/drivers/net/mdio/Makefile
> +++ b/drivers/net/mdio/Makefile
> @@ -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
> diff --git a/drivers/net/mdio/mdio-mux-cv1800b.c b/drivers/net/mdio/mdio-mux-cv1800b.c
> new file mode 100644
> index 000000000000..6c69e83c3dcd
> --- /dev/null
> +++ b/drivers/net/mdio/mdio-mux-cv1800b.c
> @@ -0,0 +1,119 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Sophgo CV1800 MDIO multiplexer driver
> + *
> + * Copyright (C) 2025 Inochi Amaoto <inochiama@gmail.com>
> + */
> +
> +#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;
> +
> +	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...

-- 
Alexander Sverdlin.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs
  2025-06-30 21:08   ` Alexander Sverdlin
@ 2025-07-01  0:36     ` Inochi Amaoto
  0 siblings, 0 replies; 7+ messages in thread
From: Inochi Amaoto @ 2025-07-01  0:36 UTC (permalink / raw)
  To: Alexander Sverdlin, Inochi Amaoto, Andrew Lunn
  Cc: netdev, devicetree, sophgo, linux-kernel, linux-riscv, Yixun Lan,
	Longbin Li

On Mon, Jun 30, 2025 at 11:08:37PM +0200, Alexander Sverdlin wrote:
> Hi Inochi!
> 
> On Wed, 2025-06-11 at 16:02 +0800, Inochi Amaoto wrote:
> > Add device driver for the mux driver for Sophgo CV18XX/SG200X
> > series SoCs.
> > 
> > Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
> > ---
> >  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
> > 
> > diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig
> > index 7db40aaa079d..fe553016b77d 100644
> > --- a/drivers/net/mdio/Kconfig
> > +++ b/drivers/net/mdio/Kconfig
> > @@ -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
> > diff --git a/drivers/net/mdio/Makefile b/drivers/net/mdio/Makefile
> > index c23778e73890..a67be2abc343 100644
> > --- a/drivers/net/mdio/Makefile
> > +++ b/drivers/net/mdio/Makefile
> > @@ -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
> > diff --git a/drivers/net/mdio/mdio-mux-cv1800b.c b/drivers/net/mdio/mdio-mux-cv1800b.c
> > new file mode 100644
> > index 000000000000..6c69e83c3dcd
> > --- /dev/null
> > +++ b/drivers/net/mdio/mdio-mux-cv1800b.c
> > @@ -0,0 +1,119 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Sophgo CV1800 MDIO multiplexer driver
> > + *
> > + * Copyright (C) 2025 Inochi Amaoto <inochiama@gmail.com>
> > + */
> > +
> > +#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;
> > +
> > +	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.

> # 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.

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.

> Maybe it just switches the external MDIO master on/off?

Yes

> Seems that we need the documentation for this thing ;-)
> 

Please ask for the vendor.

> 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

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-07-01  0:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-11  8:01 [PATCH net-next 0/2] riscv: dts: sophgo: Add mdio multiplexer for cv18xx Inochi Amaoto
2025-06-11  8:01 ` [PATCH net-next 1/2] dt-bindings: net: Add Sophgo CV1800 MDIO multiplexer Inochi Amaoto
2025-06-11  8:02 ` [PATCH net-next 2/2] net: mdio-mux: Add MDIO mux driver for Sophgo CV1800 SoCs Inochi Amaoto
2025-06-11 16:13   ` Andrew Lunn
2025-06-12  0:33     ` Inochi Amaoto
2025-06-30 21:08   ` Alexander Sverdlin
2025-07-01  0:36     ` Inochi Amaoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox