[U-Boot] [PATCH v3 0/4] Add SDHCI card detection support

Hi,
This patch series adds card detection support in sdhci framework & added functionality to read card detect dt properties.
Thanks, Michal
Changes in v3: - New patch in this series to release macros - Changed MMC_CAP_SD_NONREMOVABLE, MMC_CAP_SD_NEEDS_POLL names to align with Linux bit definitions by removing SD. - Use new MMC_SD.. macros
Changes in v2: - Moved reading CD devicetree properties functionality from sdhci.c to mmc-uclass.c & moved mmc capability macros to mmc.h from sdhci.h. - Created a new patch for reading "cd-gpio" property from DT. - Used CARD_PRESENT instead of SDHCI_CARD_DETECT_PIN_LEVEL for reading sd card presence detection.
T Karthik Reddy (4): mmc: mvebu: Remove unused MMC_CAP.. macros mmc: Read sd card detect properties from DT mmc: sdhci: Read cd-gpio from devicetree mmc: sdhci: Implement SDHCI card detect
drivers/mmc/mmc-uclass.c | 9 +++++++++ drivers/mmc/sdhci.c | 38 ++++++++++++++++++++++++++++++++++++++ include/mmc.h | 4 ++++ include/mvebu_mmc.h | 4 ---- 4 files changed, 51 insertions(+), 4 deletions(-)

From: T Karthik Reddy t.karthik.reddy@xilinx.com
Removed MMC_CAP_NONREMOVABLE, MMC_CAP_NEEDS_POLL macros from mvebu_mmc.h to avoid redefining of these macros when compiled with mvebu based configs.
Signed-off-by: T Karthik Reddy t.karthik.reddy@xilinx.com Signed-off-by: Michal Simek michal.simek@xilinx.com ---
Changes in v3: - New patch in this series to release macros
Changes in v2: None
include/mvebu_mmc.h | 4 ---- 1 file changed, 4 deletions(-)
diff --git a/include/mvebu_mmc.h b/include/mvebu_mmc.h index d51b1fe4670e..7397165f67f6 100644 --- a/include/mvebu_mmc.h +++ b/include/mvebu_mmc.h @@ -222,13 +222,9 @@ #define MMC_CAP_SDIO_IRQ (1 << 3) /* Talks only SPI protocols */ #define MMC_CAP_SPI (1 << 4) -/* Needs polling for card-detection */ -#define MMC_CAP_NEEDS_POLL (1 << 5) /* Can the host do 8 bit transfers */ #define MMC_CAP_8_BIT_DATA (1 << 6)
-/* Nonremovable e.g. eMMC */ -#define MMC_CAP_NONREMOVABLE (1 << 8) /* Waits while card is busy */ #define MMC_CAP_WAIT_WHILE_BUSY (1 << 9) /* Allow erase/trim commands */

Subject: [PATCH v3 1/4] mmc: mvebu: Remove unused MMC_CAP.. macros
From: T Karthik Reddy t.karthik.reddy@xilinx.com
Removed MMC_CAP_NONREMOVABLE, MMC_CAP_NEEDS_POLL macros from mvebu_mmc.h to avoid redefining of these macros when compiled with mvebu based configs.
Signed-off-by: T Karthik Reddy t.karthik.reddy@xilinx.com Signed-off-by: Michal Simek michal.simek@xilinx.com
Changes in v3:
- New patch in this series to release macros
Changes in v2: None
include/mvebu_mmc.h | 4 ---- 1 file changed, 4 deletions(-)
diff --git a/include/mvebu_mmc.h b/include/mvebu_mmc.h index d51b1fe4670e..7397165f67f6 100644 --- a/include/mvebu_mmc.h +++ b/include/mvebu_mmc.h @@ -222,13 +222,9 @@ #define MMC_CAP_SDIO_IRQ (1 << 3) /* Talks only SPI protocols */ #define MMC_CAP_SPI (1 << 4) -/* Needs polling for card-detection */ -#define MMC_CAP_NEEDS_POLL (1 << 5) /* Can the host do 8 bit transfers */ #define MMC_CAP_8_BIT_DATA (1 << 6)
-/* Nonremovable e.g. eMMC */ -#define MMC_CAP_NONREMOVABLE (1 << 8) /* Waits while card is busy */ #define MMC_CAP_WAIT_WHILE_BUSY (1 << 9) /* Allow erase/trim commands */
Patchset applied to mmc master.
Thanks, Peng.
-- 2.17.1

