From nobody Sun Feb 8 19:55:28 2026 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 6255AC7EE32 for ; Sun, 21 May 2023 11:47:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231158AbjEULrL (ORCPT ); Sun, 21 May 2023 07:47:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230225AbjEULqF (ORCPT ); Sun, 21 May 2023 07:46:05 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C500E47 for ; Sun, 21 May 2023 04:40:07 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-95fde138693so516268066b.0 for ; Sun, 21 May 2023 04:40:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684669205; x=1687261205; 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=8BVvd2yufw+BLykR/+MC80568t6BgpSllPFSORcsVX0=; b=Iaa2CzKYihonZCk28eUqTHfkbfErQX4rt6s/pwZQnvx1MrCh1LxXNhzvEcSU53kHFX Jatya+bPkiX0R9X1dLXu6w7gZh8DuROxd4JkC4FvhJ+6dNis5tli3b4NiZ22OSAxyY5Y Tsx7qijFN96IOaqeE+6NNZ3ZeB92oeMFtSllKYC+0Kb4ioNv+ulm1GIpjVmw9LFXoIu4 IABNOzvA6WBDknXrA/W+89a0GPbja/0J8KPZzu25WxAjfepkhY7zQsPjzJ+Z9z8Ohn69 uoAV8HW10fDSe5CCeapMVvWc8K8g14f8XpycRZNxC6cHSpMj/16Ok6aAKK1xYezcqyPo CkQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684669205; x=1687261205; 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=8BVvd2yufw+BLykR/+MC80568t6BgpSllPFSORcsVX0=; b=G1HGOIFQ/0YbD2zizcdyD/SXWgne/0WLlzGVoW2u7SRqCRUMi06D4Hr0kZaUaNzzlP OwEOwGkSC+uQ4pIJMumtLCmT+IZNFWguKBQ7SveoZjsSv46j3pfKPfdOiM0ltDi/fExh P/YQM2scJ76XdtQwuCgNCEgbecjq/vBJUmzScVtxUpzW2Qt6sSjqLjHVHr/FP7h66fGq nOm0SF5qo3Eb2qOkPosuwYFRlQbibQVhRfp0kRtKeZJfkQzX6GC8WHpsxkTbVyb8lYsH Fl+OZxecB9PjenpEjXgGKo9t+3Q/5GIxU/OTW2Mm2h9H+08rPN+b0FibDOVceOu5Ierb bmKQ== X-Gm-Message-State: AC+VfDzG5A0uyDb36VXzQZsJyTf511Vn2gefgQ9huYqCWZBrvpmmMD8k LYXKXdagbbT5TSWj7GOVauS5xcxBxBphsg== X-Google-Smtp-Source: ACHHUZ7gK3LD0rffutZs1W5DSej94BF+7nVfGNk/kLnJr6Z6StKyOOHvojNGaijTQ76fswW7V6nLGA== X-Received: by 2002:a17:907:94c1:b0:932:f88c:c2ff with SMTP id dn1-20020a17090794c100b00932f88cc2ffmr6835903ejc.34.1684669205349; Sun, 21 May 2023 04:40:05 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id h25-20020a1709070b1900b0096f7996d59csm1833911ejl.184.2023.05.21.04.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 04:40:05 -0700 (PDT) From: Benjamin Bara Date: Sun, 21 May 2023 13:39:50 +0200 Subject: [PATCH RFC v3 1/5] regulator: move monitor handling into own function MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230419-dynamic-vmon-v3-1-4179b586d8a1@skidata.com> References: <20230419-dynamic-vmon-v3-0-4179b586d8a1@skidata.com> In-Reply-To: <20230419-dynamic-vmon-v3-0-4179b586d8a1@skidata.com> To: Liam Girdwood , Mark Brown Cc: support.opensource@diasemi.com, 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 Similar to the existing implementation, the new function does not handle EOPNOTSUPP as an error. The initial monitoring state is set to the regulator state. Signed-off-by: Benjamin Bara --- drivers/regulator/core.c | 134 ++++++++++++++++++++++++++++---------------= ---- 1 file changed, 80 insertions(+), 54 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index dc741ac156c3..76f112817f9d 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1426,7 +1426,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 @@ -1451,6 +1451,80 @@ 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; + + /* 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) { + if (ret !=3D -EOPNOTSUPP) { + rdev_err(rdev, "failed to set over voltage limits %pe\n", + ERR_PTR(ret)); + return ret; + } + rdev_warn(rdev, + "IC does not support requested over voltage limits\n"); + } + } + if (reg_c->under_voltage_detection) { + ret =3D handle_notify_limits(rdev, ops->set_under_voltage_protection, + enable ? ®_c->under_voltage_limits + : &disable_limits); + if (ret) { + if (ret !=3D -EOPNOTSUPP) { + rdev_err(rdev, "failed to set under voltage limits %pe\n", + ERR_PTR(ret)); + return ret; + } + rdev_warn(rdev, + "IC does not support requested under voltage limits\n"); + } + } + if (reg_c->over_current_detection) { + ret =3D handle_notify_limits(rdev, ops->set_over_current_protection, + enable ? ®_c->over_curr_limits + : &disable_limits); + if (ret) { + if (ret !=3D -EOPNOTSUPP) { + rdev_err(rdev, "failed to set over current limits: %pe\n", + ERR_PTR(ret)); + return ret; + } + rdev_warn(rdev, + "IC does not support requested over-current limits\n"); + } + } + if (reg_c->over_temp_detection) { + ret =3D handle_notify_limits(rdev, ops->set_thermal_protection, + enable ? ®_c->temp_limits + : &disable_limits); + if (ret) { + if (ret !=3D -EOPNOTSUPP) { + rdev_err(rdev, "failed to set temperature limits %pe\n", + ERR_PTR(ret)); + return ret; + } + rdev_warn(rdev, + "IC does not support requested temperature limits\n"); + } + } + + return 0; +} + /** * set_machine_constraints - sets regulator constraints * @rdev: regulator source @@ -1564,60 +1638,12 @@ static int set_machine_constraints(struct regulator= _dev *rdev) } } =20 - if (rdev->constraints->over_current_detection) - ret =3D handle_notify_limits(rdev, - ops->set_over_current_protection, - &rdev->constraints->over_curr_limits); - if (ret) { - if (ret !=3D -EOPNOTSUPP) { - rdev_err(rdev, "failed to set over current limits: %pe\n", - ERR_PTR(ret)); - return ret; - } - rdev_warn(rdev, - "IC does not support requested over-current limits\n"); - } - - if (rdev->constraints->over_voltage_detection) - ret =3D handle_notify_limits(rdev, - ops->set_over_voltage_protection, - &rdev->constraints->over_voltage_limits); - if (ret) { - if (ret !=3D -EOPNOTSUPP) { - rdev_err(rdev, "failed to set over voltage limits %pe\n", - ERR_PTR(ret)); - return ret; - } - rdev_warn(rdev, - "IC does not support requested over voltage limits\n"); - } - - if (rdev->constraints->under_voltage_detection) - ret =3D handle_notify_limits(rdev, - ops->set_under_voltage_protection, - &rdev->constraints->under_voltage_limits); - if (ret) { - if (ret !=3D -EOPNOTSUPP) { - rdev_err(rdev, "failed to set under voltage limits %pe\n", - ERR_PTR(ret)); - return ret; - } - rdev_warn(rdev, - "IC does not support requested under voltage limits\n"); - } - - if (rdev->constraints->over_temp_detection) - ret =3D handle_notify_limits(rdev, - ops->set_thermal_protection, - &rdev->constraints->temp_limits); - if (ret) { - if (ret !=3D -EOPNOTSUPP) { - rdev_err(rdev, "failed to set temperature limits %pe\n", - ERR_PTR(ret)); + /* set initial monitor state to current regulator state. */ + ret =3D _regulator_is_enabled(rdev); + if (ret >=3D 0) { + ret =3D monitors_set_state(rdev, !!ret); + if (ret) return ret; - } - rdev_warn(rdev, - "IC does not support requested temperature limits\n"); } =20 if (rdev->constraints->active_discharge && ops->set_active_discharge) { --=20 2.34.1 From nobody Sun Feb 8 19:55:28 2026 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 2C25BC8300C for ; Sun, 21 May 2023 11:47:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231335AbjEULrV (ORCPT ); Sun, 21 May 2023 07:47:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230231AbjEULqF (ORCPT ); Sun, 21 May 2023 07:46:05 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDB3AE46 for ; Sun, 21 May 2023 04:40:07 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-96fbc74fbf1so103276666b.1 for ; Sun, 21 May 2023 04:40:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684669206; x=1687261206; 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=bPGXCIV+plZCCdzziB6S7Ng67mf6lvRgxH4hTs2ibfc=; b=oAtW79EvYmAzL5FZxdLAQJ1Dwxan8iNCa+64waGBTJq1IB1EUFfPGFeapNiySACZ2f xiCsgyTJIvf6LkqyD44LeapgnGlE/0zqtWpornA5DFDz3T6S7PPsAV9ji70Pat6/LTlG Frz2XjYbkHlo2Rr68+vr/0hfbno2Bz45dJTmRL4wmAlLnmrNBrmAh+Kgq5ocJ7LiEQtQ xcsRh9C2HFoGRPo4kENIl64MGtt/Xbq12/gSo7d9LOFMGbq9MBX+ljQA2uTrFkJYtH/v QZDPjpqJWcM/zBhH8PVeEDrxQ2qIvAeD2oQmqWbX2cg5r9VRgg7+2XL7OkgpqyeaGVlu ZVeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684669206; x=1687261206; 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=bPGXCIV+plZCCdzziB6S7Ng67mf6lvRgxH4hTs2ibfc=; b=Nf7cj9DmYFfOo1UczdpRyEhRO4SU49zSG30wDpoxoRkRiFp1+D7dgxbz2A4iD6XoVR uOqVy1Qn6SEndqmuTqedWZ/PjlOKtKoc39Fp499I1X/aNpF8zQ92shjtu2YkltaZgm9+ +qugN5pHM++eP2TEuE02zhNFH8K0nOOSbBuq4umS4Ub7cPUoRrnADYCFbGLiTuaU796u PAR1+SWhchLK4lEkg9tdKdQtN2QoDOrLkeOkHGSjd5vc+4f6jiNjAeYPu9S/s4DVfi2I o9Lsurhdv81955O1d8KxrZKj0YMeR4NCQ8NZo1jwSCJatD/QVUKqS9d+lw3rEjGpufO2 Cszw== X-Gm-Message-State: AC+VfDwNYKdyJMIglzsLm/yINrw5v/lsE//wlOvUC1FH89/m/Li0KcLc Mo3SyAzpZAmxddDnzspjCLo= X-Google-Smtp-Source: ACHHUZ5ugiYydXwfcpYi4n7scOcKuUXjWTEeqmH5P3R1Bosn8ghe2AVxBktG3D2zu7BUMOu+jrV2KQ== X-Received: by 2002:a17:906:ef0e:b0:96a:1260:dbf5 with SMTP id f14-20020a170906ef0e00b0096a1260dbf5mr6357702ejs.45.1684669206223; Sun, 21 May 2023 04:40:06 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id h25-20020a1709070b1900b0096f7996d59csm1833911ejl.184.2023.05.21.04.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 04:40:06 -0700 (PDT) From: Benjamin Bara Date: Sun, 21 May 2023 13:39:51 +0200 Subject: [PATCH RFC v3 2/5] regulator: disable monitors when regulator is disabled MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230419-dynamic-vmon-v3-2-4179b586d8a1@skidata.com> References: <20230419-dynamic-vmon-v3-0-4179b586d8a1@skidata.com> In-Reply-To: <20230419-dynamic-vmon-v3-0-4179b586d8a1@skidata.com> To: Liam Girdwood , Mark Brown Cc: support.opensource@diasemi.com, 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 This disables all enabled monitors before a regulator is disabled. This only happens if an protection is enabled in the device-tree. If an error occurs while disabling the regulator, the monitors are enabled again. Signed-off-by: Benjamin Bara --- drivers/regulator/core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 76f112817f9d..e59204920d6c 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2828,7 +2828,7 @@ static int _regulator_do_enable(struct regulator_dev = *rdev) =20 trace_regulator_enable_complete(rdev_get_name(rdev)); =20 - return 0; + return monitors_set_state(rdev, true); } =20 /** @@ -2989,6 +2989,10 @@ static int _regulator_do_disable(struct regulator_de= v *rdev) { int ret; =20 + ret =3D monitors_set_state(rdev, false); + if (ret) + return ret; + trace_regulator_disable(rdev_get_name(rdev)); =20 if (rdev->ena_pin) { @@ -3043,6 +3047,7 @@ static int _regulator_disable(struct regulator *regul= ator) _notifier_call_chain(rdev, REGULATOR_EVENT_ABORT_DISABLE, NULL); + monitors_set_state(rdev, true); return ret; } _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, @@ -3109,6 +3114,7 @@ static int _regulator_force_disable(struct regulator_= dev *rdev) rdev_err(rdev, "failed to force disable: %pe\n", ERR_PTR(ret)); _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | REGULATOR_EVENT_ABORT_DISABLE, NULL); + monitors_set_state(rdev, true); return ret; } =20 @@ -6251,8 +6257,10 @@ static int regulator_late_cleanup(struct device *dev= , void *data) */ rdev_info(rdev, "disabling\n"); ret =3D _regulator_do_disable(rdev); - if (ret !=3D 0) + if (ret !=3D 0) { rdev_err(rdev, "couldn't disable: %pe\n", ERR_PTR(ret)); + monitors_set_state(rdev, true); + } } else { /* The intention is that in future we will * assume that full constraints are provided --=20 2.34.1 From nobody Sun Feb 8 19:55:28 2026 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 3B282C87FDC for ; Sun, 21 May 2023 11:47:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231444AbjEULrY (ORCPT ); Sun, 21 May 2023 07:47:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbjEULqF (ORCPT ); Sun, 21 May 2023 07:46:05 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E21E3E49 for ; Sun, 21 May 2023 04:40:08 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-96f53c06babso549932266b.3 for ; Sun, 21 May 2023 04:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684669207; x=1687261207; 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=Z5+cmzLz6/sx+KBZ1IqAfTTXRmFup3O6Bm7K5a68gJk=; b=V2sBcJR6gvj5KaqfKFqHmKHM4+SeAw+djCQInECpMzgh1JxJpHjdWNR+hJciioEJuU sgnNpkEMv7NDqqP/HWAVCZCwBaZTwLm93dGZHodMgXCNFMNVdyZuWU243m70lnFjssB+ KV77DUbQPYIg910BHGSrz6Dx234i6cjhXYtArIvE9wSm9AqOS90A2KDsObAVUPoXkWlK lxCBRL+uYvOZUwHipb7WPin4gsa/0uc4Cj8djAxF2jiXOVvnxR/UVZOEUr3dZ3+yST6W 0aBbIZ3CtmsjYliDMhwR8Hv4myj2xJcfrcwoBYMNEhZVBuCxBM2ynZKK44bdskSSnRzK ax9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684669207; x=1687261207; 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=Z5+cmzLz6/sx+KBZ1IqAfTTXRmFup3O6Bm7K5a68gJk=; b=QDpJIZKLyUxDnPbqxzq46IvXMWVaVVLlfPT5wQuMin50FhtyoVT08xePIAzA0QRHRk DVQJe2D4KEQN+iAO8UyJocFkWfbG16WBZ/LAanwlHQCo+gLp7E8eKnf+3H3JgtTDshNA bbsfoCkex3GwDcqVPv2SCHusVWCvv7J+4xyrCB+rqXw9J6fXDCdBNH7bSa+tIS5QzdDT JogL+RgxyfJpcDlH8tBN99apcZ3ZO/sPhDCA09pz0cMFJebKsBRv9UacmlLXuxqwEPHo jxQAfpwusg8Q9TSL3yfae2cBsVx53J9p29cjhMogGT8PuUlTqLoGdHtcU0ON38hn7v+j /5jA== X-Gm-Message-State: AC+VfDxUoTp9Uvr6CNyoUvvkrKya0l4gxV/NzxRX7AvDFyUSm2i1ZoOp Q/+VGSEKBE9eNktdUNAYMUM= X-Google-Smtp-Source: ACHHUZ7CgQxi/BlZ4ZA11VDoLFX2kFm9dnMNUX7ESYahIsj3U3CH3dluiB/EGpOMPBdcgekzV5Jzsg== X-Received: by 2002:a17:907:31ce:b0:96a:6723:da48 with SMTP id xf14-20020a17090731ce00b0096a6723da48mr5845547ejb.75.1684669207146; Sun, 21 May 2023 04:40:07 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id h25-20020a1709070b1900b0096f7996d59csm1833911ejl.184.2023.05.21.04.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 04:40:06 -0700 (PDT) From: Benjamin Bara Date: Sun, 21 May 2023 13:39:52 +0200 Subject: [PATCH RFC v3 3/5] regulator: add getter for active monitors MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230419-dynamic-vmon-v3-3-4179b586d8a1@skidata.com> References: <20230419-dynamic-vmon-v3-0-4179b586d8a1@skidata.com> In-Reply-To: <20230419-dynamic-vmon-v3-0-4179b586d8a1@skidata.com> To: Liam Girdwood , Mark Brown Cc: support.opensource@diasemi.com, 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 Add an op to get all active monitors of a regulator. Signed-off-by: Benjamin Bara --- include/linux/regulator/driver.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/dri= ver.h index d3b4a3d4514a..35547e9eca48 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -25,6 +25,12 @@ struct regulator_config; struct regulator_init_data; struct regulator_enable_gpio; =20 +#define REGULATOR_MONITOR_INVALID 0x0 +#define REGULATOR_MONITOR_OVER_CURRENT 0x1 +#define REGULATOR_MONITOR_OVER_VOLTAGE 0x2 +#define REGULATOR_MONITOR_UNDER_VOLTAGE 0x4 +#define REGULATOR_MONITOR_OVER_TEMPERATURE 0x8 + enum regulator_status { REGULATOR_STATUS_OFF, REGULATOR_STATUS_ON, @@ -112,6 +118,8 @@ enum regulator_detection_severity { * @set_thermal_protection: Support enabling of and setting limits for over * temperature situation detection.Detection can be configured for same * severities as over current protection. Units of degree Kelvin. + * @get_active_protections: Get all enabled monitors of a regulator. OR'ed= val + * of REGULATOR_MONITOR_*. REGULATOR_MONITOR_INVALID means no one active. * * @set_active_discharge: Set active discharge enable/disable of regulator= s. * @@ -183,6 +191,7 @@ struct regulator_ops { int severity, bool enable); int (*set_thermal_protection)(struct regulator_dev *, int lim, int severity, bool enable); + int (*get_active_protections)(struct regulator_dev *dev, unsigned int *st= ate); int (*set_active_discharge)(struct regulator_dev *, bool enable); =20 /* enable/disable regulator */ --=20 2.34.1 From nobody Sun Feb 8 19:55:28 2026 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 6B456C87FDE for ; Sun, 21 May 2023 11:47:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbjEULrc (ORCPT ); Sun, 21 May 2023 07:47:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230282AbjEULqF (ORCPT ); Sun, 21 May 2023 07:46:05 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98839E4B for ; Sun, 21 May 2023 04:40:09 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-965ac4dd11bso985201566b.2 for ; Sun, 21 May 2023 04:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684669208; x=1687261208; 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=Tup0fS1Ilgny0Y9QHNptVTLtqhryknUFnq8PvXS+SwM=; b=h81dhzI4XMEIp+UuShvAuYmnYwf57fHKAQYu5GynhG1bMvfF0FPzo1o+IEzkqERbho LUe09PWOZrireopuOT2PV2D1qOogrNvRhHJofUvG8GA1Y2UIxTBrTZ9MHjPmb5LryMwo US9j8bhOGba1maJBegoGBc8uFs3dMwNo3dlhKHSb++XrsoMXC6ilgWu+hmvHuwCOHfiv NxDqN6HyOrvfEoFjbuW7A0v3WRhmnQkQCrqbSJ0d2CeH6rTh4z+PZrkMELoEpRuU6lWV TGG2mTABA1aXqmtRGM2w3Qu/+BzSrVllA3Wtl6Nj+Kpcz0AUKWlL/roEX6jPstiLAru6 71zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684669208; x=1687261208; 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=Tup0fS1Ilgny0Y9QHNptVTLtqhryknUFnq8PvXS+SwM=; b=IxkFktzIordtCCTx9l76vRWkuNH/psAewJK7/DYihovCbT7kGH2h+2zkSagmQwVaB8 KxdbwC7OK23QNaID7ZiINwyUVDERaA7NiuxhQzZnsq+neCQ2HCvr2M0/wn/emIAGgU6K Cg05CecLc/bY3s+N/SJO+qlW4+aKmjK2rl/1tdS1OFfDQs+0jdtGlq+48j9SjruqdjE8 UsjkjoCZw7CDiSJcWFusxzbNvGDNHn5EDjcH1Dz7Vq3nymf76Dye/Pd2R/h9vrvA/KqP roggYHQVVq8W6Wzpw1G4/Imh6gyb2wQJ9bFY5CwDvThOfw5jK8/SS3p4tScI301sK8cp GXFA== X-Gm-Message-State: AC+VfDwuaex1QHZ8Pg309xThg9jEbk7F9lsCeEOVBJDF/YAFnrh6cJZF Gm7ZN/+PMN97k8akHWsjzxc= X-Google-Smtp-Source: ACHHUZ7FkQr4E0IzlSheCD4krH4EzHncz46xuRzvGRaqLiLW13dn2NFEOPdfqpEjelWZuYCX0bueQg== X-Received: by 2002:a17:907:5cd:b0:94e:46ef:1361 with SMTP id wg13-20020a17090705cd00b0094e46ef1361mr6283834ejb.34.1684669208002; Sun, 21 May 2023 04:40:08 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id h25-20020a1709070b1900b0096f7996d59csm1833911ejl.184.2023.05.21.04.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 04:40:07 -0700 (PDT) From: Benjamin Bara Date: Sun, 21 May 2023 13:39:53 +0200 Subject: [PATCH RFC v3 4/5] regulator: add properties to handle monitoring on state change MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230419-dynamic-vmon-v3-4-4179b586d8a1@skidata.com> References: <20230419-dynamic-vmon-v3-0-4179b586d8a1@skidata.com> In-Reply-To: <20230419-dynamic-vmon-v3-0-4179b586d8a1@skidata.com> To: Liam Girdwood , Mark Brown Cc: support.opensource@diasemi.com, 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 | 90 ++++++++++++++++++++++++++++++++++++= ++++ include/linux/regulator/driver.h | 13 ++++++ 2 files changed, 103 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index e59204920d6c..98a9283a0322 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1638,6 +1638,34 @@ static int set_machine_constraints(struct regulator_= dev *rdev) } } =20 + /* + * when the core is in charge of disabling monitors while the regulator + * changes its value, it is essential to know if a monitor is active. + */ + if (rdev->desc->mon_disable_reg_set_higher || + rdev->desc->mon_disable_reg_set_lower) { + unsigned int monitor_state =3D REGULATOR_MONITOR_INVALID; + + ret =3D ops->get_active_protections(rdev, &monitor_state); + if (ret) + return ret; + + /* + * when a monitor is active, without dt knowing, we have to + * adapt the constraints to ensure functionality. + */ + if (!rdev->constraints->over_voltage_detection && + (monitor_state & REGULATOR_MONITOR_OVER_VOLTAGE)) { + rdev_warn(rdev, "dt unaware of over-voltage protection!\n"); + rdev->constraints->over_voltage_detection =3D 1; + } + if (!rdev->constraints->under_voltage_detection && + (monitor_state & REGULATOR_MONITOR_UNDER_VOLTAGE)) { + rdev_warn(rdev, "dt unaware of under-voltage protection!\n"); + rdev->constraints->under_voltage_detection =3D 1; + } + } + /* set initial monitor state to current regulator state. */ ret =3D _regulator_is_enabled(rdev); if (ret >=3D 0) { @@ -3516,6 +3544,15 @@ static int _regulator_call_set_voltage(struct regula= tor_dev *rdev, if (ret & NOTIFY_STOP_MASK) return -EINVAL; =20 + if ((rdev->desc->mon_disable_reg_set_higher && + (min_uV > data.old_uV || max_uV > data.old_uV)) || + (rdev->desc->mon_disable_reg_set_lower && + (min_uV < data.old_uV || max_uV < data.old_uV))) { + ret =3D monitors_set_state(rdev, false); + if (ret) + return ret; + } + ret =3D rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, selector); if (ret >=3D 0) return ret; @@ -3540,6 +3577,13 @@ static int _regulator_call_set_voltage_sel(struct re= gulator_dev *rdev, if (ret & NOTIFY_STOP_MASK) return -EINVAL; =20 + if ((rdev->desc->mon_disable_reg_set_higher && uV > data.old_uV) || + (rdev->desc->mon_disable_reg_set_lower && uV < data.old_uV)) { + ret =3D monitors_set_state(rdev, false); + if (ret) + return ret; + } + ret =3D rdev->desc->ops->set_voltage_sel(rdev, selector); if (ret >=3D 0) return ret; @@ -3736,6 +3780,15 @@ 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_reg_set_higher || rdev->desc->mon_disable_re= g_set_lower) && + _regulator_is_enabled(rdev) > 0) { + /* if setting voltage failed, ignore monitoring error. */ + if (ret) + monitors_set_state(rdev, true); + else + ret =3D monitors_set_state(rdev, true); + } + return ret; } =20 @@ -4645,7 +4698,24 @@ 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) { + /* get_mode() is required: regulator_curr_mode should be valid. */ + if ((regulator_curr_mode & ~rdev->desc->mon_unsupported_reg_modes) && + _regulator_is_enabled(rdev) > 0) + monitors_set_state(rdev, true); + goto out; + } + + if ((mode & ~rdev->desc->mon_unsupported_reg_modes) && _regulator_is_enab= led(rdev) > 0) + ret =3D monitors_set_state(rdev, true); + out: regulator_unlock(rdev); return ret; @@ -5572,6 +5642,26 @@ regulator_register(struct device *dev, goto rinse; } =20 + /* + * mon_unsupported_reg_modes property requires get_mode() to get the old + * state in case a state switch is failing. + */ + if (regulator_desc->mon_unsupported_reg_modes && + !regulator_desc->ops->get_mode) { + ret =3D -EINVAL; + goto rinse; + } + /* + * mon_disable_reg_set_* property requires get_active_protections() to + * know if a regulator is monitored without the device-tree knowing it. + */ + if ((regulator_desc->mon_disable_reg_set_higher || + regulator_desc->mon_disable_reg_set_lower) && + !regulator_desc->ops->get_active_protections) { + ret =3D -EINVAL; + goto rinse; + } + rdev =3D kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); if (rdev =3D=3D NULL) { ret =3D -ENOMEM; diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/dri= ver.h index 35547e9eca48..bf42a5f452c5 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -366,6 +366,15 @@ 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_reg_set_higher: Disables regulator's monitors while it is + * changing its value to a higher one. + * @mon_disable_reg_set_lower: Disables regulator's monitors while it is + * changing its value to a lower one. + * @mon_unsupported_reg_modes: Disables regulator's monitors before an + * unsupported mode is entered. REGULATOR_MODE= _* are + * OR'ed. REGULATOR_MODE_INVALID means all mod= es can + * be monitored. */ struct regulator_desc { const char *name; @@ -440,6 +449,10 @@ struct regulator_desc { unsigned int poll_enabled_time; =20 unsigned int (*of_map_mode)(unsigned int mode); + + unsigned int mon_disable_reg_set_higher; + unsigned int mon_disable_reg_set_lower; + unsigned int mon_unsupported_reg_modes; }; =20 /** --=20 2.34.1 From nobody Sun Feb 8 19:55:28 2026 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 5C038C87FDD for ; Sun, 21 May 2023 11:47:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231603AbjEULr1 (ORCPT ); Sun, 21 May 2023 07:47:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbjEULqF (ORCPT ); Sun, 21 May 2023 07:46:05 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8701FE4C for ; Sun, 21 May 2023 04:40:10 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-96f588bc322so427155766b.1 for ; Sun, 21 May 2023 04:40:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684669209; x=1687261209; 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=4ThlmQ9/C96MUGf03mOZmnjGDzq2pSyB3lE6yZuqFXk=; b=mZSyIYlSDtq9bVp4uuDbfCau4SL2O4+64oCK9s8g4xJgf5j0VNFSOGdVnRKiv8CtlR rNKwn+rvqfyvk42vMdulo9QZj2pHBGJugRGvvZZbQEie0D7T2rPl20agG0r9Ee7eriS2 guK21giyZqb5DF+YLvBD0i3/0VGkLrSkWk2gi3jegRrHAHgOmC2mFMJMzKaTGYge+pan 2eHZqL6UI6qZF01VlrorpANvtIhO1IukJDO3JlOsEowgXHX0HIVzvhWfN4lrQDqJ4r20 ldd9+fgCuETHcsfn4DfUypJFCql48GU2QQcpHh9Sz9PN3wuTBW1+i88MNFiW+iHR2rNs ndBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684669209; x=1687261209; 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=4ThlmQ9/C96MUGf03mOZmnjGDzq2pSyB3lE6yZuqFXk=; b=BaWbXtNaQhjnF2uzoy5fUSexwN++0F7+vcRQt8gKnGuZL3+0eWPas1WgLjdXW5vyhd ASa6/uuO1SUYYEUUoXBjiOUpdfr29IoYdLXDmXKbmpqD2grExaQ1aS5Au30Xzfwx3UFt G5MwRErUxlDbeffizEDgyrbvtwcbS0y4ZcHozrUwA/7vDjXvFJaQ2j92Cw5wjv8olZpv rmjY8wztgQo5oPLe4+22PPAVFi7E7mYWkIqSjfXJlAoKedtI7nY1ZEf662hNKgRFlLhB wY04+jfMDCh1gSWm7xebqnFkZyDD+oEo/MZN1guHGqPj4FB/u3tsR0EoDG8N5yWHifWI dTbA== X-Gm-Message-State: AC+VfDy47YHKWNE7l0X6uyArSR1vLwEGQM8/nvx8+93mzciQrg36lLkY yiuii0hC+o4wQUcYz9JIjbo= X-Google-Smtp-Source: ACHHUZ5ymiSN62eLBPeoGF0OZ/XsbI5fcCnWvKSe1Xvdcvc9J9TIJvaBoyk1z1MwEMwlFYszLPNbhQ== X-Received: by 2002:a17:906:ee82:b0:966:37b2:734a with SMTP id wt2-20020a170906ee8200b0096637b2734amr6921951ejb.22.1684669208869; Sun, 21 May 2023 04:40:08 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id h25-20020a1709070b1900b0096f7996d59csm1833911ejl.184.2023.05.21.04.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 04:40:08 -0700 (PDT) From: Benjamin Bara Date: Sun, 21 May 2023 13:39:54 +0200 Subject: [PATCH RFC v3 5/5] regulator: bd718x7: let the core handle the monitors MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230419-dynamic-vmon-v3-5-4179b586d8a1@skidata.com> References: <20230419-dynamic-vmon-v3-0-4179b586d8a1@skidata.com> In-Reply-To: <20230419-dynamic-vmon-v3-0-4179b586d8a1@skidata.com> To: Liam Girdwood , Mark Brown Cc: support.opensource@diasemi.com, 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 monitors of the bd718x7 must be disabled while the respective regulator is switching to a higher voltage. Use the new property '.mon_disable_reg_set_higher' to activate the handling in the core. .mon_disable_reg_set_higher requires get_active_protections() to find out if a regulator is monitored without the device-tree knowing it. Otherwise, this might lead to a failure as the core might not be aware that a regulator is monitored and therefore would not disable it. Therefore, implement it. Signed-off-by: Benjamin Bara --- drivers/regulator/bd718x7-regulator.c | 206 +++++++++++-------------------= ---- 1 file changed, 66 insertions(+), 140 deletions(-) diff --git a/drivers/regulator/bd718x7-regulator.c b/drivers/regulator/bd71= 8x7-regulator.c index b0b9938c20a1..897388d68949 100644 --- a/drivers/regulator/bd718x7-regulator.c +++ b/drivers/regulator/bd718x7-regulator.c @@ -56,7 +56,7 @@ =20 #define BD718XX_OPS(name, _list_voltage, _map_voltage, _set_voltage_sel, \ _get_voltage_sel, _set_voltage_time_sel, _set_ramp_delay, \ - _set_uvp, _set_ovp) \ + _set_uvp, _set_ovp, _get_prot) \ static const struct regulator_ops name =3D { \ .enable =3D regulator_enable_regmap, \ .disable =3D regulator_disable_regmap, \ @@ -69,6 +69,7 @@ static const struct regulator_ops name =3D { \ .set_ramp_delay =3D (_set_ramp_delay), \ .set_under_voltage_protection =3D (_set_uvp), \ .set_over_voltage_protection =3D (_set_ovp), \ + .get_active_protections =3D (_get_prot), \ }; \ \ static const struct regulator_ops BD718XX_HWOPNAME(name) =3D { \ @@ -81,6 +82,7 @@ static const struct regulator_ops BD718XX_HWOPNAME(name) = =3D { \ .set_ramp_delay =3D (_set_ramp_delay), \ .set_under_voltage_protection =3D (_set_uvp), \ .set_over_voltage_protection =3D (_set_ovp), \ + .get_active_protections =3D (_get_prot), \ } \ =20 /* @@ -126,128 +128,6 @@ static int bd71837_get_buck34_enable_hwctrl(struct re= gulator_dev *rdev) return !!(BD718XX_BUCK_RUN_ON & val); } =20 -static void voltage_change_done(struct regulator_dev *rdev, unsigned int s= el, - unsigned int *mask) -{ - int ret; - - if (*mask) { - /* - * Let's allow scheduling as we use I2C anyways. We just need to - * guarantee minimum of 1ms sleep - it shouldn't matter if we - * exceed it due to the scheduling. - */ - msleep(1); - - ret =3D regmap_clear_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2, - *mask); - if (ret) - dev_err(&rdev->dev, - "Failed to re-enable voltage monitoring (%d)\n", - ret); - } -} - -static int voltage_change_prepare(struct regulator_dev *rdev, unsigned int= sel, - unsigned int *mask) -{ - int ret; - - *mask =3D 0; - if (rdev->desc->ops->is_enabled(rdev)) { - int now, new; - - now =3D rdev->desc->ops->get_voltage_sel(rdev); - if (now < 0) - return now; - - now =3D rdev->desc->ops->list_voltage(rdev, now); - if (now < 0) - return now; - - new =3D rdev->desc->ops->list_voltage(rdev, sel); - if (new < 0) - return new; - - /* - * If we increase LDO voltage when LDO is enabled we need to - * disable the power-good detection until voltage has reached - * the new level. According to HW colleagues the maximum time - * it takes is 1000us. I assume that on systems with light load - * this might be less - and we could probably use DT to give - * system specific delay value if performance matters. - * - * Well, knowing we use I2C here and can add scheduling delays - * I don't think it is worth the hassle and I just add fixed - * 1ms sleep here (and allow scheduling). If this turns out to - * be a problem we can change it to delay and make the delay - * time configurable. - */ - if (new > now) { - int tmp; - int prot_bit; - int ldo_offset =3D rdev->desc->id - BD718XX_LDO1; - - prot_bit =3D BD718XX_LDO1_VRMON80 << ldo_offset; - ret =3D regmap_read(rdev->regmap, BD718XX_REG_MVRFLTMASK2, - &tmp); - if (ret) { - dev_err(&rdev->dev, - "Failed to read voltage monitoring state\n"); - return ret; - } - - if (!(tmp & prot_bit)) { - /* We disable protection if it was enabled... */ - ret =3D regmap_set_bits(rdev->regmap, - BD718XX_REG_MVRFLTMASK2, - prot_bit); - /* ...and we also want to re-enable it */ - *mask =3D prot_bit; - } - if (ret) { - dev_err(&rdev->dev, - "Failed to stop voltage monitoring\n"); - return ret; - } - } - } - - return 0; -} - -static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev, - unsigned int sel) -{ - int ret; - int mask; - - ret =3D voltage_change_prepare(rdev, sel, &mask); - if (ret) - return ret; - - ret =3D regulator_set_voltage_sel_regmap(rdev, sel); - voltage_change_done(rdev, sel, &mask); - - return ret; -} - -static int bd718xx_set_voltage_sel_pickable_restricted( - struct regulator_dev *rdev, unsigned int sel) -{ - int ret; - int mask; - - ret =3D voltage_change_prepare(rdev, sel, &mask); - if (ret) - return ret; - - ret =3D regulator_set_voltage_sel_pickable_regmap(rdev, sel); - voltage_change_done(rdev, sel, &mask); - - return ret; -} - static int bd71837_set_voltage_sel_pickable_restricted( struct regulator_dev *rdev, unsigned int sel) { @@ -457,6 +337,21 @@ static int bd718x7_xvp_sanity_check(struct regulator_d= ev *rdev, int lim_uV, return 0; } =20 +static int bd717x7_get_ldo_prot(struct regulator_dev *rdev, unsigned int *= val) +{ + int ldo_offset =3D rdev->desc->id - BD718XX_LDO1; + int prot_bit =3D BD718XX_LDO1_VRMON80 << ldo_offset; + int ret; + + ret =3D regmap_test_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2, prot_bit); + if (ret < 0) + return ret; + if (ret) + *val |=3D REGULATOR_MONITOR_UNDER_VOLTAGE; + + return 0; +} + static int bd718x7_set_ldo_uvp(struct regulator_dev *rdev, int lim_uV, int severity, bool enable) { @@ -519,6 +414,31 @@ static int bd718x7_get_buck_uvp_info(int id, int *reg,= int *bit) return 0; } =20 +static int bd717x7_get_buck_prot(struct regulator_dev *rdev, unsigned int = *val) +{ + int ret, reg, bit; + + ret =3D bd718x7_get_buck_uvp_info(rdev->desc->id, ®, &bit); + if (ret) + return ret; + ret =3D regmap_test_bits(rdev->regmap, reg, bit); + if (ret < 0) + return ret; + if (ret) + *val |=3D REGULATOR_MONITOR_UNDER_VOLTAGE; + + ret =3D bd718x7_get_buck_ovp_info(rdev->desc->id, ®, &bit); + if (ret) + return ret; + ret =3D regmap_test_bits(rdev->regmap, reg, bit); + if (ret < 0) + return ret; + if (ret) + *val |=3D REGULATOR_MONITOR_OVER_VOLTAGE; + + return 0; +} + static int bd718x7_set_buck_uvp(struct regulator_dev *rdev, int lim_uV, int severity, bool enable) { @@ -564,15 +484,15 @@ static int bd718x7_set_buck_ovp(struct regulator_dev = *rdev, int lim_uV, */ BD718XX_OPS(bd718xx_pickable_range_ldo_ops, regulator_list_voltage_pickable_linear_range, NULL, - bd718xx_set_voltage_sel_pickable_restricted, + regulator_set_voltage_sel_pickable_regmap, regulator_get_voltage_sel_pickable_regmap, NULL, NULL, - bd718x7_set_ldo_uvp, NULL); + bd718x7_set_ldo_uvp, NULL, bd717x7_get_ldo_prot); =20 /* BD71847 and BD71850 LDO 5 is by default OFF at RUN state */ static const struct regulator_ops bd718xx_ldo5_ops_hwstate =3D { .is_enabled =3D never_enabled_by_hwstate, .list_voltage =3D regulator_list_voltage_pickable_linear_range, - .set_voltage_sel =3D bd718xx_set_voltage_sel_pickable_restricted, + .set_voltage_sel =3D regulator_set_voltage_sel_pickable_regmap, .get_voltage_sel =3D regulator_get_voltage_sel_pickable_regmap, .set_under_voltage_protection =3D bd718x7_set_ldo_uvp, }; @@ -582,27 +502,27 @@ BD718XX_OPS(bd718xx_pickable_range_buck_ops, regulator_set_voltage_sel_pickable_regmap, regulator_get_voltage_sel_pickable_regmap, regulator_set_voltage_time_sel, NULL, bd718x7_set_buck_uvp, - bd718x7_set_buck_ovp); + bd718x7_set_buck_ovp, bd717x7_get_buck_prot); =20 BD718XX_OPS(bd718xx_ldo_regulator_ops, regulator_list_voltage_linear_range, - NULL, bd718xx_set_voltage_sel_restricted, + NULL, regulator_set_voltage_sel_regmap, regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp, - NULL); + NULL, bd717x7_get_ldo_prot); =20 BD718XX_OPS(bd718xx_ldo_regulator_nolinear_ops, regulator_list_voltage_tab= le, - NULL, bd718xx_set_voltage_sel_restricted, + NULL, regulator_set_voltage_sel_regmap, regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp, - NULL); + NULL, bd717x7_get_ldo_prot); =20 BD718XX_OPS(bd718xx_buck_regulator_ops, regulator_list_voltage_linear_rang= e, NULL, regulator_set_voltage_sel_regmap, regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, - NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp); + NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp, bd717x7_get_buck_pr= ot); =20 BD718XX_OPS(bd718xx_buck_regulator_nolinear_ops, regulator_list_voltage_ta= ble, regulator_map_voltage_ascend, regulator_set_voltage_sel_regmap, regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, - NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp); + NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp, bd717x7_get_buck_pr= ot); =20 /* * OPS for BD71837 @@ -611,34 +531,34 @@ BD718XX_OPS(bd71837_pickable_range_ldo_ops, regulator_list_voltage_pickable_linear_range, NULL, bd71837_set_voltage_sel_pickable_restricted, regulator_get_voltage_sel_pickable_regmap, NULL, NULL, - bd718x7_set_ldo_uvp, NULL); + bd718x7_set_ldo_uvp, NULL, bd717x7_get_ldo_prot); =20 BD718XX_OPS(bd71837_pickable_range_buck_ops, regulator_list_voltage_pickable_linear_range, NULL, bd71837_set_voltage_sel_pickable_restricted, regulator_get_voltage_sel_pickable_regmap, regulator_set_voltage_time_sel, NULL, bd718x7_set_buck_uvp, - bd718x7_set_buck_ovp); + bd718x7_set_buck_ovp, bd717x7_get_buck_prot); =20 BD718XX_OPS(bd71837_ldo_regulator_ops, regulator_list_voltage_linear_range, NULL, rohm_regulator_set_voltage_sel_restricted, regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp, - NULL); + NULL, bd717x7_get_ldo_prot); =20 BD718XX_OPS(bd71837_ldo_regulator_nolinear_ops, regulator_list_voltage_tab= le, NULL, rohm_regulator_set_voltage_sel_restricted, regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp, - NULL); + NULL, bd717x7_get_ldo_prot); =20 BD718XX_OPS(bd71837_buck_regulator_ops, regulator_list_voltage_linear_rang= e, NULL, rohm_regulator_set_voltage_sel_restricted, regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, - NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp); + NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp, bd717x7_get_buck_pr= ot); =20 BD718XX_OPS(bd71837_buck_regulator_nolinear_ops, regulator_list_voltage_ta= ble, regulator_map_voltage_ascend, rohm_regulator_set_voltage_sel_restrict= ed, regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, - NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp); + NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp, bd717x7_get_buck_pr= ot); /* * BD71837 bucks 3 and 4 support defining their enable/disable state also * when buck enable state is under HW state machine control. In that case = the @@ -662,7 +582,7 @@ BD718XX_OPS(bd718xx_dvs_buck_regulator_ops, regulator_l= ist_voltage_linear_range, NULL, regulator_set_voltage_sel_regmap, regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, regulator_set_ramp_delay_regmap, bd718x7_set_buck_uvp, - bd718x7_set_buck_ovp); + bd718x7_set_buck_ovp, bd717x7_get_buck_prot); =20 =20 =20 @@ -1772,6 +1692,12 @@ static int bd718xx_probe(struct platform_device *pde= v) else desc->ops =3D swops[i]; =20 + /* + * bd718x7 requires to disable a regulator's monitors while it + * changes to a higher value. + */ + desc->mon_disable_reg_set_higher =3D 1; + rdev =3D devm_regulator_register(&pdev->dev, desc, &config); if (IS_ERR(rdev)) return dev_err_probe(&pdev->dev, PTR_ERR(rdev), --=20 2.34.1