From patchwork Sun Sep 25 19:00:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 116317 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 8C5ACB6F75 for ; Mon, 26 Sep 2011 05:00:51 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4D91F28282; Sun, 25 Sep 2011 21:00:49 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uF1UiBuX-uip; Sun, 25 Sep 2011 21:00:49 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D3B7828277; Sun, 25 Sep 2011 21:00:46 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 102FE28277 for ; Sun, 25 Sep 2011 21:00:44 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IpHE8MOp4SZZ for ; Sun, 25 Sep 2011 21:00:43 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-bw0-f44.google.com (mail-bw0-f44.google.com [209.85.214.44]) by theia.denx.de (Postfix) with ESMTPS id 09CBF28272 for ; Sun, 25 Sep 2011 21:00:41 +0200 (CEST) Received: by bkaq10 with SMTP id q10so4676362bka.3 for ; Sun, 25 Sep 2011 12:00:41 -0700 (PDT) Received: by 10.204.13.83 with SMTP id b19mr3698852bka.116.1316977240934; Sun, 25 Sep 2011 12:00:40 -0700 (PDT) Received: from mashiro.ms.mff.cuni.cz (eduroam32.ms.mff.cuni.cz. [195.113.21.32]) by mx.google.com with ESMTPS id y8sm18228707bkb.4.2011.09.25.12.00.40 (version=SSLv3 cipher=OTHER); Sun, 25 Sep 2011 12:00:40 -0700 (PDT) From: Marek Vasut To: u-boot@lists.denx.de Date: Sun, 25 Sep 2011 21:00:37 +0200 Message-Id: <1316977237-8709-1-git-send-email-marek.vasut@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1316976340-31467-1-git-send-email-marek.vasut@gmail.com> References: <1316976340-31467-1-git-send-email-marek.vasut@gmail.com> Subject: [U-Boot] [PATCH V2] USB: Add functionality to poll the USB keyboard via control EP X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This allows the keyboard to avoid requests via Interrupt Endpoint altogether and run all requests via Control Endpoint. This uses the Get_Report request. Signed-off-by: Marek Vasut Cc: Remy Bohmer --- common/usb_kbd.c | 64 ++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 50 insertions(+), 14 deletions(-) V2: Add missing condition to ignore repetitive events when polling via EP0 diff --git a/common/usb_kbd.c b/common/usb_kbd.c index 9957dcc..503d175 100644 --- a/common/usb_kbd.c +++ b/common/usb_kbd.c @@ -96,6 +96,26 @@ static unsigned char usb_kbd_numkey_shifted[] = { '+', '{', '}', '|', '~', ':', '"', '~', '<', '>', '?' }; +static int usb_kbd_irq_worker(struct usb_device *dev); + +/****************************************************************** + * Interrupt polling + ******************************************************************/ +static inline void usb_kbd_poll_for_event(struct usb_device *dev) +{ +#if defined(CONFIG_SYS_USB_EVENT_POLL) + usb_event_poll(); + usb_kbd_irq_worker(dev); +#elif defined(CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP) + struct usb_interface *iface; + iface = &dev->config.if_desc[0]; + usb_get_report(dev, iface->desc.bInterfaceNumber, + 1, 1, new, sizeof(new)); + if (memcmp(old, new, sizeof(new))) + usb_kbd_irq_worker(dev); +#endif +} + /****************************************************************** * Queue handling ******************************************************************/ @@ -120,9 +140,14 @@ static void usb_kbd_put_queue(char data) /* test if a character is in the queue */ static int usb_kbd_testc(void) { -#ifdef CONFIG_SYS_USB_EVENT_POLL - usb_event_poll(); -#endif + struct stdio_dev *dev; + struct usb_device *usb_kbd_dev; + + dev = stdio_get_by_name("usbkbd"); + usb_kbd_dev = (struct usb_device *)dev->priv; + + usb_kbd_poll_for_event(usb_kbd_dev); + if(usb_in_pointer==usb_out_pointer) return(0); /* no data */ else @@ -132,11 +157,16 @@ static int usb_kbd_testc(void) static int usb_kbd_getc(void) { char c; - while(usb_in_pointer==usb_out_pointer) { -#ifdef CONFIG_SYS_USB_EVENT_POLL - usb_event_poll(); -#endif - } + + struct stdio_dev *dev; + struct usb_device *usb_kbd_dev; + + dev = stdio_get_by_name("usbkbd"); + usb_kbd_dev = (struct usb_device *)dev->priv; + + while(usb_in_pointer==usb_out_pointer) + usb_kbd_poll_for_event(usb_kbd_dev); + if((usb_out_pointer+1)==USB_KBD_BUFFER_LEN) usb_out_pointer=0; else @@ -308,15 +338,10 @@ static int usb_kbd_translate(unsigned char scancode,unsigned char modifier,int p } /* Interrupt service routine */ -static int usb_kbd_irq(struct usb_device *dev) +static int usb_kbd_irq_worker(struct usb_device *dev) { int i,res; - if((dev->irq_status!=0)||(dev->irq_act_len!=8)) - { - USB_KBD_PRINTF("usb_keyboard Error %lX, len %d\n",dev->irq_status,dev->irq_act_len); - return 1; - } res=0; switch (new[0]) { @@ -345,6 +370,17 @@ static int usb_kbd_irq(struct usb_device *dev) return 1; /* install IRQ Handler again */ } +static int usb_kbd_irq(struct usb_device *dev) +{ + if ((dev->irq_status != 0) || (dev->irq_act_len != 8)) + { + USB_KBD_PRINTF("usb_keyboard Error %lX, len %d\n",dev->irq_status,dev->irq_act_len); + return 1; + } + + return usb_kbd_irq_worker(dev); +} + /* probes the USB device dev for keyboard type */ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum) {