Skip to contentSkip to conversation

mmc: implement SDHCI card detect

PATCH New Ibai Erkiaga 3 participants 4 messages May 23, 2019 – Jun 3, 2019 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: implement SDHCI card detect

Card detect function implemented for SDHCI framework.

---

 drivers/mmc/sdhci.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/mmc/sdhci.c +17 -0
index e2bb90a..cb4db8d 100644
@@ -390,6 +390,21 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
 		return -ECOMM;
 }
 
+#if IS_ENABLED(CONFIG_DM_MMC)
+static int sdhci_get_cd(struct udevice *dev)
+{
+	struct mmc *mmc = mmc_get_mmc_dev(dev);
+#else
+static int sdhci_get_cd(struct mmc *mmc)
+{
+#endif
+	u32 state;
+	struct sdhci_host *host = mmc->priv;
+
+	state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+	return (state & SDHCI_CARD_PRESENT);
+}
+
 #if defined(CONFIG_DM_MMC) && defined(MMC_SUPPORTS_TUNING)
 static int sdhci_execute_tuning(struct udevice *dev, uint opcode)
 {
@@ -627,6 +642,7 @@ int sdhci_probe(struct udevice *dev)
 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
@@ -635,6 +651,7 @@ const struct dm_mmc_ops sdhci_ops = {
 static const struct mmc_ops sdhci_ops = {
 	.send_cmd	= sdhci_send_command,
 	.set_ios	= sdhci_set_ios,
+	.get_cd		= sdhci_get_cd,
 	.init		= sdhci_init,
 };
 #endif
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 mmc: implement SDHCI card detect

Quoted 19 lines · Ibai Erkiaga

Card detect function implemented for SDHCI framework.

---

 drivers/mmc/sdhci.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/mmc/sdhci.c +3 -0
index e2bb90a..cb4db8d 100644
@@ -390,6 +390,21 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
 		return -ECOMM;
 }
 
+#if IS_ENABLED(CONFIG_DM_MMC)
+static int sdhci_get_cd(struct udevice *dev)
+{

drivers/mmc/sdhci.c static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd, · line 405

Quoted 10 lines
drivers/mmc/sdhci.c +10 -0
+	struct mmc *mmc = mmc_get_mmc_dev(dev);
+#else
+static int sdhci_get_cd(struct mmc *mmc)
+{
+#endif
+	u32 state;
+	struct sdhci_host *host = mmc->priv;
+
+	state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+	return (state & SDHCI_CARD_PRESENT);

This should be much more robust. It should at least handle cases where you have broken-cd, cd-gpios, cd-inverted cases.
This code will likely work with boards which have CD connected properly but it is enabled for all which will cause a lot of issues.

If you want to add this functionality one by one then new Kconfig should be used but I am not big fan of that.

Quoted 15 lines
drivers/mmc/sdhci.c +3 -0
+}
+
 #if defined(CONFIG_DM_MMC) && defined(MMC_SUPPORTS_TUNING)
 static int sdhci_execute_tuning(struct udevice *dev, uint opcode)
 {
@@ -627,6 +642,7 @@ int sdhci_probe(struct udevice *dev)
 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

drivers/mmc/sdhci.c const struct dm_mmc_ops sdhci_ops = { · line 657

Quoted 7 lines
drivers/mmc/sdhci.c +1 -0
@@ -635,6 +651,7 @@ const struct dm_mmc_ops sdhci_ops = {
 static const struct mmc_ops sdhci_ops = {
 	.send_cmd	= sdhci_send_command,
 	.set_ios	= sdhci_set_ios,
+	.get_cd		= sdhci_get_cd,
 	.init		= sdhci_init,
 };
 #endif

Thanks,
Michal

#2 lore raw

PATCH 1/1 mmc: implement SDHCI card detect

Hi Michal,

Quoted 24 lines

-----Original Message-----
From: Michal Simek <[email protected]>
Sent: 27 May 2019 06:53
To: Ibai Erkiaga Elorza <[email protected]>; u-boot at lists.denx.de
Subject: Re: [U-Boot] [PATCH] mmc: implement SDHCI card detect

drivers/mmc/sdhci.c static int sdhci_send_command(struct mmc *mmc,

Quoted 13 lines · Ibai Erkiaga

Card detect function implemented for SDHCI framework.

---

 drivers/mmc/sdhci.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/mmc/sdhci.c index renamed from drivers/mmc/sdhci.c +0 -0

e2bb90a..cb4db8d 100644

drivers/mmc/sdhci.c +0 -0
@@ -390,6 +390,21 @@ static int sdhci_send_command(struct mmc *mmc,

struct mmc_cmd *cmd,

Quoted 3 lines
drivers/mmc/sdhci.c +0 -0
 		return -ECOMM;
 }
 
Quoted 15 lines

drivers/mmc/sdhci.c static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd, · line 405

Quoted 9 lines
drivers/mmc/sdhci.c +9 -0
+#if IS_ENABLED(CONFIG_DM_MMC)
+static int sdhci_get_cd(struct udevice *dev) {
+	struct mmc *mmc = mmc_get_mmc_dev(dev); #else static int
+sdhci_get_cd(struct mmc *mmc) { #endif
+	u32 state;
+	struct sdhci_host *host = mmc->priv;
+
+	state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+	return (state & SDHCI_CARD_PRESENT);

This should be much more robust. It should at least handle cases where you have broken-cd, cd-gpios, cd-inverted cases.
This code will likely work with boards which have CD connected properly but it is enabled for all which will cause a lot of issues.

You are right, this implementation is quite basic and the idea was just to get rid-off the polling message for the golden use case (properly connected CD).

Quoted 3 lines

If you want to add this functionality one by one then new Kconfig should be used but I am not big fan of that.

The broken-cd Kconfig is already in the MMC framework so I would say that you can use this implementation if your CD is properly connected and just stay as current implementation using CONFIG_MMC_BROKEN_CD.

Quoted 17 lines

drivers/mmc/sdhci.c static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd, · line 408

Quoted 3 lines
drivers/mmc/sdhci.c +2 -0
+}
+
 #if defined(CONFIG_DM_MMC) && defined(MMC_SUPPORTS_TUNING)

static

Quoted 13 lines

int sdhci_execute_tuning(struct udevice *dev, uint opcode) { @@ -627,6 +642,7 @@ int sdhci_probe(struct udevice *dev) const struct dm_mmc_ops sdhci_ops = {

drivers/mmc/sdhci.c +1 -0
 	.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
@@ -635,6 +651,7 @@ const struct dm_mmc_ops sdhci_ops = {  static
 const struct mmc_ops sdhci_ops = {
 	.send_cmd	= sdhci_send_command,
 	.set_ios	= sdhci_set_ios,
Quoted 8 lines

drivers/mmc/sdhci.c const struct dm_mmc_ops sdhci_ops = { · line 657

Quoted 5 lines
drivers/mmc/sdhci.c +1 -0
+	.get_cd		= sdhci_get_cd,
 	.init		= sdhci_init,
 };
 #endif

Thanks,
Michal

Thanks,
Ibai

#3 lore raw

PATCH 1/1 mmc: implement SDHCI card detect

Quoted 41 lines · Ibai Erkiaga Elorza

Hi Michal,

Quoted 24 lines

-----Original Message-----
From: Michal Simek <[email protected]>
Sent: 27 May 2019 06:53
To: Ibai Erkiaga Elorza <[email protected]>; u-boot at lists.denx.de
Subject: Re: [U-Boot] [PATCH] mmc: implement SDHCI card detect

drivers/mmc/sdhci.c static int sdhci_send_command(struct mmc *mmc,

Quoted 13 lines · Ibai Erkiaga

Card detect function implemented for SDHCI framework.

---

 drivers/mmc/sdhci.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/mmc/sdhci.c index renamed from drivers/mmc/sdhci.c +0 -0

e2bb90a..cb4db8d 100644

drivers/mmc/sdhci.c +0 -0
@@ -390,6 +390,21 @@ static int sdhci_send_command(struct mmc *mmc,

struct mmc_cmd *cmd,

Quoted 3 lines
drivers/mmc/sdhci.c +0 -0
 		return -ECOMM;
 }
 
Quoted 15 lines

drivers/mmc/sdhci.c static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd, · line 405

Quoted 9 lines
drivers/mmc/sdhci.c +9 -0
+#if IS_ENABLED(CONFIG_DM_MMC)
+static int sdhci_get_cd(struct udevice *dev) {
+	struct mmc *mmc = mmc_get_mmc_dev(dev); #else static int
+sdhci_get_cd(struct mmc *mmc) { #endif
+	u32 state;
+	struct sdhci_host *host = mmc->priv;
+
+	state = sdhci_readl(host, SDHCI_PRESENT_STATE);
+	return (state & SDHCI_CARD_PRESENT);

This should be much more robust. It should at least handle cases where you have broken-cd, cd-gpios, cd-inverted cases.
This code will likely work with boards which have CD connected properly but it is enabled for all which will cause a lot of issues.

Quoted 6 lines

You are right, this implementation is quite basic and the idea was just to get rid-off the polling message for the golden use case (properly connected CD).

Quoted 3 lines

If you want to add this functionality one by one then new Kconfig should be used but I am not big fan of that.

The broken-cd Kconfig is already in the MMC framework so I would say that you can use this implementation if your CD is properly connected and just stay as current implementation using CONFIG_MMC_BROKEN_CD.

I expect that there are several pieces around but it needs to be done properly or this will break a lot of boards.

M