Skip to contentSkip to conversation

netdev/phy: add MDIO bus multiplexer driven by a memory-mapped device

PATCH Applied Timur Tabi 4 participants 5 messages Aug 24, 2012 – Aug 30, 2012

Subsystems (4)
lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH v3 1/1 netdev/phy: add MDIO bus multiplexer driven by a memory-mapped device

Add support for an MDIO bus multiplexer controlled by a simple memory-mapped device, like an FPGA. The device must be memory-mapped and contain only 8-bit registers (which keeps things simple).

Tested on a Freescale P5020DS board which uses the "PIXIS" FPGA attached to the localbus.

---
 .../devicetree/bindings/net/mdio-mux-mmioreg.txt   |   77 +++++++++
 drivers/net/phy/Kconfig                            |   13 ++
 drivers/net/phy/Makefile                           |    1 +
 drivers/net/phy/mdio-mux-mmioreg.c                 |  170 ++++++++++++++++++++
 4 files changed, 261 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt
 create mode 100644 drivers/net/phy/mdio-mux-mmioreg.c
Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt new file +77 -0
new file mode 100644
index 0000000..aff8fd9
@@ -0,0 +1,77 @@
+Properties for an MDIO bus multiplexer controlled by a memory-mapped device
+
+This is a special case of a MDIO bus multiplexer.  A memory-mapped device,
+like an FPGA, is used to control which child bus is connected.  The mdio-mux
+node must be a child of the memory-mapped device.  The driver currently only
+supports devices with eight-bit registers.
+
+Required properties in addition to the generic multiplexer properties:
+
+- compatible : string, must contain "mdio-mux-mmioreg"
+
+- reg : integer, contains the offset of the register that controls the bus
+	multiplexer.  The size field in the 'reg' property is the size of
+	register, and must therefore be 1.
+
+- mux-mask : integer, contains an eight-bit mask that specifies which
+	bits in the register control the actual bus multiplexer.  The
+	'reg' property of each child mdio-mux node must be constrained by
+	this mask.
+
+Example:
+
+The FPGA node defines a memory-mapped FPGA with a register space of 0x30 bytes.
+For the "EMI2" MDIO bus, register 9 (BRDCFG1) controls the mux on that bus.
+A bitmask of 0x6 means that bits 1 and 2 (bit 0 is lsb) are the bits on
+BRDCFG1 that control the actual mux.
+
+	/* The FPGA node */
+	fpga: board-control@3,0 {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "fsl,p5020ds-fpga", "fsl,fpga-ngpixis";
+		reg = <3 0 0x30>;
+		ranges = <0 3 0 0x30>;
+
+		mdio-mux-emi2 {
+			compatible = "mdio-mux-mmioreg", "mdio-mux";
+			mdio-parent-bus = <&xmdio0>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			reg = <9 1>; // BRDCFG1
+			mux-mask = <0x6>; // EMI2
+
+			emi2_slot1: mdio@0 {	// Slot 1 XAUI (FM2)
+				reg = <0>;
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				phy_xgmii_slot1: ethernet-phy@0 {
+					compatible = "ethernet-phy-ieee802.3-c45";
+					reg = <4>;
+				};
+			};
+
+			emi2_slot2: mdio@2 {	// Slot 2 XAUI (FM1)
+				reg = <2>;
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				phy_xgmii_slot2: ethernet-phy@4 {
+					compatible = "ethernet-phy-ieee802.3-c45";
+					reg = <0>;
+				};
+			};
+		};
+	};
+
+	/* The parent MDIO bus. */
+	xmdio0: mdio@f1000 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "fsl,fman-xmdio";
+		reg = <0xf1000 0x1000>;
+		interrupts = <100 1 0 0>;
+	};
+
+
drivers/net/phy/Kconfig +13 -0
index 3090dc6..0268edd 100644
@@ -159,6 +159,19 @@ config MDIO_BUS_MUX_GPIO
 	  several child MDIO busses to a parent bus.  Child bus
 	  selection is under the control of GPIO lines.
 
+config MDIO_BUS_MUX_MMIOREG
+	tristate "Support for MMIO device-controlled MDIO bus multiplexers"
+	depends on OF_MDIO
+	select MDIO_BUS_MUX
+	help
+	  This module provides a driver for MDIO bus multiplexers that
+	  are controlled via a simple memory-mapped device, like an FPGA.
+	  The multiplexer connects one of several child MDIO busses to a
+	  parent bus.  Child bus selection is under the control of one of
+	  the FPGA's registers.
+
+	  Currently, only 8-bit registers are supported.
+
 endif # PHYLIB
 
 config MICREL_KS8995MA
