summaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/usb.c
Commit message (Collapse)AuthorAgeFilesLines
* usb: print number of skipped OTG controllers when scanningAhmad Fatoum2024-02-291-0/+14
| | | | | | | | | | | | I often get confused by running usb and wondering why devices behind unconfigured OTG controllers are not enumerated. Improve the user experience by printing a message when doing a USB scan while some OTG controllers are not yet configured (i.e. the otg.mode device parameter hasn't been set to "peripheral" or "host"). Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240228160518.1589193-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: core: replace calls to strerror with %pe format specifierAhmad Fatoum2024-02-201-3/+3
| | | | | | | | | | printf(), and by extension dev_err(), already has built-in support for formatting error codes, so make use of that instead of manual use of strerror(). Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240219172108.3780861-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: make sure dma buffers are properly allocatedDenis Orlov2023-06-301-6/+10
| | | | | | | | | | | | | When we are doing dma_map/unmap we will end up clearing caches. As we can only do that with the granularity of a cache line, we must ensure that the corresponding buffers are properly aligned, as otherwise we may accidentally overwrite some data that happens to reside in the same cache line. This is exactly what dma_alloc() is for, so use that for buffers which we are going to map for dma. Signed-off-by: Denis Orlov <denorl2009@gmail.com> Link: https://lore.barebox.org/20230629195718.14416-3-denorl2009@gmail.com Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: move include files to place where Linux has themSascha Hauer2023-03-201-2/+2
| | | | | | | | | For easier patch merging and comparison with Linux move the usb gadget files to where Linux has them. For now do a plain git mv include/usb include/linux/usb, eventhough there might be some files which are purely barebox specific. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: misc: add support for new OF onboard hub bindingAhmad Fatoum2023-02-211-0/+2
| | | | | | | | | | | | The new binding allows describing hubs that lacks a control bus (e.g. I2C) in the DT and thus replaces the ugly hack of specifying USB hub resets as gpio-hogs. It's already in use for boards we support, like the STM32MP13/5 Discovery kits and will be useful for the i.MX8MP Debix board, so port over the driver from Linux. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230217202620.2882141-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct driver_d to driverSascha Hauer2023-01-101-1/+1
| | | | | | | | | | | The '_d' suffix was originally meant to distinguish barebox struct names from Linux struct names. struct driver doesn't exist in Linux, so we can rename it and remove the meaningless suffix. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-4-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-4/+4
| | | | | | | | | | | | | The '_d' suffix was originally introduced in case we want to import Linux struct device as a separate struct into barebox. Over time it became clear that this won't happen, instead barebox struct device_d is basically the same as Linux struct device. Rename the struct name accordingly to make porting Linux code easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: have usb_rescan return count of enumerated devicesAhmad Fatoum2022-10-041-1/+3
| | | | | | | | | | | | | Some USB mass storage devices can take a comparatively long time after vbus is applied until they can be enumerated. Board code can reissue usb_rescan() to retry enumeration at a later time. It's useful for board code to check whether any new devices have been detected by a usb_rescan() call. To facilitate this, have usb_rescan() return the number of devices found in addition to printing it to the log. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220929100502.895553-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: Add functions to free devicesSascha Hauer2022-02-081-0/+1
| | | | | | | | | | | | | | | | | struct device_d has some dynamically allocated members, namely .name and .unique_name. These are normally not freed when a device is freed. Add two functions to free these resources. free_device_res() only frees the allocated members, but not the device itself. This is suitable for cases where the device is embedded in another struct. free_device() frees the allocated members along with the device itself. This can be called when the device itself has been directly allocated. Some users which should use these functions are also fixed in this patch. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20220207094953.949868-5-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers: add missing SPDX-License-IdentifierAhmad Fatoum2021-11-011-12/+1
| | | | | | | | | | | | | | | | | | | | This adds the suitable SPDX-License-Identifier to all files in drivers/ that previously lacked one. To aid manual inspection, following heuristics can be used: * No changes outside of comments/whitespace: git show -U0 HEAD | rg -v '^(@@|diff|index)|[-+]([-+]|//|#|[\s/]\*)' * -or-later come in pairs: git show --inter-hunk-context=19 HEAD | \ perl -0777 -F'/^@/gm' -ne 'for (@F) { @m = /later/g; print if @m & 1 }' Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20211030175632.2276077-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: add fallback ->detect method for USB host driversAhmad Fatoum2021-02-011-0/+14
| | | | | | | | | | We already maintain a list of USB host controllers, so we can use that to implement a generic detect callback. Currently, all drivers define their own, which uses driver-specific means to arrive at the struct usb_host and then call usb_host_detect(). Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Fix initial max packet sizeSascha Hauer2020-10-271-3/+5
| | | | | | | | | In case the USB device is a full speed device we have to set dev->epmaxpacketin[0] and dev->epmaxpacketout[0] before doing a get_descriptor_len() because otherwise it's unset during that call. Fixes: 6d1d95a386 ("usb: factor out a usb_setup_descriptor() function") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Add a slice to usb host controllersSascha Hauer2020-08-191-5/+7
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: remove references to CREDITSUwe Kleine-König2020-04-271-3/+0
| | | | | | | | The CREDITS file was removed from barebox in 2015 by commit 6570288f2d97 ("Remove the CREDITS file"). Remove references to it from several files. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Add super speed supportSascha Hauer2020-03-261-5/+20
| | | | | | | This adds the missing bits and pieces to add super speed support to the USB stack. It is based on the corresponding U-Boot code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: factor out a usb_setup_descriptor() functionSascha Hauer2020-03-261-52/+103
| | | | | | | | | | | | | | | | | | | | This factors out a usb_setup_descriptor() function with the goal to make the code better comparable to the corresponding U-Boot code. This also incorporates this U-Boot commit: | commit 2b338ef41127351089254b748de5cefd95c3e800 | Author: Hans de Goede <hdegoede@redhat.com> | Date: Tue May 5 23:56:04 2015 +0200 | | usb: Fix maxpacketsize for first descriptor read for low-speed usb devs | | 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> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: remove unnecessary variableSascha Hauer2020-03-201-5/+3
| | | | | | | | "tmp" is only used to store the size of the descriptor. The name is not very meaningful and "tmp" is not even used everywhere it could be used. Just replace by using sizeof() directly where needed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Assign dev_index onceSascha Hauer2020-03-201-10/+4
| | | | | | | | | dev->devnum is set once in usb_alloc_new_device(), set to 0 again later in usb_new_device() and then set back to the original value. This seems unnecessary, just set devnum once right before calling usb_set_address() on the device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: support set hub depth request for USB 3.0 hubsSascha Hauer2020-03-201-0/+3
| | | | | | | | | | | | | | | | | | | | | | | This is an adoption of U-Boot commit bbc6f06c0031249bf1983b875e54cb7549bafe60: | commit bbc6f06c0031249bf1983b875e54cb7549bafe60 | Author: Bin Meng <bmeng.cn@gmail.com> | Date: Wed Jul 19 21:51:13 2017 +0800 | | usb: hub: Support 'set hub depth' request for USB 3.0 hubs | | USB 3.0 hub uses a hub depth value multiplied by four as an offset | into the 'route string' to locate the bits it uses to determine the | downstream port number. We shall set the hub depth value of a USB | 3.0 hub after it is configured. | | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | Reviewed-by: Simon Glass <sjg@chromium.org> In this patch we also support recording the depth of a hub in struct usb_device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: host: make init hook optionalSascha Hauer2020-03-201-3/+5
| | | | | | | For controllers which do everything relevant during probe time make the init hook optional. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Use dev_*Sascha Hauer2020-03-201-25/+25
| | | | | | | Give the USB messages some context by using dev_* functions rather than printf()/debug(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Set new USB device name earlierSascha Hauer2020-03-201-9/+8
| | | | | | | in usb_new_device() set the device name as early as possible to let dev_* functions print a meaningful name. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: hub: do not reset devices twiceSascha Hauer2020-03-201-11/+0
| | | | | | | U-Boot has this since 3ed9eb93c2 ("usb: Don't reset the USB hub a 2nd time"), so do the same for barebox. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Forward error code from usb_set_configurationSascha Hauer2019-12-201-4/+6
| | | | | | | Instead of returning -1 forward the error code and take the opportunity to print the error string. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Make timeout unit clearSascha Hauer2019-12-201-4/+4
| | | | | | | The usb_*_msg() functions take a timeout parameter. Make clear which unit is expected by adding a _ms suffix to the variable name. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Drop usb_disable_asynch()Andrey Smirnov2019-03-111-21/+3
| | | | | | | | | | There are no users of usb_control_msg() in the codebase that pass timeout of 0, so it doesn't look like usb_disable_asynch() has any effect on USB operation. Drop that function and remove all of its uses to simplify things. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/usb'Sascha Hauer2018-11-091-0/+5
|\
| * usb: Add usb_unregister_host()Sascha Hauer2018-10-261-0/+5
| | | | | | | | | | | | | | | | We have usb_register_host() which puts a new host on the list of hosts we should also have the opposite which removes the host from the list again. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | drivers: Introduce dev_set_name()Andrey Smirnov2018-10-181-2/+3
|/ | | | | | | | Introduce dev_set_name() in order to hide implementation details of setting device's name so it'd be easier to change it. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* USB: host: hub: Adjust device speed after every port resetAndrey Smirnov2018-08-291-2/+1
| | | | | | | | | | | | | | | | | | | | | To account for the possibility of a device coming out of second reset operating at different speed compared to first, move the code that stores device speed to be a part of hub_port_reset(). This way any speed change happening as a result of port reset could be accounted for. The above behaviour was observed on i.MX51 ZII RDU1, on USBH2 port connected to SMSC2660 USB Hub/SD card reader. For reasons unclear, first reset would put it into Full Speed mode whereas second would result in switch to High Speed. Artifically disabling second reset would result in the device operating at Full Speed. Not doing second speed adjustement on that board result would result in un-processed control transfer and failure to execute usb_set_address(). Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* param: make parameter functions more consistentSascha Hauer2017-04-111-8/+8
| | | | | | | | | | | | | | | | | | | | | | This patch creates a consitent set of device parameter functions. With this we have: dev_add_param_<type><access> "type" is one of: int32, uint32, int64, uint64, string, mac, ipv4, enum, bitmask The improvement here is that we now can exactly specify the width of the int type parameters and also correctly distinguish between signed and unsigned variables which means that a variable no longer ends up with INT_MAX when it's assigned -1. "access" can be empty for regular read/write parameter, "_ro" for readonly parameters which get their value from a variable pointer in the background or "_fixed" for parameters which are set to a fixed value (without a pointer in the background). Some more exotic types are not (yet) implemented, like dev_add_param_ip_ro. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Use standard debug macroSascha Hauer2016-09-281-27/+25
| | | | | | Use standard pr_debug instead of homebrew USB_PRINTF Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: core: return -EAGAIN on usb_* functions reentrancePeter Mamonov2015-10-141-1/+39
| | | | | Signed-off-by: Peter Mamonov <pmamonov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: core: drop unnecessary le16_to_cpu() conversionAntony Pavlov2015-10-021-4/+4
| | | | | | | | | | | | | | | | | | | | | | | In drivers/usb/core/usb.c we already have le16_to_cpus() conversion just after usb_get_descriptor(): 390 /* correct le values */ 391 le16_to_cpus(&dev->descriptor->bcdUSB); 392 le16_to_cpus(&dev->descriptor->idVendor); 393 le16_to_cpus(&dev->descriptor->idProduct); 394 le16_to_cpus(&dev->descriptor->bcdDevice); so no additional idVendor/idProduct descriptor fields le16_to_cpu() conversion is needed after that. On the big-endian machines extra le16_to_cpu() conversion leads to wrong idVendor/idProduct USB device parameters values (e.g. see devinfo <usb-device> output), and to a much more serious problem: idVendor/idProduct-based USB device detection does not work. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: ehci: fix include/usb/usb.h:'struct usb_configuration' misuseAntony Pavlov2015-09-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | See the commit commit 245069bcef15ecc19db616a967501349b76c84d0 Author: Sascha Hauer <s.hauer@pengutronix.de> Date: Thu Jul 10 11:36:12 2014 +0200 USB: introduce usb_interface/usb_configuration structs On little endian systems like ARM the le16_to_cpus() macro is a no op, defined as: #define le16_to_cpus __le16_to_cpus #define __le16_to_cpus(x) do {} while (0) So struct usb_configuration field misuse was discovered on big-endian MIPS machine. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: increase USB_CNTL_TIMEOUT to match linuxSteffen Trumtrar2015-05-041-2/+2
| | | | | | | | | | | | | | | | | | | | | USB requests should be processed within a timeframe of 5s. The linux kernel also uses this timeout value for the control packets. For the musb the increase in timeout helps successfully probing USB devices (at least on one test hardware), but on the other hand doesn't slow down the system, if there are no devices, i.e. the timeout never hits. That means, that the USB core correctly aborts instead of timing out. Why and how the 100ms was chosen in the first place, can not be deduced from the git history, just that it seems to work fine for most boards. Change USB_CNTL_TIMEOUT to 5000ms and replace all occurences of `USB_CNTL_TIMEOUT * x` with just `USB_CNTL_TIMEOUT`, as the timeout is now large enough without it. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: abolish wait_ms() functionMasahiro Yamada2015-02-021-1/+1
| | | | | | | | This function is only used in drivers/usb/*. It is equivalent to mdelay(). Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/usb-host'Sascha Hauer2014-08-071-463/+63
|\ | | | | | | | | Conflicts: drivers/usb/core/Makefile
| * USB: improve error paths and tear-downSebastian Hesselbarth2014-07-281-20/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | USB core isn't too strict about allocation/deallocation and add/remove sequences of usb devices. Especially, error paths and device tear-down are kind of broken and cause hangs on failing usb device detect. This patch improves the situation by introducing a usb_free_device() that tears down allocated resources by usb_alloc_new_device(). usb_remove_device() now only deals with resources that have been added by usb_new_device(). Also, error handling is fixed or improved to ensure that no devices are unregistered that have not been previously registered. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * USB: Count detected USB devices independent of dev_indexSebastian Hesselbarth2014-07-281-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | Adding a usb device increases dev_index every time a new device is allocated. Removing a usb device does not decrease again, of course. As we print the number of detected usb devices after each usb bus scan based on dev_index, we cannot trust dev_index here. Keep track of the correct number of (currently) detected usb devices by introducing an independent dev_count that gets increased on detect and decreased on remove. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * USB: Fix stale usb devices in usb_device_listSebastian Hesselbarth2014-07-281-0/+1
| | | | | | | | | | | | | | | | | | New usb devices are added to a list of usb devices, but when removing the corresponding usb_device it was not removed from that list. Fix it by deleting it properly from the usb_device_list. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * USB: host: drop force rescanSascha Hauer2014-07-181-27/+12
| | | | | | | | | | | | | | | | We can now detect changes in the USB device hierarchy properly, so the 'force' option to the usb command is no longer necessary. We just scan the busses each time the usb command is called. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * USB: host: implement usb_remove_deviceSascha Hauer2014-07-181-0/+19
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * USB: host: fixup USB device hierarchySascha Hauer2014-07-181-2/+1
| | | | | | | | | | | | | | Make all USB devices children to the hub device they are attached to. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * USB: host: hub: Turn into a driverSascha Hauer2014-07-181-413/+11
| | | | | | | | | | | | | | | | Since we have a driver model we can make the hub driver a real driver model driver. Put it into a new file to separate the hub from the USB core stuff. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * USB: host: simplify usb_new_deviceSascha Hauer2014-07-181-18/+5
| | | | | | | | | | | | | | | | | | usb_new_device tries to find the port number it is attached to by iterating over the parents children and using the loop counter index as port number. Instead, just use the portnr field in struct usb_device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * commands: usb: add tree view capabilityAntony Pavlov2014-07-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds U-Boot 'usb tree' command functionality to barebox. Here is an example output: 1 ID 0000:0000 | u-boot EHCI Host Controller | +-2 ID 05e3:0606 | USB2.0 Hub | +-3 ID 10c4:ea60 | Silicon Labs CP2102 USB to UART Bridge Contr P-00-00669 | +-4 ID 05e3:0606 | | USB2.0 Hub | | | +-5 ID 05e3:0608 | | | USB2.0 Hub | | | | | +-6 ID 0d8c:000c | | C-Media USB Headphone Set | | | +-7 ID 0d8c:000c | C-Media USB Headphone Set | +-8 ID 0846:1040 NETGEAR NETGEAR FA120 Adapter The tree view is enabled with 'usb -t' Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | USB: gadget: Update to 3.15Sascha Hauer2014-07-221-0/+1
|/ | | | | | | | | This updates the USB Gadget stack to Linux-3.15. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Conflicts: drivers/usb/core/Makefile
* USB: introduce usb_interface/usb_configuration structsSascha Hauer2014-07-181-26/+26
| | | | | | | | | | | Currently we have two conflicting definitions of struct usb_config_descriptor and struct usb_interface_descriptor in the tree. This is because the USB code uses additional fields in the structs for internal housekeeping. Add struct usb_interface and struct struct usb_configuration with the housekeeping data and embed the corresponding hardware structs into them. This frees the way to use the definitions from ch9.h in the next step. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: fix signedness mixups in printf format specifiersLucas Stach2014-04-231-2/+2
| | | | | | | | | This most likely doesn't fix any real bugs, but it's the right thing to do and reduces the noise level with static checkers. Signed-off-by: Lucas Stach <dev@lynxeye.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>