Skip to contentSkip to conversation

Add MDIO driver model support

PATCH Superseded make at marvell.com 3 participants 5 messages Jun 7, 2018 – Jun 12, 2018 Arm (32-bit)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add MDIO driver model support

From: Ken Ma <[email protected]>

Changes in v2:
- Fix error printing:
- Change some debug to pr_err;
- mii bus has no parent member and it is not a udevice, so dev_err is changed to pr_err for mii bus error printings.

Ken Ma (2):
dm: mdio: add a uclass for MDIO
mdio: add marvell MDIO driver

 MAINTAINERS                                    |   2 +
 arch/arm/Kconfig                               |   1 +
 doc/device-tree-bindings/mdio/marvell-mdio.txt |  18 ++
 doc/device-tree-bindings/mdio/mdio-bus.txt     |  54 ++++++
 drivers/Kconfig                                |   2 +
 drivers/Makefile                               |   1 +
 drivers/mdio/Kconfig                           |  28 +++
 drivers/mdio/Makefile                          |   7 +
 drivers/mdio/mdio-uclass.c                     | 119 +++++++++++++
 drivers/mdio/mvmdio.c                          | 237 +++++++++++++++++++++++++
 include/dm/uclass-id.h                         |   1 +
 include/mdio.h                                 |  62 +++++++
 12 files changed, 532 insertions(+)
 create mode 100644 doc/device-tree-bindings/mdio/marvell-mdio.txt
 create mode 100644 doc/device-tree-bindings/mdio/mdio-bus.txt
 create mode 100644 drivers/mdio/Kconfig
 create mode 100644 drivers/mdio/Makefile
 create mode 100644 drivers/mdio/mdio-uclass.c
 create mode 100644 drivers/mdio/mvmdio.c
 create mode 100644 include/mdio.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/2 dm: mdio: add a uclass for MDIO

From: Ken Ma <[email protected]>

Add a uclass which provides access to MDIO busses and includes operations required by MDIO.
The implementation is based on the existing mii/phy/mdio data structures and APIs.
This patch also adds evice tree binding for MDIO bus.

---

Changes in v2: None

 MAINTAINERS                                |   1 +
 doc/device-tree-bindings/mdio/mdio-bus.txt |  54 +++++++++++++
 drivers/Kconfig                            |   2 +
 drivers/Makefile                           |   1 +
 drivers/mdio/Kconfig                       |  18 +++++
 drivers/mdio/Makefile                      |   6 ++
 drivers/mdio/mdio-uclass.c                 | 119 +++++++++++++++++++++++++++++
 include/dm/uclass-id.h                     |   1 +
 include/mdio.h                             |  62 +++++++++++++++
 9 files changed, 264 insertions(+)
 create mode 100644 doc/device-tree-bindings/mdio/mdio-bus.txt
 create mode 100644 drivers/mdio/Kconfig
 create mode 100644 drivers/mdio/Makefile
 create mode 100644 drivers/mdio/mdio-uclass.c
 create mode 100644 include/mdio.h
MAINTAINERS +1 -0
index 642c448..f66a904 100644
@@ -335,6 +335,7 @@ M:	Simon Glass <[email protected]>
 S:	Maintained
 T:	git git://git.denx.de/u-boot-dm.git
 F:	drivers/core/
+F:	drivers/mdio/
 F:	include/dm/
 F:	test/dm/
 
doc/device-tree-bindings/mdio/mdio-bus.txt new file +54 -0

54 lines not on this page · raw message

drivers/Kconfig +2 -0
index 9e21b28..3fc0a90 100644
@@ -44,6 +44,8 @@ source "drivers/led/Kconfig"
 
 source "drivers/mailbox/Kconfig"
 
+source "drivers/mdio/Kconfig"
+
 source "drivers/memory/Kconfig"
 
 source "drivers/misc/Kconfig"
drivers/Makefile +1 -0
index a213ea9..041a7bf 100644
@@ -82,6 +82,7 @@ obj-y += dfu/
 obj-$(CONFIG_X86) += pch/
 obj-y += phy/allwinner/
 obj-y += phy/marvell/
