Skip to contentSkip to conversation

Add SDHCI card detection support

PATCH New Michal Simek 2 participants 6 messages Jun 25, 2019 – Jul 10, 2019 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

v3 cover Add SDHCI card detection support

Hi,

This patch series adds card detection support in sdhci framework & added functionality to read card detect dt properties.

Thanks,
Michal

Changes in v3:
- New patch in this series to release macros
- Changed MMC_CAP_SD_NONREMOVABLE, MMC_CAP_SD_NEEDS_POLL names to align with Linux bit definitions by removing SD.
- Use new MMC_SD.. macros

Changes in v2:
- Moved reading CD devicetree properties functionality from sdhci.c to mmc-uclass.c & moved mmc capability macros to mmc.h from sdhci.h.
- Created a new patch for reading "cd-gpio" property from DT.
- Used CARD_PRESENT instead of SDHCI_CARD_DETECT_PIN_LEVEL for reading sd card presence detection.

T Karthik Reddy (4):
mmc: mvebu: Remove unused MMC_CAP.. macros
mmc: Read sd card detect properties from DT
mmc: sdhci: Read cd-gpio from devicetree
mmc: sdhci: Implement SDHCI card detect

 drivers/mmc/mmc-uclass.c |  9 +++++++++
 drivers/mmc/sdhci.c      | 38 ++++++++++++++++++++++++++++++++++++++
 include/mmc.h            |  4 ++++
 include/mvebu_mmc.h      |  4 ----
 4 files changed, 51 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/4 mmc: mvebu: Remove unused MMC_CAP.. macros

From: T Karthik Reddy <[email protected]>

Removed MMC_CAP_NONREMOVABLE, MMC_CAP_NEEDS_POLL macros from mvebu_mmc.h to avoid redefining of these macros when compiled with mvebu based configs.

---

Changes in v3:
- New patch in this series to release macros

Changes in v2: None

 include/mvebu_mmc.h | 4 ----
 1 file changed, 4 deletions(-)
include/mvebu_mmc.h +0 -4
index d51b1fe4670e..7397165f67f6 100644
@@ -222,13 +222,9 @@
 #define MMC_CAP_SDIO_IRQ			(1 << 3)
 /* Talks only SPI protocols */
 #define MMC_CAP_SPI				(1 << 4)
-/* Needs polling for card-detection */
-#define MMC_CAP_NEEDS_POLL			(1 << 5)
 /* Can the host do 8 bit transfers */
 #define MMC_CAP_8_BIT_DATA			(1 << 6)
 
-/* Nonremovable e.g. eMMC */
-#define MMC_CAP_NONREMOVABLE			(1 << 8)
 /* Waits while card is busy */
 #define MMC_CAP_WAIT_WHILE_BUSY			(1 << 9)
 /* Allow erase/trim commands */
Signature · 1 line
2.17.1
#2 lore raw

PATCH v3 1/4 mmc: mvebu: Remove unused MMC_CAP.. macros

Quoted 28 lines

Subject: [PATCH v3 1/4] mmc: mvebu: Remove unused MMC_CAP.. macros

From: T Karthik Reddy <[email protected]>

Removed MMC_CAP_NONREMOVABLE, MMC_CAP_NEEDS_POLL macros
from mvebu_mmc.h to avoid redefining of these macros when compiled with mvebu based configs.

---

Changes in v3:
- New patch in this series to release macros

Changes in v2: None

 include/mvebu_mmc.h | 4 ----
 1 file changed, 4 deletions(-)
include/mvebu_mmc.h index renamed from include/mvebu_mmc.h +0 -0

d51b1fe4670e..7397165f67f6 100644

include/mvebu_mmc.h +0 -0
@@ -222,13 +222,9 @@
 #define MMC_CAP_SDIO_IRQ			(1 << 3)
 /* Talks only SPI protocols */
 #define MMC_CAP_SPI				(1 << 4)

include/mvebu_mmc.h line 230

Quoted 10 lines
include/mvebu_mmc.h +0 -4
-/* Needs polling for card-detection */
-#define MMC_CAP_NEEDS_POLL			(1 << 5)
 /* Can the host do 8 bit transfers */
 #define MMC_CAP_8_BIT_DATA			(1 << 6)
 
-/* Nonremovable e.g. eMMC */
-#define MMC_CAP_NONREMOVABLE			(1 << 8)
 /* Waits while card is busy */
 #define MMC_CAP_WAIT_WHILE_BUSY			(1 << 9)
 /* Allow erase/trim commands */

Patchset applied to mmc master.

Thanks,
Peng.

Quoted 2 lines

--
2.17.1

#3 lore raw

PATCH v3 2/4 mmc: Read sd card detect properties from DT

In reply to Michal Simek

From: T Karthik Reddy <[email protected]>

