diff options
author | Uwe Stuehler <uwe@cvs.openbsd.org> | 2005-01-20 23:34:38 +0000 |
---|---|---|
committer | Uwe Stuehler <uwe@cvs.openbsd.org> | 2005-01-20 23:34:38 +0000 |
commit | 09c839285bbc7eb5a6fd783b65e8062bddd7bf9d (patch) | |
tree | c26433986555f84a9e6a6b6a35d84bf7e4145f5e /sys | |
parent | 7e9121dd734b5d2fa58cbcd88fab714a947d8397 (diff) |
Enable apm/scoop drivers and report A/C power status correctly.
ok drahn@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/arm/xscale/files.pxa2x0 | 3 | ||||
-rw-r--r-- | sys/arch/arm/xscale/pxa2x0_apm.c | 49 | ||||
-rw-r--r-- | sys/arch/arm/xscale/pxa2x0_apm.h | 14 | ||||
-rw-r--r-- | sys/arch/zaurus/conf/GENERIC | 8 | ||||
-rw-r--r-- | sys/arch/zaurus/conf/RAMDISK | 8 | ||||
-rw-r--r-- | sys/arch/zaurus/conf/files.zaurus | 6 | ||||
-rw-r--r-- | sys/arch/zaurus/dev/zaurus_scoop.c | 43 | ||||
-rw-r--r-- | sys/arch/zaurus/dev/zaurus_scoopreg.h | 9 | ||||
-rw-r--r-- | sys/arch/zaurus/dev/zaurus_scoopvar.h | 8 | ||||
-rw-r--r-- | sys/arch/zaurus/zaurus/zaurus_apm.c | 90 |
10 files changed, 177 insertions, 61 deletions
diff --git a/sys/arch/arm/xscale/files.pxa2x0 b/sys/arch/arm/xscale/files.pxa2x0 index b15530901eb..d4046bc7089 100644 --- a/sys/arch/arm/xscale/files.pxa2x0 +++ b/sys/arch/arm/xscale/files.pxa2x0 @@ -1,4 +1,4 @@ -# $OpenBSD: files.pxa2x0,v 1.5 2005/01/19 02:02:34 uwe Exp $ +# $OpenBSD: files.pxa2x0,v 1.6 2005/01/20 23:34:36 uwe Exp $ # $NetBSD: files.pxa2x0,v 1.6 2004/05/01 19:09:14 thorpej Exp $ # # Configuration info for Intel PXA2[51]0 CPU support @@ -53,7 +53,6 @@ file arch/arm/xscale/pxa2x0_lcd.c lcd needs-flag # Power manager and APM emulation device apm -attach apm at pxaip file arch/arm/xscale/pxa2x0_apm.c apm needs-flag include "dev/pcmcia/files.pcmcia" diff --git a/sys/arch/arm/xscale/pxa2x0_apm.c b/sys/arch/arm/xscale/pxa2x0_apm.c index 5d47c7e39d2..4af0b9ee836 100644 --- a/sys/arch/arm/xscale/pxa2x0_apm.c +++ b/sys/arch/arm/xscale/pxa2x0_apm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pxa2x0_apm.c,v 1.1 2005/01/19 02:02:34 uwe Exp $ */ +/* $OpenBSD: pxa2x0_apm.c,v 1.2 2005/01/20 23:34:36 uwe Exp $ */ /*- * Copyright (c) 2001 Alexander Guy. All rights reserved. @@ -64,13 +64,6 @@ #define APM_LOCK(sc) lockmgr(&(sc)->sc_lock, LK_EXCLUSIVE, NULL, curproc) #define APM_UNLOCK(sc) lockmgr(&(sc)->sc_lock, LK_RELEASE, NULL, curproc) -int apmmatch(struct device *, void *, void *); -void apmattach(struct device *, struct device *, void *); - -struct cfattach apm_ca = { - sizeof(struct pxa2x0_apm_softc), apmmatch, apmattach -}; - struct cfdriver apm_cd = { NULL, "apm", DV_DULL }; @@ -84,6 +77,8 @@ int apm_userstandbys; int apm_suspends; int apm_battlow; +void apm_battery_info(struct pxa2x0_apm_softc *, + struct pxaapm_battery_info *); void apm_standby(struct pxa2x0_apm_softc *); void apm_suspend(struct pxa2x0_apm_softc *); void apm_resume(struct pxa2x0_apm_softc *); @@ -119,18 +114,14 @@ struct filterops apmread_filtops = #define SCFLAG_OWRITE (1 << 1) #define SCFLAG_OPEN (SCFLAG_OREAD|SCFLAG_OWRITE) -int -apmmatch(struct device *parent, void *match, void *aux) -{ - return 1; -} - void -apmattach(struct device *parent, struct device *self, void *aux) +apm_battery_info(struct pxa2x0_apm_softc *sc, + struct pxaapm_battery_info *battp) { - struct pxa2x0_apm_softc *sc = (struct pxa2x0_apm_softc *)self; - pxa2x0_apm_attach_sub((struct pxa2x0_apm_softc *)sc); + bzero(battp, sizeof(struct pxaapm_battery_info)); + if (sc->sc_battery_info != NULL) + sc->sc_battery_info(battp); } void @@ -173,6 +164,9 @@ void apm_periodic_check(struct pxa2x0_apm_softc *sc) { + if (sc->sc_periodic_check != NULL) + sc->sc_periodic_check(sc); + if (apm_suspends) { apm_userstandbys = 0; apm_suspends = 0; @@ -278,9 +272,7 @@ int apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) { struct pxa2x0_apm_softc *sc; -#if 0 - struct pmu_battery_info batt; -#endif + struct pxaapm_battery_info batt; struct apm_power_info *power; int error = 0; @@ -334,25 +326,19 @@ apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) case APM_IOC_GETPOWER: power = (struct apm_power_info *)data; -#if 0 - pm_battery_info(0, &batt); + apm_battery_info(sc, &batt); - power->ac_state = ((batt.flags & PMU_PWR_AC_PRESENT) ? + power->ac_state = ((batt.flags & PXAAPM_AC_PRESENT) ? APM_AC_ON : APM_AC_OFF); power->battery_life = ((batt.cur_charge * 100) / batt.max_charge); -#else - power->ac_state = APM_AC_ON; - power->battery_life = 100; -#endif /* * If the battery is charging, return the minutes left until * charging is complete. apmd knows this. */ -#if 0 - if (!(batt.flags & PMU_PWR_BATT_PRESENT)) { + if (!(batt.flags & PXAAPM_BATT_PRESENT)) { power->battery_state = APM_BATT_UNKNOWN; power->minutes_left = 0; power->battery_life = 0; @@ -374,11 +360,6 @@ apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) else power->battery_state = APM_BATT_LOW; } -#else - power->battery_state = APM_BATT_UNKNOWN; - power->minutes_left = 0; - power->battery_life = 0; -#endif break; default: diff --git a/sys/arch/arm/xscale/pxa2x0_apm.h b/sys/arch/arm/xscale/pxa2x0_apm.h index 61cd37c92e5..719f0e0ddfa 100644 --- a/sys/arch/arm/xscale/pxa2x0_apm.h +++ b/sys/arch/arm/xscale/pxa2x0_apm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pxa2x0_apm.h,v 1.1 2005/01/19 02:02:34 uwe Exp $ */ +/* $OpenBSD: pxa2x0_apm.h,v 1.2 2005/01/20 23:34:36 uwe Exp $ */ /* * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de> @@ -23,6 +23,16 @@ #include <machine/bus.h> +#define PXAAPM_AC_PRESENT (1<<0) +#define PXAAPM_BATT_PRESENT (1<<1) + +struct pxaapm_battery_info { + int flags; + u_int cur_charge; + u_int max_charge; + int draw; +}; + struct pxa2x0_apm_softc { struct device sc_dev; struct proc *sc_thread; @@ -31,6 +41,8 @@ struct pxa2x0_apm_softc { int sc_flags; bus_space_tag_t sc_iot; bus_space_handle_t sc_pm_ioh; + void (*sc_battery_info)(struct pxaapm_battery_info *); + void (*sc_periodic_check)(struct pxa2x0_apm_softc *); }; extern void pxa2x0_apm_attach_sub(struct pxa2x0_apm_softc *); diff --git a/sys/arch/zaurus/conf/GENERIC b/sys/arch/zaurus/conf/GENERIC index d1d9e035b92..827715f48a7 100644 --- a/sys/arch/zaurus/conf/GENERIC +++ b/sys/arch/zaurus/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.21 2005/01/19 02:02:34 uwe Exp $ +# $OpenBSD: GENERIC,v 1.22 2005/01/20 23:34:36 uwe Exp $ # # GENERIC machine description file # @@ -60,8 +60,8 @@ pxaip0 at mainbus? pxaintc0 at pxaip? # interrupt controller pxagpio0 at pxaip? # GPIO -#scoop0 at pxaip? addr 0x10800000 size 0x2c -#scoop1 at pxaip? addr 0x14800000 size 0x2c +scoop0 at pxaip? +scoop1 at pxaip? saost0 at pxaip? addr 0x40a00000 size 0x20 ohci0 at pxaip? addr 0x4c000000 size 0x70 intr 3 usb* at ohci? @@ -183,7 +183,7 @@ lcd0 at pxaip? wsdisplay* at lcd? console ? # APM emulation -#apm0 at pxaip? +apm0 at pxaip? # Pseudo-Devices pseudo-device wsmux 2 # mouse & keyboard multiplexor diff --git a/sys/arch/zaurus/conf/RAMDISK b/sys/arch/zaurus/conf/RAMDISK index dc500a93516..00335981668 100644 --- a/sys/arch/zaurus/conf/RAMDISK +++ b/sys/arch/zaurus/conf/RAMDISK @@ -1,4 +1,4 @@ -# $OpenBSD: RAMDISK,v 1.16 2005/01/19 02:02:34 uwe Exp $ +# $OpenBSD: RAMDISK,v 1.17 2005/01/20 23:34:36 uwe Exp $ # # GENERIC machine description file # @@ -66,8 +66,8 @@ pxaip0 at mainbus? pxaintc0 at pxaip? # interrupt controller pxagpio0 at pxaip? # GPIO -#scoop0 at pxaip? addr 0x10800000 size 0x2c -#scoop1 at pxaip? addr 0x14800000 size 0x2c +scoop0 at pxaip? +scoop1 at pxaip? saost0 at pxaip? addr 0x40a00000 size 0x20 ohci0 at pxaip? addr 0x4c000000 size 0x70 intr 3 usb* at ohci? @@ -163,7 +163,7 @@ lcd0 at pxaip? wsdisplay* at lcd? console ? # APM emulation -#apm0 at pxaip? +apm0 at pxaip? # Pseudo-Devices pseudo-device wsmux 2 # mouse & keyboard multiplexor diff --git a/sys/arch/zaurus/conf/files.zaurus b/sys/arch/zaurus/conf/files.zaurus index e14ff5b196f..defaaf6e15b 100644 --- a/sys/arch/zaurus/conf/files.zaurus +++ b/sys/arch/zaurus/conf/files.zaurus @@ -1,4 +1,4 @@ -# $OpenBSD: files.zaurus,v 1.12 2005/01/19 02:02:34 uwe Exp $ +# $OpenBSD: files.zaurus,v 1.13 2005/01/20 23:34:36 uwe Exp $ # # First try for arm-specific configuration info # @@ -38,6 +38,10 @@ device scoop attach scoop at pxaip with scoop_pxaip file arch/zaurus/dev/zaurus_scoop.c scoop +# Power manager and APM emulation +attach apm at pxaip with apm_pxaip +file arch/zaurus/zaurus/zaurus_apm.c apm_pxaip + # # Machine-independent ATA drivers # diff --git a/sys/arch/zaurus/dev/zaurus_scoop.c b/sys/arch/zaurus/dev/zaurus_scoop.c index 83364d7e4c3..9f851de62dc 100644 --- a/sys/arch/zaurus/dev/zaurus_scoop.c +++ b/sys/arch/zaurus/dev/zaurus_scoop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: zaurus_scoop.c,v 1.2 2005/01/19 15:56:44 uwe Exp $ */ +/* $OpenBSD: zaurus_scoop.c,v 1.3 2005/01/20 23:34:37 uwe Exp $ */ /* * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de> @@ -44,9 +44,6 @@ struct cfdriver scoop_cd = { NULL, "scoop", DV_DULL }; -/* GPIO pin/bit numbers for the Zaurus C3000. */ -#define SCOOP1_BACKLIGHT_ON 8 - int scoop_gpio_pin_read(struct scoop_softc *sc, int); void scoop_gpio_pin_write(struct scoop_softc *sc, int, int); @@ -54,12 +51,8 @@ void scoop_gpio_pin_write(struct scoop_softc *sc, int, int); int scoopmatch(struct device *parent, void *match, void *aux) { - struct pxaip_attach_args *pxa = aux; struct cfdata *cf = match; - if (pxa->pxa_addr == -1) - return 0; - /* * Only the C3000 models (pxa270) are known to have two SCOOPs, * on other models we only find the first one. @@ -75,13 +68,21 @@ scoopattach(struct device *parent, struct device *self, void *aux) { struct pxaip_attach_args *pxa = aux; struct scoop_softc *sc = (struct scoop_softc *)self; + bus_addr_t addr; bus_size_t size; sc->sc_iot = pxa->pxa_iot; + + if (pxa->pxa_addr != -1) + addr = pxa->pxa_addr; + else if (sc->sc_dev.dv_unit == 0) + addr = SCOOP0_BASE; + else + addr = SCOOP1_BASE; + size = pxa->pxa_size < SCOOP_SIZE ? SCOOP_SIZE : pxa->pxa_size; - if (bus_space_map(sc->sc_iot, pxa->pxa_addr, size, 0, - &sc->sc_ioh) != 0) { + if (bus_space_map(sc->sc_iot, addr, size, 0, &sc->sc_ioh) != 0) { printf(": failed to map %s\n", sc->sc_dev.dv_xname); return; } @@ -111,12 +112,30 @@ scoop_gpio_pin_write(struct scoop_softc *sc, int pin, int value) } void -scoop_backlight_on(int enable) +scoop_backlight_set(int on) { #if 0 /* XXX no effect. maybe the pin is incorrectly configured? */ if (scoop_cd.cd_ndevs > 1 && scoop_cd.cd_devs[1] != NULL) scoop_gpio_pin_write(scoop_cd.cd_devs[1], - SCOOP1_BACKLIGHT_ON, enable); + SCOOP1_BACKLIGHT_ON, on); #endif } + +void +scoop_led_set(int led, int on) +{ + + if (scoop_cd.cd_ndevs > 0 && scoop_cd.cd_devs[0] != NULL) { + switch(led) { + case SCOOP_LED_GREEN: + scoop_gpio_pin_write(scoop_cd.cd_devs[0], + C3000_SCOOP0_LED_GREEN, on); + break; + case SCOOP_LED_ORANGE: + scoop_gpio_pin_write(scoop_cd.cd_devs[0], + C3000_SCOOP0_LED_ORANGE, on); + break; + } + } +} diff --git a/sys/arch/zaurus/dev/zaurus_scoopreg.h b/sys/arch/zaurus/dev/zaurus_scoopreg.h index e0f68355572..67abaf93e67 100644 --- a/sys/arch/zaurus/dev/zaurus_scoopreg.h +++ b/sys/arch/zaurus/dev/zaurus_scoopreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: zaurus_scoopreg.h,v 1.2 2005/01/19 15:56:44 uwe Exp $ */ +/* $OpenBSD: zaurus_scoopreg.h,v 1.3 2005/01/20 23:34:36 uwe Exp $ */ /* * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de> @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define SCOOP0_BASE 0x10800000 +#define SCOOP1_BASE 0x14800000 #define SCOOP_SIZE 0x2c #define SCOOP_MCR 0x00 @@ -30,3 +32,8 @@ #define SCOOP_GPCR 0x20 #define SCOOP_GPWR 0x24 #define SCOOP_GPRR 0x28 + +/* GPIO bit assignments for the Zaurus C3000. */ +#define C3000_SCOOP0_LED_GREEN 1 +#define C3000_SCOOP0_LED_ORANGE 7 +#define C3000_SCOOP1_BACKLIGHT_ON 8 diff --git a/sys/arch/zaurus/dev/zaurus_scoopvar.h b/sys/arch/zaurus/dev/zaurus_scoopvar.h index 35354561dc8..497680e49f4 100644 --- a/sys/arch/zaurus/dev/zaurus_scoopvar.h +++ b/sys/arch/zaurus/dev/zaurus_scoopvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: zaurus_scoopvar.h,v 1.2 2005/01/19 15:56:44 uwe Exp $ */ +/* $OpenBSD: zaurus_scoopvar.h,v 1.3 2005/01/20 23:34:37 uwe Exp $ */ /* * Copyright (c) 2005 Uwe Stuehler <uwe@bsdx.de> @@ -16,4 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -void scoop_backlight_on(int); +#define SCOOP_LED_GREEN 0 +#define SCOOP_LED_ORANGE 1 + +void scoop_backlight_set(int); +void scoop_led_set(int, int); diff --git a/sys/arch/zaurus/zaurus/zaurus_apm.c b/sys/arch/zaurus/zaurus/zaurus_apm.c new file mode 100644 index 00000000000..d4136a3b4a6 --- /dev/null +++ b/sys/arch/zaurus/zaurus/zaurus_apm.c @@ -0,0 +1,90 @@ +/* $OpenBSD: zaurus_apm.c,v 1.1 2005/01/20 23:34:37 uwe Exp $ */ + +/* + * Copyright (c) 2005 Uwe Stuehler <uwe@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/conf.h> + +#include <arm/xscale/pxa2x0_apm.h> +#include <arm/xscale/pxa2x0_gpio.h> + +#include <zaurus/dev/zaurus_scoopvar.h> + +int apm_match(struct device *, void *, void *); +void apm_attach(struct device *, struct device *, void *); + +struct cfattach apm_pxaip_ca = { + sizeof (struct pxa2x0_apm_softc), apm_match, apm_attach +}; + +#define C3000_GPIO_AC_IN 115 /* active low */ + +int zaurus_ac_present(void); +void zaurus_battery_charge(int); +void zaurus_battery_info(struct pxaapm_battery_info *); +void zaurus_power_check(struct pxa2x0_apm_softc *); + +int +apm_match(struct device *parent, void *match, void *aux) +{ + return 1; +} + +void +apm_attach(struct device *parent, struct device *self, void *aux) +{ + struct pxa2x0_apm_softc *sc = (struct pxa2x0_apm_softc *)self; + + sc->sc_battery_info = zaurus_battery_info; + sc->sc_periodic_check = zaurus_power_check; + + pxa2x0_apm_attach_sub(sc); +} + +int +zaurus_ac_present(void) +{ + + return !pxa2x0_gpio_get_bit(C3000_GPIO_AC_IN); +} + +void +zaurus_battery_charge(int on) +{ + + scoop_led_set(SCOOP_LED_ORANGE, on); +} + +void +zaurus_battery_info(struct pxaapm_battery_info *battp) +{ + + if (zaurus_ac_present()) + battp->flags |= PXAAPM_AC_PRESENT; + else + battp->flags &= ~PXAAPM_AC_PRESENT; +} + +void +zaurus_power_check(struct pxa2x0_apm_softc *sc) +{ + + if (zaurus_ac_present()) + zaurus_battery_charge(1); + else + zaurus_battery_charge(0); +} |