linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] regulator pre-enable
@ 2021-08-16  3:19 Jianqun Xu
  2021-08-16  3:20 ` [PATCH 1/4] regulator: add PRE_ENABLE event define Jianqun Xu
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Jianqun Xu @ 2021-08-16  3:19 UTC (permalink / raw)
  To: lgirdwood, broonie, ulf.hansson, lee.jones, zhangchangzhong, heiko
  Cc: linux-rockchip, linux-kernel, Jianqun Xu

Rockchip io-domain care about regulator pre-enable

Jianqun Xu (4):
  regulator: add PRE_ENABLE event define
  regulator: core: notify regulator enable with the voltage value
  regulator: core: add pre-enable event notify to regulator
  soc: rockchip: io-domain: do more thing about regulator notify

 drivers/regulator/core.c           | 9 ++++++++-
 drivers/soc/rockchip/io-domain.c   | 6 ++++++
 include/linux/regulator/consumer.h | 2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)

-- 
2.25.1




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] regulator: add PRE_ENABLE event define
  2021-08-16  3:19 [PATCH 0/4] regulator pre-enable Jianqun Xu
@ 2021-08-16  3:20 ` Jianqun Xu
  2021-08-16  3:20 ` [PATCH 2/4] regulator: core: notify regulator enable with the voltage value Jianqun Xu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Jianqun Xu @ 2021-08-16  3:20 UTC (permalink / raw)
  To: lgirdwood, broonie, ulf.hansson, lee.jones, zhangchangzhong, heiko
  Cc: linux-rockchip, linux-kernel, Jianqun Xu

Add REGULATOR_EVENT_PRE_ENABLE to allow to notify driver that the
regulator is about to enabled.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
---
 include/linux/regulator/consumer.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index 20e84a84fb77..edd31f0dad17 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -102,6 +102,7 @@ struct regulator_dev;
  *                      Data passed is old voltage cast to (void *).
  * PRE_DISABLE    Regulator is about to be disabled
  * ABORT_DISABLE  Regulator disable failed for some reason
+ * PRE_ENABLE     Regulator is about to be enabled
  *
  * NOTE: These events can be OR'ed together when passed into handler.
  */
@@ -119,6 +120,7 @@ struct regulator_dev;
 #define REGULATOR_EVENT_PRE_DISABLE		0x400
 #define REGULATOR_EVENT_ABORT_DISABLE		0x800
 #define REGULATOR_EVENT_ENABLE			0x1000
+#define REGULATOR_EVENT_PRE_ENABLE		0x2000
 
 /*
  * Regulator errors that can be queried using regulator_get_error_flags
-- 
2.25.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] regulator: core: notify regulator enable with the voltage value
  2021-08-16  3:19 [PATCH 0/4] regulator pre-enable Jianqun Xu
  2021-08-16  3:20 ` [PATCH 1/4] regulator: add PRE_ENABLE event define Jianqun Xu
@ 2021-08-16  3:20 ` Jianqun Xu
  2021-08-16 12:00   ` Mark Brown
  2021-08-16  3:20 ` [PATCH 3/4] regulator: core: add pre-enable event notify to regulator Jianqun Xu
  2021-08-16  3:20 ` [PATCH 4/4] soc: rockchip: io-domain: do more thing about regulator notify Jianqun Xu
  3 siblings, 1 reply; 7+ messages in thread
From: Jianqun Xu @ 2021-08-16  3:20 UTC (permalink / raw)
  To: lgirdwood, broonie, ulf.hansson, lee.jones, zhangchangzhong, heiko
  Cc: linux-rockchip, linux-kernel, Jianqun Xu

Get the voltage of regulator and then pass it as the parameter of
notify, the driver could take it.

The origin parameter for notify is NULL, so this patch do nothing effect
to other driver who not care about the voltage value.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
---
 drivers/regulator/core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index f192bf19492e..a53f1644a6f4 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2658,8 +2658,12 @@ static int _regulator_enable(struct regulator *regulator)
 			if (ret < 0)
 				goto err_consumer_disable;
 
