Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/hpcmips Experimental APM compatible power management.



details:   https://anonhg.NetBSD.org/src/rev/789493d855ef
branches:  trunk
changeset: 494123:789493d855ef
user:      takemura <takemura%NetBSD.org@localhost>
date:      Sun Jul 02 10:01:30 2000 +0000

description:
Experimental APM compatible power management.

diffstat:

 sys/arch/hpcmips/conf/GENERIC          |    8 +-
 sys/arch/hpcmips/conf/files.hpcmips    |   10 +-
 sys/arch/hpcmips/dev/bivideo.c         |   40 +++-
 sys/arch/hpcmips/dev/btnmgr.c          |    7 +-
 sys/arch/hpcmips/dev/hpcapm.c          |  345 +++++++++++++++++++++++++++++++++
 sys/arch/hpcmips/hpcmips/mainbus.c     |    4 +-
 sys/arch/hpcmips/include/config_hook.h |    8 +-
 sys/arch/hpcmips/vr/vrpmu.c            |   16 +-
 8 files changed, 420 insertions(+), 18 deletions(-)

diffs (truncated from 585 to 300 lines):

diff -r 4899caa24e7c -r 789493d855ef sys/arch/hpcmips/conf/GENERIC
--- a/sys/arch/hpcmips/conf/GENERIC     Sun Jul 02 09:56:39 2000 +0000
+++ b/sys/arch/hpcmips/conf/GENERIC     Sun Jul 02 10:01:30 2000 +0000
@@ -2,11 +2,11 @@
 # Distribution kernel (NEC VR based model) kernel config file
 
 #
-#      $NetBSD: GENERIC,v 1.56 2000/06/30 17:10:17 itojun Exp $
+#      $NetBSD: GENERIC,v 1.57 2000/07/02 10:01:30 takemura Exp $
 #
 include                "arch/hpcmips/conf/std.hpcmips"
 
-#ident                 "GENERIC-$Revision: 1.56 $"
+#ident                 "GENERIC-$Revision: 1.57 $"
 
 maxusers       8
 
@@ -97,6 +97,10 @@
 options        WSDISPLAY_COMPAT_USL            # VT handling
 options        WSDISPLAY_COMPAT_RAWKBD         # can get raw scancodes
 
+# temporally power management
+hpcapm0        at mainbus0                     # pseudo power management
+apm0   at hpcapm0                      # pseudo APM
+
 vrip*  at mainbus0
 vrcmu* at vrip? addr 0x0b000060 size 0x20
 vrbcu* at vrip? addr 0x0b000000 size 0x20
diff -r 4899caa24e7c -r 789493d855ef sys/arch/hpcmips/conf/files.hpcmips
--- a/sys/arch/hpcmips/conf/files.hpcmips       Sun Jul 02 09:56:39 2000 +0000
+++ b/sys/arch/hpcmips/conf/files.hpcmips       Sun Jul 02 10:01:30 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.hpcmips,v 1.33 2000/06/11 23:34:31 matt Exp $
+#      $NetBSD: files.hpcmips,v 1.34 2000/07/02 10:01:30 takemura Exp $
 
 # maxpartitions must be first item in files.${ARCH}.
 maxpartitions 8
@@ -90,6 +90,14 @@
 file   arch/hpcmips/dev/video_subr.c   tx3912video | plumvideo
 
 #
+# power management
+#
+include "dev/apm/files.apm"
+device hpcapm: apmif
+attach hpcapm at mainbus
+file   arch/hpcmips/dev/hpcapm.c       hpcapm
+
+#
 # ISA bus support
 #
 include "dev/isa/files.isa"
diff -r 4899caa24e7c -r 789493d855ef sys/arch/hpcmips/dev/bivideo.c
--- a/sys/arch/hpcmips/dev/bivideo.c    Sun Jul 02 09:56:39 2000 +0000
+++ b/sys/arch/hpcmips/dev/bivideo.c    Sun Jul 02 10:01:30 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bivideo.c,v 1.8 2000/06/29 08:17:59 mrg Exp $  */
+/*     $NetBSD: bivideo.c,v 1.9 2000/07/02 10:01:31 takemura Exp $     */
 
 /*-
  * Copyright (c) 1999
@@ -37,7 +37,7 @@
 static const char _copyright[] __attribute__ ((unused)) =
     "Copyright (c) 1999 Shin Takemura.  All rights reserved.";
 static const char _rcsid[] __attribute__ ((unused)) =
-    "$Id: bivideo.c,v 1.8 2000/06/29 08:17:59 mrg Exp $";
+    "$Id: bivideo.c,v 1.9 2000/07/02 10:01:31 takemura Exp $";
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -55,6 +55,7 @@
 #include <machine/bootinfo.h>
 #include <machine/platid.h>
 #include <machine/platid_mask.h>
+#include <machine/config_hook.h>
 
 #include <dev/wscons/wsconsio.h>
 #include <dev/wscons/wsdisplayvar.h>
@@ -78,8 +79,11 @@
        struct device           sc_dev;
        struct hpcfb_fbconf     sc_fbconf;
        struct hpcfb_dspconf    sc_dspconf;
+       void                    *sc_powerhook;  /* power management hook */
+       int                     sc_powerstate;
 };
 static int bivideo_init __P((struct hpcfb_fbconf *fb));
+static void bivideo_power __P((int, void *));
 
 /*
  *  static variables
@@ -132,6 +136,13 @@
        }
        printf("\n");
 
+       /* Add a suspend hook to power saving */
+       sc->sc_powerstate = 1;
+       sc->sc_powerhook = powerhook_establish(bivideo_power, sc);
+       if (sc->sc_powerhook == NULL)
+               printf("%s: WARNING: unable to establish power hook\n",
+                       sc->sc_dev.dv_xname);
+
        ha.ha_console = console_flag;
        ha.ha_accessops = &bivideo_ha;
        ha.ha_accessctx = sc;
@@ -266,6 +277,31 @@
        return (0); /* no error */
 }
 
+static void 
+bivideo_power(why, arg)
+       int why;
+       void *arg;
+{
+       struct bivideo_softc *sc = arg;
+
+       switch (why) {
+       case PWR_SUSPEND:
+       case PWR_STANDBY:
+               sc->sc_powerstate = 0;
+               break;
+       case PWR_RESUME:
+               sc->sc_powerstate = 1;
+               break;
+       }
+
+       config_hook_call(CONFIG_HOOK_POWERCONTROL,
+                        CONFIG_HOOK_POWERCONTROL_LCD,
+                        (void*)sc->sc_powerstate);
+       config_hook_call(CONFIG_HOOK_POWERCONTROL,
+                        CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
+                        (void*)sc->sc_powerstate);
+}
+
 int
 bivideo_ioctl(v, cmd, data, flag, p)
        void *v;
