Re: [U-Boot] [PATCH v3 1/8] dm: regulator: support regulator more state

2019-10-16 Thread Simon Glass
Hi Elaine,

On Thu, 19 Sep 2019 at 02:08, Elaine Zhang  wrote:
>
> From: Joseph Chen 
>
> support parse regulator standard property:
> regulator-off-in-suspend;
> regulator-init-microvolt;
> regulator-suspend-microvolt:
>  regulator_get_suspend_enable
>  regulator_set_suspend_enable
>  regulator_get_suspend_value
>  regulator_set_suspend_value
>
> Signed-off-by: Joseph Chen 
> Signed-off-by: Elaine Zhang 

Is there a change log?

> ---
>  doc/device-tree-bindings/regulator/regulator.txt | 27 +
>  drivers/power/regulator/regulator-uclass.c   | 70 
> 
>  include/power/regulator.h| 64 ++
>  test/dm/regulator.c  | 46 
>  4 files changed, 207 insertions(+)

Regards,
Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 1/8] dm: regulator: support regulator more state

2019-09-19 Thread Kever Yang


On 2019/9/19 下午4:08, Elaine Zhang wrote:

From: Joseph Chen 

support parse regulator standard property:
regulator-off-in-suspend;
regulator-init-microvolt;
regulator-suspend-microvolt:
  regulator_get_suspend_enable
  regulator_set_suspend_enable
  regulator_get_suspend_value
  regulator_set_suspend_value

Signed-off-by: Joseph Chen 
Signed-off-by: Elaine Zhang 


Reviewed-by: Kever Yang

Thanks,
- Kever

---
  doc/device-tree-bindings/regulator/regulator.txt | 27 +
  drivers/power/regulator/regulator-uclass.c   | 70 
  include/power/regulator.h| 64 ++
  test/dm/regulator.c  | 46 
  4 files changed, 207 insertions(+)

diff --git a/doc/device-tree-bindings/regulator/regulator.txt 
b/doc/device-tree-bindings/regulator/regulator.txt
index 4ba642b7c77f..6c9a02120fde 100644
--- a/doc/device-tree-bindings/regulator/regulator.txt
+++ b/doc/device-tree-bindings/regulator/regulator.txt
@@ -36,6 +36,28 @@ Optional properties:
  - regulator-always-on: regulator should never be disabled
  - regulator-boot-on: enabled by bootloader/firmware
  - regulator-ramp-delay: ramp delay for regulator (in uV/us)
+- regulator-init-microvolt: a init allowed Voltage value
+- regulator-state-(standby|mem|disk)
+  type: object
+  description:
+sub-nodes for regulator state in Standby, Suspend-to-RAM, and
+Suspend-to-DISK modes. Equivalent with standby, mem, and disk Linux
+sleep states.
+
+properties:
+  regulator-on-in-suspend:
+description: regulator should be on in suspend state.
+type: boolean
+
+  regulator-off-in-suspend:
+description: regulator should be off in suspend state.
+type: boolean
+
+  regulator-suspend-microvolt:
+description: the default voltage which regulator would be set in
+  suspend. This property is now deprecated, instead setting voltage
+  for suspend mode via the API which regulator driver provides is
+  recommended.
  
  Note

  The "regulator-name" constraint is used for setting the device's uclass
@@ -59,7 +81,12 @@ ldo0 {
regulator-max-microvolt = <180>;
regulator-min-microamp = <10>;
regulator-max-microamp = <10>;
+   regulator-init-microvolt = <180>;
regulator-always-on;
regulator-boot-on;
regulator-ramp-delay = <12000>;
+   regulator-state-mem {
+   regulator-on-in-suspend;
+   regulator-suspend-microvolt = <180>;
+   };
  };
diff --git a/drivers/power/regulator/regulator-uclass.c 
b/drivers/power/regulator/regulator-uclass.c
index 76be95bcd159..b49c0829ed31 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -77,6 +77,33 @@ int regulator_set_value(struct udevice *dev, int uV)
return ret;
  }
  
+int regulator_set_suspend_value(struct udevice *dev, int uV)

