]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mmc: sdhci: Add helper functions for UHS modes
authorFaiz Abbas <faiz_abbas@ti.com>
Thu, 4 Feb 2021 09:40:46 +0000 (15:10 +0530)
committerLokesh Vutla <lokeshvutla@ti.com>
Thu, 4 Feb 2021 15:07:57 +0000 (20:37 +0530)
Add a set_voltage() function which handles the switch from 3.3V to 1.8V
for SD card UHS modes.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
drivers/mmc/sdhci.c
include/sdhci.h

index 06289343124ec913af91e4833a08aec015a4b8e4..ed0dc173253be10d923fa1c49e9c76b3cd791be0 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
 #include <phys2bus.h>
+#include <power/regulator.h>
 
 static void sdhci_reset(struct sdhci_host *host, u8 mask)
 {
@@ -509,6 +510,100 @@ void sdhci_set_uhs_timing(struct sdhci_host *host)
        sdhci_writew(host, reg, SDHCI_HOST_CONTROL2);
 }
 
+static void sdhci_set_voltage(struct sdhci_host *host)
+{
+       if (IS_ENABLED(CONFIG_MMC_IO_VOLTAGE)) {
+               struct mmc *mmc = (struct mmc *)host->mmc;
+               u32 ctrl;
+
+               ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
+
+               switch (mmc->signal_voltage) {
+               case MMC_SIGNAL_VOLTAGE_330:
+#if CONFIG_IS_ENABLED(DM_REGULATOR)
+                       if (mmc->vqmmc_supply) {
+                               if (regulator_set_enable_if_allowed(mmc->vqmmc_supply, false)) {
+                                       pr_err("failed to disable vqmmc-supply\n");
+                                       return;
+                               }
+
+                               if (regulator_set_value(mmc->vqmmc_supply, 3300000)) {
+                                       pr_err("failed to set vqmmc-voltage to 3.3V\n");
+                                       return;
+                               }
+
+                               if (regulator_set_enable_if_allowed(mmc->vqmmc_supply, true)) {
+                                       pr_err("failed to enable vqmmc-supply\n");
+                                       return;
+                               }
+                       }
+#endif
+                       if (IS_SD(mmc)) {
+                               ctrl &= ~SDHCI_CTRL_VDD_180;
+                               sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+                       }
+
+                       /* Wait for 5ms */
+                       mdelay(5);
+
+                       /* 3.3V regulator output should be stable within 5 ms */
+                       if (IS_SD(mmc)) {
+                               if (ctrl & SDHCI_CTRL_VDD_180) {
+                                       pr_err("3.3V regulator output did not become stable\n");
+                                       return;
+                               }
+                       }
+
+                       break;
+               case MMC_SIGNAL_VOLTAGE_180:
+#if CONFIG_IS_ENABLED(DM_REGULATOR)
+                       if (mmc->vqmmc_supply) {
+                               if (regulator_set_enable_if_allowed(mmc->vqmmc_supply, false)) {
+                                       pr_err("failed to disable vqmmc-supply\n");
+                                       return;
+                               }
+
+                               if (regulator_set_value(mmc->vqmmc_supply, 1800000)) {
+                                       pr_err("failed to set vqmmc-voltage to 1.8V\n");
+                                       return;
+                               }
+
+                               if (regulator_set_enable_if_allowed(mmc->vqmmc_supply, true)) {
+                                       pr_err("failed to enable vqmmc-supply\n");
+                                       return;
+                               }
+                       }
+#endif
+                       if (IS_SD(mmc)) {
+                               ctrl |= SDHCI_CTRL_VDD_180;
+                               sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+                       }
+
+                       /* Wait for 5 ms */
+                       mdelay(5);
+
+                       /* 1.8V regulator output has to be stable within 5 ms */
+                       if (IS_SD(mmc)) {
+                               if (!(ctrl & SDHCI_CTRL_VDD_180)) {
+                                       pr_err("1.8V regulator output did not become stable\n");
+                                       return;
+                               }
+                       }
+
+                       break;
+               default:
+                       /* No signal voltage switch required */
+                       return;
+               }
+       }
+}
+
+void sdhci_set_control_reg(struct sdhci_host *host)
+{
+       sdhci_set_voltage(host);
+       sdhci_set_uhs_timing(host);
+}
+
 #ifdef CONFIG_DM_MMC
 static int sdhci_set_ios(struct udevice *dev)
 {
index 3e5a64981857df6188f87fba165dd008d14d2d66..0ae9471ad749ba714a01d8e984d6f670a30f1d1f 100644 (file)
@@ -491,6 +491,16 @@ void sdhci_set_uhs_timing(struct sdhci_host *host);
 /* Export the operations to drivers */
 int sdhci_probe(struct udevice *dev);
 int sdhci_set_clock(struct mmc *mmc, unsigned int clock);
+
+/**
+ * sdhci_set_control_reg - Set control registers
+ *
+ * This is used set up control registers for voltage level and UHS speed
+ * mode.
+ *
+ * @host: SDHCI host structure
+ */
+void sdhci_set_control_reg(struct sdhci_host *host);
 extern const struct dm_mmc_ops sdhci_ops;
 #else
 #endif