Module Name:    src
Committed By:   jmcneill
Date:           Wed Jun 15 13:13:40 UTC 2016

Modified Files:
        src/sys/dev/fdt: fixedregulator.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/fdt/fixedregulator.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/fdt/fixedregulator.c
diff -u src/sys/dev/fdt/fixedregulator.c:1.3 src/sys/dev/fdt/fixedregulator.c:1.4
--- src/sys/dev/fdt/fixedregulator.c:1.3	Tue Dec 22 22:19:07 2015
+++ src/sys/dev/fdt/fixedregulator.c	Wed Jun 15 13:13:40 2016
@@ -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 <jmcne...@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, d
 		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
 	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;
 }

Reply via email to