Commit 5829fe2d59d8c088dadc43dedb36a657d791970c

Authored by Patrice Chotard
Committed by Tom Rini
1 parent 5f256fe71d

mmc: arm_pl180_mmci: add .getcd callback

Add .getcd callback to check is MMC card is present

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

Showing 2 changed files with 26 additions and 2 deletions Side-by-side Diff

drivers/mmc/arm_pl180_mmci.c
... ... @@ -18,10 +18,11 @@
18 18 #include <malloc.h>
19 19 #include <mmc.h>
20 20  
21   -#include "arm_pl180_mmci.h"
22   -
23 21 #include <asm/io.h>
  22 +#include <asm-generic/gpio.h>
24 23  
  24 +#include "arm_pl180_mmci.h"
  25 +
25 26 #ifdef CONFIG_DM_MMC
26 27 #include <dm.h>
27 28 DECLARE_GLOBAL_DATA_PTR;
... ... @@ -435,6 +436,8 @@
435 436 MMC_CLOCK_MAX);
436 437 host->version2 = dev_get_driver_data(dev);
437 438  
  439 + gpio_request_by_name(dev, "cd-gpios", 0, &host->cd_gpio, GPIOD_IS_IN);
  440 +
438 441 bus_width = dev_read_u32_default(dev, "bus-width", 1);
439 442 switch (bus_width) {
440 443 case 8:
441 444  
... ... @@ -477,9 +480,26 @@
477 480 return host_set_ios(mmc);
478 481 }
479 482  
  483 +static int dm_mmc_getcd(struct udevice *dev)
  484 +{
  485 + struct arm_pl180_mmc_plat *pdata = dev_get_platdata(dev);
  486 + struct mmc *mmc = &pdata->mmc;
  487 + struct pl180_mmc_host *host = mmc->priv;
  488 + int value = 1;
  489 +
  490 + if (dm_gpio_is_valid(&host->cd_gpio)) {
  491 + value = dm_gpio_get_value(&host->cd_gpio);
  492 + if (host->cd_inverted)
  493 + return !value;
  494 + }
  495 +
  496 + return value;
  497 +}
  498 +
480 499 static const struct dm_mmc_ops arm_pl180_dm_mmc_ops = {
481 500 .send_cmd = dm_host_request,
482 501 .set_ios = dm_host_set_ios,
  502 + .get_cd = dm_mmc_getcd,
483 503 };
484 504  
485 505 static int arm_pl180_mmc_ofdata_to_platdata(struct udevice *dev)
drivers/mmc/arm_pl180_mmci.h
... ... @@ -191,6 +191,10 @@
191 191 unsigned int pwr_init;
192 192 int version2;
193 193 struct mmc_config cfg;
  194 +#ifdef CONFIG_DM_MMC
  195 + struct gpio_desc cd_gpio;
  196 + bool cd_inverted;
  197 +#endif
194 198 };
195 199  
196 200 int arm_pl180_mmci_init(struct pl180_mmc_host *host, struct mmc **mmc);