From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5E0AAC433F5 for ; Mon, 9 May 2022 07:50:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=miYM4U5wZJQG4dcGXv6Q55w0F64wYAlogOgY+INvEuw=; b=3bDvm8AyABmnNH kkuFd78W1QjvzRJrL5aCvkQbfWr/R4jsbsk/4wA2IZHctfH/xVQ3CBMWtTBxbeL8O/XoLeTwVEqVR V+2sZ05DIRRB7Mc+D5eoeV1COVTh8533GkLgMKusbey/q/E817Yj8LhP8ocIqswbHpVwTevThNK0s 2psjlbtvCUGe9McIadgoLk61fcSMRDHCHAts2V+YOhoYM23FtsW0OvSSqjU8t9I/f1Ah3duJOzoIv L2FqZWer2NnVCN8Rr1Kq19DoFihvmT8gNvE9oMkg0dEehDLu7CkRTh84kD7eQWtkPY7ccQzBA0abQ e+Rl8Gp7qT67xhVDaNSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nny8q-00CxX8-3d; Mon, 09 May 2022 07:49:16 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nny8k-00CxTH-9g for linux-arm-kernel@lists.infradead.org; Mon, 09 May 2022 07:49:13 +0000 Received: by mail-wr1-x429.google.com with SMTP id t6so18190496wra.4 for ; Mon, 09 May 2022 00:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0WOritaX7TiJ2UopsHt1F9UHI9/f6Pz6lo2giHHHHfc=; b=vLRuZyi6JG45t+95C6Zta3+FYr+M/sDzl2IdgVFDJRasR/zCxX43dHJf6IvPLSvtqr tklZR3oTHy0zplc10ONoKpKCKy119QBEUcXrz1Oo6US9ejSe0sxQ6Vs+zLtR6kmLeO3i vHXOUL9q9mUqXk+bL2tcVuMHUhrZPP1KYRc3NROkD5kFaia7iEggoHtDUbiq9gSA8Y+J iap1VxxsVh2yRdaMG9hDRwZp/j7XRdaA9/AqTBLQ7QaM9NNAG8CzYhhoBTng+EwPHqU/ tyeDLWFLZmElgocGQtR1jrB4ySjno+zMB+m2U/GkDTCt1t2NIE1e2YCxprZnmzodlgTM w1tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0WOritaX7TiJ2UopsHt1F9UHI9/f6Pz6lo2giHHHHfc=; b=7CByO8hf5RGL62yCTy/tZ8Q8orUq2P3chiqNafspPnQS7LAUFB9+ouuSfF8CtAt4oF mAKZeT+6OXlxso2/ih3hkq7IqbJFNpZ/G+2JmC0SqVjsSZnL13EYr8kmA8CLgVD3/TrI 9FGX/bztRmJhmafoOdAa1t9E3dp4Gt8VCiMLvmC5FisFI93BE3EdyeStL3C5ERQOGrb/ oGIbrzXHx11x0YKTqq/aEue4UqVdOimZ1f1gIYrcVikpukHw5RHu8Qb4THmP7g/+LJHf Z4ZpzzDd2L0D/JToqpoM+2F2ubjmNehvSqE/ESIo4lbTe+jjsl/uppEq0itVUFLWWW59 CbOQ== X-Gm-Message-State: AOAM533avfW4uAErnYgZw1lAxH77HS6+gXDTv4Ffoi/1L+ZoClVuVheu qdp68x6KL9joMGktcPKipbeVGQ== X-Google-Smtp-Source: ABdhPJzGdqYQa5SLHwgOMU9gEnMe0J8cSx5N3gasbEOGt8sIW3sW/mNltLBQn2gM6MAQ/S5AV3AtcQ== X-Received: by 2002:a5d:42c8:0:b0:20a:d91f:87b5 with SMTP id t8-20020a5d42c8000000b0020ad91f87b5mr12678734wrr.301.1652082546379; Mon, 09 May 2022 00:49:06 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id bw22-20020a0560001f9600b0020c5253d8d8sm11784768wrb.36.2022.05.09.00.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 00:49:05 -0700 (PDT) From: Corentin Labbe To: alexandre.torgue@foss.st.com, andrew@lunn.ch, broonie@kernel.org, calvin.johnson@oss.nxp.com, davem@davemloft.net, edumazet@google.com, hkallweit1@gmail.com, jernej.skrabec@gmail.com, joabreu@synopsys.com, krzysztof.kozlowski+dt@linaro.org, kuba@kernel.org, lgirdwood@gmail.com, linux@armlinux.org.uk, pabeni@redhat.com, peppe.cavallaro@st.com, robh+dt@kernel.org, samuel@sholland.org, wens@csie.org Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, Corentin Labbe Subject: [PATCH 1/6] phy: handle optional regulator for PHY Date: Mon, 9 May 2022 07:48:52 +0000 Message-Id: <20220509074857.195302-2-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220509074857.195302-1-clabbe@baylibre.com> References: <20220509074857.195302-1-clabbe@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220509_004910_396756_303D9D3D X-CRM114-Status: GOOD ( 14.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add handling of optional regulators for PHY. Regulators need to be enabled before PHY scanning, so MDIO bus initiate this task. Signed-off-by: Corentin Labbe --- drivers/net/mdio/fwnode_mdio.c | 32 ++++++++++++++++++++++++++++++++ drivers/net/phy/phy_device.c | 20 ++++++++++++++++++++ include/linux/phy.h | 3 +++ 3 files changed, 55 insertions(+) diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index 1c1584fca632..c377cadc14c3 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -10,6 +10,7 @@ #include #include #include +#include MODULE_AUTHOR("Calvin Johnson "); MODULE_LICENSE("GPL"); @@ -95,6 +96,8 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, bool is_c45 = false; u32 phy_id; int rc; + struct regulator *regulator_phy; + struct regulator *regulator_phy_io; mii_ts = fwnode_find_mii_timestamper(child); if (IS_ERR(mii_ts)) @@ -104,6 +107,32 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, "ethernet-phy-ieee802.3-c45"); if (rc >= 0) is_c45 = true; + regulator_phy_io = devm_regulator_get_optional(&bus->dev, "phy-io"); + if (IS_ERR(regulator_phy_io)) { + rc = PTR_ERR(regulator_phy_io); + if (rc == -ENODEV) + regulator_phy_io = NULL; + else + return rc; + } + regulator_phy = devm_regulator_get_optional(&bus->dev, "phy"); + if (IS_ERR(regulator_phy)) { + rc = PTR_ERR(regulator_phy); + if (rc == -ENODEV) + regulator_phy = NULL; + else + return rc; + } + if (regulator_phy_io) { + rc = regulator_enable(regulator_phy_io); + if (rc) + return rc; + } + if (regulator_phy) { + rc = regulator_enable(regulator_phy); + if (rc) + return rc; + } if (is_c45 || fwnode_get_phy_id(child, &phy_id)) phy = get_phy_device(bus, addr, is_c45); @@ -114,6 +143,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, return PTR_ERR(phy); } + phy->regulator_phy = regulator_phy; + phy->regulator_phy_io = regulator_phy_io; + if (is_acpi_node(child)) { phy->irq = bus->irq[addr]; diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 431a8719c635..ce64df596580 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -1785,6 +1786,11 @@ int phy_suspend(struct phy_device *phydev) if (!ret) phydev->suspended = true; + if (phydev->regulator_phy) + regulator_disable(phydev->regulator_phy); + if (phydev->regulator_phy_io) + regulator_disable(phydev->regulator_phy_io); + return ret; } EXPORT_SYMBOL(phy_suspend); @@ -1811,6 +1817,20 @@ int phy_resume(struct phy_device *phydev) { int ret; + if (phydev->regulator_phy_io) { + ret = regulator_enable(phydev->regulator_phy_io); + if (ret) + return ret; + } + if (phydev->regulator_phy) { + ret = regulator_enable(phydev->regulator_phy); + if (ret) { + if (phydev->regulator_phy_io) + regulator_disable(phydev->regulator_phy_io); + return ret; + } + } + mutex_lock(&phydev->lock); ret = __phy_resume(phydev); mutex_unlock(&phydev->lock); diff --git a/include/linux/phy.h b/include/linux/phy.h index 2d12054932ba..c29f45668d94 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -704,6 +704,9 @@ struct phy_device { void (*phy_link_change)(struct phy_device *phydev, bool up); void (*adjust_link)(struct net_device *dev); + struct regulator *regulator_phy; + struct regulator *regulator_phy_io; + #if IS_ENABLED(CONFIG_MACSEC) /* MACsec management functions */ const struct macsec_ops *macsec_ops; -- 2.35.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel