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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>