SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Enumerations | Functions | Variables
sys-sdhci.h File Reference
#include <io.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <types.h>
#include <reg/reg-smhc.h>
#include <sys-gpio.h>
#include <log.h>
#include "sys-mmc.h"
Include dependency graph for sys-sdhci.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  sunxi_sdhci_desc
 
struct  sunxi_sdhci_host
 
struct  sunxi_sdhci_pinctrl
 
struct  sunxi_sdhci_timing
 
struct  sunxi_sdhci_clk
 
struct  sunxi_sdhci
 

Macros

#define SMHC_DES_NUM_SHIFT   12 /* smhc2!! */
 
#define SMHC_DES_BUFFER_MAX_LEN   (1 << SMHC_DES_NUM_SHIFT)
 
#define MMC_REG_FIFO_OS   (0x200)
 
#define SMHC_TIMEOUT   0xfffff
 
#define SMHC_DMA_TIMEOUT   0xffffff
 
#define SMHC_WAITBUSY_TIMEOUT   0xfffff
 
#define SMHC_DATA_TIMEOUT   0xfffff
 
#define SMHC_RESP_TIMEOUT   0xff
 
#define SDHCI_DEFAULT_CLK_RST_OFFSET(x)   (16 + x)
 
#define SDHCI_DEFAULT_CLK_GATE_OFFSET(x)   (x)
 
#define SDHCI_DEFAULT_CLK_FACTOR_M_OFFSET   (0)
 
#define SDHCI_DEFAULT_CLK_FACTOR_N_OFFSET   (8)
 

Typedefs

typedef struct sunxi_sdhci_host sunxi_sdhci_host_t
 
typedef struct sunxi_sdhci_pinctrl sunxi_sdhci_pinctrl_t
 
typedef struct sunxi_sdhci_timing sunxi_sdhci_timing_t
 
typedef struct sunxi_sdhci_clk sunxi_sdhci_clk_t
 
typedef struct sunxi_sdhci sunxi_sdhci_t
 

Enumerations

enum  { MMC_CONTROLLER_0 = 0 , MMC_CONTROLLER_1 = 1 , MMC_CONTROLLER_2 = 2 }
 
enum  sunxi_sdhci_type_t { MMC_TYPE_SD , MMC_TYPE_EMMC }
 

Functions

struct sunxi_sdhci_desc __attribute__ ((aligned(8)))
 
int sunxi_sdhci_init (sunxi_sdhci_t *sdhci)
 Initialize the SDHC controller.
 
int sunxi_sdhci_core_init (sunxi_sdhci_t *sdhci)
 Initialize the core functionality of the SDHC controller.
 
void sunxi_sdhci_set_ios (sunxi_sdhci_t *sdhci)
 Set the I/O settings for the SDHC controller.
 
int sunxi_sdhci_update_phase (sunxi_sdhci_t *sdhci)
 Update phase for the SDHC controller.
 
int sunxi_sdhci_xfer (sunxi_sdhci_t *sdhci, mmc_cmd_t *cmd, mmc_data_t *data)
 Perform a data transfer operation on the SDHC controller.
 
void sunxi_sdhci_dump_reg (sunxi_sdhci_t *sdhci)
 Dump the contents of the SDHCI registers.
 
int sunxi_sdhci_set_mclk (sunxi_sdhci_t *sdhci, uint32_t clk_hz)
 Set the SDHC controller's clock frequency.
 
uint32_t sunxi_sdhci_get_mclk (sunxi_sdhci_t *sdhci)
 Get the current clock frequency of the SDHC controller.
 

Variables

uint32_t __pad0__
 
uint32_t dic
 
uint32_t last_desc
 
uint32_t first_desc
 
uint32_t des_chain
 
uint32_t end_of_ring
 
uint32_t err_flag
 
uint32_t own
 
uint32_t data_buf_sz
 
uint32_t data_buf_dummy
 
uint32_t buf_addr
 
uint32_t next_desc_addr
 

Macro Definition Documentation

◆ MMC_REG_FIFO_OS

#define MMC_REG_FIFO_OS   (0x200)

◆ SDHCI_DEFAULT_CLK_FACTOR_M_OFFSET

#define SDHCI_DEFAULT_CLK_FACTOR_M_OFFSET   (0)

◆ SDHCI_DEFAULT_CLK_FACTOR_N_OFFSET

#define SDHCI_DEFAULT_CLK_FACTOR_N_OFFSET   (8)

◆ SDHCI_DEFAULT_CLK_GATE_OFFSET

#define SDHCI_DEFAULT_CLK_GATE_OFFSET (   x)    (x)

◆ SDHCI_DEFAULT_CLK_RST_OFFSET

#define SDHCI_DEFAULT_CLK_RST_OFFSET (   x)    (16 + x)

◆ SMHC_DATA_TIMEOUT

#define SMHC_DATA_TIMEOUT   0xfffff

◆ SMHC_DES_BUFFER_MAX_LEN

#define SMHC_DES_BUFFER_MAX_LEN   (1 << SMHC_DES_NUM_SHIFT)

◆ SMHC_DES_NUM_SHIFT

#define SMHC_DES_NUM_SHIFT   12 /* smhc2!! */

