Skip to content

Commit 461664a

Browse files
committed
drivers: sdhc: split caps into standard and extra
Make sure the capabilities bitfield fits the standard SD Association specification and move the extra capabilities to props. Affected Drivers: - ifx_cat1_sdio - imx_usdhc - intel_emmc_host - rcar_mmc - sdhc_ambiq - sdhc_esp32 - sdhc_max32 - sdhc_renesas_ra - 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 <a-singh7@ti.com>
1 parent 3aeb76a commit 461664a

File tree

11 files changed

+117
-105
lines changed

11 files changed

+117
-105
lines changed

drivers/sdhc/ifx_cat1_sdio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static int ifx_cat1_sdio_get_host_props(const struct device *dev, struct sdhc_ho
208208
memset(props, 0, sizeof(*props));
209209
props->f_max = IFX_CAT1_SDIO_F_MAX;
210210
props->f_min = IFX_CAT1_SDIO_F_MIN;
211-
props->host_caps.bus_4_bit_support = true;
211+
props->bus_4_bit_support = true;
212212
props->host_caps.high_spd_support = true;
213213
props->host_caps.sdr50_support = true;
214214
props->host_caps.sdio_async_interrupt_support = true;

drivers/sdhc/imx_usdhc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ static void imx_usdhc_init_host_props(const struct device *dev)
260260
props->host_caps.sdr104_support = (bool)(caps.flags & kUSDHC_SupportSDR104Flag);
261261
props->host_caps.sdr50_support = (bool)(caps.flags & kUSDHC_SupportSDR50Flag);
262262
props->host_caps.bus_8_bit_support = (bool)(caps.flags & kUSDHC_Support8BitFlag);
263-
props->host_caps.bus_4_bit_support = (bool)(caps.flags & kUSDHC_Support4BitFlag);
264-
props->host_caps.hs200_support = (bool)(cfg->mmc_hs200_1_8v);
265-
props->host_caps.hs400_support = (bool)(cfg->mmc_hs400_1_8v);
263+
props->bus_4_bit_support = (bool)(caps.flags & kUSDHC_Support4BitFlag);
264+
props->hs200_support = (bool)(cfg->mmc_hs200_1_8v);
265+
props->hs400_support = (bool)(cfg->mmc_hs400_1_8v);
266266
}
267267

268268
/*

drivers/sdhc/intel_emmc_host.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,9 +1168,9 @@ static int emmc_get_host_props(const struct device *dev, struct sdhc_host_props
11681168
props->host_caps.sdr104_support = (bool)(cap & BIT(33u));
11691169
props->host_caps.sdr50_support = (bool)(cap & BIT(32u));
11701170
props->host_caps.bus_8_bit_support = true;
1171-
props->host_caps.bus_4_bit_support = true;
1172-
props->host_caps.hs200_support = (bool)config->hs200_mode;
1173-
props->host_caps.hs400_support = (bool)config->hs400_mode;
1171+
props->bus_4_bit_support = true;
1172+
props->hs200_support = (bool)config->hs200_mode;
1173+
props->hs400_support = (bool)config->hs400_mode;
11741174

11751175
emmc->props = *props;
11761176

drivers/sdhc/rcar_mmc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ static int rcar_mmc_set_bus_width(const struct device *dev, struct sdhc_io *ios)
12061206
reg_width = RCAR_MMC_OPTION_WIDTH_1;
12071207
break;
12081208
case SDHC_BUS_WIDTH4BIT:
1209-
if (data->props.host_caps.bus_4_bit_support) {
1209+
if (data->props.bus_4_bit_support) {
12101210
reg_width = RCAR_MMC_OPTION_WIDTH_4;
12111211
} else {
12121212
LOG_ERR("SDHC I/O: 4-bits bus width isn't supported");
@@ -1331,7 +1331,7 @@ static int rcar_mmc_set_timings(const struct device *dev, struct sdhc_io *ios)
13311331
}
13321332
break;
13331333
case SDHC_TIMING_HS400:
1334-
if (!data->props.host_caps.hs400_support) {
1334+
if (!data->props.hs400_support) {
13351335
LOG_ERR("SDHC I/O: HS400 timing isn't supported");
13361336
return -ENOTSUP;
13371337
}
@@ -1347,7 +1347,7 @@ static int rcar_mmc_set_timings(const struct device *dev, struct sdhc_io *ios)
13471347
data->ddr_mode = 1;
13481348
break;
13491349
case SDHC_TIMING_HS200:
1350-
if (!data->props.host_caps.hs200_support) {
1350+
if (!data->props.hs200_support) {
13511351
LOG_ERR("SDHC I/O: HS200 timing isn't supported");
13521352
return -ENOTSUP;
13531353
}
@@ -1947,7 +1947,7 @@ static void rcar_mmc_init_host_props(const struct device *dev)
19471947
case SDHC_BUS_WIDTH8BIT:
19481948
host_caps->bus_8_bit_support = 1;
19491949
case SDHC_BUS_WIDTH4BIT:
1950-
host_caps->bus_4_bit_support = 1;
1950+
props->bus_4_bit_support = 1;
19511951
default:
19521952
break;
19531953
}
@@ -1958,9 +1958,9 @@ static void rcar_mmc_init_host_props(const struct device *dev)
19581958
host_caps->sdr50_support = cfg->uhs_support;
19591959
/* neither Linux nor U-boot support DDR50 mode, that's why we don't support it too */
19601960
host_caps->ddr50_support = 0;
1961-
host_caps->hs200_support = cfg->mmc_hs200_1_8v;
1961+
props->hs200_support = cfg->mmc_hs200_1_8v;
19621962
/* TODO: add support */
1963-
host_caps->hs400_support = 0;
1963+
props->hs400_support = 0;
19641964
#endif
19651965

