Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
SDHC interface

SDHC interface . More...

Data Structures

struct  sdhc_command
 SD host controller command structure. More...
 
struct  sdhc_data
 SD host controller data structure. More...
 
struct  sdhc_host_caps
 SD host controller capabilities. More...
 
struct  sdhc_io
 SD host controller I/O control structure. More...
 
struct  sdhc_host_props
 SD host controller properties. More...
 
struct  sdhc_driver_api
 

Macros

#define SDHC_NATIVE_RESPONSE_MASK   0xF
 
#define SDHC_SPI_RESPONSE_TYPE_MASK   0xF0
 

Typedefs

typedef void(* sdhc_interrupt_cb_t) (const struct device *dev, int reason, const void *user_data)
 SDHC card interrupt callback prototype.
 

Enumerations

enum  sdhc_bus_mode { SDHC_BUSMODE_OPENDRAIN = 1 , SDHC_BUSMODE_PUSHPULL = 2 }
 SD bus mode. More...
 
enum  sdhc_power { SDHC_POWER_OFF = 1 , SDHC_POWER_ON = 2 }
 SD host controller power. More...
 
enum  sdhc_bus_width { SDHC_BUS_WIDTH1BIT = 1U , SDHC_BUS_WIDTH4BIT = 4U , SDHC_BUS_WIDTH8BIT = 8U }
 SD host controller bus width. More...
 
enum  sdhc_timing_mode {
  SDHC_TIMING_LEGACY = 1U , SDHC_TIMING_HS = 2U , SDHC_TIMING_SDR12 = 3U , SDHC_TIMING_SDR25 = 4U ,
  SDHC_TIMING_SDR50 = 5U , SDHC_TIMING_SDR104 = 6U , SDHC_TIMING_DDR50 = 7U , SDHC_TIMING_DDR52 = 8U ,
  SDHC_TIMING_HS200 = 9U , SDHC_TIMING_HS400 = 10U
}
 SD host controller timing mode. More...
 
enum  sd_voltage { SD_VOL_3_3_V = 1U , SD_VOL_3_0_V = 2U , SD_VOL_1_8_V = 3U , SD_VOL_1_2_V = 4U }
 SD voltage. More...
 
enum  sdhc_interrupt_source { SDHC_INT_SDIO = BIT(0) , SDHC_INT_INSERTED = BIT(1) , SDHC_INT_REMOVED = BIT(2) }
 SD host controller interrupt sources. More...
 

Functions

int sdhc_hw_reset (const struct device *dev)
 reset SDHC controller state
 
int sdhc_request (const struct device *dev, struct sdhc_command *cmd, struct sdhc_data *data)
 Send command to SDHC.
 
int sdhc_set_io (const struct device *dev, struct sdhc_io *io)
 set I/O properties of SDHC
 
int sdhc_card_present (const struct device *dev)
 check for SDHC card presence
 
int sdhc_execute_tuning (const struct device *dev)
 run SDHC tuning
 
int sdhc_card_busy (const struct device *dev)
 check if SD card is busy
 
int sdhc_get_host_props (const struct device *dev, struct sdhc_host_props *props)
 Get SD host controller properties.
 
int sdhc_enable_interrupt (const struct device *dev, sdhc_interrupt_cb_t callback, int sources, void *user_data)
 Enable SDHC interrupt sources.
 
int sdhc_disable_interrupt (const struct device *dev, int sources)
 Disable SDHC interrupt sources.
 

SD command timeouts

#define SDHC_TIMEOUT_FOREVER   (-1)
 

Detailed Description

SDHC interface .

Since
3.1
Version
0.1.0

Macro Definition Documentation

◆ SDHC_NATIVE_RESPONSE_MASK

#define SDHC_NATIVE_RESPONSE_MASK   0xF

◆ SDHC_SPI_RESPONSE_TYPE_MASK

#define SDHC_SPI_RESPONSE_TYPE_MASK   0xF0

◆ SDHC_TIMEOUT_FOREVER

#define SDHC_TIMEOUT_FOREVER   (-1)

Typedef Documentation

◆ sdhc_interrupt_cb_t

typedef void(* sdhc_interrupt_cb_t) (const struct device *dev, int reason, const void *user_data)

#include <zephyr/drivers/sdhc.h>

SDHC card interrupt callback prototype.

Function prototype for SDHC card interrupt callback.

Parameters
devSDHC device that produced interrupt
reasonone of sdhc_interrupt_source values.
user_dataUser data, set via sdhc_enable_interrupt

Enumeration Type Documentation

◆ sd_voltage

enum sd_voltage

#include <zephyr/drivers/sdhc.h>

SD voltage.

UHS cards can run with 1.8V signalling for improved power consumption. Legacy cards may support 3.0V signalling, and all cards start at 3.3V. Only relevant for SD controllers, not SPI ones.

Enumerator
SD_VOL_3_3_V 

card operation voltage around 3.3v

SD_VOL_3_0_V 

card operation voltage around 3.0v

SD_VOL_1_8_V 

card operation voltage around 1.8v

SD_VOL_1_2_V 

card operation voltage around 1.2v

◆ sdhc_bus_mode

#include <zephyr/drivers/sdhc.h>

SD bus mode.

Most controllers will use push/pull, including spi, but SDHC controllers that implement SD host specification can support open drain mode

Enumerator
SDHC_BUSMODE_OPENDRAIN 
SDHC_BUSMODE_PUSHPULL 

◆ sdhc_bus_width

#include <zephyr/drivers/sdhc.h>

SD host controller bus width.

Only relevant in SD mode, SPI does not support bus width. UHS cards will use 4 bit data bus, all cards start in 1 bit mode

Enumerator
SDHC_BUS_WIDTH1BIT 
SDHC_BUS_WIDTH4BIT 
SDHC_BUS_WIDTH8BIT 

◆ sdhc_interrupt_source

#include <zephyr/drivers/sdhc.h>

SD host controller interrupt sources.

Interrupt sources for SD host controller.

Enumerator
SDHC_INT_SDIO 

Card interrupt, used by SDIO cards.

SDHC_INT_INSERTED 

Card was inserted into slot.

SDHC_INT_REMOVED 

Card was removed from slot.

◆ sdhc_power

enum sdhc_power

#include <zephyr/drivers/sdhc.h>

SD host controller power.

Many host controllers can control power to attached SD cards. This enum allows applications to request the host controller power off the SD card.

Enumerator
SDHC_POWER_OFF 
SDHC_POWER_ON 

◆ sdhc_timing_mode

#include <zephyr/drivers/sdhc.h>

SD host controller timing mode.

Used by SD host controller to determine the timing of the cards attached to the bus. Cards start with legacy timing, but UHS-II cards can go up to SDR104.

Enumerator
SDHC_TIMING_LEGACY 

Legacy 3.3V Mode.

SDHC_TIMING_HS 

Legacy High speed mode (3.3V)

SDHC_TIMING_SDR12 

Identification mode & SDR12.

SDHC_TIMING_SDR25 

High speed mode & SDR25.

SDHC_TIMING_SDR50 

SDR49 mode.

SDHC_TIMING_SDR104 

SDR104 mode.

SDHC_TIMING_DDR50 

DDR50 mode.

SDHC_TIMING_DDR52 

DDR52 mode.

SDHC_TIMING_HS200 

HS200 mode.

SDHC_TIMING_HS400 

HS400 mode.

Function Documentation

◆ sdhc_card_busy()

int sdhc_card_busy ( const struct device * dev)

#include <zephyr/drivers/sdhc.h>

check if SD card is busy

This check should generally be implemented as checking the line level of the DAT[0:3] lines of the SD bus. No SD commands need to be sent, the controller simply needs to report the status of the SD bus.

Parameters
devSDHC device
Return values
0card is not busy
1card is busy
-EIOI/O error

◆ sdhc_card_present()

int sdhc_card_present ( const struct device * dev)

#include <zephyr/drivers/sdhc.h>

