From owner-svn-src-projects@FreeBSD.ORG Fri May 10 14:28:45 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 80AAACD5; Fri, 10 May 2013 14:28:45 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 735F3D6D; Fri, 10 May 2013 14:28:45 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r4AESjPp007660; Fri, 10 May 2013 14:28:45 GMT (envelope-from jhibbits@svn.freebsd.org) Received: (from jhibbits@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r4AESjQk007656; Fri, 10 May 2013 14:28:45 GMT (envelope-from jhibbits@svn.freebsd.org) Message-Id: <201305101428.r4AESjQk007656@svn.freebsd.org> From: Justin Hibbits Date: Fri, 10 May 2013 14:28:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r250455 - projects/pmac_pmu/sys/powerpc/powermac X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 May 2013 14:28:45 -0000 Author: jhibbits Date: Fri May 10 14:28:44 2013 New Revision: 250455 URL: http://svnweb.freebsd.org/changeset/base/250455 Log: Save and restore the mac-io GPIOs across suspend/resume. Modified: projects/pmac_pmu/sys/powerpc/powermac/macgpio.c projects/pmac_pmu/sys/powerpc/powermac/macgpiovar.h Modified: projects/pmac_pmu/sys/powerpc/powermac/macgpio.c ============================================================================== --- projects/pmac_pmu/sys/powerpc/powermac/macgpio.c Fri May 10 14:28:16 2013 (r250454) +++ projects/pmac_pmu/sys/powerpc/powermac/macgpio.c Fri May 10 14:28:44 2013 (r250455) @@ -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(dev 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), @@ -322,6 +327,42 @@ macgpio_deactivate_resource(device_t bus return (bus_deactivate_resource(bus, type, rid, res)); } +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); + for (i = 0; i < GPIO_EXTINT_COUNT; i++) + sc->sc_saved_extint_gpios[i] = bus_read_1(sc->sc_gpios, GPIO_EXTINT_BASE); + + 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, sc->sc_saved_gpios[i]); + for (i = 0; i < GPIO_EXTINT_COUNT; i++) + bus_write_1(sc->sc_gpios, GPIO_EXTINT_BASE, sc->sc_saved_extint_gpios[i]); + + return (0); +} + uint8_t macgpio_read(device_t dev) { Modified: projects/pmac_pmu/sys/powerpc/powermac/macgpiovar.h ============================================================================== --- projects/pmac_pmu/sys/powerpc/powermac/macgpiovar.h Fri May 10 14:28:16 2013 (r250454) +++ projects/pmac_pmu/sys/powerpc/powermac/macgpiovar.h Fri May 10 14:28:44 2013 (r250455) @@ -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 */