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 DAE0BC433EF for ; Fri, 8 Apr 2022 08:10:42 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E4ED883E2A; Fri, 8 Apr 2022 10:09:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=ziswiler.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id BD76383DD9; Fri, 8 Apr 2022 10:08:16 +0200 (CEST) Received: from mout.perfora.net (mout.perfora.net [74.208.4.194]) (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 132668021F for ; Fri, 8 Apr 2022 10:07:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=ziswiler.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=marcel@ziswiler.com Received: from toolbox.int.toradex.com ([81.221.85.15]) by mrelay.perfora.net (mreueus004 [74.208.5.2]) with ESMTPSA (Nemesis) id 1MUGJb-1nT0bu3Doh-00RLoW; Fri, 08 Apr 2022 10:07:50 +0200 From: Marcel Ziswiler To: u-boot@lists.denx.de Cc: Philippe Schenker , Marcel Ziswiler , Jaehoon Chung Subject: [PATCH v1 15/24] regulator: fixed: add possibility to enable by clock Date: Fri, 8 Apr 2022 10:07:10 +0200 Message-Id: <20220408080719.342072-16-marcel@ziswiler.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220408080719.342072-1-marcel@ziswiler.com> References: <20220408080719.342072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sYEa1 LsphVICz6yv+JM4L 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.5 at phobos.denx.de X-Virus-Status: Clean From: Philippe Schenker This commit adds the possibility to choose the compatible "regulator-fixed-clock" in devicetree. This is a special case of regulator-fixed where a clock has to be used to switch the regulator on and off. Signed-off-by: Philippe Schenker Signed-off-by: Marcel Ziswiler --- drivers/power/regulator/fixed.c | 60 ++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/power/regulator/fixed.c b/drivers/power/regulator/fixed.c index d3e0fb672d9..90004d1601a 100644 --- a/drivers/power/regulator/fixed.c +++ b/drivers/power/regulator/fixed.c @@ -6,14 +6,21 @@ */ #include +#include #include #include +#include #include #include #include #include "regulator_common.h" +struct fixed_clock_regulator_plat { + struct clk *enable_clock; + unsigned int clk_enable_counter; +}; + static int fixed_regulator_of_to_plat(struct udevice *dev) { struct dm_regulator_uclass_plat *uc_pdata; @@ -71,6 +78,38 @@ static int fixed_regulator_set_enable(struct udevice *dev, bool enable) return regulator_common_set_enable(dev, dev_get_plat(dev), enable); } +static int fixed_clock_regulator_get_enable(struct udevice *dev) +{ + struct fixed_clock_regulator_plat *priv = dev_get_priv(dev); + + return priv->clk_enable_counter > 0; +} + +static int fixed_clock_regulator_set_enable(struct udevice *dev, bool enable) +{ + struct fixed_clock_regulator_plat *priv = dev_get_priv(dev); + struct regulator_common_plat *dev_pdata = dev_get_plat(dev); + int ret = 0; + + if (enable) { + ret = clk_enable(priv->enable_clock); + priv->clk_enable_counter++; + } else { + ret = clk_disable(priv->enable_clock); + priv->clk_enable_counter--; + } + if (ret) + return ret; + + if (enable && dev_pdata->startup_delay_us) + udelay(dev_pdata->startup_delay_us); + + if (!enable && dev_pdata->off_on_delay_us) + udelay(dev_pdata->off_on_delay_us); + + return ret; +} + static const struct dm_regulator_ops fixed_regulator_ops = { .get_value = fixed_regulator_get_value, .get_current = fixed_regulator_get_current, @@ -78,16 +117,35 @@ static const struct dm_regulator_ops fixed_regulator_ops = { .set_enable = fixed_regulator_set_enable, }; +static const struct dm_regulator_ops fixed_clock_regulator_ops = { + .get_enable = fixed_clock_regulator_get_enable, + .set_enable = fixed_clock_regulator_set_enable, +}; + static const struct udevice_id fixed_regulator_ids[] = { { .compatible = "regulator-fixed" }, { }, }; +static const struct udevice_id fixed_clock_regulator_ids[] = { + { .compatible = "regulator-fixed-clock" }, + { }, +}; + U_BOOT_DRIVER(regulator_fixed) = { .name = "regulator_fixed", .id = UCLASS_REGULATOR, .ops = &fixed_regulator_ops, .of_match = fixed_regulator_ids, .of_to_plat = fixed_regulator_of_to_plat, - .plat_auto = sizeof(struct regulator_common_plat), + .plat_auto = sizeof(struct regulator_common_plat), +}; + +U_BOOT_DRIVER(regulator_fixed_clock) = { + .name = "regulator_fixed_clk", + .id = UCLASS_REGULATOR, + .ops = &fixed_clock_regulator_ops, + .of_match = fixed_clock_regulator_ids, + .of_to_plat = fixed_regulator_of_to_plat, + .plat_auto = sizeof(struct fixed_clock_regulator_plat), }; -- 2.34.1