Commit graph zephyr/drivers/usb
Author SHA1 Message Date
Mathieu Choplain
b7b55f2a2e drivers: usb: common: stm32: fix Kconfig options leak
The Kconfig options related to USB common code should be gated by the
STM32_USB_COMMON option. Otherwise, they can appear in Kconfig of builds
where USB is not enabled at all (notably, the options related to logging
configuration were always leaked)

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-07-28 12:38:48 -07:00
Mathieu Choplain
882ec6cae4 drivers: usb: common: stm32_pwr: add STM32H7R/S support
Implement support for STM32H7R/S series in the common USB power module.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-07-27 14:41:07 +02:00
Mathieu Choplain
675ea7f841 drivers: usb: common: stm32: add new PHY pseudo-driver for USBPHYC
Add a new pseudo-driver for USBPHYC instances whose input frequency
selection is configured at RCC level in a `CCIPR` register, as is
the case on STM32H7R/S series for example.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-07-27 14:41:07 +02:00
Ren Chen
2abc3088a6 drivers: udc: it82xx2: defer OUT event until buffer is complete
For non-control out endpoints, do not submit the out event to upper
stack until the transfer buffer is completely filled.

Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>
2026-07-16 10:49:06 -04:00
Ren Chen
350fd5dfd4 drivers: udc: it82xx2: move suspend work init to preinit function
Re-initializing the suspend work when it's busy may cause kernel
panic. This change moves the suspend work initialization to the pre-init
function to ensure it is initialized only once.

Tested with: sudo dfu-util --detach

Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>
2026-07-16 10:49:06 -04:00
Mathieu Choplain
6fe6ba9f4c drivers: usb: udc: stm32: enable GPIO if disconnect/reset GPIOs are used
Enable the GPIO subsystem when the driver is enabled if disconnect-gpios
are provided on a node with compatible `st,stm32-usb` or if an ULPI PHY
provides reset-gpios.

The second case should be handled at a generic level, but ULPI PHYs have
always been managed as part of the STM32 driver for historical reasons.
Since no SoC family other than STM32 seems to use ULPI PHYs, this code
remains vendor-specific for now.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-07-15 15:26:33 +02:00
Muhammad Waleed Badar
528a0627ed drivers: usb: uhc_dwc2: introduce MMIO API for MMU platforms
Use Zephyr's standard MMIO abstraction API by introducing
DEVICE_MMIO_NAMED_RAM/ROM(core) in the driver's data and
config structs, mapping the region at initialization time
with DEVICE_MMIO_NAMED_MAP, and routing all register accesses
through a uhc_dwc2_get_base() helper that calls DEVICE_MMIO_NAMED_GET.
These changes allows the driver to be useful on MMU-based
platforms like Broadcom BCM2711 SoC.

Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
2026-07-15 15:25:42 +02:00
Fin Maaß
fbeefb4185 drivers: usb: uhc: use driver api
use driver api. with this we can find out
what device is a usb host controller.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-07-15 10:50:44 +02:00
Muhammad Waleed Badar
1ce2060f56 drivers: usb: uhc_dwc2: fix warning on 64-bit platforms
Use the `%zu` format specifier when printing `size_t` values instead of
`%u`. On 64-bit platforms, using an incorrect format specifier is
causing compiler warnings due to type mismatches.

Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
2026-07-14 18:00:45 +02:00
Roman Leonov
178caea19d drivers: uhc_dwc2: esp32: update quirks to latest binding
Rename the existing full-speed uhc quirk to the speed specific
espressif,esp32-usb-otg-fs compatible, that was introduced
in #111508.

