From patchwork Fri Jul 14 12:55:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Six X-Patchwork-Id: 788483 X-Patchwork-Delegate: mario.six@gdsys.cc Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3x8Cpr4JLjz9s78 for ; Fri, 14 Jul 2017 23:15:16 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5A6DDC21FF6; Fri, 14 Jul 2017 13:01:20 +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.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS 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 277D4C21FC0; Fri, 14 Jul 2017 12:56:22 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 060B8C21FAC; Fri, 14 Jul 2017 12:56:14 +0000 (UTC) Received: from smtprelay04.ispgateway.de (smtprelay04.ispgateway.de [80.67.18.16]) by lists.denx.de (Postfix) with ESMTPS id 00E1DC21F2F for ; Fri, 14 Jul 2017 12:56:08 +0000 (UTC) Received: from [87.191.40.34] (helo=bob3.testumgebung.local) by smtprelay04.ispgateway.de with esmtpa (Exim 4.89) (envelope-from ) id 1dW08d-00062X-EK; Fri, 14 Jul 2017 14:56:07 +0200 From: Mario Six To: U-Boot Mailing List , Simon Glass , Dirk Eibach , Heiko Schocher , Stefan Roese , Joe Hershberger , Tom Rini Date: Fri, 14 Jul 2017 14:55:04 +0200 Message-Id: <20170714125537.14895-19-mario.six@gdsys.cc> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170714125537.14895-1-mario.six@gdsys.cc> References: <20170714125537.14895-1-mario.six@gdsys.cc> X-Df-Sender: bWFyaW8uc2l4QGdkc3lzLmNj Subject: [U-Boot] [PATCH 18/51] cmd: mdio: Add 'driver' subcommand 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" For debug purposes it is sometimes useful to have the ability to interact with the driver functionality of a phy from the command line (e.g. to manually issue startup, configuration, or shutdown commands to the phy device). This patch adds such a command, which allows issuing the following commands to a phy: * getting the driver's name * running the phy's configuration procedure (via calling phy_config) * running the phy's startup procedure (via calling phy_startup) * running the phy's shutdown procedure (via calling phy_shutdown) Signed-off-by: Mario Six --- cmd/Kconfig | 6 ++++++ cmd/mdio.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index 322e466313..6425c425d6 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -835,6 +835,12 @@ config CMD_MII help Enable MII utility commands. +config CMD_MII_DRIVER + bool "mii driver" + depends on CMD_MII + help + Enable MII driver utility command. + config CMD_PING bool "ping" help diff --git a/cmd/mdio.c b/cmd/mdio.c index 3f11963006..abd763ef1c 100644 --- a/cmd/mdio.c +++ b/cmd/mdio.c @@ -180,6 +180,37 @@ static int extract_phy_range(char *const argv[], int argc, struct mii_dev **bus, return extract_range(argv[0], addrlo, addrhi); } +#ifdef CONFIG_CMD_MII_DRIVER +static struct phy_device *extract_phydev(char *const argv[], int argc) +{ + struct phy_device *phydev; + struct mii_dev *bus; + int addr; + + if (argc == 1) { + phydev = mdio_phydev_for_ethname(argv[0]); + + if (phydev) + return phydev; + + bus = mdio_get_current_dev(); + } else { + bus = miiphy_get_dev_by_name(argv[0]); + } + + if (!bus) + return NULL; + + addr = simple_strtol(argv[1], NULL, 0); + if (addr >= PHY_MAX_ADDR) + return NULL; + + phydev = bus->phymap[addr]; + + return phydev; +} +#endif + /* ---------------------------------------------------------------- */ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -212,6 +243,36 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (flag & CMD_FLAG_REPEAT) op[0] = last_op[0]; +#ifdef CONFIG_CMD_MII_DRIVER + if (op[0] == 'd') { + if ((argc < 4) || (argc > 5) || (strlen(argv[2]) < 2)) + return CMD_RET_USAGE; + + phydev = extract_phydev(&argv[3], argc - 3); + if (!phydev) + return CMD_RET_USAGE; + + switch (argv[2][1]) { + case 'e': /* g'e't */ + printf("driver: "); + if (phydev->drv) + printf("%s", phydev->drv->name); + printf("\n"); + break; + case 'o': /* c'o'nfig */ + phy_config(phydev); + break; + case 't': /* s't'artup */ + phy_startup(phydev); + break; + case 'h': /* s'h'utdown */ + phy_shutdown(phydev); + break; + } + return 0; + } +#endif + if (strlen(argv[1]) > 1) { op[1] = argv[1][1]; if (op[1] == 'x') { @@ -304,6 +365,10 @@ U_BOOT_CMD( "read PHY's extended register at .\n" "mdio wx [.] - " "write PHY's extended register at .\n" +#ifdef CONFIG_CMD_MII_DRIVER + "mdio driver - " + " phy driver\n" +#endif " may be:\n" " \n" " \n"