Module Name:    src
Committed By:   uwe
Date:           Mon Mar 30 06:22:25 UTC 2009

Modified Files:
        src/sys/dev/hpc/apm: apmdev.c apmvar.h

Log Message:
Split device_t and softc, use aprint_*, rename/reformat stuff to
minimize diffs to dev/apm/apm.c (even at the cost of uglification).

Tested on Jornada 690 (hpcsh).


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/hpc/apm/apmdev.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/hpc/apm/apmvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/hpc/apm/apmdev.c
diff -u src/sys/dev/hpc/apm/apmdev.c:1.19 src/sys/dev/hpc/apm/apmdev.c:1.20
--- src/sys/dev/hpc/apm/apmdev.c:1.19	Thu Jun 12 01:46:32 2008
+++ src/sys/dev/hpc/apm/apmdev.c	Mon Mar 30 06:22:25 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: apmdev.c,v 1.19 2008/06/12 01:46:32 rafal Exp $ */
+/*	$NetBSD: apmdev.c,v 1.20 2009/03/30 06:22:25 uwe Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: apmdev.c,v 1.19 2008/06/12 01:46:32 rafal Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apmdev.c,v 1.20 2009/03/30 06:22:25 uwe Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_apmdev.h"
@@ -53,7 +53,6 @@
 #include <sys/kernel.h>
 #include <sys/proc.h>
 #include <sys/kthread.h>
-#include <sys/mutex.h>
 #include <sys/user.h>
 #include <sys/malloc.h>
 #include <sys/device.h>
@@ -67,41 +66,37 @@
 
 #include <machine/stdarg.h>
 
-#if defined(APMDEBUG)
-#define	DPRINTF(f, x)		do { if (apmdebug & (f)) printf x; } while (0)
+#ifdef APMDEBUG
+#define DPRINTF(f, x)		do { if (apmdebug & (f)) printf x; } while (0)
 
-#define	APMDEBUG_INFO		0x01
-#define	APMDEBUG_APMCALLS	0x02
-#define	APMDEBUG_EVENTS		0x04
-#define	APMDEBUG_PROBE		0x10
-#define	APMDEBUG_ATTACH		0x40
-#define	APMDEBUG_DEVICE		0x20
-#define	APMDEBUG_ANOM		0x40
 
 #ifdef APMDEBUG_VALUE
 int	apmdebug = APMDEBUG_VALUE;
 #else
 int	apmdebug = 0;
-#endif
+#endif /* APMDEBUG_VALUE */
+
 #else
 #define	DPRINTF(f, x)		/**/
-#endif
+#endif /* APMDEBUG */
 
 #define APM_NEVENTS 16
 
 struct apm_softc {
-	struct device sc_dev;
+	device_t sc_dev;
 	struct selinfo sc_rsel;
 	struct selinfo sc_xsel;
 	int	sc_flags;
-	int	event_count;
-	int	event_ptr;
+	int	sc_event_count;
+	int	sc_event_ptr;
 	int	sc_power_state;
 	lwp_t	*sc_thread;
-	kmutex_t sc_mutex;
-	struct apm_event_info event_list[APM_NEVENTS];
-	struct apm_accessops *ops;
-	void *cookie;
+	kmutex_t sc_lock;
+	struct apm_event_info sc_event_list[APM_NEVENTS];
+	struct apm_accessops *sc_ops;
+	int	sc_vers;
+	int	sc_detail;
+	void *sc_cookie;
 };
 #define	SCFLAG_OREAD	0x0000001
 #define	SCFLAG_OWRITE	0x0000002
@@ -118,11 +113,13 @@
  * APM module.  This is both the APM thread itself, as well as
  * user context.
  */
-#define	APM_LOCK(apmsc)		mutex_enter(&(apmsc)->sc_mutex)
-#define	APM_UNLOCK(apmsc)	mutex_exit(&(apmsc)->sc_mutex)
+#define	APM_LOCK(apmsc)						\
+	(void) mutex_enter(&(apmsc)->sc_lock)
+#define	APM_UNLOCK(apmsc)						\
+	(void) mutex_exit(&(apmsc)->sc_lock)
 
