From nobody Wed Dec 17 10:03:53 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DE63EB64D7 for ; Tue, 20 Jun 2023 20:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230072AbjFTUEF (ORCPT ); Tue, 20 Jun 2023 16:04:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbjFTUDl (ORCPT ); Tue, 20 Jun 2023 16:03:41 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8F7F10F0 for ; Tue, 20 Jun 2023 13:03:39 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-519f6e1a16cso6065336a12.2 for ; Tue, 20 Jun 2023 13:03:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687291418; x=1689883418; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2RVAC+ZaZODWJ+QFQBc3rYxuHiijX92xEaSVhSFgl3o=; b=mrVUpP3jn3SF8dK4Gd4pciXBMZDMGoWleyLtt8d4i0veouLd5ObXCGZhqq0qS8tZpS LHWE09xVNGj7BeUgVg1UYLBLa4lOjz9ghVQBYCOY7kdssPocZuEhZhSJJqiTutcR+O6Z vN9HKSNk4gPyIkyxNnWbq2uJFBmV8gW5gUB1aYN18CiuCVB0t5Wao8I2tIidUiHi8Fni 4PqNZNU1aiYdWsD2fKEOljz6nx3GITQCBdjjZVoaAn6mDv4DKQ+G2rcTrhOL9pC/jI6T 4aT0I+e0AFcs8sGGZ293V7yhku4PsJOhO285z/DIhUbUQaWEeSKz000q+SYSJ9Er++bq xh6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687291418; x=1689883418; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2RVAC+ZaZODWJ+QFQBc3rYxuHiijX92xEaSVhSFgl3o=; b=V5/zO1qUNKCAK5KQxzZauKyd62VUapC23OfqWKofhkbXD5CChnvg3b64c/D0laybJd fx/GoykqkMtxVwyU/UZzYY5tx5p0kCc8rAITN/43D/oLWZnJjJj/Jttoix8FeAtIWSZP 6FZJvntduBuatk6F2iL6sJQj4LTl1neIfbaSJkwfAmQ9eYP6pysvJU3ZYS5Npsmj0HNj 1CvdEgu52nSGdMoPqKVFQuDC4k779IioTvKqYr6o/w2Y7payqoFH+kA33g8QUNBOaQdI IKupNQM7v3URvEoX2cSJ7s9VLBCwWMJRyvIsjKKYGgyR3uCX5ODK/LiMTrgmPNBfi33b pSSg== X-Gm-Message-State: AC+VfDyUm+sxOaEeLBUgrvK0RiMHnfWCGJ4lqxt7/zOhh2qgyuPfcSBm FnTJlfSzgG7XMiaEtoJ4zoH0LSfjLZ+jZQ== X-Google-Smtp-Source: ACHHUZ5bp7x5munn1VtEk7+2qSwrdlsaEXcT/zqtu43LDIo0364bHeI2Z5XRriP+opDt0q/EU4hBqg== X-Received: by 2002:a17:907:9453:b0:987:47b3:6e34 with SMTP id dl19-20020a170907945300b0098747b36e34mr8704687ejc.67.1687291418327; Tue, 20 Jun 2023 13:03:38 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id u21-20020a17090617d500b00977e0bcff1esm1947064eje.10.2023.06.20.13.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 13:03:37 -0700 (PDT) From: Benjamin Bara Date: Tue, 20 Jun 2023 22:03:00 +0200 Subject: [PATCH RFC v4 07/13] regulator: find active protections during initialization MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230419-dynamic-vmon-v4-7-4d3734e62ada@skidata.com> References: <20230419-dynamic-vmon-v4-0-4d3734e62ada@skidata.com> In-Reply-To: <20230419-dynamic-vmon-v4-0-4d3734e62ada@skidata.com> To: Liam Girdwood , Mark Brown Cc: support.opensource@diasemi.com, DLG-Adam.Ward.opensource@dm.renesas.com, Martin Fuzzey , linux-kernel@vger.kernel.org, Matti Vaittinen , Benjamin Bara X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Bara It can happen that monitors are activated before the kernel is started, e.g. by bootloader or by OTP. If monitoring workarounds are active on a regulator, the core shouldn't perform the state changes without applying the workaround to the regulator. Therefore, warn the user already during initialization that the device-tree should be adapted. Warning can be fixed by enabling (or disabling) monitoring in the DT, e.g.: regulator-uv-protection-microvolt =3D <1>; or regulator-ov-error-microvolt =3D <0>; Constraints regarding the monitoring of a regulator can usually be found in the docu. Signed-off-by: Benjamin Bara --- drivers/regulator/core.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index ca5d6ba889dc..9bddab17450e 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1564,6 +1564,47 @@ static int set_machine_constraints(struct regulator_= dev *rdev) } } =20 + /* + * When the core is in charge of handling monitoring workarounds, + * it is essential to know if a monitor is already active during + * initialization. + */ + if (rdev->desc->mon_disable_reg_disabled || + rdev->desc->mon_disable_reg_set_higher || + rdev->desc->mon_disable_reg_set_lower || + rdev->desc->mon_unsupported_reg_modes) { + unsigned int monitor_state =3D REGULATOR_MONITOR_NONE; + + ret =3D ops->get_active_protections(rdev, &monitor_state); + if (ret) + return ret; + + if (!rdev->constraints->over_voltage_detection && + (monitor_state & REGULATOR_MONITOR_OVER_VOLTAGE)) { + rdev_err(rdev, "dt unaware of active %s monitor!\n", + "over-voltage"); + return -EINVAL; + } + if (!rdev->constraints->under_voltage_detection && + (monitor_state & REGULATOR_MONITOR_UNDER_VOLTAGE)) { + rdev_err(rdev, "dt unaware of active %s monitor!\n", + "under-voltage"); + return -EINVAL; + } + if (!rdev->constraints->over_current_detection && + (monitor_state & REGULATOR_MONITOR_OVER_CURRENT)) { + rdev_err(rdev, "dt unaware of active %s monitor!\n", + "over-current"); + return -EINVAL; + } + if (!rdev->constraints->over_temp_detection && + (monitor_state & REGULATOR_MONITOR_OVER_TEMPERATURE)) { + rdev_err(rdev, "dt unaware of active %s monitor!\n", + "over-temperature"); + return -EINVAL; + } + } + if (rdev->constraints->over_current_detection) ret =3D handle_notify_limits(rdev, ops->set_over_current_protection, --=20 2.34.1