net: add MDIO_MUX DM class
Subsystems (2)
PATCH v3 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
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 v3 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
doc/device-tree-bindings/net/mdio-mux.txt | 61 +++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 doc/device-tree-bindings/net/mdio-mux.txt
doc/device-tree-bindings/net/mdio-mux.txt new file +61 -0
@@ -0,0 +1,61 @@ +The expected structure of an MDIO MUX device tree node is described here. This +is heavily based on current Linux specification. +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>; + 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 */ + }; + }; + }; +
Signature · 1 line
2.17.1
PATCH v3 2/4 doc: bindings: Add description for MDIO MUX dts nodes
Quoted 23 lines · Alexandru 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]>---
Changes in v2:
- no change
Changes in v3:
- no change, just fighting with the email serverdoc/device-tree-bindings/net/mdio-mux.txt | 61 +++++++++++++++++++++++ 1 file changed, 61 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 8
Quoted 8 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +8
-0@@ -0,0 +1,61 @@ +The expected structure of an MDIO MUX device tree node is described here. This +is heavily based on current Linux specification. +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.
In Linux, "mdio-parent-bus" is optional, but in U-Boot this is required?
Quoted 19 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +19
-0+#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";
doc/device-tree-bindings/net/mdio-mux.txt line 37
Quoted 10 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +10
-0+ #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. + */
It looks the example is not complete, which makes it hard for people to understand (ie: only bus 2 is listed below) without reading the Linux bindings doc.
Quoted 14 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +14
-0+ 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>;
doc/device-tree-bindings/net/mdio-mux.txt line 61
Quoted 10 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +10
-0+ 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 */ + }; + }; + }; +
Regards,
Bin
PATCH v3 2/4 doc: bindings: Add description for MDIO MUX dts nodes
Quoted 19 lines · Bin Meng
Quoted 17 lines · Alexandru 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]>---
Changes in v2:
- no change
Changes in v3:
- no change, just fighting with the email serverdoc/device-tree-bindings/net/mdio-mux.txt | 61 +++++++++++++++++++++++ 1 file changed, 61 insertions(+)create mode 100644
doc/device-tree-bindings/net/mdio-mux.txt
Quoted 16 lines
Quoted 6 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +0
-0doc/device-tree-bindings/net/mdio-mux.txt line 8
Quoted 8 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +8
-0@@ -0,0 +1,61 @@ +The expected structure of an MDIO MUX device tree node is described here. This +is heavily based on current Linux specification. +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.In Linux, "mdio-parent-bus" is optional, but in U-Boot this is required?
That was my plan, making it optional requires some extra code that I didn't put in. I could put that code in but it would be unused for now. I can do it, or the change can be done whenever someone adds a MUX which is driven over parent MDIO.
Quoted 25 lines
Quoted 25 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +25
-0+#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>; + }; + + /*
Quoted 8 lines
doc/device-tree-bindings/net/mdio-mux.txt line 37
Quoted 4 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +4
-0+ 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. + */It looks the example is not complete, which makes it hard for people to understand (ie: only bus 2 is listed below) without reading the Linux bindings doc.
I did chop it down to the piece I though it's relevant, I can pull in the full example. Or I can replace it with the definition of the device I'm working on, that way the example is practical. 'mdio-mux-gpio' is not something I was planning to add to u-boot now.
Thank you!
Alex
Quoted 33 lines
Quoted 15 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +14
-0+ 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>;doc/device-tree-bindings/net/mdio-mux.txt line 61
Quoted 10 lines
doc/device-tree-bindings/net/mdio-mux.txt new file +10
-0+ 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 */ + }; + }; + }; +Regards,
Bin
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot
PATCH v3 3/4 test: dm_mdio: add a 2nd register to the emulated PHY
In reply to Alexandru 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
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 v3 3/4 test: dm_mdio: add a 2nd register to the emulated PHY
Quoted 6 lines · Alexandru Marginean
This 2nd register is used by the follow-up MDIO MUX test.
Signed-off-by Alex Marginean <[email protected]>---
Quoted 9 lines
Changes in v2:
- no change
Changes in v3:
- no change, just fighting with the email serverdrivers/net/mdio_sandbox.c | 16 +++++++++------- test/dm/mdio.c | 3 +++ 2 files changed, 12 insertions(+), 7 deletions(-)
PATCH v3 3/4 test: dm_mdio: add a 2nd register to the emulated PHY
In reply to Alexandru MargineanQuoted 4 lines · Alexandru Marginean
This 2nd register is used by the follow-up MDIO MUX test.
Signed-off-by Alex Marginean <[email protected]>
PATCH v3 4/4 test: dm: add a test for MDIO MUX DM uclass
In reply to Alexandru 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
arch/Kconfig | 1 + arch/sandbox/dts/test.dts | 21 +++++++- 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, 210 insertions(+), 1 deletion(-) create mode 100644 drivers/net/mdio_mux_sandbox.c create mode 100644 test/dm/mdio_mux.c
arch/Kconfig +1 -0
@@ -122,6 +122,7 @@ config SANDBOX imply PCH imply PHYLIB imply DM_MDIO + imply DM_MDIO_MUX config SH bool "SuperH architecture"
arch/sandbox/dts/test.dts +20 -1
@@ -808,7 +808,26 @@ dma-names = "m2m", "tx0", "rx0"; }; - mdio-test { + /* + * keep mdio-mux ahead of mdio, u-boot doesn't do reference count on + * these devices and we don't want mdio-parent-bus to be released before + * the mux. + */ + 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
@@ -78,3 +78,4 @@ obj-$(CONFIG_MEDIATEK_ETH) += mtk_eth.o obj-y += mscc_eswitch/ obj-$(CONFIG_HIGMACV300_ETH) += higmacv300.o obj-$(CONFIG_MDIO_SANDBOX) += mdio_sandbox.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
PATCH v3 4/4 test: dm: add a test for MDIO MUX DM uclass
Quoted 40 lines · Alexandru Marginean
Adds 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.
Signed-off-by Alex Marginean <[email protected]>---
Changes in v2:
- no change
Changes in v3:
- no change, just fighting with the email serverarch/Kconfig | 1 + arch/sandbox/dts/test.dts | 21 +++++++- 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, 210 insertions(+), 1 deletion(-) create mode 100644 drivers/net/mdio_mux_sandbox.c create mode 100644 test/dm/mdio_mux.carch/Kconfig +1
-0@@ -122,6 +122,7 @@ config SANDBOX imply PCH imply PHYLIB imply DM_MDIO + imply DM_MDIO_MUX config SH bool "SuperH architecture"arch/sandbox/dts/test.dts +0
-0
arch/sandbox/dts/test.dts line 812
Quoted 6 lines
arch/sandbox/dts/test.dts +2
-1@@ -808,7 +808,26 @@ dma-names = "m2m", "tx0", "rx0"; }; - mdio-test { + /* + * keep mdio-mux ahead of mdio, u-boot doesn't do reference count on
nits: U-Boot
arch/sandbox/dts/test.dts line 814
Quoted 2 lines
arch/sandbox/dts/test.dts +2
-0+ * these devices and we don't want mdio-parent-bus to be released before + * the mux.
I did not get it why there is a ordering issue? Could you please elaborate?
Quoted 5 lines
arch/sandbox/dts/test.dts +5
-0+ */ + mdio-mux-test { + compatible = "sandbox,mdio-mux"; + #address-cells = <1>; + #size-cells = <0>;
arch/sandbox/dts/test.dts line 829
Quoted 10 lines
arch/sandbox/dts/test.dts +10
-0+ mdio-parent-bus = <&mdio>; + + mdio-ch-test at 0 { + reg = <0>; + }; + mdio-ch-test at 1 { + reg = <1>; + }; + }; +
Test codes looks good to me though.
Regards,
Bin
PATCH v3 4/4 test: dm: add a test for MDIO MUX DM uclass
Hi Bin,
Quoted 51 lines · Bin Meng
Quoted 40 lines · Alexandru Marginean
Adds 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.
Signed-off-by Alex Marginean <[email protected]>---
Changes in v2:
- no change
Changes in v3:
- no change, just fighting with the email serverarch/Kconfig | 1 + arch/sandbox/dts/test.dts | 21 +++++++- 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, 210 insertions(+), 1 deletion(-)create mode 100644
drivers/net/mdio_mux_sandbox.ccreate mode 100644test/dm/mdio_mux.carch/Kconfig +1
-0@@ -122,6 +122,7 @@ config SANDBOX imply PCH imply PHYLIB imply DM_MDIO + imply DM_MDIO_MUX config SH bool "SuperH architecture"arch/sandbox/dts/test.dts +0
-0arch/sandbox/dts/test.dts line 812
Quoted 6 lines
arch/sandbox/dts/test.dts +2
-1@@ -808,7 +808,26 @@ dma-names = "m2m", "tx0", "rx0"; }; - mdio-test { + /* + * keep mdio-mux ahead of mdio, u-boot doesn't do reference count onnits: U-Boot
Quoted 4 lines
arch/sandbox/dts/test.dts line 814
Quoted 2 lines
arch/sandbox/dts/test.dts +2
-0+ * these devices and we don't want mdio-parent-bus to be released before + * the mux.I did not get it why there is a ordering issue? Could you please elaborate?
I can try. At the end of 'ut dm' classes and devices are removed, which by itself is fine. When MDIO buses are removed there's a reset issued, which is also fine. There is no explicit dependency between the mux and parent MDIO though, not described in the way that the code removing these devices would understand. If parent MDIO is removed first, then removal/reset of mux child MDIOs triggers a new probe of the parent MDIO device to execute reset on child MDIO buses. This leaves parent MDIO probed at the end of the test and test-main doesn't like that as it can't remove the MDIO class with parent MDIO left active. The call sequence looks like this:
Parent MDIO dev is removed first:dm_mdio_pre_remove: mdio-testmdio_sandbox_reset: mdio-testmdio_sandbox_remove: mdio-test
Then MUX is removed, along with its children:dm_mdio_pre_remove: mdio-ch-test at 0mmux_reset: mdio-mux-test/mdio-ch-test at 0mdio_sandbox_probe: mdio-testdm_mdio_post_probe: mdio-testmdio_sandbox_reset: mdio-testdm_mdio_pre_remove: mdio-ch-test at 1mmux_reset: mdio-mux-test/mdio-ch-test at 1mdio_sandbox_reset: mdio-testtest/dm/test-main.c:72, dm_test_destroy(): 0 == uclass_destroy(uc):
Expected 0, got -22
I think I can add a uclass device post_remove API and use that in MUX uclass to remove parent MDIO device, but that looks like an unsafe thing to do. There is no way for the MUX uclass code to know whether any other piece of software still holds a reference to parent MDIO device.
I could skip calling remove for child MDIOs during removal of the MUX, to avoid probing parent MDIO again, but that looks like a hack.
The fix to the general problem would involve some form of reference counting per device, but it doesn't make sense to add that just for a MDIO MUX test. In practice not removing a device that's no longer used isn't a big deal for u-boot I think.
Keeping dts nodes in that order works, but it is also a hack, it's pretty obscure, I'm not super happy with that either.
Any suggestions?
Thank you!
Alex
Quoted 26 lines
Quoted 6 lines
arch/sandbox/dts/test.dts +5
-0+ */ + mdio-mux-test { + compatible = "sandbox,mdio-mux"; + #address-cells = <1>; + #size-cells = <0>;arch/sandbox/dts/test.dts line 829
Quoted 10 lines
arch/sandbox/dts/test.dts +10
-0+ mdio-parent-bus = <&mdio>; + + mdio-ch-test at 0 { + reg = <0>; + }; + mdio-ch-test at 1 { + reg = <1>; + }; + }; +Test codes looks good to me though.
Regards,
Bin
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot
PATCH v3 1/4 net: add MDIO_MUX DM class
In reply to Alexandru MargineanQuoted 129 lines · Alexandru Marginean
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.Signed-off-by Alex Marginean <[email protected]>---
Changes in v2:
- no change
Changes in v3:
- no change, just fighting with the email serverdrivers/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.cdrivers/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 yinclude/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.onet/mdio-mux-uclass.c new file +23
-0@@ -0,0 +1,232 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* (C) Copyright 2019 +* Alex Marginean, NXP +*/ + +#include <common.h> +#include <dm.h> +#include <miiphy.h> +#include <dm/device-internal.h> +#include <dm/uclass-internal.h> +#include <dm/lists.h> + +#define MDIO_MUX_CHILD_DRV_NAME "mdio-mux-bus-drv" + +/** +* struct mdio_mux_perdev_priv - Per-device class data for MDIO MUX DM +* +* @parent_mdio: Parent DM MDIO device, this is called for actual MDIO I/O after +* setting up the mux. Typically this is a real MDIO device, +* unless there are cascaded muxes. +* @selected: Current child bus selection. Defaults to -1 +*/
net/mdio-mux-uclass.c line 33
Quoted 10 lines
net/mdio-mux-uclass.c new file +10
-0+struct mdio_mux_perdev_priv { +struct udevice *mdio_parent; +int selected; +}; + +/* +* This source file uses three types of devices, as follows: +* - mux is the hardware MDIO MUX which selects between the existing child MDIO +* buses, this is the device relevant for MDIO MUX class of drivers. +* - ch is a child MDIO bus, this is just a representation of an mux selection,
nits: a mux selection
net/mdio-mux-uclass.c line 35
Quoted 2 lines
net/mdio-mux-uclass.c new file +2
-0+* not a real piece of hardware. +* - mdio_parent is the actual MDIO bus called to perform reads/writes after
nits: 2 spaces before "after"
net/mdio-mux-uclass.c line 39
Quoted 4 lines
net/mdio-mux-uclass.c new file +4
-0+* the MUX is configured. Typically this is a real MDIO device, unless there +* are cascaded muxes. +*/ +
[snip]
Other than above,
Regards,
Bin
PATCH v3 1/4 net: add MDIO_MUX DM class
In reply to Alexandru MargineanQuoted 9 lines · Alexandru Marginean
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.Signed-off-by Alex Marginean <[email protected]>
After addressing Bin's comments,