Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Initial APM support (enough to get battery level)
details: https://anonhg.NetBSD.org/src/rev/d4c019487215
branches: trunk
changeset: 536482:d4c019487215
user: manu <manu%NetBSD.org@localhost>
date: Mon Sep 16 19:52:52 2002 +0000
description:
Initial APM support (enough to get battery level)
diffstat:
sys/arch/arm/conf/majors.arm32 | 3 +-
sys/arch/hpcarm/conf/files.hpcarm | 9 +-
sys/arch/hpcarm/dev/apm.c | 158 ++++++++++++++++++++++++++++++++++++++
sys/arch/hpcarm/include/Makefile | 4 +-
sys/arch/hpcarm/include/apmvar.h | 76 ++++++++++++++++++
5 files changed, 245 insertions(+), 5 deletions(-)
diffs (300 lines):
diff -r a93774917a3b -r d4c019487215 sys/arch/arm/conf/majors.arm32
--- a/sys/arch/arm/conf/majors.arm32 Mon Sep 16 19:50:27 2002 +0000
+++ b/sys/arch/arm/conf/majors.arm32 Mon Sep 16 19:52:52 2002 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: majors.arm32,v 1.2 2002/09/06 13:18:43 gehenna Exp $
+# $NetBSD: majors.arm32,v 1.3 2002/09/16 19:52:53 manu Exp $
#
# Device majors for arm32
#
@@ -98,3 +98,4 @@
device-major ixpcom char 100 ixpcom
device-major sysmon char 101 sysmon
device-major dmoverio char 102 dmoverio
+device-major apm char 103 apm
diff -r a93774917a3b -r d4c019487215 sys/arch/hpcarm/conf/files.hpcarm
--- a/sys/arch/hpcarm/conf/files.hpcarm Mon Sep 16 19:50:27 2002 +0000
+++ b/sys/arch/hpcarm/conf/files.hpcarm Mon Sep 16 19:52:52 2002 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.hpcarm,v 1.46 2002/09/06 13:18:43 gehenna Exp $
+# $NetBSD: files.hpcarm,v 1.47 2002/09/16 19:52:52 manu Exp $
#
# First try for arm-specific configuration info
#
@@ -65,13 +65,18 @@
attach sed at saip
file arch/hpcarm/dev/sed_saip.c sed
-device j720ssp: wskbddev, wsmousedev, tpcalib
+device j720ssp {}: wskbddev, wsmousedev, tpcalib
attach j720ssp at saip
file arch/hpcarm/dev/j720ssp.c j720ssp
file arch/hpcarm/dev/j720kbdmap.c j720ssp
file dev/cninit.c
+# APM
+device apm
+attach apm at j720ssp
+file arch/hpcarm/dev/apm.c apm needs-count
+
# Atmel microcontroller
device atmelgpioif {}
device atmelgpio: atmelgpioif
diff -r a93774917a3b -r d4c019487215 sys/arch/hpcarm/dev/apm.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hpcarm/dev/apm.c Mon Sep 16 19:52:52 2002 +0000
@@ -0,0 +1,158 @@
+/* $NetBSD: apm.c,v 1.1 2002/09/16 19:52:54 manu Exp $ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "apm.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.1 2002/09/16 19:52:54 manu Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/device.h>
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/select.h>
+#include <sys/poll.h>
+#include <sys/conf.h>
+
+#include <machine/apmvar.h>
+
+extern struct cfdriver apm_cd;
+extern int hpcarm_apm_getpower(struct apm_power_info *, void *);
+
+int apmmatch(struct device *, struct cfdata *, void *);
+void apmattach(struct device *, struct device *, void *);
+dev_type_open(apmopen);
+dev_type_close(apmclose);
+dev_type_ioctl(apmioctl);
+dev_type_poll(apmpoll);
+
+
+struct apm_softc {
+ struct device sc_dev;
+ void *sc_parent;
+};
+
+struct cfattach apm_ca = {
+ sizeof(struct apm_softc), apmmatch, apmattach, NULL, NULL
+};
+
+const struct cdevsw apm_cdevsw = {
+ apmopen, apmclose, noread, nowrite, apmioctl,
+ nostop, notty, apmpoll, nommap,
+};
+
+
+int
+apmmatch(parent, match, aux)
+ struct device *parent;
+ struct cfdata *match;
+ void *aux;
+{
+ struct apm_attach_args *apm_args = (struct apm_attach_args *)aux;
+ return (apm_args->aaa_magic == APM_ATTACH_ARGS_MAGIC);
+}
+
+void
+apmattach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
+{
+ struct apm_softc *sc = (struct apm_softc *)self;
+
+ sc->sc_parent = (void *)parent;
+
+ return;
+}
+
+int
+apmopen(dev, flag, mode, p)
+ dev_t dev;
+ int flag, mode;
+ struct proc *p;
+{
+ return 0;
+}
+
+int
+apmclose(dev, flag, mode, p)
+ dev_t dev;
+ int flag, mode;
+ struct proc *p;
+{
+ return 0;
+}
+
+int
+apmioctl(dev, cmd, data, flag, p)
+ dev_t dev;
+ u_long cmd;
+ caddr_t data;
+ int flag;
+ struct proc *p;
+{
+ struct apm_softc *sc;;
+
+ if ((apm_cd.cd_ndevs == 0) || (minor(dev) & 0xf0) ||
+ ((sc = apm_cd.cd_devs[minor(dev) & 0xf0]) == NULL))
+ return ENXIO;
+
+ switch (cmd) {
+ case APM_IOC_GETPOWER:
+ return hpcarm_apm_getpower((struct apm_power_info *)data,
+ sc->sc_parent);
+ break;
+
+ default:
+ return EINVAL;
+ break;
+ }
+
+ return 0;
+}
+
+int
+apmpoll(dev, events, p)
+ dev_t dev;
+ int events;
+ struct proc *p;
+{
+ return 0;
+}
diff -r a93774917a3b -r d4c019487215 sys/arch/hpcarm/include/Makefile
--- a/sys/arch/hpcarm/include/Makefile Mon Sep 16 19:50:27 2002 +0000
+++ b/sys/arch/hpcarm/include/Makefile Mon Sep 16 19:52:52 2002 +0000
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.17 2002/08/07 05:15:21 briggs Exp $
+# $NetBSD: Makefile,v 1.18 2002/09/16 19:52:55 manu Exp $
KDIR= /sys/arch/hpcarm/include
INCSDIR= /usr/include/hpcarm
-INCS= ansi.h aout_machdep.h asm.h \
+INCS= ansi.h apmvar.h aout_machdep.h asm.h \
bswap.h bus.h \
cdefs.h cpu.h \
db_machdep.h disklabel.h \
diff -r a93774917a3b -r d4c019487215 sys/arch/hpcarm/include/apmvar.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hpcarm/include/apmvar.h Mon Sep 16 19:52:52 2002 +0000
@@ -0,0 +1,76 @@
+/* $NetBSD: apmvar.h,v 1.1 2002/09/16 19:52:55 manu Exp $ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+struct apm_attach_args {
+ int aaa_magic;
+};
+#define APM_ATTACH_ARGS_MAGIC 0x0061706d
+
+/*
+ * All definitions from here are duplicated in i386 and macppc
+ * versions. The definitions are the same, it is probably worth
+ * moving them in a MI place.
+ */
+
+#define APM_AC_OFF 0x00
+#define APM_AC_ON 0x01
+#define APM_AC_BACKUP 0x02
+#define APM_AC_UNKNOWN 0xff
+#define APM_BATT_HIGH 0x00
+#define APM_BATT_LOW 0x01
+#define APM_BATT_CRITICAL 0x02
+#define APM_BATT_CHARGING 0x03
+#define APM_BATT_ABSENT 0x04
+#define APM_BATT_UNKNOWN 0xff
+#define APM_BATT_LIFE_UNKNOWN 0xff
+
+struct apm_power_info {
+ u_char battery_state;
+ u_char ac_state;
+ u_char battery_life;
+ u_char spare1;
+ u_int minutes_left; /* estimate */
+ u_int nbattery;
+ u_int batteryid;
+ u_int spare2[4];
+};
+
+/* ioctl definitions */
+#define APM_IOC_STANDBY _IO('A', 1)
+#define APM_IOC_SUSPEND _IO('A', 2)
+#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info)
Home |
Main Index |
Thread Index |
Old Index