Skip to content

Commit 658459f

Browse files
committed
Progress with SDHC-I testing on ZCU102
1 parent a13acfb commit 658459f

File tree

5 files changed

+74
-16
lines changed

5 files changed

+74
-16
lines changed

config/examples/zynqmp_sdcard.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ CFLAGS_EXTRA+=-DDEBUG_ZYNQ=1
2626
# SD card support - use SDHCI driver
2727
DISK_SDCARD?=1
2828
DISK_EMMC?=0
29+
# ZynqMP Arasan SDHCI does not support CDSS/CDTL card detect test level.
30+
# Since FSBL booted from the same SD card, we know it is present.
31+
CFLAGS_EXTRA+=-DSDHCI_FORCE_CARD_DETECT
2932

3033
# Disable QSPI flash when using SD card
3134
EXT_FLASH?=0

hal/zynq.c

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,8 @@ static int test_ext_flash(QspiDev_t* dev)
18691869
/* Standard SDHCI Software Reset is in the Clock/Timeout/Reset register */
18701870
#define STD_SDHCI_RESET_REG 0x2C /* Clock Control / Timeout / SW Reset */
18711871
#define STD_SDHCI_SRA (1U << 24) /* Software Reset for All */
1872+
#define STD_SDHCI_SRCMD (1U << 25) /* Software Reset for CMD Line */
1873+
#define STD_SDHCI_SRDAT (1U << 26) /* Software Reset for DAT Line */
18721874

