]> git.sur5r.net Git - u-boot/blobdiff - drivers/mmc/arm_pl180_mmci.c
dm: core: Add ofnode function to read a 64-bit int
[u-boot] / drivers / mmc / arm_pl180_mmci.c
index 3de6b12b0c52524614b159e159a9eee3c45558a5..e267cd782e8b1f4d5e9f144ebe6f2a3636c0bde9 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * ARM PrimeCell MultiMedia Card Interface - PL180
  *
@@ -6,8 +7,6 @@
  * Author: Ulf Hansson <ulf.hansson@stericsson.com>
  * Author: Martin Lundholm <martin.xa.lundholm@stericsson.com>
  * Ported to drivers/mmc/ by: Matt Waddel <matt.waddel@linaro.org>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /* #define DEBUG */
 #include <malloc.h>
 #include <mmc.h>
 
-#include "arm_pl180_mmci.h"
-
 #include <asm/io.h>
+#include <asm-generic/gpio.h>
+
+#include "arm_pl180_mmci.h"
 
 #ifdef CONFIG_DM_MMC
 #include <dm.h>
-DECLARE_GLOBAL_DATA_PTR;
-
 #define MMC_CLOCK_MAX  48000000
 #define MMC_CLOCK_MIN  400000
 
@@ -435,6 +433,8 @@ static int arm_pl180_mmc_probe(struct udevice *dev)
                                               MMC_CLOCK_MAX);
        host->version2 = dev_get_driver_data(dev);
 
+       gpio_request_by_name(dev, "cd-gpios", 0, &host->cd_gpio, GPIOD_IS_IN);
+
        bus_width = dev_read_u32_default(dev, "bus-width", 1);
        switch (bus_width) {
        case 8:
@@ -477,9 +477,26 @@ static int dm_host_set_ios(struct udevice *dev)
        return host_set_ios(mmc);
 }
 
+static int dm_mmc_getcd(struct udevice *dev)
+{
+       struct arm_pl180_mmc_plat *pdata = dev_get_platdata(dev);
+       struct mmc *mmc = &pdata->mmc;
+       struct pl180_mmc_host *host = mmc->priv;
+       int value = 1;
+
+       if (dm_gpio_is_valid(&host->cd_gpio)) {
+               value = dm_gpio_get_value(&host->cd_gpio);
+               if (host->cd_inverted)
+                       return !value;
+       }
+
+       return value;
+}
+
 static const struct dm_mmc_ops arm_pl180_dm_mmc_ops = {
        .send_cmd = dm_host_request,
        .set_ios = dm_host_set_ios,
+       .get_cd = dm_mmc_getcd,
 };
 
 static int arm_pl180_mmc_ofdata_to_platdata(struct udevice *dev)