19661966
host_caps->vol_330_support =

drivers/sdhc/sdhc_ambiq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ static int ambiq_sdio_get_host_props(const struct device *dev, struct sdhc_host_
164164
props->host_caps.adma_2_support = true;
165165
props->host_caps.sdio_async_interrupt_support = true;
166166
props->host_caps.vol_180_support = true;
167-
props->host_caps.bus_4_bit_support = true;
168167
props->host_caps.bus_8_bit_support = true;
169168
props->host_caps.high_spd_support = true;
170169
props->host_caps.sdr50_support = true;
171170
props->host_caps.sdr104_support = true;
172171
props->host_caps.ddr50_support = true;
173-
props->host_caps.hs200_support = true;
172+
props->bus_4_bit_support = true;
173+
props->hs200_support = true;
174174
props->max_current_330 = 1020;
175175
props->max_current_300 = 1020;
176176
props->max_current_180 = 1020;

drivers/sdhc/sdhc_esp32.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,13 +1426,16 @@ static DEVICE_API(sdhc, sdhc_api) = {
14261426
.d1_pin = DT_INST_PROP_OR(n, d1_pin, GPIO_NUM_NC), \
14271427
.d2_pin = DT_INST_PROP_OR(n, d2_pin, GPIO_NUM_NC), \
14281428
.d3_pin = DT_INST_PROP_OR(n, d3_pin, GPIO_NUM_NC), \
1429-
.props = {.is_spi = false, \
1430-
.f_max = DT_INST_PROP(n, max_bus_freq), \
1431-
.f_min = DT_INST_PROP(n, min_bus_freq), \
1432-
.max_current_330 = DT_INST_PROP(n, max_current_330), \
1433-
.max_current_180 = DT_INST_PROP(n, max_current_180), \
1434-
.power_delay = DT_INST_PROP_OR(n, power_delay_ms, 0), \
1435-
.host_caps = {.vol_180_support = false, \
1429+
.props = { \
1430+
.is_spi = false, \
1431+
.f_max = DT_INST_PROP(n, max_bus_freq), \
1432+
.f_min = DT_INST_PROP(n, min_bus_freq), \
1433+
.max_current_330 = DT_INST_PROP(n, max_current_330), \
1434+
.max_current_180 = DT_INST_PROP(n, max_current_180), \
1435+
.power_delay = DT_INST_PROP_OR(n, power_delay_ms, 0), \
1436+
.host_caps = \
1437+
{ \
1438+
.vol_180_support = false, \
14361439
.vol_300_support = false, \
14371440
.vol_330_support = true, \
14381441
.suspend_res_support = false, \
@@ -1445,10 +1448,11 @@ static DEVICE_API(sdhc, sdhc_api) = {
14451448
.sdr104_support = false, \
14461449
.sdr50_support = false, \
14471450
.bus_8_bit_support = false, \
1448-
.bus_4_bit_support = \
1449-
(DT_INST_PROP(n, bus_width) == 4) ? true : false, \
1450-
.hs200_support = false, \
1451-
.hs400_support = false}}}; \
1451+
}, \
1452+
.bus_4_bit_support = (DT_INST_PROP(n, bus_width) == 4) ? true : false, \
1453+
.hs200_support = false, \
1454+
.hs400_support = false, \
1455+
}}; \
14521456
\
14531457
static struct sdhc_esp32_data sdhc_esp32_##n##_data = { \
14541458
.bus_width = SDMMC_SLOT_WIDTH_DEFAULT, \

drivers/sdhc/sdhc_max32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void sdhc_max32_init_props(const struct device *dev)
9494
sdhc_data->props.host_caps.sd_base_clk = 0x00;
9595
sdhc_data->props.host_caps.max_blk_len = 0b10;
9696
sdhc_data->props.host_caps.bus_8_bit_support = false;
97-
sdhc_data->props.host_caps.bus_4_bit_support = false;
97+
sdhc_data->props.bus_4_bit_support = false;
9898
sdhc_data->props.host_caps.adma_2_support = true;
9999
sdhc_data->props.host_caps.high_spd_support = true;
100100
sdhc_data->props.host_caps.sdma_support = true;
@@ -119,8 +119,8 @@ static void sdhc_max32_init_props(const struct device *dev)
119119
sdhc_data->props.host_caps.clk_multiplier = 0;
120120
sdhc_data->props.host_caps.adma3_support = false;
121121
sdhc_data->props.host_caps.vdd2_180_support = false;
122-
sdhc_data->props.host_caps.hs200_support = false;
123-
sdhc_data->props.host_caps.hs400_support = false;
122+
sdhc_data->props.hs200_support = false;
123+
sdhc_data->props.hs400_support = false;
124124
sdhc_data->props.power_delay = sdhc_config->power_delay_ms;
125125
}
126126

