diff mbox

[U-Boot,v3,37/54] dm: power: Add a function to set up all regulators

Message ID 1435095556-15924-38-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass June 23, 2015, 9:38 p.m. UTC
The device tree provides information about which regulators should be
on at boot, or always on. Use this to set them up automatically.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3: None
Changes in v2: None

 drivers/power/regulator/regulator-uclass.c | 22 ++++++++++++++++++++++
 include/power/regulator.h                  | 11 +++++++++++
 2 files changed, 33 insertions(+)

Comments

Przemyslaw Marczak July 1, 2015, 9:44 a.m. UTC | #1
Hello Simon,

On 06/23/2015 11:38 PM, Simon Glass wrote:
> The device tree provides information about which regulators should be
> on at boot, or always on. Use this to set them up automatically.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v3: None
> Changes in v2: None
>
>   drivers/power/regulator/regulator-uclass.c | 22 ++++++++++++++++++++++
>   include/power/regulator.h                  | 11 +++++++++++
>   2 files changed, 33 insertions(+)
>
> diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
> index 687d3b1..a2d0b9f 100644
> --- a/drivers/power/regulator/regulator-uclass.c
> +++ b/drivers/power/regulator/regulator-uclass.c
> @@ -306,6 +306,28 @@ static int regulator_pre_probe(struct udevice *dev)
>   	return 0;
>   }
>
> +int regulators_enable_boot_on(bool verbose)
> +{
> +	struct udevice *dev;
> +	struct uclass *uc;
> +	int ret;
> +
> +	ret = uclass_get(UCLASS_REGULATOR, &uc);
> +	if (ret)
> +		return ret;
> +	for (uclass_first_device(UCLASS_REGULATOR, &dev);
> +	     dev && !ret;
> +	     uclass_next_device(&dev)) {
> +		ret = regulator_autoset(dev);
> +		if (ret == -EMEDIUMTYPE)
> +			continue;
> +		if (verbose)
> +			regulator_show(dev, ret);
> +	}
> +
> +	return ret;
> +}
> +
>   UCLASS_DRIVER(regulator) = {
>   	.id		= UCLASS_REGULATOR,
>   	.name		= "regulator",
> diff --git a/include/power/regulator.h b/include/power/regulator.h
> index 86e9c3b..0bdb496 100644
> --- a/include/power/regulator.h
> +++ b/include/power/regulator.h
> @@ -316,6 +316,17 @@ int regulator_get_mode(struct udevice *dev);
>   int regulator_set_mode(struct udevice *dev, int mode_id);
>
>   /**
> + * regulators_enable_boot_on() - enable regulators needed for boot
> + *
> + * This enables all regulators which are marked to be on at boot time. This
> + * only works for regulators which don't have a range for voltage/current,
> + * since in that case it is not possible to know which value to use.
> + *
> + * This effectively caslls regulator_autoset() for every regulator.

"calls"

> + */
> +int regulators_enable_boot_on(bool verbose);
> +
> +/**
>    * regulator_autoset: setup the the voltage/current on a regulator
>    *
>    * The setup depends on constraints found in device's uclass's platform data
>

Tested on:
- Odroid U3 (odroid_defconfig)
- Sandbox - ut pmic/regulator

Tested-by: Przemyslaw Marczak <p.marczak@samsung.com>
Acked-by: Przemyslaw Marczak <p.marczak@samsung.com>

Best regards,
Simon Glass July 17, 2015, 11:57 p.m. UTC | #2
On 1 July 2015 at 03:44, Przemyslaw Marczak <p.marczak@samsung.com> wrote:
> Hello Simon,
>
> On 06/23/2015 11:38 PM, Simon Glass wrote:
>>
>> The device tree provides information about which regulators should be
>> on at boot, or always on. Use this to set them up automatically.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>
>> ---
>>
>> Changes in v3: None
>> Changes in v2: None
>>
>>   drivers/power/regulator/regulator-uclass.c | 22 ++++++++++++++++++++++
>>   include/power/regulator.h                  | 11 +++++++++++
>>   2 files changed, 33 insertions(+)
>>
>> diff --git a/drivers/power/regulator/regulator-uclass.c
>> b/drivers/power/regulator/regulator-uclass.c
>> index 687d3b1..a2d0b9f 100644
>> --- a/drivers/power/regulator/regulator-uclass.c
>> +++ b/drivers/power/regulator/regulator-uclass.c
>> @@ -306,6 +306,28 @@ static int regulator_pre_probe(struct udevice *dev)
>>         return 0;
>>   }
>>
>> +int regulators_enable_boot_on(bool verbose)
>> +{
>> +       struct udevice *dev;
>> +       struct uclass *uc;
>> +       int ret;
>> +
>> +       ret = uclass_get(UCLASS_REGULATOR, &uc);
>> +       if (ret)
>> +               return ret;
>> +       for (uclass_first_device(UCLASS_REGULATOR, &dev);
>> +            dev && !ret;
>> +            uclass_next_device(&dev)) {
>> +               ret = regulator_autoset(dev);
>> +               if (ret == -EMEDIUMTYPE)
>> +                       continue;
>> +               if (verbose)
>> +                       regulator_show(dev, ret);
>> +       }
>> +
>> +       return ret;
>> +}
>> +
>>   UCLASS_DRIVER(regulator) = {
>>         .id             = UCLASS_REGULATOR,
>>         .name           = "regulator",
>> diff --git a/include/power/regulator.h b/include/power/regulator.h
>> index 86e9c3b..0bdb496 100644
>> --- a/include/power/regulator.h
>> +++ b/include/power/regulator.h
>> @@ -316,6 +316,17 @@ int regulator_get_mode(struct udevice *dev);
>>   int regulator_set_mode(struct udevice *dev, int mode_id);
>>
>>   /**
>> + * regulators_enable_boot_on() - enable regulators needed for boot
>> + *
>> + * This enables all regulators which are marked to be on at boot time.
>> This
>> + * only works for regulators which don't have a range for
>> voltage/current,
>> + * since in that case it is not possible to know which value to use.
>> + *
>> + * This effectively caslls regulator_autoset() for every regulator.
>
>
> "calls"
>
>> + */
>> +int regulators_enable_boot_on(bool verbose);
>> +
>> +/**
>>    * regulator_autoset: setup the the voltage/current on a regulator
>>    *
>>    * The setup depends on constraints found in device's uclass's platform
>> data
>>
>
> Tested on:
> - Odroid U3 (odroid_defconfig)
> - Sandbox - ut pmic/regulator
>
> Tested-by: Przemyslaw Marczak <p.marczak@samsung.com>
> Acked-by: Przemyslaw Marczak <p.marczak@samsung.com>
>
> Best regards,
> --
> Przemyslaw Marczak
> Samsung R&D Institute Poland
> Samsung Electronics
> p.marczak@samsung.com

Applied to u-boot-dm.
diff mbox

Patch

diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
index 687d3b1..a2d0b9f 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -306,6 +306,28 @@  static int regulator_pre_probe(struct udevice *dev)
 	return 0;
 }
 
+int regulators_enable_boot_on(bool verbose)
+{
+	struct udevice *dev;
+	struct uclass *uc;
+	int ret;
+
+	ret = uclass_get(UCLASS_REGULATOR, &uc);
+	if (ret)
+		return ret;
+	for (uclass_first_device(UCLASS_REGULATOR, &dev);
+	     dev && !ret;
+	     uclass_next_device(&dev)) {
+		ret = regulator_autoset(dev);
+		if (ret == -EMEDIUMTYPE)
+			continue;
+		if (verbose)
+			regulator_show(dev, ret);
+	}
+
+	return ret;
+}
+
 UCLASS_DRIVER(regulator) = {
 	.id		= UCLASS_REGULATOR,
 	.name		= "regulator",
diff --git a/include/power/regulator.h b/include/power/regulator.h
index 86e9c3b..0bdb496 100644
--- a/include/power/regulator.h
+++ b/include/power/regulator.h
@@ -316,6 +316,17 @@  int regulator_get_mode(struct udevice *dev);
 int regulator_set_mode(struct udevice *dev, int mode_id);
 
 /**
+ * regulators_enable_boot_on() - enable regulators needed for boot
+ *
+ * This enables all regulators which are marked to be on at boot time. This
+ * only works for regulators which don't have a range for voltage/current,
+ * since in that case it is not possible to know which value to use.
+ *
+ * This effectively caslls regulator_autoset() for every regulator.
+ */
+int regulators_enable_boot_on(bool verbose);
+
+/**
  * regulator_autoset: setup the the voltage/current on a regulator
  *
  * The setup depends on constraints found in device's uclass's platform data