From patchwork Sun Mar 13 10:06:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caesar Wang X-Patchwork-Id: 8573521 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 452F6C0553 for ; Sun, 13 Mar 2016 10:06:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4DDFC2028D for ; Sun, 13 Mar 2016 10:06:39 +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 601072022D for ; Sun, 13 Mar 2016 10:06:38 +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 1af2uy-0001XK-Fs; Sun, 13 Mar 2016 10:06:36 +0000 Received: from mail-pf0-f196.google.com ([209.85.192.196]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1af2uv-0001UH-K8 for linux-rockchip@lists.infradead.org; Sun, 13 Mar 2016 10:06:34 +0000 Received: by mail-pf0-f196.google.com with SMTP id u190so7240594pfb.2 for ; Sun, 13 Mar 2016 03:06:13 -0700 (PDT) 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=oKqJC9WqZ23/ddO70xt80hgVNZwWTI3v+POIEydOMhc=; b=miZ+rMfQbQQZwqmAROIvhs9jCRr0BJJm2fnld/eSGSUp2EJAJzx/xvjpSDXOGVgh0A ePvFuP6h4dSZKJdTz39P8CQ1SjpirT48VkgZ5yDNt5rxaq3a0U/JJ4/3nM+cXtpl9iSm Hlts4BDdqUykJN3hCzNopkNB2ZndfxtYGZBAftspRmg/aY4i1GAr4FGKeEGAo18MP5JF aw2Z2xFdNN8yitmcWn8Iuqr2p+LeaoG3+o1DRmgDX6MBTSaBzXbFmn7x1W2OYkRKdOgr y5y6kg67/+544HV4R/D1HxUIWz06wHYW9jCvgVfmZvPhSrmq/v74ZPBSWyE69jyWoWYB hhjQ== X-Gm-Message-State: AD7BkJL42kQ2ztBznquq7PBPhsO8cuIZZMz3mb5FZ9Z3/ns4+Xry3SOCWIlP4Rh5bv3iIw== X-Received: by 10.98.13.130 with SMTP id 2mr21194142pfn.97.1457863572891; Sun, 13 Mar 2016 03:06:12 -0700 (PDT) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id w20sm24452944pfi.31.2016.03.13.03.06.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 13 Mar 2016 03:06:11 -0700 (PDT) From: Caesar Wang To: heiko@sntech.de, davem@davemloft.net, robh+dt@kernel.org Subject: [PATCH v2.1 3/9] net: arc_emac: support the phy reset for emac driver Date: Sun, 13 Mar 2016 18:06:02 +0800 Message-Id: <1457863562-12037-1-git-send-email-wxt@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1457860062-5514-1-git-send-email-wxt@rock-chips.com> References: <1457860062-5514-1-git-send-email-wxt@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160313_030633_705324_F858D49F X-CRM114-Status: GOOD ( 15.51 ) 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: netdev@vger.kernel.org, Caesar Wang , linux-kernel@vger.kernel.org, sergei.shtylyov@cogentembedded.com, linux-rockchip@lists.infradead.org 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. Different boards may require different phy reset duration. Add property phy-reset-duration for emac driver, so that the boards that need a longer reset duration can specify it in their device tree. Signed-off-by: Heiko Stuebner Signed-off-by: Caesar Wang --- Changes in v2.1: - missing the include head file. Changes in v2: - As the pervious version, Sergei and Heiko comments on https://patchwork.kernel.org/patch/8564571/. - Nevermind, add signed-off since Heiko the original patch, refer the Heiko's test patch on https://github.com/mmind/linux-rockchip/commit/a943c588783438ff1c508dfa8c79f1709aa5775e :) drivers/net/ethernet/arc/emac.h | 6 ++++++ drivers/net/ethernet/arc/emac_mdio.c | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/net/ethernet/arc/emac.h b/drivers/net/ethernet/arc/emac.h index dae1ac3..1a40403 100644 --- a/drivers/net/ethernet/arc/emac.h +++ b/drivers/net/ethernet/arc/emac.h @@ -102,6 +102,11 @@ struct buffer_state { DEFINE_DMA_UNMAP_LEN(len); }; +struct arc_emac_mdio_bus_data { + struct gpio_desc *reset_gpio; + int msec; +}; + /** * struct arc_emac_priv - Storage of EMAC's private information. * @dev: Pointer to the current device. @@ -131,6 +136,7 @@ struct arc_emac_priv { struct device *dev; struct phy_device *phy_dev; struct mii_bus *bus; + struct arc_emac_mdio_bus_data bus_data; void __iomem *regs; struct clk *clk; diff --git a/drivers/net/ethernet/arc/emac_mdio.c b/drivers/net/ethernet/arc/emac_mdio.c index d5ee986..0ab62d4 100644 --- a/drivers/net/ethernet/arc/emac_mdio.c +++ b/drivers/net/ethernet/arc/emac_mdio.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "emac.h" @@ -99,6 +100,25 @@ static int arc_mdio_write(struct mii_bus *bus, int phy_addr, } /** + * arc_mdio_reset + * @bus: points to the mii_bus structure + * Description: reset the MII bus + */ +int arc_mdio_reset(struct mii_bus *bus) +{ + struct arc_emac_priv *priv = bus->priv; + struct arc_emac_mdio_bus_data *data = &priv->bus_data; + + if (data->reset_gpio) { + gpiod_set_value_cansleep(data->reset_gpio, 1); + msleep(data->msec); + gpiod_set_value_cansleep(data->reset_gpio, 0); + } + + return 0; +} + +/** * arc_mdio_probe - MDIO probe function. * @priv: Pointer to ARC EMAC private data structure. * @@ -109,6 +129,8 @@ static int arc_mdio_write(struct mii_bus *bus, int phy_addr, */ int arc_mdio_probe(struct arc_emac_priv *priv) { + struct arc_emac_mdio_bus_data *data = &priv->bus_data; + struct device_node *np = priv->dev->of_node; struct mii_bus *bus; int error; @@ -122,6 +144,21 @@ int arc_mdio_probe(struct arc_emac_priv *priv) bus->name = "Synopsys MII Bus", bus->read = &arc_mdio_read; bus->write = &arc_mdio_write; + bus->reset = &arc_mdio_reset; + + /* optional reset-related properties */ + data->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset", + GPIOD_OUT_LOW); + if (IS_ERR(data->reset_gpio)) { + error = PTR_ERR(data->reset_gpio); + dev_err(priv->dev, "Failed to request gpio: %d\n", error); + return error; + } + + of_property_read_u32(np, "phy-reset-duration", &data->msec); + /* A sane reset duration should not be longer than 1s */ + if (data->msec > 1000) + data->msec = 1; snprintf(bus->id, MII_BUS_ID_SIZE, "%s", bus->name);