4 * Copyright (C) 2007-2009 Cambridge Silicon Radio Ltd.
6 * Refer to LICENSE.txt included with this source code for details on
12 #include <sdioemb/sdio_api.h>
17 * @defgroup sdriver SDIO slot driver API
19 * @brief The SDIO slot driver API provides an interface for the SDIO
20 * layer to driver an SDIO slot (socket).
22 * Slot drivers register with the SDIO layer (sdioemb_slot_register()),
23 * providing functions to starting commands, enabling/disable card
24 * interrupts, card detection and bus power control.
26 * Functions are provided to notify the SDIO layer when a command has
27 * completed (sdioemb_cmd_complete()) and when an SDIO card interrupt has
28 * occurred (sdioemb_interrupt()).
31 #define SDIOEMB_BUS_FREQ_OFF 0
32 #define SDIOEMB_BUS_FREQ_DEFAULT -1
33 #define SDIOEMB_BUS_FREQ_IDLE -2
36 * Valid SDIO bus voltage levels.
41 SDIOEMB_POWER_OFF
= 0, /**< Power switched off. */
42 SDIOEMB_POWER_3V3
= 33, /**< Voltage set to 3.3V. */
46 * SDIO slot capabilities.
51 int max_bus_freq
; /**< Maximum bus frequency (Hz). */
52 int max_bus_width
; /**< Maximum bus width supported (1 or 4 data lines). */
53 uint8_t cspi_mode
; /**< CSPI_MODE register value (for CSPI capable slots). */
57 * Controller hardware type.
61 enum slot_controller_type
{
62 SDIOEMB_SLOT_TYPE_SD
= 0, /**< SD/SDIO controller. */
63 SDIOEMB_SLOT_TYPE_SPI
, /**< SPI controller. */
64 SDIOEMB_SLOT_TYPE_SPI_CSPI
, /**< SPI controller capable of CSPI. */
68 * Return values from the add_function() notifier.
72 enum sdioemb_add_func_status
{
74 * The core will call sdioemb_add_function().
76 SDIOEMB_ADD_FUNC_NOW
= 0,
78 * The slot driver will call sdioemb_add_function() or the
79 * function driver will call sdioemb_driver_probe() directly.
81 SDIOEMB_ADD_FUNC_DEFERRED
= 1,
85 * Slot/card event notifiers.
87 * A slot driver may be notified when certain slot or card events
92 struct sdioemb_slot_notifiers
{
94 * This is called when a card function has been enumerated
95 * and initialized but before can be bound to a function driver.
97 * A slot driver may use this to create an OS-specific object for
98 * the function. The slot driver must either (a) return
99 * SDIOEMB_ADD_FUNC_NOW; (b) return SDIOEMB_ADD_FUNC_DEFERRED and
100 * call sdioemb_add_function() later on; (c) return
101 * SDIOEMB_ADD_FUNC_DEFERRED and pass the fdev to the function
102 * driver for it to call sdioemb_driver_probe() directly; or (d)
105 * The slot driver may need to get a reference to the fdev with
106 * sdioemb_get_function() if the lifetime of the OS-specific
107 * object extends beyond the subsequent return of the
108 * del_function() callback.
110 * If this is non-NULL the slot driver must also provide
113 * @param slot the SDIO slot producing the notification.
114 * @param fdev the SDIO function being added.
116 * @return SDIOEMB_ADD_FUNC_NOW if the function is ready for use.
117 * @return SDIOEMB_ADD_FUNC_DEFERRED if sdioemb_add_function() or
118 * sdioemb_driver_probe() will be called later.
119 * @return -ve on a error.
121 int (*add_function
)(struct sdioemb_slot
*slot
, struct sdioemb_dev
*fdev
);
124 * This is called when a card function is being removed and after
125 * any function driver has been unbound.
127 * A slot driver may use this to delete any OS-specific object
128 * created by the add_function() notifier.
130 * @param slot the SDIO slot producing the notification.
131 * @param fdev the SDIO function being deleted.
133 void (*del_function
)(struct sdioemb_slot
*slot
, struct sdioemb_dev
*fdev
);
136 struct sdioemb_slot_priv
;
139 * An SDIO slot driver.
141 * Allocate and free with sdioemb_slot_alloc() and sdioemb_slot_free().
145 struct sdioemb_slot
{
147 * Name of the slot used in diagnostic messages.
149 * This would typically include the name of the SDIO controller
150 * and the slot number if the controller has multiple slots.
152 * This will be set by sdioemb_slot_register() if it is left as an
158 * Controller hardware type.
160 enum slot_controller_type type
;
163 * Set the SD bus clock frequency.
165 * The driver's implementation should set the SD bus clock to not
166 * more than \a clk Hz (unless \a clk is equal to
167 * #SDIOEMB_BUS_FREQ_OFF or #SDIOEMB_BUS_FREQ_IDLE).
169 * If \a clk == SDIOEMB_BUS_FREQ_OFF the clock should be stopped.
171 * \a clk == SDIOEMB_BUS_FREQ_IDLE indicates that the bus is idle
172 * (currently unused) and the host controller may slow (or stop)
173 * the SD bus clock to save power on the card. During this idle
174 * state the host controller must be capable of receiving SDIO
175 * interrupts (for certain host controllers this may require
176 * leaving the clock running).
178 * If \a clk is greater than #SDIO_CLOCK_FREQ_NORMAL_SPD (25 MHz)
179 * subsequent commands should be done with the controller in high
182 * Called from: interrupt context.
184 * @param slot the slot to configure.
185 * @param clk new SD bus clock frequency in Hz, SDIOEMB_BUS_FREQ_OFF
186 * or SDIOEMB_BUS_FREQ_IDLE.
188 * @return The bus frequency actually configured in Hz.
190 int (*set_bus_freq
)(struct sdioemb_slot
*slot
, int clk
);
193 * Set the SD bus width.
195 * The driver's implementation should set the width of the SD bus
196 * for all subsequent data transfers to the specified value.
198 * This may be NULL if the driver sets the bus width when starting
199 * a command, or the driver is for an SDIO-SPI or CSPI controller.
201 * Called from: thread context.
203 * @param slot the slot to configure.
204 * @param bus_width new SD bus width (either 1 or 4).
206 * @return 0 on success.
207 * @return -ve if a low-level error occured when setting the bus width.
209 int (*set_bus_width
)(struct sdioemb_slot
*slot
, int bus_width
);
212 * Start an SDIO command.
214 * The driver's implementation should:
216 * - set the controller's bus width to #bus_width,
217 * - program the controller to start the command.
219 * Called from: interrupt context.
221 * @param slot slot to perform the command.
222 * @param cmd SDIO command to start.
224 int (*start_cmd
)(struct sdioemb_slot
*slot
, struct sdioemb_cmd
*cmd
);
227 * Detect if a card is inserted into the slot.
229 * Called from: thread context.
231 * @param slot slot to check.
233 * @return non-zero if a card is inserted; 0 otherwise.
235 int (*card_present
)(struct sdioemb_slot
*slot
);
238 * Switch on/off the SDIO bus power and set the SDIO bus voltage.
240 * Called from: thread context.
242 * @param slot the slot.
243 * @param power the requested voltage.
245 * @return 0 on success; -ve on error: -EINVAL - requested voltage
248 int (*card_power
)(struct sdioemb_slot
*slot
, enum sdioemb_power power
);
251 * Enable (unmask) the SDIO card interrupt on the controller.
253 * Called from: interrupt context.
255 * @param slot the slot to enable the interrupt on..
257 void (*enable_card_int
)(struct sdioemb_slot
*slot
);
260 * Disable (mask) the SDIO card interrupt on the controller.
262 * Called from: thread context.
264 * @param slot the slot to disable the interrupt on.
266 void (*disable_card_int
)(struct sdioemb_slot
*slot
);
269 * Perform a hard reset of the card.
271 * Hard resets can be achieved in two ways:
273 * -# Power cycle (if the slot has power control).
274 * -# Platform-specific assertion of a card/chip reset line.
276 * If hard resets are not supported, either return 0 or set
277 * hard_reset to NULL.
279 * @param slot the slot for the card to reset.
281 * @return 0 if a hard reset was performed.
282 * @return 1 if hard resets are not supported.
284 int (*hard_reset
)(struct sdioemb_slot
*slot
);
286 struct slot_caps caps
; /**< Slot capabilities. */
287 int clock_freq
; /**< SD bus frequency requested by the SDIO layer. */
288 int bus_width
; /**< Bus width requested by the SDIO layer. */
289 struct sdioemb_slot_notifiers notifs
; /**< Slot event notifiers. */
290 int cspi_reg_pad
; /**< Padding for CSPI register reads. */
291 int cspi_burst_pad
; /**< Padding for CSPI burst reads. */
292 struct sdioemb_slot_priv
*priv
; /**< Data private to the SDIO layer. */
293 void * drv_data
; /**< Data private to the slot driver. */
296 struct sdioemb_slot
*sdioemb_slot_alloc(size_t drv_data_size
);
297 void sdioemb_slot_free(struct sdioemb_slot
*slot
);
298 int sdioemb_slot_register(struct sdioemb_slot
*slot
);
299 void sdioemb_slot_unregister(struct sdioemb_slot
*slot
);
300 int sdioemb_card_inserted(struct sdioemb_slot
*slot
);
301 void sdioemb_card_removed(struct sdioemb_slot
*slot
);
302 void sdioemb_interrupt(struct sdioemb_slot
*slot
);
303 void sdioemb_cmd_complete(struct sdioemb_slot
*slot
, struct sdioemb_cmd
*cmd
);
305 void sdioemb_suspend(struct sdioemb_slot
*slot
);
306 void sdioemb_resume(struct sdioemb_slot
*slot
);
308 void sdioemb_add_function(struct sdioemb_dev
*fdev
);
309 void sdioemb_del_function(struct sdioemb_dev
*fdev
);
310 void sdioemb_get_function(struct sdioemb_dev
*fdev
);
311 void sdioemb_put_function(struct sdioemb_dev
*fdev
);
313 #endif /* #ifndef _SLOT_API_H */