Add MDIO driver model support
cover Add MDIO driver model support
From: Ken Ma <[email protected]>
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
PATCH 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.
---
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH 2/2 mdio: add marvell MDIO driver
In reply to make at marvell.comFrom: 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.
---
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH 2/2 mdio: add marvell MDIO driver
Hi Ken,
Quoted 2 lines · On Wed, Jun 6, 2018 at 8:06 PM <[email protected]> wrote:
From: Ken Ma <[email protected]>
aside, awesome email address for someone in embedded development :)
Some minor comments below
Quoted 4 lines
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:
Quoted 8 lines
*) 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 existingmv643xx_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 themv643xx_ethdriver as well.
Yay.
In u-boot mv643xx_eth is mvgbe.c. I've been looking at converting it to DM but the first problem I hit was the MDIO interface so this is very much welcome. Were you planning on adding an actual mv643xx_eth driver or is that just a copy/paste from Linux?
Quoted 148 lines
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.
Signed-off-by Ken Ma <[email protected]>---
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.cMAINTAINERS +1
-0@@ -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@@ -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@@ -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@@ -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. endmenudrivers/mdio/Makefile +1
-0@@ -4,3 +4,4 @@ # Author: Ken Ma<[email protected]> obj-$(CONFIG_DM_MDIO) += mdio-uclass.o +obj-$(CONFIG_MVMDIO) += mvmdio.odrivers/mdio/mvmdio.c new file +47
-0@@ -0,0 +1,237 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2018 Marvell International Ltd. +* Author: Ken Ma<[email protected]> +*/ + +#include <common.h> +#include <dm.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <miiphy.h> +#include <phy.h> +#include <asm/io.h> + +DECLARE_GLOBAL_DATA_PTR ; + +#define MVMDIO_SMI_DATA_SHIFT 0 +#define MVMDIO_SMI_PHY_ADDR_SHIFT 16 +#define MVMDIO_SMI_PHY_REG_SHIFT 21 +#define MVMDIO_SMI_READ_OPERATION BIT(26) +#define MVMDIO_SMI_WRITE_OPERATION 0 +#define MVMDIO_SMI_READ_VALID BIT(27) +#define MVMDIO_SMI_BUSY BIT(28) + +#define MVMDIO_XSMI_MGNT_REG 0x0 +#define MVMDIO_XSMI_PHYADDR_SHIFT 16 +#define MVMDIO_XSMI_DEVADDR_SHIFT 21 +#define MVMDIO_XSMI_WRITE_OPERATION (0x5 << 26) +#define MVMDIO_XSMI_READ_OPERATION (0x7 << 26) +#define MVMDIO_XSMI_READ_VALID BIT(29) +#define MVMDIO_XSMI_BUSY BIT(30) +#define MVMDIO_XSMI_ADDR_REG 0x8 + +#define MVMDIO_TIMEOUT 10000 + +struct mvmdio_priv { +void *mdio_base; +}; + +enum mvmdio_bus_type { +BUS_TYPE_SMI , +BUS_TYPE_XSMI +}; + +/* Wait for the SMI unit to be ready for another operation */ +static int mvmdio_smi_wait_ready (struct mii_dev *bus) +{
drivers/mdio/mvmdio.c line 57
Quoted 10 lines
drivers/mdio/mvmdio.c new file +10
-0+u32 timeout =MVMDIO_TIMEOUT ; +struct mvmdio_priv *priv = bus->priv; +u32 smi_reg; + +/* Wait till the SMI is not busy */ + do { + /* Read smi register */ + smi_reg = readl(priv->mdio_base); + if (timeout-- == 0) { + debug("Error: SMI busy timeout\n");
Should this be dev_err(bus->parent, ...); ?
Quoted 6 lines
drivers/mdio/mvmdio.c new file +6
-0+return -ETIME ; + } + }while (smi_reg &MVMDIO_SMI_BUSY ); + +return 0 ; +}
drivers/mdio/mvmdio.c line 73
Quoted 10 lines
drivers/mdio/mvmdio.c new file +10
-0+ +static int mvmdio_smi_read (struct mii_dev *bus,int addr, +int devad,int reg) +{ +struct mvmdio_priv *priv = bus->priv; +u32 val; +int ret; + +if (devad !=MDIO_DEVAD_NONE ) +return -EOPNOTSUPP ;
mvgbe has a feature to read back the PHY address via the PHY Address Register which I assume is configureable via hardware strapping. Looks like the Armada-38x has the same feature although the mvneta driver doesn't implement it. Should this new driver include this?
Quoted 47 lines
drivers/mdio/mvmdio.c new file +47
-0+ + ret =mvmdio_smi_wait_ready (bus); +if (ret <0 ) +return ret; + +writel (((addr <<MVMDIO_SMI_PHY_ADDR_SHIFT ) | + (reg <<MVMDIO_SMI_PHY_REG_SHIFT ) | +MVMDIO_SMI_READ_OPERATION ), + priv->mdio_base); + + ret =mvmdio_smi_wait_ready (bus); +if (ret <0 ) +return ret; + + val =readl (priv->mdio_base); +if (!(val &MVMDIO_SMI_READ_VALID )) { +dev_err (bus->parent,"SMI bus read not valid\n" ); +return -ENODEV ; + } + +return val &GENMASK (15 ,0 ); +} + +static int mvmdio_smi_write (struct mii_dev *bus,int addr,int devad, +int reg,u16 value) +{ +struct mvmdio_priv *priv = bus->priv; +int ret; + +if (devad !=MDIO_DEVAD_NONE ) +return -EOPNOTSUPP ; + + ret =mvmdio_smi_wait_ready (bus); +if (ret <0 ) +return ret; + +writel (((addr <<MVMDIO_SMI_PHY_ADDR_SHIFT ) | + (reg <<MVMDIO_SMI_PHY_REG_SHIFT ) | +MVMDIO_SMI_WRITE_OPERATION | + (value <<MVMDIO_SMI_DATA_SHIFT )), + priv->mdio_base); + +return 0 ; +} + +static int mvmdio_xsmi_wait_ready (struct mii_dev *bus) +{
drivers/mdio/mvmdio.c line 130
Quoted 10 lines
drivers/mdio/mvmdio.c new file +10
-0+u32 timeout =MVMDIO_TIMEOUT ; +struct mvmdio_priv *priv = bus->priv; +u32 xsmi_reg; + +/* Wait till the xSMI is not busy */ + do { + /* Read xSMI register */ + xsmi_reg = readl(priv->mdio_base); + if (timeout-- == 0) { + debug("xSMI busy time-out\n");
Should this be dev_err(bus->parent, ...); ?
Quoted 114 lines
drivers/mdio/mvmdio.c new file +107
-1+return -ETIME ; + } + }while (xsmi_reg &MVMDIO_XSMI_BUSY ); + +return 0 ; +} + +static int mvmdio_xsmi_read (struct mii_dev *bus,int addr, +int devad,int reg) +{ +struct mvmdio_priv *priv = bus->priv; +int ret; + +if (devad ==MDIO_DEVAD_NONE ) +return -EOPNOTSUPP ; + + ret =mvmdio_xsmi_wait_ready (bus); +if (ret <0 ) +return ret; + +writel (reg &GENMASK (15 ,0 ), priv->mdio_base +MVMDIO_XSMI_ADDR_REG ); +writel (((addr <<MVMDIO_XSMI_PHYADDR_SHIFT ) | + (devad <<MVMDIO_XSMI_DEVADDR_SHIFT ) | +MVMDIO_XSMI_READ_OPERATION ), + priv->mdio_base +MVMDIO_XSMI_MGNT_REG ); + + ret =mvmdio_xsmi_wait_ready (bus); +if (ret <0 ) +return ret; + +if (!(readl (priv->mdio_base +MVMDIO_XSMI_MGNT_REG ) & +MVMDIO_XSMI_READ_VALID )) { +dev_err (bus->parent,"XSMI bus read not valid\n" ); +return -ENODEV ; + } + +return readl (priv->mdio_base +MVMDIO_XSMI_MGNT_REG ) &GENMASK (15 ,0 ); +} + +static int mvmdio_xsmi_write (struct mii_dev *bus,int addr,int devad, +int reg,u16 value) +{ +struct mvmdio_priv *priv = bus->priv; +int ret; + +if (devad ==MDIO_DEVAD_NONE ) +return -EOPNOTSUPP ; + + ret =mvmdio_xsmi_wait_ready (bus); +if (ret <0 ) +return ret; + +writel (reg &GENMASK (15 ,0 ), priv->mdio_base +MVMDIO_XSMI_ADDR_REG ); +writel (((addr <<MVMDIO_XSMI_PHYADDR_SHIFT ) | + (devad <<MVMDIO_XSMI_DEVADDR_SHIFT ) | +MVMDIO_XSMI_WRITE_OPERATION | value), + priv->mdio_base +MVMDIO_XSMI_MGNT_REG ); + +return 0 ; +} + +static int mvmdio_probe (struct udevice *dev) +{ +struct mii_dev **pbus =dev_get_uclass_platdata (dev); +struct mii_dev *bus = *pbus; +struct mvmdio_priv *priv; +enum mvmdio_bus_type type; + + priv =dev_get_priv (dev); + priv->mdio_base = (void *)devfdt_get_addr (dev); + bus->priv = priv; + + type = (enum mvmdio_bus_type )dev_get_driver_data (dev); +switch (type) { +case BUS_TYPE_SMI : + bus->read = mvmdio_smi_read; + bus->write = mvmdio_smi_write; +if (!bus->name) +snprintf (bus->name,MDIO_NAME_LEN , +"orion-mdio.%p" , priv->mdio_base); +break ; +case BUS_TYPE_XSMI : + bus->read = mvmdio_xsmi_read; + bus->write = mvmdio_xsmi_write; +if (!bus->name) +snprintf (bus->name,MDIO_NAME_LEN , +"xmdio.%p" , priv->mdio_base); +break ; + } + +return 0 ; +} + +static const struct udevice_id mvmdio_ids[] = { + { .compatible ="marvell,orion-mdio" , .data =BUS_TYPE_SMI }, + { .compatible ="marvell,xmdio" , .data =BUS_TYPE_XSMI }, + { } +}; + +U_BOOT_DRIVER (mvmdio) = { + .name ="mvmdio" , + .id =UCLASS_MDIO , + .of_match = mvmdio_ids, + .probe = mvmdio_probe, + .priv_auto_alloc_size =sizeof (struct mvmdio_priv ), +}; + --1.9.1
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot
[U-Boot] [EXT] Re: [PATCH 2/2] mdio: add marvell MDIO driver
Hi Chris
Thanks a lot for your detailed review and kind advice!
Please see my inline reply.
Yours,
Ken
________________________________________
From: Chris Packham <[email protected]>
Sent: Wednesday, June 6, 2018 1:52 AM
To: Ken Ma
Cc: u-boot; Prafulla Wadaskar; Luka Perkov; xypron.glpk at gmx.de; Michal Simek; Alexander Graf; Stefan Roese; Eugeniy.Paltsev at synopsys.com
Subject: [EXT] Re: [U-Boot] [PATCH 2/2] mdio: add marvell MDIO driver
External Email
----------------------------------------------------------------------
Hi Ken,
Quoted 2 lines · On Wed, Jun 6, 2018 at 8:06 PM <[email protected]> wrote:
From: Ken Ma <[email protected]>
aside, awesome email address for someone in embedded development :)
Some minor comments below
Quoted 4 lines
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:
Quoted 8 lines
*) 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 existingmv643xx_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 themv643xx_ethdriver as well.
Yay.
In u-boot mv643xx_eth is mvgbe.c. I've been looking at converting it to DM but the first problem I hit was the MDIO interface so this is very much welcome. Were you planning on adding an actual mv643xx_eth driver or is that just a copy/paste from Linux?
[Ken] Sorry, currently we have no such a plan to add DM mv643xx_eth driver. By the way, with new mdio driver on uclass DM, we can support such a case that an ethernet device use a phy which is controlled by another chip's mdio(that's to say, ethernet device registers and the mdio register are not in a range)
Quoted 148 lines
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.
Signed-off-by Ken Ma <[email protected]>---
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.cMAINTAINERS +1
-0@@ -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@@ -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@@ -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@@ -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. endmenudrivers/mdio/Makefile +1
-0@@ -4,3 +4,4 @@ # Author: Ken Ma<[email protected]> obj-$(CONFIG_DM_MDIO) += mdio-uclass.o +obj-$(CONFIG_MVMDIO) += mvmdio.odrivers/mdio/mvmdio.c new file +47
-0@@ -0,0 +1,237 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2018 Marvell International Ltd. +* Author: Ken Ma<[email protected]> +*/ + +#include <common.h> +#include <dm.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <miiphy.h> +#include <phy.h> +#include <asm/io.h> + +DECLARE_GLOBAL_DATA_PTR ; + +#define MVMDIO_SMI_DATA_SHIFT 0 +#define MVMDIO_SMI_PHY_ADDR_SHIFT 16 +#define MVMDIO_SMI_PHY_REG_SHIFT 21 +#define MVMDIO_SMI_READ_OPERATION BIT(26) +#define MVMDIO_SMI_WRITE_OPERATION 0 +#define MVMDIO_SMI_READ_VALID BIT(27) +#define MVMDIO_SMI_BUSY BIT(28) + +#define MVMDIO_XSMI_MGNT_REG 0x0 +#define MVMDIO_XSMI_PHYADDR_SHIFT 16 +#define MVMDIO_XSMI_DEVADDR_SHIFT 21 +#define MVMDIO_XSMI_WRITE_OPERATION (0x5 << 26) +#define MVMDIO_XSMI_READ_OPERATION (0x7 << 26) +#define MVMDIO_XSMI_READ_VALID BIT(29) +#define MVMDIO_XSMI_BUSY BIT(30) +#define MVMDIO_XSMI_ADDR_REG 0x8 + +#define MVMDIO_TIMEOUT 10000 + +struct mvmdio_priv { +void *mdio_base; +}; + +enum mvmdio_bus_type { +BUS_TYPE_SMI , +BUS_TYPE_XSMI +}; + +/* Wait for the SMI unit to be ready for another operation */ +static int mvmdio_smi_wait_ready (struct mii_dev *bus) +{
drivers/mdio/mvmdio.c line 57
Quoted 10 lines
drivers/mdio/mvmdio.c new file +10
-0+u32 timeout =MVMDIO_TIMEOUT ; +struct mvmdio_priv *priv = bus->priv; +u32 smi_reg; + +/* Wait till the SMI is not busy */ + do { + /* Read smi register */ + smi_reg = readl(priv->mdio_base); + if (timeout-- == 0) { + debug("Error: SMI busy timeout\n");
Should this be dev_err(bus->parent, ...); ?
[Ken] Thank you very much, I will update it.
Quoted 6 lines
drivers/mdio/mvmdio.c new file +6
-0+return -ETIME ; + } + }while (smi_reg &MVMDIO_SMI_BUSY ); + +return 0 ; +}
drivers/mdio/mvmdio.c line 73
Quoted 10 lines
drivers/mdio/mvmdio.c new file +10
-0+ +static int mvmdio_smi_read (struct mii_dev *bus,int addr, +int devad,int reg) +{ +struct mvmdio_priv *priv = bus->priv; +u32 val; +int ret; + +if (devad !=MDIO_DEVAD_NONE ) +return -EOPNOTSUPP ;
mvgbe has a feature to read back the PHY address via the PHY Address Register which I assume is configureable via hardware strapping. Looks like the Armada-38x has the same feature although the mvneta driver doesn't implement it. Should this new driver include this?
[Ken] I just checked it and in my opinion, we should not include it in mdio driver, the function belongs to network driver
since ethernet port can read its phy address register(this register belongs to ethernet registers range) to get its phy address.
And although an ethernet device can have a member which points to the mdio bus of its phy, but a mdio bus should not have a member which points to an ethernet device, for example, a mdio bus can have several phys, phy0 belongs to ethnet device 0, phy1 belongs to ethnet device 1, phy2 belongs to ethnet device 2...
in mvgbe.c
static int smi_reg_read(struct mii_dev *bus, int phy_adr, int devad,
49 int reg_ofs)
50 {
51 u16 data = 0; 52 struct eth_device *dev = eth_get_dev_by_name(bus->name); ### this is not right, a mii bus can have several phys which are used by several ethernet devices 53 struct mvgbe_device *dmvgbe = to_mvgbe(dev); 54 struct mvgbe_registers *regs = dmvgbe->regs;
Quoted 47 lines
drivers/mdio/mvmdio.c new file +47
-0+ + ret =mvmdio_smi_wait_ready (bus); +if (ret <0 ) +return ret; + +writel (((addr <<MVMDIO_SMI_PHY_ADDR_SHIFT ) | + (reg <<MVMDIO_SMI_PHY_REG_SHIFT ) | +MVMDIO_SMI_READ_OPERATION ), + priv->mdio_base); + + ret =mvmdio_smi_wait_ready (bus); +if (ret <0 ) +return ret; + + val =readl (priv->mdio_base); +if (!(val &MVMDIO_SMI_READ_VALID )) { +dev_err (bus->parent,"SMI bus read not valid\n" ); +return -ENODEV ; + } + +return val &GENMASK (15 ,0 ); +} + +static int mvmdio_smi_write (struct mii_dev *bus,int addr,int devad, +int reg,u16 value) +{ +struct mvmdio_priv *priv = bus->priv; +int ret; + +if (devad !=MDIO_DEVAD_NONE ) +return -EOPNOTSUPP ; + + ret =mvmdio_smi_wait_ready (bus); +if (ret <0 ) +return ret; + +writel (((addr <<MVMDIO_SMI_PHY_ADDR_SHIFT ) | + (reg <<MVMDIO_SMI_PHY_REG_SHIFT ) | +MVMDIO_SMI_WRITE_OPERATION | + (value <<MVMDIO_SMI_DATA_SHIFT )), + priv->mdio_base); + +return 0 ; +} + +static int mvmdio_xsmi_wait_ready (struct mii_dev *bus) +{
drivers/mdio/mvmdio.c line 130
Quoted 10 lines
drivers/mdio/mvmdio.c new file +10
-0+u32 timeout =MVMDIO_TIMEOUT ; +struct mvmdio_priv *priv = bus->priv; +u32 xsmi_reg; + +/* Wait till the xSMI is not busy */ + do { + /* Read xSMI register */ + xsmi_reg = readl(priv->mdio_base); + if (timeout-- == 0) { + debug("xSMI busy time-out\n");
Should this be dev_err(bus->parent, ...); ?
[Ken] Thank you very much, I will update it.
Quoted 114 lines
drivers/mdio/mvmdio.c new file +107
-1+return -ETIME ; + } + }while (xsmi_reg &MVMDIO_XSMI_BUSY ); + +return 0 ; +} + +static int mvmdio_xsmi_read (struct mii_dev *bus,int addr, +int devad,int reg) +{ +struct mvmdio_priv *priv = bus->priv; +int ret; + +if (devad ==MDIO_DEVAD_NONE ) +return -EOPNOTSUPP ; + + ret =mvmdio_xsmi_wait_ready (bus); +if (ret <0 ) +return ret; + +writel (reg &GENMASK (15 ,0 ), priv->mdio_base +MVMDIO_XSMI_ADDR_REG ); +writel (((addr <<MVMDIO_XSMI_PHYADDR_SHIFT ) | + (devad <<MVMDIO_XSMI_DEVADDR_SHIFT ) | +MVMDIO_XSMI_READ_OPERATION ), + priv->mdio_base +MVMDIO_XSMI_MGNT_REG ); + + ret =mvmdio_xsmi_wait_ready (bus); +if (ret <0 ) +return ret; + +if (!(readl (priv->mdio_base +MVMDIO_XSMI_MGNT_REG ) & +MVMDIO_XSMI_READ_VALID )) { +dev_err (bus->parent,"XSMI bus read not valid\n" ); +return -ENODEV ; + } + +return readl (priv->mdio_base +MVMDIO_XSMI_MGNT_REG ) &GENMASK (15 ,0 ); +} + +static int mvmdio_xsmi_write (struct mii_dev *bus,int addr,int devad, +int reg,u16 value) +{ +struct mvmdio_priv *priv = bus->priv; +int ret; + +if (devad ==MDIO_DEVAD_NONE ) +return -EOPNOTSUPP ; + + ret =mvmdio_xsmi_wait_ready (bus); +if (ret <0 ) +return ret; + +writel (reg &GENMASK (15 ,0 ), priv->mdio_base +MVMDIO_XSMI_ADDR_REG ); +writel (((addr <<MVMDIO_XSMI_PHYADDR_SHIFT ) | + (devad <<MVMDIO_XSMI_DEVADDR_SHIFT ) | +MVMDIO_XSMI_WRITE_OPERATION | value), + priv->mdio_base +MVMDIO_XSMI_MGNT_REG ); + +return 0 ; +} + +static int mvmdio_probe (struct udevice *dev) +{ +struct mii_dev **pbus =dev_get_uclass_platdata (dev); +struct mii_dev *bus = *pbus; +struct mvmdio_priv *priv; +enum mvmdio_bus_type type; + + priv =dev_get_priv (dev); + priv->mdio_base = (void *)devfdt_get_addr (dev); + bus->priv = priv; + + type = (enum mvmdio_bus_type )dev_get_driver_data (dev); +switch (type) { +case BUS_TYPE_SMI : + bus->read = mvmdio_smi_read; + bus->write = mvmdio_smi_write; +if (!bus->name) +snprintf (bus->name,MDIO_NAME_LEN , +"orion-mdio.%p" , priv->mdio_base); +break ; +case BUS_TYPE_XSMI : + bus->read = mvmdio_xsmi_read; + bus->write = mvmdio_xsmi_write; +if (!bus->name) +snprintf (bus->name,MDIO_NAME_LEN , +"xmdio.%p" , priv->mdio_base); +break ; + } + +return 0 ; +} + +static const struct udevice_id mvmdio_ids[] = { + { .compatible ="marvell,orion-mdio" , .data =BUS_TYPE_SMI }, + { .compatible ="marvell,xmdio" , .data =BUS_TYPE_XSMI }, + { } +}; + +U_BOOT_DRIVER (mvmdio) = { + .name ="mvmdio" , + .id =UCLASS_MDIO , + .of_match = mvmdio_ids, + .probe = mvmdio_probe, + .priv_auto_alloc_size =sizeof (struct mvmdio_priv ), +}; + --1.9.1
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot