From patchwork Mon Jan 19 18:08:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Perier X-Patchwork-Id: 5660201 Return-Path: X-Original-To: patchwork-linux-arm@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 74D36C058D for ; Mon, 19 Jan 2015 18:12:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9CE7820452 for ; Mon, 19 Jan 2015 18:12:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B580C20451 for ; Mon, 19 Jan 2015 18:12:20 +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 1YDGlw-0008MB-QO; Mon, 19 Jan 2015 18:09:56 +0000 Received: from mail-wg0-x22c.google.com ([2a00:1450:400c:c00::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YDGkh-0007lt-Lt; Mon, 19 Jan 2015 18:08:40 +0000 Received: by mail-wg0-f44.google.com with SMTP id y19so33133486wgg.3; Mon, 19 Jan 2015 10:08:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oihEGF/gIOHeHi9TYLkNQR8lGBNmJ8F+o92DlexLYfg=; b=yb1B3H5+kWwLHVpGYIucxIt87Bdjm5iMOiGswJcnDIg8o0N8OXkpe5Je3u67KZLZQW CfHJnd13bU4QfzsJSz8D0QQRy3a3h6T5vMze7FuDcBuTJfV/d0G6niH478B2rVVgTSWy wT0ic2IO11eJ5Xs0S8CARcAqe2yCfym0Todjy5ma9Uel7r4Murfjy+q2G3Y+QDIDhiil NkjG0q1TBPR9L0flXmNKTA8G6pDX+PxRANrzqF7g2mUfP0Pc2UtawPRVk/2HWS8RhpL+ qYXM/JH4tuKe0fsrtk9EFSN/kOATqJkejhajYKaNndPJzKDtsrWg1PGExJf9etiPb24X Djfw== X-Received: by 10.194.108.202 with SMTP id hm10mr63710633wjb.72.1421690897503; Mon, 19 Jan 2015 10:08:17 -0800 (PST) Received: from localhost.localdomain (AToulouse-554-1-139-234.w90-60.abo.wanadoo.fr. [90.60.234.234]) by mx.google.com with ESMTPSA id gf9sm18198011wjc.0.2015.01.19.10.08.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Jan 2015 10:08:16 -0800 (PST) From: Romain Perier To: peppe.cavallaro@st.com Subject: [PATCH v1 3/4] net: stmmac: dwmac-rk: Use standard devicetree property for phy regulator Date: Mon, 19 Jan 2015 18:08:08 +0000 Message-Id: <1421690889-11901-4-git-send-email-romain.perier@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1421690889-11901-1-git-send-email-romain.perier@gmail.com> References: <1421690889-11901-1-git-send-email-romain.perier@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150119_100839_875603_7DB2C889 X-CRM114-Status: GOOD ( 15.00 ) X-Spam-Score: -0.8 (/) Cc: devicetree@vger.kernel.org, heiko@sntech.de, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, roger.chen@rock-chips.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_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 Currently, dwmac-rk uses a custom propety "phy_regulator" to get the name of the right regulator to use to power on or power off the phy. This commit converts the driver to use phy-supply devicetree property and the corresponding API, it cleans the code a bit and make it simpler to maintain. Signed-off-by: Romain Perier --- drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 61 ++++++++------------------ 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index 06e1637..8a8091c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c @@ -32,7 +32,7 @@ struct rk_priv_data { struct platform_device *pdev; int phy_iface; - char regulator[32]; + struct regulator *regulator; bool clk_enabled; bool clock_input; @@ -287,46 +287,25 @@ static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable) static int phy_power_on(struct rk_priv_data *bsp_priv, bool enable) { - struct regulator *ldo; - char *ldostr = bsp_priv->regulator; + struct regulator *ldo = bsp_priv->regulator; int ret; struct device *dev = &bsp_priv->pdev->dev; - if (!ldostr) { - dev_err(dev, "%s: no ldo found\n", __func__); + if (!ldo) { + dev_err(dev, "%s: no regulator found\n", __func__); return -1; } - ldo = regulator_get(NULL, ldostr); - if (!ldo) { - dev_err(dev, "\n%s get ldo %s failed\n", __func__, ldostr); + if (enable) { + ret = regulator_enable(ldo); + if (ret) + dev_err(dev, "%s: fail to enable phy-supply\n", + __func__); } else { - if (enable) { - if (!regulator_is_enabled(ldo)) { - ret = regulator_enable(ldo); - if (ret != 0) - dev_err(dev, "%s: fail to enable %s\n", - __func__, ldostr); - else - dev_info(dev, "turn on ldo done.\n"); - } else { - dev_warn(dev, "%s is enabled before enable", - ldostr); - } - } else { - if (regulator_is_enabled(ldo)) { - ret = regulator_disable(ldo); - if (ret != 0) - dev_err(dev, "%s: fail to disable %s\n", - __func__, ldostr); - else - dev_info(dev, "turn off ldo done.\n"); - } else { - dev_warn(dev, "%s is disabled before disable", - ldostr); - } - } - regulator_put(ldo); + ret = regulator_disable(ldo); + if (ret) + dev_err(dev, "%s: fail to disable phy-supply\n", + __func__); } return 0; @@ -346,14 +325,12 @@ static void *rk_gmac_setup(struct platform_device *pdev) bsp_priv->phy_iface = of_get_phy_mode(dev->of_node); - ret = of_property_read_string(dev->of_node, "phy_regulator", &strings); - if (ret) { - dev_warn(dev, "%s: Can not read property: phy_regulator.\n", - __func__); - } else { - dev_info(dev, "%s: PHY power controlled by regulator(%s).\n", - __func__, strings); - strcpy(bsp_priv->regulator, strings); + bsp_priv->regulator = devm_regulator_get_optional(dev, "phy"); + if (IS_ERR(bsp_priv->regulator)) { + if (PTR_ERR(bsp_priv->regulator) == -EPROBE_DEFER) + return -EPROBE_DEFER; + dev_err(dev, "no regulator found\n"); + bsp_priv->regulator = NULL; } ret = of_property_read_string(dev->of_node, "clock_in_out", &strings);