All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
To: u-boot@lists.denx.de
Cc: Faiz Abbas <faiz_abbas@ti.com>,
	Jaehoon Chung <jh80.chung@samsung.com>,
	Philipp Tomsich <philipp.tomsich@vrull.eu>,
	Peter Robinson <pbrobinson@gmail.com>,
	Peng Fan <peng.fan@nxp.com>, Peter Geis <pgwipeout@gmail.com>,
	Jagan Teki <jagan@amarulasolutions.com>,
	Samuel Dionne-Riel <samuel@dionne-riel.com>,
	Simon Glass <sjg@chromium.org>,
	Kever Yang <kever.yang@rock-chips.com>,
	Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>,
	Aswath Govindraju <a-govindraju@ti.com>,
	Jack Mitchell <ml@embed.me.uk>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Yifeng Zhao <yifeng.zhao@rock-chips.com>,
	Michal Simek <michal.simek@xilinx.com>,
	Stephen Carlson <stcarlso@linux.microsoft.com>,
	Alper Nebi Yasak <alpernebiyasak@gmail.com>
Subject: [PATCH v5 2/3] rockchip: sdhci: Add HS400 Enhanced Strobe support for RK3399
Date: Tue, 15 Mar 2022 20:46:27 +0300	[thread overview]
Message-ID: <20220315174629.7467-3-alpernebiyasak@gmail.com> (raw)
In-Reply-To: <20220315174629.7467-1-alpernebiyasak@gmail.com>

On RK3399, a register bit must be set to enable Enhanced Strobe.
Let the Rockchip SDHCI driver set it when Enhanced Strobe configuration
is requested. However, having it set makes the lower-speed modes stop
working and makes reinitialization fail, so let it be unset as needed in
set_control_reg().

This is mostly ported from Linux's Arasan SDHCI driver which happens
to be the underlying IP. (drivers/mmc/host/sdhci-of-arasan.c in Linux
tree).

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
---

Changes in v5:
- Add tag: "Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>"

Changes in v4:
- Add comment for Rockchip SDHCI set_enhanced_strobe() driver data op

Changes in v2:
- Unset ES bit in rk3399 set_control_reg() to fix a reinit issue
- Don't use unnecessary & for function pointer in ops struct
- Rename rk3399_set_enhanced_strobe -> rk3399_sdhci_set_enhanced_strobe
- Let set_enhanced_strobe() unset the ES bit if mode is not HS400_ES

 drivers/mmc/rockchip_sdhci.c | 53 ++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/drivers/mmc/rockchip_sdhci.c b/drivers/mmc/rockchip_sdhci.c
index b91df05de4ff..f4d5a59036a2 100644
--- a/drivers/mmc/rockchip_sdhci.c
+++ b/drivers/mmc/rockchip_sdhci.c
@@ -42,6 +42,9 @@
 	((((x) >> PHYCTRL_DLLRDY_SHIFT) & PHYCTRL_DLLRDY_MASK) ==\
 	PHYCTRL_DLLRDY_DONE)
 
+#define ARASAN_VENDOR_REGISTER		0x78
+#define ARASAN_VENDOR_ENHANCED_STROBE	BIT(0)
+
 /* Rockchip specific Registers */
 #define DWCMSHC_EMMC_DLL_CTRL		0x800
 #define DWCMSHC_EMMC_DLL_CTRL_RESET	BIT(1)
@@ -117,6 +120,19 @@ struct sdhci_data {
 	 * Return: 0 if successful, -ve on error
 	 */
 	int (*set_ios_post)(struct sdhci_host *host);
+
+	/**
+	 * set_enhanced_strobe() - Set HS400 Enhanced Strobe config
+	 *
+	 * This is the set_enhanced_strobe() SDHCI operation that should
+	 * be used for the hardware this driver data is associated with.
+	 * Normally, this is used to set any host-specific configuration
+	 * necessary for HS400 ES.
+	 *
+	 * @host: SDHCI host structure
+	 * Return: 0 if successful, -ve on error
+	 */
+	int (*set_enhanced_strobe)(struct sdhci_host *host);
 };
 
 static int rk3399_emmc_phy_init(struct udevice *dev)
@@ -206,6 +222,21 @@ static int rk3399_emmc_get_phy(struct udevice *dev)
 	return 0;
 }
 