+obj-y += mdio/
 obj-y += rtc/
 obj-y += scsi/
 obj-y += sound/
drivers/mdio/Kconfig new file +18 -0
new file mode 100644
index 0000000..76e3758
@@ -0,0 +1,18 @@
+#
+# MDIO infrastructure and drivers
+#
+
+menu "MDIO Support"
+
+config DM_MDIO
+	bool "Enable Driver Model for MDIO drivers"
+	depends on DM
+	help
+	  Enable driver model for MDIO access.
+	  Drivers provide methods to management data
+	  Input/Output.
+	  MDIO uclass provides interfaces to get mdio
+	  udevice or mii bus from its child phy node or
+	  an ethernet udevice which the phy belongs to.
+
+endmenu
drivers/mdio/Makefile new file +6 -0
new file mode 100644
index 0000000..9b290c0
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2018 Marvell International Ltd.
+# Author: Ken Ma<[email protected]>
+
+obj-$(CONFIG_DM_MDIO) += mdio-uclass.o
drivers/mdio/mdio-uclass.c new file +119 -0

119 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index d7f9df3..170a0cc 100644
@@ -49,6 +49,7 @@ enum uclass_id {
 	UCLASS_LPC,		/* x86 'low pin count' interface */
 	UCLASS_MAILBOX,		/* Mailbox controller */
 	UCLASS_MASS_STORAGE,	/* Mass storage device */
+	UCLASS_MDIO,		/* MDIO device */
 	UCLASS_MISC,		/* Miscellaneous device */
 	UCLASS_MMC,		/* SD / MMC card or chip */
 	UCLASS_MOD_EXP,		/* RSA Mod Exp device */
include/mdio.h new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

PATCH v2 1/2 dm: mdio: add a uclass for MDIO

Hi Ken,

Quoted 13 lines · On 6 June 2018 at 18:08, <[email protected]> wrote:

From: Ken Ma <[email protected]>

Add a uclass which provides access to MDIO busses and includes operations required by MDIO.
The implementation is based on the existing mii/phy/mdio data structures and APIs.
This patch also adds evice tree binding for MDIO bus.

---

Changes in v2: None

Quoted 15 lines
 MAINTAINERS                                |   1 +
 doc/device-tree-bindings/mdio/mdio-bus.txt |  54 +++++++++++++
 drivers/Kconfig                            |   2 +
 drivers/Makefile                           |   1 +
 drivers/mdio/Kconfig                       |  18 +++++
 drivers/mdio/Makefile                      |   6 ++
 drivers/mdio/mdio-uclass.c                 | 119 +++++++++++++++++++++++++++++
 include/dm/uclass-id.h                     |   1 +
 include/mdio.h                             |  62 +++++++++++++++
 9 files changed, 264 insertions(+)
 create mode 100644 doc/device-tree-bindings/mdio/mdio-bus.txt
 create mode 100644 drivers/mdio/Kconfig
 create mode 100644 drivers/mdio/Makefile
 create mode 100644 drivers/mdio/mdio-uclass.c
 create mode 100644 include/mdio.h

When adding a new uclass, please add a sandbox driver and a test in test/dm/mdio.c

drivers/mdio/Kconfig line 7

Quoted 3 lines
drivers/mdio/Kconfig new file +3 -0
+menu "MDIO Support"
+
+config DM_MDIO

I don't see any CONFIG_MDIO option, so you can just make this MDIO. The DM_ prefix is for things that are being converted to driver model, but still have legacy code.

drivers/mdio/Kconfig line 11

Quoted 4 lines
drivers/mdio/Kconfig new file +4 -0
+       bool "Enable Driver Model for MDIO drivers"
+       depends on DM
+       help
+         Enable driver model for MDIO access.

What does MDIO stand for? You should use the full name in help at least once.

Quoted 40 lines
drivers/mdio/Kconfig new file +7 -0
+         Drivers provide methods to management data
+         Input/Output.
+         MDIO uclass provides interfaces to get mdio
+         udevice or mii bus from its child phy node or
+         an ethernet udevice which the phy belongs to.
+
+endmenu
drivers/mdio/Makefile new file +6 -0
new file mode 100644
index 0000000..9b290c0
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2018 Marvell International Ltd.
+# Author: Ken Ma<[email protected]>
+
+obj-$(CONFIG_DM_MDIO) += mdio-uclass.o
drivers/mdio/mdio-uclass.c new file +15 -0
new file mode 100644
index 0000000..251776b
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Marvell International Ltd.
+ * Author: Ken Ma<[email protected]>
+ */
+
+#include <common.h>
+#include <fdtdec.h>
+#include <errno.h>
+#include <dm.h>
+#include <dm/uclass.h>
+#include <dm/uclass-internal.h>
+#include <miiphy.h>
+#include <mdio.h>
+

drivers/mdio/mdio-uclass.c line 25

Quoted 10 lines
drivers/mdio/mdio-uclass.c new file +10 -0
+DECLARE_GLOBAL_DATA_PTR;
+
+int mdio_mii_bus_get(struct udevice *mdio_dev, struct mii_dev **bus)
+{
+       *bus = *(struct mii_dev **)dev_get_uclass_platdata(mdio_dev);
+
+       return 0;
+}
+
+int mdio_device_get_from_phy(int phy_node, struct udevice **devp)

Please can you use livetree functions, like dev_read_...() and ofnode_..() instead the flat-tree functions?

Quoted 8 lines
drivers/mdio/mdio-uclass.c new file +8 -0
+{
+       int mdio_off;
+
+       mdio_off = fdt_parent_offset(gd->fdt_blob, phy_node);
+       return uclass_get_device_by_of_offset(UCLASS_MDIO, mdio_off,
+                                             devp);
+}
+

[..]

drivers/mdio/mdio-uclass.c line 93

Quoted 10 lines
drivers/mdio/mdio-uclass.c new file +10 -0
+static int mdio_uclass_pre_probe(struct udevice *dev)
+{
+       struct mii_dev **pbus = dev_get_uclass_platdata(dev);
+       struct mii_dev *bus;
+       const char *name;
+
+       bus = mdio_alloc();
+       if (!bus) {
+               printf("Failed to allocate MDIO bus @%p\n",
+                      devfdt_get_addr_ptr(dev));

debug()

Quoted 1 line

+ return -1;

Should return a real error, like -ENOMEM

But can you not put struct mii_dev in the private data, to avoid the alloc? If not, you need a remove() method to free this data.

Quoted 30 lines
drivers/mdio/mdio-uclass.c new file +25 -0
+       }
+
+       name = fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
+                          "mdio-name", NULL);
+       if (name)
+               strncpy(bus->name, name, MDIO_NAME_LEN);
+       *pbus = bus;
+
+       return 0;
+}
+
+static int mdio_uclass_post_probe(struct udevice *dev)
+{
+       struct mii_dev **pbus = dev_get_uclass_platdata(dev);
+
+       return mdio_register(*pbus);
+}
+
+UCLASS_DRIVER(mdio) = {
+       .id             = UCLASS_MDIO,
+       .name           = "mdio",
+       .pre_probe      = mdio_uclass_pre_probe,
+       .post_probe     = mdio_uclass_post_probe,
+       .per_device_platdata_auto_alloc_size = sizeof(struct mii_dev *),
+};
include/dm/uclass-id.h +0 -0
index d7f9df3..170a0cc 100644