18731875
/* Handle reads from Cadence HRS registers (0x000-0x1FF) */
18741876
static uint32_t zynqmp_sdhci_hrs_read(uint32_t hrs_offset)
@@ -1878,7 +1880,10 @@ static uint32_t zynqmp_sdhci_hrs_read(uint32_t hrs_offset)
18781880
switch (hrs_offset) {
18791881
case 0x000: /* HRS00 - Software Reset */
18801882
{
1881-
/* Map standard SRA (bit 24 of 0x2C) to Cadence SWR (bit 0) */
1883+
/* Map standard SRA (bit 24 of 0x2C) to Cadence SWR (bit 0).
1884+
* SRA is safe because sdhci_platform_init() sets the slot type
1885+
* to "Embedded", so the controller accepts BP/SDCE writes after
1886+
* reset. */
18821887
uint32_t val = *((volatile uint32_t *)(base + STD_SDHCI_RESET_REG));
18831888
return (val & STD_SDHCI_SRA) ? 1U : 0U;
18841889
}
@@ -1898,7 +1903,12 @@ static void zynqmp_sdhci_hrs_write(uint32_t hrs_offset, uint32_t val)
18981903

18991904
switch (hrs_offset) {
19001905
case 0x000: /* HRS00 - Software Reset */
1901-
if (val & 1U) { /* SWR bit -> standard SRA */
1906+
if (val & 1U) {
1907+
/* Issue SRA (Software Reset for All).
1908+
* This is safe because sdhci_platform_init() configures the
1909+
* IOU_SLCR slot type to "Embedded" before this reset, so the
1910+
* controller will accept Bus Power and SD Clock Enable writes
1911+
* during the subsequent initialization. */
19021912
uint32_t reg = *((volatile uint32_t *)(base + STD_SDHCI_RESET_REG));
19031913
reg |= STD_SDHCI_SRA;
19041914
*((volatile uint32_t *)(base + STD_SDHCI_RESET_REG)) = reg;
@@ -1940,26 +1950,51 @@ void sdhci_reg_write(uint32_t offset, uint32_t val)
19401950
/* Platform initialization - called from sdhci_init()
19411951
* FSBL already initializes the SD controller on ZynqMP when booting from SD,
19421952
* so we don't need to configure clocks/reset (CRL_APB registers).
1943-
* We verify the SDHCI controller is accessible via standard register reads. */
1953+
*
1954+
* However, the FSBL uses GPIO-based card detect (polling MIO45 as GPIO)
1955+
* rather than the SDHCI controller's built-in CD mechanism. The default
1956+
* IOU_SLCR SD_CONFIG_REG2 slot type is "Removable" (00), but MIO45 is not
1957+
* routed to the SDHCI controller as a CD function. This causes the Arasan
1958+
* SDHCI to report Card Inserted=0 and gate writes to Bus Power and SD Clock
1959+
* Enable registers.
1960+
*
1961+
* Fix: Set SD1 slot type to "Embedded" (01) in IOU_SLCR SD_CONFIG_REG2.
1962+
* This makes the controller always assert Card Inserted and Card State
1963+
* Stable, allowing normal SDHCI register access. */
19441964
void sdhci_platform_init(void)
19451965
{
1966+
uint32_t reg;
1967+
1968+
/* Set SD1 slot type to "Embedded Slot for One Device" (01).
1969+
* This feeds into the SDHCI Capabilities register bits 31:30 and makes
1970+
* the controller report card as always present, bypassing the physical
1971+
* CD pin that is not connected to the SDHCI controller on ZCU102. */
1972+
reg = IOU_SLCR_SD_CONFIG_REG2;
1973+
reg &= ~SD_CONFIG_REG2_SD1_SLOTTYPE_MASK;
1974+
reg |= (1UL << SD_CONFIG_REG2_SD1_SLOTTYPE_SHIFT); /* 01 = Embedded */
1975+
IOU_SLCR_SD_CONFIG_REG2 = reg;
1976+
19461977
#ifdef DEBUG_SDHCI
1947-
volatile uint8_t *base = (volatile uint8_t *)ZYNQMP_SDHCI_BASE;
1948-
uint32_t val;
1978+
{
1979+
volatile uint8_t *base = (volatile uint8_t *)ZYNQMP_SDHCI_BASE;
1980+
uint32_t val;
19491981

1950-
wolfBoot_printf("sdhci_platform_init: SD%d at 0x%x\n",
1951-
(ZYNQMP_SDHCI_BASE == ZYNQMP_SD0_BASE) ? 0 : 1,
1952-
(unsigned int)ZYNQMP_SDHCI_BASE);
1982+
wolfBoot_printf("sdhci_platform_init: SD%d at 0x%x\n",
1983+
(ZYNQMP_SDHCI_BASE == ZYNQMP_SD0_BASE) ? 0 : 1,
1984+
(unsigned int)ZYNQMP_SDHCI_BASE);
19531985

1954-
/* Read standard SDHCI registers to verify controller access */
1955-
val = *((volatile uint32_t *)(base + 0x24)); /* Present State */
1956-
wolfBoot_printf(" Present State: 0x%x\n", (unsigned int)val);
1986+
wolfBoot_printf(" SD_CONFIG_REG2: 0x%x\n",
1987+
(unsigned int)IOU_SLCR_SD_CONFIG_REG2);
19571988

1958-
val = *((volatile uint32_t *)(base + 0x40)); /* Capabilities */
1959-
wolfBoot_printf(" Capabilities: 0x%x\n", (unsigned int)val);
1960-
(void)val;
1989+
/* Read standard SDHCI registers to verify controller access */
1990+
val = *((volatile uint32_t *)(base + 0x24)); /* Present State */
1991+
wolfBoot_printf(" Present State: 0x%x\n", (unsigned int)val);
1992+
1993+
val = *((volatile uint32_t *)(base + 0x40)); /* Capabilities */
1994+
wolfBoot_printf(" Capabilities: 0x%x\n", (unsigned int)val);
1995+
(void)val;
1996+
}
19611997
#endif
1962-
/* FSBL already configured SD1 - no clock/reset setup needed */
19631998
}
19641999

19652000
/* Platform interrupt setup - called from sdhci_init()
@@ -1971,7 +2006,7 @@ void sdhci_platform_irq_init(void)
19712006
#endif
19722007
}
19732008

1974-
/* Platform bus mode selection - called from sdhci_init() */
2009+
/* Platform bus mode selection - called from sdhci_init() after software reset */
19752010
void sdhci_platform_set_bus_mode(int is_emmc)
19762011
{
19772012
(void)is_emmc;

hal/zynq.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,15 @@
413413
#define RST_LPD_IOU2_SDIO0 (1UL << 5)
414414
#define RST_LPD_IOU2_SDIO1 (1UL << 6)
415415

416+
/* IOU_SLCR SD Configuration (feeds into SDHCI Capabilities register) */
417+
#define IOU_SLCR_SD_CONFIG_REG2 (*((volatile uint32_t*)(IOU_SLCR_BASSE + 0x320)))
418+
/* SD1 Slot Type: 00=Removable, 01=Embedded, 10=Shared Bus */
419+
#define SD_CONFIG_REG2_SD1_SLOTTYPE_SHIFT 28
420+
#define SD_CONFIG_REG2_SD1_SLOTTYPE_MASK 0x30000000UL
421+
/* SD0 Slot Type */
422+
#define SD_CONFIG_REG2_SD0_SLOTTYPE_SHIFT 12
423+
#define SD_CONFIG_REG2_SD0_SLOTTYPE_MASK 0x00003000UL
424+
416425

417426
/* Configuration Security Unit (CSU) */
418427
/* Triple-Dedundant MicroBlaze processor */

include/sdhci.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@
212212
/* SRS10 - Host Control 1 / Power / Block Gap / Wakeup */
213213
#define SDHCI_SRS10_DTW (1U << 1) /* Data transfer width (4-bit) */
214214
#define SDHCI_SRS10_EDTW (1U << 5) /* Extended data transfer width (8-bit) */
215+
#define SDHCI_SRS10_CDTL (1U << 6) /* Card Detect Test Level */
216+
#define SDHCI_SRS10_CDSS (1U << 7) /* Card Detect Signal Selection */
215217
#define SDHCI_SRS10_HSE (1U << 2) /* High speed enable */
216218
#define SDHCI_SRS10_BP (1U << 8) /* Bus power */
217219
#define SDHCI_SRS10_BVS_MASK (0x7U << 9)

src/sdhci.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,13 @@ static int sdcard_power_init_seq(uint32_t voltage)
560560
{
561561
/* Set power to specified voltage */
562562
int status = sdhci_set_power(voltage);
563+
#ifdef DEBUG_SDHCI
564+
wolfBoot_printf("sdcard_power_init: power status=%d, SRS09=0x%x, "
565+
"SRS10=0x%x, SRS11=0x%x, SRS12=0x%x\n",
566+
status,
567+
SDHCI_REG(SDHCI_SRS09), SDHCI_REG(SDHCI_SRS10),
568+
SDHCI_REG(SDHCI_SRS11), SDHCI_REG(SDHCI_SRS12));
569+
#endif
563570
if (status == 0) {
564571
/* send CMD0 (go idle) to reset card */
565572
status = sdhci_cmd(MMC_CMD0_GO_IDLE, 0, SDHCI_RESP_NONE);
@@ -1407,6 +1414,7 @@ int sdhci_init(void)
14071414

14081415
/* check if card inserted and stable */
14091416
reg = SDHCI_REG(SDHCI_SRS09);
1417+
#ifndef SDHCI_FORCE_CARD_DETECT
14101418
if ((reg & SDHCI_SRS09_CSS) == 0) {
14111419
/* card not inserted or not stable */
14121420
return -1;
@@ -1419,6 +1427,7 @@ int sdhci_init(void)
14191427
return -1;
14201428
}
14211429
#endif
1430+
#endif /* !SDHCI_FORCE_CARD_DETECT */
14221431

14231432
/* Start in 1-bit bus mode */
14241433
reg = SDHCI_REG(SDHCI_SRS10);

0 commit comments

Comments
 (0)