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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C1F47C6FD18 for ; Wed, 19 Apr 2023 13:41:13 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 986108626E; Wed, 19 Apr 2023 15:40:47 +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="NUSjX8VW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B200F86283; Wed, 19 Apr 2023 15:40:41 +0200 (CEST) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) (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 E86D386268 for ; Wed, 19 Apr 2023 15:40:37 +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 C2BAA6603253; Wed, 19 Apr 2023 14:40:36 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1681911637; bh=OPJCWA8SM8ALtuRFU+OFQWeRwKn/a3Y7mc0YD18t/nM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NUSjX8VWx1v5C1WNHatDGxBR0sgy1HduEsvDu2M3LmqTq+gEkrzWjU8PXTufkyfof ZhuWwd8y7APYvGU+tiJ2YmMP8UGnS5+4ut2zzpCxNPaosTLGLuuEGiNGdaugLkY/Tr pl55JUjgTbv8kqyitFDM7vUSxRxohnEuBLkCdtF1V+Nir2eE+YbmfgnwS4FKFppYOU LDc+tZ7dfXBkBfur9nRKKwCQJMVvM5pA3wVT96akynZTqITWgvFFpczzKx5IPf2US9 lRs63zDukylVCb5fzI2EFe2Qe1RH5OGkzsjMp1+yzKMTmF6J72tMAeFsVFVM2xhlxk /0Bs8qGskXbew== From: Eugen Hristev To: kever.yang@rock-chips.com, jonas@kwiboo.se, eugen.hristev@collabora.com, u-boot@lists.denx.de Cc: u-boot-amlogic@groups.io, xdrudis@tinet.cat, jagan@edgeble.ai, neil.armstrong@linaro.org, anarsoul@gmail.com Subject: [PATCH v5 3/6] phy: add support for phy-supply Date: Wed, 19 Apr 2023 16:40:11 +0300 Message-Id: <20230419134014.128461-3-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230419134014.128461-1-eugen.hristev@collabora.com> References: <20230419134014.128461-1-eugen.hristev@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. [jonas@kwiboo.se: use regulator_set_enable_if_allowed and disable if power_on ops fails] Signed-off-by: Jonas Karlman Signed-off-by: Eugen Hristev --- Changes in v5: - add changes done by Jonas drivers/phy/phy-uclass.c | 51 +++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c index 3fef5135a9cb..45ec1471d0ae 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) @@ -58,7 +61,7 @@ static struct phy_counts *phy_get_counts(struct phy *phy) return NULL; } -static int phy_alloc_counts(struct phy *phy) +static int phy_alloc_counts(struct phy *phy, struct udevice *supply) { struct list_head *uc_priv; struct phy_counts *counts; @@ -76,6 +79,7 @@ static int phy_alloc_counts(struct phy *phy) counts->id = phy->id; counts->power_on_count = 0; counts->init_count = 0; + counts->supply = supply; list_add(&counts->list, uc_priv); return 0; @@ -123,7 +127,7 @@ int generic_phy_get_by_index_nodev(ofnode node, int index, struct phy *phy) { struct ofnode_phandle_args args; struct phy_ops *ops; - struct udevice *phydev; + struct udevice *phydev, *supply = NULL; int i, ret; debug("%s(node=%s, index=%d, phy=%p)\n", @@ -172,7 +176,17 @@ int generic_phy_get_by_index_nodev(ofnode node, int index, struct phy *phy) goto err; } - ret = phy_alloc_counts(phy); + if (CONFIG_IS_ENABLED(DM_REGULATOR)) { + ret = device_get_supply_regulator(phydev, "phy-supply", + &supply); + if (ret && ret != -ENOENT) { + debug("%s: device_get_supply_regulator failed: %d\n", + __func__, ret); + goto err; + } + } + + ret = phy_alloc_counts(phy, supply); if (ret) { debug("phy_alloc_counts() failed: %d\n", ret); goto err; @@ -300,14 +314,23 @@ int generic_phy_power_on(struct phy *phy) return 0; } + ret = regulator_set_enable_if_allowed(counts->supply, true); + if (ret && ret != -ENOSYS) { + dev_err(phy->dev, "PHY: Failed to enable regulator %s: %d.\n", + counts->supply->name, ret); + return ret; + } + ret = ops->power_on(phy); - if (ret) + if (ret) { dev_err(phy->dev, "PHY: Failed to power on %s: %d.\n", phy->dev->name, ret); - else - counts->power_on_count = 1; + regulator_set_enable_if_allowed(counts->supply, false); + return ret; + } + counts->power_on_count = 1; - return ret; + return 0; } int generic_phy_power_off(struct phy *phy) @@ -331,13 +354,19 @@ int generic_phy_power_off(struct phy *phy) } ret = ops->power_off(phy); - if (ret) + if (ret) { dev_err(phy->dev, "PHY: Failed to power off %s: %d.\n", phy->dev->name, ret); - else - counts->power_on_count = 0; + return ret; + } + counts->power_on_count = 0; - return ret; + ret = regulator_set_enable_if_allowed(counts->supply, false); + if (ret && ret != -ENOSYS) + dev_err(phy->dev, "PHY: Failed to disable regulator %s: %d.\n", + counts->supply->name, ret); + + return 0; } int generic_phy_configure(struct phy *phy, void *params) -- 2.34.1