From owner-p4-projects@FreeBSD.ORG Mon Aug 10 10:03:57 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 41F7C106567A; Mon, 10 Aug 2009 10:03:57 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 00C311065676 for ; Mon, 10 Aug 2009 10:03:57 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id CA7AB8FC15 for ; Mon, 10 Aug 2009 10:03:56 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n7AA3ufn005419 for ; Mon, 10 Aug 2009 10:03:56 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n7AA3uui005417 for perforce@freebsd.org; Mon, 10 Aug 2009 10:03:56 GMT (envelope-from hselasky@FreeBSD.org) Date: Mon, 10 Aug 2009 10:03:56 GMT Message-Id: <200908101003.n7AA3uui005417@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Cc: Subject: PERFORCE change 167165 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Aug 2009 10:03:58 -0000 http://perforce.freebsd.org/chv.cgi?CH=167165 Change 167165 by hselasky@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 */