summaryrefslogtreecommitdiff
path: root/common/usb_kbd.c
AgeCommit message (Collapse)Author
2022-02-11console: usb: kbd: Limit poll frequency to improve performanceThomas Watson
Using the XHCI driver, the function `usb_kbd_poll_for_event` takes 30-40ms to run. The exact time is dependent on the polling interval the keyboard requests in its descriptor, and likely cannot be significantly reduced without major rework to the XHCI driver. The U-Boot EFI console service sets a timer to poll the keyboard every 5 microseconds, and this timer is checked every time a block is read off disk. The net effect is that, on my system, loading a ~40MiB kernel and initrd takes about 62 seconds with a slower keyboard and 53 seconds with a faster one, with the vast majority of the time spent polling the keyboard. To solve this problem, this patch adds a 20ms delay between consecutive calls to `usb_kbd_poll_for_event`. This is sufficient to reduce the total loading time to under half a second for both keyboards, and does not impact the perceived keystroke latency. Signed-off-by: Thomas Watson <twatson52@icloud.com>
2021-02-26usb: kbd: Also accept keyboards with Interrupt OUT endpointStefan Brüns
The OUT endpoint can just be ignored as it is not used, just as the corresponding Set_Report request for IN-only interfaces. E.g. the Linux gadget hid keyboard also provides an interrupt endpoint. Also cleanup confusing debug messages like "found set protocol", which is printed when a keyboard device is found, while the Set_Protocol request is issued quite some time later. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
2021-02-16usb: kbd: destroy device after console is stoppedAndy Shevchenko
In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console. Swap the order of device deregistration and IOMUX update along with converting to use iomux_replace_device() jelper to avoid the use-after-free. Fixes: 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used") Fixes: 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards") Reported-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-05-18common: Drop log.h from common headerSimon Glass
Move this header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-11-25usb: kbd: move USB_KBD_BOOT_REPORT_SIZE to usb.hHeinrich Schuchardt
Move constant USB_KBD_BOOT_REPORT_SIZE. This allows us to reuse it. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2019-11-25usb: kbd: implement special keysHeinrich Schuchardt
Provide support for F1-F12, Insert, Delete, Home, End, Page Up, Page Down. As this leads to a size increase provide a customizing setting CONFIG_USB_KEYBOARD_FN_KEYS. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-11-25usb: kbd: simplify coding for arrow keysHeinrich Schuchardt
Avoid duplicate translation of arrow key codes. Reduce code size by avoiding strings and eliminating usb_kbd_put_sequence(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-11-25usb: kbd: signature of usb_kbd_put_queue()Heinrich Schuchardt
usb_kbd_buffer is defined as u8[]. So let usb_kbd_put_queue() use u8 as type of the parameter for the new byte. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-11-25usb: kbd: fix typoHeinrich Schuchardt
%s/a interrupt/an interrupt/ Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2019-09-11usb: Add nonblock argument to submit_int_msgMichal Suchanek
This will be used to implement non-blocking keyboard polling in case of errors. Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2019-09-11usb: usb_submit_int_msg -> usb_int_msgMichal Suchanek
This aligns naming with usb_bulk_msg and usb_control_msg. Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2019-09-11usb_kdb: only process events successfully receivedMichal Suchanek
Causes unbound key repeat on error otherwise. Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2019-08-11env: Move env_get() to env.hSimon Glass
Move env_get() over to the new header file. Acked-by: Joe Hershberger <joe.hershberger@ni.com> Signed-off-by: Simon Glass <sjg@chromium.org>
2019-04-14usb: kbd: Properly translate up/down arrow keysAndre Przywara
So far arrows key pressed on an USB keyboard got translated to some low ASCII control sequences (Ctrl+N, Ctrl+P). Some programs understand these codes, but the standard for those keys is to use ANSI control sequences for cursor movement (ESC [ A). Our own boot menu is a victim of this, currently we cannot change the selection with an USB keyboard due to this. Since we already implement a queue for USB key codes, we can just insert the three character ANSI sequence into the key buffer. This fixes the bootmenu, and is more universal for other users (UEFI) as well. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-11-26usb: s/CONFIG_DM_USB/CONFIG_IS_ENABLED(DM_USB)/Sven Schwermer
This allows to disable the USB driver model in SPL because it checks the CONFIG_SPL_DM_USB variable for SPL builds. Nothing changes for regular non-SPL builds. Signed-off-by: Sven Schwermer <sven@svenschwermer.de>
2018-07-19usb_kdb: Get stdio_dev directly from sdev pointerMichal Simek
Driver supports only one instance of usb keyboard. Remove the first dependency on generic usbkbd DEVNAME. Signed-off-by: Michal Simek <michal.simek@xilinx.com>
2018-07-19usb_kbd: Add support for watchdogMichal Simek
There is need to service watchdog in while loop or system will be restarted when idlying. Signed-off-by: Michal Simek <michal.simek@xilinx.com>
2018-05-07SPDX: Convert all of our single license tags to Linux Kernel styleTom Rini
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
2017-08-16env: Rename getenv/_f() to env_get()Simon Glass
We are now using an env_ prefix for environment functions. Rename these two functions for consistency. Also add function comments in common.h. Quite a few places use getenv() in a condition context, provoking a warning from checkpatch. These are fixed up in this patch also. Suggested-by: Wolfgang Denk <wd@denx.de> Signed-off-by: Simon Glass <sjg@chromium.org>
2017-02-06console: Don't enable CONFIG-CONSOLE_MUX, etc. in SPLSimon Glass
CONFIG_CONSOLE_MUX and CONFIG_SYS_CONSOLE_IS_IN_ENV are not applicable for SPL. Update the console code to use CONFIG_IS_ENABLED(), so that these options will be inactive in SPL. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2016-10-23Convert CONFIG_SYS_STDIO_DEREGISTER to KconfigSimon Glass
This converts the following to Kconfig: CONFIG_SYS_STDIO_DEREGISTER This option should never be enabled in SPL, so use CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER) when checking the option. Signed-off-by: Simon Glass <sjg@chromium.org> [trini: Re-sync] Signed-off-by: Tom Rini <trini@konsulko.com>
2016-09-23usb: squash lines for immediate returnMasahiro Yamada
This makes functions much simpler. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2016-04-10usb: kbd: Do not deregister usbkbd twice when using dmHans de Goede
The dm usb_kbd_remove function() will deregister the usb keyboard for us on a "usb reset" / "usb stop" so there is no need to manually call usb_kbd_deregister() in the dm case. This commit removes usb_kbd_deregister() in the dm case fixing the following "usb reset" errors: usb_kbd_remove: warning, ret=-6 device_remove: Device 'usb_kbd' failed to remove, but children are gone Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2016-01-25usb: kbd: Prevent out of bound accessMarek Vasut
Scan code 0x39 is CapsLock, which is not a printable character and thus is not covered by either usb_kbd_numkey_shifted[] or usb_kbd_numkey[]. Fix the scan code check to avoid looking it up in either of the arrays. Signed-off-by: Marek Vasut <marex@denx.de>
2016-01-07dm: usb: Add a remove() method for USB keyboardsSimon Glass
At present USB keyboards are not properly removed with driver model. Add the code to handle this. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de>
2015-12-17usb: kbd: don't use int xfers when polling via ctrl xfersStephen Warren
When CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP is enabled, use a GET_REPORT control transfer to retrieve the initial state of the keyboard. This matches the technique used to poll the keyboard state. This is useful since it eliminates the remaining use of interrupt transfers from the USB keyboard driver, which allows it to work with USB HCD that don't support interrupt transfers. Cc: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Stephen Warren <swarren@nvidia.com>
2015-11-19usb: Avoid open-coded USB constants in usb_kbd.cSimon Glass
Replace the open-coded values with constants to make it clearer what they mean. Signed-off-by: Simon Glass <sjg@chromium.org>
2015-11-19usb: Drop unused code in usb_kbd.cSimon Glass
This was missed in the conversion to driver model. Signed-off-by: Simon Glass <sjg@chromium.org>
2015-11-19Move console definitions into a new console.h fileSimon Glass
The console includes a global variable and several functions that are only used by a small subset of U-Boot files. Before adding more functions, move the definitions into their own header file. Signed-off-by: Simon Glass <sjg@chromium.org>
2015-11-19dm: input: Create a keyboard uclassSimon Glass
Add a uclass for keyboard input, mirroring the existing stdio methods. This is enabled by a new CONFIG_DM_KEYBOARD option. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2015-11-19dm: usb: Add support for USB keyboards with driver modelSimon Glass
Switch USB keyboards over to use driver model instead of scanning with the horrible usb_get_dev_index() function. This involves creating a new uclass for keyboards, although so far there is no API. Signed-off-by: Simon Glass <sjg@chromium.org>
2015-11-05video: Drop DEV_FLAGS_SYSTEM flagBin Meng
DEV_FLAGS_SYSTEM does not have any actual meaning, hence drop it. Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2015-09-11Move ALLOC_CACHE_ALIGN_BUFFER() to the new memalign.h headerSimon Glass
Now that we have a new header file for cache-aligned allocation, we should move the stack-based allocation macro there also. Signed-off-by: Simon Glass <sjg@chromium.org>
2015-07-21dm: usb: Adjust the USB_DEVICE() macro namingSimon Glass
In Linux USB_DEVICE() is used to declare a USB device by vendor/device ID. We should follow the same convention in U-Boot. Rename the existing USB_DEVICE() macro to U_BOOT_USB_DEVICE() and bring in the USB_DEVICE() macro from Linux for use in U-Boot. Signed-off-by: Simon Glass <sjg@chromium.org>
2015-06-19usb: kbd: Disable idle input reports when we do not need themHans de Goede
When we're polling and thus handling key-repeat in software, make sure to disable idle reports, some keyboards may have these enabled by default messing up our software keyrepeat. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2015-05-29usb: kbd: Fix key repeat not always workingHans de Goede
The usb-kbd key repeat code assumes that reports get repeated every 40 ms, this is never true when using CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP, and does not always works for CONFIG_SYS_USB_EVENT_POLL and CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE since not all usb keyboards honor the usb_set_idle() command. For CONFIG_SYS_USB_EVENT_POLL we must use usb_set_idle() since we do a blocking wait for the hid report, so if we do not tell the keyboard to send a hid report every 40ms even if nothing changes then we will block u-boot for 1s (the default u-boot usb interrupt packet timeout). Note that in this case on keyboards which do not support usb_set_idle() we loose and we actually get 1s latencies on other u-boot activities. For the other poll-methods this commit stops using usb_set_idle() and instead repeats the last received hid-report every 40 ms as long as no new hid-report is received. This fixes key-repeat not working at all with CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP and fixes it not working with keyboards which do not implement usb_set_idle() when using CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2015-04-18dm: usb: Support driver model with USB keyboardsSimon Glass
Allow USB keyboards to work with driver model. The main difference is that we can have multiple buses (each with its own device numbering) and each bus must be scanned. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18dm: usb: Split out the keyboard probe into its own functionSimon Glass
Before adding driver model support, split out code from this over-long function. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de>
2015-01-18usb: Fix usb_kbd_deregister when console-muxing is usedHans de Goede
When iomuxing is used we must not only deregister the device with stdio.c, but also remove the reference to the device in the console_devices array used by console-muxing. Add a call to iomux_doenv to usb_kbd_deregister to update console_devices, which will drop the reference. This fixes the console filling with "Failed to enqueue URB to controller" messages after a "usb stop force", or when the USB keyboard is gone after a "usb reset". Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2015-01-18usb: Add an interval parameter to create_int_queueHans de Goede
Currently create_int_queue is only implemented by the ehci code, and that does not honor interrupt intervals, but other drivers which might also want to implement create_int_queue may honor intervals, so add an interval param. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-11-04usb: kbd: Add (optional) support for using an interrupt queue for pollingHans de Goede
Waiting an interrupt packet to complete in usb_kbd_poll_for_event, causes a 40 ms latency for each call to usb_kbd_testc, which is undesirable. Using control messages leads to lower (but still not 0) latency, but some devices do not work well with control messages (e.g. my kvm behaves funny with them). This commit adds support for using the int_queue mechanism which at least the ehci-hcd driver supports. This allows polling with 0 latency, while using interrupt packets. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-11-04usb: kbd: Cache pipe, interval and packetsizeHans de Goede
Instead of looking them up every time we need them. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-11-04usb: kbd: Fix memleak on usb_kbd_deregister()Hans de Goede
Free the keyboard hid-report buffer and private data on deregister. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-11-04usb: kbd: Remove unused usb_kbd_generic_poll functionHans de Goede
This is not used anywhere, so lets remove it. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-10-06usb: kbd: Allow "usb reset" to continue when an usb kbd is usedHans de Goede
Use the new force parameter to make the stdio_deregister succeed, replacing stdin with a nulldev, and assume that the usb keyboard will come back after the reset. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-10-06stdio: Add force parameter to stdio_deregisterHans de Goede
In some cases we really want to move forward with a deregister, add a force parameter to allow this, and replace the dev with a nulldev in this case. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-10-06usb: kbd: Remove check for already being registeredHans de Goede
We now always properly deregister the keyboard before calling drv_usb_kbd_init(), so we can drop the check for already being registered. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-10-06usb: kbd: Do not treat -ENODEV as an error for usb_kbd_deregisterHans de Goede
ENODEV menas no usb keyboard was registered, threat this as a successful usb_kbd_deregister. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-10-06usb: kbd: Fix unaligned buffer usage in usb_kbd_setled()Hans de Goede
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-07-23stdio: Pass device pointer to stdio methodsSimon Glass
At present stdio device functions do not get any clue as to which stdio device is being acted on. Some implementations go to great lengths to work around this, such as defining a whole separate set of functions for each possible device. For driver model we need to associate a stdio_dev with a device. It doesn't seem possible to continue with this work-around approach. Instead, add a stdio_dev pointer to each of the stdio member functions. Note: The serial drivers have the same problem, but it is not strictly necessary to fix that to get driver model running. Also, if we convert serial over to driver model the problem will go away. Code size increases by 244 bytes for Thumb2 and 428 for PowerPC. 22: stdio: Pass device pointer to stdio methods arm: (for 2/2 boards) all +244.0 bss -4.0 text +248.0 powerpc: (for 1/1 boards) all +428.0 text +428.0 Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Marek Vasut <marex@denx.de> Reviewed-by: Marek Vasut <marex@denx.de>