Signed-off-by: Roman Leonov <jam_roma@yahoo.com>
2026-07-14 17:59:50 +02:00
Mathieu Choplain
b35b9456d4 drivers: usb: udc: stm32: use DT_ENUM_HAS_VALUE()
Replace IS_EQ() + DT_ENUM_IDX() with the simpler and more explicit
DT_ENUM_HAS_VALUE() macro.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-07-12 20:02:10 -04:00
Mathieu Choplain
23c84fa1ef drivers: *: stm32: replace COND_CODE_1() chains with COND_CASE_1()
The COND_CASE_1() allows writing chained/nested COND_CODE_1() checks in
a simpler way. Replace such patterns in the STM32 drivers with this new
utility macro.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-07-12 20:02:10 -04:00
Benjamin Jurewicz
a1c9a5bacd usb: host: uhc: Start using the existing uhc mutex lock helpers
Previously Max3421e driver locked and unlocked `uhc_data` mutex by using
`k_mutex_lock()` and `k_mutex_unlock()` instead the already existing
uhc helpers: `uhc_lock_internal()` and `uhc_unlock_internal()`.

Signed-off-by: Benjamin Jurewicz <bjurewicz@internships.antmicro.com>
2026-07-09 10:34:03 -05:00
Sylvio Alves
f61a2d5440 drivers: udc_dwc2: add esp32p4 usb otg-hs device controller
Add the ESP32-P4 USB-OTG high-speed controller using the
espressif,esp32-usb-otg-hs binding and the internal UTMI PHY. The
high-speed PHY uses dedicated pins, so no pad configuration is
needed. Enable the controller on the function ev board.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-07-08 17:13:54 +01:00
Sylvio Alves
cb7f6f9b50 drivers: udc_dwc2: add generic espressif fs usb otg quirk
Introduce a shared Espressif USB-OTG binding scheme and rename the
existing full-speed quirk to the speed specific
espressif,esp32-usb-otg-fs compatible. The internal PHY D+/D- pad
numbers now come from the phy-dp-pin and phy-dm-pin device tree
properties, so migrate the esp32s3 node accordingly.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-07-08 17:13:54 +01:00
Josuah Demangeon
99129e03e7 drivers: usb: uhc: dwc2: add nRF54LM20 vendor quirks
Add vendor quirks for nRF54LM20 PHY configuration for DWC2 in host mode.
Given the PHY is powered from USB, the PHY needs to be configured and
powered on before registers can be accessed or the SoC freezes on any
register access.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-07-08 17:10:30 +01:00
Mark Wang
755b39f26f drivers: usb: udc: mcux: fix cancelled transfer handling
Fix handling of cancelled transfers in MCUX USB device controller
drivers (EHCI and IP3511). When a transfer is cancelled, the MCUX
controller returns USB_CANCELLED_TRANSFER_LENGTH as the transfer
length. Previously, this special value was treated as a valid
transfer length and callback 0 for this transfer, causing incorrect
transfer operations in class codes.
Add proper detection of cancelled transfers by checking for
USB_CANCELLED_TRANSFER_LENGTH and returning -ECONNABORTED error
code.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2026-07-07 13:35:11 +02:00
Furkan Akkiz
04d263dc54 drivers: usb: udc: Fix nodata setup status issue on MAX32
Calling MXC_USB_Ackstat(0) immediately on SETUP receipt causes the
hardware to send the STATUS IN ZLP autonomously. The host then
issues the next SETUP before the Zephyr stack enqueues its own
STATUS IN.

Fix by deferring MXC_USB_Ackstat(0) to udc_event_xfer_in() when
the stack enqueues the STATUS IN ZLP. A nodata_setup flag tracks
whether the pending transfer is a no-data SETUP status stage.

Signed-off-by: Furkan Akkiz <hasanfurkan.akkiz@analog.com>
2026-07-06 14:51:05 +01:00
Roman Leonov
89a75416b7 drivers: usb: uhc_dwc2: add initial support
Note: Control and Bulk transfers only

Add initial usb host driver for Synopsys DWC2 with vendor quirks.

Signed-off-by: Roman Leonov <jam_roma@yahoo.com>
2026-07-03 13:55:57 -04:00
Roman Leonov
cc30eeffdd drivers: usb: common: extend dwc2 register descriptions
Get core revision:
Different core revisions require different handling.
To have an option to get the revision and apply different
logic add the possibility to read masked revision from
GSNPSID register.

Set PHY Low Power Clock Select:
For the HS UTMI+ PHY interface uses 48MHz for Low speed devices,
instead of 480 MHz. We need to configure this after port
completed a reset.

Frame number:
Add HFNUM register FRNUM field getter, to allow getting the frame
number for the USB host purposes.

Signed-off-by: Roman Leonov <jam_roma@yahoo.com>
2026-07-03 13:55:57 -04:00
Fabio Baltieri
a5191c40ef drivers,subsys: use min3/max3 instead of nested MIN/MAX
Replace nested MIN/MAX macro calls with the min3/max3 APIs which are
safer (evaluate arguments only once) and cleaner.

Assisted-by: Gemini:gemini-3.1-pro
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2026-07-01 23:44:58 -04:00
Benjamin Jurewicz
7993f4b343 usb: host: uhc: make max3421e driver work with multiple instances in dts
Make the max3421e driver work with multiple max3421e nodes present in the
dts.

Previously, one thread stack was defined, and the driver defaulted to the
device 0.

Now, each instance in dts with status okay gets its own thread, driver
data, and config.

Signed-off-by: Benjamin Jurewicz <bjurewicz@internships.antmicro.com>
2026-07-01 15:26:30 +01:00
The.Thanh Nguyen
1741ac46e3 drivers: udc: fix udc_renesas_ra mutiple instances issue
Update to use the device instance's private message queue instead
of the singleton global message queue.

Signed-off-by: The.Thanh Nguyen <the.nguyen.yf@renesas.com>
2026-06-30 06:48:16 -04:00
Michael Zimmermann
e10af22991 tree-wide: replace usages of k_work_q thread with thread_id
The `thread` field is not initialized, if it's being animated via
k_work_queue_run instead of k_work_queue_start.

Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
2026-06-29 22:17:45 -04:00
Mathieu Choplain
79b83188a6 drivers: usb: common: stm32: gate PHY interface drivers using Kconfig
Create two Kconfig options which are used to gate compilation of the
PHY interface drivers, previously done using logic in CMake listfiles.

The first option uses the "HAS_xxx" style and is "selected" on series with
a quirk requiring turning off the ULPI clock when using the embedded FS PHY
whereas the other follows the regular driver style, but has a series gate
to prevent compilation on wrong targets (which could occur since the
compatible it checks for is vendor-agnostic).

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-06-29 13:46:32 -05:00
Torsten Rasmussen
b425d7a375 kconfig: cleanup ZEPHYR_BASE usage
Remove `$(ZEPHYR_BASE)` from `source "<file>"`.
Source is always relative to ZEPHYR_BASE, so no need to specify it.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2026-06-19 22:40:14 +02:00
Aiden Hu
e402022682 usb: uhc_mcux_ehci: use clock control driver to set usb host clock
Check that the controller and PHY clock devices are ready, then
enable the clocks with clock_control_on() before calling
clock_control_set_rate().

This lets the host EHCI driver bring up RT7xx USB clocks from the
devicetree clock description.

Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
2026-06-17 16:35:06 -04:00
Anas Nashif
ea1fbf3588 driver: fix various typos
Fixed various typos under drivers/

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-06-17 10:12:27 -04:00
Benedek Kupper
816ad26d89 drivers: udc_nrf: use out_ack cap to simplify ctrl status out management
The out_ack capability is meant for the exact silicon design that
the nRF chip family uses. By setting it to the correct value, a lot of
workaround code can be cleaned up.

Signed-off-by: Benedek Kupper <kupper.benedek@gmail.com>
2026-06-12 15:30:46 +02:00
Mark Wang
726452f3c7 drivers: usb: uhc: mcux: fix endpoint reinitialization logic
Fix the endpoint attribute comparison logic in uhc_mcux_check_hal_ep()
to properly handle USB endpoint max packet size (MPS) fields.

The previous code compared the raw MPS value against maxPacketSize,
but the MPS field encodes both the packet size and the number of
additional transactions per microframe for high-speed endpoints.

Extract and compare these fields separately using USB_MPS_EP_SIZE()
and USB_MPS_ADDITIONAL_TRANSACTIONS() macros. This ensures endpoints
are correctly reinitialized when either the packet size or transaction
multiplier changes.

