From patchwork Sat Apr 10 06:42:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 1464587 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=Xp1Qt5nr; 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FHQRc1ZPkz9sWH for ; Sat, 10 Apr 2021 16:42:48 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D624D800B3; Sat, 10 Apr 2021 08:42:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1618036956; bh=K0xEqRetzUwYqO0pqPk4wTcwAcYBSqVv4lj5ZyXehAQ=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=Xp1Qt5nrigLA1krFBg7OQmW31PbYiBM9SXrf7ykswqrasHSDxqgBSis6g9SQlQTwk XZOTJG9c/6UlUizbqjQH8GgxWkf4R8jv+3be0gySwh/TXs7UEuTOOThQoVBkQK8IVH EzRM7CCj7xlvm1ZXSBPVswG8TYOg6qIZ3h2p3THu0sK8MskM7FAF2TM1ns46SzbEcq Vm/OM1VQN0V2yScz/gqFJWJ95ufl8C5Q6Q1uSsHLsd6gOyMcSKNpJ/mUTJ3RqMy/SR 9WuRxZ56qxESGMfyyXBsr/ElYh6ZKx9gdktn/eNzdZgaW6T8bHzy4kzFUbWIZDBBTB PnDfDGquG7MkQ== Received: by phobos.denx.de (Postfix, from userid 109) id BEFB8801F0; Sat, 10 Apr 2021 08:42:34 +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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [IPv6:2001:67c:2050:1::465:107]) (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 0551580050 for ; Sat, 10 Apr 2021 08:42:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=sr@denx.de Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4FHQRB4jxRzQjhG; Sat, 10 Apr 2021 08:42:30 +0200 (CEST) Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id g1VAdviKdLcD; Sat, 10 Apr 2021 08:42:26 +0200 (CEST) From: Stefan Roese To: u-boot@lists.denx.de Cc: Konstantin Porotchkin , Jaehoon Chung , Simon Glass Subject: [PATCH v2] power: regulator: Add support for regulator-force-boot-off Date: Sat, 10 Apr 2021 08:42:25 +0200 Message-Id: <20210410064225.2128782-1-sr@denx.de> MIME-Version: 1.0 X-MBO-SPAM-Probability: X-Rspamd-Score: -2.76 / 15.00 / 15.00 X-Rspamd-Queue-Id: 2246E4F5 X-Rspamd-UID: 0d0419 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.4 at phobos.denx.de X-Virus-Status: Clean From: Konstantin Porotchkin Add support for regulator-force-boot-off DT property. This property can be used by the board/device drivers for turning off regulators on early init stages as pre-requisite for the other components initialization. Signed-off-by: Konstantin Porotchkin Signed-off-by: Stefan Roese Cc: Jaehoon Chung Cc: Simon Glass Reviewed-by: Jaehoon Chung --- v2: - Add check for uc_pdata in regulator_unset() drivers/power/regulator/regulator-uclass.c | 38 ++++++++++++++++++++++ include/power/regulator.h | 23 +++++++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c index 4d2e730271f9..fac960682331 100644 --- a/drivers/power/regulator/regulator-uclass.c +++ b/drivers/power/regulator/regulator-uclass.c @@ -311,6 +311,17 @@ int regulator_autoset(struct udevice *dev) return ret; } +int regulator_unset(struct udevice *dev) +{ + struct dm_regulator_uclass_plat *uc_pdata; + + uc_pdata = dev_get_uclass_plat(dev); + if (uc_pdata && uc_pdata->force_off) + return regulator_set_enable(dev, false); + + return -EMEDIUMTYPE; +} + static void regulator_show(struct udevice *dev, int ret) { struct dm_regulator_uclass_plat *uc_pdata; @@ -443,6 +454,7 @@ static int regulator_pre_probe(struct udevice *dev) uc_pdata->boot_on = dev_read_bool(dev, "regulator-boot-on"); uc_pdata->ramp_delay = dev_read_u32_default(dev, "regulator-ramp-delay", 0); + uc_pdata->force_off = dev_read_bool(dev, "regulator-force-boot-off"); node = dev_read_subnode(dev, "regulator-state-mem"); if (ofnode_valid(node)) { @@ -495,6 +507,32 @@ int regulators_enable_boot_on(bool verbose) return ret; } +int regulators_enable_boot_off(bool verbose) +{ + struct udevice *dev; + struct uclass *uc; + int ret; + + ret = uclass_get(UCLASS_REGULATOR, &uc); + if (ret) + return ret; + for (uclass_first_device(UCLASS_REGULATOR, &dev); + dev; + uclass_next_device(&dev)) { + ret = regulator_unset(dev); + if (ret == -EMEDIUMTYPE) { + ret = 0; + continue; + } + if (verbose) + regulator_show(dev, ret); + if (ret == -ENOSYS) + ret = 0; + } + + return ret; +} + UCLASS_DRIVER(regulator) = { .id = UCLASS_REGULATOR, .name = "regulator", diff --git a/include/power/regulator.h b/include/power/regulator.h index da9a065bdde0..fad87c99e5db 100644 --- a/include/power/regulator.h +++ b/include/power/regulator.h @@ -151,6 +151,7 @@ enum regulator_flag { * @max_uA* - maximum amperage (micro Amps) * @always_on* - bool type, true or false * @boot_on* - bool type, true or false + * @force_off* - bool type, true or false * TODO(sjg@chromium.org): Consider putting the above two into @flags * @ramp_delay - Time to settle down after voltage change (unit: uV/us) * @flags: - flags value (see REGULATOR_FLAG_...) @@ -176,6 +177,7 @@ struct dm_regulator_uclass_plat { unsigned int ramp_delay; bool always_on; bool boot_on; + bool force_off; const char *name; int flags; u8 ctrl_reg; @@ -420,6 +422,15 @@ int regulator_set_mode(struct udevice *dev, int mode_id); */ int regulators_enable_boot_on(bool verbose); +/** + * regulators_enable_boot_off() - disable regulators needed for boot + * + * This disables all regulators which are marked to be off at boot time. + * + * This effectively calls regulator_unset() for every regulator. + */ +int regulators_enable_boot_off(bool verbose); + /** * regulator_autoset: setup the voltage/current on a regulator * @@ -439,6 +450,18 @@ int regulators_enable_boot_on(bool verbose); */ int regulator_autoset(struct udevice *dev); +/** + * regulator_unset: turn off a regulator + * + * The setup depends on constraints found in device's uclass's platform data + * (struct dm_regulator_uclass_platdata): + * + * - Disable - will set - if 'force_off' is set to true, + * + * The function returns on the first-encountered error. + */ +int regulator_unset(struct udevice *dev); + /** * regulator_autoset_by_name: setup the regulator given by its uclass's * platform data name field. The setup depends on constraints found in device's