From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBBC5346AC1 for ; Sat, 28 Feb 2026 18:08:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772302104; cv=none; b=rHn8cu5CjPYliugmdwYEHoVknLnMiTMmqNFYo3TVHxuhQm3gUteQkGhAZXGeQivV32ZdMUV1DUmJrPozgpf8AGCXYeA+8098lT870jtE9OVdBLJY03oGla7cFKn95O0I9XEtkekjf4zYUwPTemi26cnKixeEoPMsgiQD2SbB9H8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772302104; c=relaxed/simple; bh=Nrz/TmmQJCGxSnFhStX7kGxpfWZbIpXq9SqsN3DbbX4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EGWyEkj8yIB4yYj48Z1Ol0EBg9wn3oRaFdULfWjj4KZjFjYRfJfnvfrpzVbNhp78fFREcMop2RmjeEPPfbwTgmN9FI+wEBTUXHKXv3o3ZQeIM5+i71AT1oNgGiPJTAZ/K1916FvWTgKgfJ0GzxA65LgPLEqfNKGp6XFI4rZK8+k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kl0PrU7Y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kl0PrU7Y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D229EC116D0; Sat, 28 Feb 2026 18:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772302104; bh=Nrz/TmmQJCGxSnFhStX7kGxpfWZbIpXq9SqsN3DbbX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kl0PrU7YOz2RTcvL1us6DSZF16Mp7f1h+vHxMiOagjBmrtgTA/IHZNwRuVgPFEGkj TNw1hbtemZhjul8SRdFtLAd7mD4fQJ8K7o5EjcJGisKT9DH2Ys1FvooZl0X2NcEFcp Xwp63ZmFWSjVkiwLjxXvBsS/ap5IuUhqTymwjQXcXV808vG0woamJ336bTi/xU8bgy 1AJ221xn2RjHoWkCEONXLmwZJdHHDPobYj+qx0gDMQAFPTvob9xvbP3ccDVaQSzkS+ rS2+LPdIaCThSHfFwazWwy6zoVVg/usz97lBjhLRnweB5peG8IJruR27HGkVaLnuu5 F7LKiRP/SjGdQ== From: Sasha Levin To: patches@lists.linux.dev Cc: =?UTF-8?q?Andr=C3=A9=20Draszik?= , Mark Brown , Sasha Levin Subject: [PATCH 6.6 091/283] regulator: core: move supply check earlier in set_machine_constraints() Date: Sat, 28 Feb 2026 13:03:53 -0500 Message-ID: <20260228180709.1583486-91-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260228180709.1583486-1-sashal@kernel.org> References: <20260228180709.1583486-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: André Draszik [ Upstream commit 86a8eeb0e913f4b6a55dabba5122098d4e805e55 ] Since commit 98e48cd9283d ("regulator: core: resolve supply for boot-on/always-on regulators"), set_machine_constraints() can return -EPROBE_DEFER very late, after it has done a lot of work and configuration of the regulator. This means that configuration will happen multiple times for no benefit in that case. Furthermore, this can lead to timing-dependent voltage glitches as mentioned e.g. in commit 8a866d527ac0 ("regulator: core: Resolve supply name earlier to prevent double-init"). We can know that it's going to fail very early, in particular before going through the complete regulator configuration by moving some code around a little. Do so to avoid re-configuring the regulator multiple times, also avoiding the voltage glitches if we can. Fixes: 98e48cd9283d ("regulator: core: resolve supply for boot-on/always-on regulators") Signed-off-by: André Draszik Link: https://patch.msgid.link/20260109-regulators-defer-v2-3-1a25dc968e60@linaro.org Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/regulator/core.c | 55 ++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 23cdf220ca7db..a1a26743430c0 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1466,6 +1466,33 @@ static int set_machine_constraints(struct regulator_dev *rdev) int ret = 0; const struct regulator_ops *ops = rdev->desc->ops; + /* + * If there is no mechanism for controlling the regulator then + * flag it as always_on so we don't end up duplicating checks + * for this so much. Note that we could control the state of + * a supply to control the output on a regulator that has no + * direct control. + */ + if (!rdev->ena_pin && !ops->enable) { + if (rdev->supply_name && !rdev->supply) + return -EPROBE_DEFER; + + if (rdev->supply) + rdev->constraints->always_on = + rdev->supply->rdev->constraints->always_on; + else + rdev->constraints->always_on = true; + } + + /* + * If we want to enable this regulator, make sure that we know the + * supplying regulator. + */ + if (rdev->constraints->always_on || rdev->constraints->boot_on) { + if (rdev->supply_name && !rdev->supply) + return -EPROBE_DEFER; + } + ret = machine_constraints_voltage(rdev, rdev->constraints); if (ret != 0) return ret; @@ -1631,37 +1658,15 @@ static int set_machine_constraints(struct regulator_dev *rdev) } } - /* - * If there is no mechanism for controlling the regulator then - * flag it as always_on so we don't end up duplicating checks - * for this so much. Note that we could control the state of - * a supply to control the output on a regulator that has no - * direct control. - */ - if (!rdev->ena_pin && !ops->enable) { - if (rdev->supply_name && !rdev->supply) - return -EPROBE_DEFER; - - if (rdev->supply) - rdev->constraints->always_on = - rdev->supply->rdev->constraints->always_on; - else - rdev->constraints->always_on = true; - } - /* If the constraints say the regulator should be on at this point * and we have control then make sure it is enabled. */ if (rdev->constraints->always_on || rdev->constraints->boot_on) { bool supply_enabled = false; - /* If we want to enable this regulator, make sure that we know - * the supplying regulator. - */ - if (rdev->supply_name && !rdev->supply) - return -EPROBE_DEFER; - - /* If supplying regulator has already been enabled, + /* We have ensured a potential supply has been resolved above. + * + * If supplying regulator has already been enabled, * it's not intended to have use_count increment * when rdev is only boot-on. */ -- 2.51.0