From: T Karthik Reddy t.karthik.reddy@xilinx.com
This patch reads card detect properties from device tree & added mmc capability macros in mmc.h.
Signed-off-by: T Karthik Reddy t.karthik.reddy@xilinx.com Signed-off-by: Michal Simek michal.simek@xilinx.com ---
Changes in v3: - Changed MMC_CAP_SD_NONREMOVABLE, MMC_CAP_SD_NEEDS_POLL names to align with Linux bit definitions by removing SD.
Changes in v2: - Moved reading CD devicetree properties functionality from sdhci.c to mmc-uclass.c & moved mmc capability macros to mmc.h from sdhci.h.
drivers/mmc/mmc-uclass.c | 9 +++++++++ include/mmc.h | 4 ++++ 2 files changed, 13 insertions(+)
diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c index a9c8f335c142..fa4d1af55d61 100644 --- a/drivers/mmc/mmc-uclass.c +++ b/drivers/mmc/mmc-uclass.c @@ -171,6 +171,15 @@ int mmc_of_parse(struct udevice *dev, struct mmc_config *cfg) if (dev_read_bool(dev, "mmc-hs400-1_2v")) cfg->host_caps |= MMC_CAP(MMC_HS_400);
+ if (dev_read_bool(dev, "non-removable")) { + cfg->host_caps |= MMC_CAP_NONREMOVABLE; + } else { + if (dev_read_bool(dev, "cd-inverted")) + cfg->host_caps |= MMC_CAP_CD_ACTIVE_HIGH; + if (dev_read_bool(dev, "broken-cd")) + cfg->host_caps |= MMC_CAP_NEEDS_POLL; + } + return 0; }
diff --git a/include/mmc.h b/include/mmc.h index 1f30f71d25f8..2be3e91fcb58 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -66,6 +66,10 @@ #define MMC_MODE_HS200 MMC_CAP(MMC_HS_200) #define MMC_MODE_HS400 MMC_CAP(MMC_HS_400)
+#define MMC_CAP_NONREMOVABLE BIT(14) +#define MMC_CAP_NEEDS_POLL BIT(15) +#define MMC_CAP_CD_ACTIVE_HIGH BIT(16) + #define MMC_MODE_8BIT BIT(30) #define MMC_MODE_4BIT BIT(29) #define MMC_MODE_1BIT BIT(28)

From: T Karthik Reddy t.karthik.reddy@xilinx.com
This patch reads cd-gpio property from devicetree
Signed-off-by: T Karthik Reddy t.karthik.reddy@xilinx.com Signed-off-by: Michal Simek michal.simek@xilinx.com Reviewed-by: Peng Fan peng.fan@nxp.com ---
Changes in v3: None Changes in v2: - Created a new patch for reading "cd-gpio" property from DT.
drivers/mmc/sdhci.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index e2bb90abbdf3..4ffe74e35e08 100644 --- a/drivers/mmc/sdhci.c +++ b/drivers/mmc/sdhci.c @@ -590,6 +590,12 @@ static int sdhci_set_ios(struct mmc *mmc) static int sdhci_init(struct mmc *mmc) { struct sdhci_host *host = mmc->priv; +#if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_GPIO) + struct udevice *dev = mmc->dev; + + gpio_request_by_name(dev, "cd-gpio", 0, + &host->cd_gpio, GPIOD_IS_IN); +#endif
sdhci_reset(host, SDHCI_RESET_ALL);

From: T Karthik Reddy t.karthik.reddy@xilinx.com
Card detect function implemented for SDHCI framework.
Signed-off-by: T Karthik Reddy t.karthik.reddy@xilinx.com Signed-off-by: Michal Simek michal.simek@xilinx.com ---
Changes in v3: - Use new MMC_SD.. macros
Changes in v2: - Used CARD_PRESENT instead of SDHCI_CARD_DETECT_PIN_LEVEL for reading sd card presence detection.
drivers/mmc/sdhci.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index 4ffe74e35e08..c4e88790bc68 100644 --- a/drivers/mmc/sdhci.c +++ b/drivers/mmc/sdhci.c @@ -12,6 +12,7 @@ #include <malloc.h> #include <mmc.h> #include <sdhci.h> +#include <dm.h>
#if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER) void *aligned_buffer = (void *)CONFIG_FIXED_SDHCI_ALIGNED_BUFFER; @@ -630,9 +631,40 @@ int sdhci_probe(struct udevice *dev) return sdhci_init(mmc); }
+int sdhci_get_cd(struct udevice *dev) +{ + struct mmc *mmc = mmc_get_mmc_dev(dev); + struct sdhci_host *host = mmc->priv; + int value; + + /* If nonremovable, assume that the card is always present. */ + if (mmc->cfg->host_caps & MMC_CAP_NONREMOVABLE) + return 1; + /* If polling, assume that the card is always present. */ + if (mmc->cfg->host_caps & MMC_CAP_NEEDS_POLL) + return 1; + +#if CONFIG_IS_ENABLED(DM_GPIO) + value = dm_gpio_get_value(&host->cd_gpio); + if (value >= 0) { + if (mmc->cfg->host_caps & MMC_CAP_CD_ACTIVE_HIGH) + return !value; + else + return value; + } +#endif + value = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & + SDHCI_CARD_PRESENT); + if (mmc->cfg->host_caps & MMC_CAP_CD_ACTIVE_HIGH) + return !value; + else + return value; +} + const struct dm_mmc_ops sdhci_ops = { .send_cmd = sdhci_send_command, .set_ios = sdhci_set_ios, + .get_cd = sdhci_get_cd, #ifdef MMC_SUPPORTS_TUNING .execute_tuning = sdhci_execute_tuning, #endif
participants (2)
-
Michal Simek
-
Peng Fan