include/dm/uclass-id.h enum uclass_id { · line 52

Quoted 4 lines
include/dm/uclass-id.h +1 -0
@@ -49,6 +49,7 @@ enum uclass_id {
        UCLASS_LPC,             /* x86 'low pin count' interface */
        UCLASS_MAILBOX,         /* Mailbox controller */
        UCLASS_MASS_STORAGE,    /* Mass storage device */
+       UCLASS_MDIO,            /* MDIO device */

Spell out MDIO if room

Quoted 16 lines
include/dm/uclass-id.h +0 -0
        UCLASS_MISC,            /* Miscellaneous device */
        UCLASS_MMC,             /* SD / MMC card or chip */
        UCLASS_MOD_EXP,         /* RSA Mod Exp device */
include/mdio.h new file +7 -0
new file mode 100644
index 0000000..50458b1
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2018 Marvell International Ltd.
+ * Author: Ken Ma<[email protected]>
+ */
+
+#ifndef _MDIO_H_

include/mdio.h line 17

Quoted 10 lines
include/mdio.h new file +10 -0
+#define _MDIO_H_
+
+#include <dm.h>        /* Because we dereference struct udevice here */
+#include <phy.h>
+
+/**
+ * mdio_mii_bus_get() - Get mii bus from mdio udevice
+ *
+ * @mdio_dev:  mdio udevice
+ * @bus:       mii bus

returns mii bus

Also please can you add a 'p' suffix on pointers that are used to return values.

struct mii_dev **busp

That is consistent with how things are done in the driver-model code.

include/mdio.h line 25

Quoted 8 lines
include/mdio.h new file +8 -0
+ * @returns 0 on success, error code otherwise.
+ */
+int mdio_mii_bus_get(struct udevice *mdio_dev, struct mii_dev **bus);
+
+/**
+ * mdio_device_get_from_phy() - Get the mdio udevice which the phy belongs to
+ *
+ * @phy_node:  phy node offset

Should use ofnode I think, same below

Quoted 11 lines
include/mdio.h new file +11 -0
+ * @devp:      mdio udevice
+ * @returns 0 on success, error code otherwise.
+ */
+int mdio_device_get_from_phy(int phy_node, struct udevice **devp);
+
+/**
+ * mdio_mii_bus_get_from_phy() - Get the mii bus which the phy belongs to
+ *
+ * @phy_node:  phy node offset
+ * @bus:       mii bus
+ * @returns 0 on success, error code otherwise.

include/mdio.h line 46

Quoted 10 lines
include/mdio.h new file +10 -0
+ */
+int mdio_mii_bus_get_from_phy(int phy_node, struct mii_dev **bus);
+
+/**
+ * mdio_device_get_from_eth() - When there is a phy reference of "phy = <&...>"
+ *                      under an ethernet udevice fdt node, this function can
+ *                      get the mdio udevice which the phy belongs to
+ *
+ * @dev:       the ethernet udevice which contains the phy reference
+ * @devp:      mdio udevice

Yes devp is a good name.

Quoted 17 lines
include/mdio.h new file +16 -1
+ * @returns 0 on success, error code otherwise.
+ */
+int mdio_device_get_from_eth(struct udevice *eth, struct udevice **devp);
+
+/**
+ * mdio_mii_bus_get_from_eth() - When there is a phy reference of
+ *                      "phy = <&...>" under an ethernet udevice fdt node, this
+ *                      function can get the mii bus which the phy belongs to
+ *
+ * @eth:       the ethernet udevice which contains the phy reference
+ * @bus:       mii bus
+ * @returns 0 on success, error code otherwise.
+ */
+int mdio_mii_bus_get_from_eth(struct udevice *eth, struct mii_dev **bus);
+
+#endif /* _MDIO_H_ */
--
Quoted 2 lines

1.9.1

Regards,
Simon

#3 lore raw

PATCH v2 1/2 dm: mdio: add a uclass for MDIO

In reply to make at marvell.com

Hi Ken,

Thanks for tackling this.

Quoted 13 lines · On Wed, Jun 6, 2018 at 9:08 PM, <[email protected]> wrote:

From: Ken Ma <[email protected]>

Add a uclass which provides access to MDIO busses and includes operations required by MDIO.
The implementation is based on the existing mii/phy/mdio data structures and APIs.
This patch also adds evice tree binding for MDIO bus.

---

Changes in v2: None

Quoted 7 lines
 MAINTAINERS                                |   1 +
 doc/device-tree-bindings/mdio/mdio-bus.txt |  54 +++++++++++++
 drivers/Kconfig                            |   2 +
 drivers/Makefile                           |   1 +
 drivers/mdio/Kconfig                       |  18 +++++
 drivers/mdio/Makefile                      |   6 ++
 drivers/mdio/mdio-uclass.c                 | 119 +++++++++++++++++++++++++++++

I think this should live in drivers/net. It will pretty much always be implemented by a NIC driver as a subset functionality.

Quoted 354 lines
 include/dm/uclass-id.h                     |   1 +
 include/mdio.h                             |  62 +++++++++++++++
 9 files changed, 264 insertions(+)
 create mode 100644 doc/device-tree-bindings/mdio/mdio-bus.txt
 create mode 100644 drivers/mdio/Kconfig
 create mode 100644 drivers/mdio/Makefile
 create mode 100644 drivers/mdio/mdio-uclass.c
 create mode 100644 include/mdio.h
MAINTAINERS +1 -0
index 642c448..f66a904 100644
@@ -335,6 +335,7 @@ M:  Simon Glass <[email protected]>
 S:     Maintained
 T:     git git://git.denx.de/u-boot-dm.git
 F:     drivers/core/
+F:     drivers/mdio/
 F:     include/dm/
 F:     test/dm/
 
doc/device-tree-bindings/mdio/mdio-bus.txt new file +54 -0
new file mode 100644
index 0000000..68d8b25
@@ -0,0 +1,54 @@
+MDIO (Management Data Input/Output) busses
+
+MDIO busses can be described with a node for the MDIO master device
+and a set of child nodes for each phy on the bus.
+
+The MDIO node requires the following properties:
+- #address-cells  - number of cells required to define phy address on
+                    the MDIO bus.
+- #size-cells     - should be zero.
+- compatible      - name of MDIO bus controller following generic names
+                    recommended practice.
+- reg            - address and length of the MDIO register.
+
+Optional property:
+- mdio-name       - MDIO bus name
+
+The child nodes of the MDIO driver are the individual PHY devices
+connected to this MDIO bus. They must have a "reg" property given the
+PHY address on the MDIO bus.
+- reg             - (required) phy address in MDIO bus.
+
+Example for cp110 MDIO node at the SoC level:
+       cp0_mdio: mdio at 12a200 {
+               #address-cells = <1>;
+               #size-cells = <0>;
+               compatible = "marvell,orion-mdio";
+               reg = <0x12a200 0x10>;
+               mdio-name = "cp0-mdio";
+       };
+
+       cp0_xmdio: mdio at 12a600 {
+               #address-cells = <1>;
+               #size-cells = <0>;
+               compatible = "marvell,xmdio";
+               reg = <0x12a600 0x200>;
+               mdio-name = "cp0-xmdio";
+       };
+
+And at the board level, example for armada-8040-mcbin board:
+       &cp0_mdio {
+               ge_phy: ethernet-phy at 0 {
+                       reg = <0>;
+               };
+       };
+
+       &cp0_xmdio {
+               phy0: ethernet-phy at 0 {
+                       reg = <0>;
+               };
+
+               phy8: ethernet-phy at 8 {
+                       reg = <8>;
+               };
+       };
drivers/Kconfig +2 -0
index 9e21b28..3fc0a90 100644
@@ -44,6 +44,8 @@ source "drivers/led/Kconfig"
 
 source "drivers/mailbox/Kconfig"
 
+source "drivers/mdio/Kconfig"
+
 source "drivers/memory/Kconfig"
 
 source "drivers/misc/Kconfig"
drivers/Makefile +1 -0
index a213ea9..041a7bf 100644
@@ -82,6 +82,7 @@ obj-y += dfu/
 obj-$(CONFIG_X86) += pch/
 obj-y += phy/allwinner/
 obj-y += phy/marvell/
+obj-y += mdio/
 obj-y += rtc/
 obj-y += scsi/
 obj-y += sound/
drivers/mdio/Kconfig new file +18 -0
new file mode 100644
index 0000000..76e3758
@@ -0,0 +1,18 @@
+#
+# MDIO infrastructure and drivers
+#
+
+menu "MDIO Support"
+
+config DM_MDIO
+       bool "Enable Driver Model for MDIO drivers"
+       depends on DM
+       help
+         Enable driver model for MDIO access.
+         Drivers provide methods to management data
+         Input/Output.
+         MDIO uclass provides interfaces to get mdio
+         udevice or mii bus from its child phy node or
+         an ethernet udevice which the phy belongs to.
+
+endmenu
drivers/mdio/Makefile new file +6 -0
new file mode 100644
index 0000000..9b290c0
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2018 Marvell International Ltd.
+# Author: Ken Ma<[email protected]>
+
+obj-$(CONFIG_DM_MDIO) += mdio-uclass.o
drivers/mdio/mdio-uclass.c new file +119 -0
new file mode 100644
index 0000000..251776b
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Marvell International Ltd.
+ * Author: Ken Ma<[email protected]>
+ */
+
+#include <common.h>
+#include <fdtdec.h>
+#include <errno.h>
+#include <dm.h>
+#include <dm/uclass.h>
+#include <dm/uclass-internal.h>
+#include <miiphy.h>
+#include <mdio.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int mdio_mii_bus_get(struct udevice *mdio_dev, struct mii_dev **bus)
+{
+       *bus = *(struct mii_dev **)dev_get_uclass_platdata(mdio_dev);
+
+       return 0;
+}
+
+int mdio_device_get_from_phy(int phy_node, struct udevice **devp)
+{
+       int mdio_off;
+
+       mdio_off = fdt_parent_offset(gd->fdt_blob, phy_node);
+       return uclass_get_device_by_of_offset(UCLASS_MDIO, mdio_off,
+                                             devp);
+}
+
+int mdio_mii_bus_get_from_phy(int phy_node, struct mii_dev **bus)
+{
+       struct udevice *mdio_dev;
+       int ret;
+
+       ret = mdio_device_get_from_phy(phy_node, &mdio_dev);
+       if (ret)
+               return ret;
+
+       *bus = *(struct mii_dev **)dev_get_uclass_platdata(mdio_dev);
+
+       return 0;
+}
+
+int mdio_device_get_from_eth(struct udevice *eth, struct udevice **devp)
+{
+       int dev_node = dev_of_offset(eth);
+       int phy_node;
+
+       phy_node = fdtdec_lookup_phandle(gd->fdt_blob, dev_node, "phy");
+       if (phy_node > 0)
+               return mdio_device_get_from_phy(phy_node, devp);
+
+       /*
+        * If there is no phy reference under the ethernet fdt node,
+        * it is not an error since the ethernet device may do not use
+        * mode; so in this case, the output mdio device pointer is set
+        * as NULL.
+        */
+       *devp = NULL;
+       return 0;
+}
+
+int mdio_mii_bus_get_from_eth(struct udevice *eth, struct mii_dev **bus)
+{
+       struct udevice *mdio_dev;
+       int ret;
+
+       ret = mdio_device_get_from_eth(eth, &mdio_dev);
+       if (ret)
+               return ret;
+
+       if (mdio_dev)
+               *bus = *(struct mii_dev **)dev_get_uclass_platdata(mdio_dev);
+       else
+               *bus = NULL;
+
+       return 0;
+}
+
+static int mdio_uclass_pre_probe(struct udevice *dev)
+{
+       struct mii_dev **pbus = dev_get_uclass_platdata(dev);
+       struct mii_dev *bus;
+       const char *name;
+
+       bus = mdio_alloc();
+       if (!bus) {
+               printf("Failed to allocate MDIO bus @%p\n",
+                      devfdt_get_addr_ptr(dev));
+               return -1;
+       }
+
+       name = fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
+                          "mdio-name", NULL);
+       if (name)
+               strncpy(bus->name, name, MDIO_NAME_LEN);
+       *pbus = bus;
+
+       return 0;
+}
+
+static int mdio_uclass_post_probe(struct udevice *dev)
+{
+       struct mii_dev **pbus = dev_get_uclass_platdata(dev);
+
+       return mdio_register(*pbus);
+}
+
+UCLASS_DRIVER(mdio) = {
+       .id             = UCLASS_MDIO,
+       .name           = "mdio",
+       .pre_probe      = mdio_uclass_pre_probe,
+       .post_probe     = mdio_uclass_post_probe,
+       .per_device_platdata_auto_alloc_size = sizeof(struct mii_dev *),
+};
include/dm/uclass-id.h +1 -0
index d7f9df3..170a0cc 100644
@@ -49,6 +49,7 @@ enum uclass_id {
        UCLASS_LPC,             /* x86 'low pin count' interface */
        UCLASS_MAILBOX,         /* Mailbox controller */
        UCLASS_MASS_STORAGE,    /* Mass storage device */
+       UCLASS_MDIO,            /* MDIO device */
        UCLASS_MISC,            /* Miscellaneous device */
        UCLASS_MMC,             /* SD / MMC card or chip */
        UCLASS_MOD_EXP,         /* RSA Mod Exp device */
include/mdio.h new file +62 -1
new file mode 100644
index 0000000..50458b1
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2018 Marvell International Ltd.
+ * Author: Ken Ma<[email protected]>
+ */
+
+#ifndef _MDIO_H_
+#define _MDIO_H_
+
+#include <dm.h>        /* Because we dereference struct udevice here */
+#include <phy.h>
+
+/**
+ * mdio_mii_bus_get() - Get mii bus from mdio udevice
+ *
+ * @mdio_dev:  mdio udevice
+ * @bus:       mii bus
+ * @returns 0 on success, error code otherwise.
+ */
+int mdio_mii_bus_get(struct udevice *mdio_dev, struct mii_dev **bus);
+
+/**
+ * mdio_device_get_from_phy() - Get the mdio udevice which the phy belongs to
+ *
+ * @phy_node:  phy node offset
+ * @devp:      mdio udevice
+ * @returns 0 on success, error code otherwise.
+ */
+int mdio_device_get_from_phy(int phy_node, struct udevice **devp);
+
+/**
+ * mdio_mii_bus_get_from_phy() - Get the mii bus which the phy belongs to
+ *
+ * @phy_node:  phy node offset
+ * @bus:       mii bus
+ * @returns 0 on success, error code otherwise.
+ */
+int mdio_mii_bus_get_from_phy(int phy_node, struct mii_dev **bus);
+
+/**
+ * mdio_device_get_from_eth() - When there is a phy reference of "phy = <&...>"
+ *                      under an ethernet udevice fdt node, this function can
+ *                      get the mdio udevice which the phy belongs to
+ *
+ * @dev:       the ethernet udevice which contains the phy reference
+ * @devp:      mdio udevice
+ * @returns 0 on success, error code otherwise.
+ */
+int mdio_device_get_from_eth(struct udevice *eth, struct udevice **devp);
+
+/**
+ * mdio_mii_bus_get_from_eth() - When there is a phy reference of
+ *                      "phy = <&...>" under an ethernet udevice fdt node, this
+ *                      function can get the mii bus which the phy belongs to
+ *
+ * @eth:       the ethernet udevice which contains the phy reference
+ * @bus:       mii bus
+ * @returns 0 on success, error code otherwise.
+ */
+int mdio_mii_bus_get_from_eth(struct udevice *eth, struct mii_dev **bus);
+
+#endif /* _MDIO_H_ */
--

1.9.1

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

#4 lore raw

PATCH v2 2/2 mdio: add marvell MDIO driver

In reply to make at marvell.com

From: Ken Ma <[email protected]>

This patch adds a separate driver for the MDIO interface of the Marvell Ethernet controllers based on driver model. There are two reasons to have a separate driver rather than including it inside the MAC driver itself:
*) The MDIO interface is shared by all Ethernet ports, so a driver
must guarantee non-concurrent accesses to this MDIO interface. The most logical way is to have a separate driver that handles this single MDIO interface, used by all Ethernet ports.
*) The MDIO interface is the same between the existing mv643xx_eth
driver and the new mvneta/mvpp2 driver. Even though it is for now only used by the mvneta/mvpp2 driver, it will in the future be used by the mv643xx_eth driver as well.

