From patchwork Tue Oct 3 06:21:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Svyatoslav Ryhel X-Patchwork-Id: 1842388 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=mbEKCQ61; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S075V5WYxz1yph for ; Tue, 3 Oct 2023 17:22:06 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 420F787165; Tue, 3 Oct 2023 08:21:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="mbEKCQ61"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 066D9871DB; Tue, 3 Oct 2023 08:21:47 +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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F1CD387165 for ; Tue, 3 Oct 2023 08:21:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=clamor95@gmail.com Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2c15463ddd4so5498141fa.3 for ; Mon, 02 Oct 2023 23:21:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696314104; x=1696918904; darn=lists.denx.de; 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=ANLIjtPoT6SG2XGbIRx4qpZAMR/iRxcgjWpKbr7R2AA=; b=mbEKCQ61W1eVo3s7uorOMubMaLhWu2Zp+imPFsYWzJwGftS+kYydd3r09qhjhJLKF+ d4wn0K1fakBBySO+vZARS8xn6c1sCl/9gNo7fi2zGGs6TwGOx6czf/8GGpbrH1gqPn6j EZkoQNmohoxJskovVA5uBtQ+D6mruiogSjmXys/rYo0bu9U6q0H52XIthJD7QVtiufHi tzV3Ruy6T4esllt0bEjE+ZL3kg2BrzgCVvi8NbKlf2hKPeZvNSyXuGkTIsSp/ycNeJWG Y5dBv83/fK+wTxHiaYgLY5vVZ+n7kz4gKy+LxkGqKk8pghy2Ue+Ix8WluLV/ztpkVmZL bB4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696314104; x=1696918904; 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=ANLIjtPoT6SG2XGbIRx4qpZAMR/iRxcgjWpKbr7R2AA=; b=eMyw170e5vGKL87SytQj9xPTxDesn8rAiXM6Z3GdfOG9KOhE30k5yeSt5uUrl37siz 4IEnbZyeEKmbMYD/uw5FFFNZWXAZPDx+z0a3S8sju1Two9DJIyBU6jRZESfLhDt/h0r2 s37uQAluplTVZHucEUJP+91tWnj4VF1OMYgAbmJFzMt8l3xT/KPguXM/Wc4k3G+dfvoP +TBxNQ8QflilDdTYzCsXz5IC9aBmKgfvRH7p1GfGLFWqjvk3lMJvJPW0jlzDoqbqC2I6 IJN99zbvwo2wVywY/XtLfhTU/kQhTOH1x+HWX6J5tG5Yv9C/xC0m3TB1fqmhFSKBfVDX KudQ== X-Gm-Message-State: AOJu0YziuyupH2BGWYtCTmtfqFlNQ4AfKed7al+gSJza0RUF3pVVJy2H jqTIg1ne6giaJGlTJ0u6yO0= X-Google-Smtp-Source: AGHT+IFJUro5wbB+FcKkA5/690IdtnO+34dFuefOrf7Rti2e1q9yfjTuqIxeepWM/4tf9OH4T943Sg== X-Received: by 2002:a2e:9914:0:b0:2c0:2ab7:9aae with SMTP id v20-20020a2e9914000000b002c02ab79aaemr11395562lji.11.1696314103966; Mon, 02 Oct 2023 23:21:43 -0700 (PDT) Received: from xeon.. ([188.163.112.76]) by smtp.gmail.com with ESMTPSA id n4-20020a2e86c4000000b002bfba0d26bcsm103594ljj.8.2023.10.02.23.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 23:21:43 -0700 (PDT) From: Svyatoslav Ryhel To: Jaehoon Chung , Simon Glass , Jonas Karlman , Svyatoslav Ryhel , Eugen Hristev , Patrice Chotard , John Keeping Cc: u-boot@lists.denx.de Subject: [PATCH v4 1/4] power: regulator: expand basic reference counter onto all uclass Date: Tue, 3 Oct 2023 09:21:23 +0300 Message-Id: <20231003062126.42026-2-clamor95@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231003062126.42026-1-clamor95@gmail.com> References: <20231003062126.42026-1-clamor95@gmail.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 Commit is based on 4fcba5d ("regulator: implement basic reference counter") but expands the idea to all regulators instead of just fixed/gpio regulators. Signed-off-by: Svyatoslav Ryhel Reviewed-by: Simon Glass --- drivers/power/regulator/regulator-uclass.c | 41 ++++++++++++++++++++++ drivers/power/regulator/regulator_common.c | 22 ------------ drivers/power/regulator/regulator_common.h | 21 ----------- include/power/regulator.h | 2 ++ 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c index d5a79d861c..4b2c6c2964 100644 --- a/drivers/power/regulator/regulator-uclass.c +++ b/drivers/power/regulator/regulator-uclass.c @@ -159,6 +159,25 @@ int regulator_get_enable(struct udevice *dev) return ops->get_enable(dev); } +/* + * Enable or Disable a regulator + * + * This is a reentrant function and subsequent calls that enable will + * increase an internal counter, and disable calls will decrease the counter. + * The actual resource will be enabled when the counter gets to 1 coming from 0, + * and disabled when it reaches 0 coming from 1. + * + * @dev: regulator device + * @enable: bool indicating whether to enable or disable the regulator + * @return: + * 0 on Success + * -EBUSY if the regulator cannot be disabled because it's requested by + * another device + * -EALREADY if the regulator has already been enabled or has already been + * disabled + * -EACCES if there is no possibility to enable/disable the regulator + * -ve on different error situation + */ int regulator_set_enable(struct udevice *dev, bool enable) { const struct dm_regulator_ops *ops = dev_get_driver_ops(dev); @@ -172,6 +191,23 @@ int regulator_set_enable(struct udevice *dev, bool enable) if (!enable && uc_pdata->always_on) return -EACCES; + /* If previously enabled, increase count */ + if (enable && uc_pdata->enable_count > 0) { + uc_pdata->enable_count++; + return -EALREADY; + } + + if (!enable) { + if (uc_pdata->enable_count > 1) { + /* If enabled multiple times, decrease count */ + uc_pdata->enable_count--; + return -EBUSY; + } else if (!uc_pdata->enable_count) { + /* If already disabled, do nothing */ + return -EALREADY; + } + } + if (uc_pdata->ramp_delay) old_enable = regulator_get_enable(dev); @@ -187,6 +223,11 @@ int regulator_set_enable(struct udevice *dev, bool enable) } } + if (enable) + uc_pdata->enable_count++; + else + uc_pdata->enable_count--; + return ret; } diff --git a/drivers/power/regulator/regulator_common.c b/drivers/power/regulator/regulator_common.c index 0116fa01bb..62d06bf616 100644 --- a/drivers/power/regulator/regulator_common.c +++ b/drivers/power/regulator/regulator_common.c @@ -74,23 +74,6 @@ int regulator_common_set_enable(const struct udevice *dev, return 0; } - /* If previously enabled, increase count */ - if (enable && plat->enable_count > 0) { - plat->enable_count++; - return -EALREADY; - } - - if (!enable) { - if (plat->enable_count > 1) { - /* If enabled multiple times, decrease count */ - plat->enable_count--; - return -EBUSY; - } else if (!plat->enable_count) { - /* If already disabled, do nothing */ - return -EALREADY; - } - } - ret = dm_gpio_set_value(&plat->gpio, enable); if (ret) { pr_err("Can't set regulator : %s gpio to: %d\n", dev->name, @@ -105,10 +88,5 @@ int regulator_common_set_enable(const struct udevice *dev, if (!enable && plat->off_on_delay_us) udelay(plat->off_on_delay_us); - if (enable) - plat->enable_count++; - else - plat->enable_count--; - return 0; } diff --git a/drivers/power/regulator/regulator_common.h b/drivers/power/regulator/regulator_common.h index d4962899d8..15f1fa4c93 100644 --- a/drivers/power/regulator/regulator_common.h +++ b/drivers/power/regulator/regulator_common.h @@ -13,7 +13,6 @@ struct regulator_common_plat { struct gpio_desc gpio; /* GPIO for regulator enable control */ unsigned int startup_delay_us; unsigned int off_on_delay_us; - unsigned int enable_count; }; int regulator_common_of_to_plat(struct udevice *dev, @@ -21,26 +20,6 @@ int regulator_common_of_to_plat(struct udevice *dev, char *enable_gpio_name); int regulator_common_get_enable(const struct udevice *dev, struct regulator_common_plat *plat); -/* - * Enable or Disable a regulator - * - * This is a reentrant function and subsequent calls that enable will - * increase an internal counter, and disable calls will decrease the counter. - * The actual resource will be enabled when the counter gets to 1 coming from 0, - * and disabled when it reaches 0 coming from 1. - * - * @dev: regulator device - * @plat: Platform data - * @enable: bool indicating whether to enable or disable the regulator - * @return: - * 0 on Success - * -EBUSY if the regulator cannot be disabled because it's requested by - * another device - * -EALREADY if the regulator has already been enabled or has already been - * disabled - * -EACCES if there is no possibility to enable/disable the regulator - * -ve on different error situation - */ int regulator_common_set_enable(const struct udevice *dev, struct regulator_common_plat *plat, bool enable); diff --git a/include/power/regulator.h b/include/power/regulator.h index 200652cb3d..1c7995bd5d 100644 --- a/include/power/regulator.h +++ b/include/power/regulator.h @@ -159,6 +159,7 @@ enum regulator_flag { * @name** - fdt regulator name - should be taken from the device tree * ctrl_reg: - Control register offset used to enable/disable regulator * volt_reg: - register offset for writing voltage vsel values + * enable_count - counter of enable calls for this regulator * * Note: * * - set automatically on device probe by the uclass's '.pre_probe' method. @@ -185,6 +186,7 @@ struct dm_regulator_uclass_plat { u8 volt_reg; bool suspend_on; u32 suspend_uV; + u32 enable_count; }; /* Regulator device operations */ From patchwork Tue Oct 3 06:21:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Svyatoslav Ryhel X-Patchwork-Id: 1842389 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=X5AA0zER; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S075d4rp3z1yph for ; Tue, 3 Oct 2023 17:22:13 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9F9B8871E7; Tue, 3 Oct 2023 08:21:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="X5AA0zER"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CCCF1871E2; Tue, 3 Oct 2023 08:21:48 +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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E375086E15 for ; Tue, 3 Oct 2023 08:21:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=clamor95@gmail.com Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2c28e35752cso6392411fa.0 for ; Mon, 02 Oct 2023 23:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696314105; x=1696918905; darn=lists.denx.de; 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=133KeprTV/vR0eagW5kUqY7IWB39BGwuNCAQ+zim7o4=; b=X5AA0zERXKuh2K57tXfpKg2cz5O17AIHhLXcopby7ud1Bfb3du15ntdx9dGbKrmXsY zrrCYR7WvbS1qKBi5zf0Jh1w1OqGOFn4MY2YKNkkXwJ5Dksd6tMBO6K+EVtZieaDVU+v 9jlGuX468IEAkytBLCxfQzQHWJ8HRY6f8iXVLyDgHvWSs6WHEJIeDLk48qEGEN9xcTXC ZdHtBq6QBQqynyjeorqKFuf4tG5WecHd8X3Sg6Vb33GLDN+Pl485XpohdaTt6B6CB5Ao h2WCpGHET8lKRUw0+Ix/XPny36Dte7Brqlut6R52J5uqMogVyv5xFWSgf5lN2plbkCk0 o4Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696314105; x=1696918905; 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=133KeprTV/vR0eagW5kUqY7IWB39BGwuNCAQ+zim7o4=; b=xEaAknFB3nbabNy/7rNmkoVt9BY3mv7WXjKbxCUK3Dshho/fNyEGA1uWLIli2Wlt50 oyYRrXbWMjVMh9381aqSEr07VuV2f+wUJG8v4XhVlZIv1Y0Tj4IGq47Ze19oCttW8W+1 eTft0D/dOjNNJf4z42nieuttMjTXAh9rnYAL9iKOxxJx/fJHXDr+yreVKDV4S3q1slEl 6sE0rn3BCTG03cGRdY+mUEiJsxySKU874mf8pNHNixfdCe5ctMJ00Nl6FMGdusMeXtOp la2njS85aTJYZdk5ARU6Bup+4d6xqeRYFJMIHODXw4KS/RvJgUM7bc+5doZ9yP/BlmBQ F9rg== X-Gm-Message-State: AOJu0Yw9GmL1ma40DFdMOZWfoj51cqMheo1+fLXBEEke5Pnm0gsjHatg 9coOyFcwOp1f4vxcFQG5X8o= X-Google-Smtp-Source: AGHT+IFhYTBjBHfhMFUCotjzWbttuBEwyUSRv7QwC4BeM31ftQMsgwzwjgEm4n5Yl4dNQShK8vtj3Q== X-Received: by 2002:a2e:a404:0:b0:2bc:b75e:b8b with SMTP id p4-20020a2ea404000000b002bcb75e0b8bmr12156803ljn.38.1696314104955; Mon, 02 Oct 2023 23:21:44 -0700 (PDT) Received: from xeon.. ([188.163.112.76]) by smtp.gmail.com with ESMTPSA id n4-20020a2e86c4000000b002bfba0d26bcsm103594ljj.8.2023.10.02.23.21.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 23:21:44 -0700 (PDT) From: Svyatoslav Ryhel To: Jaehoon Chung , Simon Glass , Jonas Karlman , Svyatoslav Ryhel , Eugen Hristev , Patrice Chotard , John Keeping Cc: u-boot@lists.denx.de Subject: [PATCH v4 2/4] test: dm: regulator: test counter in set_enable_if_allowed test Date: Tue, 3 Oct 2023 09:21:24 +0300 Message-Id: <20231003062126.42026-3-clamor95@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231003062126.42026-1-clamor95@gmail.com> References: <20231003062126.42026-1-clamor95@gmail.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 Emulate use of the regulator by a few consumers with balanced on/off calls. Signed-off-by: Svyatoslav Ryhel --- test/dm/regulator.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/dm/regulator.c b/test/dm/regulator.c index 86f4862d9d..33115daaf5 100644 --- a/test/dm/regulator.c +++ b/test/dm/regulator.c @@ -194,6 +194,24 @@ int dm_test_power_regulator_set_enable_if_allowed(struct unit_test_state *uts) ut_assertok(regulator_set_enable_if_allowed(dev, val_set)); ut_asserteq(regulator_get_enable(dev), !val_set); + /* Set the Enable of LDO1 - default is disabled */ + platname = regulator_names[LDO1][PLATNAME]; + ut_assertok(regulator_get_by_platname(platname, &dev)); + ut_assertok(regulator_set_enable_if_allowed(dev, true)); + + /* Get the Enable state of LDO1 and compare it with the requested one */ + ut_asserteq(regulator_get_enable(dev), true); + + /* Emulate second consumer */ + ut_assertok(regulator_set_enable_if_allowed(dev, true)); + ut_asserteq(regulator_get_enable(dev), true); + + /* Emulate one of counsumers disable call */ + ut_assertok(regulator_set_enable_if_allowed(dev, false)); + + /* Regulator should still be on since counter indicates one consumer active */ + ut_asserteq(regulator_get_enable(dev), true); + return 0; } DM_TEST(dm_test_power_regulator_set_enable_if_allowed, UT_TESTF_SCAN_FDT); From patchwork Tue Oct 3 06:21:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Svyatoslav Ryhel X-Patchwork-Id: 1842390 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YFGr7O6d; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S075n1h4wz1yph for ; Tue, 3 Oct 2023 17:22:21 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0D2C3871F2; Tue, 3 Oct 2023 08:21:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="YFGr7O6d"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5976286E15; Tue, 3 Oct 2023 08:21:49 +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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 619D287165 for ; Tue, 3 Oct 2023 08:21:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=clamor95@gmail.com Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2c022ce8114so5709791fa.1 for ; Mon, 02 Oct 2023 23:21:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696314106; x=1696918906; darn=lists.denx.de; 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=A8eoRsoVa32XOODjgTSNQ/eetbYwjwqVJhMmxh+PprY=; b=YFGr7O6d+4EwHdxnAuA9t56BV4TLv4fiiRzZkTVtPUZDJYiqBWZNzeMy0qwQ8Ljzhs 2UmB2d9lSrRTtaUJr3YJmRVTY9C+mVYuictRzCRKBL4R8+7hvQnhyhrtMO9UcXkQAleD OmjhqysznGLORszubA+dC3JxM7duqxEjFJ7fqD3YmgL813i//aBshUxywXNUVo4N9qBg trPi7UQSh6U0qJDErhdzWjSz1qt/G1TWBHgxCNP8+FNY0183F8mdYUpYhLu12qTPlQqR 3Lb1F/m/zmzDwnB51kpLaf25CWFJVNK8VOg/LIwgIE3w9/PnRAuorkc+paGJub/39sPR lm5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696314106; x=1696918906; 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=A8eoRsoVa32XOODjgTSNQ/eetbYwjwqVJhMmxh+PprY=; b=u95jbhhQNa16F82IhhGg/THcud7RvKVrzJfcd3DbQFZoQ5Dt0B8F7/bU+hnzVdNxej 21QwvC8GjNIPJwq7w9K9zqM1c4XvVHs0b6AEBQvjZcLTfkA6neWiCIC64+PrpahITWjf /kTk2tibH62HCBTYMZrk2jWNDdKFVIzne8Leoyq6M+Eo0rsoepFjT2b2Fb7AvWQJLkLe 2hnxKIuXUMjvV134HiAseUDOfxgoOgT1lK3lrKK/dyl6HA03Se4XtISHAyRM8oP6uaaq dCW9XJwTMgDTNyFUdtpQG6ItxRJfJFL92xBRdM3YPvSi2+toDiD5z0sHyH+yokQa5Xkh OLlw== X-Gm-Message-State: AOJu0Yz2fkEJmnz1netnDSSRodOdVgXuG0RwGxsZklREwiRib19oZcjC m5+GqbXhlHfK8J3qsyHwjPk= X-Google-Smtp-Source: AGHT+IGo/iSZdcLoVNNJC0Dqyl/9HzskVoVFw1iHVCky2MMUCXa8fluAQfEXV1m1X7HFrVkwZ5NjAg== X-Received: by 2002:a2e:86d3:0:b0:2c0:2e25:5730 with SMTP id n19-20020a2e86d3000000b002c02e255730mr10783351ljj.5.1696314105908; Mon, 02 Oct 2023 23:21:45 -0700 (PDT) Received: from xeon.. ([188.163.112.76]) by smtp.gmail.com with ESMTPSA id n4-20020a2e86c4000000b002bfba0d26bcsm103594ljj.8.2023.10.02.23.21.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 23:21:45 -0700 (PDT) From: Svyatoslav Ryhel To: Jaehoon Chung , Simon Glass , Jonas Karlman , Svyatoslav Ryhel , Eugen Hristev , Patrice Chotard , John Keeping Cc: u-boot@lists.denx.de Subject: [PATCH v4 3/4] power: regulator: Perform regulator setup inside uclass Date: Tue, 3 Oct 2023 09:21:25 +0300 Message-Id: <20231003062126.42026-4-clamor95@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231003062126.42026-1-clamor95@gmail.com> References: <20231003062126.42026-1-clamor95@gmail.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 Regulators initial setup was previously dependent on board call. To move from this behaviour next solution is proposed: on post_bind boot-on/always-on properties are checked, all regulators with such props will be probed just after binding which ensures that essential regulators are set, then in the post probe regulator autoset is called so that correct regulator state according to device tree is reached. Signed-off-by: Svyatoslav Ryhel [jonas@kwiboo.se: use autoset func, only probe with always/boot-on prop] Signed-off-by: Jonas Karlman --- drivers/power/regulator/regulator-uclass.c | 30 ++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c index 4b2c6c2964..69d6d6428d 100644 --- a/drivers/power/regulator/regulator-uclass.c +++ b/drivers/power/regulator/regulator-uclass.c @@ -473,6 +473,7 @@ static int regulator_post_bind(struct udevice *dev) { struct dm_regulator_uclass_plat *uc_pdata; const char *property = "regulator-name"; + int ret; uc_pdata = dev_get_uclass_plat(dev); @@ -486,13 +487,20 @@ static int regulator_post_bind(struct udevice *dev) return -EINVAL; } - if (regulator_name_is_unique(dev, uc_pdata->name)) - return 0; + ret = regulator_name_is_unique(dev, uc_pdata->name); + if (!ret) { + debug("'%s' of dev: '%s', has nonunique value: '%s'\n", + property, dev->name, uc_pdata->name); + return -EINVAL; + } - debug("'%s' of dev: '%s', has nonunique value: '%s\n", - property, dev->name, uc_pdata->name); + uc_pdata->always_on = dev_read_bool(dev, "regulator-always-on"); + uc_pdata->boot_on = dev_read_bool(dev, "regulator-boot-on"); - return -EINVAL; + if (uc_pdata->always_on || uc_pdata->boot_on) + dev_or_flags(dev, DM_FLAG_PROBE_AFTER_BIND); + + return 0; } static int regulator_pre_probe(struct udevice *dev) @@ -546,6 +554,17 @@ static int regulator_pre_probe(struct udevice *dev) return 0; } +static int regulator_post_probe(struct udevice *dev) +{ + int ret; + + ret = regulator_autoset(dev); + if (ret == -EMEDIUMTYPE || ret == -ENOSYS) + return 0; + + return ret; +} + int regulators_enable_boot_on(bool verbose) { struct udevice *dev; @@ -603,5 +622,6 @@ UCLASS_DRIVER(regulator) = { .name = "regulator", .post_bind = regulator_post_bind, .pre_probe = regulator_pre_probe, + .post_probe = regulator_post_probe, .per_device_plat_auto = sizeof(struct dm_regulator_uclass_plat), }; From patchwork Tue Oct 3 06:21:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Svyatoslav Ryhel X-Patchwork-Id: 1842391 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=nHmq1Muo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S075y55gVz1yph for ; Tue, 3 Oct 2023 17:22:30 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7377787208; Tue, 3 Oct 2023 08:21:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="nHmq1Muo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1B37886E15; Tue, 3 Oct 2023 08:21:50 +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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 328A8871BF for ; Tue, 3 Oct 2023 08:21:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=clamor95@gmail.com Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2c28e35752cso6392821fa.0 for ; Mon, 02 Oct 2023 23:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696314107; x=1696918907; darn=lists.denx.de; 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=bxLun/IMTTyxIze7X+jNwFBAftcmEXYSPcEWDswEHgg=; b=nHmq1MuoK0x1QMGIf1oURF7IhBbhjbhible3SZo+y7WoUkL3L1SVWmg9tgium5K2Zq jFpFl4PpMMX27RyFm0UZNz59pI5RkgjlQcdSpvnIyFA9QQytytNVn3Uu+cucl6Ti7TmA XTp1nXl6n5YVsAMf8v7P3MdTUVHlCg37ZOizWRPWTmytptdVxYkIBNS9MRVLCs5XSgAZ UWUQhRfYW4f8k4w3nA+Gbjztv/LgKvMfzkbq0DgtxeGK1ZkmMmd5wLdiHfACBa7B0HKG Fex+HcBQmdjHIENRhuPK7DKoiGHsDfaQbzthxR0nR4dtGClKkudExpZdBgzLFHumgVqS Rskg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696314107; x=1696918907; 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=bxLun/IMTTyxIze7X+jNwFBAftcmEXYSPcEWDswEHgg=; b=oxQ9IunM63x3qCDfoMC0N9/UAj5acHDG7waWvnkvvlDYQj9OdJN4SFpYQ9N0gumf/t P2LHkj2veQDgtrS1HPD30TexVbCAe9LAz96ibj34kY1oJdtqRooAJOjnCHZNTFnEQOnr kFlI7GZ6kvost039JGu+AMEZe1NHGDJeqdo34RHmLPZfOejeSMLiZqA8TCqLEvoBtk8o L00qR0PnOwemaFrHyngJQQrAuFtCDQAo/3ALDbT8RrT5rLAImy3TmWJkINBmLw0KSE1C v1aj529tterabEj0d8KkZETWU79YVVw8BrwwwafALGiuk4lHFRIbJ8dAC2WaBRna8uRl ONMg== X-Gm-Message-State: AOJu0Yx3TLvO5rUWuxXTIgK+pPvPB0GgVpUpw9tgTb5Seko2F19uutqy CY4PAr1UP25CA5Eiyni3RlA= X-Google-Smtp-Source: AGHT+IGAPZMJTXaNfz3Ag+rcRhMXNKSEHoXFrAMlegTBVj8efwUU6T2nE2mfCLW80Eaad5O6xSgTXQ== X-Received: by 2002:a05:651c:210b:b0:2c2:9514:d68f with SMTP id a11-20020a05651c210b00b002c29514d68fmr7913088ljq.32.1696314107442; Mon, 02 Oct 2023 23:21:47 -0700 (PDT) Received: from xeon.. ([188.163.112.76]) by smtp.gmail.com with ESMTPSA id n4-20020a2e86c4000000b002bfba0d26bcsm103594ljj.8.2023.10.02.23.21.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 23:21:47 -0700 (PDT) From: Svyatoslav Ryhel To: Jaehoon Chung , Simon Glass , Jonas Karlman , Svyatoslav Ryhel , Eugen Hristev , Patrice Chotard , John Keeping Cc: u-boot@lists.denx.de Subject: [PATCH v4 4/4] test: dm: regulator: provide test of auto setup Date: Tue, 3 Oct 2023 09:21:26 +0300 Message-Id: <20231003062126.42026-5-clamor95@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231003062126.42026-1-clamor95@gmail.com> References: <20231003062126.42026-1-clamor95@gmail.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 Adjust existing tests to pass with autosetup and so test if changes behave as expected. Signed-off-by: Svyatoslav Ryhel --- test/dm/regulator.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/dm/regulator.c b/test/dm/regulator.c index 33115daaf5..fbbbddbf72 100644 --- a/test/dm/regulator.c +++ b/test/dm/regulator.c @@ -168,7 +168,8 @@ static int dm_test_power_regulator_set_get_enable(struct unit_test_state *uts) /* Set the Enable of LDO1 - default is disabled */ platname = regulator_names[LDO1][PLATNAME]; ut_assertok(regulator_get_by_platname(platname, &dev)); - ut_assertok(regulator_set_enable(dev, val_set)); + /* LDO1 has boot-on property so enable should return -EALREADY */ + ut_asserteq(regulator_set_enable(dev, val_set), -EALREADY); /* Get the Enable state of LDO1 and compare it with the requested one */ ut_asserteq(regulator_get_enable(dev), val_set); @@ -187,7 +188,8 @@ int dm_test_power_regulator_set_enable_if_allowed(struct unit_test_state *uts) /* Get BUCK1 - always on regulator */ platname = regulator_names[BUCK1][PLATNAME]; - ut_assertok(regulator_autoset_by_name(platname, &dev_autoset)); + /* BUCK1 has always-on property so autoset should return -EALREADY */ + ut_asserteq(regulator_autoset_by_name(platname, &dev_autoset), -EALREADY); ut_assertok(regulator_get_by_platname(platname, &dev)); /* Try disabling always-on regulator */ @@ -307,7 +309,8 @@ static int dm_test_power_regulator_autoset(struct unit_test_state *uts) * Expected output state: uV=1200000; uA=200000; output enabled */ platname = regulator_names[BUCK1][PLATNAME]; - ut_assertok(regulator_autoset_by_name(platname, &dev_autoset)); + /* BUCK1 has always-on property so autoset should return -EALREADY */ + ut_asserteq(regulator_autoset_by_name(platname, &dev_autoset), -EALREADY); /* Check, that the returned device is proper */ ut_assertok(regulator_get_by_platname(platname, &dev));