check for SDHC card presence

Checks if card is present on the SD bus. Note that if a controller requires cards be powered up to detect presence, it should do so in this function.

Parameters
devSDHC device
Return values
1card is present
0card is not present
-EIOI/O error

◆ sdhc_disable_interrupt()

int sdhc_disable_interrupt ( const struct device * dev,
int sources )

#include <zephyr/drivers/sdhc.h>

Disable SDHC interrupt sources.

Disables SDHC interrupt sources. If multiple sources are enabled, only the ones specified in "sources" will be masked.

Parameters
devSDHC device
sourcesbitmask of sdhc_interrupt_source values indicating which interrupts should be disabled.
Return values
0interrupts were disabled
-ENOTSUPcontroller does not support this function
-EIOI/O error

◆ sdhc_enable_interrupt()

int sdhc_enable_interrupt ( const struct device * dev,
sdhc_interrupt_cb_t callback,
int sources,
void * user_data )

#include <zephyr/drivers/sdhc.h>

Enable SDHC interrupt sources.

Enables SDHC interrupt sources. Each subsequent call of this function should replace the previous callback set, and leave only the interrupts specified in the "sources" argument enabled.

Parameters
devSDHC device
callbackCallback called when interrupt occurs
sourcesbitmask of sdhc_interrupt_source values indicating which interrupts should produce a callback
user_dataparameter that will be passed to callback function
Return values
0interrupts were enabled, and callback was installed
-ENOTSUPcontroller does not support this function
-EIOI/O error

◆ sdhc_execute_tuning()

int sdhc_execute_tuning ( const struct device * dev)

#include <zephyr/drivers/sdhc.h>

run SDHC tuning

SD cards require signal tuning for UHS modes SDR104 and SDR50. This function allows an application to request the SD host controller to tune the card.

Parameters
devSDHC device
Return values
0tuning succeeded, card is ready for commands
-ETIMEDOUTtuning failed after timeout
-ENOTSUPcontroller does not support tuning
-EIOI/O error while tuning

◆ sdhc_get_host_props()

int sdhc_get_host_props ( const struct device * dev,
struct sdhc_host_props * props )

#include <zephyr/drivers/sdhc.h>

Get SD host controller properties.

Gets host properties from the host controller. Host controller should initialize all values in the sdhc_host_props structure provided.

Parameters
devSDHC device
propsproperty structure to be filled by sdhc driver
Return values
0function succeeded.
-ENOTSUPhost controller does not support this call

◆ sdhc_hw_reset()

int sdhc_hw_reset ( const struct device * dev)

#include <zephyr/drivers/sdhc.h>

reset SDHC controller state

Used when the SDHC has encountered an error. Resetting the SDHC controller should clear all errors on the SDHC, but does not necessarily reset I/O settings to boot (this can be done with sdhc_set_io)

Parameters
devSD host controller device
Return values
0reset succeeded
-ETIMEDOUTcontroller reset timed out
-EIOreset failed

◆ sdhc_request()

int sdhc_request ( const struct device * dev,
struct sdhc_command * cmd,
struct sdhc_data * data )

#include <zephyr/drivers/sdhc.h>

Send command to SDHC.

Sends a command to the SD host controller, which will send this command to attached SD cards.

Parameters
devSDHC device
cmdSDHC command
dataSDHC data. Leave NULL to send SD command without data.
Return values
0command was sent successfully
-ETIMEDOUTcommand timed out while sending
-ENOTSUPhost controller does not support command
-EIOI/O error

◆ sdhc_set_io()

int sdhc_set_io ( const struct device * dev,
struct sdhc_io * io )

#include <zephyr/drivers/sdhc.h>

set I/O properties of SDHC

I/O properties should be reconfigured when the card has been sent a command to change its own SD settings. This function can also be used to toggle power to the SD card.

Parameters
devSDHC device
ioI/O properties
Returns
0 I/O was configured correctly
-ENOTSUP controller does not support these I/O settings
-EIO controller could not configure I/O settings