Also restructure the conditional logic for clarity: return early if
no endpoint exists, then check if attributes have changed and close
the endpoint if needed.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2026-06-09 07:11:16 +02:00
Chun-Chieh Li
0ab53e172f drivers: usb: udc: numaker: make vbus detect configurable
Nuvoton USBD/HSUSBD peripherals support VBUS detect functionality, but
some PCB designs may choose to use mutually exclusive USB-C peripheral
for VBUS detection. In this case, the USB controller backed VBUS detect
functionality won't work and needs to be disabled.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-06-02 13:27:46 +02:00
Tomasz Moń
d40884d3ab drivers: udc_dwc2: Execute disable in driver thread
After DWC2 core is disabled the registers should no longer be accessed
to prevent CPU hangs. While the concurrent access is guarded by mutex,
there was no mechanism to ensure that driver thread won't access any
register after udc_disable() was called. Solve the issue by executing
disable in driver thread context.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-05-29 07:33:24 +02:00
Johann Fischer
0e0d804267 drivers: udc_dwc2: call disable quirk if controller initialization fails
Call disable quirk if controller initialization fails.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-05-29 07:33:24 +02:00
Johann Fischer
e11ea494e5 drivers: usb: add Nordic USBHS BC12 driver
Add driver for Nordic USB PD Charging-Type detector.
This driver depends on the USBHS wrapper driver.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Co-authored-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-05-29 07:33:24 +02:00
Johann Fischer
a458052e4a drivers: udc: use USBHS wrapper driver in nRF54LM20a vendor quirks
Use USBHS wrapper driver to register VREGUSB regulator callback and
enable USB peripheral.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Co-authored-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-05-29 07:33:24 +02:00
Johann Fischer
b5d8897727 drivers: usb: common: add driver for Nordic USBHS wrapper
Nordic USBHS wrapper is a set of registers used by both USB BC12 driver
and vendor specific part in UDC driver. The wrapper can be considered
to be MFD device. Both drivers depends on the VBUS regulator driver and
require some synchronisation when accessing wrapper register.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Co-authored-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-05-29 07:33:24 +02:00
Nicolas Pitre
90d1963745 sys: util: move lowercase min/max/clamp to a new minmax.h
Since commit 37717b229f ("sys: util: rename Z_MIN Z_MAX Z_CLAMP to min
max and clamp"), <zephyr/sys/util.h> unconditionally defines function-
like macros named `min`, `max`, and `clamp` in the global namespace (in
C mode). util.h gets pulled in transitively by very broad headers,
including the POSIX layer's <pthread.h>, so any third-party C code that
uses these names as ordinary identifiers (e.g. XNNPACK's static `clamp`
helper and its public `clamp` struct field) fails to build as soon as
<pthread.h> is included.

Following the approach used by Linux, move the lowercase `min`, `max`,
`min3`, `max3`, and `clamp` macros (and their helpers) into a new
<zephyr/sys/minmax.h> header that has to be included explicitly by
source files that want them. util.h keeps the uppercase MIN/MAX/CLAMP,
so most code is unaffected; only the (much smaller) set of files that
actually use the lowercase variants needs to pick up the new include.

Fixes #107853.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-05-19 17:49:24 -04:00
Davide Di Lello
58f192e773 drivers: infineon: Update copyright for Infineon
Update structure of the copyright

Signed-off-by: Davide Di Lello <Davide.Dilello@Infineon.com>
2026-05-15 23:27:34 +02:00
William Markezana
3ffbb0dee5 drivers: usb: udc: bflb: fix bulk endpoint stalls, speed up transfers
Mask the per-endpoint done interrupt while a bulk OUT is left NAKed
(NAKed OUT tokens otherwise storm the ISR), bound the exrs/RDY busy-wait
(RM 18.3.4) so a stuck status bit can't hang the ISR, re-arm rather than
truncate a multi-packet OUT on a zero-count done, and skip the thread hop.

Signed-off-by: William Markezana <william.markezana@gmail.com>
2026-05-15 10:46:35 +02:00
Chun-Chieh Li
48e0033268 drivers: usb: udc: numaker: hsusbd: fix stuck in control transfer
Host can cancel current Control transfer for timeout and send new
Setup packet for new one. In this situation, driver can get out
of sync and even fail all the following Control transfers, probably
getting stuck in NAK'ing.

Because the HSUSBD hardware doesn't support disarm for Control Data
already armed for previous Control transfer, this update tries to
fix the issue via monitor of Data IN token. This approach has the
points:

* Wait for Data IN token received to arm Data IN
  This lowers the chance of mis-arm at the cost of performance.
  It also makes mis-arm error not propagate further in one or two
  broken Control transfers.
* Cancel current Control transfer on new Setup packet received

Fixes: #104922

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-05-13 09:13:43 +02:00
Chun-Chieh Li
0c8b6eee3a drivers: usb: udc: numaker: hsusbd: flush fifo for control in
For HSUSBD, unlike Control Data OUT which is automatically armed,
we can safely flush FIFO on new Setup packet whose direction is IN
because Data IN for the new Control transfer is not yet armed.
It is manually armed after processing the new Setup packet.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-05-13 09:13:43 +02:00
Chun-Chieh Li
75d57ec951 drivers: usb: udc: numaker: hsusbd: refactor on transfer can arm
Refactor on if transfer can arm or needs to arm into one function

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-05-13 09:13:43 +02:00
Chun-Chieh Li
b58f05d188 drivers: usb: udc: numaker: usbd: place Setup after Data/Status
For USBD, move Setup interrupt handling to the back of Data/Status
so that the order Data/Status->Setup can be kept when both flags
are asserted at the same time for delayed message handling. Both
flags asserted for the order Setup->Data/Status is an error
condition because the Data/Status transfer won't be armed until
the Setup packet is processed.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-05-13 09:13:43 +02:00
Mark Wang
ff4d6a8d71 drivers: usb: common: buf: Fix net_buf size modification in alloc
keep the allocated net_buf's size as the requested size, avoid
increasing it by USB_BUF_ROUND_UP.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2026-05-11 08:48:33 +02:00
Jamie McCrae
ceb26f67f0 drivers: Add support for dts RAM configuration
Allows using the chosen SRAM node for RAM configuration without
using Kconfig values

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-05-11 08:45:38 +02:00
Egill Sigurdur
16ac4a5b78 kernel: mem_slab: add K_MEM_SLAB_DEFINE_TYPE for automatic alignment
Introduces K_MEM_SLAB_DEFINE_TYPE() and K_MEM_SLAB_DEFINE_STATIC_TYPE()
helpers to allow the user to declare slabs for types without having to
manually ensure the alignment is correct.

Manual slab alignment was very error-prone and this change fixes several
instances of misalignment that would be trapped by the undefined
behavior sanitizer when running on 64-bit targets.

Signed-off-by: Egill Sigurdur <egill@egill.xyz>
2026-05-07 18:09:41 -05:00
Pete Johanson
a0d8f78655 drivers: usb: udc: Buffer null checks, EP0 OUT handling, etc
Add missing null buffer checks in event callbacks for IN/OUT done handling,
various small fixes for halted state handling, remove some unnecessary
logging for expected failure modes, etc

Signed-off-by: Pete Johanson <pete.johanson@analog.com>
2026-05-06 19:59:08 +02:00
Zhaoxiang Jin
abf8033953 usb: udc_mcux_ehci: enable clocks before setting rates
Check that the controller and PHY clock devices are ready, then
enable the clocks with clock_control_on() before calling
clock_control_set_rate().

This lets the EHCI driver bring up RT7xx USB clocks from the
devicetree clock description.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
2026-05-03 21:40:02 +02:00
Zayne Stites
059fca326c drivers: usb: udc: Add Infineon vendor quirks
Add Infineon vendor quirks to the UDC DW2 implementation.  This
ties to the infineon,usbhs binding.

Signed-off-by: Zayne Stites <Zayne.Stites@infineon.com>
2026-04-29 11:53:30 -05:00
Chun-Chieh Li
164ad704ba drivers: usb: udc: numaker: support m335x usbd
Add support for Nuvoton NuMaker SoC series M3351 USBD

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-04-29 10:00:37 +02:00