Skip to content

Commit 1929eb3

Browse files
LeHackcarlescufi
authored andcommitted
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>
1 parent 7951078 commit 1929eb3

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

drivers/sdhc/sdhc_spi.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,10 @@ static struct sdhc_driver_api sdhc_spi_api = {
768768
\
769769
struct sdhc_spi_data sdhc_spi_data_##n = { \
770770
.cfg_a = SPI_CONFIG_DT_INST(n, \
771-
(SPI_LOCK_ON | SPI_HOLD_ON_CS | SPI_WORD_SET(8)),\
771+
(SPI_LOCK_ON | SPI_HOLD_ON_CS | SPI_WORD_SET(8) \
772+
| (DT_INST_PROP(n, spi_clock_mode_cpol) ? SPI_MODE_CPOL : 0) \
773+
| (DT_INST_PROP(n, spi_clock_mode_cpha) ? SPI_MODE_CPHA : 0) \
774+
),\
772775
0), \
773776
}; \
774777
\

dts/bindings/sdhc/zephyr,sdhc-spi-slot.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,18 @@ properties:
1313
delay gives the card time to power up or down fully. It can be increased
1414
if you observe issues initializing your card.
1515
16+
spi-clock-mode-cpol:
17+
type: boolean
18+
description: |
19+
Clock polarity to use for SPI SDHC. Some cards respond properly
20+
only when the clock goes low when not active.
21+
22+
spi-clock-mode-cpha:
23+
type: boolean
24+
description: |
25+
Clock phase: this dictates when is the data captured, and depends
26+
on the clock's polarity. When mode-cpol is set and this option as well,
27+
capture will occur on low to high transition and high to low if
28+
this option is not set (default).
29+
1630
bus: sd
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_SPI=y
2+
CONFIG_DISK_DRIVER_SDMMC=y
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2023 Łukasz Hejnak (LeHack) <lehack-ghub@lehack.pl>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&spi1 {
8+
sdhc0: sdhc@0 {
9+
compatible = "zephyr,sdhc-spi-slot";
10+
reg = <0>;
11+
status = "okay";
12+
mmc {
13+
compatible = "zephyr,sdmmc-disk";
14+
status = "okay";
15+
};
16+
spi-max-frequency = <25000000>;
17+
spi-clock-mode-cpol;
18+
spi-clock-mode-cpha;
19+
};
20+
};

0 commit comments

Comments
 (0)