-static void	apmattach(struct device *, struct device *, void *);
-static int	apmmatch(struct device *, struct cfdata *, void *);
+static void	apmattach(device_t, device_t, void *);
+static int	apmmatch(device_t, cfdata_t, void *);
 
 static void	apm_event_handle(struct apm_softc *, u_int, u_int);
 static void	apm_periodic_check(struct apm_softc *);
@@ -133,13 +130,13 @@
 static void	apm_power_print(struct apm_softc *, struct apm_power_info *);
 #endif
 static int	apm_record_event(struct apm_softc *, u_int);
-static void	apm_set_ver(struct apm_softc *, u_long);
+static void	apm_set_ver(struct apm_softc *);
 static void	apm_standby(struct apm_softc *);
 static const char *apm_strerror(int);
 static void	apm_suspend(struct apm_softc *);
 static void	apm_resume(struct apm_softc *, u_int, u_int);
 
-CFATTACH_DECL(apmdev, sizeof(struct apm_softc),
+CFATTACH_DECL_NEW(apmdev, sizeof(struct apm_softc),
     apmmatch, apmattach, NULL, NULL);
 
 extern struct cfdriver apmdev_cd;
@@ -247,10 +244,11 @@
 {
 
 	if (pi->battery_life != APM_BATT_LIFE_UNKNOWN) {
-		printf("%s: battery life expectancy: %d%%\n",
-		    device_xname(&sc->sc_dev), pi->battery_life);
+		aprint_normal_dev(sc->sc_dev,
+		    "battery life expectancy: %d%%\n",
+		    pi->battery_life);
 	}
-	printf("%s: A/C state: ", device_xname(&sc->sc_dev));
+	aprint_normal_dev(sc->sc_dev, "A/C state: ");
 	switch (pi->ac_state) {
 	case APM_AC_OFF:
 		printf("off\n");
@@ -266,8 +264,8 @@
 		printf("unknown\n");
 		break;
 	}
-	if (apm_major == 1 && apm_minor == 0) {
-		printf("%s: battery charge state:", device_xname(&sc->sc_dev));
+	aprint_normal_dev(sc->sc_dev, "battery charge state:");
+	if (apm_minver == 0)
 		switch (pi->battery_state) {
 		case APM_BATT_HIGH:
 			printf("high\n");
@@ -288,22 +286,26 @@
 			printf("undecoded state %x\n", pi->battery_state);
 			break;
 		}
-	} else {
-		if (pi->battery_state&APM_BATT_FLAG_CHARGING)
-			printf("charging ");
+	else if (apm_minver >= 1) {
+		if (pi->battery_flags & APM_BATT_FLAG_NO_SYSTEM_BATTERY)
+			printf(" no battery");
+		else {
+			if (pi->battery_flags & APM_BATT_FLAG_HIGH)
+				printf(" high");
+			if (pi->battery_flags & APM_BATT_FLAG_LOW)
+				printf(" low");
+			if (pi->battery_flags & APM_BATT_FLAG_CRITICAL)
+				printf(" critical");
+			if (pi->battery_flags & APM_BATT_FLAG_CHARGING)
+				printf(" charging");
+		}
+		printf("\n");
+		if (pi->minutes_valid) {
+			aprint_normal_dev(sc->sc_dev, "estimated ");
+			if (pi->minutes_left / 60)
+				printf("%dh ", pi->minutes_left / 60);
+			printf("%dm\n", pi->minutes_left % 60);
 		}
-		if (pi->battery_state&APM_BATT_FLAG_UNKNOWN)
-			printf("unknown\n");
-		else if (pi->battery_state&APM_BATT_FLAG_CRITICAL)
-			printf("critical\n");
-		else if (pi->battery_state&APM_BATT_FLAG_LOW)
-			printf("low\n");
-		else if (pi->battery_state&APM_BATT_FLAG_HIGH)
-			printf("high\n");
-	}
-	if (pi->minutes_left != 0) {
-		printf("%s: estimated ", device_xname(&sc->sc_dev));
-		printf("%dh ", pi->minutes_left / 60);
 	}
 	return;
 }
@@ -312,11 +314,12 @@
 static void
 apm_suspend(struct apm_softc *sc)
 {
+	int error;
 
 	if (sc->sc_power_state == PWR_SUSPEND) {
 #ifdef APMDEBUG
-		printf("%s: apm_suspend: already suspended?\n",
-		    device_xname(&sc->sc_dev));
+		aprint_debug_dev(sc->sc_dev,
+		    "apm_suspend: already suspended?\n");
 #endif
 		return;
 	}
@@ -329,18 +332,19 @@
 
 	dopowerhooks(PWR_SUSPEND);
 
-	/* XXX cgd */
-	(void)sc->ops->set_powstate(sc->cookie, APM_DEV_ALLDEVS, APM_SYS_SUSPEND);
+	error = (*sc->sc_ops->aa_set_powstate)(sc->sc_cookie, APM_DEV_ALLDEVS,
+	    APM_SYS_SUSPEND);
 }
 
 static void
 apm_standby(struct apm_softc *sc)
 {
+	int error;
 
 	if (sc->sc_power_state == PWR_STANDBY) {
 #ifdef APMDEBUG
-		printf("%s: apm_standby: already standing by?\n",
-		    device_xname(&sc->sc_dev));
+		aprint_debug_dev(sc->sc_dev,
+		    "apm_standby: already standing by?\n");
 #endif
 		return;
 	}
@@ -352,8 +356,9 @@
 	apm_spl = splhigh();
 
 	dopowerhooks(PWR_STANDBY);
-	/* XXX cgd */
-	(void)sc->ops->set_powstate(sc->cookie, APM_DEV_ALLDEVS, APM_SYS_STANDBY);
+
+	error = (*sc->sc_ops->aa_set_powstate)(sc->sc_cookie, APM_DEV_ALLDEVS,
+	    APM_SYS_STANDBY);
 }
 
 static void
@@ -362,19 +367,18 @@
 
 	if (sc->sc_power_state == PWR_RESUME) {
 #ifdef APMDEBUG
-		printf("%s: apm_resume: already running?\n",
-		    device_xname(&sc->sc_dev));
+		aprint_debug_dev(sc->sc_dev, "apm_resume: already running?\n");
 #endif
 		return;
 	}
 	sc->sc_power_state = PWR_RESUME;
 
+#if 0 /* XXX: def TIME_FREQ */
 	/*
 	 * Some system requires its clock to be initialized after hybernation.
 	 */
-/* XXX
-	initrtclock();
-*/
+	initrtclock(TIMER_FREQ);
+#endif
 
 	inittodr(time_second);
 	dopowerhooks(PWR_RESUME);
@@ -397,12 +401,12 @@
 
 	if ((sc->sc_flags & SCFLAG_OPEN) == 0)
 		return 1;		/* no user waiting */
-	if (sc->event_count == APM_NEVENTS)
+	if (sc->sc_event_count == APM_NEVENTS)
 		return 1;			/* overflow */
-	evp = &sc->event_list[sc->event_ptr];
-	sc->event_count++;
-	sc->event_ptr++;
-	sc->event_ptr %= APM_NEVENTS;
+	evp = &sc->sc_event_list[sc->sc_event_ptr];
+	sc->sc_event_count++;
+	sc->sc_event_ptr++;
+	sc->sc_event_ptr %= APM_NEVENTS;
 	evp->type = event_type;
 	evp->index = ++apm_evindex;
 	selnotify(&sc->sc_rsel, 0, 0);
@@ -423,15 +427,13 @@
 			if (apm_record_event(sc, event_code))
 				apm_userstandbys++;
 			apm_op_inprog++;
-			(void)sc->ops->set_powstate(sc->cookie,
-						    APM_DEV_ALLDEVS,
-						    APM_LASTREQ_INPROG);
+			(void)(*sc->sc_ops->aa_set_powstate)(sc->sc_cookie,
+			    APM_DEV_ALLDEVS, APM_LASTREQ_INPROG);
 		} else {
-			(void)sc->ops->set_powstate(sc->cookie,
-						    APM_DEV_ALLDEVS,
-						    APM_LASTREQ_REJECTED);
+			(void)(*sc->sc_ops->aa_set_powstate)(sc->sc_cookie,
+			    APM_DEV_ALLDEVS, APM_LASTREQ_REJECTED);
 			/* in case BIOS hates being spurned */
-			sc->ops->enable(sc->cookie, 1);
+			(*sc->sc_ops->aa_enable)(sc->sc_cookie, 1);
 		}
 		break;
 
@@ -447,15 +449,13 @@
 			if (apm_record_event(sc, event_code))
 				apm_standbys++;
 			apm_op_inprog++;
-			(void)sc->ops->set_powstate(sc->cookie,
-						    APM_DEV_ALLDEVS,
-						    APM_LASTREQ_INPROG);
+			(void)(*sc->sc_ops->aa_set_powstate)(sc->sc_cookie,
+			    APM_DEV_ALLDEVS, APM_LASTREQ_INPROG);
 		} else {
-			(void)sc->ops->set_powstate(sc->cookie,
-						    APM_DEV_ALLDEVS,
-						    APM_LASTREQ_REJECTED);
+			(void)(*sc->sc_ops->aa_set_powstate)(sc->sc_cookie,
+			    APM_DEV_ALLDEVS, APM_LASTREQ_REJECTED);
 			/* in case BIOS hates being spurned */
-			sc->ops->enable(sc->cookie, 1);
+			(*sc->sc_ops->aa_enable)(sc->sc_cookie, 1);
 		}
 		break;
 
