Skip to contentSkip to conversation

regulator pre-enable

PATCH Superseded Jianqun Xu 3 participants 9 messages Aug 16, 2021 – Aug 17, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jianqun Xu

author
#0 lore raw

cover regulator pre-enable

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(-)
Signature · 9 lines
2.25.1




_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author
#1 lore raw

PATCH 1/4 regulator: add PRE_ENABLE event define

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

---
 include/linux/regulator/consumer.h | 2 ++
 1 file changed, 2 insertions(+)
include/linux/regulator/consumer.h +2 -0
index 20e84a84fb77..edd31f0dad17 100644
@@ -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
Signature · 9 lines
2.25.1




_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author
#2 lore raw

PATCH 2/4 regulator: core: notify regulator enable with the voltage value

In reply to 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.

---
 drivers/regulator/core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/regulator/core.c +5 -1
index f192bf19492e..a53f1644a6f4 100644
@@ -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;
Signature · 9 lines
2.25.1




_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
maintainer
#3 lore raw

Re: [PATCH 2/4] regulator: core: notify regulator enable with the voltage value

drivers/regulator/core.c static int _regulator_enable(struct regulator *regulator) · line 2666

Quoted 7 lines · Jianqun Xu
drivers/regulator/core.c +5 -1
+			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.

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#4 lore raw

Re: Re: [PATCH 2/4] regulator: core: notify regulator enable with the voltage value

Hi, Mark
--------------
[email protected]

Quoted 12 lines · Jianqun Xu

drivers/regulator/core.c static int _regulator_enable(struct regulator *regulator) · line 2666

Quoted 8 lines
drivers/regulator/core.c +4 -0
+	ret = _regulator_get_voltage(rdev);
+	if (ret < 0)
+	ret = 0;
+

  _notifier_call_chain(rdev, REGULATOR_EVENT_ENABLE,

drivers/regulator/core.c +1 -1
-	     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.

How about to only to notify the EVENT_ENABLE without get voltage, then driver who care about this event could get the voltage itself ?
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#5 lore raw

Re: Re: [PATCH 2/4] regulator: core: notify regulator enable with the voltage value

--------------
[email protected]

Quoted 16 lines

Hi, Mark
--------------
[email protected]

Quoted 12 lines · Jianqun Xu

drivers/regulator/core.c static int _regulator_enable(struct regulator *regulator) · line 2666

Quoted 8 lines
drivers/regulator/core.c +4 -0
+	ret = _regulator_get_voltage(rdev);
+	if (ret < 0)
+	ret = 0;
+

  _notifier_call_chain(rdev, REGULATOR_EVENT_ENABLE,

drivers/regulator/core.c +1 -1
-	     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.

Quoted 2 lines

How about to only to notify the EVENT_ENABLE without get voltage, then driver who care about this event could get the voltage itself ?

ignore my reply here about EVENT_ENABLE, sorry

How about the next patch about PRE_ENABLE ? At least I need a notify without voltage

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

author
#6 lore raw

PATCH 3/4 regulator: core: add pre-enable event notify to regulator

In reply to 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.

---
 drivers/regulator/core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/regulator/core.c +3 -0
index a53f1644a6f4..0eb7af487931 100644
@@ -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;
Signature · 9 lines
2.25.1




_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author
#7 lore raw

PATCH 4/4 soc: rockchip: io-domain: do more thing about regulator notify

In reply to 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.

---
 drivers/soc/rockchip/io-domain.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/soc/rockchip/io-domain.c +6 -0
index cf8182fc3642..af5fb11ad9a3 100644
@@ -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;
 	}
Signature · 9 lines
2.25.1




_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
#8 lore raw

Re: [PATCH 4/4] soc: rockchip: io-domain: do more thing about regulator notify

Quoted 8 lines · 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
Quoted 6 lines

* 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

Quoted 24 lines
---
 drivers/soc/rockchip/io-domain.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/soc/rockchip/io-domain.c +6 -1
index cf8182fc3642..af5fb11ad9a3 100644
@@ -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;
        }
--
Quoted 4 lines

2.25.1

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip