All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aswath Govindraju <a-govindraju@ti.com>
To: u-boot@lists.denx.de
Subject: [PATCH v3 01/20] mmc: sdhci: Add helper functions for UHS modes
Date: Thu, 21 Jan 2021 18:10:33 +0530	[thread overview]
Message-ID: <20210121124052.3454-2-a-govindraju@ti.com> (raw)
In-Reply-To: <20210121124052.3454-1-a-govindraju@ti.com>

From: Faiz Abbas <faiz_abbas@ti.com>

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>
---
 drivers/mmc/sdhci.c | 80 +++++++++++++++++++++++++++++++++++++++++++++
 include/sdhci.h     |  1 +
 2 files changed, 81 insertions(+)

diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 06289343124e..e7e3e22d1a7e 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -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,85 @@ void sdhci_set_uhs_timing(struct sdhci_host *host)
 	sdhci_writew(host, reg, SDHCI_HOST_CONTROL2);
 }
 
+#if CONFIG_IS_ENABLED(MMC_IO_VOLTAGE)
+static void sdhci_set_voltage(struct sdhci_host *host)
+{
+	struct mmc *mmc = (struct mmc *)host->mmc;
+	u32 ctrl;
+	int ret;
+
+	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) {
+			ret = regulator_set_enable(mmc->vqmmc_supply, false);
+			if (ret) {
+				pr_err("failed to disable vqmmc-supply: %d\n", ret);
+				return;
+			}
+
+			ret = regulator_set_value(mmc->vqmmc_supply, 3300000);
+			if (ret) {
+				pr_err("failed to set vqmmc-voltage to 3.3V: %d\n", ret);
+				return;
+			}
+
+			ret = regulator_set_enable(mmc->vqmmc_supply, true);
+			if (ret) {
+				pr_err("failed to enable vqmmc-supply: %d\n", ret);
+				return;
+			}
+		}
+#endif
+		mdelay(5);
+		if (IS_SD(mmc)) {
+			ctrl &= ~SDHCI_CTRL_VDD_180;
+			sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+		}
+		break;
+	case MMC_SIGNAL_VOLTAGE_180:
+#if CONFIG_IS_ENABLED(DM_REGULATOR)
+		if (mmc->vqmmc_supply) {
+			regulator_set_enable(mmc->vqmmc_supply, false);
+			if (ret) {
+				pr_err("failed to disable vqmmc-supply: %d\n", ret);
+				return;
+			}
+
+			regulator_set_value(mmc->vqmmc_supply, 1800000);
+			if (ret) {
+				pr_err("failed to set vqmmc-voltage to 1.8V: %d\n", ret);
+				return;
+			}
+
+			regulator_set_enable(mmc->vqmmc_supply, true);
+			if (ret) {
+				pr_err("failed to enable vqmmc-supply: %d\n", ret);
+				return;
+			}
+		}
+#endif
+		if (IS_SD(mmc)) {
+			ctrl |= SDHCI_CTRL_VDD_180;
+			sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+		}
+		break;
+	default:
+		/* No signal voltage switch required */
+		return;
+	}
+}
+#else
+static void sdhci_set_voltage(struct sdhci_host *host) { }
+#endif
+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)
 {
diff --git a/include/sdhci.h b/include/sdhci.h
index 3e5a64981857..0f820c6d2669 100644
--- a/include/sdhci.h
+++ b/include/sdhci.h
@@ -491,6 +491,7 @@ 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);
+void sdhci_set_control_reg(struct sdhci_host *host);
 extern const struct dm_mmc_ops sdhci_ops;
 #else
 #endif
-- 
2.17.1

  reply	other threads:[~2021-01-21 12:40 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21 12:40 [PATCH v3 00/20] Add support for MMC higher speed modes for TI's am65x, j721e and j7200 platforms Aswath Govindraju
2021-01-21 12:40 ` Aswath Govindraju [this message]
2021-01-24  2:03   ` [PATCH v3 01/20] mmc: sdhci: Add helper functions for UHS modes Simon Glass
2021-01-25 10:23     ` Aswath Govindraju
2021-01-25 22:18   ` Jaehoon Chung
2021-01-28  9:20     ` Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 02/20] mmc: am654_sdhci: Unconditionally switch off DLL in the beginning of ios_post() Aswath Govindraju
2021-01-25 22:19   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 03/20] mmc: am654_sdhci: Convert flag fields to BIT macro Aswath Govindraju
2021-01-25 22:19   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 04/20] mmc: am654_sdhci: Add flag for PHY calibration Aswath Govindraju
2021-01-25 22:19   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 05/20] mmc: am654_sdhci: Add support for AM65x SR2.0 Aswath Govindraju
2021-01-25 22:19   ` Jaehoon Chung
2021-01-28  9:15     ` Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 06/20] mmc: am654_sdhci: Add support for input tap delay Aswath Govindraju
2021-01-25 22:21   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 07/20] mmc: am654_sdhci: Add support for writing to clkbuf_sel Aswath Govindraju
2021-01-25 22:22   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 08/20] mmc: am654_sdhci: Add support for software tuning Aswath Govindraju
2021-01-25 22:41   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 09/20] mmc: am654_sdhci: Fix HISPD bit configuration in some lower speed modes Aswath Govindraju
2021-01-25 22:43   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 10/20] mmc: am654_sdhci: Use sdhci_set_control_reg() Aswath Govindraju
2021-01-25 22:43   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 11/20] arm: dts: k3-am65: Fix mmc nodes Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 12/20] arm: dts: k3-j721e-main: Update otap-delay values Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 13/20] arm: dts: k3-j721e-common-proc-board: Add support for UHS modes for SD card Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 14/20] arm: dts: k3-j7200-main: Add support for gpio0 Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 15/20] arm: dts: k3-j7200-common-proc-board: Enable support for UHS modes Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 16/20] configs: j721e_evm: Add " Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 17/20] configs: j7200_evm: " Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 18/20] arm: dts: k3-am65-main: Add itapdly and clkbuf-sel values Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 19/20] arm: dts: k3-am654-base-board: Limit Sd card to High speed modes Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 20/20] configs: am65x_evm: Add configs for UHS modes Aswath Govindraju

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210121124052.3454-2-a-govindraju@ti.com \
    --to=a-govindraju@ti.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.