@@ -464,9 +464,8 @@
 		if (apm_record_event(sc, event_code))
 			apm_suspends++;
 		apm_op_inprog++;
-		(void)sc->ops->set_powstate(sc->cookie,
-					    APM_DEV_ALLDEVS,
-					    APM_LASTREQ_INPROG);
+		(void)(*sc->sc_ops->aa_set_powstate)(sc->sc_cookie,
+		    APM_DEV_ALLDEVS, APM_LASTREQ_INPROG);
 		break;
 
 	case APM_SUSPEND_REQ:
@@ -480,14 +479,13 @@
 		if (apm_record_event(sc, event_code))
 			apm_suspends++;
 		apm_op_inprog++;
-		(void)sc->ops->set_powstate(sc->cookie,
-					    APM_DEV_ALLDEVS,
-					    APM_LASTREQ_INPROG);
+		(void)(*sc->sc_ops->aa_set_powstate)(sc->sc_cookie,
+		    APM_DEV_ALLDEVS, APM_LASTREQ_INPROG);
 		break;
 
 	case APM_POWER_CHANGE:
 		DPRINTF(APMDEBUG_EVENTS, ("apmev: power status change\n"));
-		error = sc->ops->get_powstat(sc->cookie, &pi);
+		error = (*sc->sc_ops->aa_get_powstat)(sc->sc_cookie, &pi);
 #ifdef APM_POWER_PRINT
 		/* only print if nobody is catching events. */
 		if (error == 0 &&
@@ -535,9 +533,9 @@
 			DPRINTF(APMDEBUG_EVENTS, ("apm: unexpected event\n"));
 		} else {
 			u_int numbatts, capflags;
-			sc->ops->get_capabilities(sc->cookie,
-						  &numbatts, &capflags);
-			sc->ops->get_powstat(sc->cookie, &pi); /* XXX */
+			(*sc->sc_ops->aa_get_capabilities)(sc->sc_cookie,
+			    &numbatts, &capflags);
+			(*sc->sc_ops->aa_get_powstat)(sc->sc_cookie, &pi);
 		}
 		break;
 
@@ -572,12 +570,11 @@
 	 * suspend/standby
 	 */
 	if (apm_op_inprog)
-		sc->ops->set_powstate(sc->cookie, APM_DEV_ALLDEVS,
-				      APM_LASTREQ_INPROG);
+		(*sc->sc_ops->aa_set_powstate)(sc->sc_cookie, APM_DEV_ALLDEVS,
+		    APM_LASTREQ_INPROG);
 
-	while ((error = sc->ops->get_event(sc->cookie, &event_code,
-					   &event_info)) == 0
-	       && !apm_damn_fool_bios)
+	while ((error = (*sc->sc_ops->aa_get_event)(sc->sc_cookie, &event_code,
+	    &event_info)) == 0 && !apm_damn_fool_bios)
 		apm_event_handle(sc, event_code, event_info);
 
 	if (error != APM_ERR_NOEVENTS)
@@ -594,20 +591,20 @@
 }
 
 static void
-apm_set_ver(struct apm_softc *self, u_long detail)
+apm_set_ver(struct apm_softc *sc)
 {
 
 	if (apm_v12_enabled &&
-	    APM_MAJOR_VERS(detail) == 1 &&
-	    APM_MINOR_VERS(detail) == 2) {
+	    APM_MAJOR_VERS(sc->sc_vers) == 1 &&
+	    APM_MINOR_VERS(sc->sc_vers) == 2) {
 		apm_majver = 1;
 		apm_minver = 2;
 		goto ok;
 	}
 
 	if (apm_v11_enabled &&
-	    APM_MAJOR_VERS(detail) == 1 &&
-	    APM_MINOR_VERS(detail) == 1) {
+	    APM_MAJOR_VERS(sc->sc_vers) == 1 &&
+	    APM_MINOR_VERS(sc->sc_vers) == 1) {
 		apm_majver = 1;
 		apm_minver = 1;
 	} else {
@@ -615,52 +612,53 @@
 		apm_minver = 0;
 	}
 ok:
-	printf("Power Management spec V%d.%d", apm_majver, apm_minver);
+	aprint_normal("Power Management spec V%d.%d", apm_majver, apm_minver);
 	apm_inited = 1;
-	if (detail & APM_IDLE_SLOWS) {
+	if (sc->sc_detail & APM_IDLE_SLOWS) {
 #ifdef DIAGNOSTIC
 		/* not relevant often */
-		printf(" (slowidle)");
+		aprint_normal(" (slowidle)");
 #endif
 		/* leave apm_do_idle at its user-configured setting */
 	} else
 		apm_do_idle = 0;
 #ifdef DIAGNOSTIC
-	if (detail & APM_BIOS_PM_DISABLED)
-		printf(" (BIOS mgmt disabled)");
-	if (detail & APM_BIOS_PM_DISENGAGED)
-		printf(" (BIOS managing devices)");
+	if (sc->sc_detail & APM_BIOS_PM_DISABLED)
+		aprint_normal(" (BIOS mgmt disabled)");
+	if (sc->sc_detail & APM_BIOS_PM_DISENGAGED)
+		aprint_normal(" (BIOS managing devices)");
 #endif
 }
 
 static int
-apmmatch(struct device *parent,
-	 struct cfdata *match, void *aux)
+apmmatch(device_t parent, cfdata_t match, void *aux)
 {
-
-	/* There can be only one! */
-	if (apm_inited)
-		return 0;
-
-	return (1);
+	static int got;
+	return !got++;
 }
 
 static void
-apmattach(struct device *parent, struct device *self, void *aux)
+apmattach(device_t parent, device_t self, void *aux)
 {
-	struct apm_softc *sc = (void *)self;
+	struct apm_softc *sc;
 	struct apmdev_attach_args *aaa = aux;
 	struct apm_power_info pinfo;
 	u_int numbatts, capflags;
 	int error;
 
-	printf(": ");
+	sc = device_private(self);
+	sc->sc_dev = self;
+
+	sc->sc_detail = aaa->apm_detail;
+	sc->sc_vers = aaa->apm_detail & 0xffff; /* XXX: magic */
+
+	sc->sc_ops = aaa->accessops;
+	sc->sc_cookie = aaa->accesscookie;
 
-	sc->ops = aaa->accessops;
-	sc->cookie = aaa->accesscookie;
+	aprint_naive("\n");
+	aprint_normal(": ");
 
-	switch ((APM_MAJOR_VERS(aaa->apm_detail) << 8) +
-		APM_MINOR_VERS(aaa->apm_detail)) {
+	switch ((APM_MAJOR_VERS(sc->sc_vers) << 8) + APM_MINOR_VERS(sc->sc_vers)) {
 	case 0x0100:
 		apm_v11_enabled = 0;
 		apm_v12_enabled = 0;
@@ -673,31 +671,34 @@
 		break;
 	}
 
-	apm_set_ver(sc, aaa->apm_detail);	/* prints version info */
-	printf("\n");
+	apm_set_ver(sc);	/* prints version info */
+	aprint_normal("\n");
 	if (apm_minver >= 2)
-		sc->ops->get_capabilities(sc->cookie, &numbatts, &capflags);
+		(*sc->sc_ops->aa_get_capabilities)(sc->sc_cookie, &numbatts,
+		    &capflags);
 
 	/*
 	 * enable power management
 	 */
-	sc->ops->enable(sc->cookie, 1);
+	(*sc->sc_ops->aa_enable)(sc->sc_cookie, 1);
 
-	error = sc->ops->get_powstat(sc->cookie, &pinfo);
+	error = (*sc->sc_ops->aa_get_powstat)(sc->sc_cookie, &pinfo);
 	if (error == 0) {
 #ifdef APM_POWER_PRINT
-		apm_power_print(apmsc, &pinfo);
+		apm_power_print(sc, &pinfo);
 #endif
 	} else
 		apm_perror("get power status", error);
-	sc->ops->cpu_busy(sc->cookie);
 
-	mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_NONE);
-	selinit(&sc->sc_rsel);
-	selinit(&sc->sc_xsel);
+	if (sc->sc_ops->aa_cpu_busy)
+		(*sc->sc_ops->aa_cpu_busy)(sc->sc_cookie);
+
+	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
 
 	/* Initial state is `resumed'. */
 	sc->sc_power_state = PWR_RESUME;
+	selinit(&sc->sc_rsel);
+	selinit(&sc->sc_xsel);
 
 	/* Do an initial check. */
 	apm_periodic_check(sc);
@@ -707,12 +708,13 @@
 	 * and notify other subsystems when they occur.
 	 */
 	if (kthread_create(PRI_NONE, 0, NULL, apm_thread, sc,
-	    &sc->sc_thread, "%s", device_xname(&sc->sc_dev)) != 0) {
+	    &sc->sc_thread, "%s", device_xname(sc->sc_dev)) != 0) {
 		/*
 		 * We were unable to create the APM thread; bail out.
 		 */
-		sc->ops->disconnect(sc->cookie);
-		aprint_error_dev(&sc->sc_dev, "unable to create thread, "
+		if (sc->sc_ops->aa_disconnect)
+			(*sc->sc_ops->aa_disconnect)(sc->sc_cookie);
+		aprint_error_dev(sc->sc_dev, "unable to create thread, "
 		    "kernel APM support disabled\n");
 	}
 }
@@ -728,6 +730,7 @@
 
 	return (UNCONF);
 }
