diff options
author | Justin Hibbits <jhibbits@FreeBSD.org> | 2014-01-11 06:35:29 +0000 |
---|---|---|
committer | Justin Hibbits <jhibbits@FreeBSD.org> | 2014-01-11 06:35:29 +0000 |
commit | e68afcedbcfa0050f81905c7a3073e7bbfa13675 (patch) | |
tree | b55b5f6f765fd6cad2e6398bfd7f523e7f36a3c3 /sys/powerpc | |
parent | 176666c2c95a9d7616956c5d0a0c16802e55757e (diff) | |
download | src-e68afcedbcfa0050f81905c7a3073e7bbfa13675.tar.gz src-e68afcedbcfa0050f81905c7a3073e7bbfa13675.zip |
Save and restore the GPIOs on the macio for suspend/resume.
Notes
Notes:
svn path=/head/; revision=260533
Diffstat (limited to 'sys/powerpc')
-rw-r--r-- | sys/powerpc/powermac/macgpio.c | 44 | ||||
-rw-r--r-- | sys/powerpc/powermac/macgpiovar.h | 6 |
2 files changed, 48 insertions, 2 deletions
diff --git a/sys/powerpc/powermac/macgpio.c b/sys/powerpc/powermac/macgpio.c index 709bcffcad2a..9fc4541c0788 100644 --- a/sys/powerpc/powermac/macgpio.c +++ b/sys/powerpc/powermac/macgpio.c @@ -59,6 +59,9 @@ struct macgpio_softc { phandle_t sc_node; struct resource *sc_gpios; int sc_gpios_rid; + uint32_t sc_saved_gpio_levels[2]; + uint32_t sc_saved_gpios[GPIO_COUNT]; + uint32_t sc_saved_extint_gpios[GPIO_EXTINT_COUNT]; }; static MALLOC_DEFINE(M_MACGPIO, "macgpio", "macgpio device information"); @@ -74,6 +77,8 @@ static int macgpio_activate_resource(device_t, device_t, int, int, static int macgpio_deactivate_resource(device_t, device_t, int, int, struct resource *); static ofw_bus_get_devinfo_t macgpio_get_devinfo; +static int macgpio_suspend(device_t dev); +static int macgpio_resume(device_t dev); /* * Bus interface definition @@ -84,8 +89,8 @@ static device_method_t macgpio_methods[] = { DEVMETHOD(device_attach, macgpio_attach), DEVMETHOD(device_detach, bus_generic_detach), DEVMETHOD(device_shutdown, bus_generic_shutdown), - DEVMETHOD(device_suspend, bus_generic_suspend), - DEVMETHOD(device_resume, bus_generic_resume), + DEVMETHOD(device_suspend, macgpio_suspend), + DEVMETHOD(device_resume, macgpio_resume), /* Bus interface */ DEVMETHOD(bus_print_child, macgpio_print_child), @@ -361,3 +366,38 @@ macgpio_get_devinfo(device_t dev, device_t child) return (&dinfo->mdi_obdinfo); } +static int +macgpio_suspend(device_t dev) +{ + struct macgpio_softc *sc; + int i; + + sc = device_get_softc(dev); + sc->sc_saved_gpio_levels[0] = bus_read_4(sc->sc_gpios, GPIO_LEVELS_0); + sc->sc_saved_gpio_levels[1] = bus_read_4(sc->sc_gpios, GPIO_LEVELS_1); + + for (i = 0; i < GPIO_COUNT; i++) + sc->sc_saved_gpios[i] = bus_read_1(sc->sc_gpios, GPIO_BASE + i); + for (i = 0; i < GPIO_EXTINT_COUNT; i++) + sc->sc_saved_extint_gpios[i] = bus_read_1(sc->sc_gpios, GPIO_EXTINT_BASE + i); + + return (0); +} + +static int +macgpio_resume(device_t dev) +{ + struct macgpio_softc *sc; + int i; + + sc = device_get_softc(dev); + bus_write_4(sc->sc_gpios, GPIO_LEVELS_0, sc->sc_saved_gpio_levels[0]); + bus_write_4(sc->sc_gpios, GPIO_LEVELS_1, sc->sc_saved_gpio_levels[1]); + + for (i = 0; i < GPIO_COUNT; i++) + bus_write_1(sc->sc_gpios, GPIO_BASE + i, sc->sc_saved_gpios[i]); + for (i = 0; i < GPIO_EXTINT_COUNT; i++) + bus_write_1(sc->sc_gpios, GPIO_EXTINT_BASE + i, sc->sc_saved_extint_gpios[i]); + + return (0); +} diff --git a/sys/powerpc/powermac/macgpiovar.h b/sys/powerpc/powermac/macgpiovar.h index b4f02ea15b4f..2719e44ed313 100644 --- a/sys/powerpc/powermac/macgpiovar.h +++ b/sys/powerpc/powermac/macgpiovar.h @@ -32,6 +32,12 @@ #define GPIO_EXTINT_BASE 0x08 #define GPIO_BASE 0x1a +#define GPIO_EXTINT_COUNT 0x12 +#define GPIO_COUNT 0x11 + +#define GPIO_LEVELS_0 0x50 +#define GPIO_LEVELS_1 0x54 + /* gpio bit definitions */ #define GPIO_DATA 0x01 /* GPIO data */ #define GPIO_LEVEL_RO 0x02 /* read-only level on pin */ |