diff mbox series

[v3,4/6] mmc: fsl_esdhc_imx: add CD support when OF_PLATDATA is enabled

Message ID 20200729153121.29548-5-walter.lozano@collabora.com
State Accepted
Commit 7142ff9ec23a3dc496b43b284595bfa25ab668bf
Delegated to: Stefano Babic
Headers show
Series mx6cuboxi: enable OF_PLATDATA with MMC support | expand

Commit Message

Walter Lozano July 29, 2020, 3:31 p.m. UTC
After enabling OF_PLATDATA support to both MMC and GPIO drivers add the
support for card detection.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

Changes in v3:
- Change #ifdef to if when possible

 drivers/mmc/fsl_esdhc_imx.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

Comments

Stefano Babic Aug. 4, 2020, 8:52 a.m. UTC | #1
> After enabling OF_PLATDATA support to both MMC and GPIO drivers add the
> support for card detection.
> Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/drivers/mmc/fsl_esdhc_imx.c b/drivers/mmc/fsl_esdhc_imx.c
index 2713682cf7..788677984b 100644
--- a/drivers/mmc/fsl_esdhc_imx.c
+++ b/drivers/mmc/fsl_esdhc_imx.c
@@ -1498,7 +1498,30 @@  static int fsl_esdhc_probe(struct udevice *dev)
 		priv->bus_width = 4;
 	else
 		priv->bus_width = 1;
-	priv->non_removable = 1;
+
+	if (dtplat->non_removable)
+		priv->non_removable = 1;
+	else
+		priv->non_removable = 0;
+
+	if (CONFIG_IS_ENABLED(DM_GPIO) && !priv->non_removable) {
+		struct udevice *gpiodev;
+		struct driver_info *info;
+
+		info = (struct driver_info *)dtplat->cd_gpios->node;
+
+		ret = device_get_by_driver_info(info, &gpiodev);
+
+		if (ret)
+			return ret;
+
+		ret = gpio_dev_request_index(gpiodev, gpiodev->name, "cd-gpios",
+					     dtplat->cd_gpios->arg[0], GPIOD_IS_IN,
+					     dtplat->cd_gpios->arg[1], &priv->cd_gpio);
+
+		if (ret)
+			return ret;
+	}
 #endif
 
 	if (data)