Line data Source code
1 1 : /*
2 : * Copyright 2023 NXP
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : /**
8 : * @file
9 : * @brief Public API for SDIO subsystem
10 : */
11 :
12 : #ifndef ZEPHYR_INCLUDE_SD_SDIO_H_
13 : #define ZEPHYR_INCLUDE_SD_SDIO_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 Initialize SDIO function.
25 : *
26 : * Initializes SDIO card function. The card function will not be enabled,
27 : * but after this call returns the SDIO function structure can be used to read
28 : * and write data from the card.
29 : * @param func: function structure to initialize
30 : * @param card: SD card to enable function on
31 : * @param num: function number to initialize
32 : * @retval 0 function was initialized successfully
33 : * @retval -EIO: I/O error
34 : */
35 1 : int sdio_init_func(struct sd_card *card, struct sdio_func *func,
36 : enum sdio_func_num num);
37 :
38 : /**
39 : * @brief Enable SDIO function
40 : *
41 : * Enables SDIO card function. @ref sdio_init_func must be called to
42 : * initialized the function structure before enabling it in the card.
43 : * @param func: function to enable
44 : * @retval 0 function was enabled successfully
45 : * @retval -ETIMEDOUT: card I/O timed out
46 : * @retval -EIO: I/O error
47 : */
48 1 : int sdio_enable_func(struct sdio_func *func);
49 :
50 : /**
51 : * @brief Set block size of SDIO function
52 : *
53 : * Set desired block size for SDIO function, used by block transfers
54 : * to SDIO registers.
55 : * @param func: function to set block size for
56 : * @param bsize: block size
57 : * @retval 0 block size was set
58 : * @retval -EINVAL: unsupported/invalid block size
59 : * @retval -EIO: I/O error
60 : */
61 1 : int sdio_set_block_size(struct sdio_func *func, uint16_t bsize);
62 :
63 : /**
64 : * @brief Read byte from SDIO register
65 : *
66 : * Reads byte from SDIO register
67 : * @param func: function to read from
68 : * @param reg: register address to read from
69 : * @param val: filled with byte value read from register
70 : * @retval 0 read succeeded
71 : * @retval -EBUSY: card is busy with another request
72 : * @retval -ETIMEDOUT: card read timed out
73 : * @retval -EIO: I/O error
74 : */
75 1 : int sdio_read_byte(struct sdio_func *func, uint32_t reg, uint8_t *val);
76 :
77 : /**
78 : * @brief Write byte to SDIO register
79 : *
80 : * Writes byte to SDIO register
81 : * @param func: function to write to
82 : * @param reg: register address to write to
83 : * @param write_val: value to write to register
84 : * @retval 0 write succeeded
85 : * @retval -EBUSY: card is busy with another request
86 : * @retval -ETIMEDOUT: card write timed out
87 : * @retval -EIO: I/O error
88 : */
89 1 : int sdio_write_byte(struct sdio_func *func, uint32_t reg, uint8_t write_val);
90 :
91 : /**
92 : * @brief Write byte to SDIO register, and read result
93 : *
94 : * Writes byte to SDIO register, and reads the register after write
95 : * @param func: function to write to
96 : * @param reg: register address to write to
97 : * @param write_val: value to write to register
98 : * @param read_val: filled with value read from register
99 : * @retval 0 write succeeded
100 : * @retval -EBUSY: card is busy with another request
101 : * @retval -ETIMEDOUT: card write timed out
102 : * @retval -EIO: I/O error
103 : */
104 1 : int sdio_rw_byte(struct sdio_func *func, uint32_t reg, uint8_t write_val,
105 : uint8_t *read_val);
106 :
107 : /**
108 : * @brief Read bytes from SDIO fifo
109 : *
110 : * Reads bytes from SDIO register, treating it as a fifo. Reads will
111 : * all be done from same address.
112 : * @param func: function to read from
113 : * @param reg: register address of fifo
114 : * @param data: filled with data read from fifo
115 : * @param len: length of data to read from card
116 : * @retval 0 read succeeded
117 : * @retval -EBUSY: card is busy with another request
118 : * @retval -ETIMEDOUT: card read timed out
119 : * @retval -EIO: I/O error
120 : */
121 1 : int sdio_read_fifo(struct sdio_func *func, uint32_t reg, uint8_t *data,
122 : uint32_t len);
123 :
124 : /**
125 : * @brief Write bytes to SDIO fifo
126 : *
127 : * Writes bytes to SDIO register, treating it as a fifo. Writes will
128 : * all be done to same address.
129 : * @param func: function to write to
130 : * @param reg: register address of fifo
131 : * @param data: data to write to fifo
132 : * @param len: length of data to write to card
133 : * @retval 0 write succeeded
134 : * @retval -EBUSY: card is busy with another request
135 : * @retval -ETIMEDOUT: card write timed out
136 : * @retval -EIO: I/O error
137 : */
138 1 : int sdio_write_fifo(struct sdio_func *func, uint32_t reg, uint8_t *data,
139 : uint32_t len);
140 :
141 : /**
142 : * @brief Read blocks from SDIO fifo
143 : *
144 : * Reads blocks from SDIO register, treating it as a fifo. Reads will
145 : * all be done from same address.
146 : * @param func: function to read from
147 : * @param reg: register address of fifo
148 : * @param data: filled with data read from fifo
149 : * @param blocks: number of blocks to read from fifo
150 : * @retval 0 read succeeded
151 : * @retval -EBUSY: card is busy with another request
152 : * @retval -ETIMEDOUT: card read timed out
153 : * @retval -EIO: I/O error
154 : */
155 1 : int sdio_read_blocks_fifo(struct sdio_func *func, uint32_t reg, uint8_t *data,
156 : uint32_t blocks);
157 :
158 : /**
159 : * @brief Write blocks to SDIO fifo
160 : *
161 : * Writes blocks from SDIO register, treating it as a fifo. Writes will
162 : * all be done to same address.
163 : * @param func: function to write to
164 : * @param reg: register address of fifo
165 : * @param data: data to write to fifo
166 : * @param blocks: number of blocks to write to fifo
167 : * @retval 0 write succeeded
168 : * @retval -EBUSY: card is busy with another request
169 : * @retval -ETIMEDOUT: card write timed out
170 : * @retval -EIO: I/O error
171 : */
172 1 : int sdio_write_blocks_fifo(struct sdio_func *func, uint32_t reg, uint8_t *data,
173 : uint32_t blocks);
174 :
175 : /**
176 : * @brief Copy bytes from an SDIO card
177 : *
178 : * Copies bytes from an SDIO card, starting from provided address.
179 : * @param func: function to read from
180 : * @param reg: register address to start copy at
181 : * @param data: buffer to copy data into
182 : * @param len: length of data to read
183 : * @retval 0 read succeeded
184 : * @retval -EBUSY: card is busy with another request
185 : * @retval -ETIMEDOUT: card read timed out
186 : * @retval -EIO: I/O error
187 : */
188 1 : int sdio_read_addr(struct sdio_func *func, uint32_t reg, uint8_t *data,
189 : uint32_t len);
190 :
191 : /**
192 : * @brief Copy bytes to an SDIO card
193 : *
194 : * Copies bytes to an SDIO card, starting from provided address.
195 : *
196 : * @param func: function to write to
197 : * @param reg: register address to start copy at
198 : * @param data: buffer to copy data from
199 : * @param len: length of data to write
200 : * @retval 0 write succeeded
201 : * @retval -EBUSY: card is busy with another request
202 : * @retval -ETIMEDOUT: card write timed out
203 : * @retval -EIO: I/O error
204 : */
205 1 : int sdio_write_addr(struct sdio_func *func, uint32_t reg, uint8_t *data,
206 : uint32_t len);
207 :
208 : #ifdef __cplusplus
209 : }
210 : #endif
211 :
212 : #endif /* ZEPHYR_INCLUDE_SD_SDMMC_H_ */
|