This driver supports SMI IEEE for 802.3 Clause 22 and XSMI for IEEE 802.3 Clause 45.

This patch also adds device tree binding for marvell MDIO driver.

---

Changes in v2:
- Fix error printing:
- Change some debug to pr_err;
- mii bus has no parent member and it is not a udevice, so dev_err is changed to pr_err for mii bus error printings.

 MAINTAINERS                                    |   1 +
 arch/arm/Kconfig                               |   1 +
 doc/device-tree-bindings/mdio/marvell-mdio.txt |  18 ++
 drivers/mdio/Kconfig                           |  10 ++
 drivers/mdio/Makefile                          |   1 +
 drivers/mdio/mvmdio.c                          | 237 +++++++++++++++++++++++++
 6 files changed, 268 insertions(+)
 create mode 100644 doc/device-tree-bindings/mdio/marvell-mdio.txt
 create mode 100644 drivers/mdio/mvmdio.c
MAINTAINERS +1 -0
index f66a904..fb58f17 100644
@@ -137,6 +137,7 @@ T:	git git://git.denx.de/u-boot-marvell.git
 F:	arch/arm/mach-kirkwood/
 F:	arch/arm/mach-mvebu/
 F:	drivers/ata/ahci_mvebu.c
+F:	drivers/mdio/mvmdio.c
 
 ARM MARVELL PXA
 M:	Marek Vasut <[email protected]>
