public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2] USB: Add functionality to poll the USB keyboard via control EP
Date: Sun, 25 Sep 2011 21:00:37 +0200	[thread overview]
Message-ID: <1316977237-8709-1-git-send-email-marek.vasut@gmail.com> (raw)
In-Reply-To: <1316976340-31467-1-git-send-email-marek.vasut@gmail.com>

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 <marek.vasut@gmail.com>
Cc: Remy Bohmer <linux@bohmer.net>
---
 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)
 {
-- 
1.7.5.4

  reply	other threads:[~2011-09-25 19:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-25 18:45 [U-Boot] [PATCH] USB: Add functionality to poll the USB keyboard via control EP Marek Vasut
2011-09-25 19:00 ` Marek Vasut [this message]
2011-10-06 21:21   ` [U-Boot] [PATCH V2] " Wolfgang Denk
2011-10-06 23:31     ` Marek Vasut
2011-10-07  6:15       ` Wolfgang Denk
2011-10-08 18:32         ` Remy Bohmer
2011-10-08 18:33     ` Remy Bohmer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1316977237-8709-1-git-send-email-marek.vasut@gmail.com \
    --to=marek.vasut@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox