Teach the Xilinx SDHC driver to also drive the Zynq-7000 PS SD/SDIO
controller (same Arasan 8.9a IP, one generation older). It binds to
"arasan,sdhci-8.9a", the compatible the Linux Zynq-7000 devicetree uses
for this controller.
The data transfer path is selected with Kconfig: XLNX_SDHC_ADMA2 or
XLNX_SDHC_PIO, which moves the data through the Buffer Data Port; the
unused path is compiled out. PIO is the default when a Zynq-7000
controller is enabled, as ADMA2 is not yet supported there. In PIO mode
the buffer-ready and transfer-complete events are taken from the
interrupt handler when the node has an interrupt, as the handler
acknowledges those status bits, and polled otherwise. The handler and
the signal-enable mask now also cover Buffer Write Ready.
Per-SoC differences come from the compatible:
- maximum SD clock: 208 MHz on Versal; 50 MHz on Zynq-7000, which has no
PHY/tap-delay block and therefore no UHS modes.
- tap delay: the SD input/output tap-delay registers exist only on
Versal. They lie outside the Zynq-7000 register window, so they are
not programmed there when switching to High Speed.
- broken slot type: the Zynq-7000 Capabilities register reports an
embedded slot although carriers wire a removable SD slot. The SD slot
type is forced so the eMMC command-framing and power paths (which
reject CMD8/R7 and assert the eMMC reset) are not taken.
A command without a data phase now writes Transfer Mode 0 rather than
leaving the data-transfer bits set. Zynq-7000 rejects the command
otherwise, and 0 is the spec-correct value.
struct reg_base is no longer __packed. A packed struct makes GCC split
the 16-bit interrupt-enable writes into byte stores, which the Zynq-7000
controller drops: status-enable stays 0, so Command-Complete never
latches. Every register is naturally aligned, so the layout does not
change; BUILD_ASSERTs check the offsets. The register interface is
32 bits wide and discards 64-bit accesses, so the three 64-bit registers
(Capabilities, Max Current Capabilities, ADMA System Address) are split
into lower and upper words that are accessed separately.
Tested on a Trenz TE0726 (Zynq-7000, PIO) with a 7.7 GB SDHC card, with
and without the interrupt line. The card comes up at 4-bit High Speed
(50 MHz). Single- and multi-block reads of several sectors, in
alternating order, match reference data written by independent code.
Single-block raw writes read back correctly, and a 66536-byte file
written through FatFs (single- and multi-block writes) reads back intact
after a remount and through an independent SD/FatFs implementation; the
other files on the card are unchanged. The Versal configuration was
built but not run on hardware.
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: David Paul-Beier <david@paul-beier.de>
Added standard controller driver per SD Specifications Part A2
SD Host Controller Simplified Specification (Version 3.00) which
matches current sdhc and sd subsystem features support.
It can be updated in the future for example to v4.20 if new
features are required to support.
For now, the driver provided standard registers definition and
access APIs, also provided a sdhc_standard_host_init API for host
properties/capabilities initialization.
Vendor drivers to reuse the standard host driver are required to
use sdhc_standard_host_common_config/sdhc_standard_host_common_data.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Added sdhc_common.c for common code. For now, it provided
only one common API, for SDHC device tree properties
initialization.
Vendor drivers can convert to use sdhc_common_config and
sdhc_common_dt_props_init API.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Renamed sdhc_helpers.h to sdhc_common.h for more usage
in the future. The SDHC needs a common c file for vendor
drivers reusing, and this file can be as its header file.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
The new SDHC API driver for the STM32 SDMMC IP does not work across the
entire family portfolio, as some series (STM32F1/F2/F4/F7/L1) and lines
(STM32L4; but not STM32L4+!) use a different IP from the one which this
driver was tested against. Prevent enabling the driver on such series
since it will not work properly, or in fact build at all, because the
peripheral is called "SDIO" instead of "SDMMC" on most of these series
and the HAL/LL namings follow suit.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
this commit adds HEAP_MEM_POOL_ADD_SIZE_SDHC_STM32_SDMMC with
a default value of 2048 bytes for sdhc driver.
Signed-off-by: Sara Touqan <zephyr@exalt.ps>
Add support for CMD5, CMD52, CMD53 for Renesas RA to support
SDIO mode
Add interrupt enable/disable API and support SDIO in-band interrupt
callback
Signed-off-by: Duy Nguyen <duy.nguyen.xa@renesas.com>
Three correctness fixes for the Infineon SDHC driver:
- WAIT_FOR() takes a total timeout in microseconds, not a loop count.
sdhc_host_poll_transfer_complete(), sdhc_poll_buf_read_ready() and the
buffer-read-enable poll passed the raw retry count (1000 -> 1 ms), so
slower cards timed out during the non-DMA PIO reads used by CMD6
(SWITCH_FUNC) and ACMD51 (SEND_SCR), producing "Buffer read is not
ready" and ACMD51 timeouts. Pass retries * per-iteration delay, matching
sdhc_poll_cmd_complete(). Also drop the duplicate IFX_SDHC_RETRY_TIMES
macro in favour of IFX_SDHC_RETRY_TIME.
- Add a clock-settle delay in sdhc_change_clock() after re-enabling the SD
clock: 2000 us for the 400 kHz identification clock (cold bring-up) and
500 us for later speed changes. Fixes intermittent cold-start CMD8
failures where commands were issued before the divider settled.
- Restrict sdhc_infineon_card_busy() to the DAT[3:0] line level. The
DAT_LINE_ACTIVE / CMD_INHIBIT_DAT present-state bits reflect host-side
transfer activity and caused false-positive "busy" reporting, which
breaks the CMD11 voltage-switch checks in the SD subsystem.
Signed-off-by: Kevin Chan <kevin.chan3@infineon.com>
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>
Use controller/peripheral and SDO/SDI terminology in the remaining
SPI-using drivers (audio, auxdisplay, bluetooth HCI, dac, eeprom,
ethernet, flash, fpga, gpio, haptics, hdlc_rcp_if, ieee802154,
input, led, led_strip, lora, mfd, misc, mux, rtc, sdhc, stepper,
video, watchdog, wifi) and the ec_host_cmd SPI STM32 backend,
following coding guideline rule A.2: switch to
SPI_OP_MODE_CONTROLLER/PERIPHERAL and SPI_SDO_OVERRUN_DT, rename
Zephyr-owned identifiers (the HCI SPI header buffers, the winc1500
bus wrapper transfer parameters), and update comments, log messages
and Kconfig help prose.
Vendor and out-of-scope identifiers keep their names: STM32
LL_SPI_MODE_SLAVE in the ec_host_cmd backend, the ATWINC1500 SDK I2C
SLAVE_ADDRESS definition, and the I2S codec clock-role variable in
tlv320aic26.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Two-line copyright notices were wrapped in the SPDX "<text>...</text>"
construct, which is only valid in an SPDX document, not a file header.
The REUSE tool then folds the literal "<text>" into the holder name
and drops the second line from the SBOM.
Remove the markers and tag the continuation line. Holder, year and
e-mail are left unchanged; only the syntax is fixed.
Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
The aligned path clears FBYTE and computes a word count but set
byte_mode to true, and the unaligned path did the opposite, so
manual transfers moved a quarter of the data or overran the buffer
fourfold. Swap the two assignments to match the FBYTE setting.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Fix the Byte order when receiving a R2 response from the SDcard.
It will give the correct Device Size depending on the CSD structure.
For standard capacity SDSC memory cards, CSD struct if Version 1.0.
For high capacity SDHC and SDXC memory cards, CSD struct is Version 2.0.
Signed-off-by: Francois Ramu <francois.ramu@st.com>
The sdmmc_ll_set_command helper writes the command register
through memcpy, which the compiler expands into four byte
stores. The peripheral bus only accepts 32-bit accesses, so
the command never reached the card interface unit and the
driver spun forever waiting for it to be taken.
Restore the single word store to the command register. This
is a regression from f4c7092ad6.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Perform the required cache maintenance before and after ADMA
transfers when the data cache is enabled.
Direct DMA read buffers must be aligned to the data cache line size because
invalidating a partial cache line may discard unrelated dirty data.
Use a cache-line-aligned bounce buffer for small reads whose transfer
size is not a multiple of the cache line size. This allows commands
such as the 4-byte MMC SEND_WRITE_PROT command to use ADMA safely.
Set the SDHC buffer alignment to the greater of the configured
data cache line size and the controller's minimum 32-byte
alignment requirement.
Signed-off-by: Takumi Ando <takumi@spacecubics.com>
The Zephyr SD subsystem expects a 136-bit R2 response in
sdhc_command::response[4] with response[3] holding the most
significant 32 bits and response[0] holding the least significant
32 bits.
intel_emmc_host stored the 32-bit fragments in reverse order, so
resp3 (bits 127:96) was placed in response[0] and resp0 (bits 31:0)
in response[3]. Reverse the assignments.
sam_hsmci read the HSMCI_RSPR FIFO into response[3..0] in the order
the FIFO returns data, but that puts the most significant word in
response[0]. Read the FIFO into response[0..3] instead, matching the
Zephyr layout.
Fixes#112868
Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
This reverts commit 713cdff118.
Build error:
ERROR: /soc/mmc@ee140000 <rcar_mmc_init> is initialized before its
dependency /regulator_1p8v <regulator_fixed_init>
ERROR: ... /regulator_3p3v <regulator_fixed_init>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
set the default of SDHC_INIT_PRIORITY to
KERNEL_INIT_PRIORITY_DEVICE, just like at the other
driver priorities.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This macro eliminates manual size/alignment management and prevents
namespace collisions by moving internal queues to file-private scope.
Signed-off-by: Cesar Vandevelde <cesar.vandevelde@gmail.com>
Replace direct SDMMC register accesses with the equivalent
sdmmc_ll_* low-level helpers from hal_espressif for interrupt
handling, controller and fifo reset, DMA setup, the command
engine, timeout configuration, card data-busy polling and
bus-width selection. The two duplicated local DMA helpers are
dropped in favor of sdmmc_ll_init_dma and sdmmc_ll_stop_dma.
Register accesses with no low-level equivalent (whole-register
interrupt-mask save, restore and set, and the response fifo
read) are left unchanged.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Every bus width, clock and timing change logged at info level, so
enumerating a card printed a dozen lines of routine progress on
any build with info logging on. An sdio peripheral on the second
slot doubles that.
Drop those messages to debug level. The error paths are
unchanged, so a failure still reports at its original level.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Both slots are served by a single sdmmc controller: one register
block, one command engine, one dma channel and one interrupt
line. The driver kept that state per instance, so enabling a
second slot had the two fight over the shared registers and the
build asserted on more than one slot.
Move the controller-wide state into a shared struct and run the
bring-up once, on whichever slot initialises first. A controller
mutex serialises transactions across slots and records the owner,
so the interrupt handler routes completion events to the right
queue and the per-slot clock divider is reprogrammed through a
clock update command when the bus changes hands. Restore the
saved interrupt mask on every error path in the clock helper,
which previously left the mask blanked and killed the other
slot's interrupts.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
The esp32 sdhc driver routed its slot pins directly and had
no path for block-mode CMD53 transfers or for the DAT1 card
interrupt, so an sdio card function could not be driven from
it.
Route the slot pins through the gpio matrix and add CMD53
block and byte transfers plus card interrupt enable and
disable, which an sdio client needs to move frames and to be
woken by the card. The card interrupt is masked in the
handler and re-armed by the consumer, so the enable and
disable helpers avoid sleeping primitives and stay callable
from the callback.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
these drivers are already conditionally
included/added in drivers/CMakeLists.txt
so we dont' need another if.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
After a read the cache invalidation only covered one block even
for multi-block transfers, leaving the remaining blocks to be read
from stale cache lines. Invalidate the full transfer size, which
matches the range flushed when the DMA descriptors are prepared.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The async completion timeout returned while still holding the
access mutex and the PM runtime reference, wedging the controller
for every subsequent request. Unlock and drop the reference before
returning.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Convert cmd->response_type from a Zephyr enum sd_rsp_type value to the
Ambiq HAL's MMC_RSP_* bitmask via a new helper
ambiq_sdio_resp_type_to_hal(). The helper returns false on an
unrecognized response type and the caller propagates -EINVAL to fail
fast at the API boundary.
Remove the redundant CMD-index based ui32RespType overrides, keeping
only the bCheckBusyCmd handling for CMD6 and CMD38, which is a real
HAL-specific semantic not covered by the response type enum.
Also change the helper parameter type from enum sd_rsp_type to
uint32_t to match cmd->response_type, and add an explicit (int) cast
in the LOG_ERR format call.
Fixes zephyrproject-rtos#112220
Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
(op & A) || (op & B) is equivalent to op & (A | B). Collapse the
RES_TYPE_SEL_48 / RES_TYPE_SEL_136 test into a single masked check.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
Enable the GPIO subsystem when cd-gpios or pwr-gpios are used on
any STM32 SDMMC node and the corresponding driver is enabled.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
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>
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>
Add the driver for TI's interrupt based AM654 SD Host Controller that can
be used with both eMMC and SD cards.
Signed-off-by: Amneesh Singh <amneesh@ti.com>
Fix R2 (CID/CSD) response ordering for the Ambiq SDHC driver.
The Ambiq HAL packs 136-bit R2 responses as a big-endian 128-bit
value with bits 127:96 in ui32Resp[0]. Zephyr's SD stack expects
cmd->response[3] to hold the highest 32 bits, matching the SDHCI
register layout used by other SDHC drivers. The existing memcpy
therefore placed the response words in reverse order, causing
sdmmc_decode_csd() to read sector_count and block_size as zero.
Replace the memcpy with a conditional copy that reverses the word
order for R2 responses and clears the unused response words for
all other response types.
Fixes#111443
Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
Acquire the SDMMC source clock with esp_clk_tree_enable_src() before
selecting it, so the host has a clock even when the ROM left that
reference-clock gate disabled.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
sdmmc_host_set_clk_div() enabled the sample clocks via
sdmmc_ll_init_phase_delay() but never programmed the data-in sampling
phase. On SoCs where that register powers up with a value that does not
sample the data lines correctly, reads return a 0x55/0xAA pattern, the
SCR decodes wrong and the card stays in 1-bit default speed where data
transfers fail. Program the nominal phase 0 after init so reads sample
correctly and high-speed/4-bit negotiation succeeds.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
The command dispatch had no entries for the SD erase sequence, so
CMD32 returned -ENOTSUP and any erase request failed. Add the three
erase opcodes: CMD32 and CMD33 as addressed commands with an R1
response, and CMD38 with R1b plus SCF_WAIT_BUSY so the driver waits
for the card to finish erasing before returning.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
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>
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>
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>
Wire ESP32-P4 specific IOMUX paths and status register layout,
use the combined raw interrupt status field, and align the DMA
descriptors to the cache line for coherent flush and invalidate.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Update all drivers to use "flags" instead of "sense" when accessing
interrupt properties from device tree. This aligns with the updated
interrupt controller bindings that now consistently use "flags" as
the cell name for the IRQ type field.
Signed-off-by: Amneesh Singh <amneesh@ti.com>
The RA SDHC driver handles SD_SWITCH/CMD6 through
r_sdhi_read_and_block(), then copies the returned status from the
FSP aligned buffer into the Zephyr request buffer.
CMD6 switch status is a 64-byte data block. The driver copied only
8 bytes, which is the SCR size used by ACMD51. This left byte 13
uninitialized or stale, so the SD core could read bus_speed as 0.
With bus_speed misread, the SD core skipped high-speed setup. Since
the current init flow switches to 4-bit width after high-speed setup,
ACMD6 bus-width switching was also skipped despite host and card
both advertising 4-bit support.
Copy ra_cmd.sector_size bytes instead, matching the requested data
block size. For CMD6 this preserves the full 64-byte switch status.
Signed-off-by: Shan Pen <bricle031@gmail.com>
Use dma-coherent dt prop to determine, if
cache operations are needed before and after
DMA operations.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>