drivers/sdhc/sdhc_renesas_ra.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -694,31 +694,37 @@ static DEVICE_API(sdhc, sdhc_api) = {
694694
.p_extend = NULL, \
695695
.p_lower_lvl_transfer = &sdhc_ra_priv_##index.transfer, \
696696
}, \
697-
.props = {.is_spi = false, \
698-
.f_max = DT_INST_PROP(index, max_bus_freq), \
699-
.f_min = DT_INST_PROP(index, min_bus_freq), \
700-
.max_current_330 = DT_INST_PROP(index, max_current_330), \
701-
.max_current_180 = DT_INST_PROP(index, max_current_180), \
702-
.power_delay = DT_INST_PROP_OR(index, power_delay_ms, 0), \
703-
.host_caps = {.vol_180_support = false, \
704-
.vol_300_support = false, \
705-
.vol_330_support = true, \
706-
.suspend_res_support = false, \
707-
.sdma_support = true, \
708-
.high_spd_support = (DT_INST_PROP(index, bus_width) == 4) \
709-
? true \
710-
: false, \
711-
.adma_2_support = false, \
712-
.max_blk_len = 0, \
713-
.ddr50_support = false, \
714-
.sdr104_support = false, \
715-
.sdr50_support = false, \
716-
.bus_8_bit_support = false, \
717-
.bus_4_bit_support = (DT_INST_PROP(index, bus_width) == 4) \
718-
? true \
719-
: false, \
720-
.hs200_support = false, \
721-
.hs400_support = false}}, \
697+
.props = \
698+
{ \
699+
.is_spi = false, \
700+
.f_max = DT_INST_PROP(index, max_bus_freq), \
701+
.f_min = DT_INST_PROP(index, min_bus_freq), \
702+
.max_current_330 = DT_INST_PROP(index, max_current_330), \
703+
.max_current_180 = DT_INST_PROP(index, max_current_180), \
704+
.power_delay = DT_INST_PROP_OR(index, power_delay_ms, 0), \
705+
.host_caps = \
706+
{ \
707+
.vol_180_support = false, \
708+
.vol_300_support = false, \
709+
.vol_330_support = true, \
710+
.suspend_res_support = false, \
711+
.sdma_support = true, \
712+
.high_spd_support = \
713+
(DT_INST_PROP(index, bus_width) == 4) \
714+
? true \
715+
: false, \
716+
.adma_2_support = false, \
717+
.max_blk_len = 0, \
718+
.ddr50_support = false, \
719+
.sdr104_support = false, \
720+
.sdr50_support = false, \
721+
.bus_8_bit_support = false, \
722+
}, \
723+
.bus_4_bit_support = \
724+
(DT_INST_PROP(index, bus_width) == 4) ? true : false, \
725+
.hs200_support = false, \
726+
.hs400_support = false, \
727+
}, \
722728
RA_SDHI_EN(index), \
723729
RA_SDMMC_DTC_STRUCT_INIT(index)}; \
724730
\

