Skip to content

Commit 02e0fd7

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 756eed2 commit 02e0fd7

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
@@ -2129,6 +2129,7 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
21292129
struct sdhci_host *host;
21302130
int ret, bar = first_bar + slotno;
21312131
size_t priv_size = chip->fixes ? chip->fixes->priv_size : 0;
2132+
u32 cd_debounce_delay_ms;
21322133

21332134
if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
21342135
dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
@@ -2195,6 +2196,10 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
21952196
if (host->mmc->caps & MMC_CAP_CD_WAKE)
21962197
device_init_wakeup(&pdev->dev, true);
21972198

2199+
if (device_property_read_u32(&pdev->dev, "cd-debounce-delay-ms",
2200+
&cd_debounce_delay_ms))
2201+
cd_debounce_delay_ms = 200;
2202+
21982203
if (slot->cd_idx >= 0) {
21992204
struct gpiod_lookup_table *cd_gpio_lookup_table;
22002205

@@ -2213,7 +2218,7 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
22132218
ret = mmc_gpiod_request_cd(host->mmc, NULL,
22142219
slot->cd_idx,
22152220
slot->cd_override_level,
2216-
0);
2221+
cd_debounce_delay_ms * 1000);
22172222
if (ret == -EPROBE_DEFER)
22182223
goto remove;
22192224

@@ -2225,7 +2230,8 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
22252230
/* Allow all OF systems to use a CD GPIO if provided */
22262231

22272232
ret = mmc_gpiod_request_cd(host->mmc, "cd", 0,
2228-
slot->cd_override_level, 0);
2233+
slot->cd_override_level,
2234+
cd_debounce_delay_ms * 1000);
22292235
if (ret == -EPROBE_DEFER)
22302236
goto remove;
22312237
else if (ret == 0)

0 commit comments

Comments
 (0)