[PATCH 2/2] callback: mmc: tmio: Add card detect polling callback
Marek Vasut
marek.vasut at gmail.com
Sat Jan 30 18:55:22 CET 2021
Implement callback for polling the card detect line. This way the
driver automatically detects when a card was removed and sets the
mmc system state for that particular slot to re-init the card on
next use.
Signed-off-by: Marek Vasut <marek.vasut+renesas at gmail.com>
---
drivers/mmc/tmio-common.c | 15 +++++++++++++++
drivers/mmc/tmio-common.h | 3 +++
2 files changed, 18 insertions(+)
diff --git a/drivers/mmc/tmio-common.c b/drivers/mmc/tmio-common.c
index 2c528689bd..57f52af314 100644
--- a/drivers/mmc/tmio-common.c
+++ b/drivers/mmc/tmio-common.c
@@ -713,6 +713,18 @@ int tmio_sd_bind(struct udevice *dev)
return mmc_bind(dev, &plat->mmc, &plat->cfg);
}
+static void tmio_sd_poll_cd(struct callback *cb)
+{
+ struct tmio_sd_plat *plat = container_of(cb, struct tmio_sd_plat, cb_poll_cd);
+ struct mmc *mmc = &plat->mmc;
+ struct udevice *dev = mmc->dev;
+
+ if (mmc->has_init && !mmc_getcd(mmc)) {
+ mmc->has_init = 0;
+ dev_err(dev, "card removed\n");
+ }
+}
+
int tmio_sd_probe(struct udevice *dev, u32 quirks)
{
struct tmio_sd_plat *plat = dev_get_plat(dev);
@@ -775,5 +787,8 @@ int tmio_sd_probe(struct udevice *dev, u32 quirks)
upriv->mmc = &plat->mmc;
+ plat->cb_poll_cd.callback_func = tmio_sd_poll_cd;
+ callback_register(&plat->cb_poll_cd);
+
return 0;
}
diff --git a/drivers/mmc/tmio-common.h b/drivers/mmc/tmio-common.h
index 9062300c64..aac3c24e68 100644
--- a/drivers/mmc/tmio-common.h
+++ b/drivers/mmc/tmio-common.h
@@ -8,6 +8,8 @@
#define __TMIO_COMMON_H__
#include <linux/bitops.h>
+#include <init.h>
+
#define TMIO_SD_CMD 0x000 /* command */
#define TMIO_SD_CMD_NOSTOP BIT(14) /* No automatic CMD12 issue */
#define TMIO_SD_CMD_MULTI BIT(13) /* multiple block transfer */
@@ -114,6 +116,7 @@
struct tmio_sd_plat {
struct mmc_config cfg;
struct mmc mmc;
+ struct callback cb_poll_cd;
};
struct tmio_sd_priv {
--
2.29.2
More information about the U-Boot
mailing list