drivers/net/phy/Makefile +1 -0
index 6d2dc6c..426674d 100644
@@ -28,3 +28,4 @@ obj-$(CONFIG_MICREL_KS8995MA)	+= spi_ks8995.o
 obj-$(CONFIG_AMD_PHY)		+= amd.o
 obj-$(CONFIG_MDIO_BUS_MUX)	+= mdio-mux.o
 obj-$(CONFIG_MDIO_BUS_MUX_GPIO)	+= mdio-mux-gpio.o
+obj-$(CONFIG_MDIO_BUS_MUX_MMIOREG) += mdio-mux-mmioreg.o
drivers/net/phy/mdio-mux-mmioreg.c new file +170 -0

170 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#1 lore raw
Quoted 9 lines · Timur Tabi

Add support for an MDIO bus multiplexer controlled by a simple memory-mapped device, like an FPGA. The device must be memory-mapped and contain only 8-bit registers (which keeps things simple).

Tested on a Freescale P5020DS board which uses the "PIXIS" FPGA attached to the localbus.

+++ b/Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt

Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt line 6

Quoted 6 lines
Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt new file +6 -0
+Properties for an MDIO bus multiplexer controlled by a memory-mapped device
+
+This is a special case of a MDIO bus multiplexer.  A memory-mapped device,
+like an FPGA, is used to control which child bus is connected.  The mdio-mux
+node must be a child of the memory-mapped device.  The driver currently only
+supports devices with eight-bit registers.

That last sentence seems like a property of the driver, not the binding; I could easily anticipate allowing the size to be 1 or 2 or 4, and a driver adapter to that in the future.

Otherwise, this binding looks great now.

drivers/net/phy/mdio-mux-mmioreg.c line 54

Quoted 13 lines

+++ b/drivers/net/phy/mdio-mux-mmioreg.c

drivers/net/phy/mdio-mux-mmioreg.c new file +11 -0
+static int mdio_mux_mmioreg_switch_fn(int current_child, int desired_child,
+				      void *data)
+{
+	struct mdio_mux_mmioreg_state *s = data;
+
+	if (current_child ^ desired_child) {
+		void *p = ioremap(s->phys, 1);
+		uint8_t x, y;
+
+		if (!p)
+			return -ENOMEM;

Why not map it during probe?

drivers/net/phy/mdio-mux-mmioreg.c line 58

Quoted 3 lines
drivers/net/phy/mdio-mux-mmioreg.c new file +3 -0
+		x = ioread8(p);
+		y = (x & ~s->mask) | desired_child;
+		if (x != y) {

Isn't that always true, given if (current_child ^ desired_child) above?

Quoted 9 lines
drivers/net/phy/mdio-mux-mmioreg.c new file +9 -0
+			iowrite8((x & ~s->mask) | desired_child, p);
+			pr_debug("%s: %02x -> %02x\n", __func__, x, y);
+		}
+
+		iounmap(p);
+	}
+
+	return 0;
+}
#2 lore raw
Quoted 8 lines · Stephen Warren

Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt line 6

Quoted 4 lines
Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt new file +4 -0
+This is a special case of a MDIO bus multiplexer.  A memory-mapped device,
+like an FPGA, is used to control which child bus is connected.  The mdio-mux
+node must be a child of the memory-mapped device.  The driver currently only
+supports devices with eight-bit registers.

That last sentence seems like a property of the driver, not the binding; I could easily anticipate allowing the size to be 1 or 2 or 4, and a driver adapter to that in the future.

True, but I couldn't think of a better place to mention this. Adding support for multi-byte registers also requires handling the endianness of those registers. I have that problem with the mdio-mux-gpio driver. That driver assumes that the GPIO bits are numbered in little-endian order, so my device tree on my big-endian CPU (PowerPC) lists the GPIO pins in reverse order.

Quoted 1 line

Otherwise, this binding looks great now.

Do you still want me to scrub any references to the register size requirement from the document?

Quoted 15 lines

drivers/net/phy/mdio-mux-mmioreg.c line 54

Quoted 13 lines

+++ b/drivers/net/phy/mdio-mux-mmioreg.c

