From patchwork Thu Aug 23 11:41:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sekhar Nori X-Patchwork-Id: 144926 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp76183ljw; Thu, 23 Aug 2018 04:43:41 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZgu36rmaFPnlaxydQDFGzcLYLNWC2zDbtUv3a+o0iSLJepb6oi8xy4plydgExvHlxXcElT X-Received: by 2002:a50:ba59:: with SMTP id 25-v6mr8622045eds.214.1535024621341; Thu, 23 Aug 2018 04:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535024621; cv=none; d=google.com; s=arc-20160816; b=yYmuODP9GF9tymYWhlTPOLdGY59Bg0zDgbGp+ngiIPPa5d+/cLFOCYH1eMzsbDzZPZ nx1Zwtyp9adHCAyM+I+prBcM+WlTotXrTJyLJH5W7Y3rXRXqHdB7aA5XvrtZ22r+3lUH u4B6sX/aytI0rDVJBCABjrdz86vQ4GmaAWym6Z3RQAmVlaN/nGptOQ8FKak2rBkoblDE x/rmN8blUFBe5A7LcJSX1Z190rnYy2D2vsr/EbUJLqdiCu9UTjcoHxuyD9MT9ImxvCT6 pXnydRnxplbA+v47XE8J6LpDvNlNW3rp1yf8GhkUesxfhkXbjEVD7yoV+knA8Dg0PT9r 0J9g== 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=6O5cH6zmB1Hmop5CB7lH02/x6BsHkGG6msAIJOs5VhE=; b=lSUVUCL7PwFm0zoiOds64vgzv8yaG0XnWLtMhypr0HSs+BvXtgM9qwyBaUMxIWkGMf dpP3/Kfu0RfCmZUS9hqjcaCkf7LBty/+HH3agbt+1QCMioSfDb2EtMssShxySIxzyHGi B2iZKMhAG+uz4wE/KhxESlS7bNWBmNm/d1NpWlwz0Qex2lO/NyLVlyCoA+JxSfx0mhU2 U61CGNSsMD24/j2uqOnGe8Cwy4M91O/we8VMMp+SAFKJtsRPYNs5ADx+3DIoM9TfnZ33 AbYk9FzPy9Tqtv4UTeQne66laCd38sv8pe9pMlWst0a/gWp6q/rFL62n6uNqs+sOpiYB O9NQ== 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="PjEB/sIy"; 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 b15-v6si3188274edm.391.2018.08.23.04.43.41; Thu, 23 Aug 2018 04:43:41 -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="PjEB/sIy"; 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 F115BC21DAF; Thu, 23 Aug 2018 11:42:18 +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 8BE15C21F7E; Thu, 23 Aug 2018 11:41:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 362E5C21F7D; Thu, 23 Aug 2018 11:41:43 +0000 (UTC) Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) by lists.denx.de (Postfix) with ESMTPS id 1963AC21EEB for ; Thu, 23 Aug 2018 11:41:39 +0000 (UTC) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id w7NBfaZF113669; Thu, 23 Aug 2018 06:41:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1535024496; bh=EJa0vet0GELEQa9J4G1PpBgctYCRpjdBbLJ9Ul9CXTk=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=PjEB/sIy8PQqZ1PKNf4sPz/+RC0SRsb4HGfeXKxhus63cDLRrfObfUFYLdydfxLmY SoE4J4MYpAyOrbwDiC/Xi6ABbm8iICVRaWUWiMLq3oZXh/OCqkGB2vWe3ECwnReiGi 1J4Or2U/zEwYvK1cBvBakYdoORGN1DCkP/bsKYUw= Received: from DFLE102.ent.ti.com (dfle102.ent.ti.com [10.64.6.23]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w7NBfaVa004720; Thu, 23 Aug 2018 06:41:36 -0500 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE102.ent.ti.com (10.64.6.23) 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:36 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE105.ent.ti.com (10.64.6.26) 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:36 -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 w7NBfWhr003432; Thu, 23 Aug 2018 06:41:34 -0500 From: Sekhar Nori To: Joe Hershberger , Tom Rini , Lokesh Vutla Date: Thu, 23 Aug 2018 17:11:29 +0530 Message-ID: <20180823114131.8684-2-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 1/3] drivers: net: cpsw: add support to update 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 some boards using TI CPSW, it may be possible that PHY address was not latched correctly, and the actual address that the phy responds on is different from that set in device-tree. For example, see this problem report on beaglebone black: https://groups.google.com/d/msg/beagleboard/9mctrG26Mc8/1FuI_i5KW10J Add support to check for this condition and use the detected phy address when its safe to do so. Also, add a public API that exposes the phy address of a given slave. This can be used to update device-tree that is passed to Linux kernel. Signed-off-by: Sekhar Nori Reviewed-by: Tom Rini --- drivers/net/cpsw.c | 29 +++++++++++++++++++++++++++++ include/cpsw.h | 1 + 2 files changed, 30 insertions(+) diff --git a/drivers/net/cpsw.c b/drivers/net/cpsw.c index c31695eba9dd..8e2a48cfd678 100644 --- a/drivers/net/cpsw.c +++ b/drivers/net/cpsw.c @@ -1008,6 +1008,25 @@ static int cpsw_phy_init(struct cpsw_priv *priv, struct cpsw_slave *slave) return 1; } +static void cpsw_phy_addr_update(struct cpsw_priv *priv) +{ + struct cpsw_platform_data *data = &priv->data; + u16 alive = mdio_regs->alive & GENMASK(15, 0); + int active = data->active_slave; + int new_addr = ffs(alive) - 1; + + /* + * If there is only one phy alive and its address does not match + * that of active slave, then phy address can safely be updated. + */ + if (hweight16(alive) == 1 && + data->slave_data[active].phy_addr != new_addr) { + printf("Updated phy address for CPSW#%d, old: %d, new: %d\n", + active, data->slave_data[active].phy_addr, new_addr); + data->slave_data[active].phy_addr = new_addr; + } +} + int _cpsw_register(struct cpsw_priv *priv) { struct cpsw_slave *slave; @@ -1034,6 +1053,9 @@ int _cpsw_register(struct cpsw_priv *priv) } cpsw_mdio_init(priv->dev->name, data->mdio_base, data->mdio_div); + + cpsw_phy_addr_update(priv); + priv->bus = miiphy_get_dev_by_name(priv->dev->name); for_active_slave(slave, priv) cpsw_phy_init(priv, slave); @@ -1458,6 +1480,13 @@ static int cpsw_eth_ofdata_to_platdata(struct udevice *dev) return 0; } +int cpsw_get_slave_phy_addr(struct udevice *dev, int slave) +{ + struct cpsw_priv *priv = dev_get_priv(dev); + struct cpsw_platform_data *data = &priv->data; + + return data->slave_data[slave].phy_addr; +} static const struct udevice_id cpsw_eth_ids[] = { { .compatible = "ti,cpsw" }, diff --git a/include/cpsw.h b/include/cpsw.h index f135e7bfe0cc..9f8ce8850f51 100644 --- a/include/cpsw.h +++ b/include/cpsw.h @@ -54,5 +54,6 @@ struct cpsw_platform_data { int cpsw_register(struct cpsw_platform_data *data); int ti_cm_get_macid(struct udevice *dev, int slave, u8 *mac_addr); +int cpsw_get_slave_phy_addr(struct udevice *dev, int slave); #endif /* _CPSW_H_ */