![]() |
SyterKit 0.4.0.x
SyterKit is a bare-metal framework
|
#include <barrier.h>#include <io.h>#include <stdarg.h>#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <types.h>#include <log.h>#include <timer.h>#include <sys-clk.h>#include <sys-gpio.h>#include <mmc/sys-mmc.h>#include <mmc/sys-sdhci.h>
Macros | |
| #define | UNSTUFF_BITS(resp, start, size) |
| Extracts a specified bit field from a response buffer. | |
Functions | |
| static int | sunxi_mmc_host_is_spi (mmc_t *mmc) |
| Checks if the MMC host operates in SPI mode. | |
| static int | sunxi_mmc_device_is_sd (mmc_t *mmc) |
| Checks if the MMC device is an SD card. | |
| static uint32_t | extract_mid (mmc_t *card) |
| Extracts the Manufacturer ID from the MMC card. | |
| static uint32_t | extract_oid (mmc_t *card) |
| Extracts the OEM/Application ID from the MMC card. | |
| static uint32_t | extract_prv (mmc_t *card) |
| Extracts the Product Revision from the MMC card. | |
| static uint32_t | extract_psn (mmc_t *card) |
| Extracts the Product Serial Number (PSN) from the MMC card. | |
| static uint32_t | extract_month (mmc_t *card) |
| Extracts the manufacturing month from the MMC card. | |
| static uint32_t | extract_year (mmc_t *card) |
| Extracts the manufacturing year from the MMC card. | |
| static int | sunxi_mmc_send_status (sunxi_sdhci_t *sdhci, uint32_t timeout) |
| Sends status command to the SD/MMC card and waits for the card to be ready. | |
| static int | sunxi_mmc_set_block_len (sunxi_sdhci_t *sdhci, uint32_t len) |
| Sets the block length for data transfer on the SD/MMC card. | |
| static uint32_t | sunxi_mmc_read_blocks (sunxi_sdhci_t *sdhci, void *dst, uint32_t start, uint32_t blkcnt) |
| Reads blocks from the SD/MMC card. | |
| static uint32_t | sunxi_mmc_write_blocks (sunxi_sdhci_t *sdhci, void *dst, uint32_t start, uint32_t blkcnt) |
| Writes blocks of data to the MMC device. | |
| static int | sunxi_mmc_go_idle (sunxi_sdhci_t *sdhci) |
| Sends the SD/MMC card to idle state. | |
| static int | sunxi_mmc_sd_send_op_cond (sunxi_sdhci_t *sdhci) |
| Sends SD card initialization sequence and waits for it to become ready. | |
| static int | sunxi_mmc_mmc_send_op_cond (sunxi_sdhci_t *sdhci) |
| Send the SEND_OP_COND command to the MMC/SD card. | |
| static int | sunxi_mmc_send_ext_csd (sunxi_sdhci_t *sdhci, char *ext_csd) |
| Send the SEND_EXT_CSD command to retrieve the Extended CSD from the MMC/SD card. | |
| static int | sunxi_mmc_switch (sunxi_sdhci_t *sdhci, uint8_t set, uint8_t index, uint8_t value) |
| Send the SWITCH command to the MMC/SD card to change a specified mode or setting. | |
| static int | sunxi_mmc_mmc_change_freq (sunxi_sdhci_t *sdhci) |
| Change the frequency of the MMC/SD card to support high-speed modes. | |
| static int | sunxi_mmc_sd_switch (sunxi_sdhci_t *sdhci, int mode, int group, uint8_t value, uint8_t *resp) |
| Switch the functionality of the SD card. | |
| static int | sunxi_mmc_sd_change_freq (sunxi_sdhci_t *sdhci) |
| Change the frequency of the SD card. | |
| static void | sunxi_mmc_set_clock (sunxi_sdhci_t *sdhci, uint32_t clock) |
| Set the clock frequency for the Sunxi SDHCI controller. | |
| static void | sunxi_mmc_set_bus_width (sunxi_sdhci_t *sdhci, uint32_t width) |
| Set the bus width for the Sunxi SDHCI controller. | |
| static int | sunxi_mmc_mmc_switch_ds (sunxi_sdhci_t *sdhci) |
| Switch the Sunxi SDHCI controller to Double Speed (DS) mode. | |
| static int | sunxi_mmc_mmc_switch_hs (sunxi_sdhci_t *sdhci) |
| Switch the Sunxi SDHCI controller to High Speed (HS) mode. | |
| static int | sunxi_mmc_mmc_switch_hs200 (sunxi_sdhci_t *sdhci) |
| Switch the Sunxi SDHCI controller to High Speed 200 (HS200) mode. | |
| static int | sunxi_mmc_mmc_switch_hs400 (sunxi_sdhci_t *sdhci) |
| Switch the Sunxi SDHCI controller to High Speed 400 (HS400) mode. | |
| static int | sunxi_mmc_mmc_switch_speed_mode (sunxi_sdhci_t *sdhci, uint32_t spd_mode) |
| Switches the speed mode of the MMC controller. | |
| static int | sunxi_mmc_check_bus_width (sunxi_sdhci_t *sdhci, uint32_t emmc_hs_ddr, uint32_t bus_width) |
| Checks if the specified bus width is supported by the MMC controller. | |
| static int | sunxi_mmc_mmc_switch_bus_width (sunxi_sdhci_t *sdhci, uint32_t spd_mode, uint32_t width) |
| Switches the bus width of the MMC controller. | |
| static int | sunxi_mmc_mmc_switch_bus_mode (sunxi_sdhci_t *sdhci, uint32_t spd_mode, uint32_t width) |
| Switches the speed mode and bus width of the MMC controller. | |
| static int | sunxi_mmc_sd_send_if_cond (sunxi_sdhci_t *sdhci) |
| Sends the SD CMD8 (SEND_IF_COND) command to the MMC controller. | |
| static void | sunxi_mmc_show_card_info (sunxi_sdhci_t *sdhci) |
| Displays information about the SD/MMC card attached to the given host controller. | |
| static int | sunxi_mmc_probe (sunxi_sdhci_t *sdhci) |
| Probes the SD/MMC card attached to the given host controller. | |
| int | sunxi_mmc_init (void *sdhci_hdl) |
| Initializes the SD/MMC host controller and attached card. | |
| uint32_t | sunxi_mmc_blk_read (void *sdhci, void *dst, uint32_t start, uint32_t blkcnt) |
| Read blocks from the Sunxi MMC block device. | |
| uint32_t | sunxi_mmc_blk_write (void *sdhci, void *dst, uint32_t start, uint32_t blkcnt) |
| Writes blocks of data to the MMC device using the specified SDHCI instance. | |
Variables | |
| static const int | tran_speed_unit [] |
| static const int | tran_speed_time [] |
| #define UNSTUFF_BITS | ( | resp, | |
| start, | |||
| size | |||
| ) |
Extracts a specified bit field from a response buffer.
This macro extracts a specified bit field from a response buffer or an array of integers. It calculates the offset, shift amount, and bitmask based on the starting position and size of the field, then performs the extraction and applies the bitmask to isolate the desired bits.
| resp | The response buffer or array of integers. |
| start | The starting bit position of the field within the response buffer. |
| size | The size (in bits) of the field to be extracted. |
Extracts the Manufacturer ID from the MMC card.
This function extracts the Manufacturer ID from the MMC card's CID (Card Identification Data) register. The extraction is performed based on the MMC version and CID structure.
| card | Pointer to the MMC card structure. |
Extracts the manufacturing month from the MMC card.
This function extracts the manufacturing month from the MMC card's CID (Card Identification Data) register.
| card | Pointer to the MMC card structure. |
Extracts the OEM/Application ID from the MMC card.
This function extracts the OEM/Application ID from the MMC card's CID (Card Identification Data) register.
| card | Pointer to the MMC card structure. |
Extracts the Product Revision from the MMC card.
This function extracts the Product Revision from the MMC card's CID (Card Identification Data) register.
| card | Pointer to the MMC card structure. |
Extracts the Product Serial Number (PSN) from the MMC card.
This function extracts the Product Serial Number (PSN) from the MMC card based on its version and CSD/CID structure.
| card | Pointer to the MMC card structure. |
Extracts the manufacturing year from the MMC card.
This function extracts the manufacturing year from the MMC card's CID (Card Identification Data) register.
| card | Pointer to the MMC card structure. |
Read blocks from the Sunxi MMC block device.
This function reads a specified number of blocks from the Sunxi MMC block device and stores the data into the destination buffer.
| sdhci | Pointer to the Sunxi SD Host Controller instance |
| dst | Pointer to the destination buffer where the read data will be stored |
| start | The starting block number to read from |
| blkcnt | The number of blocks to read |
Writes blocks of data to the MMC device using the specified SDHCI instance.
This function writes a specified number of blocks to the MMC (MultiMediaCard) device associated with the given SDHCI (SD Host Controller Interface) instance. It serves as a wrapper around the sunxi_mmc_write_blocks function, providing a simplified interface for block data write operations.
| [in] | sdhci | A pointer to the SDHCI instance. |
| [in] | dst | A pointer to the destination buffer from which data will be written to the MMC. |
| [in] | start | The starting block number where the data writing begins. |
| [in] | blkcnt | The number of blocks to write. |
|
static |
Checks if the specified bus width is supported by the MMC controller.
This function checks if the specified bus width is supported by the MMC controller, based on the provided parameters.
| sdhci | Pointer to the SD/MMC host controller structure. |
| emmc_hs_ddr | Flag indicating if eMMC high-speed DDR mode is enabled. |
| bus_width | The bus width to be checked. |
|
inlinestatic |
Checks if the MMC device is an SD card.
This function checks if the MMC device is an SD card based on its version information.
| mmc | Pointer to the MMC structure. |
|
static |
Sends the SD/MMC card to idle state.
This function sends the SD/MMC card to the idle state, preparing it for further commands.
| sdhci | Pointer to the SDHCI controller structure. |
|
inlinestatic |
Checks if the MMC host operates in SPI mode.
This function checks if the MMC host operates in SPI mode based on its capabilities.
| mmc | Pointer to the MMC structure. |
| int sunxi_mmc_init | ( | void * | sdhci_hdl | ) |
Initializes the SD/MMC host controller and attached card.
This function initializes the specified SD/MMC host controller and the attached SD/MMC card. It initializes the host controller core, sets the bus width and clock speed, resets the card, and initializes the card based on its type (SD or eMMC). Finally, it probes the card to retrieve card-specific data.
| sdhci_hdl | Pointer to the SD/MMC host controller structure. |
|
static |
Change the frequency of the MMC/SD card to support high-speed modes.
This function changes the frequency of the MMC/SD card to support high-speed modes. It checks if the card supports high-speed modes and switches to the appropriate mode if possible.
| sdhci | Pointer to the Sunxi SDHCI controller structure. |
|
static |
Send the SEND_OP_COND command to the MMC/SD card.
This function sends the SEND_OP_COND command to the MMC/SD card to initialize and check its capabilities. It waits for the card to respond and initializes it, updating the MMC structure with card information upon successful initialization.
| sdhci | Pointer to the Sunxi SDHCI controller structure. |
|
static |
Switches the speed mode and bus width of the MMC controller.
This function switches the speed mode and bus width of the MMC controller based on the provided parameters. If the device is an SD card, no action is taken and the function returns successfully.
| sdhci | Pointer to the SD/MMC host controller structure. |
| spd_mode | Speed mode to be switched to. |
| width | The bus width to be set. |
|
static |
Switches the bus width of the MMC controller.
This function switches the bus width of the MMC controller based on the provided parameters.
| sdhci | Pointer to the SD/MMC host controller structure. |
| spd_mode | Speed mode of the MMC controller. |
| width | The bus width to be set. |
|
static |
Switch the Sunxi SDHCI controller to Double Speed (DS) mode.
This function switches the Secure Digital Host Controller Interface (SDHCI) in a Sunxi system-on-a-chip (SoC) environment to Double Speed (DS) mode.
| sdhci | A pointer to the Sunxi SDHCI controller structure. |
|
static |
Switch the Sunxi SDHCI controller to High Speed (HS) mode.
This function switches the Secure Digital Host Controller Interface (SDHCI) in a Sunxi system-on-a-chip (SoC) environment to High Speed (HS) mode.
| sdhci | A pointer to the Sunxi SDHCI controller structure. |
|
static |
Switch the Sunxi SDHCI controller to High Speed 200 (HS200) mode.
This function switches the Secure Digital Host Controller Interface (SDHCI) in a Sunxi system-on-a-chip (SoC) environment to High Speed 200 (HS200) mode.
| sdhci | A pointer to the Sunxi SDHCI controller structure. |
|
static |
Switch the Sunxi SDHCI controller to High Speed 400 (HS400) mode.
This function switches the Secure Digital Host Controller Interface (SDHCI) in a Sunxi system-on-a-chip (SoC) environment to High Speed 400 (HS400) mode.
| sdhci | A pointer to the Sunxi SDHCI controller structure. |
|
static |
Switches the speed mode of the MMC controller.
This function switches the speed mode of the MMC controller based on the provided speed mode.
| sdhci | Pointer to the SD/MMC host controller structure. |
| spd_mode | Speed mode to be switched to. |
|
static |
Probes the SD/MMC card attached to the given host controller.
This function probes the SD/MMC card attached to the specified host controller, retrieves various card-specific data such as CID and CSD, and sets the card to the appropriate mode. It also handles sending commands and checking for errors.
| sdhci | Pointer to the SD/MMC host controller structure. |
|
static |
Reads blocks from the SD/MMC card.
This function reads blocks from the SD/MMC card starting from the specified block address. It supports reading multiple blocks and handles high capacity cards appropriately.
| sdhci | Pointer to the SDHCI controller structure. |
| dst | Pointer to the destination buffer where the data will be stored. |
| start | Start block address from where to read the data. |
| blkcnt | Number of blocks to read. |
|
static |
Change the frequency of the SD card.
This function changes the operating frequency of the SD card based on its capabilities. It reads the SCR (SD Configuration Register) to determine if the card supports higher speeds. If the card supports higher speeds, it adjusts the frequency accordingly.
| sdhci | Pointer to the Sunxi SDHCI controller structure. |
|
static |
Sends the SD CMD8 (SEND_IF_COND) command to the MMC controller.
This function sends the SD CMD8 command to the MMC controller to check if the card supports the given voltage range.
| sdhci | Pointer to the SD/MMC host controller structure. |
|
static |
Sends SD card initialization sequence and waits for it to become ready.
This function sends the SD card initialization sequence, which includes sending application-specific commands and checking the card's response until it becomes ready. It also updates the MMC structure with relevant information such as the card version, OCR value, and high capacity flag.
| sdhci | Pointer to the SDHCI controller structure. |
|
static |
Switch the functionality of the SD card.
This function switches the functionality of the SD card, such as changing the frequency or mode of operation. It sends a SWITCH_FUNC command to the SD card with the specified parameters to perform the desired switch.
| sdhci | Pointer to the Sunxi SDHCI controller structure. |
| mode | Switch mode indicating the type of switch operation to perform. |
| group | Switch group indicating the group of functions to switch. |
| value | Value indicating the specific function or setting to switch to within the specified group. |
| resp | Pointer to a buffer to store the response from the SD card. |
|
static |
Send the SEND_EXT_CSD command to retrieve the Extended CSD from the MMC/SD card.
This function sends the SEND_EXT_CSD command to the MMC/SD card to retrieve its Extended CSD register, which contains various configuration parameters and settings. It stores the retrieved Extended CSD data in the provided buffer.
| sdhci | Pointer to the Sunxi SDHCI controller structure. |
| ext_csd | Pointer to the buffer where the Extended CSD data will be stored. |
|
static |
Sends status command to the SD/MMC card and waits for the card to be ready.
This function sends the status command to the SD/MMC card and waits for the card to be ready for data transfer. It retries sending the command until the card is ready or until the timeout expires.
| sdhci | Pointer to the SDHCI controller structure. |
| timeout | Timeout value in milliseconds. |
|
static |
Sets the block length for data transfer on the SD/MMC card.
This function sets the block length for data transfer on the SD/MMC card, except in DDR mode.
| sdhci | Pointer to the SDHCI controller structure. |
| len | Block length to be set. |
|
static |
Set the bus width for the Sunxi SDHCI controller.
This function sets the bus width for the Secure Digital Host Controller Interface (SDHCI) in a Sunxi system-on-a-chip (SoC) environment.
| sdhci | A pointer to the Sunxi SDHCI controller structure. |
| width | The bus width to be set (in bits). |
|
static |
Set the clock frequency for the Sunxi SDHCI controller.
This function sets the clock frequency for the Secure Digital Host Controller Interface (SDHCI) in a Sunxi system-on-a-chip (SoC) environment.
| sdhci | A pointer to the Sunxi SDHCI controller structure. |
| clock | The desired clock frequency to be set. |
|
static |
Displays information about the SD/MMC card attached to the given host controller.
This function prints various details about the SD/MMC card attached to the specified host controller, such as the card type, capacity, CID, CSD, maximum transfer speed, manufacturer ID, OEM/application ID, product name, product revision, serial number, and manufacturing date.
| sdhci | Pointer to the SD/MMC host controller structure. |
|
static |
Send the SWITCH command to the MMC/SD card to change a specified mode or setting.
This function sends the SWITCH command to the MMC/SD card to change a specified mode or setting. It is typically used to modify various parameters or configurations of the card.
| sdhci | Pointer to the Sunxi SDHCI controller structure. |
| set | Value indicating the type of setting to be changed. |
| index | Index of the setting within the specified set. |
| value | New value to set for the specified setting. |
|
static |
Writes blocks of data to the MMC device.
This function writes a specified number of blocks to the MMC (MultiMediaCard) device associated with the given SDHCI (SD Host Controller Interface) instance. It supports both single block and multiple block write operations, and handles sending the appropriate commands to the MMC device.
| [in] | sdhci | A pointer to the SDHCI instance. |
| [in] | dst | A pointer to the destination buffer from which data will be written to the MMC. |
| [in] | start | The starting block number where the data writing begins. |
| [in] | blkcnt | The number of blocks to write. |
|
static |
|
static |