Commit aa2067a8692ece9b4ce470a2c6c6704987bfd56c

Authored by Sven Schwermer
Committed by Tom Rini
1 parent 2f7a5f2682

regulator: Allow enabling GPIO regulator

Drivers need to be able to enable regulators that may be implemented as
GPIO regulators. Example: fsl_esdhc enables the vqmmc supply which is
commonly implemented as a GPIO regulator in order to switch between I/O
voltage levels.

Signed-off-by: Sven Schwermer <sven@svenschwermer.de>
Reviewed-by: Lukasz Majewski <lukma@denx.de>

Showing 2 changed files with 19 additions and 1 deletions Side-by-side Diff

drivers/power/regulator/Kconfig
... ... @@ -120,6 +120,7 @@
120 120 config DM_REGULATOR_GPIO
121 121 bool "Enable Driver Model for GPIO REGULATOR"
122 122 depends on DM_REGULATOR && DM_GPIO
  123 + select DM_REGULATOR_COMMON
123 124 ---help---
124 125 This config enables implementation of driver-model regulator uclass
125 126 features for gpio regulators. The driver implements get/set for
... ... @@ -128,6 +129,7 @@
128 129 config SPL_DM_REGULATOR_GPIO
129 130 bool "Enable Driver Model for GPIO REGULATOR in SPL"
130 131 depends on DM_REGULATOR_GPIO && SPL_GPIO_SUPPORT
  132 + select SPL_DM_REGULATOR_COMMON
131 133 ---help---
132 134 This config enables implementation of driver-model regulator uclass
133 135 features for gpio regulators in SPL.
drivers/power/regulator/gpio-regulator.c
... ... @@ -4,6 +4,7 @@
4 4 * Keerthy <j-keerthy@ti.com>
5 5 */
6 6  
  7 +#include "regulator_common.h"
7 8 #include <common.h>
8 9 #include <fdtdec.h>
9 10 #include <errno.h>
... ... @@ -18,6 +19,7 @@
18 19 DECLARE_GLOBAL_DATA_PTR;
19 20  
20 21 struct gpio_regulator_platdata {
  22 + struct regulator_common_platdata common;
21 23 struct gpio_desc gpio; /* GPIO for regulator voltage control */
22 24 int states[GPIO_REGULATOR_MAX_STATES];
23 25 int voltages[GPIO_REGULATOR_MAX_STATES];
... ... @@ -65,7 +67,7 @@
65 67 j++;
66 68 }
67 69  
68   - return 0;
  70 + return regulator_common_ofdata_to_platdata(dev, &dev_pdata->common, "enable-gpios");
69 71 }
70 72  
71 73 static int gpio_regulator_get_value(struct udevice *dev)
72 74  
... ... @@ -116,9 +118,23 @@
116 118 return 0;
117 119 }
118 120  
  121 +static int gpio_regulator_get_enable(struct udevice *dev)
  122 +{
  123 + struct gpio_regulator_platdata *dev_pdata = dev_get_platdata(dev);
  124 + return regulator_common_get_enable(dev, &dev_pdata->common);
  125 +}
  126 +
  127 +static int gpio_regulator_set_enable(struct udevice *dev, bool enable)
  128 +{
  129 + struct gpio_regulator_platdata *dev_pdata = dev_get_platdata(dev);
  130 + return regulator_common_set_enable(dev, &dev_pdata->common, enable);
  131 +}
  132 +
119 133 static const struct dm_regulator_ops gpio_regulator_ops = {
120 134 .get_value = gpio_regulator_get_value,
121 135 .set_value = gpio_regulator_set_value,
  136 + .get_enable = gpio_regulator_get_enable,
  137 + .set_enable = gpio_regulator_set_enable,
122 138 };
123 139  
124 140 static const struct udevice_id gpio_regulator_ids[] = {