[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pbsd-mg2] Re: Linux-mips (VR41xx)



In message <199908260307.MAA12735@shin1.sm.sony.co.jp> takemura@sm.sony.co.jp writes:
: こっちもこれから、なんとか Power Management をサポートして
: PocketBSD スタイルのインストールキット(*)をリリースしていきたいですね。

私はvrpmu デヴィスしました。pmu eventをプリントしってが、割り込みを晴
れります。Power Management をなおします。

I have done a vrpmu device.  It prints the pmu events and then clears
the interrupt.  It could do Power Management things as well.

Warner

Index: pmureg.h
===================================================================
RCS file: /cvs/jproot//hpcmips/sys/arch/hpcmips/vr/pmureg.h,v
retrieving revision 1.2
diff -u -r1.2 pmureg.h
--- pmureg.h	1999/07/18 13:22:29	1.2
+++ pmureg.h	1999/08/26 07:18:16
@@ -53,8 +53,8 @@
 #define		PMUINT_BATT		(1<<8)		/* BATTERY LOW  */
 #define		PMUINT_TIMOUTRST	(1<<5)		/* HAL Timer Reset */
 #define		PMUINT_RTCRST		(1<<4)		/* RTC Reset */
-#define		PMUINT_RTCRST		(1<<3)		/* Reset SW */
-#define		PMUINT_DMSRST		(1<<2)		/* Deadman's SW */
+#define		PMUINT_RSTSWRST		(1<<3)		/* Reset SW */
+#define		PMUINT_DMSWRST		(1<<2)		/* Deadman's SW */
 #define		PMUINT_BATTINTR		(1<<1)		/* Low batt during normal operation */
 #define		PMUINT_POWERSW		(1)		/* Power Switch */
 
@@ -74,23 +74,23 @@
 #define		PMUCNT_GPIO1DS		(0<<13)		/* GPIO1 Disable */
 
 #define		PMUCNT_GPIO0MASK	(1<<12)		/* GPIO0 MASK */
-#define		PMUCNT_GPIO0D		(1<<12)		/* GPIO0 Enable */
-#define		PMUCNT_GPIO0U		(0<<12)		/* GPIO0 Disable */
+#define		PMUCNT_GPIO0EN		(1<<12)		/* GPIO0 Enable */
+#define		PMUCNT_GPIO0DS		(0<<12)		/* GPIO0 Disable */
 
 #define		PMUCNT_GPIO3TRIG	(1<<11)		/* GPIO3 TRIG */
-#define		PMUCNT_GPIO3D		(1<<11)		/* GPIO3 Fail */
+#define		PMUCNT_GPIO3D		(1<<11)		/* GPIO3 Fall */
 #define		PMUCNT_GPIO3U		(0<<11)		/* GPIO3 Raise */
 
 #define		PMUCNT_GPIO2TRIG	(1<<10)		/* GPIO2 TRIG */
-#define		PMUCNT_GPIO2D		(1<<10)		/* GPIO2 Fail */
+#define		PMUCNT_GPIO2D		(1<<10)		/* GPIO2 Fall */
 #define		PMUCNT_GPIO2U		(0<<10)		/* GPIO2 Raise */
 
 #define		PMUCNT_GPIO1TRIG	(1<<9)		/* GPIO1 TRIG */
-#define		PMUCNT_GPIO1D		(1<<9)		/* GPIO1 Fail */
+#define		PMUCNT_GPIO1D		(1<<9)		/* GPIO1 Fall */
 #define		PMUCNT_GPIO1U		(0<<9)		/* GPIO1 Raise */
 
 #define		PMUCNT_GPIO0TRIG	(1<<8)		/* GPIO0 TRIG */
-#define		PMUCNT_GPIO0D		(1<<8)		/* GPIO0 Fail */
+#define		PMUCNT_GPIO0D		(1<<8)		/* GPIO0 Fall */
 #define		PMUCNT_GPIO0U		(0<<8)		/* GPIO0 Raise */
 
 #define		PMUCNT_HALTIMERRST	(1<<2)		/* HAL Timer Reset */ 
@@ -118,8 +118,8 @@
 #define		PMUCNT_GPIO10DS		(0<<13)		/* GPIO10 Disable */
 
 #define		PMUCNT_GPIO9MASK	(1<<12)		/* GPIO9 MASK */
-#define		PMUCNT_GPIO9D		(1<<12)		/* GPIO9 Enable */
-#define		PMUCNT_GPIO9U		(0<<12)		/* GPIO9 Disable */
+#define		PMUCNT_GPIO9EN		(1<<12)		/* GPIO9 Enable */
+#define		PMUCNT_GPIO9DS		(0<<12)		/* GPIO9 Disable */
 
 #define		PMUCNT_GPIO12TRIG	(1<<11)		/* GPIO12 TRIG */
 #define		PMUCNT_GPIO12D		(1<<11)		/* GPIO12 Fail */
