RFC About USB Keyboard Polling
Wolfgang,
We need to add USB Keyboard support to the 8641 HPCN board. We currently have this working in a mode that is polled rather than configuring any interrupts and handlers.
However, to do so, we needed to extend the usb_kbd_getc() routine to possibly poll for interrupts as well. So as to avoid introducing extra code for platforms that do not need it, we propose the following two patches.
Does this seem look a good approach to you?
Thanks,
jdl
PS -- The actual USB OHCI driver is a separate patch too,
but it is board specific. The patches below represent the changes to the common code.
commit 78c25c38ba8786b12b5d08d2555493ad74564825
Author: Zhang Wei <[email protected]> Date: Wed Feb 14 14:43:53 2007 +0800
Add CFG_USB_INTERRUPT_POLL support.
Allow the USB controller to use interrupt polling in the input waiting loop in usb_kbd_getc() instead of asynchronous interrupts.
README +3 -0
@@ -883,6 +883,9 @@ The following options need to be configured: for differential drivers: 0x00001000 for single ended drivers: 0x00005000 + CFG_USB_INTERRUPT_POLL + May be defined to allow interrupt polling + instead of using aysnchronous interrupts. - MMC Support: The MMC controller on the Intel PXA is supported. To
common/usb_kbd.c +5 -1
@@ -129,7 +129,11 @@ static int usb_kbd_testc(void)static int usb_kbd_getc (void ) {char c; -while (usb_in_pointer==usb_out_pointer); +while (usb_in_pointer==usb_out_pointer) { +#ifdef CFG_USB_INTERRUPT_POLL +usb_interrupt_query (); +#endif + }if ((usb_out_pointer+1 )==USB_KBD_BUFFER_LEN ) usb_out_pointer=0 ;else
include/configs/MPC8641HPCN.h +1 -0
@@ -337,6 +337,7 @@#define CONFIG_USB_OHCI 1#define CONFIG_USB_KEYBOARD 1#define CFG_DEVICE_DEREGISTER +#define CFG_USB_INTERRUPT_POLL 1#if !defined(CONFIG_PCI_PNP )#define PCI_ENET0_IOADDR 0xe0000000
And then the actual poll routine itself:
commit f4a95829c0b9ef555d1ce750a5e501985e7c31b1
Author: Zhang Wei <[email protected]> Date: Mon Feb 12 19:00:37 2007 +0800
Add interrupt query function to USB core.
Without asynchronous interrupt support, it may be necessary to poll for USB keyboard interrupts.
common/usb.c +11 -0
@@ -143,6 +143,17 @@ void usb_disable_asynch(int disable) } +#ifdef CFG_USB_INTERRUPT_POLL +/* +* Poll for USB keyboard interrupts. +*/ +void usb_interrupt_query (void ) +{ +interrupt_poll (); +} +#endif + +/*------------------------------------------------------------------- * Message wrappers. *
include/usb.h +2 -0
@@ -177,6 +177,7 @@ int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int transfer_len,struct devrequest *setup);int submit_int_msg (struct usb_device *dev,unsigned long pipe,void *buffer,int transfer_len,int interval); +void interrupt_poll (void );/* Might need to poll for interrupts */ /* Defines */ #define USB_UHCI_VEND_ID 0x8086
@@ -218,6 +219,7 @@ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe,int usb_submit_int_msg (struct usb_device *dev,unsigned long pipe,void *buffer,int transfer_len,int interval);void usb_disable_asynch (int disable); +void usb_interrupt_query (void );int usb_maxpacket (struct usb_device *dev,unsigned long pipe);void __inline__wait_ms (unsigned long ms);int usb_get_configuration_no (struct usb_device *dev,unsigned char *buffer,int cfgno);
Dear Jon,
Quoted 4 lines · in message <1174589857.32390.52.camel@ld0161-tx32> you wrote:
We need to add USB Keyboard support to the 8641 HPCN board. We currently have this working in a mode that is polled rather than configuring any interrupts and handlers.
Understood.
Quoted 2 lines
However, to do so, we needed to extend the
usb_kbd_getc()routine to possibly poll for interrupts as well. So as
Um... this causes my scalp to curl...
Either we have interrupts, or we use polling.
[I think I know what you mean, but interrupt polling is a strict oxymoron to me.]
Quoted 1 line
Does this seem look a good approach to you?
You may want to include Markus Klotzb?cher in the Cc: list of such USB related patches.
Quoted 3 lines
Add
CFG_USB_INTERRUPT_POLLsupport.Allow the USB controller to use interrupt polling
Please use a better name. interrupt polling ... shudder...
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, HRB 165235 Munich, CEO: Wolfgang Denk Office: Kirchenstr. 5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Life would be so much easier if everyone read the manual.
Quoted 8 lines · Wolfgang Denk
Dear Jon,
Quoted 4 lines · in message <1174589857.32390.52.camel@ld0161-tx32> you wrote:
We need to add USB Keyboard support to the 8641 HPCN board. We currently have this working in a mode that is polled rather than configuring any interrupts and handlers.
Quoted 6 lines
Understood.
Quoted 2 lines
However, to do so, we needed to extend the
usb_kbd_getc()routine to possibly poll for interrupts as well. So asUm... this causes my scalp to curl...
Oh no!
Quoted 4 lines
Either we have interrupts, or we use polling.
[I think I know what you mean, but interrupt polling is a strict oxymoron to me.]
Oh, right. Yeah, I see your point here. :-) I'll change that name to something less confusing!
Quoted 4 lines
Quoted 1 line
Does this seem look a good approach to you?
You may want to include Markus Klotzb??cher in the Cc: list of such USB related patches.
OK. I'll try to track down an address for him!
I now see the -usb tree in his name. Got it.
Quoted 5 lines
Quoted 3 lines
Add
CFG_USB_INTERRUPT_POLLsupport.Allow the USB controller to use interrupt polling
Please use a better name. interrupt polling ... shudder...
Will do.
But again, does the overall approach seem like the right way? Or should that be a Markus question (too)?
Quoted 3 lines
Best regards,
Wolfgang Denk
Thanks for your review,
jdl