diff -r 4899caa24e7c -r 789493d855ef sys/arch/hpcmips/dev/btnmgr.c
--- a/sys/arch/hpcmips/dev/btnmgr.c     Sun Jul 02 09:56:39 2000 +0000
+++ b/sys/arch/hpcmips/dev/btnmgr.c     Sun Jul 02 10:01:30 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: btnmgr.c,v 1.8 2000/05/18 03:27:22 sato Exp $  */
+/*     $NetBSD: btnmgr.c,v 1.9 2000/07/02 10:01:31 takemura Exp $      */
 
 /*-
  * Copyright (c) 1999
@@ -234,6 +234,11 @@
                            button_config[id].keycode);
        }
 
+       if (id == CONFIG_HOOK_BUTTONEVENT_POWER && msg)
+               config_hook_call(CONFIG_HOOK_PMEVENT, 
+                                CONFIG_HOOK_PMEVENT_SUSPENDREQ, NULL);
+
+
        return (0);
 }
 
diff -r 4899caa24e7c -r 789493d855ef sys/arch/hpcmips/dev/hpcapm.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hpcmips/dev/hpcapm.c     Sun Jul 02 10:01:30 2000 +0000
@@ -0,0 +1,345 @@
+/*     $NetBSD: hpcapm.c,v 1.1 2000/07/02 10:01:31 takemura Exp $      */
+
+/*
+ * Copyright (c) 2000 Takemura Shin
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <sys/param.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+
+#include <dev/apm/apmvar.h>
+
+#include <machine/bus.h>
+#include <machine/autoconf.h>
+#include <machine/config_hook.h>
+#include <machine/platid.h>
+#include <machine/platid_mask.h>
+
+#include "vrip.h"
+#if NVRIP > 0
+#include <hpcmips/vr/vripvar.h>
+#include <hpcmips/vr/vr_asm.h>
+#endif
+
+#define HPCAPMDEBUG
+#ifdef HPCAPMDEBUG
+#ifndef HPCAPMDEBUG_CONF
+#define HPCAPMDEBUG_CONF 1
+#endif
+int    hpcapm_debug = HPCAPMDEBUG_CONF;
+#define        DPRINTF(arg)     do { if (hpcapm_debug) printf arg; } while(0);
+#define        DPRINTFN(n, arg) do { if (hpcapm_debug > (n)) printf arg; } while (0);
+#else
+#define        DPRINTF(arg)     do { } while (0);
+#define DPRINTFN(n, arg) do { } while (0);
+#endif
+
+/* Definition of the driver for autoconfig. */
+static int     hpcapm_match(struct device *, struct cfdata *, void *);
+static void    hpcapm_attach(struct device *, struct device *, void *);
+static int     hpcapm_hook __P((void *, int, long, void *));
+
+static void    hpcapm_disconnect __P((void *));
+static void    hpcapm_enable __P((void *, int));
+static int     hpcapm_set_powstate __P((void *, u_int, u_int));
+static int     hpcapm_get_powstat __P((void *, struct apm_power_info *));
+static int     hpcapm_get_event __P((void *, u_int *, u_int *));
+static void    hpcapm_cpu_busy __P((void *));
+static void    hpcapm_cpu_idle __P((void *));
+static void    hpcapm_get_capabilities __P((void *, u_int *, u_int *));
+
+struct cfattach hpcapm_ca = {
+       sizeof (struct device), hpcapm_match, hpcapm_attach
+};
+
+struct apmhpc_softc {
+       struct device sc_dev;
+       void *sc_apmdev;
+       unsigned int events;
+       int power_state;
+       config_hook_tag sc_standby_hook;
+       config_hook_tag sc_suspend_hook;
+};
+
+struct apm_accessops hpcapm_accessops = {
+       hpcapm_disconnect,
+       hpcapm_enable,
+       hpcapm_set_powstate,
+       hpcapm_get_powstat,
+       hpcapm_get_event,
+       hpcapm_cpu_busy,
+       hpcapm_cpu_idle,
+       hpcapm_get_capabilities,
+};
+
+extern struct cfdriver hpcapm_cd;
+
+static int
+hpcapm_match(parent, cf, aux)
+       struct device *parent;
+       struct cfdata *cf;
+       void *aux;
+{
+       struct mainbus_attach_args *ma = aux;
+
+       if (strcmp(ma->ma_name, hpcapm_cd.cd_name) != 0) {
+               return (0);
+       }
+       return (1);
+}
+
+static void
+hpcapm_attach(parent, self, aux)
+       struct device *parent;
+       struct device *self;
+       void *aux;
+{
+       struct apmhpc_softc *sc;
+       struct apmdev_attach_args aaa;
+
+       sc = (struct apmhpc_softc *)self;
+       printf(": pseudo power management module\n");
+
+       sc->events = 0;
+       sc->power_state = APM_SYS_READY;
+       sc->sc_standby_hook = config_hook(CONFIG_HOOK_PMEVENT,
+                                         CONFIG_HOOK_PMEVENT_STANDBYREQ,
+                                         CONFIG_HOOK_EXCLUSIVE,
+                                         hpcapm_hook, sc);
+       sc->sc_suspend_hook = config_hook(CONFIG_HOOK_PMEVENT,
+                                         CONFIG_HOOK_PMEVENT_SUSPENDREQ,
+                                         CONFIG_HOOK_EXCLUSIVE,
+                                         hpcapm_hook, sc);
+
+       aaa.accessops = &hpcapm_accessops;
+       aaa.accesscookie = sc;



Home | Main Index | Thread Index | Old Index