Zephyr SDHC Driver Support

This page gives an overview of the SDHC Zephyr driver which is available as part of the zephyr-amd repo.

HW Features

  • SD/eMMC Host Controller

Design Notes

  • N/A

Implementation

Features Supported

  • SD/eMMC Host Controller Driver Initialization

  • raw disk mode - read/write support

  • Filesystem - read/write support

  • raw subsystem based - read/write support

  • Support hs400 and UHS speed modes

  • support both interrupt and polled mode

Missing Features

  • User mode

  • DDR-HS mode support

  • SDR25 mode support

Known Issues

  • The core switches to SDR-HS mode but does not report itself as SDR-HS, because the card structure is not updated to the latest speed mode after the switch.

Limitations

  • Does not support custom clock phase delay configuration and non-cache-based system.

  • While registering for disk operation, if both SD and eMMC are enabled then by default eMMC fails to register. The eMMC configuration must be explicitly changed to make it work.

  • Raw subsystem-based read/write operation in case of eMMC is locked to legacy speed mode.

Kernel Configuration

CONFIG_SDHC=y
CONFIG_XLNX_VERSAL_8_9A=y
CONFIG_SDMMC_STACK=y
CONFIG_MMC_STACK=y
CONFIG_DISK_DRIVER_MMC=y
CONFIG_DISK_DRIVER_SDMMC=y
CONFIG_SDHC_SUPPORTS_UHS=y

Device Tree

SD/eMMC host controller node for Versal NET

sdhci0: mmc@f1040000 {
        compatible = "xlnx,versal-8.9a";
        status = "okay";
        interrupts = <GIC_SPI 184 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
        reg = <0xf1040000 0x10000>;
        power-delay-ms = <10>;
        clocks = <&clk_sdhci>;
        sdmmc {
                 compatible = "zephyr,sdmmc-disk";
        };
};

sdhci1: mmc@f1050000 {
        compatible = "xlnx,versal-8.9a";
        status = "okay";
        reg = <0xf1050000 0x10000>;
        interrupts = <GIC_SPI 186 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
        mmc-hs200-1_8v;
        mmc-hs400-1_8v;
        clocks = <&clk_sdhci>;
        mmc {
                 compatible = "zephyr,mmc-disk";
                 bus-width = <8>;
        };
};

clk_sdhci: clk_sdhci {
        compatible = "fixed-clock";
        clock-frequency = <199998001>;
        #clock-cells = <0>;
};
  • disk node must be a child node of SD/eMMC nodes.

Driver Stack Size

  • 6.3 KB

    • txt - 4.8 KB, data - 1.5 KB

Test Platform

  • Versal Gen 2 QEMU

  • Versal NET

Test SoC Architecture

  • RPU - R52 Core

  • RPU - R52 Core (QEMU)

Testing Sequence

  • Build zephyr application for R52 or R52(QEMU) core

    • west build -p -b <board> <sample application path>

  • Run zephyr elf on board or QEMU

QEMU Run

qemu-system-aarch64 -M arm-generic-fdt -serial null -serial null -serial \
   mon:stdio -display none -hw-dtb \
   $QEMU_PATH/LATEST/SINGLE_ARCH/board-versal2-xc2ve3858-psxc-virt.dtb \
   -machine-path /tmp/ -display none \
   -device loader,file=/<path>/<to>/<zephyr.elf>,cpu-num=8 \
   -device loader,addr=0xEB580000,data=0x1,data-len=4 \
   -device loader,addr=0xEB5E0310,data=0x2,data-len=4 \
   -drive file=sd.img,if=sd,format=raw,index=<3>

Index Usage:

0 -> sd0
1 -> sd1
2 -> emmc0
3 -> emmc1

Example Tests

Test Name

Example Source

Description

SDHC driver

(Not supported for EA)

tests/drivers/sdhc/

validate driver callbacks without a read/write operations.

SDHC subsys

tests/subsys/sd/sdmmc/

tests/subsys/sd/mmc/

functionality check and performs read/write - stress test

DISK - SD

DISK -eMMC

(only one instance can be enabled to run this test on eMMC - EA)

tests/drivers/disk/disk_access/

tests/drivers/disk/disk_performance/

Initialize and perform read/write using disk layer.

Filesystem - SD/eMMC

(only one instance can be enabled to run this test on eMMC -EA)

tests/subsys/fs/fat_fs_api/

