net: add MDIO_MUX DM class
Subsystems (2)
PATCH v5 1/4 net: add MDIO_MUX DM class
Adds a class for MDIO MUXes, which control access to a series of downstream child MDIOs.
MDIO MUX drivers are required to implement a select function used to switch between child buses.
MUX children are registered as MDIO buses and they can be used just like regular MDIOs.
---
Changes in v2:
- no change
Changes in v3:
- no change, just fighting with the email server
Changes in v4:
- fixed a couple of typos
Changes in v5:
- no change
drivers/net/Kconfig | 12 +++ include/dm/uclass-id.h | 1 + include/miiphy.h | 20 ++++ net/Makefile | 1 + net/mdio-mux-uclass.c | 232 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 266 insertions(+) create mode 100644 net/mdio-mux-uclass.c
drivers/net/Kconfig +12 -0
@@ -24,6 +24,18 @@ config DM_MDIO This is currently implemented in net/mdio-uclass.c Look in include/miiphy.h for details. +config DM_MDIO_MUX + bool "Enable Driver Model for MDIO MUX devices" + depends on DM_MDIO + help + Enable driver model for MDIO MUX devices + + Adds UCLASS_MDIO_MUX DM class supporting MDIO MUXes. Useful for + systems that support DM_MDIO and integrate one or multiple muxes on + the MDIO bus. + This is currently implemented in net/mdio-mux-uclass.c + Look in include/miiphy.h for details. + config MDIO_SANDBOX depends on DM_MDIO && SANDBOX default y
include/dm/uclass-id.h +1 -0
@@ -59,6 +59,7 @@ enum uclass_id {UCLASS_MAILBOX ,/* Mailbox controller */ UCLASS_MASS_STORAGE ,/* Mass storage device */ UCLASS_MDIO ,/* MDIO bus */ +UCLASS_MDIO_MUX ,/* MDIO MUX/switch */ UCLASS_MISC ,/* Miscellaneous device */ UCLASS_MMC ,/* SD / MMC card or chip */ UCLASS_MOD_EXP, /* RSA Mod Exp device */
include/miiphy.h +20 -0
@@ -167,4 +167,24 @@ struct phy_device *dm_mdio_phy_connect(struct udevice *dev, int addr,#endif +#ifdef CONFIG_DM_MDIO_MUX + +/* indicates none of the child buses is selected */ +#define MDIO_MUX_SELECT_NONE -1 + +/** +* struct mdio_mux_ops - MDIO MUX operations +* +* @select: Selects a child bus +* @deselect: Clean up selection. Optional, can be NULL +*/ +struct mdio_mux_ops { +int (*select)(struct udevice *mux,int cur,int sel); +int (*deselect)(struct udevice *mux,int sel); +}; + +#define mdio_mux_get_ops (dev) ((struct mdio_mux_ops *)(dev)->driver->ops) + +#endif +#endif
net/Makefile +1 -0
@@ -16,6 +16,7 @@ else obj-$(CONFIG_NET) += eth_legacy.o endif obj-$(CONFIG_DM_MDIO) += mdio-uclass.o +obj-$(CONFIG_DM_MDIO_MUX) += mdio-mux-uclass.o obj-$(CONFIG_NET) += eth_common.o obj-$(CONFIG_CMD_LINK_LOCAL) += link_local.o obj-$(CONFIG_NET) += net.o
net/mdio-mux-uclass.c new file +232 -0
232 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v5 2/4 doc: bindings: Add description for MDIO MUX dts nodes
Adds a short bindings document describing the expected structure of a MDIO MUX dts node. This is based on Linux binding and the example is in fact copied from there.
---
Changes in v2:
- no change
Changes in v3:
- no change, just fighting with the email server
Changes in v4:
- pulled in full binding example from Linux, added a note on why mdio-parent-bus is currently required in U-boot but not in Linux
Changes in v5:
- fixed a few typos, a multi-line comment format
doc/device-tree-bindings/net/mdio-mux.txt | 138 ++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 doc/device-tree-bindings/net/mdio-mux.txt
doc/device-tree-bindings/net/mdio-mux.txt new file +138 -0
@@ -0,0 +1,138 @@ +The expected structure of an MDIO MUX device tree node is described here. This +is heavily based on current Linux specification. +One notable difference to Linux is that mdio-parent-bus is currently required +by U-boot, not optional as is in Linux. Current U-boot MDIO MUX udevice class +implementation does not have specific support for MDIOs with an integrated MUX, +the property should be made optional if such support is added. + +The MDIO buses downstream of the MUX should be described in the device tree as +child nodes as indicated below. + +Required properties: +mdio-parent-bus = a phandle to the MDIO bus used to perform actual I/O. This is + typically a real MDIO device, unless there are cascaded MUXes. +#address-cells = <1>, each MDIO group is identified by one 32b value. +#size-cells = <0> + +Other properties: +The properties described here are sufficient for MDIO MUX DM class code, but +MUX drivers may define additional properties, either required or optional. + +Required properties in child nodes: +reg = value to be configured on the MUX to select the respective downstream + MDIO. + +Child nodes should normally contain PHY nodes, referenced by phandle from +ethernet nodes of the eth interfaces using these PHYs. + +Example structure, extracted from Linux bindings document: + + /* The parent MDIO bus. */ + smi1: mdio at 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 at 2 { + reg = <2>; + #address-cells = <1>; + #size-cells = <0>; + phy11: ethernet-phy at 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 at 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 at 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 at 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 at 3 { + reg = <3>; + #address-cells = <1>; + #size-cells = <0>; + phy21: ethernet-phy at 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 at 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 at 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 at 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 */ + }; + }; + };
Signature · 1 line
2.17.1
PATCH v5 2/4 doc: bindings: Add description for MDIO MUX dts nodes
Hi Alex,
Quoted 30 lines · Alex Marginean
Adds a short bindings document describing the expected structure of a MDIO MUX dts node. This is based on Linux binding and the example is in fact copied from there.
Signed-off-by Alex Marginean <[email protected]>Acked-by Joe Hershberger <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Changes in v2:
- no change
Changes in v3:
- no change, just fighting with the email server
Changes in v4:
- pulled in full binding example from Linux, added a note on why mdio-parent-bus is currently required in U-boot but not in Linux
Changes in v5:
- fixed a few typos, a multi-line comment formatdoc/device-tree-bindings/net/mdio-mux.txt | 138 ++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 doc/device-tree-bindings/net/mdio-mux.txtdoc/device-tree-bindings/net/mdio-mux.txt new file +0
-0
doc/device-tree-bindings/net/mdio-mux.txt line 4
Quoted 4 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +4
-0@@ -0,0 +1,138 @@ +The expected structure of an MDIO MUX device tree node is described here. This +is heavily based on current Linux specification. +One notable difference to Linux is that mdio-parent-bus is currently required +by U-boot, not optional as is in Linux. Current U-boot MDIO MUX udevice class
Sorry but I was saying "U-Boot" :) too nitpicking I am :)
[snip]
Regards,
Bin
PATCH v5 2/4 doc: bindings: Add description for MDIO MUX dts nodes
Quoted 28 lines · Bin Meng
Hi Alex,
Quoted 24 lines · Alex Marginean
Adds a short bindings document describing the expected structure of a MDIO MUX dts node. This is based on Linux binding and the example is in fact copied from there.
Signed-off-by Alex Marginean <[email protected]>Acked-by Joe Hershberger <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Changes in v2:
- no change
Changes in v3:
- no change, just fighting with the email server
Changes in v4:
- pulled in full binding example from Linux, added a note on why mdio-parent-bus is currently required in U-boot but not in Linux
Changes in v5:
- fixed a few typos, a multi-line comment formatdoc/device-tree-bindings/net/mdio-mux.txt | 138 ++++++++++++++++++++++ 1 file changed, 138 insertions(+)create mode 100644
doc/device-tree-bindings/net/mdio-mux.txt
Quoted 12 lines
doc/device-tree-bindings/net/mdio-mux.txt line 4
Quoted 10 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +4
-0@@ -0,0 +1,138 @@ +The expected structure of an MDIO MUX device tree node is described here. This +is heavily based on current Linux specification. +One notable difference to Linux is that mdio-parent-bus is currently required +by U-boot, not optional as is in Linux. Current U-boot MDIO MUX udevice classSorry but I was saying "U-Boot" :) too nitpicking I am :)
oops, I'll send a v6 :)
Quoted 6 lines
[snip]
Regards,
Bin
PATCH v5 3/4 test: dm_mdio: add a 2nd register to the emulated PHY
In reply to Alex MargineanThis 2nd register is used by the follow-up MDIO MUX test.
---
Changes in v2:
- no change
Changes in v3:
- no change, just fighting with the email server
Changes in v4:
- no change
Changes in v5:
- no change
drivers/net/mdio_sandbox.c | 16 +++++++++------- test/dm/mdio.c | 3 +++ 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/net/mdio_sandbox.c +9 -7
@@ -9,11 +9,11 @@#include <miiphy.h> #define SANDBOX_PHY_ADDR 5 -#define SANDBOX_PHY_REG 0 +#define SANDBOX_PHY_REG_CNT 2struct mdio_sandbox_priv {int enabled; -u16 reg; +u16 reg[SANDBOX_PHY_REG_CNT ]; };static int mdio_sandbox_read (struct udevice *dev,int addr,int devad,int reg)
@@ -27,10 +27,10 @@ static int mdio_sandbox_read(struct udevice *dev, int addr, int devad, int reg)return -ENODEV ;if (devad !=MDIO_DEVAD_NONE )return -ENODEV ; -if (reg !=SANDBOX_PHY_REG ) +if (reg <0 || reg >SANDBOX_PHY_REG_CNT )return -ENODEV ; -return priv->reg; +return priv->reg[reg]; } static int mdio_sandbox_write(struct udevice *dev, int addr, int devad, int reg,
@@ -45,10 +45,10 @@ static int mdio_sandbox_write(struct udevice *dev, int addr, int devad, int reg,return -ENODEV ;if (devad !=MDIO_DEVAD_NONE )return -ENODEV ; -if (reg !=SANDBOX_PHY_REG ) +if (reg <0 || reg >SANDBOX_PHY_REG_CNT )return -ENODEV ; - priv->reg = val; + priv->reg[reg] = val;return 0 ; }
@@ -56,8 +56,10 @@ static int mdio_sandbox_write(struct udevice *dev, int addr, int devad, int reg,static int mdio_sandbox_reset (struct udevice *dev) {struct mdio_sandbox_priv *priv =dev_get_priv (dev); +int i; - priv->reg =0 ; +for (i =0 ; i <SANDBOX_PHY_REG_CNT ; i++) + priv->reg[i] =0 ;return 0 ; }
test/dm/mdio.c +3 -0
@@ -13,6 +13,9 @@/* macros copied over from mdio_sandbox.c */ #define SANDBOX_PHY_ADDR 5 +#define SANDBOX_PHY_REG_CNT 2 + +/* test using 1st register, 0 */ #define SANDBOX_PHY_REG 0#define TEST_REG_VALUE 0xabcd
Signature · 1 line
2.17.1
PATCH v5 4/4 test: dm: add a test for MDIO MUX DM uclass
In reply to Alex MargineanAdds a test using a makeshift MDIO MUX. The test is based on the existing MDIO test. It uses the last emulated PHY register to verify MUX selection.
---
Changes in v2:
- no change
Changes in v3:
- no change, just fighting with the email server
Changes in v4:
- a more explicit comment on why relative ordering between mdio-test and mdio-mux-test nodes in test.dts matters.
Changes in v5:
- no change
arch/Kconfig | 1 + arch/sandbox/dts/test.dts | 23 +++++++- drivers/net/Kconfig | 10 ++++ drivers/net/Makefile | 1 + drivers/net/mdio_mux_sandbox.c | 97 ++++++++++++++++++++++++++++++++++ test/dm/Makefile | 1 + test/dm/mdio_mux.c | 80 ++++++++++++++++++++++++++++ 7 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 drivers/net/mdio_mux_sandbox.c create mode 100644 test/dm/mdio_mux.c
arch/Kconfig +1 -0
@@ -123,6 +123,7 @@ config SANDBOX imply PCH imply PHYLIB imply DM_MDIO + imply DM_MDIO_MUX config SH bool "SuperH architecture"
arch/sandbox/dts/test.dts +22 -1
@@ -808,7 +808,28 @@ dma-names = "m2m", "tx0", "rx0"; }; - mdio-test { + /* + * keep mdio-mux ahead of mdio so that the mux is removed first at the + * end of the test. If parent mdio is removed first, clean-up of the + * mux will trigger a 2nd probe of parent-mdio, leaving parent-mdio + * active at the end of the test. That it turn doesn't allow the mdio + * class to be destroyed, triggering an error. + */ + mdio-mux-test { + compatible = "sandbox,mdio-mux"; + #address-cells = <1>; + #size-cells = <0>; + mdio-parent-bus = <&mdio>; + + mdio-ch-test at 0 { + reg = <0>; + }; + mdio-ch-test at 1 { + reg = <1>; + }; + }; + + mdio: mdio-test { compatible = "sandbox,mdio"; }; };
drivers/net/Kconfig +10 -0
@@ -46,6 +46,16 @@ config MDIO_SANDBOX This driver is used in for testing in test/dm/mdio.c +config MDIO_MUX_SANDBOX + depends on DM_MDIO_MUX && MDIO_SANDBOX + default y + bool "Sandbox: Mocked MDIO-MUX driver" + help + This driver implements dummy select/deselect ops mimicking a MUX on + the MDIO bux. It uses mdio_sandbox driver as parent MDIO. + + This driver is used for testing in test/dm/mdio.c + menuconfig NETDEVICES bool "Network device support" depends on NET
drivers/net/Makefile +1 -0
@@ -79,3 +79,4 @@ obj-y += mscc_eswitch/ obj-$(CONFIG_HIGMACV300_ETH) += higmacv300.o obj-$(CONFIG_MDIO_SANDBOX) += mdio_sandbox.o obj-$(CONFIG_FSL_ENETC) += fsl_enetc.o fsl_enetc_mdio.o +obj-$(CONFIG_MDIO_MUX_SANDBOX) += mdio_mux_sandbox.o
drivers/net/mdio_mux_sandbox.c new file +97 -0
97 lines not on this page · raw message
test/dm/Makefile +1 -0
@@ -61,4 +61,5 @@ obj-$(CONFIG_TEE) += tee.o obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o obj-$(CONFIG_DMA) += dma.o obj-$(CONFIG_DM_MDIO) += mdio.o +obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o endif
test/dm/mdio_mux.c new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.17.1