Skip to contentSkip to conversation

mmc: core: Add host specific tuning support for SD HS mode

PATCH Superseded Wenchao Chen 4 participants 5 messages Aug 9, 2023 – Aug 11, 2023

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: core: Add host specific tuning support for SD HS mode

Added .prepare_hs_tuning and .execute_hs_tuning host callbacks to support host-specific tuning for SD high speed mode.

---
 drivers/mmc/core/sd.c         |  12 ++++
 drivers/mmc/host/sdhci-sprd.c | 124 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h      |   6 ++
 3 files changed, 142 insertions(+)
drivers/mmc/core/sd.c +12 -0
index 246ce027ae0a..ac2da8f2fbce 100644
@@ -1518,6 +1518,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 		 */
 		mmc_set_clock(host, mmc_sd_get_max_clock(card));
 
+		if (host->ops->prepare_hs_tuning) {
+			err = host->ops->prepare_hs_tuning(host, card);
+			if (err)
+				goto free_card;
+		}
+
 		/*
 		 * Switch to wider bus (if supported).
 		 */
@@ -1529,6 +1535,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 
 			mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
 		}
+
+		if (host->ops->execute_hs_tuning) {
+			err = host->ops->execute_hs_tuning(host, card);
+			if (err)
+				goto free_card;
+		}
 	}
 cont:
 	if (!oldcard) {
drivers/mmc/host/sdhci-sprd.c +124 -0

160 lines not on this page · raw message

include/linux/mmc/host.h +6 -0
index 461d1543893b..13cf894b9e3c 100644
@@ -184,6 +184,12 @@ struct mmc_host_ops {
 	/* Execute HS400 tuning depending host driver */
 	int	(*execute_hs400_tuning)(struct mmc_host *host, struct mmc_card *card);
 
+	/* Prepare HS tuning depending host driver */
+	int	(*prepare_hs_tuning)(struct mmc_host *host, struct mmc_card *card);
+
+	/* Execute HS tuning depending host driver */
+	int	(*execute_hs_tuning)(struct mmc_host *host, struct mmc_card *card);
+
 	/* Prepare switch to DDR during the HS400 init sequence */
 	int	(*hs400_prepare_ddr)(struct mmc_host *host);
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · Wenchao Chen

Added .prepare_hs_tuning and .execute_hs_tuning host callbacks to support host-specific tuning for SD high speed mode.

This certainly needs to be clarified more. Especially why it's needed for the sdhci-sprd variant.

Quoted 13 lines
---
 drivers/mmc/core/sd.c         |  12 ++++
 drivers/mmc/host/sdhci-sprd.c | 124 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h      |   6 ++
 3 files changed, 142 insertions(+)
drivers/mmc/core/sd.c +0 -0
index 246ce027ae0a..ac2da8f2fbce 100644

drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, · line 1525

Quoted 8 lines
drivers/mmc/core/sd.c +5 -0
@@ -1518,6 +1518,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
                 */
                mmc_set_clock(host, mmc_sd_get_max_clock(card));
 
+               if (host->ops->prepare_hs_tuning) {
+                       err = host->ops->prepare_hs_tuning(host, card);
+                       if (err)
+                               goto free_card;
+               }

Adding a new callback for this is a bit questionable, I think.

In the ->set_ios() callback, we could instead check MMC_TIMING_SD_HS and when the clock is updated, then also run a tuning sequence, right?

Quoted 5 lines
drivers/mmc/core/sd.c +1 -0
+
                /*
                 * Switch to wider bus (if supported).
                 */

drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, · line 1543

Quoted 9 lines
drivers/mmc/core/sd.c +6 -0
@@ -1529,6 +1535,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 
                        mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
                }
+
+               if (host->ops->execute_hs_tuning) {
+                       err = host->ops->execute_hs_tuning(host, card);
+                       if (err)
+                               goto free_card;
+               }

Similar to the above comment, in the ->set_ios() callback we could instead check MMC_TIMING_SD_HS when moving to MMC_BUS_WIDTH_4, then run a tuning sequence, right?

Quoted 16 lines
drivers/mmc/core/sd.c +0 -0
        }
 cont:
        if (!oldcard) {
drivers/mmc/host/sdhci-sprd.c +1 -0
index 7f4ee2e12735..5f365dcbb9c7 100644
@@ -9,6 +9,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/highmem.h>
 #include <linux/iopoll.h>
+#include <linux/mmc/mmc.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>

drivers/mmc/host/sdhci-sprd.c line 27

Quoted 5 lines
drivers/mmc/host/sdhci-sprd.c +2 -0
@@ -22,6 +23,9 @@
 #include "sdhci-pltfm.h"
 #include "mmc_hsq.h"
 
+#include "../core/mmc_ops.h"
+#include "../core/sd_ops.h"

No, this isn't how we include header files. Instead move the functions that you may need to include/linux/mmc/host.h.

Also, please split up core changes from host driver changes.

Quoted 30 lines
drivers/mmc/host/sdhci-sprd.c +11 -0
+
 /* SDHCI_ARGUMENT2 register high 16bit */
 #define SDHCI_SPRD_ARG2_STUFF          GENMASK(31, 16)
 
@@ -73,6 +77,11 @@
 #define SDHCI_SPRD_CLK_DEF_RATE                26000000
 #define SDHCI_SPRD_PHY_DLL_CLK         52000000
 
+#define SDHCI_SPRD_MAX_PHASE           0xff
+#define SDHCI_SPRD_CMD_DLY_MASK                GENMASK(15, 8)
+#define SDHCI_SPRD_POSRD_DLY_MASK      GENMASK(23, 16)
+#define SDHCI_SPRD_CPST_EN             GENMASK(27, 24)
+
 struct sdhci_sprd_host {
        u32 version;
        struct clk *clk_sdio;
@@ -86,6 +95,11 @@ struct sdhci_sprd_host {
        u32 phy_delay[MMC_TIMING_MMC_HS400 + 2];
 };
 
+enum sdhci_sprd_tuning_type {
+       SDHCI_SPRD_TUNING_SD_HS_CMD,
+       SDHCI_SPRD_TUNING_SD_HS_DATA,
+};
+
 struct sdhci_sprd_phy_cfg {
        const char *property;
        u8 timing;
@@ -533,6 +547,111 @@ static void sdhci_sprd_hs400_enhanced_strobe(struct mmc_host *mmc,
                     SDHCI_SPRD_REG_32_DLL_DLY);

drivers/mmc/host/sdhci-sprd.c static void sdhci_sprd_hs400_enhanced_strobe(struct mmc_host *mmc, · line 557

Quoted 10 lines
drivers/mmc/host/sdhci-sprd.c +8 -0
 }
 
+static int mmc_send_tuning_cmd(struct mmc_card *card)
+{
+       return mmc_send_status(card, NULL);
+}
+
+static int mmc_send_tuning_data(struct mmc_card *card)
+{
+       u8 status[64];

We use kmalloc-ed data for data transfers.

Quoted 59 lines
drivers/mmc/host/sdhci-sprd.c +59 -0
+
+       return mmc_sd_switch(card, 0, 0, 0, status);
+}
+
+static int sdhci_sprd_tuning(struct mmc_host *mmc, struct mmc_card *card,
+                       enum sdhci_sprd_tuning_type type)
+{
+       struct sdhci_host *host = mmc_priv(mmc);
+       struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host);
+       u32 *p = sprd_host->phy_delay;
+       int err = 0;
+       int i;
+       bool value;
+       int final_phase;
+       u32 dll_cfg, dll_dly;
+       int range_end = SDHCI_SPRD_MAX_PHASE;
+       int len = 0;
+       int count = 0;
+
+       sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
+
+       dll_cfg = sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_CFG);
+       dll_cfg &= ~SDHCI_SPRD_CPST_EN;
+       sdhci_writel(host, dll_cfg, SDHCI_SPRD_REG_32_DLL_CFG);
+
+       dll_dly = p[mmc->ios.timing];
+
+       for (i = 0; i <= SDHCI_SPRD_MAX_PHASE; i++) {
+               if (type == SDHCI_SPRD_TUNING_SD_HS_CMD) {
+                       dll_dly &= ~SDHCI_SPRD_CMD_DLY_MASK;
+                       dll_dly |= ((i << 8) & SDHCI_SPRD_CMD_DLY_MASK);
+               } else {
+                       dll_dly &= ~SDHCI_SPRD_POSRD_DLY_MASK;
+                       dll_dly |= ((i << 16) & SDHCI_SPRD_POSRD_DLY_MASK);
+               }
+
+               sdhci_writel(host, dll_dly, SDHCI_SPRD_REG_32_DLL_DLY);
+
+               if (type == SDHCI_SPRD_TUNING_SD_HS_CMD)
+                       value = !mmc_send_tuning_cmd(card);
+               else
+                       value = !mmc_send_tuning_data(card);
+
+               if (value) {
+                       dev_dbg(mmc_dev(host->mmc), "tuning ok: %d\n", i);
+                       count++;
+               } else {
+                       dev_dbg(mmc_dev(host->mmc), "tuning fail: %d\n", i);
+                       if (len < count) {
+                               len = count;
+                               range_end = i - 1;
+                               count = 0;
+                       }
+               }
+       }
+
+       if (!count) {
+               final_phase = 0;
+               dev_err(mmc_dev(host->mmc), "all tuning phase fail!\n");

drivers/mmc/host/sdhci-sprd.c static void sdhci_sprd_hs400_enhanced_strobe(struct mmc_host *mmc, · line 626

Quoted 10 lines
drivers/mmc/host/sdhci-sprd.c +10 -0
+               err = -EIO;
+               goto out;
+       }
+
+       if (count > len) {
+               len = count;
+               range_end = i - 1;
+       }
+
+       final_phase = range_end - (len - 1) / 2;

The whole len, count, range_end, final_phase things look rather messy. Please have a look and try to clean up that part a bit, I am sure it can be done, somehow.

drivers/mmc/host/sdhci-sprd.c static void sdhci_sprd_hs400_enhanced_strobe(struct mmc_host *mmc, · line 637

Quoted 11 lines
drivers/mmc/host/sdhci-sprd.c +11 -0
+
+       if (type == SDHCI_SPRD_TUNING_SD_HS_CMD) {
+               p[mmc->ios.timing] &= ~SDHCI_SPRD_CMD_DLY_MASK;
+               p[mmc->ios.timing] |= ((final_phase << 8) & SDHCI_SPRD_CMD_DLY_MASK);
+       } else {
+               p[mmc->ios.timing] &= ~(SDHCI_SPRD_POSRD_DLY_MASK);
+               p[mmc->ios.timing] |= ((final_phase << 16) & SDHCI_SPRD_POSRD_DLY_MASK);
+       }
+
+       dev_info(mmc_dev(host->mmc), "the best step %d, phase 0x%02x, delay value 0x%08x\n",
+                       final_phase, final_phase, p[mmc->ios.timing]);

Does this really deserve to be a dev_info? Looks like a dev_dbg to me, no?

Quoted 39 lines
drivers/mmc/host/sdhci-sprd.c +22 -0
+
+out:
+       sdhci_writel(host, p[mmc->ios.timing], SDHCI_SPRD_REG_32_DLL_DLY);
+
+       return err;
+}
+
+static int sdhci_sprd_prepare_hs_cmd_tuning(struct mmc_host *mmc, struct mmc_card *card)
+{
+       return sdhci_sprd_tuning(mmc, card, SDHCI_SPRD_TUNING_SD_HS_CMD);
+}
+
+static int sdhci_sprd_execute_hs_data_tuning(struct mmc_host *mmc, struct mmc_card *card)
+{
+       return sdhci_sprd_tuning(mmc, card, SDHCI_SPRD_TUNING_SD_HS_DATA);
+}
+
 static void sdhci_sprd_phy_param_parse(struct sdhci_sprd_host *sprd_host,
                                       struct device_node *np)
 {
@@ -577,6 +696,11 @@ static int sdhci_sprd_probe(struct platform_device *pdev)
        host->mmc_host_ops.request = sdhci_sprd_request;
        host->mmc_host_ops.hs400_enhanced_strobe =
                sdhci_sprd_hs400_enhanced_strobe;
+       host->mmc_host_ops.prepare_hs_tuning =
+               sdhci_sprd_prepare_hs_cmd_tuning;
+       host->mmc_host_ops.execute_hs_tuning =
+               sdhci_sprd_execute_hs_data_tuning;
+
        /*
         * We can not use the standard ops to change and detect the voltage
         * signal for Spreadtrum SD host controller, since our voltage regulator
include/linux/mmc/host.h +0 -0
index 461d1543893b..13cf894b9e3c 100644
@@ -184,6 +184,12 @@ struct mmc_host_ops {
        /* Execute HS400 tuning depending host driver */
        int     (*execute_hs400_tuning)(struct mmc_host *host, struct mmc_card *card);

include/linux/mmc/host.h struct mmc_host_ops { · line 195

Quoted 10 lines
include/linux/mmc/host.h +6 -0
 
+       /* Prepare HS tuning depending host driver */
+       int     (*prepare_hs_tuning)(struct mmc_host *host, struct mmc_card *card);
+
+       /* Execute HS tuning depending host driver */
+       int     (*execute_hs_tuning)(struct mmc_host *host, struct mmc_card *card);
+
        /* Prepare switch to DDR during the HS400 init sequence */
        int     (*hs400_prepare_ddr)(struct mmc_host *host);
 

Kind regards
Uffe

#2 lore raw
Quoted 10 lines · Ulf Hansson
Quoted 4 lines · Wenchao Chen

Added .prepare_hs_tuning and .execute_hs_tuning host callbacks to support host-specific tuning for SD high speed mode.

This certainly needs to be clarified more. Especially why it's needed for the sdhci-sprd variant.

First of all, Unisoc's IC provides cmd delay and read delay to ensure that the host can
get the correct data. However, according to SD Spec, there is no need to do tuning in
high speed mode, but with the development of chip processes, it is more and more difficult
to find a suitable delay to cover all the chips. Therefore, we need SD high speed mode online tuning.

Quoted 24 lines
Quoted 13 lines
---
 drivers/mmc/core/sd.c         |  12 ++++
 drivers/mmc/host/sdhci-sprd.c | 124 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h      |   6 ++
 3 files changed, 142 insertions(+)
drivers/mmc/core/sd.c +0 -0
index 246ce027ae0a..ac2da8f2fbce 100644

drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, · line 1525

Quoted 8 lines
drivers/mmc/core/sd.c +5 -0
@@ -1518,6 +1518,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
                 */
                mmc_set_clock(host, mmc_sd_get_max_clock(card));
 
+               if (host->ops->prepare_hs_tuning) {
+                       err = host->ops->prepare_hs_tuning(host, card);
+                       if (err)
+                               goto free_card;
+               }

Adding a new callback for this is a bit questionable, I think.

Quoted 3 lines

In the ->set_ios() callback, we could instead check MMC_TIMING_SD_HS and when the clock is updated, then also run a tuning sequence, right?

Yeah, I'll try.

Quoted 6 lines
Quoted 6 lines
drivers/mmc/core/sd.c +1 -0
+
                /*
                 * Switch to wider bus (if supported).
                 */
@@ -1529,6 +1535,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 
Quoted 13 lines

drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, · line 1543

Quoted 8 lines
drivers/mmc/core/sd.c +6 -0
                        mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
                }
+
+               if (host->ops->execute_hs_tuning) {
+                       err = host->ops->execute_hs_tuning(host, card);
+                       if (err)
+                               goto free_card;
+               }

Similar to the above comment, in the ->set_ios() callback we could instead check MMC_TIMING_SD_HS when moving to MMC_BUS_WIDTH_4, then run a tuning sequence, right?

ibid.

Quoted 19 lines
Quoted 19 lines
drivers/mmc/core/sd.c +0 -0
        }
 cont:
        if (!oldcard) {
drivers/mmc/host/sdhci-sprd.c +1 -0
index 7f4ee2e12735..5f365dcbb9c7 100644
@@ -9,6 +9,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/highmem.h>
 #include <linux/iopoll.h>
+#include <linux/mmc/mmc.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -22,6 +23,9 @@
 #include "sdhci-pltfm.h"
 #include "mmc_hsq.h"
 
Quoted 8 lines

drivers/mmc/host/sdhci-sprd.c line 27

Quoted 2 lines
drivers/mmc/host/sdhci-sprd.c +2 -0
+#include "../core/mmc_ops.h"
+#include "../core/sd_ops.h"

No, this isn't how we include header files. Instead move the functions that you may need to include/linux/mmc/host.h.

Also, please split up core changes from host driver changes.

I'll fix it in the next version.

Quoted 32 lines
Quoted 32 lines
drivers/mmc/host/sdhci-sprd.c +11 -0
+
 /* SDHCI_ARGUMENT2 register high 16bit */
 #define SDHCI_SPRD_ARG2_STUFF          GENMASK(31, 16)
 
@@ -73,6 +77,11 @@
 #define SDHCI_SPRD_CLK_DEF_RATE                26000000
 #define SDHCI_SPRD_PHY_DLL_CLK         52000000
 
+#define SDHCI_SPRD_MAX_PHASE           0xff
+#define SDHCI_SPRD_CMD_DLY_MASK                GENMASK(15, 8)
+#define SDHCI_SPRD_POSRD_DLY_MASK      GENMASK(23, 16)
+#define SDHCI_SPRD_CPST_EN             GENMASK(27, 24)
+
 struct sdhci_sprd_host {
        u32 version;
        struct clk *clk_sdio;
@@ -86,6 +95,11 @@ struct sdhci_sprd_host {
        u32 phy_delay[MMC_TIMING_MMC_HS400 + 2];
 };
 
+enum sdhci_sprd_tuning_type {
+       SDHCI_SPRD_TUNING_SD_HS_CMD,
+       SDHCI_SPRD_TUNING_SD_HS_DATA,
+};
+
 struct sdhci_sprd_phy_cfg {
        const char *property;
        u8 timing;
@@ -533,6 +547,111 @@ static void sdhci_sprd_hs400_enhanced_strobe(struct mmc_host *mmc,
                     SDHCI_SPRD_REG_32_DLL_DLY);
 }
 
Quoted 11 lines

drivers/mmc/host/sdhci-sprd.c static void sdhci_sprd_hs400_enhanced_strobe(struct mmc_host *mmc, · line 557

Quoted 8 lines
drivers/mmc/host/sdhci-sprd.c +8 -0
+static int mmc_send_tuning_cmd(struct mmc_card *card)
+{
+       return mmc_send_status(card, NULL);
+}
+
+static int mmc_send_tuning_data(struct mmc_card *card)
+{
+       u8 status[64];

We use kmalloc-ed data for data transfers.

Why is it better to use kmalloc-ed data?

Quoted 65 lines
Quoted 65 lines
drivers/mmc/host/sdhci-sprd.c +65 -0
+
+       return mmc_sd_switch(card, 0, 0, 0, status);
+}
+
+static int sdhci_sprd_tuning(struct mmc_host *mmc, struct mmc_card *card,
+                       enum sdhci_sprd_tuning_type type)
+{
+       struct sdhci_host *host = mmc_priv(mmc);
+       struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host);
+       u32 *p = sprd_host->phy_delay;
+       int err = 0;
+       int i;
+       bool value;
+       int final_phase;
+       u32 dll_cfg, dll_dly;
+       int range_end = SDHCI_SPRD_MAX_PHASE;
+       int len = 0;
+       int count = 0;
+
+       sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
+
+       dll_cfg = sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_CFG);
+       dll_cfg &= ~SDHCI_SPRD_CPST_EN;
+       sdhci_writel(host, dll_cfg, SDHCI_SPRD_REG_32_DLL_CFG);
+
+       dll_dly = p[mmc->ios.timing];
+
+       for (i = 0; i <= SDHCI_SPRD_MAX_PHASE; i++) {
+               if (type == SDHCI_SPRD_TUNING_SD_HS_CMD) {
+                       dll_dly &= ~SDHCI_SPRD_CMD_DLY_MASK;
+                       dll_dly |= ((i << 8) & SDHCI_SPRD_CMD_DLY_MASK);
+               } else {
+                       dll_dly &= ~SDHCI_SPRD_POSRD_DLY_MASK;
+                       dll_dly |= ((i << 16) & SDHCI_SPRD_POSRD_DLY_MASK);
+               }
+
+               sdhci_writel(host, dll_dly, SDHCI_SPRD_REG_32_DLL_DLY);
+
+               if (type == SDHCI_SPRD_TUNING_SD_HS_CMD)
+                       value = !mmc_send_tuning_cmd(card);
+               else
+                       value = !mmc_send_tuning_data(card);
+
+               if (value) {
+                       dev_dbg(mmc_dev(host->mmc), "tuning ok: %d\n", i);
+                       count++;
+               } else {
+                       dev_dbg(mmc_dev(host->mmc), "tuning fail: %d\n", i);
+                       if (len < count) {
+                               len = count;
+                               range_end = i - 1;
+                               count = 0;
+                       }
+               }
+       }
+
+       if (!count) {
+               final_phase = 0;
+               dev_err(mmc_dev(host->mmc), "all tuning phase fail!\n");
+               err = -EIO;
+               goto out;
+       }
+
+       if (count > len) {
+               len = count;
Quoted 9 lines

drivers/mmc/host/sdhci-sprd.c static void sdhci_sprd_hs400_enhanced_strobe(struct mmc_host *mmc, · line 626

Quoted 4 lines
drivers/mmc/host/sdhci-sprd.c +4 -0
+               range_end = i - 1;
+       }
+
+       final_phase = range_end - (len - 1) / 2;

The whole len, count, range_end, final_phase things look rather messy. Please have a look and try to clean up that part a bit, I am sure it can be done, somehow.

Indeed, it looks messy. I'll fix it in the next version.

Quoted 5 lines
Quoted 5 lines
drivers/mmc/host/sdhci-sprd.c +5 -0
+
+       if (type == SDHCI_SPRD_TUNING_SD_HS_CMD) {
+               p[mmc->ios.timing] &= ~SDHCI_SPRD_CMD_DLY_MASK;
+               p[mmc->ios.timing] |= ((final_phase << 8) & SDHCI_SPRD_CMD_DLY_MASK);
+       } else {
Quoted 9 lines

drivers/mmc/host/sdhci-sprd.c static void sdhci_sprd_hs400_enhanced_strobe(struct mmc_host *mmc, · line 637

Quoted 6 lines
drivers/mmc/host/sdhci-sprd.c +6 -0
+               p[mmc->ios.timing] &= ~(SDHCI_SPRD_POSRD_DLY_MASK);
+               p[mmc->ios.timing] |= ((final_phase << 16) & SDHCI_SPRD_POSRD_DLY_MASK);
+       }
+
+       dev_info(mmc_dev(host->mmc), "the best step %d, phase 0x%02x, delay value 0x%08x\n",
+                       final_phase, final_phase, p[mmc->ios.timing]);

Does this really deserve to be a dev_info? Looks like a dev_dbg to me, no?

Yeah. You're right.
I'll fix it in the next version.

Quoted 52 lines
Quoted 39 lines
drivers/mmc/host/sdhci-sprd.c +22 -0
+
+out:
+       sdhci_writel(host, p[mmc->ios.timing], SDHCI_SPRD_REG_32_DLL_DLY);
+
+       return err;
+}
+
+static int sdhci_sprd_prepare_hs_cmd_tuning(struct mmc_host *mmc, struct mmc_card *card)
+{
+       return sdhci_sprd_tuning(mmc, card, SDHCI_SPRD_TUNING_SD_HS_CMD);
+}
+
+static int sdhci_sprd_execute_hs_data_tuning(struct mmc_host *mmc, struct mmc_card *card)
+{
+       return sdhci_sprd_tuning(mmc, card, SDHCI_SPRD_TUNING_SD_HS_DATA);
+}
+
 static void sdhci_sprd_phy_param_parse(struct sdhci_sprd_host *sprd_host,
                                       struct device_node *np)
 {
@@ -577,6 +696,11 @@ static int sdhci_sprd_probe(struct platform_device *pdev)
        host->mmc_host_ops.request = sdhci_sprd_request;
        host->mmc_host_ops.hs400_enhanced_strobe =
                sdhci_sprd_hs400_enhanced_strobe;
+       host->mmc_host_ops.prepare_hs_tuning =
+               sdhci_sprd_prepare_hs_cmd_tuning;
+       host->mmc_host_ops.execute_hs_tuning =
+               sdhci_sprd_execute_hs_data_tuning;
+
        /*
         * We can not use the standard ops to change and detect the voltage
         * signal for Spreadtrum SD host controller, since our voltage regulator
include/linux/mmc/host.h +0 -0
index 461d1543893b..13cf894b9e3c 100644
@@ -184,6 +184,12 @@ struct mmc_host_ops {
        /* Execute HS400 tuning depending host driver */
        int     (*execute_hs400_tuning)(struct mmc_host *host, struct mmc_card *card);

include/linux/mmc/host.h struct mmc_host_ops { · line 195

Quoted 10 lines
include/linux/mmc/host.h +6 -0
 
+       /* Prepare HS tuning depending host driver */
+       int     (*prepare_hs_tuning)(struct mmc_host *host, struct mmc_card *card);
+
+       /* Execute HS tuning depending host driver */
+       int     (*execute_hs_tuning)(struct mmc_host *host, struct mmc_card *card);
+
        /* Prepare switch to DDR during the HS400 init sequence */
        int     (*hs400_prepare_ddr)(struct mmc_host *host);
 

Kind regards
Uffe

#3 lore raw
Quoted 13 lines · Wenchao Chen
Quoted 10 lines · Ulf Hansson
Quoted 4 lines · Wenchao Chen

Added .prepare_hs_tuning and .execute_hs_tuning host callbacks to support host-specific tuning for SD high speed mode.

This certainly needs to be clarified more. Especially why it's needed for the sdhci-sprd variant.

Quoted 8 lines

First of all, Unisoc's IC provides cmd delay and read delay to ensure that the host can
get the correct data. However, according to SD Spec, there is no need to do tuning in
high speed mode, but with the development of chip processes, it is more and more difficult
to find a suitable delay to cover all the chips. Therefore, we need SD high speed mode online tuning.

Thanks for sharing this information - and please add some of this in the commit message next time.

[...]

Quoted 8 lines
Quoted 6 lines

drivers/mmc/host/sdhci-sprd.c static void sdhci_sprd_hs400_enhanced_strobe(struct mmc_host *mmc, · line 557

Quoted 3 lines
drivers/mmc/host/sdhci-sprd.c +3 -0
+static int mmc_send_tuning_data(struct mmc_card *card)
+{
+       u8 status[64];

We use kmalloc-ed data for data transfers.

Why is it better to use kmalloc-ed data?

If you use DMA for example. From the core point of view, all data should be kmalloc-ed, if it's a data transfer and possibility that that DMA is used. Hence, it seems reasonable to conform to this behaviour when using this helper function from the core.

[...]

Kind regards
Uffe

#4 lore raw
In reply to Wenchao Chen
kernel test robot noticed the following build errors:

Hi Wenchao,

kernel test robot noticed the following build errors:

[auto build test ERROR on ulf-hansson-mmc-mirror/next]
[also build test ERROR on linus/master v6.5-rc5 next-20230809] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wenchao-Chen/mmc-core-Add-host-specific-tuning-support-for-SD-HS-mode/20230809-133203
base:   https://git.linaro.org/people/ulf.hansson/mmc-mirror.git next
patch link:    https://lore.kernel.org/r/20230809052952.323-1-wenchao.chen%40unisoc.com
patch subject: [PATCH] mmc: core: Add host specific tuning support for SD HS mode
config: arm-randconfig-r064-20230809 (https://download.01.org/0day-ci/archive/20230810/[email protected]/config)
compiler: arm-linux-gnueabi-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230810/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "mmc_sd_switch" [drivers/mmc/host/sdhci-sprd.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki