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 A9D28C001DC for ; Sat, 15 Jul 2023 18:35:09 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CA2CC861C3; Sat, 15 Jul 2023 20:34:54 +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="IVpNjW+b"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4B0098619C; Sat, 15 Jul 2023 20:34:51 +0200 (CEST) Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (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 E15F98618E for ; Sat, 15 Jul 2023 20:34: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-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fbd33a57ddso28267015e9.1 for ; Sat, 15 Jul 2023 11:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689446088; x=1692038088; 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=tUm6XYVspbbRaAbAZXR+NqacDVcUrosRd8Ob1yElUU0=; b=IVpNjW+bq8KuwMPFlTkk97ZnbTXv/YloptetnF5gba7QoPM7EJoDgWrk233t09yWWf q6hFfNnryjuBDNBgbRE16QWhu7uMjdduLzC8ryql/KjmUD+D0R5Mq01IuxsS1rDUGP12 0DliKVqMaz4lmqc/wuWhHSUk0pk2IfmPQvQmj+HU2NgHqBSGAZUddVm/zJ7PEwyxeHqI KP+Po1hfbPQzToXsU1SsmvNENAIC48cckQgAwHxc9+a3h8KQi9iFPujOATw5K0DH1JcO CZuSNiDFDOj9RSM+wTUccC9UNWAIXxJ3s2Gu7boh82R4Oba2/8a7IznVG0iz6A94Ct97 QZvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689446088; x=1692038088; 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=tUm6XYVspbbRaAbAZXR+NqacDVcUrosRd8Ob1yElUU0=; b=lM650mxEhDuekrEYL0rYEXE1464fhfctkX4HEZPHa8vnFRB9GMJeg+CEvwWg/xzms0 fnYS89UFVfhMeFn2e/7KiWIpr97NuvB7O7R3zaM9XQWa727kOvfF6GHfOpeCCe6mCoBi KGt2ahe/zrVZqx4/32W4Ip1AZaPphBfmi0O2w8tRNw1ypkTvAjsC8md4IfBRt5YDTp1q gBm5yOeGBhfdAyeJEUwdGj+2PxGLpYC5IfGGsqll0In5vGnt75XnJzX8ak6TX5MtHcku ENEBP41sbBizdyo3IMTr5x7c5WbtwvbMRGl3m6UZg2SEt0cOWXwU/gB/gVU2x1/RGYur NcsA== X-Gm-Message-State: ABy/qLYLSaN09rzr9zF3FsrEbc9ruJrv+CIybOqmeGSg2t8sas7O9pGx BWVP/X8vjIseaOs29wWo3+I= X-Google-Smtp-Source: APBJJlHxJUL/1qooSrPvoOmbPhbFvXpz2a/J0JoyST5FVzkIodRx71GlyPT+CYAWKJdq90H3wUJBlA== X-Received: by 2002:a05:6000:11c4:b0:314:a0:6363 with SMTP id i4-20020a05600011c400b0031400a06363mr7359266wrx.50.1689446088130; Sat, 15 Jul 2023 11:34:48 -0700 (PDT) Received: from xeon.. ([188.163.112.64]) by smtp.gmail.com with ESMTPSA id j1-20020a5d4641000000b0031434936f0dsm14365073wrs.68.2023.07.15.11.34.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jul 2023 11:34:47 -0700 (PDT) From: Svyatoslav Ryhel To: Jaehoon Chung , Simon Glass , Patrick Delaunay , Svyatoslav Ryhel Cc: u-boot@lists.denx.de Subject: [PATCH v2 2/2] power: pmic: fix regulators behaviour Date: Sat, 15 Jul 2023 21:34:31 +0300 Message-Id: <20230715183431.5318-3-clamor95@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230715183431.5318-1-clamor95@gmail.com> References: <20230715183431.5318-1-clamor95@gmail.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 Currently device tree entries of regulators are completely ignored and regulators are probed only if they are called by the device which uses it. This results into two issues: regulators which must run under boot-on or always-on mode are ignored and not enabled; dts props like voltage are not applied to the regulator so the regulator may be enabled with random actual voltage, which may have unexpected consequences. This patch changes this behavior. Post-probe function is introduced which performs probing of each pmics child and if it is a regulator, regulator_autoset function is called, which handles always-on and boot-on regulators, but if none of those props are set, the regulator is disabled. Later disabled regulators can be re-enabled by devices which use them without issues. Signed-off-by: Svyatoslav Ryhel --- drivers/power/pmic/pmic-uclass.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/power/pmic/pmic-uclass.c b/drivers/power/pmic/pmic-uclass.c index 0e2f5e1f41..8a26b519c9 100644 --- a/drivers/power/pmic/pmic-uclass.c +++ b/drivers/power/pmic/pmic-uclass.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #if CONFIG_IS_ENABLED(PMIC_CHILDREN) @@ -198,9 +199,26 @@ static int pmic_pre_probe(struct udevice *dev) return 0; } +static int pmic_post_probe(struct udevice *dev) +{ + struct udevice *child; + int ret; + + device_foreach_child_probe(child, dev) { + if (device_get_uclass_id(child) == UCLASS_REGULATOR) { + ret = regulator_autoset(child); + if (ret == -EMEDIUMTYPE) + regulator_set_enable(child, false); + }; + }; + + return 0; +} + UCLASS_DRIVER(pmic) = { .id = UCLASS_PMIC, .name = "pmic", .pre_probe = pmic_pre_probe, + .post_probe = pmic_post_probe, .per_device_auto = sizeof(struct uc_pmic_priv), }; -- 2.39.2