From patchwork Fri Mar 11 10:55:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caesar Wang X-Patchwork-Id: 8564571 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0C04B9F38C for ; Fri, 11 Mar 2016 10:59:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2D09C2034B for ; Fri, 11 Mar 2016 10:59:00 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A9CA32035E for ; Fri, 11 Mar 2016 10:58:55 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aeKmU-0008EV-W3; Fri, 11 Mar 2016 10:58:54 +0000 Received: from mail-pa0-f65.google.com ([209.85.220.65]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aeKm1-0007jM-Co for linux-rockchip@lists.infradead.org; Fri, 11 Mar 2016 10:58:28 +0000 Received: by mail-pa0-f65.google.com with SMTP id fl4so7993241pad.2 for ; Fri, 11 Mar 2016 02:58:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gO3pl3/qPVL0e+B8GOaAXJS5ZNFJKUlULDt3fRs3VeQ=; b=PULqGTvZuYx9NAynMmiK8JZ+UBa8QZivoKYBnkbTNYSCSldCVlpd5NTyRU81j/MeSs PlDiL2/hM0Xgzk8qmh8brWNcaM6kgGyTr1SY/2R1Bja1XDJ5ikD3+UWOGGDEGql6Xevz drPXCpkYcMB3e5u4haG/28IIF7E2J6NfIXJF/OAyhYryCVYO4SoY0TDkR5UjaWg41iuM JK/ehNidmahG1zZL1HHCD05k2i4gFkQ7uP7vql1rJ9Sl0BjRilL9vcrktgfvwu/OTKiW VKAnfseEh2IFgHnxvDDlPtU1vrm2Aeh7dWYA8FmYTRrazTiqhAzAvHc8U5snyawkQavM xEvg== X-Gm-Message-State: AD7BkJK6r14FwVQRsZvGJLDAYm8cp7hqKCWoPb6nW+33VUbBwJVN9y3Yyt4l5Ly6qQgU1A== X-Received: by 10.66.190.40 with SMTP id gn8mr13799796pac.64.1457693886478; Fri, 11 Mar 2016 02:58:06 -0800 (PST) Received: from localhost.localdomain ([58.22.7.114]) by smtp.gmail.com with ESMTPSA id x64sm12042302pfa.72.2016.03.11.02.58.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Mar 2016 02:58:05 -0800 (PST) From: Caesar Wang To: Heiko Stuebner , "David S. Miller" , Rob Herring Subject: [PATCH 3/6] net: arc_emac: support the phy reset for emac driver Date: Fri, 11 Mar 2016 18:55:28 +0800 Message-Id: <1457693731-6966-4-git-send-email-wxt@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1457693731-6966-1-git-send-email-wxt@rock-chips.com> References: <1457693731-6966-1-git-send-email-wxt@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160311_025825_759151_AE024E7C X-CRM114-Status: GOOD ( 13.64 ) X-Spam-Score: -2.4 (--) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexander Kochetkov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, keescook@google.com, leozwang@google.com, Caesar Wang MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds to support the emac phy reset. 1) phy-reset-gpios: The phy-reset-gpios is an optional property for arc emac device tree boot. Change the binding document to match the driver code. 2) phy-reset-duration: Different boards may require different phy reset duration. Add property phy-reset-duration for device tree probe, so that the boards that need a longer reset duration can specify it in their device tree. 3) phy-reset-active-high: We need that for a custom hardware that needs the reverse reset sequence. Of course, this patch will fix the issue on https://patchwork.kernel.org/patch/8186801/. In some cases, the emac couldn't work if you don't have reset the phy. Let's add it to happy work. Signed-off-by: Caesar Wang --- drivers/net/ethernet/arc/emac_main.c | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c index 6446af1..42384f6a 100644 --- a/drivers/net/ethernet/arc/emac_main.c +++ b/drivers/net/ethernet/arc/emac_main.c @@ -764,6 +764,45 @@ static const struct net_device_ops arc_emac_netdev_ops = { #endif }; +#ifdef CONFIG_OF +static void emac_reset_phy(struct net_device *pdev) +{ + int err, phy_reset; + bool active_high = false; + int msec = 10; + struct device *dev = pdev->dev.parent; + struct device_node *np = dev->of_node; + + if (!np) + return; + + of_property_read_u32(np, "phy-reset-duration", &msec); + /* A sane reset duration should not be longer than 1s */ + if (msec > 1000) + msec = 1; + + phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0); + if (!gpio_is_valid(phy_reset)) + return; + + active_high = of_property_read_bool(np, "phy-reset-active-high"); + + err = devm_gpio_request_one(dev, phy_reset, active_high ? + GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW, + "phy-reset"); + if (err) { + dev_err(dev, "failed to get phy-reset-gpios: %d\n", err); + return; + } + msleep(msec); + gpio_set_value_cansleep(phy_reset, !active_high); +} +#else +static void emac_reset_phy(struct platform_device *pdev) +{ +} +#endif /* CONFIG_OF */ + int arc_emac_probe(struct net_device *ndev, int interface) { struct device *dev = ndev->dev.parent; @@ -803,6 +842,8 @@ int arc_emac_probe(struct net_device *ndev, int interface) /* FIXME :: no multicast support yet */ ndev->flags &= ~IFF_MULTICAST; + emac_reset_phy(ndev); + priv = netdev_priv(ndev); priv->dev = dev;