+{
+   const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
+   struct dm_regulator_uclass_platdata *uc_pdata;
+
+   uc_pdata = dev_get_uclass_platdata(dev);
+   if (uc_pdata->min_uV != -ENODATA && uV < uc_pdata->min_uV)
+   return -EINVAL;
+   if (uc_pdata->max_uV != -ENODATA && uV > uc_pdata->max_uV)
+   return -EINVAL;
+
+   if (!ops->set_suspend_value)
+   return -ENOSYS;
+
+   return ops->set_suspend_value(dev, uV);
+}
+
+int regulator_get_suspend_value(struct udevice *dev)
+{
+   const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
+
+   if (!ops->get_suspend_value)
+   return -ENOSYS;
+
+   return ops->get_suspend_value(dev);
+}
+
  /*
   * To be called with at most caution as there is no check
   * before setting the actual voltage value.
@@ -170,6 +197,26 @@ int regulator_set_enable_if_allowed(struct udevice *dev, 
bool enable)
return ret;
  }
  
+int regulator_set_suspend_enable(struct udevice *dev, bool enable)

+{
+   const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
+
+   if (!ops->set_suspend_enable)
+   return -ENOSYS;
+
+   return ops->set_suspend_enable(dev, enable);
+}
+
+int regulator_get_suspend_enable(struct udevice *dev)
+{
+   const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
+
+   if (!ops->get_suspend_enable)
+   return -ENOSYS;
+
+   return ops->get_suspend_enable(dev);
+}
+
  int regulator_get_mode(struct udevice *dev)
  {
const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
@@ -235,6 +282,14 @@ int regulator_autoset(struct udevice *dev)
int ret = 0;
  
  	uc_pdata = dev_get_uclass_platdata(dev);

+
+   ret = regulator_set_suspend_enable(dev, uc_pdata->suspend_on);
+   if (!ret && uc_pdata->suspend_on) {
+   ret = regulator_set_suspend_value(dev, uc_pdata->suspend_uV);
+   if (!ret)
+   

[U-Boot] [PATCH v3 1/8] dm: regulator: support regulator more state

2019-09-19 Thread Elaine Zhang
From: Joseph Chen 

support parse regulator standard property:
regulator-off-in-suspend;
regulator-init-microvolt;
regulator-suspend-microvolt:
 regulator_get_suspend_enable
 regulator_set_suspend_enable
 regulator_get_suspend_value
 regulator_set_suspend_value

Signed-off-by: Joseph Chen 
Signed-off-by: Elaine Zhang 
---
 doc/device-tree-bindings/regulator/regulator.txt | 27 +
 drivers/power/regulator/regulator-uclass.c   | 70 
 include/power/regulator.h| 64 ++
 test/dm/regulator.c  | 46 
 4 files changed, 207 insertions(+)

diff --git a/doc/device-tree-bindings/regulator/regulator.txt 
b/doc/device-tree-bindings/regulator/regulator.txt
index 4ba642b7c77f..6c9a02120fde 100644
--- a/doc/device-tree-bindings/regulator/regulator.txt
+++ b/doc/device-tree-bindings/regulator/regulator.txt
@@ -36,6 +36,28 @@ Optional properties:
 - regulator-always-on: regulator should never be disabled
 - regulator-boot-on: enabled by bootloader/firmware
 - regulator-ramp-delay: ramp delay for regulator (in uV/us)
+- regulator-init-microvolt: a init allowed Voltage value
+- regulator-state-(standby|mem|disk)
+  type: object
+  description:
+sub-nodes for regulator state in Standby, Suspend-to-RAM, and
+Suspend-to-DISK modes. Equivalent with standby, mem, and disk Linux
+sleep states.
+
+properties:
+  regulator-on-in-suspend:
+description: regulator should be on in suspend state.
+type: boolean
+
+  regulator-off-in-suspend:
+description: regulator should be off in suspend state.
+type: boolean
+
+  regulator-suspend-microvolt:
+description: the default voltage which regulator would be set in
+  suspend. This property is now deprecated, instead setting voltage
+  for suspend mode via the API which regulator driver provides is
+  recommended.
 
 Note
 The "regulator-name" constraint is used for setting the device's uclass
@@ -59,7 +81,12 @@ ldo0 {
regulator-max-microvolt = <180>;
regulator-min-microamp = <10>;
regulator-max-microamp = <10>;
+   regulator-init-microvolt = <180>;
regulator-always-on;
regulator-boot-on;
regulator-ramp-delay = <12000>;
+   regulator-state-mem {
+   regulator-on-in-suspend;
+   regulator-suspend-microvolt = <180>;
+   };
 };
diff --git a/drivers/power/regulator/regulator-uclass.c 
b/drivers/power/regulator/regulator-uclass.c
index 76be95bcd159..b49c0829ed31 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -77,6 +77,33 @@ int regulator_set_value(struct udevice *dev, int uV)
return ret;
 }
 
+int regulator_set_suspend_value(struct udevice *dev, int uV)
+{
+   const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
+   struct dm_regulator_uclass_platdata *uc_pdata;
+
+   uc_pdata = dev_get_uclass_platdata(dev);
+   if (uc_pdata->min_uV != -ENODATA && uV < uc_pdata->min_uV)
+   return -EINVAL;
+   if (uc_pdata->max_uV != -ENODATA && uV > uc_pdata->max_uV)
+   return -EINVAL;
+
+   if (!ops->set_suspend_value)
+   return -ENOSYS;
+
+   return ops->set_suspend_value(dev, uV);
+}
+
+int regulator_get_suspend_value(struct udevice *dev)
+{
+   const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
+
+   if (!ops->get_suspend_value)
+   return -ENOSYS;
+
+   return ops->get_suspend_value(dev);
+}
+
 /*
  * To be called with at most caution as there is no check
  * before setting the actual voltage value.
@@ -170,6 +197,26 @@ int regulator_set_enable_if_allowed(struct udevice *dev, 
bool enable)
return ret;
 }
 
+int regulator_set_suspend_enable(struct udevice *dev, bool enable)
+{
+   const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
+
+   if (!ops->set_suspend_enable)
+   return -ENOSYS;
+
+   return ops->set_suspend_enable(dev, enable);
+}
+
+int regulator_get_suspend_enable(struct udevice *dev)
+{
+   const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
+
+   if (!ops->get_suspend_enable)
+   return -ENOSYS;
+
+   return ops->get_suspend_enable(dev);
+}
+
 int regulator_get_mode(struct udevice *dev)
 {
const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
@@ -235,6 +282,14 @@ int regulator_autoset(struct udevice *dev)
int ret = 0;
 
uc_pdata = dev_get_uclass_platdata(dev);
+
+   ret = regulator_set_suspend_enable(dev, uc_pdata->suspend_on);
+   if (!ret && uc_pdata->suspend_on) {
+   ret = regulator_set_suspend_value(dev, uc_pdata->suspend_uV);
+   if (!ret)
+   return ret;
+   }
+
if (!uc_pdata->always_on && !uc_pdata->boot_on)
return -EMEDI