Commit graph

11 commits

Author SHA1 Message Date
Daniel DeGrasse
a2087bed16 drivers: sdhc: sdhc_spi: rework CMD12 failure logic
Rework CMD12 failure logic for SDHC SPI driver. Previously, the error
code of CMD12 was not checked, so even if CMD12 failed to send the
initial command would be retried. Change this behavior to retry CMD12
until it succeeds. If CMD12 fails, its error code will be propagated to
the caller. Otherwise, the return code from the command being sent by
the caller will be propagated.

Fixes #72365

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-05-17 09:30:12 +02:00
Daniel DeGrasse
cb9d8bac54 drivers: sdhc: sdhc_spi: release bus on error
Properly release SPI bus on transmit error within the SDHC SPI driver.
In these cases return code is not checked, as we wish to return the
error code from the failed transfer to the SD stack.

Fixes #72364

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-05-17 09:30:12 +02:00
Pisit Sawangvonganan
e7875de3f9 drivers: sdhc: set 'sdhc_driver_api' as 'static const'
This change marks each instance of the 'api' as 'static const'.
The rationale is that 'api' is used for declaring internal
module interfaces and is not intended to be modified at runtime.
By using 'static const', we ensure immutability, leading to usage of only
.rodata and a reduction in the .data area.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-01-24 21:25:06 +00:00
Daniel DeGrasse
429188723e drivers: sdhc: sdhc_spi: wait for card response until cmd timeout
In sdhc_spi_response_get, the logic for slow cards previously only
retried reads 16 times. Instead of using this approach, read from the
card every 10 ms until the command timeout is reached or it responds.
This way, the command timeout will be respected for cards that do not
respond.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-01-20 12:44:02 +01:00
Daniel DeGrasse
f9daa0397c drivers: sdhc: enable pwr-gpios property within SPI SDHC driver
Enable SPI SDHC driver to manage card power via pwr-gpios property.
Control for this property was previously partially implemented. When
this property is present, the SPI SDHC driver will use it to control
power to the SD card.

Power is toggled during SD init, so this power control can make SD init
more reliable as the power toggle will insure the SD card state is reset.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-07-28 09:07:55 +00:00
Łukasz Hejnak (LeHack)
1929eb3af7 drivers: sdhc: add support for using CPOL/CPHA SPI clock modes
Make it possible to use CPOL/CPHA SPI clock modes with the SDHC driver.
Some cards require the clock to switch to low when not active.

Signed-off-by: Łukasz Hejnak (LeHack) <lehack-ghub@lehack.pl>
2023-04-26 20:07:53 +02:00
Daniel DeGrasse
01b9a9cdbb drivers: sdhc: add support for configurable power on delay to SPI SDHC
Add support for configuring power on delay when using SPI SDHC. This
allows cards that reliably initialize with a shorter (1ms) delay to
avoid the long initialize delay otherwise imposed.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-03-03 09:18:47 +01:00
Ivan Herrera Olivares
2c2b8c3422 SD: Implement sdhc_card_busy in SDHC SPI-driver
Currently, the sdhc_card_busy function is unimplemented in the
SDHC SPI-driver. This causes some functions which rely on f_sync(),
such as fs_close(), to fail as it will timeout the busy-check. This PR
implements sdhc_card_busy by checking if the MISO-line is kept high to
check if the SD-card is idle (not busy).

Solves https://github.com/zephyrproject-rtos/zephyr/issues/49982

Signed-off-by: Ivan Herrera Olivares <ivan.herreraolivares@uantwerpen.be>
2022-09-09 16:32:52 -04:00
Kumar Gala
355da1dd84 drivers: sdhc: Rework SPI config initialization
Move to using SPI_CONFIG_DT_INST macro to initialization the
struct spi_config cfg_a.  This fixes an issue with how the old
code was initializing the deprecated fields of spi_cs_control.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-06-29 14:59:43 +00: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
a3182ced7a drivers: sdhc: add SD SPI mode host controller driver
Add SDHC driver implementing spi mode support for SD cards. This driver
implements the standard SD host controller APIs, and sets the host
property "is_spi" to indicate to the SD subsystem the card will be
running in SPI mode.

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