From nobody Wed Dec 17 08:19:08 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 048F2C7618E for ; Fri, 21 Apr 2023 09:13:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231442AbjDUJN0 (ORCPT ); Fri, 21 Apr 2023 05:13:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbjDUJNV (ORCPT ); Fri, 21 Apr 2023 05:13:21 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40C141998 for ; Fri, 21 Apr 2023 02:13:20 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-94f109b1808so229725066b.1 for ; Fri, 21 Apr 2023 02:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682068398; x=1684660398; 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=Xxxa39sRYsIqUGyxDA0sj3TJcO5atZMPoDeI65I6qiA=; b=UD8IgWBqREhpJJAyEJjTmgocAe8i1Yzp1Ysg5Qcf6sZYHjL8eCs1ZF44BC5lyUsf+r tCSHj/PvyuUckcDSlN++V+4lc+u0wOEZBegwINUCrYAM0hhOTUrgeoEvw8Z6rCaFF3ag 1FKRcT+vLlqB2mf7TnCbEptPqY/d3+FwcQzLNUHouYwCJ8ApmiMkjDJ63YWuq3M1r2Yg hWQtGgmh8nn+BO+6HWjCmrO8CgXd4orNf4CP6P7+eshAqZfhVjwUodxzdpzrXBmZQItI YyLoe/m4jWvgdDbaD9y8ujRCxGNVZonumwXuVRfTWz3kBH/STuVV2+8rIpqaa1u9YhI5 z/cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682068398; x=1684660398; 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=Xxxa39sRYsIqUGyxDA0sj3TJcO5atZMPoDeI65I6qiA=; b=YntA+xRsB45swb6M5wVYS+R2Ed7mpIM4j8RovgqAWoAwdkMn4tRVcgsYyh/YleO4oR JWX01FNl8yLPH8K7IOhLeEOS/KUkEEHTZWtUI4cVqTUI45DB4EXGU/4jOUApQaWwfE0d hRqeKCiWYnml946LHcjz20MDKrocV59REVXcAw+mpLMLktEmiyMIvLWoe3mzEHvMh1el zwW4UsL9b2L4D4B7LwMFmzgF/R9GUg4TPdXFrCKoRbgsKdtEyQW2IC5JIEepPowUyOU0 bZ1fkQH1z9t+Kcme7TnR2P7Dy2V64pYWrG1P+NlBFHaOKCFVhBk3V7vUwxypH7RbpuFj u8KA== X-Gm-Message-State: AAQBX9ddmJyi6aZMhNdmqzG7MSAH5bFKswX1RFiFuGBjGHCdK+2HcA6m 3FeuHQyHF55Sr4/IYwDtGAfyI75vYDsLX48H X-Google-Smtp-Source: AKy350Z51fHEnOiBFDpJWjgPvurG7DtFxu7CEeEObtuo/rubpZjMoHFef84+2ho8sa9l5xZn4+nsvQ== X-Received: by 2002:a17:906:269b:b0:94e:4fe5:613a with SMTP id t27-20020a170906269b00b0094e4fe5613amr1595454ejc.25.1682068398437; Fri, 21 Apr 2023 02:13:18 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id lc21-20020a170906dff500b0094ef10eceb3sm1766775ejc.185.2023.04.21.02.13.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 02:13:18 -0700 (PDT) From: Benjamin Bara Date: Fri, 21 Apr 2023 11:13:06 +0200 Subject: [PATCH RFC v2 1/2] regulator: add properties to disable monitoring on actions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230419-dynamic-vmon-v2-1-c303bcc75ebc@skidata.com> References: <20230419-dynamic-vmon-v2-0-c303bcc75ebc@skidata.com> In-Reply-To: <20230419-dynamic-vmon-v2-0-c303bcc75ebc@skidata.com> To: Liam Girdwood , Mark Brown , support.opensource@diasemi.com Cc: DLG-Adam.Ward.opensource@dm.renesas.com, 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 These are useful when the state of the regulator might change during runtime, but the monitors state (in hardware) are not implicitly changed with the change of the regulator state or mode (in hardware). Also, when the monitors should be disabled while ramping after a set_value(). Signed-off-by: Benjamin Bara --- drivers/regulator/core.c | 64 ++++++++++++++++++++++++++++++++++++= ---- include/linux/regulator/driver.h | 10 +++++++ 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 4fcd36055b02..5052e1da85a7 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1360,7 +1360,7 @@ static int notif_set_limit(struct regulator_dev *rdev, =20 static int handle_notify_limits(struct regulator_dev *rdev, int (*set)(struct regulator_dev *, int, int, bool), - struct notification_limit *limits) + const struct notification_limit *limits) { int ret =3D 0; =20 @@ -1385,6 +1385,29 @@ static int handle_notify_limits(struct regulator_dev= *rdev, =20 return ret; } + +static const struct notification_limit disable_limits =3D { + .prot =3D REGULATOR_NOTIF_LIMIT_DISABLE, + .err =3D REGULATOR_NOTIF_LIMIT_DISABLE, + .warn =3D REGULATOR_NOTIF_LIMIT_DISABLE, +}; + +static int monitors_set_state(struct regulator_dev *rdev, bool enable) +{ + const struct regulation_constraints *reg_c =3D rdev->constraints; + const struct regulator_ops *ops =3D rdev->desc->ops; + int ret =3D 0; + + /* only set the state if monitoring is activated in the device-tree. */ + if (reg_c->over_voltage_detection) + ret =3D handle_notify_limits(rdev, ops->set_over_voltage_protection, + enable ? ®_c->over_voltage_limits : &disable_limits); + if (!ret && reg_c->under_voltage_detection) + ret =3D handle_notify_limits(rdev, ops->set_under_voltage_protection, + enable ? ®_c->under_voltage_limits : &disable_limits); + return ret; +} + /** * set_machine_constraints - sets regulator constraints * @rdev: regulator source @@ -1512,7 +1535,7 @@ static int set_machine_constraints(struct regulator_d= ev *rdev) "IC does not support requested over-current limits\n"); } =20 - if (rdev->constraints->over_voltage_detection) + if (rdev->constraints->over_voltage_detection && !rdev->desc->mon_disable= _while_reg_off) ret =3D handle_notify_limits(rdev, ops->set_over_voltage_protection, &rdev->constraints->over_voltage_limits); @@ -1526,7 +1549,7 @@ static int set_machine_constraints(struct regulator_d= ev *rdev) "IC does not support requested over voltage limits\n"); } =20 - if (rdev->constraints->under_voltage_detection) + if (rdev->constraints->under_voltage_detection && !rdev->desc->mon_disabl= e_while_reg_off) ret =3D handle_notify_limits(rdev, ops->set_under_voltage_protection, &rdev->constraints->under_voltage_limits); @@ -2734,7 +2757,10 @@ static int _regulator_do_enable(struct regulator_dev= *rdev) =20 trace_regulator_enable_complete(rdev_get_name(rdev)); =20 - return 0; + if (rdev->desc->mon_disable_while_reg_off) + ret =3D monitors_set_state(rdev, true); + + return ret; } =20 /** @@ -2893,7 +2919,12 @@ EXPORT_SYMBOL_GPL(regulator_enable); =20 static int _regulator_do_disable(struct regulator_dev *rdev) { - int ret; + int ret =3D 0; + + if (rdev->desc->mon_disable_while_reg_off) + ret =3D monitors_set_state(rdev, false); + if (ret) + return ret; =20 trace_regulator_disable(rdev_get_name(rdev)); =20 @@ -3537,7 +3568,7 @@ static int _regulator_set_voltage_time(struct regulat= or_dev *rdev, static int _regulator_do_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) { - int ret; + int ret =3D 0; int delay =3D 0; int best_val =3D 0; unsigned int selector; @@ -3545,6 +3576,11 @@ static int _regulator_do_set_voltage(struct regulato= r_dev *rdev, const struct regulator_ops *ops =3D rdev->desc->ops; int old_uV =3D regulator_get_voltage_rdev(rdev); =20 + if (rdev->desc->mon_disable_while_reg_set) + ret =3D monitors_set_state(rdev, false); + if (ret) + return ret; + trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV); =20 min_uV +=3D rdev->constraints->uV_offset; @@ -3636,6 +3672,10 @@ static int _regulator_do_set_voltage(struct regulato= r_dev *rdev, out: trace_regulator_set_voltage_complete(rdev_get_name(rdev), best_val); =20 + if (rdev->desc->mon_disable_while_reg_set) + /* TODO: ignore return value here when ret already !0? */ + ret =3D monitors_set_state(rdev, true); + return ret; } =20 @@ -4545,7 +4585,19 @@ int regulator_set_mode(struct regulator *regulator, = unsigned int mode) if (ret < 0) goto out; =20 + if (mode & rdev->desc->mon_unsupported_reg_modes) + ret =3D monitors_set_state(rdev, false); + if (ret) + goto out; + ret =3D rdev->desc->ops->set_mode(rdev, mode); + if (ret) + goto out; + + if (mode & ~rdev->desc->mon_unsupported_reg_modes) + /* TODO: if set_mode fails, we stay unmonitored */ + ret =3D monitors_set_state(rdev, true); + out: regulator_unlock(rdev); return ret; diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/dri= ver.h index d3b4a3d4514a..2fdc2c78e4bd 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -357,6 +357,12 @@ enum regulator_type { * the regulator was actually enabled. Max upto enable= _time. * * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standar= d mode + * + * @mon_disable_while_reg_off: Disables regulator's monitors while it is o= ff. + * @mon_disable_while_reg_set: Disables regulator's monitors while it is c= hanging its value. + * @mon_unsupported_reg_modes: Disables regulator's monitors before an uns= upported mode is entered. + * Unsupported REGULATOR_MODE_* are OR'ed. REG= ULATOR_MODE_INVALID means + * all modes can be monitored. */ struct regulator_desc { const char *name; @@ -431,6 +437,10 @@ struct regulator_desc { unsigned int poll_enabled_time; =20 unsigned int (*of_map_mode)(unsigned int mode); + + unsigned int mon_disable_while_reg_off; + unsigned int mon_disable_while_reg_set; + unsigned int mon_unsupported_reg_modes; }; =20 /** --=20 2.34.1 From nobody Wed Dec 17 08:19:08 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 73CF0C77B78 for ; Fri, 21 Apr 2023 09:13:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231841AbjDUJN2 (ORCPT ); Fri, 21 Apr 2023 05:13:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231495AbjDUJNW (ORCPT ); Fri, 21 Apr 2023 05:13:22 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 290A91BE3 for ; Fri, 21 Apr 2023 02:13:21 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-94ed301bba0so224987066b.0 for ; Fri, 21 Apr 2023 02:13:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682068399; x=1684660399; 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=NsvjETPrSb0GWQ9sM/isFsteBwM2pPLGbwlCMDf8cJ0=; b=VoxFnSfNnwsiWr1ptqTWWm+K9ejzFS9hfugiOPnQMWYCzOivvb1jjHf0C/l7I0N/Jb 3kHZbYx0DNxcprD5Q+3cQQoGsFp8vf6IZO52VGtg4m7gilNRdhbLeCjAePWXazekukSJ oVixvaBQX/6mxBjy6p21GE89t1k7E294Or28K4V51uHA4PXSQ1KOzBBt34UZy+vx8660 XXAgzJRn0uXPK7325LZ4IKP7U5vh4Z9VMoXWNGJLTsJG/ES4mBjXJ1izk6zonCmxTiyE J9yIV35quGrC+CpKg2VWw/FUy9FtlCB4JlBWje0z55HCmRZ/mcTv032X7SRsQo1zsU7j 9kAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682068399; x=1684660399; 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=NsvjETPrSb0GWQ9sM/isFsteBwM2pPLGbwlCMDf8cJ0=; b=V16ySRXUJ4/05Eg7K0lhzveku8Ve5XIaGcqqLm6aoMbe3+rN1vat1Dr0PFeVvrlUop Lb49lZhkcAdvtm74ip+DJXzejm1iJLHTyulQQI2PPX308+TzgrAMvW6iVNJePLgg3EcZ 7BHF51Ns/4n1BimY5QIIuGzKer/4hAS8bi1svlj3IfGNBi++6TCdoHu4HCz2iay4uu5K WcmJs0CUEI5P2wY+4u3m38IGN/u+19tNJzASB2xCBGr8HRWPHkPmtxd5xzd/S/3Zaah2 PnuQtfaED7NwCkDCWelGTf0CWE3zMGCdU6H1IZ6hUO8AZulgyTZQfmsNKyG8oxlqs7gD MuJA== X-Gm-Message-State: AAQBX9eQN92C9WnKO0B2/OO7KtqXwOCINSPgtX5xnn2dAxfmjwz/gknM iW4BY9Zo+OYZo7AIXCPbGRNjVJXR6n+Qb/MP X-Google-Smtp-Source: AKy350YGpqDTKeFNfnN4Qluc5ERf07kq2FSx7YQ3Ph95dGocKdY5U8RZH4fX5c+T4K2aSxrBdBD8zg== X-Received: by 2002:a17:906:cc5b:b0:94e:c43f:316b with SMTP id mm27-20020a170906cc5b00b0094ec43f316bmr1661374ejb.19.1682068399351; Fri, 21 Apr 2023 02:13:19 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id lc21-20020a170906dff500b0094ef10eceb3sm1766775ejc.185.2023.04.21.02.13.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 02:13:19 -0700 (PDT) From: Benjamin Bara Date: Fri, 21 Apr 2023 11:13:07 +0200 Subject: [PATCH RFC v2 2/2] regulator: da9063: disable monitoring while regulator is off MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230419-dynamic-vmon-v2-2-c303bcc75ebc@skidata.com> References: <20230419-dynamic-vmon-v2-0-c303bcc75ebc@skidata.com> In-Reply-To: <20230419-dynamic-vmon-v2-0-c303bcc75ebc@skidata.com> To: Liam Girdwood , Mark Brown , support.opensource@diasemi.com Cc: DLG-Adam.Ward.opensource@dm.renesas.com, 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 The PWR_OK state of the da9063 indicates whether all monitored voltages are within the expected range. When a regulator is disabled without disabling its voltage monitor before, the PWR_OK state becomes false. On our board, this invalid state leads to a hard reset. Therefore, prevent the invalid state by disabling the monitor before the regulator is disabled. This still requires to explicitly enable the voltage monitor in the device tree and has no impact otherwise. TODO: clarify if a MODE change has impact on the voltage monitor Signed-off-by: Benjamin Bara --- drivers/regulator/da9063-regulator.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da906= 3-regulator.c index 82f52a2a031a..13a6b189f23a 100644 --- a/drivers/regulator/da9063-regulator.c +++ b/drivers/regulator/da9063-regulator.c @@ -99,6 +99,7 @@ struct da9063_regulator_info { .desc.vsel_reg =3D DA9063_REG_V##regl_name##_A, \ .desc.vsel_mask =3D DA9063_V##regl_name##_MASK, \ .desc.linear_min_sel =3D DA9063_V##regl_name##_BIAS, \ + .desc.mon_disable_while_reg_off =3D 1, \ .sleep =3D BFIELD(DA9063_REG_V##regl_name##_A, DA9063_LDO_SL), \ .suspend =3D BFIELD(DA9063_REG_##regl_name##_CONT, DA9063_LDO_CONF), \ .suspend_sleep =3D BFIELD(DA9063_REG_V##regl_name##_B, DA9063_LDO_SL), \ @@ -124,6 +125,7 @@ struct da9063_regulator_info { .desc.vsel_reg =3D DA9063_REG_V##regl_name##_A, \ .desc.vsel_mask =3D DA9063_VBUCK_MASK, \ .desc.linear_min_sel =3D DA9063_VBUCK_BIAS, \ + .desc.mon_disable_while_reg_off =3D 1, \ .sleep =3D BFIELD(DA9063_REG_V##regl_name##_A, DA9063_BUCK_SL), \ .suspend =3D BFIELD(DA9063_REG_##regl_name##_CONT, DA9063_BUCK_CONF), \ .suspend_sleep =3D BFIELD(DA9063_REG_V##regl_name##_B, DA9063_BUCK_SL), \ --=20 2.34.1