Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/fdt Defer acquiring the gpio until first use.
details: https://anonhg.NetBSD.org/src/rev/89053b41a3a2
branches: trunk
changeset: 353221:89053b41a3a2
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Mon Apr 24 10:55:26 2017 +0000
description:
Defer acquiring the gpio until first use.
diffstat:
sys/dev/fdt/fixedregulator.c | 26 +++++++++++++++++++-------
1 files changed, 19 insertions(+), 7 deletions(-)
diffs (77 lines):
diff -r c8ea77fbf8bf -r 89053b41a3a2 sys/dev/fdt/fixedregulator.c
--- a/sys/dev/fdt/fixedregulator.c Mon Apr 24 10:04:38 2017 +0000
+++ b/sys/dev/fdt/fixedregulator.c Mon Apr 24 10:55:26 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fixedregulator.c,v 1.4 2016/06/15 13:13:40 jmcneill Exp $ */
+/* $NetBSD: fixedregulator.c,v 1.5 2017/04/24 10:55:26 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fixedregulator.c,v 1.4 2016/06/15 13:13:40 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fixedregulator.c,v 1.5 2017/04/24 10:55:26 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -60,6 +60,9 @@
bool sc_boot_on;
bool sc_enable_val;
uint32_t sc_delay;
+
+ int sc_gpioflags;
+ bool sc_deferred;
};
CFATTACH_DECL_NEW(fregulator, sizeof(struct fixedregulator_softc),
@@ -81,7 +84,7 @@
const struct fdt_attach_args *faa = aux;
const int phandle = faa->faa_phandle;
char *name;
- int len, gpioflags;
+ int len;
sc->sc_dev = self;
sc->sc_phandle = phandle;
@@ -101,9 +104,9 @@
aprint_normal("\n");
}
- gpioflags = GPIO_PIN_OUTPUT;
+ sc->sc_gpioflags = GPIO_PIN_OUTPUT;
if (of_getprop_bool(phandle, "gpio-open-drain"))
- gpioflags |= GPIO_PIN_OPENDRAIN;
+ sc->sc_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");
@@ -111,9 +114,9 @@
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);
+ sc->sc_pin = fdtbus_gpio_acquire(phandle, "gpio", sc->sc_gpioflags);
if (sc->sc_pin == NULL)
- sc->sc_always_on = true;
+ sc->sc_always_on = OF_getproplen(phandle, "gpio") <= 0;
fdtbus_register_regulator_controller(self, phandle,
&fixedregulator_funcs);
@@ -129,6 +132,15 @@
static int
fixedregulator_acquire(device_t dev)
{
+ struct fixedregulator_softc * const sc = device_private(dev);
+
+ if (sc->sc_pin == NULL && !sc->sc_always_on) {
+ sc->sc_pin = fdtbus_gpio_acquire(sc->sc_phandle, "gpio",
+ sc->sc_gpioflags);
+ if (sc->sc_pin == NULL)
+ return ENXIO;
+ }
+
return 0;
}
Home |
Main Index |
Thread Index |
Old Index