
Hi Michal,
On 07/06/19 2:05 PM, Michal Simek wrote:
From: T Karthik Reddy t.karthik.reddy@xilinx.com
Card detect function implemented for SDHCI framework.
Signed-off-by: T Karthik Reddy t.karthik.reddy@xilinx.com Signed-off-by: Michal Simek michal.simek@xilinx.com
drivers/mmc/sdhci.c | 32 ++++++++++++++++++++++++++++++++ include/sdhci.h | 7 +++++++ 2 files changed, 39 insertions(+)
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index e2bb90abbdf3..67ca324c9320 100644 --- a/drivers/mmc/sdhci.c +++ b/drivers/mmc/sdhci.c @@ -12,6 +12,7 @@ #include <malloc.h> #include <mmc.h> #include <sdhci.h> +#include <dm.h>
#if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER) void *aligned_buffer = (void *)CONFIG_FIXED_SDHCI_ALIGNED_BUFFER; @@ -624,9 +625,40 @@ int sdhci_probe(struct udevice *dev) return sdhci_init(mmc); }
+int sdhci_get_cd(struct udevice *dev) +{
- struct mmc *mmc = mmc_get_mmc_dev(dev);
- struct sdhci_host *host = mmc->priv;
- int value;
- /* If nonremovable, assume that the card is always present. */
- if (host->host_caps & MMC_CAP_NONREMOVABLE)
return 1;
- /* If polling, assume that the card is always present. */
- if (host->host_caps & MMC_CAP_NEEDS_POLL)
return 1;
+#if CONFIG_IS_ENABLED(DM_GPIO)
- value = dm_gpio_get_value(&host->cd_gpio);
- if (value >= 0) {
if (host->host_caps & MMC_CAP_CD_ACTIVE_HIGH)
return !value;
else
return value;
- }
+#endif
- value = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) &
SDHCI_CARD_DETECT_PIN_LEVEL);
I think you need to use CARD_PRESENT instead of this. According to the spec, "This bit may be valid when Card State Stable is set to 1, but it is not guaranteed because of propagation delay. Use of this bit is limited to testing since it must be debounced by software."
Thanks, Faiz