From patchwork Tue Nov 15 07:36:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 20227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2571916wru; Mon, 14 Nov 2022 23:39:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf7vGYoYdU4vVBndk5tv0rjf8h502ADSgzNM3po0p4Zf6qx39kYhu5KuInYrQY1FxiCf0dZA X-Received: by 2002:aa7:d9c8:0:b0:458:3f65:4e42 with SMTP id v8-20020aa7d9c8000000b004583f654e42mr14052042eds.39.1668497956681; Mon, 14 Nov 2022 23:39:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668497956; cv=none; d=google.com; s=arc-20160816; b=ZLYrh96onCPjWs+E+MFzdWKR1qcjvKp6SW//Xesjw7RipkU1hNhAgEWoX28lr3J10P Td7g69TVBblmeNPQms/E3vTkm2Q38e/eZC/LHEVSLDTB9AppxzVIrn1yG0Ts/q9vY12j wujPm5Ruc+hSuZk3NWKTEaaJbohTMgH+NYjQTX4N5eHyhD1B0wDBMpobRjueG0RS2LmR 5hCrNcVJ7rDqIAxhkJeIgz0SsPew6hC/G1GAy9NgXibNIVzIv47TAme3LJ60XefByUay 1bmjEBsEn4XWPzhzyvVpaGjkECC1iGtku6XX1K2rEP8GNb2mWnczAg2cILOu066QyQDB X9DA== 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=tofLe7VkhuAP8ykkOBP52ao1zn0HKFI/d0yOPPGhcQo=; b=ukv++JKwdCo0q+bNBif1wkET2cFTG/Zn9ON1/JzMOuYjIcn7+STp7irp+lFO6YES4Q RxOrX2HqaPSpSXhEIvSNZ2lXvQDvDDb6ROmp3Vw6q+7oeeNPkiqfQ9AHd366V/af/SQz zBr8CMfBzckns651MPDI8swJj8cYqWwI2qiKPfyTrpoG3ElL6c82rFZ4px+/AHe9qtTh NAeGAJfqFy10giI/UOwqEXOkUD6HNu7sJq2FfIICRbbtZ/fT3DtrwnZNc3sJp2rTH0WJ +Lv4+4Cbz5vtpY9rzwB8UZaiduVCpKDTQB4FTfEmnfcwbDq7jNO5FsuVJl6E3vmEt/Mt ZXcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=qPiL6puF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw18-20020a1709066a1200b007ae98ea45e0si11085478ejc.751.2022.11.14.23.38.53; Mon, 14 Nov 2022 23:39:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=qPiL6puF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232248AbiKOHgb (ORCPT + 99 others); Tue, 15 Nov 2022 02:36:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232454AbiKOHgQ (ORCPT ); Tue, 15 Nov 2022 02:36:16 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69985A193 for ; Mon, 14 Nov 2022 23:36:15 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id v1so22688837wrt.11 for ; Mon, 14 Nov 2022 23:36:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tofLe7VkhuAP8ykkOBP52ao1zn0HKFI/d0yOPPGhcQo=; b=qPiL6puFyXidlZ5GnQU+0u6EL9qAiYmCMt24RnSKcbIMSUr5Kmz8io3EDiisxn2Rvi RyK559oeh78DtbEgoT9QrR1UNYamo6xU7Fq66jqy6ADPulLvK6J4+5yy8vARriFEzId9 KD4AI4UjxSLma6Y2IKCLw4/lTppt0zGiIxCrPMV7tP7NEMQKJPpNYLkDnGDO5JctjEtX 3SCvPbQHLzTOBl2xrZlcwSjiZfrECeWbnNufsssKhB1JGrWRAUIY0DL5Moo23P97yJjp l4l7lw2H/hVJCTBdDE+NeftFAHLnDldHKR3HeLMj+SyMpmeFlNV6vP4qUfeFvhQ0cVNs o/FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tofLe7VkhuAP8ykkOBP52ao1zn0HKFI/d0yOPPGhcQo=; b=V3KmLOcFx9Ipw/O1YO+BC0SLZAmRfEt36L9zGdAVMiLikYdXcHGZbi4FGOjKvs1GBK zJDiicwkFrZYzMM91LObjVzEEJHQt6dOKPaZQgTqmSleMlppnDUYVj6NYPbZ5RF54H3j sCtg6hmkRjTFGF+Pcy4uSV4r3rqvwr6Gbfjb5mHBub/XfkTmTdxBEQz4d+dGaUPaYphj we5/WwG4dMmkysxi6CI/yiAAwDb/Pmhzl8+DuOnTWpugYtYerYY8tlYW7KndGO5dHtQB ZDsiKf53b7gZSt1RXyI+PjqpvNp2h+MoJLvGfsSuhX9tqy8gWCa/SwCBHyT7hFigq118 V62g== X-Gm-Message-State: ANoB5pkg1H9IbvbIOaqAjxq7ybR3G0G4Bjybtv8V8t5VB4OgiBbPbd96 2S9z7EZ2j6xiLwbtan9ZeNxilw== X-Received: by 2002:adf:dc91:0:b0:236:debd:bd65 with SMTP id r17-20020adfdc91000000b00236debdbd65mr9339427wrj.527.1668497773920; Mon, 14 Nov 2022 23:36:13 -0800 (PST) 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 j13-20020a5d452d000000b0022cbf4cda62sm13836811wra.27.2022.11.14.23.36.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 23:36:13 -0800 (PST) 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, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH v4 2/3] phy: handle optional regulator for PHY Date: Tue, 15 Nov 2022 07:36:02 +0000 Message-Id: <20221115073603.3425396-3-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221115073603.3425396-1-clabbe@baylibre.com> References: <20221115073603.3425396-1-clabbe@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749546913502341882?= X-GMAIL-MSGID: =?utf-8?q?1749546913502341882?= 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 | 31 ++++++++++++++++++++++++++++++- drivers/net/phy/phy_device.c | 10 ++++++++++ include/linux/phy.h | 3 +++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index 689e728345ce..19a16072d4ca 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -10,6 +10,7 @@ #include #include #include +#include #include MODULE_AUTHOR("Calvin Johnson "); @@ -116,7 +117,9 @@ 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 = NULL; + struct device_node __maybe_unused *nchild = NULL; psec = fwnode_find_pse_control(child); if (IS_ERR(psec)) @@ -133,6 +136,26 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, if (rc >= 0) is_c45 = true; +#ifdef CONFIG_OF + for_each_child_of_node(bus->dev.of_node, nchild) { + u32 reg; + + of_property_read_u32(nchild, "reg", ®); + if (reg != addr) + continue; + reg_cnt = of_regulator_bulk_get_all(&bus->dev, nchild, &consumers); + if (reg_cnt > 0) { + rc = regulator_bulk_enable(reg_cnt, consumers); + if (rc) + return rc; + } + if (reg_cnt < 0) { + dev_err(&bus->dev, "Fail to regulator_bulk_get_all err=%d\n", reg_cnt); + return reg_cnt; + } + } +#endif + if (is_c45 || fwnode_get_phy_id(child, &phy_id)) phy = get_phy_device(bus, addr, is_c45); else @@ -142,6 +165,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, goto clean_mii_ts; } + phy->regulator_cnt = reg_cnt; + phy->consumers = consumers; + if (is_acpi_node(child)) { phy->irq = bus->irq[addr]; @@ -180,6 +206,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, clean_pse: pse_control_put(psec); + 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 57849ac0384e..957e27c75eb2 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -1818,6 +1819,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); @@ -1844,6 +1848,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 9a3752c0c444..5d1311b35cc3 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -729,6 +729,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;