PERFORCE change 167165 for review
Hans Petter Selasky
hselasky at FreeBSD.org
Mon Aug 10 10:03:58 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=167165
Change 167165 by hselasky at hselasky_laptop001 on 2009/08/10 10:03:29
USB input:
- patch to stop keyboard timer when no keys are pressed
Affected files ...
.. //depot/projects/usb/src/sys/dev/usb/input/ukbd.c#29 edit
Differences ...
==== //depot/projects/usb/src/sys/dev/usb/input/ukbd.c#29 (text+ko) ====
@@ -165,6 +165,7 @@
#define UKBD_FLAG_APPLE_EJECT 0x0040
#define UKBD_FLAG_APPLE_FN 0x0080
#define UKBD_FLAG_APPLE_SWAP 0x0100
+#define UKBD_FLAG_TIMER_RUNNING 0x0200
int32_t sc_mode; /* input mode (K_XLATE,K_RAW,K_CODE) */
int32_t sc_state; /* shift/lock key state */
@@ -279,6 +280,25 @@
static device_detach_t ukbd_detach;
static device_resume_t ukbd_resume;
+static uint8_t
+ukbd_any_key_pressed(struct ukbd_softc *sc)
+{
+ uint8_t i;
+ uint8_t j;
+
+ for (j = i = 0; i < UKBD_NKEYCODE; i++)
+ j |= sc->sc_odata.keycode[i];
+
+ return (j ? 1 : 0);
+}
+
+static void
+ukbd_start_timer(struct ukbd_softc *sc)
+{
+ sc->sc_flags |= UKBD_FLAG_TIMER_RUNNING;
+ usb_callout_reset(&sc->sc_callout, hz / 40, &ukbd_timeout, sc);
+}
+
static void
ukbd_put_key(struct ukbd_softc *sc, uint32_t key)
{
@@ -302,9 +322,6 @@
static void
ukbd_do_poll(struct ukbd_softc *sc, uint8_t wait)
{
- uint8_t i;
- uint8_t j;
-
DPRINTFN(2, "polling\n");
while (sc->sc_inputs == 0) {
@@ -313,10 +330,7 @@
/* Delay-optimised support for repetition of keys */
- for (j = i = 0; i < UKBD_NKEYCODE; i++)
- j |= sc->sc_odata.keycode[i];
-
- if (j) {
+ if (ukbd_any_key_pressed(sc)) {
/* a key is pressed - need timekeeping */
DELAY(1000);
@@ -480,7 +494,11 @@
}
ukbd_interrupt(sc);
- usb_callout_reset(&sc->sc_callout, hz / 40, &ukbd_timeout, sc);
+ if (ukbd_any_key_pressed(sc)) {
+ ukbd_start_timer(sc);
+ } else {
+ sc->sc_flags &= ~UKBD_FLAG_TIMER_RUNNING;
+ }
}
static uint8_t
@@ -592,6 +610,12 @@
}
ukbd_interrupt(sc);
+
+ if (!(sc->sc_flags & UKBD_FLAG_TIMER_RUNNING)) {
+ if (ukbd_any_key_pressed(sc)) {
+ ukbd_start_timer(sc);
+ }
+ }
}
case USB_ST_SETUP:
tr_setup:
@@ -657,11 +681,11 @@
usbd_xfer_set_frames(xfer, 2);
usbd_transfer_submit(xfer);
}
- return;
+ break;
default: /* Error */
DPRINTFN(0, "error=%s\n", usbd_errstr(error));
- return;
+ break;
}
}
@@ -869,9 +893,6 @@
usbd_transfer_start(sc->sc_xfer[UKBD_INTR_DT]);
- /* start the timer */
-
- ukbd_timeout(sc);
mtx_unlock(&Giant);
return (0); /* success */
More information about the p4-projects
mailing list