From nobody Mon Feb 9 14:14:33 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