This patch reads card detect properties from device tree & added mmc capability macros in mmc.h.

---

Changes in v3:
- Changed MMC_CAP_SD_NONREMOVABLE, MMC_CAP_SD_NEEDS_POLL names to align with Linux bit definitions by removing SD.

Changes in v2:
- Moved reading CD devicetree properties functionality from sdhci.c to mmc-uclass.c & moved mmc capability macros to mmc.h from sdhci.h.

 drivers/mmc/mmc-uclass.c | 9 +++++++++
 include/mmc.h            | 4 ++++
 2 files changed, 13 insertions(+)
drivers/mmc/mmc-uclass.c +9 -0
index a9c8f335c142..fa4d1af55d61 100644
@@ -171,6 +171,15 @@ int mmc_of_parse(struct udevice *dev, struct mmc_config *cfg)
 	if (dev_read_bool(dev, "mmc-hs400-1_2v"))
 		cfg->host_caps |= MMC_CAP(MMC_HS_400);
 
+	if (dev_read_bool(dev, "non-removable")) {
+		cfg->host_caps |= MMC_CAP_NONREMOVABLE;
+	} else {
+		if (dev_read_bool(dev, "cd-inverted"))
+			cfg->host_caps |= MMC_CAP_CD_ACTIVE_HIGH;
+		if (dev_read_bool(dev, "broken-cd"))
+			cfg->host_caps |= MMC_CAP_NEEDS_POLL;
+	}
+
 	return 0;
 }
 
include/mmc.h +4 -0
index 1f30f71d25f8..2be3e91fcb58 100644
@@ -66,6 +66,10 @@
 #define MMC_MODE_HS200		MMC_CAP(MMC_HS_200)
 #define MMC_MODE_HS400		MMC_CAP(MMC_HS_400)
 
+#define MMC_CAP_NONREMOVABLE	BIT(14)
+#define MMC_CAP_NEEDS_POLL	BIT(15)
+#define MMC_CAP_CD_ACTIVE_HIGH  BIT(16)
+
 #define MMC_MODE_8BIT		BIT(30)
 #define MMC_MODE_4BIT		BIT(29)
 #define MMC_MODE_1BIT		BIT(28)
Signature · 1 line
2.17.1
#4 lore raw

PATCH v3 3/4 mmc: sdhci: Read cd-gpio from devicetree

In reply to Michal Simek

From: T Karthik Reddy <[email protected]>

This patch reads cd-gpio property from devicetree

---

Changes in v3: None
Changes in v2:
- Created a new patch for reading "cd-gpio" property from DT.

 drivers/mmc/sdhci.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/mmc/sdhci.c +6 -0
index e2bb90abbdf3..4ffe74e35e08 100644
@@ -590,6 +590,12 @@ static int sdhci_set_ios(struct mmc *mmc)
 static int sdhci_init(struct mmc *mmc)
 {
 	struct sdhci_host *host = mmc->priv;
+#if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_GPIO)
+	struct udevice *dev = mmc->dev;
+
+	gpio_request_by_name(dev, "cd-gpio", 0,
+			     &host->cd_gpio, GPIOD_IS_IN);
+#endif
 
 	sdhci_reset(host, SDHCI_RESET_ALL);
 
Signature · 1 line
2.17.1
#5 lore raw

PATCH v3 4/4 mmc: sdhci: Implement SDHCI card detect

In reply to Michal Simek

From: T Karthik Reddy <[email protected]>

Card detect function implemented for SDHCI framework.

---

Changes in v3:
- Use new MMC_SD.. macros

Changes in v2:
- Used CARD_PRESENT instead of SDHCI_CARD_DETECT_PIN_LEVEL for reading sd card presence detection.

 drivers/mmc/sdhci.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
drivers/mmc/sdhci.c +32 -0
index 4ffe74e35e08..c4e88790bc68 100644
@@ -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;
@@ -630,9 +631,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 (mmc->cfg->host_caps & MMC_CAP_NONREMOVABLE)
+		return 1;
+	/* If polling, assume that the card is always present. */
+	if (mmc->cfg->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 (mmc->cfg->host_caps & MMC_CAP_CD_ACTIVE_HIGH)
+			return !value;
+		else
+			return value;
+	}
+#endif
+	value = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) &
+		   SDHCI_CARD_PRESENT);
+	if (mmc->cfg->host_caps & MMC_CAP_CD_ACTIVE_HIGH)
+		return !value;
+	else
+		return value;
+}
+
 const struct dm_mmc_ops sdhci_ops = {
 	.send_cmd	= sdhci_send_command,
 	.set_ios	= sdhci_set_ios,
+	.get_cd		= sdhci_get_cd,
 #ifdef MMC_SUPPORTS_TUNING
 	.execute_tuning	= sdhci_execute_tuning,
 #endif
Signature · 1 line
2.17.1