diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2011-12-05 16:19:01 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2011-12-05 17:57:38 +0100 |
commit | 521c8ff41ecb2e125daa6bfcdbaec63800db7058 (patch) | |
tree | 495e2612b7dbab079c3e0fbfed60c30902dd2b4e /drivers/mci/imx-esdhc.c | |
parent | 133788546c7b00616332ae76c7744f072fe7a543 (diff) | |
download | barebox-521c8ff41ecb2e125daa6bfcdbaec63800db7058.tar.gz barebox-521c8ff41ecb2e125daa6bfcdbaec63800db7058.tar.xz |
imx-esdhc: add support of card detect
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mci/imx-esdhc.c')
-rw-r--r-- | drivers/mci/imx-esdhc.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c index d19b6da4c5..fe55697638 100644 --- a/drivers/mci/imx-esdhc.c +++ b/drivers/mci/imx-esdhc.c @@ -36,6 +36,8 @@ #include <asm/mmu.h> #include <mach/clock.h> #include <mach/generic.h> +#include <mach/esdhc.h> +#include <gpio.h> #include "imx-esdhc.h" @@ -392,6 +394,31 @@ static void esdhc_set_ios(struct mci_host *mci, struct device_d *dev, } +static int esdhc_card_detect(struct fsl_esdhc_host *host) +{ + struct fsl_esdhc *regs = host->regs; + struct esdhc_platform_data *pdata = host->dev->platform_data; + int ret; + + if (!pdata) + return 1; + + switch (pdata->cd_type) { + case ESDHC_CD_NONE: + case ESDHC_CD_PERMANENT: + return 1; + case ESDHC_CD_CONTROLLER: + return !(esdhc_read32(®s->prsstat) & PRSSTAT_WPSPL); + case ESDHC_CD_GPIO: + ret = gpio_direction_input(pdata->cd_gpio); + if (ret) + return ret; + return gpio_get_value(pdata->cd_gpio) ? 0 : 1; + } + + return 0; +} + static int esdhc_init(struct mci_host *mci, struct device_d *dev) { struct fsl_esdhc_host *host = to_fsl_esdhc(mci); @@ -399,6 +426,16 @@ static int esdhc_init(struct mci_host *mci, struct device_d *dev) int timeout = 1000; int ret = 0; + ret = esdhc_card_detect(host); + + if (ret == 0) + return -ENODEV; + + if (ret < 0) + return ret; + + ret = 0; + /* Enable cache snooping */ if (host && !host->no_snoop) esdhc_write32(®s->scr, 0x00000040); |