+			ret = _regulator_get_voltage(rdev);
+			if (ret < 0)
+				ret = 0;
+
 			_notifier_call_chain(rdev, REGULATOR_EVENT_ENABLE,
-					     NULL);
+					     &ret);
 		} else if (ret < 0) {
 			rdev_err(rdev, "is_enabled() failed: %pe\n", ERR_PTR(ret));
 			goto err_consumer_disable;
-- 
2.25.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] regulator: core: add pre-enable event notify to regulator
  2021-08-16  3:19 [PATCH 0/4] regulator pre-enable Jianqun Xu
  2021-08-16  3:20 ` [PATCH 1/4] regulator: add PRE_ENABLE event define Jianqun Xu
  2021-08-16  3:20 ` [PATCH 2/4] regulator: core: notify regulator enable with the voltage value Jianqun Xu
@ 2021-08-16  3:20 ` Jianqun Xu
  2021-08-16  3:20 ` [PATCH 4/4] soc: rockchip: io-domain: do more thing about regulator notify Jianqun Xu
  3 siblings, 0 replies; 7+ messages in thread
From: Jianqun Xu @ 2021-08-16  3:20 UTC (permalink / raw)
  To: lgirdwood, broonie, ulf.hansson, lee.jones, zhangchangzhong, heiko
  Cc: linux-rockchip, linux-kernel, Jianqun Xu

Notify the event about regulator to be enabled to driver.

The IO-DOMAIN driver on Rockchip SoCs will take this event and then to
configure the io-domain mode before regualtor_enable.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
---
 drivers/regulator/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index a53f1644a6f4..0eb7af487931 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2654,6 +2654,9 @@ static int _regulator_enable(struct regulator *regulator)
 				goto err_consumer_disable;
 			}
 
+			_notifier_call_chain(rdev, REGULATOR_EVENT_PRE_ENABLE,
+					     NULL);
+
 			ret = _regulator_do_enable(rdev);
 			if (ret < 0)
 				goto err_consumer_disable;
-- 
2.25.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] soc: rockchip: io-domain: do more thing about regulator notify
  2021-08-16  3:19 [PATCH 0/4] regulator pre-enable Jianqun Xu
                   ` (2 preceding siblings ...)
  2021-08-16  3:20 ` [PATCH 3/4] regulator: core: add pre-enable event notify to regulator Jianqun Xu
@ 2021-08-16  3:20 ` Jianqun Xu
  2021-08-16 12:39   ` Ulf Hansson
  3 siblings, 1 reply; 7+ messages in thread
From: Jianqun Xu @ 2021-08-16  3:20 UTC (permalink / raw)
  To: lgirdwood, broonie, ulf.hansson, lee.jones, zhangchangzhong, heiko
  Cc: linux-rockchip, linux-kernel, Jianqun Xu

Do a fix to rockchip io-domain, follow this orders:

* system running state
  -> io-domain vsel to 3.3V
    -> regulator_enable
      -> vsel change according to regulator voltage

* system running state
  -> io-domain vsel to 3.3V
    -> regulator_disable

Found on some Rockchip SoCs, the regulator enable or disable without
care about the io-domain maybe caused soc damaged.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
---
 drivers/soc/rockchip/io-domain.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/soc/rockchip/io-domain.c b/drivers/soc/rockchip/io-domain.c
index cf8182fc3642..af5fb11ad9a3 100644
--- a/drivers/soc/rockchip/io-domain.c
+++ b/drivers/soc/rockchip/io-domain.c
@@ -123,6 +123,12 @@ static int rockchip_iodomain_notify(struct notifier_block *nb,
 	} else if (event & (REGULATOR_EVENT_VOLTAGE_CHANGE |
 			    REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE)) {
 		uV = (unsigned long)data;
+	} else if (event & REGULATOR_EVENT_PRE_ENABLE) {
+		uV = MAX_VOLTAGE_3_3;
+	} else if (event & REGULATOR_EVENT_PRE_DISABLE) {
+		uV = MAX_VOLTAGE_3_3;
+	} else if (event & REGULATOR_EVENT_ENABLE) {
+		uV = (unsigned long)data;
 	} else {
 		return NOTIFY_OK;
 	}
