[PATCH RFC 11/20] mmc/jz_mmc: Support wp-gpio/cd-gpio

Lubomir Rintel lkundrak at v3.sk
Tue Nov 17 22:00:09 CET 2020


This adds support for using GPIO lines for detecting Write-Protect and
Card-Detect status.

This way the driver can fail fast if there's no card inserted.

Signed-off-by: Lubomir Rintel <lkundrak at v3.sk>
---
 drivers/mmc/jz_mmc.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/mmc/jz_mmc.c b/drivers/mmc/jz_mmc.c
index d4b9d15ef2e..03fb506e571 100644
--- a/drivers/mmc/jz_mmc.c
+++ b/drivers/mmc/jz_mmc.c
@@ -9,6 +9,7 @@
 #include <common.h>
 #include <malloc.h>
 #include <mmc.h>
+#include <asm/gpio.h>
 #include <asm/io.h>
 #include <asm/unaligned.h>
 #include <errno.h>
@@ -130,6 +131,11 @@ struct jz_mmc_priv {
 #define JZ_MMC_BUS_WIDTH_4	0x2
 #define JZ_MMC_BUS_WIDTH_8	0x3
 #define JZ_MMC_SENT_INIT	BIT(2)
+
+#if CONFIG_IS_ENABLED(DM_GPIO)
+	struct gpio_desc gpio_wp;
+	struct gpio_desc gpio_cd;
+#endif
 };
 
 static int jz_mmc_clock_rate(void)
@@ -438,9 +444,33 @@ static int jz_mmc_dm_set_ios(struct udevice *dev)
 	return jz_mmc_set_ios(mmc, priv);
 };
 
+#if CONFIG_IS_ENABLED(DM_GPIO)
+static int jz_mmc_dm_get_cd(struct udevice *dev)
+{
+	struct jz_mmc_priv *priv = dev_get_priv(dev);
+
+	if (priv->gpio_cd.dev)
+		return dm_gpio_get_value(&priv->gpio_cd);
+	return -ENOSYS;
+}
+
+static int jz_mmc_dm_get_wp(struct udevice *dev)
+{
+	struct jz_mmc_priv *priv = dev_get_priv(dev);
+
+	if (priv->gpio_wp.dev)
+		dm_gpio_get_value(&priv->gpio_wp);
+	return -ENOSYS;
+}
+#endif
+
 static const struct dm_mmc_ops jz_msc_ops = {
 	.send_cmd	= jz_mmc_dm_send_cmd,
 	.set_ios	= jz_mmc_dm_set_ios,
+#if CONFIG_IS_ENABLED(DM_GPIO)
+	.get_cd		= jz_mmc_dm_get_cd,
+	.get_wp		= jz_mmc_dm_get_wp,
+#endif
 };
 
 static int jz_mmc_ofdata_to_platdata(struct udevice *dev)
@@ -484,6 +514,11 @@ static int jz_mmc_probe(struct udevice *dev)
 	struct jz_mmc_priv *priv = dev_get_priv(dev);
 	struct jz_mmc_plat *plat = dev_get_platdata(dev);
 
+#if CONFIG_IS_ENABLED(DM_GPIO)
+	gpio_request_by_name(dev, "wp-gpios", 0, &priv->gpio_wp, GPIOD_IS_IN);
+	gpio_request_by_name(dev, "cd-gpios", 0, &priv->gpio_cd, GPIOD_IS_IN);
+#endif
+
 	plat->mmc.priv = priv;
 	upriv->mmc = &plat->mmc;
 	return jz_mmc_core_init(&plat->mmc);
-- 
2.28.0



More information about the U-Boot mailing list