summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmcneill <jmcneill@NetBSD.org>2016-06-15 13:13:40 +0000
committerjmcneill <jmcneill@NetBSD.org>2016-06-15 13:13:40 +0000
commita9abd0ccbe4af3aba53ba8a1271d2a634bb65cae (patch)
tree0e43740ddf1f7edca306df3004c1d4ee7f13c617
parent0faafe2604e184e8b091a7cf5c9087acbe187cc5 (diff)
If either "regulator-boot-on" or "regulator-always-on" properties are true,
explicitly enable the regulator at attach time. In addition, if the "startup-delay-us" property is present, delay after enabling the regulator.
-rw-r--r--sys/dev/fdt/fixedregulator.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/sys/dev/fdt/fixedregulator.c b/sys/dev/fdt/fixedregulator.c
index 5df08b0130f..d5f4b00f990 100644
--- a/sys/dev/fdt/fixedregulator.c
+++ b/sys/dev/fdt/fixedregulator.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fixedregulator.c,v 1.3 2015/12/22 22:19:07 jmcneill Exp $ */
+/* $NetBSD: fixedregulator.c,v 1.4 2016/06/15 13:13:40 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fixedregulator.c,v 1.3 2015/12/22 22:19:07 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fixedregulator.c,v 1.4 2016/06/15 13:13:40 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -57,7 +57,9 @@ struct fixedregulator_softc {
struct fdtbus_gpio_pin *sc_pin;
bool sc_always_on;
+ bool sc_boot_on;
bool sc_enable_val;
+ uint32_t sc_delay;
};
CFATTACH_DECL_NEW(fregulator, sizeof(struct fixedregulator_softc),
@@ -104,13 +106,24 @@ fixedregulator_attach(device_t parent, device_t self, void *aux)
gpioflags |= GPIO_PIN_OPENDRAIN;
sc->sc_always_on = of_getprop_bool(phandle, "regulator-always-on");
+ sc->sc_boot_on = of_getprop_bool(phandle, "regulator-boot-on");
+ sc->sc_enable_val = of_getprop_bool(phandle, "enable-active-high");
+ if (of_getprop_uint32(phandle, "startup-delay-us", &sc->sc_delay) != 0)
+ sc->sc_delay = 0;
+
sc->sc_pin = fdtbus_gpio_acquire(phandle, "gpio", gpioflags);
if (sc->sc_pin == NULL)
sc->sc_always_on = true;
- sc->sc_enable_val = of_getprop_bool(phandle, "enable-active-high");
fdtbus_register_regulator_controller(self, phandle,
&fixedregulator_funcs);
+
+ /*
+ * If the regulator is flagged as always on or enabled at boot,
+ * ensure that it is enabled
+ */
+ if (sc->sc_always_on || sc->sc_boot_on)
+ fixedregulator_enable(self, true);
}
static int
@@ -130,18 +143,14 @@ fixedregulator_enable(device_t dev, bool enable)
struct fixedregulator_softc * const sc = device_private(dev);
if (enable) {
- if (sc->sc_always_on) {
- return 0;
- } else {
+ if (sc->sc_pin != NULL)
fdtbus_gpio_write_raw(sc->sc_pin, sc->sc_enable_val);
- return 0;
- }
+ if (sc->sc_delay > 0)
+ delay(sc->sc_delay);
} else {
- if (sc->sc_always_on) {
+ if (sc->sc_always_on)
return EIO;
- } else {
- fdtbus_gpio_write_raw(sc->sc_pin, !sc->sc_enable_val);
- return 0;
- }
+ fdtbus_gpio_write_raw(sc->sc_pin, !sc->sc_enable_val);
}
+ return 0;
}