From patchwork Thu Aug 23 11:41:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sekhar Nori X-Patchwork-Id: 144924 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp75230ljw; Thu, 23 Aug 2018 04:42:19 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzXiWzuzE0dlotf0A8e/XrTSoZSqvDdOM+1z9jWALB/0hTqVoW+58+hV9aJCLpDn9A0iYHx X-Received: by 2002:a50:9306:: with SMTP id m6-v6mr26078094eda.206.1535024539863; Thu, 23 Aug 2018 04:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535024539; cv=none; d=google.com; s=arc-20160816; b=dbQVoiJyWVqHe8zl7u75aKLXqD0n7je/UJEnVal2A4Jb/N8QY8oSLfF1FFaCsA0z2q erS6n/cBeAsFq7wAzRtnBgAcXTUD6f4DngU8F136uAsJW+PbhreWyZrIau1ZQazl50ai l3AKnXdSlxVL/dwxdrzHEPi9aQqiDnDrOXlBwgodpSu9hCaSvSEMHhSFyG1kwnmTL1x8 iBT5zlqbpLGQCv+JLHBYcb+5MoQycaORKXqYBrzstd8Ls4z2uCaGv8THVSIBcC3FNQaZ RwC26fs3DxgmP3qG/nJ7qA+qWDue8y1yYRibVEge60F9RSe6jHrim8L/r+HPDqMOyct9 o1yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=C1Y4rQjQfU66ZRaoXntHq1xvJ3hj5K0aCWzgSu3oJPw=; b=yEVSTTcobI1VgQMEx/MGjHXr6eD9Jj8IIDp31nafV3qM8GafGdDNnqdv5eApt6rZC5 ATB1e+1ywyfLpdNkrxZ97X6co0+J7917Fq6WhRVhQodPilEyDinsxpSv+NcDmyftMt8/ 9Q5gbP+1F29oV0XTGZjACFHDdAk/eQO6Jv5aUJrCOBeAl7A6JAwaZDOuYkBy2sDIB0Cv 00FNyROZnVcdVn688prux1QOWWF30hVpNjpZLqf03dj8XB5l/2AYIe6Wlmj0XJ/2ThBF /tTNJhNmt7mg9Fdz+A7cfGrYQzo8i+4LY5ZpJzui0mNhU7VnQMCo/Rgulh5/mZcyh+xH Hz3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=LyvYeWPZ; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id v14-v6si432933ede.25.2018.08.23.04.42.19; Thu, 23 Aug 2018 04:42:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=LyvYeWPZ; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: by lists.denx.de (Postfix, from userid 105) id 73CC2C21F1C; Thu, 23 Aug 2018 11:42:01 +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=T_DKIM_INVALID 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 790B5C21F6E; Thu, 23 Aug 2018 11:41:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6FCBCC21F59; Thu, 23 Aug 2018 11:41:43 +0000 (UTC) Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lists.denx.de (Postfix) with ESMTPS id 68EDCC21DAF for ; Thu, 23 Aug 2018 11:41:40 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id w7NBfddo022226; Thu, 23 Aug 2018 06:41:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1535024499; bh=aNDT4oulqMaLT1eCBpsn3gi9OH6f79gEca3JE17CKLI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=LyvYeWPZCMHd8okSrFgh51BLizCDXmfsWC4mCJiyw6afwqOE2kgGqNcTDRi8Sf1h9 zfY322fTbnqmhv3TAAJkU1wajefP2fTaQfAvc2/1666JTtnPFOASSO3Vxf7KDjLi8W KIWHmM5lY15BM7VjOO+emwA0GJmdwK030jkH/Hts= Received: from DLEE106.ent.ti.com (dlee106.ent.ti.com [157.170.170.36]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w7NBfdJh010538; Thu, 23 Aug 2018 06:41:39 -0500 Received: from DLEE100.ent.ti.com (157.170.170.30) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Thu, 23 Aug 2018 06:41:38 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Thu, 23 Aug 2018 06:41:38 -0500 Received: from psplinux063.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w7NBfWhs003432; Thu, 23 Aug 2018 06:41:37 -0500 From: Sekhar Nori To: Joe Hershberger , Tom Rini , Lokesh Vutla Date: Thu, 23 Aug 2018 17:11:30 +0530 Message-ID: <20180823114131.8684-3-nsekhar@ti.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180823114131.8684-1-nsekhar@ti.com> References: <20180823114131.8684-1-nsekhar@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: u-boot@lists.denx.de, William Mills Subject: [U-Boot] [PATCH 2/3] board: ti: am335x: add support to fixup phy address 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" On beaglebone black, it can so happen that PHY address is not latched correctly on reset and board boots with PHY responding to a different address than that programmed in device-tree. For example, see this report: https://groups.google.com/d/msg/beagleboard/9mctrG26Mc8/1FuI_i5KW10J Workaround this by fixing up device-tree passed to kernel by using the PHY address detected in hardware. Beaglebone itself uses only one ethernet port and its DT currently uses phy_id (obsoleted). But the function has been written to handle multiple ports and phy_id as well as phy-handle to make the function more generically useful. Signed-off-by: Sekhar Nori Reviewed-by: Tom Rini --- board/ti/am335x/board.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/board/ti/am335x/board.c b/board/ti/am335x/board.c index a359d20021fd..13845251afb5 100644 --- a/board/ti/am335x/board.c +++ b/board/ti/am335x/board.c @@ -608,6 +608,84 @@ static struct clk_synth cdce913_data = { }; #endif +#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_CONTROL) && \ + defined(CONFIG_DM_ETH) && defined(CONFIG_DRIVER_TI_CPSW) + +#define MAX_CPSW_SLAVES 2 + +/* At the moment, we do not want to stop booting for any failures here */ +int ft_board_setup(void *fdt, bd_t *bd) +{ + const char *slave_path, *enet_name; + int enetnode, slavenode, phynode; + struct udevice *ethdev; + char alias[16]; + u32 phy_id[2]; + int phy_addr; + int i, ret; + + /* phy address fixup needed only on beagle bone family */ + if (!board_is_beaglebonex()) + goto done; + + for (i = 0; i < MAX_CPSW_SLAVES; i++) { + sprintf(alias, "ethernet%d", i); + + slave_path = fdt_get_alias(fdt, alias); + if (!slave_path) + continue; + + slavenode = fdt_path_offset(fdt, slave_path); + if (slavenode < 0) + continue; + + enetnode = fdt_parent_offset(fdt, slavenode); + enet_name = fdt_get_name(fdt, enetnode, NULL); + + ethdev = eth_get_dev_by_name(enet_name); + if (!ethdev) + continue; + + phy_addr = cpsw_get_slave_phy_addr(ethdev, i); + + /* check for phy_id as well as phy-handle properties */ + ret = fdtdec_get_int_array_count(fdt, slavenode, "phy_id", + phy_id, 2); + if (ret == 2) { + if (phy_id[1] != phy_addr) { + printf("fixing up phy_id for %s, old: %d, new: %d\n", + alias, phy_id[1], phy_addr); + + phy_id[0] = cpu_to_fdt32(phy_id[0]); + phy_id[1] = cpu_to_fdt32(phy_addr); + do_fixup_by_path(fdt, slave_path, "phy_id", + phy_id, sizeof(phy_id), 0); + } + } else { + phynode = fdtdec_lookup_phandle(fdt, slavenode, + "phy-handle"); + if (phynode < 0) + continue; + + ret = fdtdec_get_int(fdt, phynode, "reg", -ENOENT); + if (ret < 0) + continue; + + if (ret != phy_addr) { + printf("fixing up phy-handle for %s, old: %d, new: %d\n", + alias, ret, phy_addr); + + fdt_setprop_u32(fdt, phynode, "reg", + cpu_to_fdt32(phy_addr)); + } + } + } + +done: + return 0; +} +#endif + /* * Basic board specific setup. Pinmux has been handled already. */