Index: vrpmu.c
===================================================================
RCS file: vrpmu.c
diff -N vrpmu.c
--- /dev/null	Thu Aug 26 01:09:57 1999
+++ vrpmu.c	Thu Aug 26 01:19:14 1999
@@ -0,0 +1,151 @@
+/* $Id:$ */
+/*
+ * Copyright (c) 1999 M. Warner Losh.  All rights reserved.
+ * Copyright (c) 1999 PocketBSD Project. All rights reserved.
+ */
+
+#include <sys/param.h>
+#include <sys/tty.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+
+#include <machine/autoconf.h>
+#include <machine/intr.h>
+#include <machine/cpu.h>
+#include <machine/bus.h>
+#include <machine/platid.h>
+
+#include <hpcmips/vr/vr.h>
+#include <hpcmips/vr/vripvar.h>
+#include <hpcmips/vr/vrpmuvar.h>
+#include <hpcmips/vr/pmureg.h>
+#include <hpcmips/vr/icureg.h>
+
+static int vrpmumatch __P((struct device *, struct cfdata *, void *));
+static void vrpmuattach __P((struct device *, struct device *, void *));
+
+static void vrpmu_write __P((struct vrpmu_softc *, int, unsigned short));
+static unsigned short vrpmu_read __P((struct vrpmu_softc *, int));
+
+int vrpmu_intr __P((void *));
+
+struct cfattach vrpmu_ca = {
+	sizeof(struct vrpmu_softc), vrpmumatch, vrpmuattach
+};
+
+static int
+vrpmumatch(parent, cf, aux)
+	struct device *parent;
+	struct cfdata *cf;
+	void *aux;
+{
+	return 1;
+}
+
+static void
+vrpmuattach(parent, self, aux)
+	struct device *parent;
+	struct device *self;
+	void *aux;
+{
+	struct vrpmu_softc *sc = (struct vrpmu_softc *)self;
+	struct vrip_attach_args *va = aux;
+
+	bus_space_tag_t iot = va->va_iot;
+	bus_space_handle_t ioh;
+
+	if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
+		printf(": can't map bus space\n");
+		return;
+	}
+
+	sc->sc_iot = iot;
+	sc->sc_ioh = ioh;
+
+	if (!(sc->sc_handler = 
+	      vrip_intr_establish(va->va_vc, va->va_intr, IPL_TTY,
+				  vrpmu_intr, sc))) {
+	    printf (": can't map interrupt line.\n");
+	    return;
+	}
+
+	printf("\n");
+}
+
+static inline void
+vrpmu_write(sc, port, val)
+     struct vrpmu_softc *sc;
+     int port;
+     unsigned short val;
+{
+	bus_space_write_2(sc->sc_iot, sc->sc_ioh, port, val);
+}
+
+static inline unsigned short
+vrpmu_read(sc, port)
+     struct vrpmu_softc *sc;
+     int port;
+{
+	return bus_space_read_2(sc->sc_iot, sc->sc_ioh, port);
+}
+
+/*
+ * XXX
+ *
+ * In the following interrupt routine we should actually DO something
+ * with the knowledge that we've gained.  For now we just report it.
+ */
+int
+vrpmu_intr(arg)
+    void *arg;
+{
+        struct vrpmu_softc *sc = arg;
+	unsigned int intmask;
+
+	intmask = vrpmu_read(sc, PMUINT_REG_W);
+	vrpmu_write(sc, PMUINT_REG_W, intmask);
+
+	if (intmask & PMUINT_GPIO3)
+		printf("vrpmu: GPIO[3] activation\n");
+	if (intmask & PMUINT_GPIO2)
+		printf("vrpmu: GPIO[2] activation\n");
+	if (intmask & PMUINT_GPIO1)
+		printf("vrpmu: GPIO[1] activation\n");
+	if (intmask & PMUINT_GPIO0)
+		printf("vrpmu: GPIO[0] activation\n");
+
+	if (intmask & PMUINT_RTC)
+		printf("vrpmu: RTC alarm detected\n");
+	if (intmask & PMUINT_BATT)
+		printf("vrpmu: Battery low during activation\n");
+
+	if (intmask & PMUINT_TIMOUTRST)
+		printf("vrpmu: HAL timer reset\n");
+	if (intmask & PMUINT_RTCRST)
+		printf("vrpmu: RTC reset detected\n");
+	if (intmask & PMUINT_RSTSWRST)
+		printf("vrpmu: RESET switch detected\n");
+	if (intmask & PMUINT_DMSWRST)
+		printf("vrpmu: Deadman's switch detected\n");
+	if (intmask & PMUINT_BATTINTR)
+		printf("vrpmu: Battery low during normal ops\n");
+	if (intmask & PMUINT_POWERSW)
+		printf("vrpmu: POWER switch detected\n");
+
+	intmask = vrpmu_read(sc, PMUINT2_REG_W);
+	vrpmu_write(sc, PMUINT2_REG_W, intmask);
+
+	if (intmask & PMUINT_GPIO12)
+		printf("vrpmu: GPIO[12] activation\n");
+	if (intmask & PMUINT_GPIO11)
+		printf("vrpmu: GPIO[11] activation\n");
+	if (intmask & PMUINT_GPIO10)
+		printf("vrpmu: GPIO[10] activation\n");
+	if (intmask & PMUINT_GPIO9)
+		printf("vrpmu: GPIO[9] activation\n");
+
+	return 0;
+}
Index: vrpmuvar.h
===================================================================
RCS file: vrpmuvar.h
diff -N vrpmuvar.h
--- /dev/null	Thu Aug 26 01:09:57 1999
+++ vrpmuvar.h	Thu Aug 26 00:11:03 1999
@@ -0,0 +1,13 @@
+/* $Id:$ */
+
+/*
+ * Copyright (c) 1999 M. Warner Losh.  All rights reserved.
+ * Copyright (c) 1999 PocketBSD Project. All rights reserved.
+ */
+
+struct vrpmu_softc {
+  struct device sc_dev;
+  bus_space_tag_t sc_iot;
+  bus_space_handle_t sc_ioh;
+  void *sc_handler;
+};