Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
sdhc.h
Go to the documentation of this file.
1/*
2 * Copyright 2022, 2025 NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_SDHC_H_
14#define ZEPHYR_INCLUDE_DRIVERS_SDHC_H_
15
16#include <errno.h>
17#include <zephyr/device.h>
18#include <zephyr/net_buf.h>
19#include <zephyr/sd/sd_spec.h>
20
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34
39#define SDHC_TIMEOUT_FOREVER (-1)
41
56
57#define SDHC_NATIVE_RESPONSE_MASK 0xF
58#define SDHC_SPI_RESPONSE_TYPE_MASK 0xF0
59
66struct sdhc_data {
67 unsigned int block_addr;
68 unsigned int block_size;
69 unsigned int blocks;
70 unsigned int bytes_xfered;
71#if defined(CONFIG_SDHC_SCATTER_GATHER_TRANSFER) || defined(__DOXYGEN__)
73#endif
74 void *data;
76};
77
89
101
113
143
161
170 unsigned int timeout_clk_freq: 6;
171 unsigned int _rsvd_6: 1;
172 unsigned int timeout_clk_unit: 1;
173 unsigned int sd_base_clk: 8;
174 unsigned int max_blk_len: 2;
175 unsigned int bus_8_bit_support: 1;
176 unsigned int adma_2_support: 1;
177 unsigned int _rsvd_20: 1;
178 unsigned int high_spd_support: 1;
179 unsigned int sdma_support: 1;
180 unsigned int suspend_res_support: 1;
181 unsigned int vol_330_support: 1;
182 unsigned int vol_300_support: 1;
183 unsigned int vol_180_support: 1;
187 unsigned int slot_type: 2;
188 unsigned int sdr50_support: 1;
189 unsigned int sdr104_support: 1;
190 unsigned int ddr50_support: 1;
191 unsigned int uhs_2_support: 1;
192 unsigned int drv_type_a_support: 1;
193 unsigned int drv_type_c_support: 1;
194 unsigned int drv_type_d_support: 1;
195 unsigned int _rsvd_39: 1;
196 unsigned int retune_timer_count: 4;
197 unsigned int _rsvd_44: 1;
198 unsigned int sdr50_needs_tuning: 1;
199 unsigned int retuning_mode: 2;
200 unsigned int clk_multiplier: 8;
201 unsigned int _rsvd_56: 3;
202 unsigned int adma3_support: 1;
203 unsigned int vdd2_180_support: 1;
204 unsigned int _rsvd_61: 3;
205};
206
224
244
255
264typedef void (*sdhc_interrupt_cb_t)(const struct device *dev, int reason,
265 const void *user_data);
266
272
276__subsystem struct sdhc_driver_api {
278 int (*reset)(const struct device *dev);
280 int (*request)(const struct device *dev,
281 struct sdhc_command *cmd,
282 struct sdhc_data *data);
284 int (*set_io)(const struct device *dev, struct sdhc_io *ios);
286 int (*get_card_present)(const struct device *dev);
288 int (*execute_tuning)(const struct device *dev);
290 int (*card_busy)(const struct device *dev);
292 int (*get_host_props)(const struct device *dev,
293 struct sdhc_host_props *props);
295 int (*enable_interrupt)(const struct device *dev,
296 sdhc_interrupt_cb_t callback,
297 int sources, void *user_data);
299 int (*disable_interrupt)(const struct device *dev, int sources);
300};
301
303
317__syscall int sdhc_hw_reset(const struct device *dev);
318
319static inline int z_impl_sdhc_hw_reset(const struct device *dev)
320{
321 const struct sdhc_driver_api *api = DEVICE_API_GET(sdhc, dev);
322
323 if (!api->reset) {
324 return -ENOSYS;
325 }
326
327 return api->reset(dev);
328}
329
330
343__syscall int sdhc_request(const struct device *dev, struct sdhc_command *cmd,
344 struct sdhc_data *data);
345
346static inline int z_impl_sdhc_request(const struct device *dev,
347 struct sdhc_command *cmd,
348 struct sdhc_data *data)
349{
350 const struct sdhc_driver_api *api = DEVICE_API_GET(sdhc, dev);
351
352 return api->request(dev, cmd, data);
353}
354
368__syscall int sdhc_set_io(const struct device *dev, struct sdhc_io *io);
369
370static inline int z_impl_sdhc_set_io(const struct device *dev,
371 struct sdhc_io *io)
372{
373 const struct sdhc_driver_api *api = DEVICE_API_GET(sdhc, dev);
374
375 return api->set_io(dev, io);
376}
377
389__syscall int sdhc_card_present(const struct device *dev);
390
391static inline int z_impl_sdhc_card_present(const struct device *dev)
392{
393 const struct sdhc_driver_api *api = DEVICE_API_GET(sdhc, dev);
394
395 return api->get_card_present(dev);
396}
397
398
410__syscall int sdhc_execute_tuning(const struct device *dev);
411
412static inline int z_impl_sdhc_execute_tuning(const struct device *dev)
413{
414 const struct sdhc_driver_api *api = DEVICE_API_GET(sdhc, dev);
415
416 if (!api->execute_tuning) {
417 return -ENOSYS;
418 }
419
420 return api->execute_tuning(dev);
421}
422
434__syscall int sdhc_card_busy(const struct device *dev);
435
436static inline int z_impl_sdhc_card_busy(const struct device *dev)
437{
438 const struct sdhc_driver_api *api = DEVICE_API_GET(sdhc, dev);
439
440 return api->card_busy(dev);
441}
442
443
454__syscall int sdhc_get_host_props(const struct device *dev,
455 struct sdhc_host_props *props);
456
457static inline int z_impl_sdhc_get_host_props(const struct device *dev,
458 struct sdhc_host_props *props)
459{
460 const struct sdhc_driver_api *api = DEVICE_API_GET(sdhc, dev);
461
462 return api->get_host_props(dev, props);
463}
464
481__syscall int sdhc_enable_interrupt(const struct device *dev,
482 sdhc_interrupt_cb_t callback,
483 int sources, void *user_data);
484
485static inline int z_impl_sdhc_enable_interrupt(const struct device *dev,
486 sdhc_interrupt_cb_t callback,
487 int sources, void *user_data)
488{
489 const struct sdhc_driver_api *api = DEVICE_API_GET(sdhc, dev);
490
491 if (!api->enable_interrupt) {
492 return -ENOSYS;
493 }
494
495 return api->enable_interrupt(dev, callback, sources, user_data);
496}
497
510__syscall int sdhc_disable_interrupt(const struct device *dev, int sources);
511
512static inline int z_impl_sdhc_disable_interrupt(const struct device *dev,
513 int sources)
514{
515 const struct sdhc_driver_api *api = DEVICE_API_GET(sdhc, dev);
516
517 if (!api->disable_interrupt) {
518 return -ENOSYS;
519 }
520
521 return api->disable_interrupt(dev, sources);
522}
523
527
528#ifdef __cplusplus
529}
530#endif
531
532#include <zephyr/syscalls/sdhc.h>
533#endif /* ZEPHYR_INCLUDE_DRIVERS_SDHC_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
System error numbers.
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition ft8xx_reference_api.h:153
int sdhc_set_io(const struct device *dev, struct sdhc_io *io)
set I/O properties of SDHC
sd_voltage
SD voltage.
Definition sdhc.h:151
void(* sdhc_interrupt_cb_t)(const struct device *dev, int reason, const void *user_data)
SDHC card interrupt callback prototype.
Definition sdhc.h:264
int sdhc_disable_interrupt(const struct device *dev, int sources)
Disable SDHC interrupt sources.
sdhc_timing_mode
SD host controller timing mode.
Definition sdhc.h:121
int sdhc_card_present(const struct device *dev)
check for SDHC card presence
int sdhc_enable_interrupt(const struct device *dev, sdhc_interrupt_cb_t callback, int sources, void *user_data)
Enable SDHC interrupt sources.
int sdhc_card_busy(const struct device *dev)
check if SD card is busy
sdhc_interrupt_source
SD host controller interrupt sources.
Definition sdhc.h:250
int sdhc_get_host_props(const struct device *dev, struct sdhc_host_props *props)
Get SD host controller properties.
int sdhc_execute_tuning(const struct device *dev)
run SDHC tuning
int sdhc_request(const struct device *dev, struct sdhc_command *cmd, struct sdhc_data *data)
Send command to SDHC.
sdhc_power
SD host controller power.
Definition sdhc.h:97
int sdhc_hw_reset(const struct device *dev)
reset SDHC controller state
sdhc_bus_width
SD host controller bus width.
Definition sdhc.h:108
sdhc_bus_mode
SD bus mode.
Definition sdhc.h:85
@ SD_VOL_3_3_V
card operation voltage around 3.3v
Definition sdhc.h:152
@ SD_VOL_1_2_V
card operation voltage around 1.2v
Definition sdhc.h:158
@ SD_VOL_3_0_V
card operation voltage around 3.0v
Definition sdhc.h:154
@ SD_VOL_1_8_V
card operation voltage around 1.8v
Definition sdhc.h:156
@ SDHC_TIMING_HS400
HS400 mode.
Definition sdhc.h:140
@ SDHC_TIMING_DDR52
DDR52 mode.
Definition sdhc.h:136
@ SDHC_TIMING_SDR50
SDR49 mode.
Definition sdhc.h:130
@ SDHC_TIMING_LEGACY
Legacy 3.3V Mode.
Definition sdhc.h:122
@ SDHC_TIMING_SDR25
High speed mode & SDR25.
Definition sdhc.h:128
@ SDHC_TIMING_SDR12
Identification mode & SDR12.
Definition sdhc.h:126
@ SDHC_TIMING_SDR104
SDR104 mode.
Definition sdhc.h:132
@ SDHC_TIMING_HS200
HS200 mode.
Definition sdhc.h:138
@ SDHC_TIMING_HS
Legacy High speed mode (3.3V).
Definition sdhc.h:124
@ SDHC_TIMING_DDR50
DDR50 mode.
Definition sdhc.h:134
@ SDHC_INT_REMOVED
Card was removed from slot.
Definition sdhc.h:253
@ SDHC_INT_INSERTED
Card was inserted into slot.
Definition sdhc.h:252
@ SDHC_INT_SDIO
Card interrupt, used by SDIO cards.
Definition sdhc.h:251
@ SDHC_POWER_OFF
Definition sdhc.h:98
@ SDHC_POWER_ON
Definition sdhc.h:99
@ SDHC_BUS_WIDTH8BIT
Definition sdhc.h:111
@ SDHC_BUS_WIDTH4BIT
Definition sdhc.h:110
@ SDHC_BUS_WIDTH1BIT
Definition sdhc.h:109
@ SDHC_BUSMODE_OPENDRAIN
Definition sdhc.h:86
@ SDHC_BUSMODE_PUSHPULL
Definition sdhc.h:87
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ENOSYS
Function not implemented.
Definition errno.h:82
Buffer management.
sd_driver_type
SD driver types.
Definition sd_spec.h:476
sdhc_clock_speed
SD host controller clock speed.
Definition sd_spec.h:430
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
SD host controller command structure.
Definition sdhc.h:48
uint32_t opcode
SD Host specification CMD index.
Definition sdhc.h:49
uint32_t response[4]
SD card response field.
Definition sdhc.h:51
unsigned int retries
Max number of retries.
Definition sdhc.h:53
int timeout_ms
Command timeout in milliseconds.
Definition sdhc.h:54
uint32_t arg
SD host specification argument.
Definition sdhc.h:50
uint32_t response_type
Expected SD response type.
Definition sdhc.h:52
SD host controller data structure.
Definition sdhc.h:66
void * data
Data to transfer or receive.
Definition sdhc.h:74
unsigned int block_size
Block size.
Definition sdhc.h:68
unsigned int blocks
Number of blocks.
Definition sdhc.h:69
bool is_sg_data
Is scatter gather data using net_buf data structure.
Definition sdhc.h:72
unsigned int block_addr
Block to start read from.
Definition sdhc.h:67
unsigned int bytes_xfered
populated with number of bytes sent by SDHC
Definition sdhc.h:70
int timeout_ms
data timeout in milliseconds
Definition sdhc.h:75
<span class="mlabel">Driver Operations</span> SDHC driver operations
Definition sdhc.h:276
int(* get_card_present)(const struct device *dev)
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition sdhc.h:286
int(* enable_interrupt)(const struct device *dev, sdhc_interrupt_cb_t callback, int sources, void *user_data)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition sdhc.h:295
int(* request)(const struct device *dev, struct sdhc_command *cmd, struct sdhc_data *data)
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition sdhc.h:280
int(* execute_tuning)(const struct device *dev)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition sdhc.h:288
int(* disable_interrupt)(const struct device *dev, int sources)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition sdhc.h:299
int(* reset)(const struct device *dev)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition sdhc.h:278
int(* card_busy)(const struct device *dev)
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition sdhc.h:290
int(* set_io)(const struct device *dev, struct sdhc_io *ios)
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition sdhc.h:284
int(* get_host_props)(const struct device *dev, struct sdhc_host_props *props)
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition sdhc.h:292
SD host controller capabilities.
Definition sdhc.h:169
unsigned int address_64_bit_support_v3
64-bit system address support for V3
Definition sdhc.h:185
unsigned int uhs_2_support
UHS-II support.
Definition sdhc.h:191
unsigned int sd_base_clk
SD base clock frequency.
Definition sdhc.h:173
unsigned int sdma_support
SDMA support.
Definition sdhc.h:179
unsigned int vdd2_180_support
1.8V VDD2 support
Definition sdhc.h:203
unsigned int slot_type
Slot type.
Definition sdhc.h:187
unsigned int timeout_clk_freq
Timeout clock frequency.
Definition sdhc.h:170
unsigned int sdr104_support
SDR104 support.
Definition sdhc.h:189
unsigned int drv_type_a_support
Driver type A support.
Definition sdhc.h:192
unsigned int retuning_mode
Re-tuning mode.
Definition sdhc.h:199
unsigned int sdr50_support
SDR50 support.
Definition sdhc.h:188
unsigned int sdio_async_interrupt_support
Asynchronous interrupt support.
Definition sdhc.h:186
unsigned int vol_300_support
Voltage support 3.0V.
Definition sdhc.h:182
unsigned int timeout_clk_unit
Timeout clock unit.
Definition sdhc.h:172
unsigned int adma3_support
ADMA3 support.
Definition sdhc.h:202
unsigned int max_blk_len
Max block length.
Definition sdhc.h:174
unsigned int ddr50_support
DDR50 support.
Definition sdhc.h:190
unsigned int vol_180_support
Voltage support 1.8V.
Definition sdhc.h:183
unsigned int high_spd_support
High speed support.
Definition sdhc.h:178
unsigned int drv_type_c_support
Driver type C support.
Definition sdhc.h:193
unsigned int retune_timer_count
Timer count for re-tuning.
Definition sdhc.h:196
unsigned int sdr50_needs_tuning
Use tuning for SDR50.
Definition sdhc.h:198
unsigned int vol_330_support
Voltage support 3.3V.
Definition sdhc.h:181
unsigned int adma_2_support
ADMA2 support.
Definition sdhc.h:176
unsigned int bus_8_bit_support
8-bit Support for embedded device
Definition sdhc.h:175
unsigned int drv_type_d_support
Driver type D support.
Definition sdhc.h:194
unsigned int address_64_bit_support_v4
64-bit system address support for V4
Definition sdhc.h:184
unsigned int suspend_res_support
Suspend/Resume support.
Definition sdhc.h:180
unsigned int clk_multiplier
Clock multiplier.
Definition sdhc.h:200
SD host controller properties.
Definition sdhc.h:230
unsigned int f_min
Min bus frequency.
Definition sdhc.h:232
uint32_t max_current_180
Max current (in mA) at 1.8V.
Definition sdhc.h:237
bool bus_4_bit_support
4 bit bus support
Definition sdhc.h:238
bool hs200_support
HS200 support.
Definition sdhc.h:239
bool hs400_enhanced_strobe_support
HS400 enhanced strobe support.
Definition sdhc.h:241
unsigned int power_delay
Delay to allow SD to power up or down (in ms).
Definition sdhc.h:233
bool is_spi
Is the host using SPI mode.
Definition sdhc.h:242
uint32_t max_current_300
Max current (in mA) at 3.0V.
Definition sdhc.h:236
struct sdhc_host_caps host_caps
Host capability bitfield.
Definition sdhc.h:234
bool hs400_support
HS400 support.
Definition sdhc.h:240
unsigned int f_max
Max bus frequency.
Definition sdhc.h:231
uint32_t max_current_330
Max current (in mA) at 3.3V.
Definition sdhc.h:235
SD host controller I/O control structure.
Definition sdhc.h:214
enum sd_driver_type driver_type
SD driver type.
Definition sdhc.h:221
enum sdhc_bus_mode bus_mode
command output mode
Definition sdhc.h:216
enum sdhc_timing_mode timing
SD bus timing.
Definition sdhc.h:219
enum sdhc_bus_width bus_width
SD bus width.
Definition sdhc.h:218
enum sdhc_clock_speed clock
Clock rate.
Definition sdhc.h:215
enum sdhc_power power_mode
SD power supply mode.
Definition sdhc.h:217
enum sd_voltage signal_voltage
IO signalling voltage (usually 1.8 or 3.3V).
Definition sdhc.h:222
bool enhanced_strobe
eMMC HS400 enhanced strobe state
Definition sdhc.h:220