From patchwork Tue Apr 4 14:11:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 1765008 X-Patchwork-Delegate: ykai007@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=WFjEeBzm; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PrV9D1nDLz1yYn for ; Wed, 5 Apr 2023 00:13:20 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E1CF6859E0; Tue, 4 Apr 2023 16:12:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="WFjEeBzm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A896D857B1; Tue, 4 Apr 2023 16:12:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 26A2585927 for ; Tue, 4 Apr 2023 16:12:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=eugen.hristev@collabora.com Received: from eugen-station.. (unknown [82.76.24.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madras.collabora.co.uk (Postfix) with ESMTPSA id 1BAC76603162; Tue, 4 Apr 2023 15:12:21 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680617541; bh=Av+nAjll95/V07i1rVX8QkEYQgPIiz9CocMeuCmFXTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WFjEeBzmLG4R/PhszCHpXLapVOESfPXAKhsvH2OxG1FsbI2icmGI4Xno9Rm5A98mU wnPNO/mEq+5sUSN4oXFaht7KZeYkWoj4yuAF1IRkjOZxAS15HTSILbfZjRZTnG+YST l7edxeES0qvmc44HAurW4CQOJJaylK7s3CQMNDI9c1iB1F9mliaMItSVWcWFYy9iVA 9kuqzeuh943eD1+YL7/f+ijEzy4Ig0vtdyvWGRI5FW2RjHBy0LodloFyEf+NuNWTir G3MXhUffOVa0nKbhC/CR+aubY9PQehefgKY/+6gqcGQuXgBapmEGwBux3+TaTqqWyz yGePUxdR9eF0g== From: Eugen Hristev To: u-boot@lists.denx.de Cc: u-boot-amlogic@groups.io, kever.yang@rock-chips.com, neil.armstrong@linaro.org, jagan@edgeble.ai, jonas@kwiboo.se, xdrudis@tinet.cat, anarsoul@gmail.com, Eugen Hristev Subject: [PATCH v4 3/5] phy: add support for phy-supply Date: Tue, 4 Apr 2023 17:11:53 +0300 Message-Id: <20230404141155.283987-3-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230404141155.283987-1-eugen.hristev@collabora.com> References: <20230404141155.283987-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Some phys require a phy-supply property that is a phandle to a regulator that needs to be enabled for phy operations. Implement basic supply lookup, enable and disabling, if DM_REGULATOR is available. Signed-off-by: Eugen Hristev --- drivers/phy/phy-uclass.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c index 3fef5135a9cb..475ac285df05 100644 --- a/drivers/phy/phy-uclass.c +++ b/drivers/phy/phy-uclass.c @@ -12,6 +12,7 @@ #include #include #include +#include /** * struct phy_counts - Init and power-on counts of a single PHY port @@ -29,12 +30,14 @@ * without a matching generic_phy_exit() afterwards * @list: Handle for a linked list of these structures corresponding to * ports of the same PHY provider + * @supply: Handle to a phy-supply device */ struct phy_counts { unsigned long id; int power_on_count; int init_count; struct list_head list; + struct udevice *supply; }; static inline struct phy_ops *phy_dev_ops(struct udevice *dev) @@ -224,6 +227,12 @@ int generic_phy_init(struct phy *phy) return 0; } +#if CONFIG_IS_ENABLED(DM_REGULATOR) + device_get_supply_regulator(phy->dev, "phy-supply", &counts->supply); + if (IS_ERR(counts->supply)) + dev_dbg(phy->dev, "no phy-supply property found\n"); +#endif + ret = ops->init(phy); if (ret) dev_err(phy->dev, "PHY: Failed to init %s: %d.\n", @@ -272,6 +281,12 @@ int generic_phy_exit(struct phy *phy) return 0; } +#if CONFIG_IS_ENABLED(DM_REGULATOR) + if (!IS_ERR_OR_NULL(counts->supply)) { + ret = regulator_set_enable(counts->supply, false); + dev_dbg(phy->dev, "supply disable status: %d\n", ret); + } +#endif ret = ops->exit(phy); if (ret) dev_err(phy->dev, "PHY: Failed to exit %s: %d.\n", @@ -300,6 +315,13 @@ int generic_phy_power_on(struct phy *phy) return 0; } +#if CONFIG_IS_ENABLED(DM_REGULATOR) + if (!IS_ERR_OR_NULL(counts->supply)) { + ret = regulator_set_enable(counts->supply, true); + dev_dbg(phy->dev, "supply enable status: %d\n", ret); + } +#endif + ret = ops->power_on(phy); if (ret) dev_err(phy->dev, "PHY: Failed to power on %s: %d.\n",