public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Adam Ford <aford173@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2] MMC: davinici_mmc: Enable CD and WP with DM and OF_CONTROL
Date: Mon,  3 Sep 2018 03:47:52 -0500	[thread overview]
Message-ID: <20180903084752.17279-1-aford173@gmail.com> (raw)

When used with a device tree, this will extract the card detect
and write protect pins from the device tree and configure them
accordingly.  This assumes the GPIO_ACTIVE_LOW/HIGH is supported
by da8xx_gpio.

Signed-off-by: Adam Ford <aford173@gmail.com>
---
V2: Wrap the CD and WP GPIO references around DM_GPIO to prevent errors

diff --git a/drivers/mmc/davinci_mmc.c b/drivers/mmc/davinci_mmc.c
index db950ea5ec..0d63279db0 100644
--- a/drivers/mmc/davinci_mmc.c
+++ b/drivers/mmc/davinci_mmc.c
@@ -15,6 +15,7 @@
 #include <malloc.h>
 #include <asm/io.h>
 #include <asm/arch/sdmmc_defs.h>
+#include <asm-generic/gpio.h>
 
 #define DAVINCI_MAX_BLOCKS	(32)
 #define WATCHDOG_COUNT		(100000)
@@ -35,6 +36,8 @@ struct davinci_mmc_priv {
 	struct davinci_mmc_regs *reg_base;	/* Register base address */
 	uint input_clk;		/* Input clock to MMC controller */
 	uint version;		/* MMC Controller version */
+	struct gpio_desc cd_gpio;       /* Card Detect GPIO */
+	struct gpio_desc wp_gpio;       /* Write Protect GPIO */
 };
 
 struct davinci_mmc_plat
@@ -425,9 +428,41 @@ static const struct mmc_ops dmmc_ops = {
        .init           = dmmc_init,
 };
 #else
+
+static int davinci_mmc_getcd(struct udevice *dev)
+{
+	int value = -1;
+#if CONFIG_IS_ENABLED(DM_GPIO)
+	struct davinci_mmc_priv *priv = dev_get_priv(dev);
+	value = dm_gpio_get_value(&priv->cd_gpio);
+#endif
+	/* if no CD return as 1 */
+	if (value < 0)
+		return 1;
+
+	return value;
+}
+
+static int davinci_mmc_getwp(struct udevice *dev)
+{
+	int value = -1;
+#if CONFIG_IS_ENABLED(DM_GPIO)
+	struct davinci_mmc_priv *priv = dev_get_priv(dev);
+
+	value = dm_gpio_get_value(&priv->wp_gpio);
+#endif
+	/* if no WP return as 0 */
+	if (value < 0)
+		return 0;
+
+	return value;
+}
+
 static const struct dm_mmc_ops davinci_mmc_ops = {
 	.send_cmd	= davinci_mmc_send_cmd,
 	.set_ios	= davinci_mmc_set_ios,
+	.get_cd		= davinci_mmc_getcd,
+	.get_wp		= davinci_mmc_getwp,
 };
 #endif
 
@@ -475,6 +510,12 @@ static int davinci_mmc_probe(struct udevice *dev)
 	priv->reg_base = (struct davinci_mmc_regs *)dev_read_addr(dev);
 	priv->input_clk = clk_get(DAVINCI_MMCSD_CLKID);
 
+#if CONFIG_IS_ENABLED(DM_GPIO)
+	/* These GPIOs are optional */
+	gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio, GPIOD_IS_IN);
+	gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio, GPIOD_IS_IN);
+#endif
+
 	upriv->mmc = &plat->mmc;
 
 	return davinci_dm_mmc_init(dev);
-- 
2.17.1

             reply	other threads:[~2018-09-03  8:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-03  8:47 Adam Ford [this message]
2018-09-18 21:27 ` [U-Boot] [U-Boot, V2] MMC: davinici_mmc: Enable CD and WP with DM and OF_CONTROL Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180903084752.17279-1-aford173@gmail.com \
    --to=aford173@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox