From patchwork Mon Jun 22 09:37:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11617803 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06A26618 for ; Mon, 22 Jun 2020 13:51:54 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C1B4020716 for ; Mon, 22 Jun 2020 13:51:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="B3fDl6rD"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="L18aNuz3"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="rox8r/P9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1B4020716 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1paeSoCHPllenqWSkDM/8V8BrVL2ihyg2p9oiLWptsE=; b=B3fDl6rDEwbA+r8iiDF5e2run sjyNDAlVukWue13Tx1dFZb4N4RUvDShnGI41VM9YhRz3chotbDqETTcpy7+prxXmebXfpELcAhS41 QA137365642RajRg/m7z4FIVmriwU9kME14xRMJ7CgiYxI58hKrRCEtY9Ro2s9UTscofLhgVzd6gA ajz0mZW5b19YEFgXX3pr0KT0xrnLONN/9O+iPBpxYdvq+pfr1YbKa9dmnEwps2+1eQZRvKEriQ5lk PBrJKqpiwyYCBsQhe0ptUS5jp3tivwYXfqw4VL3iZsHFEZVTtbNzpVzTZ8XZCXAuk/L1BbT4BnyX3 /lhp5/B+w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnMrX-00044B-2c; Mon, 22 Jun 2020 13:51:51 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnLyF-0005E2-HO for linux-mediatek@merlin.infradead.org; Mon, 22 Jun 2020 12:54:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=39tcT1sImiChTRqBAQCitq8OvfITErWq/Xk+xRkWTtw=; b=L18aNuz378xXP83nMMmSLw+RbM WwIlBEXTGQAfUA1Nyly8W8JvkFWwhdgtgJd/JSogUp+sGOrGvRUfixQ/nyxD3G1cSSUnkkWy1pE7J U+FoY8+30DR4eAXX2CIX9xiywtxsoVQAO5ojJwAjIX7WkJaE1hxp2zLa6PIlgTAWmYBFkCTF868tv 1YgEFlBJCVJPrTuMNDQ4yJL34P+8dtcXAs9wLm0UjyAviNtfsmCX+z9PALrUKX9/pJH0ZqDahMctj CX2pohH/9AW1EVvhY3sNttt+ZnuG0dSrvTkuGcWK4epvn1jDzPE1Jn6ZAb3VldGdDiw+OKzabIQpd 7m2A6KUQ==; Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnIxZ-0004BB-BV for linux-mediatek@lists.infradead.org; Mon, 22 Jun 2020 09:41:52 +0000 Received: by mail-wm1-x343.google.com with SMTP id l17so14221663wmj.0 for ; Mon, 22 Jun 2020 02:41:49 -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=SkWpdFNGvw7mXB5Qg4F6iwS8POELevcPJJYTu+2mv3S1d/I3Owq4SaWWrtIRetRtkZ 1AKmoXo4uDGzUlGGRPBtYVejMpUeqU3Zxe58pTbzR96jGq4tvuQV7hOKzYAlP2s1Z26m j9Qe0dEBSV6Sk6CqfVQ5Q7LsvBJkCgNTNoc7tNztfoc0AvuKek847sGcaarYSWeXwSXC nDFSot7Hu+VBc0uom5Wu8eQc3SVhDOGx4o7cquZq6g2+6zH5IluPQU2h/kg+UL2j0cdo EsF9g0O5yifHBBFpg9Xe3Ni8evY26sw4wS/FJlLpD9zgNlwnvZHNJIqoDwxieuO/VQTR rxcA== X-Gm-Message-State: AOAM5318vptLNR891fnuU32hEMuIuiIvTTpsoF5xAPWmcIOr7YsuuX+n bu0lHIVGhfnIDeusB9Gkc6TeJw== X-Google-Smtp-Source: ABdhPJxuZnlfHnNwpXMmEqVCYAbLPujZmk1SV/mDkcx4Z73yrAJcet27yegyTxUrUHZ6wyfJf9ZIqA== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200622_104149_508323_D3E8549C X-CRM114-Status: GOOD ( 18.07 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:343 listed in] [list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Stephane Le Provost , Bartosz Golaszewski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Fabien Parent , linux-mediatek@lists.infradead.org, Andrew Perepech , Pedro Tsai , linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.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)