Skip to content

Commit 78e1be1

Browse files
marcanjannau
authored andcommitted
mmc: sdhci-pci: Support setting CD debounce delay
Some systems (e.g. 2021 MacBook Pro 14/16") have noncompliant connectors where CD activates before the card is fully inserted. We need debounce delay support on these to avoid detection failures when the card isn't inserted very quickly. Set the default to 200ms for all systems instead of 0. This is the default on non-PCI platforms, and will probably help other systems too. The naughty MacBooks will need closer to 750ms in the device tree to be reliable... Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent d8f31c9 commit 78e1be1

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

drivers/mmc/host/sdhci-pci-core.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,7 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
20432043
struct sdhci_host *host;
20442044
int ret, bar = first_bar + slotno;
20452045
size_t priv_size = chip->fixes ? chip->fixes->priv_size : 0;
2046+
u32 cd_debounce_delay_ms;
20462047

20472048
if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
20482049
dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
@@ -2109,14 +2110,18 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
21092110
if (host->mmc->caps & MMC_CAP_CD_WAKE)
21102111
device_init_wakeup(&pdev->dev, true);
21112112

2113+
if (device_property_read_u32(&pdev->dev, "cd-debounce-delay-ms",
2114+
&cd_debounce_delay_ms))
2115+
cd_debounce_delay_ms = 200;
2116+
21122117
if (slot->cd_idx >= 0) {
21132118
ret = mmc_gpiod_request_cd(host->mmc, "cd", slot->cd_idx,
21142119
slot->cd_override_level, 0);
21152120
if (ret && ret != -EPROBE_DEFER)
21162121
ret = mmc_gpiod_request_cd(host->mmc, NULL,
21172122
slot->cd_idx,
21182123
slot->cd_override_level,
2119-
0);
2124+
cd_debounce_delay_ms * 1000);
21202125
if (ret == -EPROBE_DEFER)
21212126
goto remove;
21222127

@@ -2128,7 +2133,8 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
21282133
/* Allow all OF systems to use a CD GPIO if provided */
21292134

21302135
ret = mmc_gpiod_request_cd(host->mmc, "cd", 0,
2131-
slot->cd_override_level, 0);
2136+
slot->cd_override_level,
2137+
cd_debounce_delay_ms * 1000);
21322138
if (ret == -EPROBE_DEFER)
21332139
goto remove;
21342140
else if (ret == 0)

0 commit comments

Comments
 (0)