From patchwork Wed Jun 13 04:37:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Ma X-Patchwork-Id: 928663 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=marvell.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 415Dkv5q1mz9s3C for ; Wed, 13 Jun 2018 14:47:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 72E96C21E52; Wed, 13 Jun 2018 04:47:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=KHOP_BIG_TO_CC autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 5A3C1C21E52; Wed, 13 Jun 2018 04:47:22 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B2677C21E0F; Wed, 13 Jun 2018 04:46:53 +0000 (UTC) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by lists.denx.de (Postfix) with ESMTPS id 0532AC21E79 for ; Wed, 13 Jun 2018 04:46:52 +0000 (UTC) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w5D4jdU5013588; Tue, 12 Jun 2018 21:45:39 -0700 Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 2jjpaps4fs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 12 Jun 2018 21:45:39 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Tue, 12 Jun 2018 21:45:34 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Tue, 12 Jun 2018 21:45:33 -0700 Received: from mshsrv05.marvell.com (unknown [10.38.120.46]) by maili.marvell.com (Postfix) with ESMTP id 781B23F7040; Tue, 12 Jun 2018 21:45:30 -0700 (PDT) From: To: U-Boot Mailing List Date: Wed, 13 Jun 2018 12:37:05 +0800 Message-ID: <1528864626-13340-2-git-send-email-make@marvell.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1528864626-13340-1-git-send-email-make@marvell.com> References: <1528864626-13340-1-git-send-email-make@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-06-13_02:, , signatures=0 X-Proofpoint-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806130055 Cc: Andy Shevchenko , Martyn Welch , Ian Ray , Ken Ma , Eugeniy Paltsev , Michal Simek , Alexander Graf , Joe Hershberger , Wenbin Song , Heinrich Schuchardt , Stefan Roese , judge.packham@gmail.com Subject: [U-Boot] [PATCH v3 1/2] dm: mdio: add a uclass for MDIO X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Ken Ma 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 device tree binding for MDIO bus. Signed-off-by: Ken Ma Reviewed-by: sjg@chromium.org, joe.hershberger@ni.com --- Changes in v3: - Move mdio uclass implementation to driver/net folder; - Replace flat-tree functions with livetree functions and update codes and comments to be consistent with driver-model codes style; - Put struct mii_dev to uclass platdata to avoid the mdio alloc and let driver model framework to alloc the memroy automatically, meanwhile the mii bus link initialization is added, Changes in v2: None MAINTAINERS | 1 + doc/device-tree-bindings/net/mdio-bus.txt | 54 ++++++++++++++ drivers/Kconfig | 2 + drivers/net/Makefile | 1 + drivers/net/mdio/Kconfig | 18 +++++ drivers/net/mdio/Makefile | 6 ++ drivers/net/mdio/mdio-uclass.c | 112 ++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/net/mdio.h | 62 +++++++++++++++++ 9 files changed, 257 insertions(+) create mode 100644 doc/device-tree-bindings/net/mdio-bus.txt create mode 100644 drivers/net/mdio/Kconfig create mode 100644 drivers/net/mdio/Makefile create mode 100644 drivers/net/mdio/mdio-uclass.c create mode 100644 include/net/mdio.h diff --git a/MAINTAINERS b/MAINTAINERS index 642c448..9e1fc83 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -335,6 +335,7 @@ M: Simon Glass S: Maintained T: git git://git.denx.de/u-boot-dm.git F: drivers/core/ +F: drivers/net/mdio/ F: include/dm/ F: test/dm/ diff --git a/doc/device-tree-bindings/net/mdio-bus.txt b/doc/device-tree-bindings/net/mdio-bus.txt new file mode 100644 index 0000000..68d8b25 --- /dev/null +++ b/doc/device-tree-bindings/net/mdio-bus.txt @@ -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@12a200 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "marvell,orion-mdio"; + reg = <0x12a200 0x10>; + mdio-name = "cp0-mdio"; + }; + + cp0_xmdio: mdio@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@0 { + reg = <0>; + }; + }; + + &cp0_xmdio { + phy0: ethernet-phy@0 { + reg = <0>; + }; + + phy8: ethernet-phy@8 { + reg = <8>; + }; + }; diff --git a/drivers/Kconfig b/drivers/Kconfig index 9e21b28..0e0982c 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -54,6 +54,8 @@ source "drivers/mtd/Kconfig" source "drivers/net/Kconfig" +source "drivers/net/mdio/Kconfig" + source "drivers/nvme/Kconfig" source "drivers/pci/Kconfig" diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 584bfdf..1cda03f 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -70,3 +70,4 @@ obj-$(CONFIG_VSC9953) += vsc9953.o obj-$(CONFIG_PIC32_ETH) += pic32_mdio.o pic32_eth.o obj-$(CONFIG_DWC_ETH_QOS) += dwc_eth_qos.o obj-$(CONFIG_FSL_PFE) += pfe_eth/ +obj-$(CONFIG_MDIO) += mdio/ diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig new file mode 100644 index 0000000..533cc4a --- /dev/null +++ b/drivers/net/mdio/Kconfig @@ -0,0 +1,18 @@ +# +# MDIO infrastructure and drivers +# + +menu "MDIO Support" + +config MDIO + bool "Enable MDIO(Management Data Input/Output) 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 diff --git a/drivers/net/mdio/Makefile b/drivers/net/mdio/Makefile new file mode 100644 index 0000000..45ae502 --- /dev/null +++ b/drivers/net/mdio/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2018 Marvell International Ltd. +# Author: Ken Ma + +obj-$(CONFIG_MDIO) += mdio-uclass.o diff --git a/drivers/net/mdio/mdio-uclass.c b/drivers/net/mdio/mdio-uclass.c new file mode 100644 index 0000000..5a23d21 --- /dev/null +++ b/drivers/net/mdio/mdio-uclass.c @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Marvell International Ltd. + * Author: Ken Ma + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +int mdio_mii_bus_get(struct udevice *mdio_dev, struct mii_dev **busp) +{ + *busp = (struct mii_dev *)dev_get_uclass_platdata(mdio_dev); + + return 0; +} + +int mdio_device_get_from_phy(ofnode phy_node, struct udevice **devp) +{ + ofnode mdio_node; + + mdio_node = ofnode_get_parent(phy_node); + return uclass_get_device_by_ofnode(UCLASS_MDIO, mdio_node, devp); +} + +int mdio_mii_bus_get_from_phy(ofnode phy_node, struct mii_dev **busp) +{ + struct udevice *mdio_dev; + int ret; + + ret = mdio_device_get_from_phy(phy_node, &mdio_dev); + if (ret) + return ret; + + *busp = (struct mii_dev *)dev_get_uclass_platdata(mdio_dev); + + return 0; +} + +int mdio_device_get_from_eth(struct udevice *eth, struct udevice **devp) +{ + struct ofnode_phandle_args phy_args; + int ret; + + ret = dev_read_phandle_with_args(eth, "phy", NULL, 0, 0, &phy_args); + if (!ret) + return mdio_device_get_from_phy(phy_args.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 **busp) +{ + struct udevice *mdio_dev; + int ret; + + ret = mdio_device_get_from_eth(eth, &mdio_dev); + if (ret) + return ret; + + if (mdio_dev) + *busp = (struct mii_dev *)dev_get_uclass_platdata(mdio_dev); + else + *busp = NULL; + + return 0; +} + +static int mdio_uclass_pre_probe(struct udevice *dev) +{ + struct mii_dev *bus = (struct mii_dev *)dev_get_uclass_platdata(dev); + const char *name; + + /* initialize mii_dev struct fields */ + INIT_LIST_HEAD(&bus->link); + + name = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), + "mdio-name", NULL); + if (name) + strncpy(bus->name, name, MDIO_NAME_LEN); + + return 0; +} + +static int mdio_uclass_post_probe(struct udevice *dev) +{ + struct mii_dev *bus = (struct mii_dev *)dev_get_uclass_platdata(dev); + + return mdio_register(bus); +} + +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), +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index d7f9df3..504decd 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -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, /* Management Data Input/Output(MDIO) device */ UCLASS_MISC, /* Miscellaneous device */ UCLASS_MMC, /* SD / MMC card or chip */ UCLASS_MOD_EXP, /* RSA Mod Exp device */ diff --git a/include/net/mdio.h b/include/net/mdio.h new file mode 100644 index 0000000..5d8d703 --- /dev/null +++ b/include/net/mdio.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2018 Marvell International Ltd. + * Author: Ken Ma + */ + +#ifndef _MDIO_H_ +#define _MDIO_H_ + +#include /* Because we dereference struct udevice here */ +#include + +/** + * mdio_mii_bus_get() - Get mii bus from mdio udevice + * + * @mdio_dev: mdio udevice + * @busp: returns mii bus + * @returns 0 on success, error code otherwise. + */ +int mdio_mii_bus_get(struct udevice *mdio_dev, struct mii_dev **busp); + +/** + * mdio_device_get_from_phy() - Get the mdio udevice which the phy belongs to + * + * @phy_node: phy node offset + * @devp: returns mdio udevice + * @returns 0 on success, error code otherwise. + */ +int mdio_device_get_from_phy(ofnode 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 + * @busp: returns mii bus + * @returns 0 on success, error code otherwise. + */ +int mdio_mii_bus_get_from_phy(ofnode phy_node, struct mii_dev **busp); + +/** + * 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: returns 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 + * @busp: returns mii bus + * @returns 0 on success, error code otherwise. + */ +int mdio_mii_bus_get_from_eth(struct udevice *eth, struct mii_dev **busp); + +#endif /* _MDIO_H_ */