2727#include <linux/debugfs.h>
2828#include <linux/acpi.h>
2929#include <linux/dmi.h>
30+ #include <linux/of.h>
3031
3132#include <linux/mmc/host.h>
3233#include <linux/mmc/mmc.h>
@@ -2129,6 +2130,7 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
21292130 struct sdhci_host * host ;
21302131 int ret , bar = first_bar + slotno ;
21312132 size_t priv_size = chip -> fixes ? chip -> fixes -> priv_size : 0 ;
2133+ u32 cd_debounce_delay_ms ;
21322134
21332135 if (!(pci_resource_flags (pdev , bar ) & IORESOURCE_MEM )) {
21342136 dev_err (& pdev -> dev , "BAR %d is not iomem. Aborting.\n" , bar );
@@ -2195,6 +2197,10 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
21952197 if (host -> mmc -> caps & MMC_CAP_CD_WAKE )
21962198 device_init_wakeup (& pdev -> dev , true);
21972199
2200+ if (device_property_read_u32 (& pdev -> dev , "cd-debounce-delay-ms" ,
2201+ & cd_debounce_delay_ms ))
2202+ cd_debounce_delay_ms = 200 ;
2203+
21982204 if (slot -> cd_idx >= 0 ) {
21992205 struct gpiod_lookup_table * cd_gpio_lookup_table ;
22002206
@@ -2213,14 +2219,24 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
22132219 ret = mmc_gpiod_request_cd (host -> mmc , NULL ,
22142220 slot -> cd_idx ,
22152221 slot -> cd_override_level ,
2216- 0 );
2222+ cd_debounce_delay_ms * 1000 );
22172223 if (ret == - EPROBE_DEFER )
22182224 goto remove ;
22192225
22202226 if (ret ) {
22212227 dev_warn (& pdev -> dev , "failed to setup card detect gpio\n" );
22222228 slot -> cd_idx = -1 ;
22232229 }
2230+ } else if (is_of_node (pdev -> dev .fwnode )) {
2231+ /* Allow all OF systems to use a CD GPIO if provided */
2232+
2233+ ret = mmc_gpiod_request_cd (host -> mmc , "cd" , 0 ,
2234+ slot -> cd_override_level ,
2235+ cd_debounce_delay_ms * 1000 );
2236+ if (ret == - EPROBE_DEFER )
2237+ goto remove ;
2238+ else if (ret == 0 )
2239+ slot -> cd_idx = 0 ;
22242240 }
22252241
22262242 if (chip -> fixes && chip -> fixes -> add_host )
0 commit comments