+
 void
 apm_thread(void *arg)
 {
@@ -810,8 +813,8 @@
 		break;
 	}
 	if ((sc->sc_flags & SCFLAG_OPEN) == 0) {
-		sc->event_count = 0;
-		sc->event_ptr = 0;
+		sc->sc_event_count = 0;
+		sc->sc_event_ptr = 0;
 	}
 	APM_UNLOCK(sc);
 	return 0;
@@ -854,21 +857,22 @@
 		break;
 
 	case APM_IOC_NEXTEVENT:
-		if (!sc->event_count)
+		if (!sc->sc_event_count)
 			error = EAGAIN;
 		else {
 			evp = (struct apm_event_info *)data;
-			i = sc->event_ptr + APM_NEVENTS - sc->event_count;
+			i = sc->sc_event_ptr + APM_NEVENTS - sc->sc_event_count;
 			i %= APM_NEVENTS;
-			*evp = sc->event_list[i];
-			sc->event_count--;
+			*evp = sc->sc_event_list[i];
+			sc->sc_event_count--;
 		}
 		break;
 
 	case OAPM_IOC_GETPOWER:
 	case APM_IOC_GETPOWER:
 		powerp = (struct apm_power_info *)data;
-		if ((error = sc->ops->get_powstat(sc->cookie, powerp)) != 0) {
+		if ((error = (*sc->sc_ops->aa_get_powstat)(sc->sc_cookie,
+		    powerp)) != 0) {
 			apm_perror("ioctl get power status", error);
 			error = EIO;
 			break;
@@ -878,7 +882,7 @@
 			break;
 		case 1:
 		default:
-			batt_flags = powerp->battery_state;
+			batt_flags = powerp->battery_flags;
 			powerp->battery_state = APM_BATT_UNKNOWN;
 			if (batt_flags & APM_BATT_FLAG_HIGH)
 				powerp->battery_state = APM_BATT_HIGH;
@@ -910,7 +914,7 @@
 
 	APM_LOCK(sc);
 	if (events & (POLLIN | POLLRDNORM)) {
-		if (sc->event_count)
+		if (sc->sc_event_count)
 			revents |= events & (POLLIN | POLLRDNORM);
 		else
 			selrecord(l, &sc->sc_rsel);
@@ -935,7 +939,7 @@
 {
 	struct apm_softc *sc = kn->kn_hook;
 
-	kn->kn_data = sc->event_count;
+	kn->kn_data = sc->sc_event_count;
 	return (kn->kn_data > 0);
 }
 

Index: src/sys/dev/hpc/apm/apmvar.h
diff -u src/sys/dev/hpc/apm/apmvar.h:1.3 src/sys/dev/hpc/apm/apmvar.h:1.4
--- src/sys/dev/hpc/apm/apmvar.h:1.3	Mon Apr 28 20:23:48 2008
+++ src/sys/dev/hpc/apm/apmvar.h	Mon Mar 30 06:22:25 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: apmvar.h,v 1.3 2008/04/28 20:23:48 martin Exp $	*/
+/*	$NetBSD: apmvar.h,v 1.4 2009/03/30 06:22:25 uwe Exp $	*/
 /*-
  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -34,14 +34,14 @@
 #include <dev/apm/apmio.h>
 
 struct apm_accessops {
-	void	(*disconnect)(void *);
-	void	(*enable)(void *, int);
-	int	(*set_powstate)(void *, u_int, u_int);
-	int	(*get_powstat)(void *, struct apm_power_info *);
-	int	(*get_event)(void *, u_int *, u_int *);
-	void	(*cpu_busy)(void *);
-	void	(*cpu_idle)(void *);
-	void	(*get_capabilities)(void *, u_int *, u_int *);
+	void	(*aa_disconnect)(void *);
+	void	(*aa_enable)(void *, int);
+	int	(*aa_set_powstate)(void *, u_int, u_int);
+	int	(*aa_get_powstat)(void *, struct apm_power_info *);
+	int	(*aa_get_event)(void *, u_int *, u_int *);
+	void	(*aa_cpu_busy)(void *);
+	void	(*aa_cpu_idle)(void *);
+	void	(*aa_get_capabilities)(void *, u_int *, u_int *);
 };
 
 struct apmdev_attach_args {

Reply via email to