summaryrefslogtreecommitdiff
path: root/common/usb.c
AgeCommit message (Collapse)Author
2016-09-23usb: squash lines for immediate returnMasahiro Yamada
This makes functions much simpler. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2016-06-04usb: move CONFIG_USB_XHCI to Kconfig with renamingMasahiro Yamada
Move CONFIG_USB_XHCI to defconfig files for all boards, renaming it into CONFIG_USB_XHCI_HCD. As commented in the help of "config USB_XHCI" entry, this has been a TODO for a long time; now CONFIG_USB_XHCI_HCD and CONFIG_USB_XHCI have been unified in favor of the former. Note: Some boards define CONFIG_USB_XHCI in their headers without CONFIG_USB, which does not meet the "depends on" in Kconfig. I added CONFIG_USB=y for those boards when converting. Otherwise, they would fail to build. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2016-05-06usb: Assure Get Descriptor request is in separate microframeMarek Vasut
The Kingston DT Ultimate USB 3.0 stick is sensitive to this first Get Descriptor request and if the request is not in a separate microframe, the stick refuses to operate. Add slight delay, which is enough for one microframe to pass on any USB spec revision. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Chin Liang See <clsee@altera.com> Cc: Dinh Nguyen <dinguyen@opensource.altera.com> Cc: Hans de Goede <hdegoede@redhat.com> Cc: Stefan Roese <sr@denx.de> Cc: Stephen Warren <swarren@nvidia.com>
2016-05-06usb: Wait after sending Set Configuration requestMarek Vasut
Some devices, like the SanDisk Cruzer Pop need some time to process the Set Configuration request, so wait a little until they are ready. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Chin Liang See <clsee@altera.com> Cc: Dinh Nguyen <dinguyen@opensource.altera.com> Cc: Hans de Goede <hdegoede@redhat.com> Cc: Stefan Roese <sr@denx.de> Cc: Stephen Warren <swarren@nvidia.com>
2016-05-06usb: Don't init pointer to zero, but NULLMarek Vasut
The pointer should always be inited to NULL, not zero (0). These are two different things and not necessarily equal. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Chin Liang See <clsee@altera.com> Cc: Dinh Nguyen <dinguyen@opensource.altera.com> Cc: Hans de Goede <hdegoede@redhat.com> Cc: Stefan Roese <sr@denx.de> Cc: Stephen Warren <swarren@nvidia.com>
2016-03-22Fix spelling of "transferred".Vagrant Cascadian
Signed-off-by: Vagrant Cascadian <vagrant@debian.org> Acked-by: Marek Vasut <marex@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2016-03-20usb: Don't reset the USB hub a 2nd timeStefan Roese
Debugging has shown, that all USB hubs are being reset twice while USB scanning. This introduces additional delays and makes USB scanning even more slow. Testing has shown that this 2nd USB hub reset doesn't seem to be necessary. This patch now removes this 2nd USB hub reset. Resulting in faster USB scan time. Here the current numbers: Without this patch: => time usb start starting USB... USB0: USB EHCI 1.00 scanning bus 0 for devices... 9 USB Device(s) found time: 24.003 seconds With this patch: => time usb start starting USB... USB0: USB EHCI 1.00 scanning bus 0 for devices... 9 USB Device(s) found time: 20.392 seconds So ~3.6 seconds of USB scanning time reduction. Signed-off-by: Stefan Roese <sr@denx.de> Cc: Simon Glass <sjg@chromium.org> Acked-by: Hans de Goede <hdegoede@redhat.com> Tested-by: Stephen Warren <swarren@nvidia.com> Cc: Marek Vasut <marex@denx.de>
2016-01-16common: usb: fix checking conditionPeng Fan
We support max USB_MAXENDPOINTS, so need to use "epno >= USB_MAXENDPOINTS", but not "epno > USB_MAXENDPOINTS". If use ">", we may exceeds the array of if_desc->ep_desc. Signed-off-by: Peng Fan <peng.fan@nxp.com> Cc: Simon Glass <sjg@chromium.org> Cc: Hans de Goede <hdegoede@redhat.com> Cc: Marek Vasut <marex@denx.de> Cc: Paul Kocialkowski <contact@paulk.fr> Cc: "Stefan Brüns" <stefan.bruens@rwth-aachen.de> Cc: Vincent Palatin <vpalatin@chromium.org>
2015-12-31usb: Move determination of TT hub address/port into separate functionStefan Brüns
Start split and complete split tokens need the hub address and the downstream port of the first HS hub (device view). The core of the function was duplicated in both host/ehci_hcd and musb-new/usb-compat.h. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Marek Vasut <marex@denx.de> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Tested-by: Hans de Goede <hdegoede@redhat.com>
2015-12-31usb: Alloc buffer for USB descriptor dynamicallyStefan Brüns
The configuration descriptor includes all interface, endpoint and auxiliary descriptors (e.g. report, union) so 512 bytes may not be enough. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Reviewed-by: Marek Vasut <marex@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
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-21usb: Add an usb_device parameter to usb_reset_root_portHans de Goede
Add an usb_device parameter to usb_reset_root_port so that it knows which root-port it is resetting. This is necessary for proper device-model support for usb_reset_root_port. Also remove a duplicate declaration of usb_reset_root_port() from usb.h . Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Simon Glass <sjg@chromium.org>
2015-07-21usb: Pass device instead of portnr to usb_legacy_port_resetHans de Goede
Pass the usb_device instead of the portnr to usb_legacy_port_reset and rename it to usb_hub_port_reset as there is nothing legacy about it. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Simon Glass <sjg@chromium.org>
2015-07-21usb: usb_setup_device: Drop unneeded portnr function argumentHans de Goede
Drop the unneeded portnr function argument, the portnr is part of the usb_device struct which is passed via the dev argument. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Simon Glass <sjg@chromium.org>
2015-07-21usb: Drop device-model specific copy of usb_legacy_port_resetHans de Goede
The device-model usb_legacy_port_reset function calls the device-model usb_port_reset function which is a 1 on 1 copy of the non dm usb_legacy_port_reset and this is the only use of usb_port_reset in all of u-boot. Drop both, and alway use the usb_legacy_port_reset() version in common/usb.c . Also while at it make it static as it is only used in common/usb.c . Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Simon Glass <sjg@chromium.org>
2015-05-29usb: Remove unused variable in usb_setup_descriptor()Hans de Goede
The compiler did not catch this as it was marked __maybe_unused. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2015-05-14usb: add device connection/disconnection detectionVincent Palatin
Provide a function to detect USB device insertion/removal in order to avoid having to do USB enumeration in a tight loop when trying to detect peripheral hotplugging. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Stefan Reinauer <reinauer@chromium.org> Tested-by: Stefan Reinauer <reinauer@chromium.org> Signed-off-by: Simon Glass <sjg@chromium.org>
2015-05-14usb: usb_control_msg() propagate controller error codeHans de Goede
Propagate the error returned by submit_control_msg() rather then always returning -EIO when the hcd code indicates an error. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2015-05-06usb: Fix maxpacketsize for first descriptor read for low-speed usb devsHans de Goede
This fixes descriptor reading of lowspeed devices through ohci not working. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Marek Vasut <marex@denx.de>
2015-04-18dm: usb: Convert core usb.c file to support driver modelSimon Glass
Add the required #ifdefs and remove unwanted data structures so that the USB uclass will be able to use this file. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18dm: usb: Complete the splitting up of usb_new_device()Simon Glass
This function now calls usb_setup_device() to set up the device and usb_hub_probe() to check if it is a hub. The XHCI special case is now a parameter to usb_setup_device(). The latter will be used by the USB uclass when it is added, since it does not rely on any CONFIGs or legacy data structures. Signed-off-by: Simon Glass <sjg@chromium.org> Bug-fixes for descriptor reading and usb_new_device() return value Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Marek Vasut <marex@denx.de> Tested-by: Tom Rini <trini@konsulko.com>
2015-04-18dm: usb: Split out more code from usb_new_device()Simon Glass
Move the code that sets up the device with a new address into its own function, usb_prepare_device(). Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18dm: usb: Move descriptor setup code into its own functionSimon Glass
usb_new_device() is far too long and does far too much. As a first step, move the code that does initial setup and reads a descriptor into its own function called usb_setup_descriptor(). For XHCI the init order is different - we set up the device but don't actually read the descriptor until after we set an address. Support this option as a parameter to usb_setup_descriptor(). Avoid changing this torturous code more than necessary to make it easy to review. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18dm: usb: Refactor port resetsSimon Glass
Move the port reset code into its own function. Rename usb_hub_reset() to indicate that is is now a legacy function. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18dm: usb: Drop the legacy USB init sequenceSimon Glass
This CONFIG is not used anywhere in U-Boot, so drop it. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Marek Vasut <marex@denx.de>
2015-04-18dm: usb: Adjust usb_alloc_new_device() to return an errorSimon Glass
This function returns NULL on error at present. Adjust it so that we can return a real error, as is needed with driver model. Also improve the error handling in its caller, usb_hub_port_connect_change(), and adjust the code order to prepare for driver model. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-14common: cmd_dfu: invoke board_usb_cleanup() for cleaning upKishon Vijay Abraham I
Invoked board_usb_cleanup for cleaning up initialized USB. It will be invoked if the user enterts ctrl-C. Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2015-04-14usb: fix first descriptor fetch error handlingStephen Warren
When fetching the first descriptor from a new device, only validate that we received at least 8 bytes, not that we received the entire descriptor. The reasoning is: - The code only uses fields in the first 8 bytes, so that's all we need to have fetched at this stage. - The smallest maxpacket size is 8 bytes. Before we know the actual maxpacket the device uses, the USB controller may only accept a single packet (see the DWC2 note in the comment added in the commit). Consequently we are only guaranteed to receive 1 packet (at least 8 bytes) even in a non-error case. Fixes: 1a7758044b04 ("usb: Early failure when the first descriptor read fails or is invalid") Cc: Paul Kocialkowski <contact@paulk.fr> Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
2015-04-14usb: Early failure when the first descriptor read fails or is invalidPaul Kocialkowski
This may happen when using an USB1 device on a controller that only supports USB2 (e.g. EHCI). Reading the first descriptor will fail (read 0 byte), so we can abort the process at this point instead of failing later and wasting time. Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
2015-04-14usb: Check usb_new_device for failurePaul Kocialkowski
This checks that a new USB device is correctly initialized and frees it if not. In addition, this doesn't report that USB was started when no device was found. Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
2015-04-14usb: usb_new_device return codes consistencyPaul Kocialkowski
This makes use of errno return codes for representing error codes in a unified way. Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
2015-01-18musb-new: Fix reset sequence when in host modeHans de Goede
This commit fixes a number of issues with the reset sequence of musb-new in host mode: 1) Our usb device probe relies on a second device reset being done after the first descriptors read. Factor the musb reset code into a usb_reset_root_port function (and add this as an empty define for other controllers), and call this when a device has no parent. 2) Just like with normal usb controllers there needs to be a delay after reset, for normal usb controllers, this is handled in hub_port_reset, add a delay to usb_reset_root_port. 3) Sync the musb reset sequence with the upstream kernel, clear all bits of power except bits 4-7, and increase the time reset is asserted to 50 ms. With these fixes an usb keyboard I have now always enumerates properly, where as earlier it would only enumerare properly once every 5 tries. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2015-01-18usb: Do not log an error when no devices is plugged into a root-hub-less hcdHans de Goede
Before this commit u-boot would print the following on boot with musb and no usb device plugged in: starting USB... USB0: Port not available. USB error: all controllers failed lowlevel init This commit changes this to: starting USB... USB0: Port not available. Which is the correct thing to do since the low-level init went fine. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-12-08Replace <compiler.h> with <linux/compiler.h>Masahiro Yamada
Including <linux/compiler.h> is enough for general use. Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
2014-11-04usb: Remove unnecessary portnr lookup from usb_new_deviceHans de Goede
If the device has a parent, it is instantiated from usb_hub_port_connect_change and the portnr is right there in dev->portnr, so there is no need for this whole dance to look it up. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-08-29usb: Handle -ENODEV from usb_lowlevel_init()Marek Vasut
As we support both Host and Device mode operation, an OTG controller can return -ENODEV on a port which it found to be in Device mode during Host mode scan for devices. In case -ENODEV is returned, print that the port is not available and continue instead of screaming a bloody error message. Signed-off-by: Marek Vasut <marex@denx.de>
2013-10-20usb: add enum usb_init_type parameter to usb_lowlevel_initTroy Kisky
This parameter will later be used to verify OTG ports. Signed-off-by: Troy Kisky <troy.kisky@boundarydevices.com>
2013-10-20usb: rename board_usb_init_type to usb_init_typeTroy Kisky
This will be used by usb_lowlevel_init so it will no longer be used by only board specific functions. Move definition of enum usb_init_type higher in file so that it will be available for usb_low_level_init. Signed-off-by: Troy Kisky <troy.kisky@boundarydevices.com>
2013-10-20usb: new board-specific USB init interfaceMateusz Zalega
This commit unifies board-specific USB initialization implementations under one symbol (usb_board_init), declaration of which is available in usb.h. New API allows selective initialization of USB controllers whenever needed. Signed-off-by: Mateusz Zalega <m.zalega@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com> Cc: Marek Vasut <marex@denx.de> Cc: Lukasz Majewski <l.majewski@samsung.com>
2013-10-20USB: xHCI: Add stack support for xHCIVivek Gautam
This adds stack layer for eXtensible Host Controller Interface which facilitates use of USB 3.0 in host mode. Adapting xHCI host controller driver in linux-kernel by Sarah Sharp to needs in u-boot. Initial porting from Linux kernel version 3.4, with following top commit history of drivers/usb/host/xhci* : cf84055 xHCI: Cleanup isoc transfer ring when TD length mismatch found This adds the basic xHCI host controller driver with bare minimum features: - Control/Bulk transfer support has been added with required infrastructure for necessary xHC data structures. - Stream protocol hasn't been supported yet. - No support for quirky devices has been added. Signed-off-by: Vikas C Sajjan <vikas.sajjan@samsung.com> Signed-off-by: Julius Werner <jwerner@chromium.org> Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com> Cc: Simon Glass <sjg@chromium.org> Cc: Minkyu Kang <mk7.kang@samsung.com> Cc: Dan Murphy <dmurphy@ti.com> Cc: Marek Vasut <marex@denx.de>
2013-08-26usb: Use well-known descriptor sizes when parsing configurationJulius Werner
The existing USB configuration parsing code relies on the descriptors' own length values when reading through the configuration blob. Since the size of those descriptors is always well-defined, we should rather use the known sizes instead of trusting device-provided values to be correct. Also adds some safety to potential out-of-order descriptors. Change-Id: I16f69dfdd6793aa0fe930b5148d4521f3e5c3090 Signed-off-by: Julius Werner <jwerner@chromium.org>
2013-07-24Add GPL-2.0+ SPDX-License-Identifier to source filesWolfgang Denk
Signed-off-by: Wolfgang Denk <wd@denx.de> [trini: Fixup common/cmd_io.c] Signed-off-by: Tom Rini <trini@ti.com>
2013-05-05USB: SS: Add support for Super Speed USB interfaceVivek Gautam
This adds usb framework support for super-speed usb, which will further facilitate to add stack support for xHCI. Signed-off-by: Vikas C Sajjan <vikas.sajjan@samsung.com> Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
2013-05-05usb: Update device class in usb device's descriptorVivek Gautam
Fetch the device class into usb device's dwcriptors, so that the host controller's driver can use this info to differentiate between HUB and DEVICE. Signed-off-by: Amar <amarendra.xt@samsung.com>
2013-05-05USB: Some cleanup prior to USB 3.0 interface additionVivek Gautam
Some cleanup in usb framework, nothing much on feature side. Signed-off-by: Vikas C Sajjan <vikas.sajjan@samsung.com> Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
2013-05-05usb: common: Weed out USB_**_PRINTFs from usb frameworkVivek Gautam
USB_PRINTF, USB_HUB_PRINTF, USB_STOR_PRINTF, USB_KBD_PRINTF are nothing but conditional debug prints, depending on DEBUG. So better remove them and use debug() simply. Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
2012-12-17usb: Clean up newly allocated device nodes in case of configuration failureMilind Choudhary
If probe of a newly connected device fails for some reason, clean up the allocated entry in usb_dev array. Signed-off-by: Milind Choudhary <milindc@codeaurora.org> Signed-off-by: Simon Glass <sjg@chromium.org>
2012-11-20usb: use linux/usb/ch9.h instead of usbdescriptors.hIlya Yanok
Linux usb/ch9.h seems to have all the same information (and more) as usbdescriptors.h so use the former instead of the later one. As a consequense of this change USB_SPEED_* values don't correspond directly to EHCI speed encoding anymore, I've added necessary recoding in EHCI driver. Also there is no point to put speed into pipe anymore so it's removed and a bunch of host drivers fixed to look at usb_device->speed instead. Old usbdescriptors.h included is not removed as it seems to be used by old USB device code. This makes usb.h and usbdevice.h incompatible. Fortunately the only place that tries to include both are the old MUSB code and it needs usb.h only for USB_DMA_MINALIGN used in aligned attribute on musb_regs structure but this attribute seems to be unneeded (old MUSB code doesn't support any DMA at all). Signed-off-by: Ilya Yanok <ilya.yanok@cogentembedded.com>
2012-10-22usb: fallback safely when a configuration descriptor is too largeVincent Palatin
When a USB configuration descriptor was larger than our USB buffer (512 bytes), we were skipping the full descriptor reading but then we were still parsing and using it, triggering memory corruptions. Now in that case, it just skips this device enumeration and displays the appropriate message to the user, so he can fix the buffer if he wants. This bug was triggered by some UVC webcams which have very large configuration descriptors (e.g. a couple of kB) describing all their supported video encodings. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> Acked-by: Simon Glass <sjg@chromium.org>
2012-10-15usb: add support for multiple usb controllersLucas Stach
Allows to initialize more than one USB controller at once. v2: print message when controller stop fails Signed-off-by: Lucas Stach <dev@lynxeye.de> Reviewed-by: Marek Vasut <marex@denx.de>