1 /*
2  * Copyright 2022 NXP
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Public API for SD memory card subsystem
10  */
11 
12 #ifndef ZEPHYR_INCLUDE_SD_SDMMC_H_
13 #define ZEPHYR_INCLUDE_SD_SDMMC_H_
14 
15 #include <zephyr/device.h>
16 #include <zephyr/drivers/sdhc.h>
17 #include <zephyr/sd/sd.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /**
24  * @brief Write blocks to SD card from buffer
25  *
26  * Writes blocks from SD buffer to SD card. For best performance, this buffer
27  * should be aligned to CONFIG_SDHC_BUFFER_ALIGNMENT
28  * @param card SD card to write from
29  * @param wbuf write buffer
30  * @param start_block first block to write to
31  * @param num_blocks number of blocks to write
32  * @retval 0 write succeeded
33  * @retval -EBUSY: card is busy with another request
34  * @retval -ETIMEDOUT: card write timed out
35  * @retval -EIO: I/O error
36  */
37 int sdmmc_write_blocks(struct sd_card *card, const uint8_t *wbuf,
38 	uint32_t start_block, uint32_t num_blocks);
39 
40 /**
41  * @brief Read block from SD card to buffer
42  *
43  * Reads blocks into SD buffer from SD card. For best performance, this buffer
44  * should be aligned to CONFIG_SDHC_BUFFER_ALIGNMENT
45  * @param card SD card to read from
46  * @param rbuf read buffer
47  * @param start_block first block to read from
48  * @param num_blocks number of blocks to read
49  * @retval 0 read succeeded
50  * @retval -EBUSY: card is busy with another request
51  * @retval -ETIMEDOUT: card read timed out
52  * @retval -EIO: I/O error
53  */
54 int sdmmc_read_blocks(struct sd_card *card, uint8_t *rbuf,
55 	uint32_t start_block, uint32_t num_blocks);
56 
57 /**
58  * @brief Get I/O control data from SD card
59  *
60  * Sends I/O control commands to SD card.
61  * @param card SD card
62  * @param cmd I/O control command
63  * @param buf I/O control buf
64  * @retval 0 IOCTL command succeeded
65  * @retval -ENOTSUP: IOCTL command not supported
66  * @retval -EIO: I/O failure
67  */
68 int sdmmc_ioctl(struct sd_card *card, uint8_t cmd, void *buf);
69 
70 #ifdef __cplusplus
71 }
72 #endif
73 
74 #endif /* ZEPHYR_INCLUDE_SD_SDMMC_H_ */
75