Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2609225ybt; Mon, 22 Jun 2020 02:44:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxifWnh1+2Kc/xznFt4VJOxSTfnO0IGNMvhSGWyzKxCu/V2CMWuxtjMaSjB7Cq2/msyK8TY X-Received: by 2002:a17:907:216c:: with SMTP id rl12mr15760402ejb.156.1592819089220; Mon, 22 Jun 2020 02:44:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592819089; cv=none; d=google.com; s=arc-20160816; b=Y3AmzTKiXg0OwzlpqKWdvl4miSyyRh7olVQDIm5bxmhkQoIBsLIk27vrmtPYw/1txA MSHa3oxcLHkWu7J2a9ectYyjBmuUXfQGVhIgmGbPAUMwr9WszmvT3UZQQZwBR2i0QTSf fk/KqRiaUltIigl1bxPhnoDAKO009tvFCbHAcxYgsQEqSU5yLGZoZIP9nepvo644+ULm enUraS3PlHNqAK1v2q6XSA9GDRZX7lWAnwjt7/oYkl2wJ9cdmwVDhDsbTARd9kXgRvSv 5hzHjqdM7DvOZO38q8tvEARsZD3ac9fiDNb0XzBAVML6zZcY8JosmMBXB7v9W3LVJaj0 UoWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=39tcT1sImiChTRqBAQCitq8OvfITErWq/Xk+xRkWTtw=; b=OovlTWsb0ICmt1AXdOk8rfdngEKWrRwroHUHemWD1Fv0eFzs8qP8qOrMuAacQEe0HT w0yBha56Rud+XuSpSF/RYJA7MMxAcUODbf0c8IFSqajbENLR+qiBXetAEoJC7TtkAD7q Rr9WssZtPJybPVDiHMLhl6pEibAfG8a3xdftbkV954Aq+uq7SUgKe6qk+LjIY7KkvS0A JOULNkQcukcgwZSTJECdhf07HZEH50sYfIiJ2vgNv6vcnibQ0tOkBGfD7cqS7knlRg5K fnqF2ujT2Sw9u9mS6K66M20HNqc0x3FzE2YBKoDMG/ydIsAnd20gtzj/VPZC9rvYpni5 BvLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="rox8r/P9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w1si3607779edu.491.2020.06.22.02.44.27; Mon, 22 Jun 2020 02:44:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="rox8r/P9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727817AbgFVJlw (ORCPT + 99 others); Mon, 22 Jun 2020 05:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727807AbgFVJlt (ORCPT ); Mon, 22 Jun 2020 05:41:49 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A80A1C061799 for ; Mon, 22 Jun 2020 02:41:48 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id g75so6115009wme.5 for ; Mon, 22 Jun 2020 02:41:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=39tcT1sImiChTRqBAQCitq8OvfITErWq/Xk+xRkWTtw=; b=rox8r/P9m0M75MrSrW0gaefUbBrzsyQiQQ+nuSUyw7jmgK72RdIrEAET+9NDW80nJV 6NoN3fQgrn8u3TAuYWY9vEZmFhT+PYmy+pixzcxBMoxFYd2WlDCvoisyxCnl9XIvgl4L 2UaUBXGdTuKrvDtQtBHE5L7odP4nDBB7nbDPbFnH6FoanY0lq1FWTQXI+whJq1jJA2hU Ot3SzrgslqAj4dfBjZPmBbOgClucsuSk5FJIDeFu2gEMTSGwLi4/f1DXekQJh5ClPfdx IiB0mjGPZS7Om5sXsEMBsr/HJQuJgLUO0T+W94WaGsZzXwZOeddJTllPhKS2Nil1ZvIb szOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=39tcT1sImiChTRqBAQCitq8OvfITErWq/Xk+xRkWTtw=; b=a2PspAuRrRK48emdX/4aGpFguSf6tBnVb81wdceNgi2FISJdQUp+8SJ7Kfp45y+izQ wwYzliAM4WXvJ3kijTlyOnKG2yYFrq/677N+SVnkWaajPHU78EJCgNuSrZIvJLY2uaNs /7WDAIzZh7qKx8Jv2Powuj381+RfhWgk9uicApEVjV7t9AGV9rKM0sHo1CFq61qfkeUZ E0Fr8fV52+mQ3h5CKr30MdQ8ftA+mtQcnAXRUpNL0wxHZzyXLhA62RDwaxj08SLrVTl3 VrwSkudrnTWsNvc/y6g7dx8WajFcWH+FnIIjGeXR2CM/YSN0uT20GRoJK3ybT0Vh6BmK i6Lw== X-Gm-Message-State: AOAM533HKVHrgOBwAmBL24xmA5FAe0+auEQqO+WZ4NHTubC6Xl3jgd0V pb4nO2c2v/maUETNMjRVuECVqQ== X-Received: by 2002:a1c:2d54:: with SMTP id t81mr18695221wmt.154.1592818907355; Mon, 22 Jun 2020 02:41:47 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id j24sm14392652wrd.43.2020.06.22.02.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 02:41:46 -0700 (PDT) From: Bartosz Golaszewski To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Rob Herring , Matthias Brugger , Microchip Linux Driver Support , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , Vivien Didelot , Tom Lendacky , Yisen Zhuang , Salil Mehta , Jassi Brar , Ilias Apalodimas , Iyappan Subramanian , Keyur Chudgar , Quan Nguyen , Frank Rowand , Philipp Zabel , Liam Girdwood , Mark Brown Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Fabien Parent , Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH 14/15] net: phy: add PHY regulator support Date: Mon, 22 Jun 2020 11:37:43 +0200 Message-Id: <20200622093744.13685-15-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200622093744.13685-1-brgl@bgdev.pl> References: <20200622093744.13685-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski The MDIO sub-system now supports PHY regulators. Let's reuse the code to extend this support over to the PHY device. Signed-off-by: Bartosz Golaszewski --- drivers/net/phy/phy_device.c | 49 ++++++++++++++++++++++++++++-------- include/linux/phy.h | 10 ++++++++ 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 58923826838b..d755adb748a5 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -827,7 +827,12 @@ int phy_device_register(struct phy_device *phydev) err = mdiobus_register_device(&phydev->mdio); if (err) - return err; + goto err_out; + + /* Enable the PHY regulator */ + err = phy_device_power_on(phydev); + if (err) + goto err_unregister_mdio; /* Deassert the reset signal */ phy_device_reset(phydev, 0); @@ -846,22 +851,25 @@ int phy_device_register(struct phy_device *phydev) err = phy_scan_fixups(phydev); if (err) { phydev_err(phydev, "failed to initialize\n"); - goto out; + goto err_reset; } err = device_add(&phydev->mdio.dev); if (err) { phydev_err(phydev, "failed to add\n"); - goto out; + goto err_reset; } return 0; - out: +err_reset: /* Assert the reset signal */ phy_device_reset(phydev, 1); - + /* Disable the PHY regulator */ + phy_device_power_off(phydev); +err_unregister_mdio: mdiobus_unregister_device(&phydev->mdio); +err_out: return err; } EXPORT_SYMBOL(phy_device_register); @@ -883,6 +891,8 @@ void phy_device_remove(struct phy_device *phydev) /* Assert the reset signal */ phy_device_reset(phydev, 1); + /* Disable the PHY regulator */ + phy_device_power_off(phydev); mdiobus_unregister_device(&phydev->mdio); } @@ -1064,6 +1074,11 @@ int phy_init_hw(struct phy_device *phydev) { int ret = 0; + /* Enable the PHY regulator */ + ret = phy_device_power_on(phydev); + if (ret) + return ret; + /* Deassert the reset signal */ phy_device_reset(phydev, 0); @@ -1644,6 +1659,8 @@ void phy_detach(struct phy_device *phydev) /* Assert the reset signal */ phy_device_reset(phydev, 1); + /* Disable the PHY regulator */ + phy_device_power_off(phydev); } EXPORT_SYMBOL(phy_detach); @@ -2684,13 +2701,18 @@ static int phy_probe(struct device *dev) mutex_lock(&phydev->lock); + /* Enable the PHY regulator */ + err = phy_device_power_on(phydev); + if (err) + goto out; + /* Deassert the reset signal */ phy_device_reset(phydev, 0); if (phydev->drv->probe) { err = phydev->drv->probe(phydev); if (err) - goto out; + goto out_reset; } /* Start out supporting everything. Eventually, @@ -2708,7 +2730,7 @@ static int phy_probe(struct device *dev) } if (err) - goto out; + goto out_reset; if (!linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported)) @@ -2751,11 +2773,16 @@ static int phy_probe(struct device *dev) /* Set the state to READY by default */ phydev->state = PHY_READY; -out: - /* Assert the reset signal */ - if (err) - phy_device_reset(phydev, 1); + mutex_unlock(&phydev->lock); + + return 0; +out_reset: + /* Assert the reset signal */ + phy_device_reset(phydev, 1); + /* Disable the PHY regulator */ + phy_device_power_off(phydev); +out: mutex_unlock(&phydev->lock); return err; diff --git a/include/linux/phy.h b/include/linux/phy.h index 01d24a934ad1..585ce8db32cf 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1291,6 +1291,16 @@ static inline void phy_device_reset(struct phy_device *phydev, int value) mdio_device_reset(&phydev->mdio, value); } +static inline int phy_device_power_on(struct phy_device *phydev) +{ + return mdio_device_power_on(&phydev->mdio); +} + +static inline int phy_device_power_off(struct phy_device *phydev) +{ + return mdio_device_power_off(&phydev->mdio); +} + #define phydev_err(_phydev, format, args...) \ dev_err(&_phydev->mdio.dev, format, ##args) -- 2.26.1