2 * SDIO Userspace Interface library.
4 * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
6 * Refer to LICENSE.txt included with this source code for details on
9 #ifndef SDIOEMB_LIBSDIO_H
10 #define SDIOEMB_LIBSDIO_H
13 * \defgroup libsdio Userspace SDIO library (libsdio)
15 * \brief \e libsdio is a Linux C library for accessing SDIO cards.
17 * Use of this library requires several \e sdioemb kernel modules to be
20 * - \c An SDIO slot driver (e.g., \c slot_shc for a standard PCI
21 * SDIO Host Controller).
22 * - \c sdio_uif which provides the required character devices
23 * (/dev/sdio_uif0 for the card in SDIO slot 0 etc.).
32 # define LIBSDIOAPI __stdcall
40 * Handle to an opened SDIO Userspace Interface device.
42 typedef struct sdio_uif
*sdio_uif_t
;
57 * Card interrupt handler function.
59 * @param uif handle to the interrupting device.
60 * @param arg data supplied by the caller of sdio_open().
62 typedef void (LIBSDIOAPI
*sdio_int_handler_t
)(sdio_uif_t uif
, void *arg
);
65 * Asynchronous IO completion callback function.
67 * @param uif handle to the device that completed the IO operation.
68 * @param arg data supplied by the caller of the asynchronous IO operation.
69 * @param status status of the IO operation. 0 is success; -EIO,
70 * -EINVAL, -ETIMEDOUT etc. on an error.
72 typedef void (LIBSDIOAPI
*sdio_io_callback_t
)(sdio_uif_t uif
, void *arg
, int status
);
75 * Open a SDIO Userspace Interface device and (optionally) register a
76 * card interrupt handler and enable card interrupts.
78 * Card interrupts are masked before calling int_handler and are
79 * unmasked when int_handler returns (unless sdio_interrupt_mask() is
82 * @param dev_filename filename of the device to open.
83 * @param int_handler card interrupt handler; or NULL if no
84 * interrupt handler is required.
85 * @param arg argument to be passed to the interrupt handler.
87 * @return handle to the opened device; or NULL on error with errno
90 sdio_uif_t LIBSDIOAPI
sdio_open(const char *dev_filename
,
91 sdio_int_handler_t int_handler
, void *arg
);
94 * Mask the SDIO interrupt.
96 * Call this in an interrupt handler to allow the processing of
97 * interrupts to be deferred until after the interrupt handler has
100 * @note \e Must only be called from within the interrupt handler
101 * registered with sdio_open().
103 * @param uif device handle.
105 void LIBSDIOAPI
sdio_interrupt_mask(sdio_uif_t uif
);
108 * Unmask the SDIO interrupt.
110 * Unmasks the SDIO interrupt if it had previously been masked with
111 * sdio_interrupt_mask().
113 * @param uif device handle.
115 void LIBSDIOAPI
sdio_interrupt_unmask(sdio_uif_t uif
);
118 * Close an opened SDIO Userspace Interface device, freeing all
119 * associated resources.
121 * @param uif handle to the device.
123 void LIBSDIOAPI
sdio_close(sdio_uif_t uif
);
126 * Return the number of functions the card has.
128 * @param uif device handle.
130 * @return number of card functions.
132 int LIBSDIOAPI
sdio_num_functions(sdio_uif_t uif
);
135 * Set an SDIO bus to 1 bit or 4 bit wide mode.
137 * The CCCR bus interface control register will be read and rewritten
138 * with the new bus width.
140 * @param uif device handle.
141 * @param bus_width bus width (1 or 4).
143 * @return 0 on success; -ve on error with errno set.
145 * @note The card capabilities are \e not checked. The user should
146 * ensure 4 bit mode is not enabled on a card that does not support
149 int LIBSDIOAPI
sdio_set_bus_width(sdio_uif_t uif
, int bus_width
);
152 * Limit the frequency of (or stop) the SD bus clock.
154 * The frequency cannot be set greater than that supported by the card
157 * @note Stopping the bus clock while other device drivers are
158 * executing commands may result in those commands not completing
159 * until the bus clock is restarted.
161 * @param uif device handle.
162 * @param max_freq maximum frequency (Hz) or 0 to stop the bus clock
163 * until the start of the next command.
165 void LIBSDIOAPI
sdio_set_max_bus_freq(sdio_uif_t uif
, int max_freq
);
168 * Return the card's manufacturer (vendor) ID.
170 * @param uif device handle.
172 * @return manufacturer ID.
174 uint16_t LIBSDIOAPI
sdio_manf_id(sdio_uif_t uif
);
177 * Return the card's card (device) ID.
179 * @param uif device handle.
183 uint16_t LIBSDIOAPI
sdio_card_id(sdio_uif_t uif
);
186 * Return the standard interface code for a function.
188 * @param uif device handle.
189 * @param func card function to query.
191 * @return the standard interface.
193 uint8_t LIBSDIOAPI
sdio_std_if(sdio_uif_t uif
, int func
);
196 * Return a function's maximum supported block size.
198 * @param uif device handle.
199 * @param func card function to query.
201 * @return maximum block size.
203 int LIBSDIOAPI
sdio_max_block_size(sdio_uif_t uif
, int func
);
206 * Return a function's current block size.
208 * @note This returns the driver's view of the block size and not the
209 * value in the function's block size register.
211 * @param uif device handle.
212 * @param func card function to query.
214 * @return the current block size.
216 int LIBSDIOAPI
sdio_block_size(sdio_uif_t uif
, int func
);
219 * Set a function's block size.
221 * The function's block size registers will be written if necessary.
223 * @param uif device handle.
224 * @param func function to modify.
225 * @param blksz the new block size; or 0 for the default size.
227 * @return 0 on success; or -ve on error with errno set.
229 int LIBSDIOAPI
sdio_set_block_size(sdio_uif_t uif
, int func
, int blksz
);
232 * Read an 8 bit register.
234 * @param uif device handle.
235 * @param func card function.
236 * @param addr register address.
237 * @param data the data read.
239 * @return 0 on success; or -ve on error with errno set.
241 int LIBSDIOAPI
sdio_read8(sdio_uif_t uif
, int func
, uint32_t addr
, uint8_t *data
);
244 * Write an 8 bit register.
246 * @param uif device handle.
247 * @param func card function.
248 * @param addr register address.
249 * @param data the data to write.
251 * @return 0 on success; or -ve on error with errno set.
253 int LIBSDIOAPI
sdio_write8(sdio_uif_t uif
, int func
, uint32_t addr
, uint8_t data
);
256 * Read a buffer from a 8 bit wide register/FIFO.
258 * The buffer read uses a fixed (not incrementing) address.
260 * \a block_size \e must be set to the value writted into \a func's
261 * I/O block size FBR register.
263 * If \a len % \a block_size == 0, a block mode transfer is used; a
264 * byte mode transfer is used if \a len < \a block_size.
266 * @param uif device handle.
267 * @param func card function.
268 * @param addr register/FIFO address.
269 * @param data buffer to store the data read.
270 * @param len length of data to read.
271 * @param block_size block size to use for this transfer.
273 * @return 0 on success; or -ve on error with errno set.
275 int LIBSDIOAPI
sdio_read(sdio_uif_t uif
, int func
, uint32_t addr
, uint8_t *data
,
276 size_t len
, int block_size
);
279 * Write a buffer to an 8 bit wide register/FIFO.
281 * The buffer write uses a fixed (not incrementing) address.
283 * \a block_size \e must be set to the value writted into \a func's
284 * I/O block size FBR register.
286 * If \a len % \a block_size == 0, a block mode transfer is used; a
287 * byte mode transfer is used if \a len < \a block_size.
289 * @param uif device handle.
290 * @param func card function.
291 * @param addr register/FIFO address.
292 * @param data buffer of data to write.
293 * @param len length of the data to write.
294 * @param block_size block size to use for this transfer.
296 * @return 0 on success; or -ve on error with errno set.
298 int LIBSDIOAPI
sdio_write(sdio_uif_t uif
, int func
, uint32_t addr
, const uint8_t *data
,
299 size_t len
, int block_size
);
302 * Read an 8 bit register, without waiting for completion.
304 * @param uif device handle.
305 * @param func card function.
306 * @param addr register address.
307 * @param data the data read.
308 * @param callback function to be called when the read completes.
309 * @param arg argument to be passed to callback.
311 * @return 0 on success; or -ve on error with errno set.
313 int LIBSDIOAPI
sdio_read8_async(sdio_uif_t uif
, int func
, uint32_t addr
, uint8_t *data
,
314 sdio_io_callback_t callback
, void *arg
);
317 * Write an 8 bit register, without waiting for completion.
319 * @param uif device handle.
320 * @param func card function.
321 * @param addr register address.
322 * @param data the data to write.
323 * @param callback function to be called when the write completes.
324 * @param arg argument to be passed to callback.
326 * @return 0 on success; or -ve on error with errno set.
328 int LIBSDIOAPI
sdio_write8_async(sdio_uif_t uif
, int func
, uint32_t addr
, uint8_t data
,
329 sdio_io_callback_t callback
, void *arg
);
332 * Read a buffer from a 8 bit wide register/FIFO, without waiting for
335 * The buffer read uses a fixed (not incrementing) address.
337 * \a block_size \e must be set to the value writted into \a func's
338 * I/O block size FBR register.
340 * If \a len % \a block_size == 0, a block mode transfer is used; a
341 * byte mode transfer is used if \a len < \a block_size.
343 * @param uif device handle.
344 * @param func card function.
345 * @param addr register/FIFO address.
346 * @param data buffer to store the data read.
347 * @param len length of data to read.
348 * @param block_size block size to use for this transfer.
349 * @param callback function to be called when the read completes.
350 * @param arg argument to be passed to callback.
352 * @return 0 on success; or -ve on error with errno set.
354 int LIBSDIOAPI
sdio_read_async(sdio_uif_t uif
, int func
, uint32_t addr
, uint8_t *data
,
355 size_t len
, int block_size
,
356 sdio_io_callback_t callback
, void *arg
);
359 * Write a buffer to an 8 bit wide register/FIFO, without waiting for
362 * The buffer write uses a fixed (not incrementing) address.
364 * \a block_size \e must be set to the value writted into \a func's
365 * I/O block size FBR register.
367 * If \a len % \a block_size == 0, a block mode transfer is used; a
368 * byte mode transfer is used if \a len < \a block_size.
370 * @param uif device handle.
371 * @param func card function.
372 * @param addr register/FIFO address.
373 * @param data buffer of data to write.
374 * @param len length of the data to write.
375 * @param block_size block size to use for this transfer.
376 * @param callback function to be called when the write completes.
377 * @param arg argument to be passed to callback.
379 * @return 0 on success; or -ve on error with errno set.
381 int LIBSDIOAPI
sdio_write_async(sdio_uif_t uif
, int func
, uint32_t addr
, const uint8_t *data
,
382 size_t len
, int block_size
,
383 sdio_io_callback_t callback
, void *arg
);
385 * Force a card removal and reinsertion.
387 * This will power cycle the card if the slot hardware supports power
390 * @note The device handle will no longer be valid.
392 * @param uif device handle.
394 * @return 0 on success; or -ve on error with errno set.
396 int LIBSDIOAPI
sdio_reinsert_card(sdio_uif_t uif
);
404 #endif /* #ifndef SDIOEMB_LIBSDIO_H */