+static int rk3399_sdhci_set_enhanced_strobe(struct sdhci_host *host)
+{
+	struct mmc *mmc = host->mmc;
+	u32 vendor;
+
+	vendor = sdhci_readl(host, ARASAN_VENDOR_REGISTER);
+	if (mmc->selected_mode == MMC_HS_400_ES)
+		vendor |= ARASAN_VENDOR_ENHANCED_STROBE;
+	else
+		vendor &= ~ARASAN_VENDOR_ENHANCED_STROBE;
+	sdhci_writel(host, vendor, ARASAN_VENDOR_REGISTER);
+
+	return 0;
+}
+
 static void rk3399_sdhci_set_control_reg(struct sdhci_host *host)
 {
 	struct rockchip_sdhc *priv = container_of(host, struct rockchip_sdhc, host);
@@ -217,6 +248,15 @@ static void rk3399_sdhci_set_control_reg(struct sdhci_host *host)
 		rk3399_emmc_phy_power_off(priv->phy);
 
 	sdhci_set_control_reg(host);
+
+	/*
+	 * Reinitializing the device tries to set it to lower-speed modes
+	 * first, which fails if the Enhanced Strobe bit is set, making
+	 * the device impossible to use. Set the correct value here to
+	 * let reinitialization attempts succeed.
+	 */
+	if (CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT))
+		rk3399_sdhci_set_enhanced_strobe(host);
 };
 
 static int rk3399_sdhci_set_ios_post(struct sdhci_host *host)
@@ -409,10 +449,22 @@ static int rockchip_sdhci_execute_tuning(struct mmc *mmc, u8 opcode)
 	return ret;
 }
 
+static int rockchip_sdhci_set_enhanced_strobe(struct sdhci_host *host)
+{
+	struct rockchip_sdhc *priv = container_of(host, struct rockchip_sdhc, host);
+	struct sdhci_data *data = (struct sdhci_data *)dev_get_driver_data(priv->dev);
+
+	if (data->set_enhanced_strobe)
+		return data->set_enhanced_strobe(host);
+
+	return -ENOTSUPP;
+}
+
 static struct sdhci_ops rockchip_sdhci_ops = {
 	.set_ios_post	= rockchip_sdhci_set_ios_post,
 	.platform_execute_tuning = &rockchip_sdhci_execute_tuning,
 	.set_control_reg = rockchip_sdhci_set_control_reg,
+	.set_enhanced_strobe = rockchip_sdhci_set_enhanced_strobe,
 };
 
 static int rockchip_sdhci_probe(struct udevice *dev)
@@ -495,6 +547,7 @@ static const struct sdhci_data rk3399_data = {
 	.emmc_phy_init = rk3399_emmc_phy_init,
 	.set_control_reg = rk3399_sdhci_set_control_reg,
 	.set_ios_post = rk3399_sdhci_set_ios_post,
+	.set_enhanced_strobe = rk3399_sdhci_set_enhanced_strobe,
 };
 
 static const struct sdhci_data rk3568_data = {
-- 
2.35.1


  parent reply	other threads:[~2022-03-15 17:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20220315174657epcas1p23089ad47a1f6fac2017f8ac2f4802765@epcas1p2.samsung.com>
2022-03-15 17:46 ` [PATCH v5 0/3] rockchip: sdhci: Add HS400 Enhanced Strobe support Alper Nebi Yasak
2022-03-15 17:46   ` [PATCH v5 1/3] mmc: " Alper Nebi Yasak
2022-03-16  1:26     ` Kever Yang
2022-03-15 17:46   ` Alper Nebi Yasak [this message]
2022-03-16  1:26     ` [PATCH v5 2/3] rockchip: sdhci: Add HS400 Enhanced Strobe support for RK3399 Kever Yang
2022-03-15 17:46   ` [PATCH v5 3/3] rockchip: sdhci: Add HS400 Enhanced Strobe support for RK3568 Alper Nebi Yasak
2022-03-16  1:12     ` zyf
2022-03-16  1:56     ` Kever Yang
2022-03-16 10:25   ` [PATCH v5 0/3] rockchip: sdhci: Add HS400 Enhanced Strobe support Jaehoon Chung

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=20220315174629.7467-3-alpernebiyasak@gmail.com \
    --to=alpernebiyasak@gmail.com \
    --cc=a-govindraju@ti.com \
    --cc=ashok.reddy.soma@xilinx.com \
    --cc=faiz_abbas@ti.com \
    --cc=jagan@amarulasolutions.com \
    --cc=jh80.chung@samsung.com \
    --cc=kever.yang@rock-chips.com \
    --cc=michal.simek@xilinx.com \
    --cc=ml@embed.me.uk \
    --cc=pbrobinson@gmail.com \
    --cc=peng.fan@nxp.com \
    --cc=pgwipeout@gmail.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=samuel@dionne-riel.com \
    --cc=sjg@chromium.org \
    --cc=stcarlso@linux.microsoft.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    --cc=yifeng.zhao@rock-chips.com \
    /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.