Demonstrates basic file and dir operations using the Zephyr filesystem.

Code Coverage

Driver code coverage with disk_performance - (eMMC)73.8%, (SD)66%.

Expected Output

  • west build -p -b versalnet_rpu zephyr/tests/subsys/sd/sdmmc/ -DDTC_OVERLAY_FILE=boards/versal.overlay

  • west build -p -b versalnet_rpu zephyr/tests/subsys/sd/mmc/ -DDTC_OVERLAY_FILE=boards/versal.overlay

  • west build -p -b versal2_rpu zephyr/tests/subsys/fs/fat_fs_api/ -DCONF_FILE=prj_mmc.conf

  • west build -p -b versal2_rpu zephyr/tests/subsys/fs/fat_fs_api/ -DCONF_FILE=prj_sdmmc.conf

  • west build -p -b versal2_rpu zephyr/tests/drivers/disk/disk_access/

  • west build -p -b versal2_rpu zephyr/tests/drivers/disk/disk_performance/

Note: The alias is fixed as sdhc0. To test sdhci1, update the alias to sdhc0 = &sdhci1.

*** Booting Zephyr OS build xilinx_v2024.2-47-ga1dcbf4a3003 ***
Running TESTSUITE sd_stack
===================================================================
START - test_0_init
I: Card switched to 1.8 V signaling
PASS - test_0_init in 0.122 seconds
===================================================================
START - test_card_config
Card voltage: 1.8 V
Card timing: SDR104
Bus Frequency: 208000000 Hz
Card type: SDMMC
Card spec: 3.0
PASS - test_card_config in 0.010 seconds
===================================================================
START - test_ioctl
SD card reports sector count of 62357504
SD card reports sector size of 512
PASS - test_ioctl in 0.007 seconds
===================================================================
START - test_read
PASS - test_read in 0.108 seconds
===================================================================
START - test_rw
PASS - test_rw in 1.676 seconds
===================================================================
START - test_write
PASS - test_write in 0.132 seconds
===================================================================
TESTSUITE sd_stack succeeded

------ TESTSUITE SUMMARY START ------

SUITE PASS - 100.00% [sd_stack]: pass = 6, fail = 0, skip = 0, total = 6 duration = 2.055 seconds

- PASS - [sd_stack.test_0_init] duration = 0.122 seconds
- PASS - [sd_stack.test_card_config] duration = 0.010 seconds
- PASS - [sd_stack.test_ioctl] duration = 0.007 seconds
- PASS - [sd_stack.test_read] duration = 0.108 seconds
- PASS - [sd_stack.test_rw] duration = 1.676 seconds
- PASS - [sd_stack.test_write] duration = 0.132 seconds

------ TESTSUITE SUMMARY END ------

Performance Metric

  • TBA

Mainline Status

  • mainlined

Driver Source Path

  • drivers/sdhc/xlnx_sdhc.c

Misra C Report

  • Per coding guidelines of zephyr

Misra-c

xlnx_sdhc.c

xlnx_sdhc.h

kernel utility

Actual violation

4.6

675

0

660

15

4.8

11

0

11

0

4.9

34

0

34

0

1.2

112

1

108

5

10.1

102

0

100

2

10.3

318

0

260

58

10.4

408

0

396

12

10.5

0

0

0

0

10.6

1

0

0

1

10.7

20

0

19

1

10.8

2

0

0

2

11.3

239

0

239

0

11.4

18

0

0

18

11.5

35

0

0

35

11.6

1

0

0

1

11.8

70

0

40

30

11.9

0

0

0

0

12.1

401

0

401

0

12.2

0

0

0

0

13.3

59

0

59

0

13.4

0

0

0

0

14.3

147

0

147

0

14.4

0

0

0

0

15.1

0

0

0

0

15.4

40

0

40

0

15.5

31

0

0

31

15.6

0

0

0

0

15.7

20

0

20

0

16.1

6

0

0

6

16.3

6

0

0

6

17.7

26

0

20

6

18.4

20

0

20

0

18.8

39

0

39

0

19.2

59

0

59

0

2.1

13

0

13

0

2.2

39

0

39

0

2.4

0

0

0

0

20.10

3

0

3

0

20.12

12

0

12

0

20.7

0

0

0

0

21.2

12

0

12

0

7.4

20

0

20

0

8.13

17

0

12

5

9.1

0

0

0

0

Total

3016

1

2783

234