drivers/net/phy/mdio-mux-mmioreg.c new file +11 -0
+static int mdio_mux_mmioreg_switch_fn(int current_child, int desired_child,
+				      void *data)
+{
+	struct mdio_mux_mmioreg_state *s = data;
+
+	if (current_child ^ desired_child) {
+		void *p = ioremap(s->phys, 1);
+		uint8_t x, y;
+
+		if (!p)
+			return -ENOMEM;

Why not map it during probe?

I thought about that, but I generally don't like mappings that exist for all eternity even though they're rarely used. Once the interface is up, we don't expect any bus muxing to occur.

Quoted 6 lines

drivers/net/phy/mdio-mux-mmioreg.c line 58

Quoted 4 lines
drivers/net/phy/mdio-mux-mmioreg.c new file +3 -0
+		x = ioread8(p);
+		y = (x & ~s->mask) | desired_child;
+		if (x != y) {

Isn't that always true, given if (current_child ^ desired_child) above?

If current_child == -1, but the bus is already muxed properly, then there's no point in setting it. Do you want me to remove the test, or add a comment?

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#3 lore raw
Quoted 11 lines · Timur Tabi
Quoted 8 lines · Stephen Warren

Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt line 6

Quoted 4 lines
Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt new file +4 -0
+This is a special case of a MDIO bus multiplexer.  A memory-mapped device,
+like an FPGA, is used to control which child bus is connected.  The mdio-mux
+node must be a child of the memory-mapped device.  The driver currently only
+supports devices with eight-bit registers.

That last sentence seems like a property of the driver, not the binding; I could easily anticipate allowing the size to be 1 or 2 or 4, and a driver adapter to that in the future.

Quoted 6 lines

True, but I couldn't think of a better place to mention this. Adding support for multi-byte registers also requires handling the endianness of those registers. I have that problem with the mdio-mux-gpio driver. That driver assumes that the GPIO bits are numbered in little-endian order, so my device tree on my big-endian CPU (PowerPC) lists the GPIO pins in reverse order.

True. One could always simply assume that the registers are native endian by default, and then if ever they need not to be, add optional properties to the binding.

Quoted 4 lines
Quoted 1 line

Otherwise, this binding looks great now.

Do you still want me to scrub any references to the register size requirement from the document?

I don't feel too strongly about it. It seems cleaner to, but not a big deal.

Quoted 27 lines
Quoted 15 lines

drivers/net/phy/mdio-mux-mmioreg.c line 54

Quoted 13 lines

+++ b/drivers/net/phy/mdio-mux-mmioreg.c

drivers/net/phy/mdio-mux-mmioreg.c new file +11 -0
+static int mdio_mux_mmioreg_switch_fn(int current_child, int desired_child,
+				      void *data)
+{
+	struct mdio_mux_mmioreg_state *s = data;
+
+	if (current_child ^ desired_child) {
+		void *p = ioremap(s->phys, 1);
+		uint8_t x, y;
+
+		if (!p)
+			return -ENOMEM;

Why not map it during probe?

I thought about that, but I generally don't like mappings that exist for all eternity even though they're rarely used. Once the interface is up, we don't expect any bus muxing to occur.

Quoted 6 lines

drivers/net/phy/mdio-mux-mmioreg.c line 58

Quoted 4 lines
drivers/net/phy/mdio-mux-mmioreg.c new file +3 -0
+		x = ioread8(p);
+		y = (x & ~s->mask) | desired_child;
+		if (x != y) {

Isn't that always true, given if (current_child ^ desired_child) above?

Quoted 3 lines

If current_child == -1, but the bus is already muxed properly, then there's no point in setting it. Do you want me to remove the test, or add a comment?

Ah right, I suppose that is true. It almost doesn't seem worth writing the code to ignore that special case, since presumably the register write is idempotent, but since it's already there you can feel free not to rip it out!

maintainer Applied
#4 lore raw
In reply to Timur Tabi

From: Timur Tabi <[email protected]>
Date: Fri, 24 Aug 2012 14:10:53 -0500

Quoted 8 lines

Add support for an MDIO bus multiplexer controlled by a simple memory-mapped device, like an FPGA. The device must be memory-mapped and contain only 8-bit registers (which keeps things simple).

Tested on a Freescale P5020DS board which uses the "PIXIS" FPGA attached to the localbus.

Applied to net-next, thanks.