Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp797407iob; Wed, 18 May 2022 13:14:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvxjOty+oNGWKC+wCUTFlglRWdCp+DJj/Jw1+Jeo4TlcGJa7N2wletGH/jxZMaLJCTEw4t X-Received: by 2002:a63:5012:0:b0:3f5:ef64:6557 with SMTP id e18-20020a635012000000b003f5ef646557mr933603pgb.33.1652904844830; Wed, 18 May 2022 13:14:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652904844; cv=none; d=google.com; s=arc-20160816; b=VUSiRU5gSUbp73dfVRegHRqjN+jJdo2+gFvscsIavEqCKE0yGVmJtFiC5BuibIh/zo kLOhiSt0+MdujVdlFmTfHfI42NIrwy5QdcYMriNHtp5WqPC3iTJsY/TsFGa6dhxAHOAU Ls9M+DwzaCRSldvSaNIMKMlP1XDkxyyeh7rYf2xH47ea4cFq6AvQiVHL1h+rQhliwXWJ MH9YuEhpy5gsZtE6jYX/994XsX+8R1mOa+3u3m2+p5DlDa0OqV7BjnCFwsKGhX29dcDd Oppmyj5BHfjLFRn/oARCFf8rm2ZwGitwC+AzVoz+FjfERvAezayzXyXDUIGUVCDDabSI dfiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zWSv1nsIrifugG1nZe+GG3CiYU/pokPOKop6RME5qNI=; b=ggEgczHir1b3XYj0jTU0TXedqtUbrrrBHeXTTtMCrZW92rFAskU7QPrtBppRAbE6M9 TBdZ1UNmhzVJKJcxh30TyBNpomXgsmgsWu5CuqiiGYaET48BfLiebQC6mwHVblCT+ASR Ucf6CJIyfPtDntyxCtK/ycFsxYmsnYXjllbwUzU5QlfjI/bLWW3ed0hyI7CYQEhAyS2t NQ3EMc//mYM+3pznclkDF0kuUoa/I/rb49dGwTj5kNJy0QjpFnugdKaIZW9ExCl6jziD wIeso1VjRhi6S9MFFgFJmuXF9vx4zjlMY7k7MlJllAhR2GEVQX2C23LMZZEq6v+vE52e yIRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=qCU5VnLv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c16-20020a63d150000000b003820b4f8361si3914154pgj.182.2022.05.18.13.14.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:14:04 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=qCU5VnLv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8773F3E5EE; Wed, 18 May 2022 13:10:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242407AbiERUKI (ORCPT + 99 others); Wed, 18 May 2022 16:10:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242364AbiERUKA (ORCPT ); Wed, 18 May 2022 16:10:00 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77FD72375F3 for ; Wed, 18 May 2022 13:09:51 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id j25so4149778wrc.9 for ; Wed, 18 May 2022 13:09:51 -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=zWSv1nsIrifugG1nZe+GG3CiYU/pokPOKop6RME5qNI=; b=qCU5VnLvgmoMb3sOSQ/yF4RotpAJ/DggXO7ITDvwgXeUbi++LQbYCQZVvxAC9EWHYJ Aq60BDj9bXJOIRTA+nNPwZ6iuQYMVUinVtV2xEl7u0NhDY+FdcL+1lUs5E0xAJZ2lGOc jZbWd59afyneSyQLuQmk5EgWYVPDMgInKRMAlVI23UIY343D34oREuXRKZnrUmUJwdqf 91nElBZnYyKcy0ewUU+t1WoWWyBeHW4XnkE65hQj4NLWTS7KQ56VuJe62d89P1iPDt39 5volX/xxiaQoVctOPh19b9jEBOX3pyctNFjSARMLa5VIR/FhqvDlcJF945k6Qklgtt91 mZuw== 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=zWSv1nsIrifugG1nZe+GG3CiYU/pokPOKop6RME5qNI=; b=H0e+DSdhLIyweNNGGWqwf2TbK7ARTwBtDlfNsYT38S54/FncijidpGR4DzqhNAMSu8 Iog4HYfu0RvErdqaHePs35NE0UQshMGPE+wsskDH7LBPcgqww/itw0gFpPUIQk2YqSqR w8M86o3mfvh3Nq3Y5HRe62MCL7aIXL16lc8TS2N2rOwThRl59p1LQjh1YKkMUKbXr2cc aLW771NsJ8kxiuvGPZzm15lc9N+2D438Xwr0qOrs3XlTMEYMfuqhXoSMCuOFqcAVo0LK Q4bNe9Sat/KlLt7u5XmsT0t8g1RlLkVSRAnlZCKqMTL2Y2lYejCIJatS5xixMPoTNjqC XMIQ== X-Gm-Message-State: AOAM532a8ktFnXPbP7nM5ngn/UUhteeAeRdA7JyB3NtiaNP06ygZ4rtM BsiGH0dZ+C4UX0afAQpnor7Agw== X-Received: by 2002:adf:eb82:0:b0:20c:a2eb:5fe6 with SMTP id t2-20020adfeb82000000b0020ca2eb5fe6mr1091386wrn.563.1652904590013; Wed, 18 May 2022 13:09:50 -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 o23-20020a05600c511700b0039456c00ba7sm6859281wms.1.2022.05.18.13.09.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:09:49 -0700 (PDT) From: Corentin Labbe To: andrew@lunn.ch, broonie@kernel.org, calvin.johnson@oss.nxp.com, davem@davemloft.net, edumazet@google.com, hkallweit1@gmail.com, jernej.skrabec@gmail.com, krzysztof.kozlowski+dt@linaro.org, kuba@kernel.org, lgirdwood@gmail.com, linux@armlinux.org.uk, pabeni@redhat.com, robh+dt@kernel.org, samuel@sholland.org, wens@csie.org Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, netdev@vger.kernel.org, Corentin Labbe Subject: [PATCH v2 3/5] phy: handle optional regulator for PHY Date: Wed, 18 May 2022 20:09:37 +0000 Message-Id: <20220518200939.689308-4-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220518200939.689308-1-clabbe@baylibre.com> References: <20220518200939.689308-1-clabbe@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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/Kconfig | 1 + drivers/net/mdio/fwnode_mdio.c | 34 ++++++++++++++++++++++++++++++---- drivers/net/phy/phy_device.c | 10 ++++++++++ include/linux/phy.h | 3 +++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig index bfa16826a6e1..3f8098fac74b 100644 --- a/drivers/net/mdio/Kconfig +++ b/drivers/net/mdio/Kconfig @@ -22,6 +22,7 @@ config MDIO_BUS config FWNODE_MDIO def_tristate PHYLIB depends on (ACPI || OF) || COMPILE_TEST + depends on REGULATOR select FIXED_PHY help FWNODE MDIO bus (Ethernet PHY) accessors diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index 1c1584fca632..c97ccb0863f9 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"); @@ -94,7 +95,10 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, struct phy_device *phy; bool is_c45 = false; u32 phy_id; - int rc; + int rc, reg_cnt = 0; + struct regulator_bulk_data *consumers; + struct device_node *nchild = NULL; + u32 reg; mii_ts = fwnode_find_mii_timestamper(child); if (IS_ERR(mii_ts)) @@ -105,15 +109,33 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, if (rc >= 0) is_c45 = true; + for_each_child_of_node(bus->dev.of_node, nchild) { + of_property_read_u32(nchild, "reg", ®); + if (reg != addr) + continue; + reg_cnt = regulator_bulk_get_all(&bus->dev, nchild, &consumers); + if (reg_cnt > 0) { + rc = regulator_bulk_enable(reg_cnt, consumers); + if (rc) + return rc; + } else { + dev_err(&bus->dev, "Fail to regulator_bulk_get_all err=%d\n", reg_cnt); + } + } + if (is_c45 || fwnode_get_phy_id(child, &phy_id)) phy = get_phy_device(bus, addr, is_c45); else phy = phy_device_create(bus, addr, phy_id, 0, NULL); if (IS_ERR(phy)) { unregister_mii_timestamper(mii_ts); - return PTR_ERR(phy); + rc = PTR_ERR(phy); + goto error; } + phy->regulator_cnt = reg_cnt; + phy->consumers = consumers; + if (is_acpi_node(child)) { phy->irq = bus->irq[addr]; @@ -127,14 +149,14 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, if (rc) { phy_device_free(phy); fwnode_handle_put(phy->mdio.dev.fwnode); - return rc; + goto error; } } else if (is_of_node(child)) { rc = fwnode_mdiobus_phy_device_register(bus, phy, child, addr); if (rc) { unregister_mii_timestamper(mii_ts); phy_device_free(phy); - return rc; + goto error; } } @@ -145,5 +167,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, if (mii_ts) phy->mii_ts = mii_ts; return 0; +error: + if (reg_cnt > 0) + regulator_bulk_disable(reg_cnt, consumers); + return rc; } EXPORT_SYMBOL(fwnode_mdiobus_register_phy); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 431a8719c635..711919e40ef7 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,9 @@ int phy_suspend(struct phy_device *phydev) if (!ret) phydev->suspended = true; + if (phydev->regulator_cnt > 0) + regulator_bulk_disable(phydev->regulator_cnt, phydev->consumers); + return ret; } EXPORT_SYMBOL(phy_suspend); @@ -1811,6 +1815,12 @@ int phy_resume(struct phy_device *phydev) { int ret; + if (phydev->regulator_cnt > 0) { + ret = regulator_bulk_enable(phydev->regulator_cnt, phydev->consumers); + if (ret) + 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 508f1149665b..ef4e0ce67194 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); + int regulator_cnt; + struct regulator_bulk_data *consumers; + #if IS_ENABLED(CONFIG_MACSEC) /* MACsec management functions */ const struct macsec_ops *macsec_ops; -- 2.35.1