Skip to contentSkip to conversation

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

PATCH In review Timur Tabi 6 participants 11 messages Aug 23, 2012 – Aug 24, 2012 2 messages not in the archive

Subsystems (4)
lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH v2 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   |   73 ++++++++
 drivers/net/phy/Kconfig                            |   13 ++
 drivers/net/phy/Makefile                           |    1 +
 drivers/net/phy/mdio-mux-mmioreg.c                 |  185 ++++++++++++++++++++
 4 files changed, 272 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 +73 -0
new file mode 100644
index 0000000..251aa10
@@ -0,0 +1,73 @@
+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 8-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.
+
+- mux-mask : integer, contains an 8-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 {
+		compatible = "fsl,p5020ds-fpga", "fsl,fpga-ngpixis";
+		reg = <3 0 0x30>;
+
+		mdio-mux-emi2 {
+			compatible = "mdio-mux-mmioreg", "mdio-mux";
+			mdio-parent-bus = <&xmdio0>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			reg = <9>; // 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 +185 -0

185 lines not on this page · raw message

Signature · 1 line
1.7.3.4

A message that is not in the archive (sent off-list or not yet received): 1345751071-23128-1-git-send-email-timur-KZfg59tc24xl57MIdRCFDg@public.gmane.org

#2 lore raw

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

Quoted 10 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).

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

Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt new file +4 -0
+	/* The FPGA node */
+	fpga: board-control@3,0 {
+		compatible = "fsl,p5020ds-fpga", "fsl,fpga-ngpixis";
+		reg = <3 0 0x30>;

Why not add the following here:

	#address-cells = <1>:
	#size-cells = <1>;
	ranges = <...>;

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

Quoted 7 lines
Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt new file +7 -0
+
+		mdio-mux-emi2 {
+			compatible = "mdio-mux-mmioreg", "mdio-mux";
+			mdio-parent-bus = <&xmdio0>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			reg = <9>; // BRDCFG1

Then, that'd have to be <9 1>;

That way, ...

Quoted 8 lines
drivers/net/phy/mdio-mux-mmioreg.c +5 -0
 
+static int __devinit mdio_mux_mmioreg_probe(struct platform_device *pdev)
 
+	/* The MMIO device is the parent of this device */
+	np2 = of_get_parent(np);
+	if (!np2) {
+		dev_err(&pdev->dev, "could not find parent MMIO device\n");

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

Quoted 10 lines
drivers/net/phy/mdio-mux-mmioreg.c +10 -0
+		return -ENODEV;
+	}
+
+	ret = of_address_to_resource(np2, 0, &res);
+	if (ret) {
+		dev_err(&pdev->dev, "could not obtain memory map for node %s\n",
+			np2->full_name);
+		return ret;
+	}
+	s->phys = res.start;

You could simplify all that into just "of_iomap(np, 0)", and all the address translation etc. happens entirely automatically, in the standard fashion for DT.

The advantage here is that it completely decouples the mdio-mux-mmioreg driver from any knowledge of its parent; you could just as easily use this driver/binding as a device directly on some SoC bus, rather than requiring there to be a parent device above it. After all, the mux register might be some random standalone on-SoC register (although I wonder if that case might not be better covered by a mdio-mux-pinctrl driver instead; I guess it depends on how special-purpose the mux register is).

#3 lore raw
Quoted 14 lines · Stephen Warren

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

Quoted 10 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).

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

Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt new file +4 -0
+	/* The FPGA node */
+	fpga: board-control@3,0 {
+		compatible = "fsl,p5020ds-fpga", "fsl,fpga-ngpixis";
+		reg = <3 0 0x30>;

Why not add the following here:

Quoted 3 lines
	#address-cells = <1>:
	#size-cells = <1>;
	ranges = <...>;

I forgot to add them in the txt file. They are in the real device tree.

Quoted 10 lines

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

Quoted 8 lines
Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt new file +7 -0
+
+		mdio-mux-emi2 {
+			compatible = "mdio-mux-mmioreg", "mdio-mux";
+			mdio-parent-bus = <&xmdio0>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			reg = <9>; // BRDCFG1

Then, that'd have to be <9 1>;

Actually, I had #size-cells = <0>.

Quoted 17 lines

That way, ...

Quoted 14 lines
drivers/net/phy/mdio-mux-mmioreg.c +11 -0
 
+static int __devinit mdio_mux_mmioreg_probe(struct platform_device *pdev)
 
+	/* The MMIO device is the parent of this device */
+	np2 = of_get_parent(np);
+	if (!np2) {
+		dev_err(&pdev->dev, "could not find parent MMIO device\n");
+		return -ENODEV;
+	}
+
+	ret = of_address_to_resource(np2, 0, &res);
+	if (ret) {
+		dev_err(&pdev->dev, "could not obtain memory map for node %s\n",
Quoted 8 lines

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

Quoted 4 lines
drivers/net/phy/mdio-mux-mmioreg.c +4 -0
+			np2->full_name);
+		return ret;
+	}
+	s->phys = res.start;

You could simplify all that into just "of_iomap(np, 0)", and all the address translation etc. happens entirely automatically, in the standard fashion for DT.

Ah! You're right. I don't need to look for the parent node. Duh.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale

A message that is not in the archive (sent off-list or not yet received): 6AE080B68D46FC4BA2D2769E68D765B7059D1DC7-RL0Hj/+nBVC81RJBUSuqCa4g8xLGJsHaLnY5E4hWTkheoWH0uzbU5w@public.gmane.org

#5 lore raw
Quoted 32 lines · On 08/23/2012 06:28 PM, Tabi Timur-B04825 wrote:
Quoted 14 lines · Stephen Warren

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

Quoted 10 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).

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

Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt new file +4 -0
+	/* The FPGA node */
+	fpga: board-control@3,0 {
+		compatible = "fsl,p5020ds-fpga", "fsl,fpga-ngpixis";
+		reg = <3 0 0x30>;

Why not add the following here:

Quoted 3 lines
	#address-cells = <1>:
	#size-cells = <1>;
	ranges = <...>;

I forgot to add them in the txt file. They are in the real device tree.

Quoted 10 lines

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

Quoted 8 lines
Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt new file +7 -0
+
+		mdio-mux-emi2 {
+			compatible = "mdio-mux-mmioreg", "mdio-mux";
+			mdio-parent-bus = <&xmdio0>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			reg = <9>; // BRDCFG1

Then, that'd have to be <9 1>;

Quoted 1 line

Actually, I had #size-cells = <0>.

I think that if you have #size-cells=<0>, then you'll see the following error message when attempting to translate the address into the parent's address space:

prom_parse: Bad cell count for /board-control@3,0/mdio-mux-emi2

I fixed that error for cases where actual address translation isn't required (i.e. coming up with the platform device name), but IIRC it'll still trigger if you actually want to translate the address.

author
#6 lore raw
Quoted 9 lines · Stephen Warren
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

Then, that'd have to be <9 1>;

Actually, I had #size-cells = <0>.

I think that if you have #size-cells=<0>, then you'll see the following error message when attempting to translate the address into the parent's address space:

prom_parse: Bad cell count for /board-control@3,0/mdio-mux-emi2

It doesn't appear to be working. Here's my tree:

/ {
	model = "fsl,P5020DS";
	compatible = "fsl,P5020DS";
	#address-cells = <2>;
	#size-cells = <2>;
	interrupt-parent = <&mpic>;

	lbc: localbus@ffe124000 {
		reg = <0xf 0xfe124000 0 0x1000>;
		ranges = <0 0 0xf 0xe8000000 0x08000000
			  2 0 0xf 0xffa00000 0x00040000
			  3 0 0xf 0xffdf0000 0x00008000>;

		fpga: board-control@3,0 {
			#address-cells = <1>;
			#size-cells = <1>;
			compatible = "fsl,p5020ds-fpga", "fsl,fpga-ngpixis";
			reg = <3 0 0x30>;

			mdio-mux-emi1 {
				compatible = "mdio-mux-mmioreg";
				mdio-parent-bus = <&mdio0>;
				#address-cells = <1>;
				#size-cells = <0>;
				reg = <9 1>; // BRDCFG1
				mux-mask = <0x78>; // EMI1

That means that the physical address that I need is fffdf0009. However, when I call of_address_to_resource(), the returned address I get is fe8000009.

So it's not picking up the "3" in the 'reg' property of the board-control@3,0 node. What am I missing? Do I need a 'ranges' property in the board-control@3,0 node?

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#7 lore raw
Quoted 40 lines · Timur Tabi
Quoted 9 lines · Stephen Warren
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

Then, that'd have to be <9 1>;

Actually, I had #size-cells = <0>.

I think that if you have #size-cells=<0>, then you'll see the following error message when attempting to translate the address into the parent's address space:

prom_parse: Bad cell count for /board-control@3,0/mdio-mux-emi2

It doesn't appear to be working. Here's my tree:

/ {
	model = "fsl,P5020DS";
	compatible = "fsl,P5020DS";
	#address-cells = <2>;
	#size-cells = <2>;
	interrupt-parent = <&mpic>;

	lbc: localbus@ffe124000 {
		reg = <0xf 0xfe124000 0 0x1000>;
		ranges = <0 0 0xf 0xe8000000 0x08000000
			  2 0 0xf 0xffa00000 0x00040000
			  3 0 0xf 0xffdf0000 0x00008000>;

		fpga: board-control@3,0 {
			#address-cells = <1>;
			#size-cells = <1>;
			compatible = "fsl,p5020ds-fpga", "fsl,fpga-ngpixis";
			reg = <3 0 0x30>;

			mdio-mux-emi1 {
				compatible = "mdio-mux-mmioreg";
				mdio-parent-bus = <&mdio0>;
				#address-cells = <1>;
				#size-cells = <0>;
				reg = <9 1>; // BRDCFG1
				mux-mask = <0x78>; // EMI1
Quoted 6 lines

That means that the physical address that I need is fffdf0009. However, when I call of_address_to_resource(), the returned address I get is fe8000009.

So it's not picking up the "3" in the 'reg' property of the board-control@3,0 node. What am I missing? Do I need a 'ranges' property in the board-control@3,0 node?

Yes.

When translating the child node's reg property into the parent's address space, the parent's reg property shouldn't even be used at all; all the mapping is done through the ranges property.

I thought the code error-checked for a missing ranges property, but I guess not...

author
#8 lore raw
Quoted 6 lines · Stephen Warren

When translating the child node's reg property into the parent's address space, the parent's reg property shouldn't even be used at all; all the mapping is done through the ranges property.

I thought the code error-checked for a missing ranges property, but I guess not...

I don't think 'ranges' is always necessary, because sometimes the child nodes have a different address space that's not mapped to the parent. For instance, I2C devices have addresses that are not mapped to the I2C controller itself.

Anyway, thanks to Scott for helping me figure this out. I was missing a ranges property:

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

This maps the child address of 0 to the parent address of 3 0. It seems obvious now, but it was driving me crazy. We've never put child devices under our FPGA nodes, so there was no prior use case of a 'ranges' property in any of the localbus devices that I could learn from. Plus, this is the first time we're probing directly on a child of a localbus device.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#9 lore raw
Quoted 23 lines · Timur Tabi
Quoted 6 lines · Stephen Warren

When translating the child node's reg property into the parent's address space, the parent's reg property shouldn't even be used at all; all the mapping is done through the ranges property.

I thought the code error-checked for a missing ranges property, but I guess not...

I don't think 'ranges' is always necessary, because sometimes the child nodes have a different address space that's not mapped to the parent. For instance, I2C devices have addresses that are not mapped to the I2C controller itself.

Anyway, thanks to Scott for helping me figure this out. I was missing a ranges property:

	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>;
Quoted 5 lines

This maps the child address of 0 to the parent address of 3 0. It seems obvious now, but it was driving me crazy. We've never put child devices under our FPGA nodes, so there was no prior use case of a 'ranges' property in any of the localbus devices that I could learn from. Plus, this is the first time we're probing directly on a child of a localbus device.

There's ep8248e.dts, not that I'd have expected you to look there. :-)

-Scott

#10 lore raw
In reply to Timur Tabi
Quoted 5 lines · Timur Tabi
Quoted 4 lines · Stephen Warren

When translating the child node's reg property into the parent's address space, the parent's reg property shouldn't even be used at all; all the mapping is done through the ranges property.

Quoted 7 lines
Quoted 2 lines

I thought the code error-checked for a missing ranges property, but I guess not...

I don't think 'ranges' is always necessary, because sometimes the child nodes have a different address space that's not mapped to the parent. For instance, I2C devices have addresses that are not mapped to the I2C controller itself.

In the I2C case, the address spaces are disjoint, so there's never any mapping between them, so there's no need for ranges.

Any time the child address space is intended to be part of the parent's address space, I believe ranges is supposed to be specified, perhaps even mandatory, even if the translation is 1:1.

Quoted 11 lines

Anyway, thanks to Scott for helping me figure this out. I was missing a ranges property:

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

This maps the child address of 0 to the parent address of 3 0.

Yes, that looks reasonable.

maintainer
#11 lore raw

From: Stephen Warren <[email protected]>
Date: Fri, 24 Aug 2012 12:56:05 -0600

Quoted 6 lines

In the I2C case, the address spaces are disjoint, so there's never any mapping between them, so there's no need for ranges.

Any time the child address space is intended to be part of the parent's address space, I believe ranges is supposed to be specified, perhaps even mandatory, even if the translation is 1:1.

Regardless, you really can't just generically translate ranges in some universal way and expect it to work in all cases.

You need bus specific drivers to deal with various special cases.

See the *_map() methods implemented in:

arch/sparc/kernel/of_device_64.c

for example.

#12 lore raw
Quoted 9 lines · David Miller

From: Stephen Warren <[email protected]>
Date: Fri, 24 Aug 2012 12:56:05 -0600

Quoted 6 lines

In the I2C case, the address spaces are disjoint, so there's never any mapping between them, so there's no need for ranges.

Any time the child address space is intended to be part of the parent's address space, I believe ranges is supposed to be specified, perhaps even mandatory, even if the translation is 1:1.

Yes, it's mandatory (even if the kernel lets you get away without it for the sake of some broken Apple firmware, IIRC). If the translation is an identity map you can use an empty "ranges;".

Quoted 11 lines

Regardless, you really can't just generically translate ranges in some universal way and expect it to work in all cases.

You need bus specific drivers to deal with various special cases.

See the *_map() methods implemented in:

arch/sparc/kernel/of_device_64.c

for example.

We don't expect it to work in all cases. We expect it to work if the bus node is on the whitelist for which we create devices on platform_bus, there's a platform driver that binds against it, and that driver calls of_iomap() or equivalent because the binding says that reg refers to something that is memory mapped.

-Scott