arch/arm/Kconfig +1 -0
index dde422b..aae4570 100644
@@ -432,6 +432,7 @@ config ARCH_MVEBU
 	select DM_SPI
 	select DM_SPI_FLASH
 	select SPI
+	select DM_MDIO
 
 config TARGET_DEVKIT3250
 	bool "Support devkit3250"
doc/device-tree-bindings/mdio/marvell-mdio.txt new file +18 -0
new file mode 100644
index 0000000..55db435
@@ -0,0 +1,18 @@
+* Marvell MDIO Ethernet Controller interface
+
+The Ethernet controllers of the Marvel Armada 3700 and Armada 7k/8k
+have an identical unit that provides an interface with the MDIO bus.
+This driver handles this MDIO interface.
+
+Mandatory properties:
+SoC specific:
+	- #address-cells: Must be <1>.
+	- #size-cells: Must be <0>.
+	- compatible: Should be "marvell,orion-mdio" (for SMI)
+				"marvell,xmdio"	     (for XSMI)
+	- reg: Base address and size SMI/XMSI bus.
+
+Optional properties:
+	- mdio-name       - MDIO bus name
+
+For example, please refer to "mdio-bus.txt".
drivers/mdio/Kconfig +10 -0
index 76e3758..ce251c5 100644
@@ -15,4 +15,14 @@ config DM_MDIO
 	  udevice or mii bus from its child phy node or
 	  an ethernet udevice which the phy belongs to.
 
+config MVMDIO
+	bool "Marvell MDIO interface support"
+	depends on DM_MDIO
+	select PHYLIB
+	help
+	  This driver supports the MDIO interface found in the network
+	  interface units of the Marvell EBU SoCs (Kirkwood, Orion5x,
+	  Dove, Armada 370, Armada XP, Armada 37xx and Armada7K/8K/8KP).
+
+	  This driver is used by the MVPP2 and MVNETA drivers.
 endmenu
drivers/mdio/Makefile +1 -0
index 9b290c0..9f571aa 100644
@@ -4,3 +4,4 @@
 # Author: Ken Ma<[email protected]>
 
 obj-$(CONFIG_DM_MDIO) += mdio-uclass.o
+obj-$(CONFIG_MVMDIO) += mvmdio.o
drivers/mdio/mvmdio.c new file +237 -0

237 lines not on this page · raw message

Signature · 1 line
1.9.1