Zephyr API 3.6.99
Loading...
Searching...
No Matches
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
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32
37#define SDHC_TIMEOUT_FOREVER (-1)
54
55#define SDHC_NATIVE_RESPONSE_MASK 0xF
56#define SDHC_SPI_RESPONSE_TYPE_MASK 0xF0
57
64struct sdhc_data {
65 unsigned int block_addr;
66 unsigned int block_size;
67 unsigned int blocks;
68 unsigned int bytes_xfered;
69 void *data;
71};
72
84
96
108
138
147 SD_VOL_3_3_V = 1U,
149 SD_VOL_3_0_V = 2U,
151 SD_VOL_1_8_V = 3U,
153 SD_VOL_1_2_V = 4U,
155};
156
164 unsigned int timeout_clk_freq: 5;
165 unsigned int _rsvd_6: 1;
166 unsigned int timeout_clk_unit: 1;
167 unsigned int sd_base_clk: 8;
168 unsigned int max_blk_len: 2;
169 unsigned int bus_8_bit_support: 1;
170 unsigned int bus_4_bit_support: 1;
171 unsigned int adma_2_support: 1;
172 unsigned int _rsvd_20: 1;
173 unsigned int high_spd_support: 1;
174 unsigned int sdma_support: 1;
175 unsigned int suspend_res_support: 1;
176 unsigned int vol_330_support: 1;
177 unsigned int vol_300_support: 1;
178 unsigned int vol_180_support: 1;
182 unsigned int slot_type: 2;
183 unsigned int sdr50_support: 1;
184 unsigned int sdr104_support: 1;
185 unsigned int ddr50_support: 1;
186 unsigned int uhs_2_support: 1;
187 unsigned int drv_type_a_support: 1;
188 unsigned int drv_type_c_support: 1;
189 unsigned int drv_type_d_support: 1;
190 unsigned int _rsvd_39: 1;
191 unsigned int retune_timer_count: 4;
192 unsigned int sdr50_needs_tuning: 1;
193 unsigned int retuning_mode: 2;
194 unsigned int clk_multiplier: 8;
195 unsigned int _rsvd_56: 3;
196 unsigned int adma3_support: 1;
197 unsigned int vdd2_180_support: 1;
198 unsigned int _rsvd_61: 3;
199 unsigned int hs200_support: 1;
200 unsigned int hs400_support: 1;
201};
202
219
235
246
256typedef void (*sdhc_interrupt_cb_t)(const struct device *dev, int reason,
257 const void *user_data);
258
259__subsystem struct sdhc_driver_api {
260 int (*reset)(const struct device *dev);
261 int (*request)(const struct device *dev,
262 struct sdhc_command *cmd,
263 struct sdhc_data *data);
264 int (*set_io)(const struct device *dev, struct sdhc_io *ios);
265 int (*get_card_present)(const struct device *dev);
266 int (*execute_tuning)(const struct device *dev);
267 int (*card_busy)(const struct device *dev);
268 int (*get_host_props)(const struct device *dev,
269 struct sdhc_host_props *props);
270 int (*enable_interrupt)(const struct device *dev,
271 sdhc_interrupt_cb_t callback,
272 int sources, void *user_data);
273 int (*disable_interrupt)(const struct device *dev, int sources);
274};
275
288__syscall int sdhc_hw_reset(const struct device *dev);
289
290static inline int z_impl_sdhc_hw_reset(const struct device *dev)
291{
292 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
293
294 if (!api->reset) {
295 return -ENOSYS;
296 }
297
298 return api->reset(dev);
299}
300
301
315__syscall int sdhc_request(const struct device *dev, struct sdhc_command *cmd,
316 struct sdhc_data *data);
317
318static inline int z_impl_sdhc_request(const struct device *dev,
319 struct sdhc_command *cmd,
320 struct sdhc_data *data)
321{
322 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
323
324 if (!api->request) {
325 return -ENOSYS;
326 }
327
328 return api->request(dev, cmd, data);
329}
330
343__syscall int sdhc_set_io(const struct device *dev, struct sdhc_io *io);
344
345static inline int z_impl_sdhc_set_io(const struct device *dev,
346 struct sdhc_io *io)
347{
348 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
349
350 if (!api->set_io) {
351 return -ENOSYS;
352 }
353
354 return api->set_io(dev, io);
355}
356
368__syscall int sdhc_card_present(const struct device *dev);
369
370static inline int z_impl_sdhc_card_present(const struct device *dev)
371{
372 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
373
374 if (!api->get_card_present) {
375 return -ENOSYS;
376 }
377
378 return api->get_card_present(dev);
379}
380
381
393__syscall int sdhc_execute_tuning(const struct device *dev);
394
395static inline int z_impl_sdhc_execute_tuning(const struct device *dev)
396{
397 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
398
399 if (!api->execute_tuning) {
400 return -ENOSYS;
401 }
402
403 return api->execute_tuning(dev);
404}
405
417__syscall int sdhc_card_busy(const struct device *dev);
418
419static inline int z_impl_sdhc_card_busy(const struct device *dev)
420{
421 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
422
423 if (!api->card_busy) {
424 return -ENOSYS;
425 }
426
427 return api->card_busy(dev);
428}
429
430
441__syscall int sdhc_get_host_props(const struct device *dev,
442 struct sdhc_host_props *props);
443
444static inline int z_impl_sdhc_get_host_props(const struct device *dev,
445 struct sdhc_host_props *props)
446{
447 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
448
449 if (!api->get_host_props) {
450 return -ENOSYS;
451 }
452
453 return api->get_host_props(dev, props);
454}
455
471__syscall int sdhc_enable_interrupt(const struct device *dev,
472 sdhc_interrupt_cb_t callback,
473 int sources, void *user_data);
474
475static inline int z_impl_sdhc_enable_interrupt(const struct device *dev,
476 sdhc_interrupt_cb_t callback,
477 int sources, void *user_data)
478{
479 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
480
481 if (!api->enable_interrupt) {
482 return -ENOSYS;
483 }
484
485 return api->enable_interrupt(dev, callback, sources, user_data);
486}
487
500__syscall int sdhc_disable_interrupt(const struct device *dev, int sources);
501
502static inline int z_impl_sdhc_disable_interrupt(const struct device *dev,
503 int sources)
504{
505 const struct sdhc_driver_api *api = (const struct sdhc_driver_api *)dev->api;
506
507 if (!api->disable_interrupt) {
508 return -ENOSYS;
509 }
510
511 return api->disable_interrupt(dev, sources);
512}
513
518#ifdef __cplusplus
519}
520#endif
521
522#include <zephyr/syscalls/sdhc.h>
523#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:146
void(* sdhc_interrupt_cb_t)(const struct device *dev, int reason, const void *user_data)
SDHC card interrupt callback prototype.
Definition sdhc.h:256
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:116
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:241
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:92
int sdhc_hw_reset(const struct device *dev)
reset SDHC controller state
sdhc_bus_width
SD host controller bus width.
Definition sdhc.h:103
sdhc_bus_mode
SD bus mode.
Definition sdhc.h:80
@ SD_VOL_3_3_V
card operation voltage around 3.3v
Definition sdhc.h:147
@ SD_VOL_1_2_V
card operation voltage around 1.2v
Definition sdhc.h:153
@ SD_VOL_3_0_V
card operation voltage around 3.0v
Definition sdhc.h:149
@ SD_VOL_1_8_V
card operation voltage around 1.8v
Definition sdhc.h:151
@ SDHC_TIMING_HS400
HS400 mode.
Definition sdhc.h:135
@ SDHC_TIMING_DDR52
DDR52 mode.
Definition sdhc.h:131
@ SDHC_TIMING_SDR50
SDR49 mode.
Definition sdhc.h:125
@ SDHC_TIMING_LEGACY
Legacy 3.3V Mode.
Definition sdhc.h:117
@ SDHC_TIMING_SDR25
High speed mode & SDR25.
Definition sdhc.h:123
@ SDHC_TIMING_SDR12
Identification mode & SDR12.
Definition sdhc.h:121
@ SDHC_TIMING_SDR104
SDR104 mode.
Definition sdhc.h:127
@ SDHC_TIMING_HS200
HS200 mode.
Definition sdhc.h:133
@ SDHC_TIMING_HS
Legacy High speed mode (3.3V)
Definition sdhc.h:119
@ SDHC_TIMING_DDR50
DDR50 mode.
Definition sdhc.h:129
@ SDHC_INT_REMOVED
Card was removed from slot.
Definition sdhc.h:244
@ SDHC_INT_INSERTED
Card was inserted into slot.
Definition sdhc.h:243
@ SDHC_INT_SDIO
Card interrupt, used by SDIO cards.
Definition sdhc.h:242
@ SDHC_POWER_OFF
Definition sdhc.h:93
@ SDHC_POWER_ON
Definition sdhc.h:94
@ SDHC_BUS_WIDTH8BIT
Definition sdhc.h:106
@ SDHC_BUS_WIDTH4BIT
Definition sdhc.h:105
@ SDHC_BUS_WIDTH1BIT
Definition sdhc.h:104
@ SDHC_BUSMODE_OPENDRAIN
Definition sdhc.h:81
@ SDHC_BUSMODE_PUSHPULL
Definition sdhc.h:82
#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
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:403
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:409
SD host controller command structure.
Definition sdhc.h:46
uint32_t opcode
SD Host specification CMD index.
Definition sdhc.h:47
uint32_t response[4]
SD card response field.
Definition sdhc.h:49
unsigned int retries
Max number of retries.
Definition sdhc.h:51
int timeout_ms
Command timeout in milliseconds.
Definition sdhc.h:52
uint32_t arg
SD host specification argument.
Definition sdhc.h:48
uint32_t response_type
Expected SD response type.
Definition sdhc.h:50
SD host controller data structure.
Definition sdhc.h:64
void * data
Data to transfer or receive.
Definition sdhc.h:69
unsigned int block_size
Block size.
Definition sdhc.h:66
unsigned int blocks
Number of blocks.
Definition sdhc.h:67
unsigned int block_addr
Block to start read from.
Definition sdhc.h:65
unsigned int bytes_xfered
populated with number of bytes sent by SDHC
Definition sdhc.h:68
int timeout_ms
data timeout in milliseconds
Definition sdhc.h:70
Definition sdhc.h:259
int(* get_card_present)(const struct device *dev)
Definition sdhc.h:265
int(* enable_interrupt)(const struct device *dev, sdhc_interrupt_cb_t callback, int sources, void *user_data)
Definition sdhc.h:270
int(* request)(const struct device *dev, struct sdhc_command *cmd, struct sdhc_data *data)
Definition sdhc.h:261
int(* execute_tuning)(const struct device *dev)
Definition sdhc.h:266
int(* disable_interrupt)(const struct device *dev, int sources)
Definition sdhc.h:273
int(* reset)(const struct device *dev)
Definition sdhc.h:260
int(* card_busy)(const struct device *dev)
Definition sdhc.h:267
int(* set_io)(const struct device *dev, struct sdhc_io *ios)
Definition sdhc.h:264
int(* get_host_props)(const struct device *dev, struct sdhc_host_props *props)
Definition sdhc.h:268
SD host controller capabilities.
Definition sdhc.h:163
unsigned int address_64_bit_support_v3
64-bit system address support for V3
Definition sdhc.h:180
unsigned int uhs_2_support
UHS-II support.
Definition sdhc.h:186
unsigned int sd_base_clk
SD base clock frequency.
Definition sdhc.h:167
unsigned int sdma_support
SDMA support.
Definition sdhc.h:174
unsigned int vdd2_180_support
1.8V VDD2 support
Definition sdhc.h:197
unsigned int slot_type
Slot type.
Definition sdhc.h:182
unsigned int timeout_clk_freq
Timeout clock frequency.
Definition sdhc.h:164
unsigned int sdr104_support
SDR104 support.
Definition sdhc.h:184
unsigned int drv_type_a_support
Driver type A support.
Definition sdhc.h:187
unsigned int retuning_mode
Re-tuning mode.
Definition sdhc.h:193
unsigned int sdr50_support
SDR50 support.
Definition sdhc.h:183
unsigned int sdio_async_interrupt_support
Asynchronous interrupt support.
Definition sdhc.h:181
unsigned int bus_4_bit_support
4 bit bus support
Definition sdhc.h:170
unsigned int vol_300_support
Voltage support 3.0V.
Definition sdhc.h:177
unsigned int timeout_clk_unit
Timeout clock unit.
Definition sdhc.h:166
unsigned int adma3_support
ADMA3 support.
Definition sdhc.h:196
unsigned int hs200_support
HS200 support.
Definition sdhc.h:199
unsigned int max_blk_len
Max block length.
Definition sdhc.h:168
unsigned int ddr50_support
DDR50 support.
Definition sdhc.h:185
unsigned int vol_180_support
Voltage support 1.8V.
Definition sdhc.h:178
unsigned int high_spd_support
High speed support.
Definition sdhc.h:173
unsigned int drv_type_c_support
Driver type C support.
Definition sdhc.h:188
unsigned int retune_timer_count
Timer count for re-tuning.
Definition sdhc.h:191
unsigned int sdr50_needs_tuning
Use tuning for SDR50.
Definition sdhc.h:192
unsigned int vol_330_support
Voltage support 3.3V.
Definition sdhc.h:176
unsigned int adma_2_support
ADMA2 support.
Definition sdhc.h:171
unsigned int bus_8_bit_support
8-bit Support for embedded device
Definition sdhc.h:169
unsigned int hs400_support
HS400 support.
Definition sdhc.h:200
unsigned int drv_type_d_support
Driver type D support.
Definition sdhc.h:189
unsigned int address_64_bit_support_v4
64-bit system address support for V4
Definition sdhc.h:179
unsigned int suspend_res_support
Suspend/Resume support.
Definition sdhc.h:175
unsigned int clk_multiplier
Clock multiplier.
Definition sdhc.h:194
SD host controller properties.
Definition sdhc.h:225
unsigned int f_min
Min bus frequency.
Definition sdhc.h:227
uint32_t max_current_180
Max current (in mA) at 1.8V.
Definition sdhc.h:232
unsigned int power_delay
Delay to allow SD to power up or down (in ms)
Definition sdhc.h:228
bool is_spi
Is the host using SPI mode.
Definition sdhc.h:233
uint32_t max_current_300
Max current (in mA) at 3.0V.
Definition sdhc.h:231
struct sdhc_host_caps host_caps
Host capability bitfield.
Definition sdhc.h:229
unsigned int f_max
Max bus frequency.
Definition sdhc.h:226
uint32_t max_current_330
Max current (in mA) at 3.3V.
Definition sdhc.h:230
SD host controller I/O control structure.
Definition sdhc.h:210
enum sd_driver_type driver_type
SD driver type.
Definition sdhc.h:216
enum sdhc_bus_mode bus_mode
command output mode
Definition sdhc.h:212
enum sdhc_timing_mode timing
SD bus timing.
Definition sdhc.h:215
enum sdhc_bus_width bus_width
SD bus width.
Definition sdhc.h:214
enum sdhc_clock_speed clock
Clock rate.
Definition sdhc.h:211
enum sdhc_power power_mode
SD power supply mode.
Definition sdhc.h:213
enum sd_voltage signal_voltage
IO signalling voltage (usually 1.8 or 3.3V)
Definition sdhc.h:217