drivers/sdhc/xlnx_sdhc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,14 @@ static int xlnx_sdhc_host_props(const struct device *dev, struct sdhc_host_props
587587
XLNX_SDHC_SLOT_TYPE_GET);
588588
props->host_caps.bus_8_bit_support = XLNX_SDHC_GET_HOST_PROP_BIT(cap,
589589
XLNX_SDHC_8BIT_SUPPORT);
590-
props->host_caps.bus_4_bit_support = XLNX_SDHC_GET_HOST_PROP_BIT(cap,
590+
props->bus_4_bit_support = XLNX_SDHC_GET_HOST_PROP_BIT(cap,
591591
XLNX_SDHC_4BIT_SUPPORT);
592592

593593
if ((cap & CHECK_BITS(XLNX_SDHC_SDR400_SUPPORT)) != 0U) {
594-
props->host_caps.hs400_support = (uint8_t)config->hs400_mode;
594+
props->hs400_support = (uint8_t)config->hs400_mode;
595595
dev_data->has_phy = true;
596596
}
597-
props->host_caps.hs200_support = (uint8_t)config->hs200_mode;
597+
props->hs200_support = (uint8_t)config->hs200_mode;
598598

599599
dev_data->props = *props;
600600

include/zephyr/drivers/sdhc.h

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -158,46 +158,45 @@ enum sd_voltage {
158158
* @brief SD host controller capabilities
159159
*
160160
* SD host controller capability flags. These flags should be set by the SDHC
161-
* driver, using the @ref sdhc_get_host_props api.
161+
* driver, using the @ref sdhc_get_host_props api. These are packed to fit the capabilities register
162+
* in the standard specification by the SD Association.
162163
*/
163164
struct sdhc_host_caps {
164-
unsigned int timeout_clk_freq: 6; /**< Timeout clock frequency */
165-
unsigned int _rsvd_6: 1; /**< Reserved */
166-
unsigned int timeout_clk_unit: 1; /**< Timeout clock unit */
167-
unsigned int sd_base_clk: 8; /**< SD base clock frequency */
168-
unsigned int max_blk_len: 2; /**< Max block length */
169-
unsigned int bus_8_bit_support: 1; /**< 8-bit Support for embedded device */
170-
unsigned int bus_4_bit_support: 1; /**< 4 bit bus support */
171-
unsigned int adma_2_support: 1; /**< ADMA2 support */
172-
unsigned int _rsvd_20: 1; /**< Reserved */
173-
unsigned int high_spd_support: 1; /**< High speed support */
174-
unsigned int sdma_support: 1; /**< SDMA support */
175-
unsigned int suspend_res_support: 1; /**< Suspend/Resume support */
176-
unsigned int vol_330_support: 1; /**< Voltage support 3.3V */
177-
unsigned int vol_300_support: 1; /**< Voltage support 3.0V */
178-
unsigned int vol_180_support: 1; /**< Voltage support 1.8V */
179-
unsigned int address_64_bit_support_v4: 1; /**< 64-bit system address support for V4 */
180-
unsigned int address_64_bit_support_v3: 1; /**< 64-bit system address support for V3 */
181-
unsigned int sdio_async_interrupt_support: 1; /**< Asynchronous interrupt support */
182-
unsigned int slot_type: 2; /**< Slot type */
183-
unsigned int sdr50_support: 1; /**< SDR50 support */
184-
unsigned int sdr104_support: 1; /**< SDR104 support */
185-
unsigned int ddr50_support: 1; /**< DDR50 support */
186-
unsigned int uhs_2_support: 1; /**< UHS-II support */
187-
unsigned int drv_type_a_support: 1; /**< Driver type A support */
188-
unsigned int drv_type_c_support: 1; /**< Driver type C support */
189-
unsigned int drv_type_d_support: 1; /**< Driver type D support */
190-
unsigned int _rsvd_39: 1; /**< Reserved */
191-
unsigned int retune_timer_count: 4; /**< Timer count for re-tuning */
192-
unsigned int sdr50_needs_tuning: 1; /**< Use tuning for SDR50 */
193-
unsigned int retuning_mode: 2; /**< Re-tuning mode */
194-
unsigned int clk_multiplier: 8; /**< Clock multiplier */
195-
unsigned int _rsvd_56: 3; /**< Reserved */
196-
unsigned int adma3_support: 1; /**< ADMA3 support */
197-
unsigned int vdd2_180_support: 1; /**< 1.8V VDD2 support */
198-
unsigned int _rsvd_61: 3; /**< Reserved */
199-
unsigned int hs200_support: 1; /**< HS200 support */
200-
unsigned int hs400_support: 1; /**< HS400 support */
165+
unsigned int timeout_clk_freq: 6; /**< Timeout clock frequency */
166+
unsigned int _rsvd_6: 1; /**< Reserved */
167+
unsigned int timeout_clk_unit: 1; /**< Timeout clock unit */
168+
unsigned int sd_base_clk: 8; /**< SD base clock frequency */
169+
unsigned int max_blk_len: 2; /**< Max block length */
170+
unsigned int bus_8_bit_support: 1; /**< 8-bit Support for embedded device */
171+
unsigned int adma_2_support: 1; /**< ADMA2 support */
172+
unsigned int _rsvd_20: 1; /**< Reserved */
173+
unsigned int high_spd_support: 1; /**< High speed support */
174+
unsigned int sdma_support: 1; /**< SDMA support */
175+
unsigned int suspend_res_support: 1; /**< Suspend/Resume support */
176+
unsigned int vol_330_support: 1; /**< Voltage support 3.3V */
177+
unsigned int vol_300_support: 1; /**< Voltage support 3.0V */
178+
unsigned int vol_180_support: 1; /**< Voltage support 1.8V */
179+
unsigned int address_64_bit_support_v4: 1; /**< 64-bit system address support for V4 */
180+
unsigned int address_64_bit_support_v3: 1; /**< 64-bit system address support for V3 */
181+
unsigned int sdio_async_interrupt_support: 1; /**< Asynchronous interrupt support */
182+
unsigned int slot_type: 2; /**< Slot type */
183+
unsigned int sdr50_support: 1; /**< SDR50 support */
184+
unsigned int sdr104_support: 1; /**< SDR104 support */
185+
unsigned int ddr50_support: 1; /**< DDR50 support */
186+
unsigned int uhs_2_support: 1; /**< UHS-II support */
187+
unsigned int drv_type_a_support: 1; /**< Driver type A support */
188+
unsigned int drv_type_c_support: 1; /**< Driver type C support */
189+
unsigned int drv_type_d_support: 1; /**< Driver type D support */
190+
unsigned int _rsvd_39: 1; /**< Reserved */
191+
unsigned int retune_timer_count: 4; /**< Timer count for re-tuning */
192+
unsigned int _rsvd_44: 1; /**< Reserved */
193+
unsigned int sdr50_needs_tuning: 1; /**< Use tuning for SDR50 */
194+
unsigned int retuning_mode: 2; /**< Re-tuning mode */
195+
unsigned int clk_multiplier: 8; /**< Clock multiplier */
196+
unsigned int _rsvd_56: 3; /**< Reserved */
197+
unsigned int adma3_support: 1; /**< ADMA3 support */
198+
unsigned int vdd2_180_support: 1; /**< 1.8V VDD2 support */
199+
unsigned int _rsvd_61: 3; /**< Reserved */
201200
};
202201

203202
/**
@@ -223,14 +222,17 @@ struct sdhc_io {
223222
* Populated by the host controller using @ref sdhc_get_host_props api.
224223
*/
225224
struct sdhc_host_props {
226-
unsigned int f_max; /*!< Max bus frequency */
227-
unsigned int f_min; /*!< Min bus frequency */
228-
unsigned int power_delay; /*!< Delay to allow SD to power up or down (in ms) */
225+
unsigned int f_max; /*!< Max bus frequency */
226+
unsigned int f_min; /*!< Min bus frequency */
227+
unsigned int power_delay; /*!< Delay to allow SD to power up or down (in ms) */
229228
struct sdhc_host_caps host_caps; /*!< Host capability bitfield */
230-
uint32_t max_current_330; /*!< Max current (in mA) at 3.3V */
231-
uint32_t max_current_300; /*!< Max current (in mA) at 3.0V */
232-
uint32_t max_current_180; /*!< Max current (in mA) at 1.8V */
233-
bool is_spi; /*!< Is the host using SPI mode */
229+
uint32_t max_current_330; /*!< Max current (in mA) at 3.3V */
230+
uint32_t max_current_300; /*!< Max current (in mA) at 3.0V */
231+
uint32_t max_current_180; /*!< Max current (in mA) at 1.8V */
232+
bool bus_4_bit_support; /**< 4 bit bus support */
233+
bool hs200_support; /**< HS200 support */
234+
bool hs400_support; /**< HS400 support */
235+
bool is_spi; /*!< Is the host using SPI mode */
234236
};
235237

236238
/**

0 commit comments

Comments
 (0)