Commit graph zephyr/drivers/sdhc/imx_usdhc.c
Author SHA1 Message Date
Ryan Erickson
004ffb498e drivers: sdhc: imx_usdhc: add non-removable devicetree property
Some USDHC instances are permanently wired to a non-removable device,
such as an SDIO Wi-Fi module, with no card-detect GPIO or host
card-detect line available. Previously this relied on falling through
to the "no card detection method configured" warning path and assuming
the card was present. Add an explicit non-removable boolean property so
boards can declare this intent directly; when set, the driver reports
the card as always present and skips card detection.

Signed-off-by: Ryan Erickson <ryan.erickson@ezurio.com>
2026-09-03 18:47:49 -04:00
Thomas Hebb
ec46c494a9 drivers: sdhc: imx_usdhc: revert Zephyr-side cache maintenance
NXP's USDHC SDK driver knows how to do its own cache maintenance and
does so on platforms that set HAS_MCUX_CACHE[1]. Recently, a copy of
that cache maintenance logic was added on the Zephyr side because
certain cores, like the Cortex-M33 of the i.MX RT1180, use an external
cache controller and instead set HAS_MCUX_XCACHE.

However, the Zephyr-side cache logic is buggy: it clobbers the response
data in cases when the SDK can't use DMA (specifically, when the RX
buffer isn't 4-byte aligned[2]): in those cases, the SDK code writes to
the buffer, those writes go to cache, then Zephyr invalidates the cache
discarding the written data.

NXP's SDK abstracts over different cache drivers just like Zephyr does,
so it's fine to enable its cache control for platforms with any type of
cache. Do that instead of reimplementing cache maintenance in Zephyr.

This partially reverts commit 0b8babdcc3 ("drivers: sdhc: imx_usdhc:
add cache maintenance on DMA path"), leaving only the new default value
for CONFIG_SDHC_BUFFER_ALIGNMENT.

[1] 2d8b1b1133/modules/hal_nxp/mcux/CMakeLists.txt (L140-L142)
[2] cddb388583/mcux/mcux-sdk-ng/drivers/usdhc/fsl_usdhc.c (L1343-L1346)

Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
2026-07-06 10:27:10 +02:00
Jiafei Pan
8edca5b8df drivers: sdhc: imx_usdhc: fix VS18 flasg missing
In case of FSL_FEATURE_USDHC_HAS_NO_VS18 is definied,
kUSDHC_SupportV180Flag is not defined in fsl_usdhc.h, so it will has
compile issue, the fix is to make 1.8v support to be false in case of
FSL_FEATURE_USDHC_HAS_NO_VS18 is definied.

Signed-off-by: Jiafei Pan <Jiafei.Pan@nxp.com>
2026-07-03 13:58:29 +02:00
Thomas Hebb
9e7c3d7ece drivers: sdhc: imx_usdhc: Replace IMX_USDHC_NOCACHE_TAG with __nocache
These are both gated on CONFIG_NOCACHE_MEMORY and both place the symbol
in a non-cacheable section, so there's no reason to define our own
macro. The only difference is that __nocache uses a file-specific
section name, which helps with debugging but shouldn't affect
functionality.

Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
2026-06-10 10:56:45 +02:00
Lucien Zhao
0b8babdcc3 drivers: sdhc: imx_usdhc: add cache maintenance on DMA path
When CONFIG_IMX_USDHC_DMA_SUPPORT is enabled, the USDHC ADMA2
engine DMAs to/from the data buffer supplied by upper layers
(e.g. FAT FS, SD subsystem) which lives in regular cacheable
RAM. Without explicit cache maintenance, on writes the
controller may DMA-read stale RAM while CPU writes are still
in D-cache, and on reads the CPU may consume stale cache lines
after the controller has DMA-written fresh data.

Flush the data buffer before each transfer (correct for TX,
and prevents later dirty-line eviction over DMA-written data
on RX) and invalidate after RX completes. Both scatter-gather
and non-scatter-gather paths are handled.

Raise SDHC_BUFFER_ALIGNMENT to DCACHE_LINE_SIZE when D-cache is
enabled so that DMA buffers (both upper-layer pass-through and
the SD subsystem fallback card_buffer) are cache-line aligned.
Without this, sys_cache_data_invd_range may operate on partial
cache lines and silently discard dirty data of adjacent
allocations sharing the head/tail line.

Fixes #107862

Signed-off-by: Lucien Zhao <lucien.zhao@nxp.com>
2026-06-09 11:55:27 +02:00
Thomas Hebb
dd329ad617 drivers: sdhc: Log SDIO timing mode in more drivers
rcar already had a function to map timing mode to a string. Move that
function into the shared header and use it from multiple drivers. Also
use a shared function to convert voltage to a string instead of open
coding it everywhere.

Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
2026-06-08 19:00:27 +02:00
Zhaoxiang Jin
8cef371272 sdhc: imx_usdhc: add reset controller support
Add optional devicetree reset support to the i.MX USDHC
driver and deassert the reset line before controller
initialization.

Keep existing behavior unchanged when no reset is described.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
2026-05-01 09:42:15 +02:00
Lucien Zhao
c8512077b8 drivers: sdhc: imx_usdhc: support no-3-3-v and no-3-0-v voltage options
Add support for the no-3-3-v and no-3-0-v devicetree properties in the
IMX USDHC driver. When both are set, the driver overrides the host
capability flags to disable 3.3V and 3.0V support, and sets the USDHC
VSELECT bit at init time to configure the data line sampling threshold
for 1.8V I/O without triggering the SD voltage switch protocol.

Update the reset function to respect the voltage configuration: when
both no-3-3-v and no-3-0-v are set, the reset path now restores 1.8V
signaling instead of unconditionally switching to 3.3V, ensuring correct
behavior after card re-initialization on fixed 1.8V I/O boards.

This is required for boards like the MIMXRT700-EVK where the USDHC1
I/O voltage domain (VDDIO_0) is fixed at 1.8V.

Signed-off-by: Lucien Zhao <lucien.zhao@nxp.com>
2026-04-24 12:59:09 +02:00
Hake Huang
8c036b2ae8 drivers: sdhc: remove unused fsl_cache.h include from imx_usdhc
imx_usdhc.c does not use any symbols from fsl_cache.h, and
fsl_usdhc.h does not require it transitively.

Remove the unused include to avoid build failures on targets where
the cache HAL header is not available, such as MCXN947 CPU1 virtual
board builds.

Signed-off-by: Hake Huang <hake.huang@nxp.com>
2026-04-16 10:12:21 +02:00
Thomas Hebb
477568a2ae drivers: sdhc: imx_usdhc: Automatically mask SDIO interrupt
There are currently two other sdhc drivers that support this interrupt:
Infineon and Ambiq. Both those vendor HALs automatically mask the
interrupt after invoking the callback[1][2], expecting the user to
unmask it asynchronously once they've cleared the card's interrupt
condition.

The NXP usdhc driver doesn't do this and so is inconsistent with the
other two. This has caused bugs with higher-level drivers, such as the
AIROC Wi-Fi driver (#101100). Fix the issue by masking the interrupt
ourselves.

[1] 470f874ce4/mtb-hal-cat1/source/cyhal_sdhc.c (L1251-L1260)
[2] 5efc022852/mcu/apollo510/hal/mcu/am_hal_sdhc.c (L2256)

Fixes #101100

Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
2026-01-27 08:06:52 +01:00
Amneesh Singh
03ba08615a drivers: sdhc: split caps into standard and extra
Make sure the capability bitfields fit the standard SD Association
specification and move the extra capabilities to props.

Affected Drivers:
- sdhc_infineon
- imx_usdhc
- intel_emmc_host
- rcar_mmc
- sam_sdmmc
- sdhc_ambiq
- sdhc_esp32
- sdhc_max32
- sdhc_renesas_ra
- sdhc_stm32
- xlnx_sdhc

Affected Subsys
- sd

Reference: 2.2.26, SD Specifications, Part A2, SD Host Controller
           Simplified Specification, Version 4.20
           URL: https://www.sdcard.org/downloads/pls/pdf/?p=PartA2_SD%20Host_Controller_Simplified_Specification_Ver4.20.jpg

Signed-off-by: Amneesh Singh <amneesh@ti.com>
2026-01-26 13:53:51 -06:00
Thomas Hebb
21cd98a5e1 drivers: sdhc: imx_usdhc: Extend all reset timeouts
commit bf61a47887 ("drivers: sdhc: imx_usdhc: extend reset timeout
duration") extended the timeout from 100 iterations to 1000 iterations
for the USDHC_Reset() call in imx_usdhc_reset() but not in the other
places it's called. I have observed a "usdhc: Failed to reset command
line" error from imx_usdhc_error_recovery() on an i.MX RT1061, which
goes away if I extend the timeout. Do so there and also at other call
sites for good measure.

Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
2026-01-19 10:03:39 +01:00
Maochen Wang
a8137baf65 drivers: sdhc: imx_usdhc: add retry for DAT3 card detection
DAT3-based card detection can return a false negative on the first read
due to transient signal states after enabling detection. Add a bounded
retry loop (limited by IMX_USDHC_DAT3_DETECT_RETRY) with a short delay
between attempts to improve robustness.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2025-12-26 10:17:10 -06:00
Yangbo Lu
c3a3c2bd99 drivers: sdhc: imx_usdhc: support scatter gather DMA transfer
Supported scatter gather DMA transfer.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-12-23 05:04:25 +01:00
Bas van Loon
8d417a31a2 drivers: sdhc: imx_usdhc: Add more verbose error reporting.
When USDHC_Reset fails, we should be more verbose about it failing. Add
the error prints here so that we can observe the failure in logs.

Signed-off-by: Bas van Loon <bas@arch-embedded.com>
2025-09-04 08:10:40 +02:00
Bas van Loon
04d40ecc68 drivers: sdhc: imx_usdhc: Fix USDHC_Reset reset type.
Probably a C/P error. This error was leading to reset timeouts as the
wrong mask is being used.

Signed-off-by: Bas van Loon <bas@arch-embedded.com>
2025-09-04 08:10:40 +02:00
Jiafei Pan
51e0fcf80c drivers: sdhc: imx_usdhc: enable MMIO mapping
Enable MMIO mapping in the driver.

Signed-off-by: Jiafei Pan <Jiafei.Pan@nxp.com>
2025-05-12 16:47:49 +02:00
Jiafei Pan
819125f726 drivers: sdhc: imx_usdhc: run clang-format on the driver
Format the driver by using clang-format.

Signed-off-by: Jiafei Pan <Jiafei.Pan@nxp.com>
2025-05-12 16:47:49 +02:00
Pieter De Gendt
c4fbec2377 drivers: sdhc: Place API into iterable section
Add wrapper DEVICE_API macro to all sdhc_driver_api instances.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-12-02 23:04:22 +01:00
Daniel DeGrasse
17f71e19f0 drivers: sdhc: imx_usdhc: assume card is present if no detection method
The imx USDHC driver previously queried the peripheral's internal card
detect signal to check card presence if no card detect method was
configured. However, some boards do not route the card detect signal and
do not work correctly with the DAT3 detection method supported by this
peripheral. As a fallback, assume the card is present in the slot but
log a warning to the user.

Fixes #42227

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-08-22 14:19:37 -04:00
Daniel DeGrasse
bf61a47887 drivers: sdhc: imx_usdhc: extend reset timeout duration
Some instances of the USDHC peripheral take longer to reset, and will
timeout with the previous delay of 100 cycles. Extend this delay to 1000
cycles to resolve this.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-05-14 20:23:28 -04:00
Daniel DeGrasse
da9361e544 drivers: sdhc: imx_usdhc: remove dead code for waiting for clock gate
Remove function for waiting for clock gate, as this is not used anywhere
within the USDHC driver.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-05-14 20:23:28 -04:00
Daniel DeGrasse
bd17c86299 drivers: sdhc: imx_usdhc: move voltage selection to separate function
Some USDHC IP instances do not have the voltage control bit present, as
they can only operate at 3.3V. Move code to select 1.8V mode into a
separate helper, and guard the call to UDSHC_SelectVoltage() behind a
feature macro from MCUX SDK.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-05-14 20:23:28 -04:00
Daniel DeGrasse
2236eaf52c drivers: sdhc: imx_usdhc: add explicit fallthrough to I/O timing setup
DDR50/DDR52 modes should use PINCTRL_STATE_SLOW (50MHz), so the lack of a
break statement after enabling DDR mode is expected. Add an explicit
__fallthrough to resolve the issue flagged by coverity scan

Fixes #65324

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-12-12 10:57:20 +01:00
Daniel DeGrasse
0b365359dc drivers: sdhc: imx_usdhc: explicitly set host_io fields
Explicitly set host_io fields, instead of using memset(). This way the
fields should have values that are defined in the enum types for each
field.

Fixes #63130

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-12-12 10:57:20 +01:00
Daniel DeGrasse
7ca3aec97e drivers: sdhc: imx_usdhc: Initialize card clock with CMD0
Use CMD0 to detect card initialization, rather than using card power on.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-11-06 19:01:08 -05:00
Daniel DeGrasse
a517d79eff drivers: sdhc: imx_usdhc: enable DDR50 mode
Enable support for DDR50 mode within imx usdhc driver.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-11-06 19:01:08 -05:00
Daniel DeGrasse
c28ffb4305 drivers: sdhc: imx_usdhc: add support for SDIO RW extended command
Add support for CMD53 (read/write extended) to imx USDHC driver.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-11-06 19:01:08 -05:00
Daniel DeGrasse
69aaed1266 drivers: sdhc: imx_usdhc: add support for card interrupts
Add support for card interrupt sources to USDHC driver.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-11-06 19:01:08 -05:00
Gerard Marull-Paretas
c4c5f57d59 drivers: all: imx: remove conditional support for pinctrl
The iMX platform always uses pinctrl, there's no need to keep
extra macrology around pinctrl. Also updated driver's Kconfig to `select
PINCTRL`.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-24 13:34:22 +02:00
Declan Snyder
4fe04f9a85 drivers: sdhc: Support HS400 mode on IMX driver
Enables HS400 mode on mimxrt595_evk

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-01-14 09:22:22 +01:00
Declan Snyder
f7e026f655 drivers: sdhc: Adds MMC functionality to IMX USDHC
Adds MMC support to IMX USDHC driver.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-01-14 09:22:22 +01:00
Declan Snyder
26ad12f55e drivers: sdhc: Fixes IMX SDHC DMA support
Enables DMA support for cacheless IMX systems.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-01-14 09:22:22 +01:00
Gerard Marull-Paretas
178bdc4afc include: add missing zephyr/irq.h include
Change automated searching for files using "IRQ_CONNECT()" API not
including <zephyr/irq.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-17 22:57:39 +09:00
Gerard Marull-Paretas
79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Henrik Brix Andersen
9c1833b2e8 drivers: sdhc: check if clock device is ready before accessing
Add check for device_is_ready() before accessing clock control devices.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-09 17:16:16 +02:00
Daniel DeGrasse
e2fe582d62 drivers: sdhc: Add SD response type masks
Add SD response type masks, to allow drivers to mask out the
SPI or SD native mode response type based on the SD host controller
mode they use.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-05-09 08:46:29 -05:00
Daniel DeGrasse
c91d473ead drivers: imx_usdhc: change DT_COMPAT string to imx-usdhc
with the legacy USDHC driver fully removed from the tree, the
nxp,imx-usdhc binding can now be used for the new SD host controller
driver.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-04-29 14:21:36 -05:00
Daniel DeGrasse
6aaa2b5d33 drivers: sdhc: Implement NXP USDHC SDHC driver
Implement SDHC driver for NXP USDHC peripheral, supporting all api calls
available in the sdhc driver. This implementation leverages NXP's HAL,
and simply implements a shim layer over the HAL itself.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-04-29 14:21:36 -05:00