summaryrefslogtreecommitdiffstats
path: root/common/usb.c
Commit message (Collapse)AuthorAgeFilesLines
* Move ALLOC_CACHE_ALIGN_BUFFER() to the new memalign.h headerSimon Glass2015-09-111-0/+1
| | | | | | | 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>
* usb: Add an usb_device parameter to usb_reset_root_portHans de Goede2015-07-211-1/+1
| | | | | | | | | | | 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>
* usb: Pass device instead of portnr to usb_legacy_port_resetHans de Goede2015-07-211-4/+4
| | | | | | | | 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>
* usb: usb_setup_device: Drop unneeded portnr function argumentHans de Goede2015-07-211-5/+5
| | | | | | | | 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>
* usb: Drop device-model specific copy of usb_legacy_port_resetHans de Goede2015-07-211-3/+1
| | | | | | | | | | | | | | | 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>
* usb: Remove unused variable in usb_setup_descriptor()Hans de Goede2015-05-291-2/+0
| | | | | | The compiler did not catch this as it was marked __maybe_unused. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* usb: add device connection/disconnection detectionVincent Palatin2015-05-141-0/+26
| | | | | | | | | | | | 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>
* usb: usb_control_msg() propagate controller error codeHans de Goede2015-05-141-2/+4
| | | | | | | 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>
* usb: Fix maxpacketsize for first descriptor read for low-speed usb devsHans de Goede2015-05-061-6/+11
| | | | | | | 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>
* dm: usb: Convert core usb.c file to support driver modelSimon Glass2015-04-181-6/+25
| | | | | | | | 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>
* dm: usb: Complete the splitting up of usb_new_device()Simon Glass2015-04-181-62/+95
| | | | | | | | | | | | | | 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>
* dm: usb: Split out more code from usb_new_device()Simon Glass2015-04-181-30/+42
| | | | | | | | 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>
* dm: usb: Move descriptor setup code into its own functionSimon Glass2015-04-181-65/+82
| | | | | | | | | | | | | | | | 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>
* dm: usb: Refactor port resetsSimon Glass2015-04-181-14/+26
| | | | | | | | 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>
* dm: usb: Drop the legacy USB init sequenceSimon Glass2015-04-181-22/+4
| | | | | | | 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>
* dm: usb: Adjust usb_alloc_new_device() to return an errorSimon Glass2015-04-181-10/+9
| | | | | | | | | | 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>
* common: cmd_dfu: invoke board_usb_cleanup() for cleaning upKishon Vijay Abraham I2015-04-141-0/+6
| | | | | | | | 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>
* usb: fix first descriptor fetch error handlingStephen Warren2015-04-141-1/+16
| | | | | | | | | | | | | | | | | | 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>
* usb: Early failure when the first descriptor read fails or is invalidPaul Kocialkowski2015-04-141-1/+4
| | | | | | | | 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>
* usb: Check usb_new_device for failurePaul Kocialkowski2015-04-141-4/+10
| | | | | | | 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>
* usb: usb_new_device return codes consistencyPaul Kocialkowski2015-04-141-29/+29
| | | | | | | This makes use of errno return codes for representing error codes in a unified way. Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
* musb-new: Fix reset sequence when in host modeHans de Goede2015-01-181-0/+2
| | | | | | | | | | | | | | | | | | | | | | 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>
* usb: Do not log an error when no devices is plugged into a root-hub-less hcdHans de Goede2015-01-181-4/+5
| | | | | | | | | | | | | | | | | | 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>
* Replace <compiler.h> with <linux/compiler.h>Masahiro Yamada2014-12-081-1/+0
| | | | | | Including <linux/compiler.h> is enough for general use. Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
* usb: Remove unnecessary portnr lookup from usb_new_deviceHans de Goede2014-11-041-17/+2
| | | | | | | | 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>
* usb: Handle -ENODEV from usb_lowlevel_init()Marek Vasut2014-08-291-2/+9
| | | | | | | | | | 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>
* usb: add enum usb_init_type parameter to usb_lowlevel_initTroy Kisky2013-10-201-1/+1
| | | | | | This parameter will later be used to verify OTG ports. Signed-off-by: Troy Kisky <troy.kisky@boundarydevices.com>
* usb: rename board_usb_init_type to usb_init_typeTroy Kisky2013-10-201-1/+1
| | | | | | | | | | 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>
* usb: new board-specific USB init interfaceMateusz Zalega2013-10-201-0/+6
| | | | | | | | | | | | | | 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>
* USB: xHCI: Add stack support for xHCIVivek Gautam2013-10-201-2/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* usb: Use well-known descriptor sizes when parsing configurationJulius Werner2013-08-261-16/+71
| | | | | | | | | | | 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>
* Add GPL-2.0+ SPDX-License-Identifier to source filesWolfgang Denk2013-07-241-19/+1
| | | | | | Signed-off-by: Wolfgang Denk <wd@denx.de> [trini: Fixup common/cmd_io.c] Signed-off-by: Tom Rini <trini@ti.com>
* USB: SS: Add support for Super Speed USB interfaceVivek Gautam2013-05-051-0/+5
| | | | | | | | 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>
* usb: Update device class in usb device's descriptorVivek Gautam2013-05-051-0/+5
| | | | | | | | 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>
* USB: Some cleanup prior to USB 3.0 interface additionVivek Gautam2013-05-051-8/+13
| | | | | | | 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>
* usb: common: Weed out USB_**_PRINTFs from usb frameworkVivek Gautam2013-05-051-48/+37
| | | | | | | | 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>
* usb: Clean up newly allocated device nodes in case of configuration failureMilind Choudhary2012-12-171-0/+12
| | | | | | | | 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>
* usb: use linux/usb/ch9.h instead of usbdescriptors.hIlya Yanok2012-11-201-2/+2
| | | | | | | | | | | | | | | | | | | | | | 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>
* usb: fallback safely when a configuration descriptor is too largeVincent Palatin2012-10-221-3/+9
| | | | | | | | | | | | | | | 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>
* usb: add support for multiple usb controllersLucas Stach2012-10-151-50/+56
| | | | | | | | | 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>
* usb: lowlevel interface change to support multiple controllersLucas Stach2012-10-151-4/+6
| | | | | | | | | | | Carry an index in the lowlevel usb functions to make specify the respective usb controller. Also pass through an controller struct from lowlevel_init to the creation of the root usb device of this controller. Signed-off-by: Lucas Stach <dev@lynxeye.de> Reviewed-by: Marek Vasut <marex@denx.de>
* usb: check return value of submit_{control, bulk}_msgIlya Yanok2012-07-181-2/+4
| | | | | | | Return values of submit_{control,bulk}_msg() functions should be checked to detect possible error. Signed-off-by: Ilya Yanok <ilya.yanok@cogentembedded.com>
* usb: pass cache-aligned buffer to usb_get_descriptor()Ilya Yanok2012-07-181-2/+4
| | | | | | | usb_get_descriptor passes it's buffer argument directly to usb_control_msg() so it has to be properly aligned/padded. Signed-off-by: Ilya Yanok <ilya.yanok@cogentembedded.com>
* USB: Align buffers at cachelinePuneet Saxena2012-05-201-11/+11
| | | | | | | | | | | | This avoids cache-alignment warnings shown in console when a usb command is entered. Whenever X bytes of unaligned buffer is invalidated, arm core invalidates X + Y bytes as per the cache line size and throws these warnings. Signed-off-by: Puneet Saxena <puneets@nvidia.com> Signed-off-by: Marek Vasut <marex@denx.de>
* usb: use noinline defineMike Frysinger2012-05-201-1/+2
| | | | | | | | | | Building usb for Blackfin boards fails as we get linux/compiler.h included which expands the "noinline" inside of the attribute and we get attribute(attribute(noinline)). Explicitly use the helper define to avoid this. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* usb: replace wait_ms() with mdelay()Mike Frysinger2012-03-191-13/+3
| | | | | | | | | | | | | | | | | | | | | | | Common code has a mdelay() func, so use that instead of the usb-specific wait_ms() func. This also fixes the build errors: ohci-hcd.c: In function 'submit_common_msg': /usr/local/src/u-boot/blackfin/include/usb.h:202:44: sorry, unimplemented: inlining failed in call to 'wait_ms': function body not available ohci-hcd.c:1519:9: sorry, unimplemented: called from here /usr/local/src/u-boot/blackfin/include/usb.h:202:44: sorry, unimplemented: inlining failed in call to 'wait_ms': function body not available ohci-hcd.c:1816:10: sorry, unimplemented: called from here /usr/local/src/u-boot/blackfin/include/usb.h:202:44: sorry, unimplemented: inlining failed in call to 'wait_ms': function body not available ohci-hcd.c:1827:10: sorry, unimplemented: called from here /usr/local/src/u-boot/blackfin/include/usb.h:202:44: sorry, unimplemented: inlining failed in call to 'wait_ms': function body not available ohci-hcd.c:1844:10: sorry, unimplemented: called from here /usr/local/src/u-boot/blackfin/include/usb.h:202:44: sorry, unimplemented: inlining failed in call to 'wait_ms': function body not available ohci-hcd.c:1563:11: sorry, unimplemented: called from here /usr/local/src/u-boot/blackfin/include/usb.h:202:44: sorry, unimplemented: inlining failed in call to 'wait_ms': function body not available ohci-hcd.c:1583:9: sorry, unimplemented: called from here make[1]: *** [ohci-hcd.o] Error 1 Signed-off-by: Mike Frysinger <vapier@gentoo.org> Acked-by: Marek Vasut <marex@denx.de>
* USB: Make struct devrequest setup_packet localMarek Vasut2012-03-031-1/+2
| | | | | | Signed-off-by: Marek Vasut <marek.vasut@gmail.com> Cc: Remy Bohmer <linux@bohmer.net> Acked-by: Mike Frysinger <vapier@gentoo.org>
* USB: Separate out USB hub driverMarek Vasut2012-03-031-430/+2
| | | | | | Signed-off-by: Marek Vasut <marek.vasut@gmail.com> Cc: Remy Bohmer <linux@bohmer.net> Acked-by: Mike Frysinger <vapier@gentoo.org>
* USB: Staticize internal functionsMarek Vasut2012-03-031-22/+23
| | | | | | Signed-off-by: Marek Vasut <marek.vasut@gmail.com> Cc: Remy Bohmer <linux@bohmer.net> Acked-by: Mike Frysinger <vapier@gentoo.org>
* USB: Use (get|put)_unaligned for accessing wMaxPacketSizeTom Rini2011-12-161-8/+19
| | | | | | | | | | | | | | | | | | | | | | In 9792987721c7980453fe6447c3fa6593b44f8458 Stefan describes a usecase where the previous behavior of leaving wMaxPacketSize be unaligned caused fatal problems. The initial fix for this problem was incomplete however as it showed another cases of non-aligned access that previously worked implicitly. This switches to making sure that all access of wMaxPacketSize are done via (get|put)_unaligned. In order to maintain a level of readability to the code in some cases we now use a variable for the value of wMaxPacketSize and in others, a macro. Cc: Minkyu Kang <mk7.kang@samsung.com> Cc: Remy Bohmer <linux@bohmer.net> OpenRISC: Tested-by: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi> Beagleboard xM, Pandaboard run-tested, s5p_goni build-tested. Signed-off-by: Tom Rini <trini@ti.com>
OpenPOWER on IntegriCloud