--- sys/arch/palm/conf/GENERIC | 3 + sys/arch/palm/conf/RAMDISK | 3 + sys/arch/palm/conf/files.palm | 3 + sys/arch/palm/dev/palm_apm.c | 195 +++++++++++++++++++++++++++++++++++++++++ sys/arch/palm/dev/palm_apm.h | 20 ++++ 5 files changed, 224 insertions(+), 0 deletions(-) create mode 100644 sys/arch/palm/dev/palm_apm.c create mode 100644 sys/arch/palm/dev/palm_apm.h
diff --git a/sys/arch/palm/conf/GENERIC b/sys/arch/palm/conf/GENERIC index 419b611..feff44d 100644 --- a/sys/arch/palm/conf/GENERIC +++ b/sys/arch/palm/conf/GENERIC @@ -217,6 +217,9 @@ owid* at onewire? # ID owsbm* at onewire? # Smart Battery Monitor owtemp* at onewire? # Temperature +# APM emulation +apm0 at pxaip? + # Pseudo-Devices pseudo-device wsmux 2 # mouse & keyboard multiplexor pseudo-device hotplug 1 # devices hot plugging diff --git a/sys/arch/palm/conf/RAMDISK b/sys/arch/palm/conf/RAMDISK index 9c3cfd7..c8c40c9 100644 --- a/sys/arch/palm/conf/RAMDISK +++ b/sys/arch/palm/conf/RAMDISK @@ -152,6 +152,9 @@ wskbd0 at pxa27x_kpc0 mux 1 lcd0 at pxaip? addr 0x44000000 wsdisplay* at lcd? console ? +# APM emulation +apm0 at pxaip? + # Pseudo-Devices pseudo-device wsmux 2 # mouse & keyboard multiplexor #pseudo-device crypto 1 diff --git a/sys/arch/palm/conf/files.palm b/sys/arch/palm/conf/files.palm index bb756a8..6f960ca 100644 --- a/sys/arch/palm/conf/files.palm +++ b/sys/arch/palm/conf/files.palm @@ -32,6 +32,9 @@ file arch/palm/palm/palm_lcd.c lcd_pxaip attach pxammc at pxaip with pxammc_palm file arch/palm/dev/palm_mmc.c pxammc_palm +# Power manager and APM emulation +attach apm at pxaip with pxaapm_palm +file arch/palm/dev/palm_apm.c pxaapm_palm # # Machine-independent ATA drivers # diff --git a/sys/arch/palm/dev/palm_apm.c b/sys/arch/palm/dev/palm_apm.c new file mode 100644 index 0000000..fa527d2 --- /dev/null +++ b/sys/arch/palm/dev/palm_apm.c @@ -0,0 +1,195 @@ +/* $OpenBSD: src/sys/arch/zaurus/dev/zaurus_apm.c,v 1.13 2006/12/12 23:14:28 dim Exp $ */ + +/* + * Copyright (c) 2005 Uwe Stuehler <u...@bsdx.de> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/timeout.h> +#include <sys/conf.h> +#include <sys/sysctl.h> + +#include <arm/xscale/pxa2x0reg.h> +#include <arm/xscale/pxa2x0var.h> +#include <arm/xscale/pxa2x0_apm.h> +#include <arm/xscale/pxa2x0_gpio.h> + +#include <palm/dev/palm_apm.h> + +#if defined(APMDEBUG) +#define DPRINTF(x) printf x +#else +#define DPRINTF(x) /**/ +#endif + +struct papm_softc { + struct pxa2x0_apm_softc sc; + struct timeout sc_poll; + struct timeval sc_lastbattchk; + int sc_suspended; + u_int sc_event; +}; + +int apm_match(struct device *, void *, void *); +void apm_attach(struct device *, struct device *, void *); + +struct cfattach pxaapm_palm_ca = { + sizeof (struct papm_softc), apm_match, apm_attach +}; +extern struct cfdriver apm_cd; + +/* Prototypes */ + +int papm_get_event(struct pxa2x0_apm_softc *, u_int *); +void papm_suspend(struct pxa2x0_apm_softc *); +int papm_resume(struct pxa2x0_apm_softc *); +void pxa2x0_setperf(int); +int pxa2x0_cpuspeed(int *); + + +int +apm_match(struct device *parent, void *match, void *aux) +{ + return (1); +} + +void +apm_attach(struct device *parent, struct device *self, void *aux) +{ + struct papm_softc *sc = (struct papm_softc *)self; + + sc->sc_event = APM_NOEVENT; + sc->sc.sc_get_event = papm_get_event; + sc->sc.sc_suspend = papm_suspend; + sc->sc.sc_resume = papm_resume; + + pxa2x0_apm_attach_sub(&sc->sc); + + cpu_setperf = pxa2x0_setperf; + cpu_cpuspeed = pxa2x0_cpuspeed; +} + +/* + * apm_thread() calls this routine approximately once per second. + */ +int +papm_get_event(struct pxa2x0_apm_softc *pxa_sc, u_int *typep) +{ + struct papm_softc *sc = (struct papm_softc *)pxa_sc; + int s; + + s = splsoftclock(); + + *typep = sc->sc_event; + sc->sc_event = APM_NOEVENT; + + splx(s); + return 1; +} + +/* + * Called before suspending when all powerhooks are done. + */ +void +papm_suspend(struct pxa2x0_apm_softc *pxa_sc) +{ + struct papm_softc *sc = (struct papm_softc *)pxa_sc; + + /* Poll in suspended mode and forget the discharge timeout. */ + sc->sc_suspended = 1; + timeout_del(&sc->sc_poll); + + /* Make sure charging is enabled and RTC alarm is set. */ + timerclear(&sc->sc_lastbattchk); + + pxa2x0_wakeup_config(PXA2X0_WAKEUP_ALL, 1); +} + +/* + * Called after wake-up from suspend with interrupts still disabled, + * before any powerhooks are done. + */ +int +papm_resume(struct pxa2x0_apm_softc *pxa_sc) +{ + struct papm_softc *sc = (struct papm_softc *)pxa_sc; + int wakeup = 0; + + sc->sc_suspended = 0; + pxa2x0_rtc_setalarm(0); + + return (wakeup); +} + +void +papm_poweroff(void) +{ + struct pxa2x0_apm_softc *sc; + + KASSERT(apm_cd.cd_ndevs > 0 && apm_cd.cd_devs[0] != NULL); + sc = apm_cd.cd_devs[0]; + + dopowerhooks(PWR_SUSPEND); + + /* XXX enable charging during suspend */ + + /* XXX keep power LED state during suspend */ + + /* XXX do the same thing for GPIO 43 (BTTXD) */ + + /* XXX scoop power down */ + + /* XXX set PGSRn and GPDRn */ + + pxa2x0_wakeup_config(PXA2X0_WAKEUP_ALL, 1); + + do { + pxa2x0_apm_sleep(sc); + } + while (!papm_resume(sc)); + + papm_restart(); + + /* NOTREACHED */ + dopowerhooks(PWR_RESUME); +} + +/* + * Do a GPIO reset, immediately causing the processor to begin the normal + * boot sequence. See 2.7 Reset in the PXA27x Developer's Manual for the + * summary of effects of this kind of reset. + */ +void +papm_restart(void) +{ + if (apm_cd.cd_ndevs > 0 && apm_cd.cd_devs[0] != NULL) { + struct pxa2x0_apm_softc *sc = apm_cd.cd_devs[0]; + int rv; + + /* + * Reduce the ROM Delay Next Access and ROM Delay First + * Access times for synchronous flash connected to nCS1. + */ + rv = bus_space_read_4(sc->sc_iot, sc->sc_memctl_ioh, + MEMCTL_MSC0); + if ((rv & 0xffff0000) == 0x7ff00000) + bus_space_write_4(sc->sc_iot, sc->sc_memctl_ioh, + MEMCTL_MSC0, (rv & 0xffff) | 0x7ee00000); + } + + delay(1000000); +} diff --git a/sys/arch/palm/dev/palm_apm.h b/sys/arch/palm/dev/palm_apm.h new file mode 100644 index 0000000..cda1482 --- /dev/null +++ b/sys/arch/palm/dev/palm_apm.h @@ -0,0 +1,20 @@ +/* $OpenBSD: src/sys/arch/zaurus/dev/zaurus_apm.h,v 1.1 2005/04/11 03:21:03 uwe Exp $ */ + +/* + * Copyright (c) 2005 Uwe Stuehler <u...@bsdx.de> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +void papm_poweroff(void); +void papm_restart(void); -- 1.7.0.5