-- 
2.25.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/4] regulator: core: notify regulator enable with the voltage value
  2021-08-16  3:20 ` [PATCH 2/4] regulator: core: notify regulator enable with the voltage value Jianqun Xu
@ 2021-08-16 12:00   ` Mark Brown
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2021-08-16 12:00 UTC (permalink / raw)
  To: Jianqun Xu
  Cc: lgirdwood, ulf.hansson, lee.jones, zhangchangzhong, heiko,
	linux-rockchip, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 354 bytes --]

On Mon, Aug 16, 2021 at 11:20:01AM +0800, Jianqun Xu wrote:

> +			ret = _regulator_get_voltage(rdev);
> +			if (ret < 0)
> +				ret = 0;
> +
>  			_notifier_call_chain(rdev, REGULATOR_EVENT_ENABLE,
> -					     NULL);
> +					     &ret);

This is going to be really expensive for devices without a cache and
it's going to be *very* rarely used if ever.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 4/4] soc: rockchip: io-domain: do more thing about regulator notify
  2021-08-16  3:20 ` [PATCH 4/4] soc: rockchip: io-domain: do more thing about regulator notify Jianqun Xu
@ 2021-08-16 12:39   ` Ulf Hansson
  0 siblings, 0 replies; 7+ messages in thread
From: Ulf Hansson @ 2021-08-16 12:39 UTC (permalink / raw)
  To: Jianqun Xu
  Cc: Liam Girdwood, Mark Brown, Lee Jones, zhangchangzhong,
	Heiko Stuebner, open list:ARM/Rockchip SoC...,
	Linux Kernel Mailing List

On Mon, 16 Aug 2021 at 05:20, Jianqun Xu <jay.xu@rock-chips.com> wrote:
>
> Do a fix to rockchip io-domain, follow this orders:
>
> * system running state
>   -> io-domain vsel to 3.3V
>     -> regulator_enable
>       -> vsel change according to regulator voltage
>
> * system running state
>   -> io-domain vsel to 3.3V
>     -> regulator_disable
>
> Found on some Rockchip SoCs, the regulator enable or disable without
> care about the io-domain maybe caused soc damaged.

Can you please try to elaborate on the problem a bit more, as I don't
quite get the problem.

What regulator is causing this problem? Who is the consumer of the regulator?

Kind regards
Uffe

>
> Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
> ---
>  drivers/soc/rockchip/io-domain.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/drivers/soc/rockchip/io-domain.c b/drivers/soc/rockchip/io-domain.c
> index cf8182fc3642..af5fb11ad9a3 100644
> --- a/drivers/soc/rockchip/io-domain.c
> +++ b/drivers/soc/rockchip/io-domain.c
> @@ -123,6 +123,12 @@ static int rockchip_iodomain_notify(struct notifier_block *nb,
>         } else if (event & (REGULATOR_EVENT_VOLTAGE_CHANGE |
>                             REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE)) {
>                 uV = (unsigned long)data;
> +       } else if (event & REGULATOR_EVENT_PRE_ENABLE) {
> +               uV = MAX_VOLTAGE_3_3;
> +       } else if (event & REGULATOR_EVENT_PRE_DISABLE) {
> +               uV = MAX_VOLTAGE_3_3;
> +       } else if (event & REGULATOR_EVENT_ENABLE) {
> +               uV = (unsigned long)data;
>         } else {
>                 return NOTIFY_OK;
>         }
> --
> 2.25.1
>
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-16 12:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16  3:19 [PATCH 0/4] regulator pre-enable Jianqun Xu
2021-08-16  3:20 ` [PATCH 1/4] regulator: add PRE_ENABLE event define Jianqun Xu
2021-08-16  3:20 ` [PATCH 2/4] regulator: core: notify regulator enable with the voltage value Jianqun Xu
2021-08-16 12:00   ` Mark Brown
2021-08-16  3:20 ` [PATCH 3/4] regulator: core: add pre-enable event notify to regulator Jianqun Xu
2021-08-16  3:20 ` [PATCH 4/4] soc: rockchip: io-domain: do more thing about regulator notify Jianqun Xu
2021-08-16 12:39   ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).