Skip to content

Commit 0ed0bb7

Browse files
committed
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 a5e3e8a commit 0ed0bb7

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
@@ -2042,6 +2042,7 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
20422042
struct sdhci_host *host;
20432043
int ret, bar = first_bar + slotno;
20442044
size_t priv_size = chip->fixes ? chip->fixes->priv_size : 0;
2045+
u32 cd_debounce_delay_ms;
20452046

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

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

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

21292134
ret = mmc_gpiod_request_cd(host->mmc, "cd", 0,
2130-
slot->cd_override_level, 0);
2135+
slot->cd_override_level,
2136+
cd_debounce_delay_ms * 1000);
21312137
if (ret == -EPROBE_DEFER)
21322138
goto remove;
21332139
else if (ret == 0)

0 commit comments

Comments
 (0)