SDMMC USER GUIDE


REVISION HISTORY

Revision No.
Description
Date
1.0
  • Initial release
  • 04/15/2025

    1. OVERVIEW

    MMC under Kernel adopts the standard Linux framework and can use standard interfaces to drive MMC Device (eMMC card, SD card or SDIO device).

    The MMC subsystem consists of the card layer, core layer and host layer. The card layer registers the entire MMC Device as an MMC Block Device, which can support the data request work of the upper layer; the core layer implements the initialization process and reading and writing work in the MMC/SD/SDIO protocol. The host layer can mobilize the hardware and communicate the cmd or data request passed down by the core layer with the eMMC/SD/SDIO card through the FCIE/SDIO Engine.

    Figure 1-1: SDMMC Host Layer Framework

    The overall framework of the SD host layer consists of three layers, namely the MDrv layer, the Hal layer, the Support layer, and the MMC device connected to the Support layer. The functions of each layer are as follows:

    Drv layer:

    The Drv layer mainly completes the host registration, improves the description of the mmc_host and mmc_host_ops structures, adds the host information to the core layer, and provides some additional encapsulation interfaces to set or obtain the status of the Engine and the card for the user layer, such as debug_get_sdmmc_clock, set_sdmmc_driving_control, etc. In addition, the Drv layer also completes the MIE and hot-swap interrupt registration to ensure the normal transmission of subsequent signals and the plug-in and plug-out detection of the card.

    Hal layer:

    The Hal layer directly sets registers and is closely related to the HW Engine. It mainly includes the hal_sdmmc_v5.c file that operates the Host Engine. The sending and receiving of commands and data is implemented in this file. The hal_sdmmc_platform_common.c file determines which group of pad pins the Host Engine connects to and performs operations such as pull-up and pull-down on it. The hal_sdmmc_intr.c file is related to interrupt processing, and the hal_sdmmc_timer.c file is related to time processing, etc.

    Support layer:

    This layer belongs to the hardware support layer, and the related final implementation of the driver requires hardware support.

    MMC device:

    MMC devices, such as SD/SDIO cards, are directly connected to the driver's hardware support and are the driver's final operation object.


    2. KEYWORD DESCRIPTION

    IP: Host Engine connected to SD/SDIO cards.

    IP bank: Register address of Host Engine used by driver to access SD/SDIO cards.

    SDSC: Standard capacity card, no larger than 2GB.

    SDHC: High capacity card, larger than 2GB but no larger than 32GB.

    SDXC: Extended capacity card, larger than 32GB.


    3. FUNCTION DESCRIPTION

    Products SD card Bus bandwidth Clock range SD3.0 supported speed modes SD2.0 supported speed modes IP bank
    pcupid SD0 Card 1, 4 300k-48M Not supported Default Speed, High Speed FCIE: 0x1410
    pcupid SD1 Card 1, 4 300k-48M Not supported Default Speed, High Speed SDIO: 0x1413

    Pcupid has two IPs, one of which is FCIE IP, which supports connecting to EMMC or SD card, and the other is SDIO IP, which supports connecting to SD card or SDIO card. In other words, the chip specification only supports two MMC devices at most.

    Bus bandwidth setting:

    SD supports configuring 1-1bit mode/4-4bit mode two bus bandwidths, and the default mode is 4bit mode. The SDIO card needs to set the bandwidth to 1bit mode, which can be set by setting the sdio-use-1bit parameter in the device tree.

    Clock setting:

    Supports configuration of clock frequencies within the range of 300KHz-48MHz. The maximum clock can be set by modifying the max-frequency parameter in the device tree. The final set clock frequency is the maximum frequency supported by the current bus speed.

    Figure 3-1: SDMMC Bus Speed Mode

    Configuring different bus bandwidths and clock frequencies will affect the data transfer speed. SD3.0 supports the use of SDR50, SDR104 and DDR50 speed modes. If you want to use them, you can configure sd-uhs-sdr50/sd-uhs-sdr104/sd-uhs-ddr50 in the corresponding slots in the device tree. Pcupid does not support SD3.0.

    pcupid supports SD2.0. The actual experiment is in High Speed ​​mode. The clock frequency and theoretical speed supported by the hardware refer to the following table(implies x4 bus width).

    No Clock frequency(Hz) Transfer rate(MB/s)
    0 300000 1.5
    1 12000000 6
    2 20000000 10
    3 32000000 16
    4 36000000 18
    5 40000000 20
    6 43200000 21.6
    7 48000000 24

    Note that the actual read and write speed is affected by factors such as cmd transmission consumption and mmc device performance during the read and write process, and cannot reach the theoretical speed. To test the performance, it is recommended to use the fio tool to read and write large files for testing.

    Speed Mode:

    (1) Check the SD card speed mode.

    cat /sys/kernel/debug/mmc1/ios

    Figure 3-2: Sdmmc-12

    (2) Set the SD card speed mode.

    The SD card speed mode can be directly configured in the dtsi file.

    Figure 3-3: Sdmmc-13


    4. HARDWARE CONNECTION INTRODUCTION

    4.1. Pcupid

    Figure 4-1: SD0 Hardware Schematic

    Figure 4-2: SD1 Hardware Schematic

    The software padmux settings corresponding to the hardware connection are as follows:

    1.    padmux {
    2.        compatible = "sstar-padmux";
    3.        schematic =
    4.            // SDMMC0
    5.            <PAD_GPIOE_00            PINMUX_FOR_SD_BOOT_MODE_1        MDRV_PUSE_EMMC_D1>,
    6.            <PAD_GPIOE_01            PINMUX_FOR_SD_BOOT_MODE_1        MDRV_PUSE_EMMC_D0>,
    7.            <PAD_GPIOE_02            PINMUX_FOR_SD_BOOT_MODE_1        MDRV_PUSE_EMMC_CLK>,
    8.            <PAD_GPIOE_03            PINMUX_FOR_SD_BOOT_MODE_1        MDRV_PUSE_EMMC_CMD>,
    9.            <PAD_GPIOE_04            PINMUX_FOR_SD_BOOT_MODE_1        MDRV_PUSE_EMMC_D3>,
    10.           <PAD_GPIOE_05            PINMUX_FOR_SD_BOOT_MODE_1        MDRV_PUSE_EMMC_D2>,
    11.           <PAD_GPIOE_07            PINMUX_FOR_GPIO_MODE             MDRV_PUSE_EMMC_PWR>,
    12.           <PAD_GPIOE_06            PINMUX_FOR_SD_BOOT_MODE_1        MDRV_PUSE_EMMC_RST>,
    13.           // SDMMC1
    14.           <PAD_GPIOA_00            PINMUX_FOR_SDIO_MODE_1           MDRV_PUSE_SDIO0_D1>,
    15.           <PAD_GPIOA_01            PINMUX_FOR_SDIO_MODE_1           MDRV_PUSE_SDIO0_D0>,
    16.           <PAD_GPIOA_02            PINMUX_FOR_SDIO_MODE_1           MDRV_PUSE_SDIO0_CLK>,
    17.           <PAD_GPIOA_03            PINMUX_FOR_SDIO_MODE_1           MDRV_PUSE_SDIO0_CMD>,
    18.           <PAD_GPIOA_04            PINMUX_FOR_SDIO_MODE_1           MDRV_PUSE_SDIO0_D3>,
    19.           <PAD_GPIOA_05            PINMUX_FOR_SDIO_MODE_1           MDRV_PUSE_SDIO0_D2>,
    20.           <PAD_GPIOA_07            PINMUX_FOR_GPIO_MODE             MDRV_PUSE_SDIO0_PWR>,
    21.           <PAD_GPIOA_06            PINMUX_FOR_SDIO_CDZ_MODE_1       MDRV_PUSE_SDIO0_CDZ>,
    22.    };
    

    The first column indicates the pad name of sd, the second column indicates the pad mode, which is set according to the usage of the pad, and the third column is the identifier used by the driver,the field names are independent of the device type.For configuration of device type, refer to the device node parameter description in the following chapters. SD0 corresponds to the software SDMMC0, that is, the PAD_GPIOE_XX pad group, and the pad mode can choose PINMUX_FOR_SD_BOOT_MODE_1 or PINMUX_FOR_SDIO_MODE_2.SD boot needs to select PINMUX_FOR_SD_BOOT_MODE_1. SD1 corresponds to the software SDMMC1, that is, the PAD_GPIOA_XX pad group, and the pad mode can only be PINMUX_FOR_SDIO_MODE_1. Since PINMUX_FOR_SDIO_MODE_1 and PINMUX_FOR_SDIO_MODE_2 use the same IP, they cannot be set on SDMMC0 and SDMMC1 at the same time. Also, it should be noted that the sdio device can only be connected to SDMMC1.

    Note: When using an SD card, you can choose to use sdmmc0 or sdmmc1. When using an SDIO card, you can only choose sdmmc1.

    5. UBOOT USAGE INTRODUCTION

    5.1. Uboot Config Configuration

    1. make menuconfig
    2. # SigmaStar drivers -->
    3. #    <*> SigmaStar mmc host
    

    The directory where the SDMMC driver is located under boot is drivers/sstar/mmc_host/. The compilation option SSTAR_MMC_HOST needs to be enabled. The opening method is as above.

    5.2. DTS Parameter Configuration Description

    You can set the basic parameters of the host layer driver by configuring the sstar_mmc0 item in dtsi. The parameters of dtsi are shown as follows:

            sstar_mmc0: sstar_mmc0 {
                compatible = "sstar-mmc";
    
                bus-width = <4>;
                max-frequency = <48000000>;
                cap-sd-highspeed = <1>;
                ip-order = <2>;
                pad-order = <1>;
                pwr-on-delay = <10>;
                pwr-off-delay = <50>;
                fake-cdz = <0>;
                rev-cdz = <0>;
                pwr-pad = <PAD_GPIOE_07>;
                cdz-pad = <PAD_GPIOE_06>;
                clk-driving = <1>;
                cmd-driving = <1>;
                data-driving = <1>;
                en-clk-phase = <0>;
                rx-clk-phase = <0>;
                tx-clk-phase = <0>;
                status = "okay";
            };
    

    The definitions are as follows:

    Parameter Definition Remark
    bus-width Configure the buswidth of the card slot 4 - 4bit mode
    max-frequency Configure the maximum clock frequency supported by the corresponding card slot Uboot supports 48MHz
    ip-order Configure the IP number of the corresponding card slot Modification prohibited
    pad-order Specify which pad group the card is connected to Public version software is not used and does not need to be modified
    pwr-on-delay Configure the power-on delay time of each card slot in ms SDIO devices generally need to configure a delay time so that the SDIO device can load the firmware and the state is ready. The specific time is subject to the recommendations of the SDIO device manufacturer(EMMC/SD device nodes do not need to be modified)
    pwr-off-delay Configure the power-off delay time of each card slot in ms Configure the power-on delay time of each card slot in ms
    fake-cdz Configure whether to ignore Card detect. Setting it to 1 means that the slot is assumed to have a card connected by default For devices fixed on the board, such as some SDIO devices, the slot corresponding item should be configured as 1
    rev-cdz This parameter can be used to configure whether to reverse the Card detect condition of the current Board By default, the card is detected at a low level. If the hardware design shows that the CDZ level is high after the card is inserted, configure this item to 1.
    pwr-pad Configure the Power pin of the corresponding card slot The actual selected Power pin is configured in the padmux file and does not need to be modified here
    cdz-pad Configure the CDZ pin of the corresponding card slot The actual selected CDZ pin is configured in the padmux file and does not need to be modified here
    clk-driving Configure the driving capability of the clock pad pin of the corresponding card slot The GPIOE pad gear is 0-1, and the GPIOA pad gear is 0-3.This item generally does not need to be modified. If you encounter communication signal quality problems, you can adjust this item based on the waveform.
    cmd-driving Configure the driving capability of the command pad pin of the corresponding card slot The GPIOE pad gear is 0-1, and the GPIOA pad gear is 0-3.This item generally does not need to be modified. If you encounter communication signal quality problems, you can adjust this item based on the waveform.
    data-driving Configure the driving capability of the data[3:0] pad pin of the corresponding card slot The GPIOE pad gear is 0-1, and the GPIOA pad gear is 0-3.This item generally does not need to be modified. If you encounter communication signal quality problems, you can adjust this item based on the waveform.
    en-clk_phase Configure whether to enable clock phase tuning for the corresponding card slot When CRC problems occur in device read/write communications, they can be solved by changing the sampling points of rx and tx.
    rx-clk_phase Configure the clock tx phase of the corresponding card slot Gear: 0-3, this parameter is valid only when en-clk_phase is set to 1, each gear phase interval is 90°
    tx-clk_phase Configure the clock rx phase of the corresponding card slot Gear: 0-3, this parameter is valid only when en-clk_phase is set to 1, Each gear phase interval is 90°
    non-removable Configure whether the device is non-removable No modification is required, EMMC devices need to configure this item

    5.3. Uboot Cmd Parameter Description

    (1) fatls

    Format:

    fatls <interface> [<dev[:part]>] [directory]
    

    Description: Read all the file contents in a directory in the nth partition of the nth device under a certain interface.

    Interface: Both SD cards and eMMC cards belong to MMC devices.

    Dev: Device number, according to the ip number, the default is 0.

    Part: Corresponds to the partition number under the mmc part command.

    Directory: Directory, use the absolute path.

    Example: Print the contents of the root directory in the first partition of SD.

    fatls mmc 0:1 /
    

    (2) fatload

    Format:

    fatload <interface> <dev<:part>> <addr> <filename> <bytes <pos>>
    

    Description: Read data of a specific size from a file in the nth partition of the nth device under a certain interface to the ddr at the specified address.

    Addr: Target memory address, ddr address, use real physical address.

    Filename: File name to be loaded, use the absolute path file name.

    Bytes: Data size to be loaded, in bytes, hexadecimal number, if 0, read the entire file.

    Pos: Offset in the target file. For example, if the target file data is "123456", if pos is 1, read from position '1' when loading the file.

    Example: Read 512 bytes of the demo.sh file in the root directory of the first partition of SD to 0x21000000 of ddr.

    fatload mmc 0:1 0x21000000 /demo.sh 0x200
    

    (3) fatwrite

    Format:

    fatwrite <interface> <dev<:part>> <addr> <filename> <bytes>
    

    Description: Read a specific size of data <bytes> from the ddr at the specified address and write it to a file in the nth partition of the nth device under a certain interface.

    Addr: Source memory address, ddr address, use the real physical address.

    Filename: The file name to be written, use the absolute path file name.

    Bytes: The data size to be written, in bytes, hexadecimal.

    Example: Read 512 bytes from ddr 0x21000000 and write it to the demo.sh file in the root directory of the first partition of SD.

    fatwrite mmc 0:1 0x21000000 /demo.sh 0x200
    

    (4) fatinfo

    Format:

    fatinfo <interface> <dev<:part>>
    

    Description: Display the nth partition information of the nth device under a certain interface.

    (5) fatsize

    Format:

    fatsize <interface> <dev<:part>> <filename>
    

    Description: Find the file of the nth partition of the nth device under a certain interface and calculate the file size.

    5.4. Uboot Cmd Use Case

    (1) fdisk

    Fdisk is used to manage Linux disks, perform partitioning and formatting operations.

    fdisk -p displays partition information.

    Figure 5-1: Sdmmc-5

    (2) fdisk -d 0: Delete all partitions of device 0

    Figure 5-2: Sdmmc-6

    (3) fdisk -c 0 0x32000: Create partition 1 and specify the partition size as 0x32000 blocks

    Figure 5-3: Sdmmc-7

    (4) fdisk -c 0 0x4800: Create partition 2 and specify the partition size as 0x4800 blocks

    Figure 5-4: Sdmmc-8

    (5) fdisk -c 0 0x64000: Create partition 3 and specify the partition size as 0x64000 blocks

    Figure 5-5: Sdmmc-9

    (6) fdisk -c 0 0x96000: Create partition 5 and specify the partition size as 0x96000 blocks. Partition 4 is the extended partition mbr and needs to be skipped

    Figure 5-6: Sdmmc-10

    (7) fdisk -c 0 0x400000: Create partition 6 and specify the partition size as 0x400000 blocks

    Figure 5-7: Sdmmc-11


    6. KERNEL USAGE INTRODUCTION

    6.1. Kernel Config Configuration

    1. Associated Driver Module

    The Card layer (mmc_block.ko) and the Core layer (mmc_host.ko) use the Linux standard code, and the Host layer (kdrv_sdmmc.ko) is maintained by Sigmastar. In menuconfig, you can choose to compile them into the kernel or compile them into ko.

    2. Enable the Corresponding Driver Module

    1. make menuconfig
    2. # Device Drivers -->
    3. #    <*> MMC/SD/SDIO card support -->                   (mmc_core.ko)
    4. #        <*> MMC block device driver                    (mmc_block.ko)
    5. #    [*] SStar SoC platform drivers -->
    6. #        <*> SStar SD/MMC Card Interface Support        (kdrv_sdmmc.ko)
    7. #        [ ]     Support SD30
    8. #        [ ]     Support EMMC50
    9. #        [*]     Support SDMMC Command
    10.#        [*]       Support SDMMC UT verify
    

    6.2. DTS Configuration Parameter Description

    You can set the basic parameters of the host layer driver by configuring the sstar_sdmmc1 item in dtsi. The parameters of dtsi are shown as follows:

    sstar_sdmmc1: sstar_sdmmc1 {
                compatible = "sstar,sdmmc";
    
                bus-width = <4>;
                max-frequency = <48000000>;
                //non-removable;
                //broken-cd;
                //cap-sd-highspeed;
                //sd-uhs-sdr50;
                //sd-uhs-sdr104;
                //sd-uhs-ddr50;
                //cap-sdio-irq;
                //no-sdio;
                //no-sd;
                //no-mmc;
                reg = <0x0 0x1F282600 0x0 0x200>;//1413
                pll-reg = <0x1F283200 0x200>;//1419
                cifd-reg = <0x1F282800 0x200>;//1414
                pwr-save-reg = <0x1F282A00 0x200>;//1415
                ip-order = /bits/ 8 <0>;
                pad-order = /bits/ 8 <0>;
                trans-mode = /bits/ 8 <1>;
                cifd-mcg-off = /bits/ 8 <0>; // mcg on/off in cifd
                ssc-switch =  /bits/ 8 <0>;
                //support-runtime-pm = /bits/ 8 <0>;
                fake-cdz = /bits/ 8 <0>;
                rev-cdz = /bits/ 8 <0>;
                rev-pwr = /bits/ 8 <0>;
                rev-ctrl = /bits/ 8 <0>;
                cdz-pad = <PAD_GPIOA_06>;
                pwr-pad = <PAD_GPIOA_07>;
                pwr-on-delay = <1000>;
                pwr-off-delay = <300>;
                dev-ctrl-delay = <1>;
                sdio-use-1bit = /bits/ 8 <0>;
                clk-driving = <1>;
                cmd-driving = <1>;
                data-driving = <1>;
                en-clk-phase = /bits/ 8 <0>; //0/1
                rx-clk-phase = <0>; //0-3
                tx-clk-phase = <0>; //0-3
                en-eight-phase = /bits/ 8 <0>; //0/1
                rx-eight-phase = /bits/ 8 <0>; //0/1
                tx-clk-phase = <0>; //0-3
                en-eight-phase = /bits/ 8 <0>; //0/1
                rx-eight-phase = /bits/ 8 <0>; //0/1
                tx-eight-phase = /bits/ 8 <0>; //0/1
                interrupts = <GIC_SPI INT_IRQ_SD IRQ_TYPE_LEVEL_HIGH>,
                            <GIC_SPI INT_FIQ_SD_CDZ_IN_0 IRQ_TYPE_LEVEL_HIGH>;
                interrupt-names = "mie0_irq", "cdz_slot0_irq";
                clocks = <&CLK_sd>;
                clock-names = "clk_sdmmc0";
                status = "ok";
            };
    

    As shown in the figure above, the definitions of the SD/SDIO device tree configuration nodes are:

    Parameter Definition Remark
    bus-width Configure the buswidth of the corresponding card slot 4 - 4bit mode
    max-frequency Configure the maximum clock frequency supported by the corresponding card slot pcupid supports a maximum clock frequency of 48MHz
    non-removable Configure whether the device is non-removable. Setting 1 means that the device is non-removable by default eMMC/SDIO devices are generally set to non-removable attributes
    broken-cd Configure whether to use cdz interrupt This property is configured for non-pluggable devices.
    cap-mmc-highspeed Configure whether the device supports mmc highspeed bus speed mode Enable mmc highspeed mode by default
    cap-sd-highspeed Configure whether the device supports sd highspeed bus speed mode Enable sd highspeed mode by default
    sd-uhs-sdr50 Configure whether to enable the sdr50 bus speed mode pcupid does not support
    sd-uhs-sdr104 Configure whether to enable the sdr104 bus speed mode pcupid does not support
    sd-uhs-ddr50 Configure whether to enable the ddr bus speed mode pcupid does not support
    cap-sdio-irq Configure whether to enable sdio interrupt mode Used by SDIO devices, comment out no-sdio when using SDIO devices
    no-mmc Configure the device does not support eMMC protocol SD/SDIO devices do not support eMMC protocol
    no-sd Configure the device does not support sd protocol EMMC/SDIO devices do not support sd protocol
    no-sdio Configure the device does not support sdio protocol EMMC/SD devices do not support sdio protocol
    reg Configure SD/SDIO Host Engine Bank address Modification prohibited
    pll-reg Configure SD/SDIO Host Engine PLL Bank address Modification prohibited
    cifd-reg Configure SD/SDIO Host Engine CIFD Bank address Modification prohibited
    pwr-save-reg Configure SD/SDIO Host Engine PSM Bank address Modification prohibited
    ip-order Configure the IP number of the corresponding card slot Modification prohibited
    pad-order Configure the padmux mode number of the corresponding card slot Public version software is not used and does not need to be modified
    trans-mode Configure the data transmission mode of the corresponding card slot No modification required
    fake-cdz Configure whether the corresponding card slot ignores Card Detect Non-pluggable devices are configured as 1
    rev-cdz Configure CDZ detection direction By default, the card is detected at a low level. If the hardware design shows that the CDZ level is high after the card is inserted, configure this item to 1.
    rev-pwr Configure power control direction By default, the power pin is powered on at a low level. If the hardware is designed to be powered on at a high level, set this item to 1.
    rev-ctrl Configure ctrl pin control direction Some sdio cards may require additional pins to control device enable, such as chip en. By default, the ctrl pin is pulled high first and then low. If this option is configured to 1, the ctrl pin will be pulled low first and then high.
    pwr-pad Configure the Power pin of the corresponding card slot The actual selected Power pin is configured in the padmux file and does not need to be modified here
    cdz-pad Configure the CDZ pin of the corresponding card slot The actual selected CDZ pin is configured in the padmux file and does not need to be modified here
    pwr-on-delay Configure the power-on delay time of each card slot in ms SDIO devices generally need to configure a delay time so that the SDIO device can load the firmware and the state is ready. The specific time is subject to the recommendations of the SDIO device manufacturer(EMMC/SD device nodes do not need to be modified)
    pwr-off-delay Configure the power-off delay time of each card slot in ms Configure the power-on delay time of each card slot in ms
    dev-ctrl-delay Configure the delay time before and after the ctrl pin polarity flips in ms Some sdio cards may require additional pins to control device enable, such as chip en. The specific delay time is subject to the recommendations of the sdio manufacturer.
    sdio-use-1bit Configure the buswidth of the corresponding card slot to 1bit mode Both SD/SDIO devices can be set
    support-cmd23 Configure whether to support the preset transmission block number function eMMC device use
    support-runtime-pm Configure whether to support runtime power management Enable as needed
    clk-driving Configure the driving of the clock line of the corresponding card slot The GPIOE pad gear is 0-1, and the GPIOA pad gear is 0-3.This item generally does not need to be modified. If you encounter communication signal quality problems, you can adjust this item based on the waveform.
    cmd-driving Configure the driving of the cmd line of the corresponding card slot The GPIOE pad gear is 0-1, and the GPIOA pad gear is 0-3.This item generally does not need to be modified. If you encounter communication signal quality problems, you can adjust this item based on the waveform.
    data-driving Configure the driving of the data line of the corresponding card slot The GPIOE pad gear is 0-1, and the GPIOA pad gear is 0-3.This item generally does not need to be modified. If you encounter communication signal quality problems, you can adjust this item based on the waveform.
    en-clk-phase Configure whether to enable clock phase tuning for the corresponding card slot 0 - Disable / 1 - Enable
    rx-clk-phase Configure the clock rx four-phase of the corresponding card slot Gear: 0-3, en-clk-phase is set to 1 to make this parameter effective
    tx-clk-phase Configure the clock tx four-phase of the corresponding card slot Gear: 0-3, en-clk-phase is set to 1 to make this parameter effective
    en-eight-phase Configure whether the corresponding card slot enables clock 8 phase tuning 0 - Disable / 1 - Enable
    rx-eight-phase Configure the clock rx eight-phase of the corresponding card slot For details, see clk phase usage instructions.
    tx-eight-phase Configure the clock tx eight-phase of the corresponding card slot For details, see clk phase usage instructions.
    interrupts Configure interrupt information Modification prohibited
    interrupt-names Configure interrupt names Modification prohibited
    clocks Configure the eMMC Host Engine clock source Modification prohibited
    clock-names Configure the clock source name Modification prohibited

    clk phase instructions:

    When using the four-phase mode, en-clk-phase needs to be set to 1, and then set the values ​​of rx-clk-phase and tx-clk-phase according to the phase to be set, with a phase interval of 90°. When using the eight-phase mode, en-clk-phase and en-eight-phase need to be set to 1, and then set the values ​​of rx-clk-phase, tx-clk-phase, rx-eight-phase and tx-eight-phase according to the phase to be set, with a phase interval of 45°.

    Phase values ​​corresponding to different phases

    • four-phase mode

      phase rx-clk-phase tx-clk-phase
      0 0
      90° 1 1
      180° 2 2
      270° 3 3
    • eight-phase mode

      phase rx-clk-phase rx-eight-phase tx-clk-phase tx-eight-phase
      0 0 0 0
      45° 1 0 1 0
      90° 2 0 2 0
      135° 3 0 3 0
      180° 0 1 0 1
      225° 1 1 1 1
      270° 2 1 2 1
      315° 3 1 3 1
    • Note 1: The default setting of hardware tx phase is 180°, so when the phase is set to 180°, the waveform of tx will be the same as when the phase is not turned on. When it is set to 0°, the phase will be 180° different from when the phase is not turned on.

    • Note 2: rx and tx can be set separately.

    • Note 3: When using the four-phase mode, the clock will be divided into four, and when using the eight-phase mode, the clock will be divided into eight. When the software setting has been turned on the phase function, the clock frequency will automatically be set to correspond to X4 and X8. When using the four-phase mode, when the clock frequency is 48M, the software sets 48M X 4, which is 192M, but the hardware is limited to no 192M clock source (as shown below), and the 108M clock source (four-division is 27M) will be used downward, so it will be downgraded. Therefore, when using a 48M clock, it is recommended to use the eight-phase mode (48M X 8 = 384M). After setting the phase, the clock frequency output is still 48M. When using other clock frequencies, you need to choose which mode to use according to the previous description.

    • Note 4: When the spread spectrum is turned on, the clock source will select spi_synth_pll. The clock frequency generated by spi_synth_pll is continuous and the setting range is 12M-266M. Therefore, if you need to output a 48M clock, you need to select the four-phase mode (the maximum clock output of the eight-phase is 266M/8 = 33M). In addition, since spi_synth_pll is also the clock source used by flash, when flash and spread spectrum need to be used at the same time, it is recommended to switch the flash clock source to spi_nonpm.

    SD card configuration example in dts file:

            sstar_sdmmc1: sstar_sdmmc1 {
                //non-removable;
                //broken-cd;
                cap-sd-highspeed;
                //cap-sdio-irq;
                no-sdio;
                //no-sd;
                no-mmc;
                fake-cdz = /bits/ 8 <0>;
            };
    

    SDIO card configuration example in dts file:

            sstar_sdmmc1: sstar_sdmmc1 {
                //non-removable;
                //broken-cd;
                cap-sd-highspeed;
                cap-sdio-irq;
                //no-sdio;
                no-sd;
                no-mmc;
                fake-cdz = /bits/ 8 <0>;
            };
    

    Control the timing of power pin and dev ctrl pin in the driver

    The device will be powered off only when it is reinitialized.

    6.3. Sample Code

    None.

    6.4. Module Usage Introduction

    After the Linux system starts, the SD/SDIO driver is loaded normally, and the SD/SDIO Card is recognized, the SD Card will create the corresponding block device node /dev/mmcblk*. Use fdisk, mkfs, mount, and dd tools to apply for partitions, format partitions, mount partitions, and read and write mounted partitions for MMC devices.

    In addition, the driver provides sysfs for debugging. For example, you can enter the /sys/class/mmc_host/mmc1/device/ directory to perform operations:

    1.  cd /sys/class/mmc_host/mmc0/device/
    2.
    3.  # View SD/SDIO Host clock frequencey
    4.  cat debug_get_sdmmc_clock
    5.
    6.  # View the last communication status between SD/SDIO Host and Device
    7.  cat debug_get_sdmmc_status
    6.
    7.  # Set the driving capability of SD/SDIO pin
    8.  echo [slotIndex] [signalLine] [drvLevel] > set_sdmmc_driving_control
    9.  echo [slotIndex]  [drvLevel] > set_sdmmc_driving_control
    10. echo [signalLine] [drvLevel] > set_sdmmc_driving_control
    11. echo [drvLevel] > set_sdmmc_driving_control
    12. #[slotIndex]: 0-1
    13. #[signalLine]: "clk"/"cmd"/"data"/"all"
    14. #[drvLevel]: 0-3
    15.
    16.  # Rescan SD/SDIO card
    17.  echo [slot] > sdmmc_rescan
    18.
    19. # Set the spread spectrum parameters
    20. ssc set param usage:
    21. 1. echo [slotIndex] [modulation] [deviation] > sdmmc_setssc
    22.     operation [slotIndex]   is slot number:0-2.
    23.     operation [modulation]  value is between [20, 40], origin default is 20
    24.     operation [deviation]   value is between [1000, 3001], origin default is 3001
    25.     e.g. echo 0 20 1001 > sdmmc_setssc
    26. 2. echo [slotIndex] [disable ssc] > sdmmc_setssc
    27.     disable: e.g. echo 0 0 > sdmmc_setssc
    28.     enable: e.g. echo 0 1 > sdmmc_setssc
    29.
    30. # Set the clock phase
    31. set phase param usage:\n");
    32. 1. echo [mode] [tx-clk-phase] [rx-clk-phase] [tx-eight-phase] [rx-eight-phase] > sdmmc_clk_phase
    33.     operation [mode]               is phase mode:4 or 8
    34.     operation [tx/rx-clk-phase]    value is between [0, 3]
    35.     operation [tx/rx-eight-phase]  value is between [0, 1]
    36.     e.g. Four-phase mode(180°):
    37.         echo 4 2 2 > sdmmc_clk_phase
    38.     e.g. Eight-phase mode(180°):
    39.         echo 8 0 0 1 1 > sdmmc_clk_phase
    40. 2. echo [enable/disable clk phase] > sdmmc_clk_phase
    41.     disable: e.g. echo 0 > sdmmc_clk_phase
    42.     enable: e.g. echo [4/8] > sdmmc_clk_phase
    

    Spread spectrum parameter usage instructions:

    There are 3 parameters which may affect the modulation rate of SSC function: SET, SPAN and STEP.

    • PLL_SET = (MPLL*524288)/(SYN_CLK)

      SPAN (14 bits)

      STEP (12 bits)

      SPAN = (MPLL * 131072) / (PLL_SET * Fmodulation)

      STEP = (PLL_SET * Rdeviation) / SPAN

    Fmodulation is the modulation frequency of SSC, it’s range is (20KHz ~ 40KHz)

    Rdeviation is the deviation of SSC.(the max range is +-3 %)

    Example:

    Set the spread spectrum modulation frequency to 40KHz and the deviation to +-1%

    echo 0 40 1000 > sdmmc_setssc

    • SYN_CLK = 75Mhz

      ref_clk = 432Mhz

      Modulation is 40KHz

      Deviation is 1%

      SET = ( 432MHz * 524288) / (75MHz ) = 3019899 = 0x2E147B

      SPAN = (432MHz * 131072)/ ( 3019899 * 40KHz) = 468 = 0x1D4

      STEP = (3019899 * 1%) /468 = 64 = 0x40


    7. API REFERENCE

    None.


    8. DEBUG & FAQ

    The error code types printed in the log when an exception occurs are:

    (1)SD_STS:0xFF01 Read CRC error

    (2)SD_STS:0xFF02 Write CRC error

    (3)SD_STS:0xFF04 Write data timeout

    (4)SD_STS:0xFF08 Command sent but no response

    (5)SD_STS:0xFF10 Command response has CRC error

    (6)SD_STS:0xFF20 Read data timeout

    (7)SD_STS:0xFF40 Device is busy

    SD Card Status Register Description:

    Figure 8-1: Sdmmc-14

    You can find the corresponding SD card status according to the (E: 0xXXXX) information in the driver error log to determine what problem the card has.

    According to the actual problems that the SD card may encounter, it is divided into the following types:

    Card Recognition Failure

    If the card recognition fails, it is necessary to determine whether the response acquisition fails or the transmission signal is not good and there is a CRC problem. The problem can be determined by the log printed by the driver. The specific difference and debug method are as follows:

    • SD card does not reply to command response

      Phenomenon: Driver log reports (E: 0x0008) information

      Debug method: First, determine whether the voltage and clock are normal. Secondly, you can capture the waveform to see whether the host has sent a command. If the first two are fine, then determine whether the card has a reply response. If there is no response, check the device status.

      Related logs:

      Figure 8-2: Sdmmc-15

    • Command response has CRC problem

      Phenomenon: Driver log reports (E: 0x0010) information

      Debug method: If there is a CRC problem, first eliminate the hardware problem, such as: whether the device contact is good, whether there is external interference, etc. Then try to change the driving gear in dts. If there is still a problem, you need to consider adjusting the clock phase.

      Related logs:

      Figure 8-3: Sdmmc-16

    Read and Write Failure

    If you encounter a problem during normal reading and writing, you need to determine whether it is a read and write timeout problem or a CRC problem due to poor signal. You can distinguish the problem through the log. The timeout problem has the word timeout. The debug method is as follows:

    • Read and write timeout

      Phenomenon: The word timeout is included in the driver error log

      Debug method: First, you need to determine whether the current clock frequency and bus width are the expected configuration values. Secondly, you can increase the timeout time in the driver and try again. If there is still a timeout problem, you need to capture the waveform for detailed analysis.

      The read and write timeout is set in the hal_card_platform_config.h file in the driver's corresponding chip directory:

      Figure 8-4: Sdmmc-18

    • Read and write CRC problem

      Phenomenon: Driver log reports (E: 0x0001) or (E: 0x0002) information

      Debug method: See the previous article for debug method. In addition, for CRC problems in the read and write process, if the speed requirement is not very high, you can consider reducing the frequency or bus width.

      Related logs:

      Figure 8-5: Sdmmc-17

    Card Read and Write Speed Are Slow

    First check whether the card clock frequency and bus width are normal. In addition, you can test and compare the read and write speeds of different models of cards.

    Note: SD card reading and writing are affected by multiple factors such as the transmission time of the command and its response, the card busy time, and the stop command time. The actual read and write speeds are lower than its theoretical speed; The read and write speed test should test the read and write bandwidth of the application layer, that is, transfer a large file for testing.