Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/hpcmips/dev Fix buttons arg of wsmouse_input().



details:   https://anonhg.NetBSD.org/src/rev/70e0b4b7bbfe
branches:  trunk
changeset: 580805:70e0b4b7bbfe
user:      hamajima <hamajima%NetBSD.org@localhost>
date:      Mon May 09 14:36:39 2005 +0000

description:
Fix buttons arg of wsmouse_input().
Add hard power hook. disable at suspend, enable at resume.

diffstat:

 sys/arch/hpcmips/dev/optpoint.c |  55 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 47 insertions(+), 8 deletions(-)

diffs (125 lines):

diff -r f6408145dc07 -r 70e0b4b7bbfe sys/arch/hpcmips/dev/optpoint.c
--- a/sys/arch/hpcmips/dev/optpoint.c   Mon May 09 11:35:19 2005 +0000
+++ b/sys/arch/hpcmips/dev/optpoint.c   Mon May 09 14:36:39 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: optpoint.c,v 1.1 2005/05/04 07:54:39 hamajima Exp $ */
+/*     $NetBSD: optpoint.c,v 1.2 2005/05/09 14:36:39 hamajima Exp $ */
 
 /*-
  * Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved.
@@ -31,12 +31,13 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: optpoint.c,v 1.1 2005/05/04 07:54:39 hamajima Exp $");
+__KERNEL_RCSID(0, "$NetBSD: optpoint.c,v 1.2 2005/05/09 14:36:39 hamajima Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/device.h>
 #include <machine/bus.h>
+#include <machine/config_hook.h>
 #include <dev/hpc/hpciovar.h>
 #include <dev/wscons/wsconsio.h>
 #include <dev/wscons/wsmousevar.h>
@@ -58,6 +59,7 @@
        struct tx39spi_softc *sc_spi;
        struct hpcio_chip *sc_hc;
        struct device *sc_wsmousedev;
+       void *sc_powerhook;     /* power management hook */
        char packet[4];
        int index;      /* number of bytes received for this packet */
        u_int buttons;  /* mouse button status */
@@ -73,6 +75,7 @@
 static int optpoint_initialize(void *);
 static void optpoint_send(struct optpoint_softc *, int);
 static int optpoint_recv(struct optpoint_softc *);
+static int optpoint_power(void *, int, long, void *);
 
 #define LBUTMASK 0x01
 #define RBUTMASK 0x02
@@ -127,6 +130,17 @@
        wsmaa.accesscookie = sc;
        /* attach the wsmouse */
        sc->sc_wsmousedev = config_found(self, &wsmaa, wsmousedevprint);
+
+       /* Add a hard power hook to power saving */
+       sc->sc_powerhook = config_hook(CONFIG_HOOK_PMEVENT,
+                                      CONFIG_HOOK_PMEVENT_HARDPOWER,
+                                      CONFIG_HOOK_SHARE,
+                                      optpoint_power, sc);
+#ifdef DIAGNOSTIC
+       if (sc->sc_powerhook == 0)
+               printf("%s: unable to establish hard power hook",
+                      sc->sc_dev.dv_xname);
+#endif
 }
 
 int
@@ -153,17 +167,16 @@
 
        sc->packet[sc->index++] = data;
        if (sc->index >= 3){
-               u_int newbuttons = ((sc->packet[1] & LBUTMASK) ? 0x1 : 0) |
-                   ((sc->packet[1] & RBUTMASK) ? 0x2 : 0);
+               u_int newbuttons = ((sc->packet[1] & LBUTMASK) ? 0x1 : 0)
+                                | ((sc->packet[1] & RBUTMASK) ? 0x2 : 0);
                int dx = sc->packet[2];
                int dy = sc->packet[0];
                u_int changed = (sc->buttons ^ newbuttons);
 
                if (dx || dy || changed){
-                       DPRINTF(("buttons=0x%x, dx=%d, dy=%d\n",
-                                newbuttons, dx, dy));
-                       wsmouse_input(sc->sc_wsmousedev,
-                                     sc->buttons, dx, dy, 0,
+                       DPRINTF(("%s: buttons=0x%x, dx=%d, dy=%d\n",
+                                sc->sc_dev.dv_xname, newbuttons, dx, dy));
+                       wsmouse_input(sc->sc_wsmousedev, newbuttons, dx, dy, 0,
                                      WSMOUSE_INPUT_DELTA);
                }
                sc->buttons = newbuttons;
@@ -185,6 +198,8 @@
                struct hpcio_chip *hc = sc->sc_hc;
                int s = spltty();
 
+               DPRINTF(("%s: enable\n", sc->sc_dev.dv_xname));
+
                sc->enabled = 1;
                sc->index = 0;
                sc->buttons = 0;
@@ -214,6 +229,8 @@
                struct hpcio_chip *hc = sc->sc_hc;
                int s = spltty();
 
+               DPRINTF(("%s: disable\n", sc->sc_dev.dv_xname));
+
                sc->enabled = 0;
                (*hc->hc_portwrite)(hc, TELIOS_MFIO_OPTP_C_REQ, 0);
                (*hc->hc_portwrite)(hc, TELIOS_MFIO_OPTP_T_RDY, 0);
@@ -285,3 +302,25 @@
                ;
        return tx39spi_get_word(sc->sc_spi) & 0xff;
 }
+
+int
+optpoint_power(void *self, int type, long id, void *msg)
+{
+       struct optpoint_softc *sc = (void *)self;
+       int why = (int)msg;
+
+       switch (why) {
+       case PWR_RESUME:
+               /* power on */
+               optpoint_enable(sc);
+               break;
+       case PWR_SUSPEND:
+               /* FALLTHROUGH */
+       case PWR_STANDBY:
+               /* power off */
+               optpoint_disable(sc);
+               break;
+       }
+
+       return 0;
+}



Home | Main Index | Thread Index | Old Index