netdev/of/phy: MDIO bus multiplexer support.
Subsystems (6)
v3 cover netdev/of/phy: MDIO bus multiplexer support.
From: David Daney <david.daney-YGCgFSpz5w/[email protected]>
This code has been working well for about six months on a couple of different configurations (boards), so I thought it would be a good time to send it out again, and I hope get it on the path towards merging.
v3: Update binding to use "mdio-mux-gpio" compatible property.
Cleanups suggested by Grant Likely. Now uses the driver probe deferral mechanism if GPIOs or parent bus not available.
v2: Update bindings to use "reg" and "mdio-parent-bus" instead of
"cell-index" and "parent-bus"
v1:
We have several different boards with a multiplexer in the MDIO bus. There is an MDIO bus controller connected to a switching device with several child MDIO busses.
Everything is wired up using device tree bindings.
1/3 - New of_mdio_find_bus() function used to help configuring the
driver topology.
2/3 - MDIO bus multiplexer framework.
3/3 - A driver for a GPIO controlled multiplexer.
David Daney (3):
netdev/of/phy: New function: of_mdio_find_bus(). netdev/of/phy: Add MDIO bus multiplexer support. netdev/of/phy: Add MDIO bus multiplexer driven by GPIO lines.
.../devicetree/bindings/net/mdio-mux-gpio.txt | 127 +++++++++++++ Documentation/devicetree/bindings/net/mdio-mux.txt | 136 ++++++++++++++ drivers/net/phy/Kconfig | 18 ++ drivers/net/phy/Makefile | 2 + drivers/net/phy/mdio-mux-gpio.c | 142 +++++++++++++++ drivers/net/phy/mdio-mux.c | 192 ++++++++++++++++++++ drivers/net/phy/mdio_bus.c | 32 ++++ drivers/of/of_mdio.c | 2 + include/linux/mdio-mux.h | 21 ++ include/linux/of_mdio.h | 2 + 10 files changed, 674 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/mdio-mux-gpio.txt create mode 100644 Documentation/devicetree/bindings/net/mdio-mux.txt create mode 100644 drivers/net/phy/mdio-mux-gpio.c create mode 100644 drivers/net/phy/mdio-mux.c create mode 100644 include/linux/mdio-mux.h
Signature · 1 line
1.7.2.3
PATCH v3 1/3 netdev/of/phy: New function: of_mdio_find_bus().
From: David Daney <[email protected]>
Add of_mdio_find_bus() which allows an mii_bus to be located given its associated the device tree node.
This is needed by the follow-on patch to add a driver for MDIO bus multiplexers.
The of_mdiobus_register() function is modified so that the device tree node is recorded in the mii_bus. Then we can find it again by iterating over all mdio_bus_class devices.
Because the OF device tree has now become an integral part of the kernel, this can live in mdio_bus.c (which contains the needed mdio_bus_class structure) instead of of_mdio.c.
--- drivers/net/phy/mdio_bus.c | 32 ++++++++++++++++++++++++++++++++ drivers/of/of_mdio.c | 2 ++ include/linux/of_mdio.h | 2 ++ 3 files changed, 36 insertions(+), 0 deletions(-)
drivers/net/phy/mdio_bus.c +32 -0
@@ -88,6 +88,38 @@ static struct class mdio_bus_class = { .dev_release = mdiobus_release, }; +#ifdef CONFIG_OF_MDIO +/* Helper function for of_phy_find_device */ +static int of_mii_bus_match (struct device *dev,void *mii_bus_np) +{ +return dev->of_node == mii_bus_np; +} +/** +* of_mdio_find_bus - Given an mii_bus node, find the mii_bus. +* @mdio_np: Pointer to the mii_bus. +* +* Returns a pointer to the mii_bus, or NULL if none found. +* +* Because the association of a device_node and mii_bus is made via +* of_mdiobus_register(), the mii_bus cannot be found before it is +* registered with of_mdiobus_register(). +* +*/ +struct mii_bus *of_mdio_find_bus (struct device_node *mdio_np) +{ +struct device *d; + +if (!mdio_np) +return NULL ; + + d =class_find_device (&mdio_bus_class,NULL , mdio_np, + of_mii_bus_match); + +return d ?to_mii_bus (d) :NULL ; +} +EXPORT_SYMBOL (of_mdio_find_bus); +#endif +/** * mdiobus_register - bring up all the PHYs on a given bus and attach them to bus * @bus: target mii_bus
drivers/of/of_mdio.c +2 -0
@@ -45,6 +45,8 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)for (i=0 ; i<PHY_MAX_ADDR ; i++) mdio->irq[i] =PHY_POLL ; + mdio->dev.of_node = np; +/* Register the MDIO bus */ rc =mdiobus_register (mdio);if (rc)
include/linux/of_mdio.h +2 -0
@@ -22,4 +22,6 @@ extern struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,void (*hndlr)(struct net_device *), phy_interface_t iface); +extern struct mii_bus *of_mdio_find_bus (struct device_node *mdio_np); +#endif /* __LINUX_OF_MDIO_H */
Signature · 1 line
1.7.2.3
Re: [PATCH v3 1/3] netdev/of/phy: New function: of_mdio_find_bus().
Quoted 30 lines · David Daney
From: David Daney<[email protected]>
Add
of_mdio_find_bus()which allows anmii_busto be located given its associated the device tree node.This is needed by the follow-on patch to add a driver for MDIO bus multiplexers.
The
of_mdiobus_register()function is modified so that the device tree node is recorded in themii_bus. Then we can find it again by iterating over allmdio_bus_classdevices.Because the OF device tree has now become an integral part of the kernel, this can live in
mdio_bus.c(which contains the neededmdio_bus_classstructure) instead ofof_mdio.c.Signed-off-by David Daney<[email protected]>Cc Grant Likely<[email protected]>Cc "David S. Miller"<[email protected]>--- drivers/net/phy/mdio_bus.c | 32 ++++++++++++++++++++++++++++++++ drivers/of/of_mdio.c | 2 ++ include/linux/of_mdio.h | 2 ++ 3 files changed, 36 insertions(+), 0 deletions(-)drivers/net/phy/mdio_bus.c +0
-0
drivers/net/phy/mdio_bus.c static struct class mdio_bus_class = { · line 92
Quoted 5 lines
drivers/net/phy/mdio_bus.c +2
-0@@ -88,6 +88,38 @@ static struct class mdio_bus_class = { .dev_release = mdiobus_release, }; +#ifdef CONFIG_OF_MDIO +/* Helper function for of_phy_find_device */
This comment is incorrect. I will resend the set with this cleaned up.
David Daney
Quoted 17 lines
drivers/net/phy/mdio_bus.c +17
-0+static int of_mii_bus_match (struct device *dev,void *mii_bus_np) +{ +return dev->of_node == mii_bus_np; +} +/** +* of_mdio_find_bus - Given an mii_bus node, find the mii_bus. +* @mdio_np: Pointer to the mii_bus. +* +* Returns a pointer to the mii_bus, or NULL if none found. +* +* Because the association of a device_node and mii_bus is made via +* of_mdiobus_register(), the mii_bus cannot be found before it is +* registered with of_mdiobus_register(). +* +*/ +struct mii_bus *of_mdio_find_bus (struct device_node *mdio_np) +{
[...]
PATCH v3 2/3 netdev/of/phy: Add MDIO bus multiplexer support.
In reply to David DaneyFrom: David Daney <[email protected]>
This patch adds a somewhat generic framework for MDIO bus multiplexers. It is modeled on the I2C multiplexer.
The multiplexer is needed if there are multiple PHYs with the same address connected to the same MDIO bus adepter, or if there is insufficient electrical drive capability for all the connected PHY devices.
Conceptually it could look something like this:
------------------
| Control Signal |
--------+---------
|
--------------- --------+------
| MDIO MASTER |---| Multiplexer |
--------------- --+-------+----
| |
C C
h h
i i
l l
d d
| |
--------- A B ---------
| | | | | |
| PHY@1 +-------+ +---+ PHY@1 |
| | | | | |
--------- | | ---------
--------- | | ---------
| | | | | |
| PHY@2 +-------+ +---+ PHY@2 |
| | | |
--------- ---------This framework configures the bus topology from device tree data. The mechanics of switching the multiplexer is left to device specific drivers.
The follow-on patch contains a multiplexer driven by GPIO lines.
--- Documentation/devicetree/bindings/net/mdio-mux.txt | 136 ++++++++++++++ drivers/net/phy/Kconfig | 8 + drivers/net/phy/Makefile | 1 + drivers/net/phy/mdio-mux.c | 192 ++++++++++++++++++++ include/linux/mdio-mux.h | 21 ++ 5 files changed, 358 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/mdio-mux.txt create mode 100644 drivers/net/phy/mdio-mux.c create mode 100644 include/linux/mdio-mux.h
Documentation/devicetree/bindings/net/mdio-mux.txt new file +136 -0
@@ -0,0 +1,136 @@ +Common MDIO bus multiplexer/switch properties. + +An MDIO bus multiplexer/switch will have several child busses that are +numbered uniquely in a device dependent manner. The nodes for an MDIO +bus multiplexer/switch will have one child node for each child bus. + +Required properties: +- mdio-parent-bus : phandle to the parent MDIO bus. +- #address-cells = <1>; +- #size-cells = <0>; + +Optional properties: +- Other properties specific to the multiplexer/switch hardware. + +Required properties for child nodes: +- #address-cells = <1>; +- #size-cells = <0>; +- reg : The sub-bus number. + + +Example : + + /* The parent MDIO bus. */ + smi1: mdio@1180000001900 { + compatible = "cavium,octeon-3860-mdio"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x11800 0x00001900 0x0 0x40>; + }; + + /* + An NXP sn74cbtlv3253 dual 1-of-4 switch controlled by a + pair of GPIO lines. Child busses 2 and 3 populated with 4 + PHYs each. + */ + mdio-mux { + compatible = "mdio-mux-gpio"; + gpios = <&gpio1 3 0>, <&gpio1 4 0>; + mdio-parent-bus = <&smi1>; + #address-cells = <1>; + #size-cells = <0>; + + mdio@2 { + reg = <2>; + #address-cells = <1>; + #size-cells = <0>; + + phy11: ethernet-phy@1 { + reg = <1>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <10 8>; /* Pin 10, active low */ + }; + phy12: ethernet-phy@2 { + reg = <2>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <10 8>; /* Pin 10, active low */ + }; + phy13: ethernet-phy@3 { + reg = <3>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <10 8>; /* Pin 10, active low */ + }; + phy14: ethernet-phy@4 { + reg = <4>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <10 8>; /* Pin 10, active low */ + }; + }; + + mdio@3 { + reg = <3>; + #address-cells = <1>; + #size-cells = <0>; + + phy21: ethernet-phy@1 { + reg = <1>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <12 8>; /* Pin 12, active low */ + }; + phy22: ethernet-phy@2 { + reg = <2>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <12 8>; /* Pin 12, active low */ + }; + phy23: ethernet-phy@3 { + reg = <3>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <12 8>; /* Pin 12, active low */ + }; + phy24: ethernet-phy@4 { + reg = <4>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <12 8>; /* Pin 12, active low */ + }; + }; + };
drivers/net/phy/Kconfig +8 -0
@@ -135,6 +135,14 @@ config MDIO_OCTEON If in doubt, say Y. +config MDIO_BUS_MUX + tristate + help + This module provides a driver framework for MDIO bus + multiplexers which connect one of several child MDIO busses + to a parent bus. Switching between child busses is done by + device specific drivers. + endif # PHYLIB config MICREL_KS8995MA
drivers/net/phy/Makefile +1 -0
@@ -25,3 +25,4 @@ obj-$(CONFIG_MICREL_PHY) += micrel.o obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o obj-$(CONFIG_MICREL_KS8995MA) += spi_ks8995.o obj-$(CONFIG_AMD_PHY) += amd.o +obj-$(CONFIG_MDIO_BUS_MUX) += mdio-mux.o
drivers/net/phy/mdio-mux.c new file +192 -0
192 lines not on this page · raw message
include/linux/mdio-mux.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* MDIO bus multiplexer framwork. +* +* This file is subject to the terms and conditions of the GNU General Public +* License. See the file "COPYING" in the main directory of this archive +* for more details. +* +* Copyright (C) 2011, 2012 Cavium, Inc. +*/ +#ifndef __LINUX_MDIO_MUX_H +#define __LINUX_MDIO_MUX_H +#include <linux/device.h> + +int mdio_mux_init (struct device *dev, +int (*switch_fn) (int cur,int desired,void *data), +void **mux_handle, +void *data); + +void mdio_mux_uninit (void *mux_handle); + +#endif /* __LINUX_MDIO_MUX_H */
Signature · 1 line
1.7.2.3
PATCH v3 3/3 netdev/of/phy: Add MDIO bus multiplexer driven by GPIO lines.
In reply to David DaneyFrom: David Daney <[email protected]>
The GPIO pins select which sub bus is connected to the master.
Initially tested with an sn74cbtlv3253 switch device wired into the MDIO bus.
--- .../devicetree/bindings/net/mdio-mux-gpio.txt | 127 +++++++++++++++++ drivers/net/phy/Kconfig | 10 ++ drivers/net/phy/Makefile | 1 + drivers/net/phy/mdio-mux-gpio.c | 142 ++++++++++++++++++++ 4 files changed, 280 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/mdio-mux-gpio.txt create mode 100644 drivers/net/phy/mdio-mux-gpio.c
Documentation/devicetree/bindings/net/mdio-mux-gpio.txt new file +127 -0
@@ -0,0 +1,127 @@ +Properties for an MDIO bus multiplexer/switch controlled by GPIO pins. + +This is a special case of a MDIO bus multiplexer. One or more GPIO +lines are used to control which child bus is connected. + +Required properties in addition to the generic multiplexer properties: + +- compatible : mdio-mux-gpio. +- gpios : GPIO specifiers for each GPIO line. One or more must be specified. + + +Example : + + /* The parent MDIO bus. */ + smi1: mdio@1180000001900 { + compatible = "cavium,octeon-3860-mdio"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x11800 0x00001900 0x0 0x40>; + }; + + /* + An NXP sn74cbtlv3253 dual 1-of-4 switch controlled by a + pair of GPIO lines. Child busses 2 and 3 populated with 4 + PHYs each. + */ + mdio-mux { + compatible = "mdio-mux-gpio"; + gpios = <&gpio1 3 0>, <&gpio1 4 0>; + mdio-parent-bus = <&smi1>; + #address-cells = <1>; + #size-cells = <0>; + + mdio@2 { + reg = <2>; + #address-cells = <1>; + #size-cells = <0>; + + phy11: ethernet-phy@1 { + reg = <1>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <10 8>; /* Pin 10, active low */ + }; + phy12: ethernet-phy@2 { + reg = <2>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <10 8>; /* Pin 10, active low */ + }; + phy13: ethernet-phy@3 { + reg = <3>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <10 8>; /* Pin 10, active low */ + }; + phy14: ethernet-phy@4 { + reg = <4>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <10 8>; /* Pin 10, active low */ + }; + }; + + mdio@3 { + reg = <3>; + #address-cells = <1>; + #size-cells = <0>; + + phy21: ethernet-phy@1 { + reg = <1>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <12 8>; /* Pin 12, active low */ + }; + phy22: ethernet-phy@2 { + reg = <2>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <12 8>; /* Pin 12, active low */ + }; + phy23: ethernet-phy@3 { + reg = <3>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <12 8>; /* Pin 12, active low */ + }; + phy24: ethernet-phy@4 { + reg = <4>; + compatible = "marvell,88e1149r"; + marvell,reg-init = <3 0x10 0 0x5777>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x0a60>; + interrupt-parent = <&gpio>; + interrupts = <12 8>; /* Pin 12, active low */ + }; + }; + };
drivers/net/phy/Kconfig +10 -0
@@ -143,6 +143,16 @@ config MDIO_BUS_MUX to a parent bus. Switching between child busses is done by device specific drivers. +config MDIO_BUS_MUX_GPIO + tristate "Support for GPIO controlled MDIO bus multiplexers" + depends on GENERIC_GPIO + select MDIO_BUS_MUX + help + This module provides a driver for MDIO bus multiplexers that + are controlled via GPIO lines. The multiplexer connects one of + several child MDIO busses to a parent bus. Child bus + selection is under the control of GPIO lines. + endif # PHYLIB config MICREL_KS8995MA
drivers/net/phy/Makefile +1 -0
@@ -26,3 +26,4 @@ obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o 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
drivers/net/phy/mdio-mux-gpio.c new file +142 -0
142 lines not on this page · raw message
Signature · 1 line
1.7.2.3