Zephyr API Documentation  3.6.0
A Scalable Open Source RTOS
3.6.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sdhc.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_DRIVERS_SDHC_H_
13#define ZEPHYR_INCLUDE_DRIVERS_SDHC_H_
14
15#include <errno.h>
16#include <zephyr/device.h>
17#include <zephyr/sd/sd_spec.h>
18
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30
35#define SDHC_TIMEOUT_FOREVER (-1)
49 unsigned int retries;
51};
52
53#define SDHC_NATIVE_RESPONSE_MASK 0xF
54#define SDHC_SPI_RESPONSE_TYPE_MASK 0xF0
55
62struct sdhc_data {
63 unsigned int block_addr;
64 unsigned int block_size;
65 unsigned int blocks;
66 unsigned int bytes_xfered;
67 void *data;
69};
70
81};
82
93};
94
105};
106
117 SDHC_TIMING_HS = 2U,
133 SDHC_TIMING_HS400 = 10U,
135};
136
145 SD_VOL_3_3_V = 1U,
147 SD_VOL_3_0_V = 2U,
149 SD_VOL_1_8_V = 3U,
151 SD_VOL_1_2_V = 4U,
153};
154
162 unsigned int timeout_clk_freq: 5;
163 unsigned int _rsvd_6: 1;
164 unsigned int timeout_clk_unit: 1;
165 unsigned int sd_base_clk: 8;
166 unsigned int max_blk_len: 2;
167 unsigned int bus_8_bit_support: 1;
168 unsigned int bus_4_bit_support: 1;
169 unsigned int adma_2_support: 1;
170 unsigned int _rsvd_20: 1;
171 unsigned int high_spd_support: 1;
172 unsigned int sdma_support: 1;
173 unsigned int suspend_res_support: 1;
174 unsigned int vol_330_support: 1;
175 unsigned int vol_300_support: 1;
176 unsigned int vol_180_support: 1;
180 unsigned int slot_type: 2;
181 unsigned int sdr50_support: 1;
182 unsigned int sdr104_support: 1;
183 unsigned int ddr50_support: 1;
184 unsigned int uhs_2_support: 1;
185 unsigned int drv_type_a_support: 1;
186 unsigned int drv_type_c_support: 1;
187 unsigned int drv_type_d_support: 1;
188 unsigned int _rsvd_39: 1;
189 unsigned int retune_timer_count: 4;
190 unsigned int sdr50_needs_tuning: 1;
191 unsigned int retuning_mode: 2;
192 unsigned int clk_multiplier: 8;
193 unsigned int _rsvd_56: 3;
194 unsigned int adma3_support: 1;
195 unsigned int vdd2_180_support: 1;
196 unsigned int _rsvd_61: 3;
197 unsigned int hs200_support: 1;
198 unsigned int hs400_support: 1;
199};
200
208struct sdhc_io {
216};
217
224 unsigned int f_max;
225 unsigned int f_min;
226 unsigned int power_delay;
231 bool is_spi;
232};
233
243};
244
254typedef void (*sdhc_interrupt_cb_t)(const struct device *dev, int reason,
255 const void *user_data);
256
257__subsystem struct sdhc_driver_api {
258 int (*reset)(const struct device *dev);
259 int (*request)(const struct device *dev,
260 struct sdhc_command *cmd,
261 struct sdhc_data *data);
262 int (*set_io)(const struct device *dev, struct sdhc_io *ios);
263 int (*get_card_present)(const struct device *dev);
264 int (*execute_tuning)(const struct device *dev);
265 int (*card_busy)(const struct device *dev);
266 int (*get_host_props)(const struct device *dev,
267 struct sdhc_host_props *props);
268 int (*enable_interrupt)(const struct device *dev,
269 sdhc_interrupt_cb_t callback,
270 int sources, void *user_data);
271 int (*disable_interrupt)(const struct device *dev, int sources);
272};
273
286__syscall int sdhc_hw_reset(const struct device *dev);
287
288static inline int z_impl_sdhc_hw_reset(const struct device *dev)
289{
290 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
291
292 if (!api->reset) {
293 return -ENOSYS;
294 }
295
296 return api->reset(dev);
297}
298
299
313__syscall int sdhc_request(const struct device *dev, struct sdhc_command *cmd,
314 struct sdhc_data *data);
315
316static inline int z_impl_sdhc_request(const struct device *dev,
317 struct sdhc_command *cmd,
318 struct sdhc_data *data)
319{
320 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
321
322 if (!api->request) {
323 return -ENOSYS;
324 }
325
326 return api->request(dev, cmd, data);
327}
328
341__syscall int sdhc_set_io(const struct device *dev, struct sdhc_io *io);
342
343static inline int z_impl_sdhc_set_io(const struct device *dev,
344 struct sdhc_io *io)
345{
346 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
347
348 if (!api->set_io) {
349 return -ENOSYS;
350 }
351
352 return api->set_io(dev, io);
353}
354
366__syscall int sdhc_card_present(const struct device *dev);
367
368static inline int z_impl_sdhc_card_present(const struct device *dev)
369{
370 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
371
372 if (!api->get_card_present) {
373 return -ENOSYS;
374 }
375
376 return api->get_card_present(dev);
377}
378
379
391__syscall int sdhc_execute_tuning(const struct device *dev);
392
393static inline int z_impl_sdhc_execute_tuning(const struct device *dev)
394{
395 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
396
397 if (!api->execute_tuning) {
398 return -ENOSYS;
399 }
400
401 return api->execute_tuning(dev);
402}
403
415__syscall int sdhc_card_busy(const struct device *dev);
416
417static inline int z_impl_sdhc_card_busy(const struct device *dev)
418{
419 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
420
421 if (!api->card_busy) {
422 return -ENOSYS;
423 }
424
425 return api->card_busy(dev);
426}
427
428
439__syscall int sdhc_get_host_props(const struct device *dev,
440 struct sdhc_host_props *props);
441
442static inline int z_impl_sdhc_get_host_props(const struct device *dev,
443 struct sdhc_host_props *props)
444{
445 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
446
447 if (!api->get_host_props) {
448 return -ENOSYS;
449 }
450
451 return api->get_host_props(dev, props);
452}
453
469__syscall int sdhc_enable_interrupt(const struct device *dev,
470 sdhc_interrupt_cb_t callback,
471 int sources, void *user_data);
472
473static inline int z_impl_sdhc_enable_interrupt(const struct device *dev,
474 sdhc_interrupt_cb_t callback,
475 int sources, void *user_data)
476{
477 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
478
479 if (!api->enable_interrupt) {
480 return -ENOSYS;
481 }
482
483 return api->enable_interrupt(dev, callback, sources, user_data);
484}
485
498__syscall int sdhc_disable_interrupt(const struct device *dev, int sources);
499
500static inline int z_impl_sdhc_disable_interrupt(const struct device *dev,
501 int sources)
502{
503 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
504
505 if (!api->disable_interrupt) {
506 return -ENOSYS;
507 }
508
509 return api->disable_interrupt(dev, sources);
510}
511
516#ifdef __cplusplus
517}
518#endif
519
520#include <syscalls/sdhc.h>
521#endif /* ZEPHYR_INCLUDE_DRIVERS_SDHC_H_ */
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:144
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:114
int sdhc_card_present(const struct device *dev)
check for SDHC card presence
void(* sdhc_interrupt_cb_t)(const struct device *dev, int reason, const void *user_data)
SDHC card interrupt callback prototype.
Definition: sdhc.h:254
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:239
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:90
int sdhc_hw_reset(const struct device *dev)
reset SDHC controller state
sdhc_bus_width
SD host controller bus width.
Definition: sdhc.h:101
sdhc_bus_mode
SD bus mode.
Definition: sdhc.h:78
@ SD_VOL_3_3_V
card operation voltage around 3.3v
Definition: sdhc.h:145
@ SD_VOL_1_2_V
card operation voltage around 1.2v
Definition: sdhc.h:151
@ SD_VOL_3_0_V
card operation voltage around 3.0v
Definition: sdhc.h:147
@ SD_VOL_1_8_V
card operation voltage around 1.8v
Definition: sdhc.h:149
@ SDHC_TIMING_HS400
HS400 mode.
Definition: sdhc.h:133
@ SDHC_TIMING_DDR52
DDR52 mode.
Definition: sdhc.h:129
@ SDHC_TIMING_SDR50
SDR49 mode.
Definition: sdhc.h:123
@ SDHC_TIMING_LEGACY
Legacy 3.3V Mode.
Definition: sdhc.h:115
@ SDHC_TIMING_SDR25
High speed mode & SDR25.
Definition: sdhc.h:121
@ SDHC_TIMING_SDR12
Identification mode & SDR12.
Definition: sdhc.h:119
@ SDHC_TIMING_SDR104
SDR104 mode.
Definition: sdhc.h:125
@ SDHC_TIMING_HS200
HS200 mode.
Definition: sdhc.h:131
@ SDHC_TIMING_HS
Legacy High speed mode (3.3V)
Definition: sdhc.h:117
@ SDHC_TIMING_DDR50
DDR50 mode.
Definition: sdhc.h:127
@ SDHC_INT_REMOVED
Card was removed from slot.
Definition: sdhc.h:242
@ SDHC_INT_INSERTED
Card was inserted into slot.
Definition: sdhc.h:241
@ SDHC_INT_SDIO
Card interrupt, used by SDIO cards.
Definition: sdhc.h:240
@ SDHC_POWER_OFF
Definition: sdhc.h:91
@ SDHC_POWER_ON
Definition: sdhc.h:92
@ SDHC_BUS_WIDTH8BIT
Definition: sdhc.h:104
@ SDHC_BUS_WIDTH4BIT
Definition: sdhc.h:103
@ SDHC_BUS_WIDTH1BIT
Definition: sdhc.h:102
@ SDHC_BUSMODE_OPENDRAIN
Definition: sdhc.h:79
@ SDHC_BUSMODE_PUSHPULL
Definition: sdhc.h:80
#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:83
sd_driver_type
SD driver types.
Definition: sd_spec.h:459
sdhc_clock_speed
SD host controller clock speed.
Definition: sd_spec.h:413
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition: device.h:387
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:393
SD host controller command structure.
Definition: sdhc.h:44
uint32_t opcode
SD Host specification CMD index.
Definition: sdhc.h:45
uint32_t response[4]
SD card response field.
Definition: sdhc.h:47
unsigned int retries
Max number of retries.
Definition: sdhc.h:49
int timeout_ms
Command timeout in milliseconds.
Definition: sdhc.h:50
uint32_t arg
SD host specification argument.
Definition: sdhc.h:46
uint32_t response_type
Expected SD response type.
Definition: sdhc.h:48
SD host controller data structure.
Definition: sdhc.h:62
void * data
Data to transfer or receive.
Definition: sdhc.h:67
unsigned int block_size
Block size.
Definition: sdhc.h:64
unsigned int blocks
Number of blocks.
Definition: sdhc.h:65
unsigned int block_addr
Block to start read from.
Definition: sdhc.h:63
unsigned int bytes_xfered
populated with number of bytes sent by SDHC
Definition: sdhc.h:66
int timeout_ms
data timeout in milliseconds
Definition: sdhc.h:68
Definition: sdhc.h:257
int(* get_card_present)(const struct device *dev)
Definition: sdhc.h:263
int(* enable_interrupt)(const struct device *dev, sdhc_interrupt_cb_t callback, int sources, void *user_data)
Definition: sdhc.h:268
int(* request)(const struct device *dev, struct sdhc_command *cmd, struct sdhc_data *data)
Definition: sdhc.h:259
int(* execute_tuning)(const struct device *dev)
Definition: sdhc.h:264
int(* disable_interrupt)(const struct device *dev, int sources)
Definition: sdhc.h:271
int(* reset)(const struct device *dev)
Definition: sdhc.h:258
int(* card_busy)(const struct device *dev)
Definition: sdhc.h:265
int(* set_io)(const struct device *dev, struct sdhc_io *ios)
Definition: sdhc.h:262
int(* get_host_props)(const struct device *dev, struct sdhc_host_props *props)
Definition: sdhc.h:266
SD host controller capabilities.
Definition: sdhc.h:161
unsigned int address_64_bit_support_v3
64-bit system address support for V3
Definition: sdhc.h:178
unsigned int uhs_2_support
UHS-II support.
Definition: sdhc.h:184
unsigned int sd_base_clk
SD base clock frequency.
Definition: sdhc.h:165
unsigned int sdma_support
SDMA support.
Definition: sdhc.h:172
unsigned int vdd2_180_support
1.8V VDD2 support
Definition: sdhc.h:195
unsigned int slot_type
Slot type.
Definition: sdhc.h:180
unsigned int timeout_clk_freq
Timeout clock frequency.
Definition: sdhc.h:162
unsigned int sdr104_support
SDR104 support.
Definition: sdhc.h:182
unsigned int drv_type_a_support
Driver type A support.
Definition: sdhc.h:185
unsigned int retuning_mode
Re-tuning mode.
Definition: sdhc.h:191
unsigned int sdr50_support
SDR50 support.
Definition: sdhc.h:181
unsigned int sdio_async_interrupt_support
Asynchronous interrupt support.
Definition: sdhc.h:179
unsigned int bus_4_bit_support
4 bit bus support
Definition: sdhc.h:168
unsigned int vol_300_support
Voltage support 3.0V.
Definition: sdhc.h:175
unsigned int timeout_clk_unit
Timeout clock unit.
Definition: sdhc.h:164
unsigned int adma3_support
ADMA3 support.
Definition: sdhc.h:194
unsigned int hs200_support
HS200 support.
Definition: sdhc.h:197
unsigned int max_blk_len
Max block length.
Definition: sdhc.h:166
unsigned int ddr50_support
DDR50 support.
Definition: sdhc.h:183
unsigned int vol_180_support
Voltage support 1.8V.
Definition: sdhc.h:176
unsigned int high_spd_support
High speed support.
Definition: sdhc.h:171
unsigned int drv_type_c_support
Driver type C support.
Definition: sdhc.h:186
unsigned int retune_timer_count
Timer count for re-tuning.
Definition: sdhc.h:189
unsigned int sdr50_needs_tuning
Use tuning for SDR50.
Definition: sdhc.h:190
unsigned int vol_330_support
Voltage support 3.3V.
Definition: sdhc.h:174
unsigned int adma_2_support
ADMA2 support.
Definition: sdhc.h:169
unsigned int bus_8_bit_support
8-bit Support for embedded device
Definition: sdhc.h:167
unsigned int hs400_support
HS400 support.
Definition: sdhc.h:198
unsigned int drv_type_d_support
Driver type D support.
Definition: sdhc.h:187
unsigned int address_64_bit_support_v4
64-bit system address support for V4
Definition: sdhc.h:177
unsigned int suspend_res_support
Suspend/Resume support.
Definition: sdhc.h:173
unsigned int clk_multiplier
Clock multiplier.
Definition: sdhc.h:192
SD host controller properties.
Definition: sdhc.h:223
unsigned int f_min
Min bus frequency.
Definition: sdhc.h:225
uint32_t max_current_180
Max current (in mA) at 1.8V.
Definition: sdhc.h:230
unsigned int power_delay
Delay to allow SD to power up or down (in ms)
Definition: sdhc.h:226
bool is_spi
Is the host using SPI mode.
Definition: sdhc.h:231
uint32_t max_current_300
Max current (in mA) at 3.0V.
Definition: sdhc.h:229
struct sdhc_host_caps host_caps
Host capability bitfield.
Definition: sdhc.h:227
unsigned int f_max
Max bus frequency.
Definition: sdhc.h:224
uint32_t max_current_330
Max current (in mA) at 3.3V.
Definition: sdhc.h:228
SD host controller I/O control structure.
Definition: sdhc.h:208
enum sd_driver_type driver_type
SD driver type.
Definition: sdhc.h:214
enum sdhc_bus_mode bus_mode
command output mode
Definition: sdhc.h:210
enum sdhc_timing_mode timing
SD bus timing.
Definition: sdhc.h:213
enum sdhc_bus_width bus_width
SD bus width.
Definition: sdhc.h:212
enum sdhc_clock_speed clock
Clock rate.
Definition: sdhc.h:209
enum sdhc_power power_mode
SD power supply mode.
Definition: sdhc.h:211
enum sd_voltage signal_voltage
IO signalling voltage (usually 1.8 or 3.3V)
Definition: sdhc.h:215