◆ SMHC_DMA_TIMEOUT

#define SMHC_DMA_TIMEOUT   0xffffff

◆ SMHC_RESP_TIMEOUT

#define SMHC_RESP_TIMEOUT   0xff

◆ SMHC_TIMEOUT

#define SMHC_TIMEOUT   0xfffff

◆ SMHC_WAITBUSY_TIMEOUT

#define SMHC_WAITBUSY_TIMEOUT   0xfffff

Typedef Documentation

◆ sunxi_sdhci_clk_t

◆ sunxi_sdhci_host_t

◆ sunxi_sdhci_pinctrl_t

◆ sunxi_sdhci_t

typedef struct sunxi_sdhci sunxi_sdhci_t

◆ sunxi_sdhci_timing_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MMC_CONTROLLER_0 
MMC_CONTROLLER_1 
MMC_CONTROLLER_2 

◆ sunxi_sdhci_type_t

Enumerator
MMC_TYPE_SD 
MMC_TYPE_EMMC 

Function Documentation

◆ __attribute__()

struct sunxi_sdhci_desc __attribute__ ( (aligned(8))  )

◆ sunxi_sdhci_core_init()

int sunxi_sdhci_core_init ( sunxi_sdhci_t sdhci)

Initialize the core functionality of the SDHC controller.

This function initializes the core functionality of the SDHC controller, including resetting the controller, setting timeout values, configuring thresholds and debug parameters, and releasing the eMMC reset signal.

Parameters
sdhciPointer to the SDHC controller structure.
Returns
Returns 0 on success, -1 on failure.

◆ sunxi_sdhci_dump_reg()

void sunxi_sdhci_dump_reg ( sunxi_sdhci_t sdhci)

Dump the contents of the SDHCI registers.

This function dumps the contents of the SDHCI registers for a given SD card host controller.

Parameters
sdhciA pointer to the structure representing the SD card host controller.
Returns
void
Note
This function is useful for debugging and analyzing the state of the SD card controller.

◆ sunxi_sdhci_get_mclk()

uint32_t sunxi_sdhci_get_mclk ( sunxi_sdhci_t sdhci)
extern

Get the current clock frequency of the SDHC controller.

This function retrieves the current clock frequency of the specified SDHC controller.

Parameters
sdhciPointer to the SDHC controller structure.
Returns
Current clock frequency in Hertz.

◆ sunxi_sdhci_init()

int sunxi_sdhci_init ( sunxi_sdhci_t sdhci)

Initialize the SDHC controller.

This function initializes the SDHC controller by configuring its parameters, capabilities, and features based on the provided SDHC structure. It sets up the controller's timing mode, supported voltages, host capabilities, clock frequency limits, and register addresses. Additionally, it configures pin settings and enables clocks for the SDHC controller.

Parameters
sdhciPointer to the SDHC structure.
Returns
Returns 0 on success, -1 on failure.

◆ sunxi_sdhci_set_ios()

void sunxi_sdhci_set_ios ( sunxi_sdhci_t sdhci)

Set the I/O settings for the SDHC controller.

This function configures the I/O settings for the SDHC controller based on the provided MMC clock, bus width, and speed mode.

Parameters
sdhciPointer to the SDHC controller structure.
Returns
void

◆ sunxi_sdhci_set_mclk()

int sunxi_sdhci_set_mclk ( sunxi_sdhci_t sdhci,
uint32_t  clk_hz 
)
extern

Set the SDHC controller's clock frequency.

This function sets the clock frequency for the specified SDHC controller.

Parameters
sdhciPointer to the SDHC controller structure.
clk_hzDesired clock frequency in Hertz.
Returns
Returns 0 on success, -1 on failure.

◆ sunxi_sdhci_update_phase()

int sunxi_sdhci_update_phase ( sunxi_sdhci_t sdhci)

Update phase for the SDHC controller.

This function updates the phase for the specified SDHC controller.

Parameters
sdhciPointer to the SDHC controller structure.
Returns
Returns 0 on success.

◆ sunxi_sdhci_xfer()

int sunxi_sdhci_xfer ( sunxi_sdhci_t sdhci,
mmc_cmd_t cmd,
mmc_data_t data 
)

Perform a data transfer operation on the SDHC controller.

This function performs a data transfer operation on the SDHC controller, including sending a command and managing data transfer if present. It also handles error conditions such as fatal errors and card busy status.

Parameters
sdhciPointer to the SDHC controller structure.
cmdPointer to the MMC command structure.
dataPointer to the MMC data structure.
Returns
Returns 0 on success, -1 on failure.

Variable Documentation

◆ __pad0__

uint32_t __pad0__

◆ buf_addr

uint32_t buf_addr

◆ data_buf_dummy

uint32_t data_buf_dummy

◆ data_buf_sz

uint32_t data_buf_sz

◆ des_chain

uint32_t des_chain

◆ dic

uint32_t dic

◆ end_of_ring

uint32_t end_of_ring

◆ err_flag

uint32_t err_flag

◆ first_desc

uint32_t first_desc

◆ last_desc

uint32_t last_desc

◆ next_desc_addr

uint32_t next_desc_addr

◆ own

uint32_t own