Skip to contentSkip to conversation

mmc: sdhci-sirf: fix the tuning count in platform_execute_tuning

PATCH New Barry Song 2 participants 4 messages Apr 27, 2015 – May 5, 2015

Subsystems (2)
lore
Share & tools
lore

Barry Song

author
#0 lore raw

PATCH 1/2 mmc: sdhci-sirf: fix the tuning count in platform_execute_tuning

From: Weijun Yang <[email protected]>

hardware has 16bit to record the tuning count, so fix it to 16384. at the same time, tuned_phases[SIRF_TUNING_COUNT] is useless as the array is never used, so move it to a variant.

---
 drivers/mmc/host/sdhci-sirf.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci-sirf.c +5 -4
index 32848eb..2201f76 100644
@@ -17,7 +17,7 @@
 
 #define SDHCI_CLK_DELAY_SETTING 0x4C
 #define SDHCI_SIRF_8BITBUS BIT(3)
-#define SIRF_TUNING_COUNT 128
+#define SIRF_TUNING_COUNT 16384
 
 struct sdhci_sirf_priv {
 	int gpio_cd;
@@ -46,7 +46,7 @@ static void sdhci_sirf_set_bus_width(struct sdhci_host *host, int width)
 static int sdhci_sirf_execute_tuning(struct sdhci_host *host, u32 opcode)
 {
 	int tuning_seq_cnt = 3;
-	u8 phase, tuned_phases[SIRF_TUNING_COUNT];
+	int phase;
 	u8 tuned_phase_cnt = 0;
 	int rc = 0, longest_range = 0;
 	int start = -1, end = 0, tuning_value = -1, range = 0;
@@ -58,6 +58,7 @@ static int sdhci_sirf_execute_tuning(struct sdhci_host *host, u32 opcode)
 
 retry:
 	phase = 0;
+	tuned_phase_cnt = 0;
 	do {
 		sdhci_writel(host,
 			clock_setting | phase,
@@ -65,7 +66,7 @@ retry:
 
 		if (!mmc_send_tuning(mmc)) {
 			/* Tuning is successful at this tuning point */
-			tuned_phases[tuned_phase_cnt++] = phase;
+			tuned_phase_cnt++;
 			dev_dbg(mmc_dev(mmc), "%s: Found good phase = %d\n",
 				 mmc_hostname(mmc), phase);
 			if (start == -1)
@@ -85,7 +86,7 @@ retry:
 			start = -1;
 			end = range = 0;
 		}
-	} while (++phase < ARRAY_SIZE(tuned_phases));
+	} while (++phase < SIRF_TUNING_COUNT);
 
 	if (tuned_phase_cnt && tuning_value > 0) {
 		/*
Signature · 1 line
2.3.5
author
#1 lore raw

PATCH 2/2 mmc: sdhci-sirf: fake version and capbility registers

From: Weijun Yang <[email protected]>

chips have some issues for version and capbility registers, here we fake them.

---
 drivers/mmc/host/Kconfig      |  1 +
 drivers/mmc/host/sdhci-sirf.c | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
drivers/mmc/host/Kconfig +1 -0
index b1f837e..d5e107b 100644
@@ -219,6 +219,7 @@ config MMC_SDHCI_SIRF
 	tristate "SDHCI support on CSR SiRFprimaII and SiRFmarco SoCs"
 	depends on ARCH_SIRF
 	depends on MMC_SDHCI_PLTFM
+	select MMC_SDHCI_IO_ACCESSORS
 	help
 	  This selects the SDHCI support for SiRF System-on-Chip devices.
 
drivers/mmc/host/sdhci-sirf.c +35 -0
index 2201f76..0110bae 100644
@@ -43,6 +43,39 @@ static void sdhci_sirf_set_bus_width(struct sdhci_host *host, int width)
 	sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
 }
 
+static u32 sdhci_sirf_readl_le(struct sdhci_host *host, int reg)
+{
+	u32 val = readl(host->ioaddr + reg);
+
+	if (unlikely((reg == SDHCI_CAPABILITIES_1) &&
+			(host->mmc->caps & MMC_CAP_UHS_SDR50))) {
+		/* fake CAP_1 register */
+		val = SDHCI_SUPPORT_SDR50 | SDHCI_USE_SDR50_TUNING;
+	}
+
+	if (unlikely(reg == SDHCI_SLOT_INT_STATUS)) {
+		u32 prss = val;
+		/* fake chips as V3.0 host conreoller */
+		prss &= ~(0xFF << 16);
+		val = prss | (SDHCI_SPEC_300 << 16);
+	}
+	return val;
+}
+
+static u16 sdhci_sirf_readw_le(struct sdhci_host *host, int reg)
+{
+	u16 ret = 0;
+
+	ret = readw(host->ioaddr + reg);
+
+	if (unlikely(reg == SDHCI_HOST_VERSION)) {
+		ret = readw(host->ioaddr + SDHCI_HOST_VERSION);
+		ret |= SDHCI_SPEC_300;
+	}
+
+	return ret;
+}
+
 static int sdhci_sirf_execute_tuning(struct sdhci_host *host, u32 opcode)
 {
 	int tuning_seq_cnt = 3;
@@ -113,6 +146,8 @@ retry:
 }
 
 static struct sdhci_ops sdhci_sirf_ops = {
+	.read_l = sdhci_sirf_readl_le,
+	.read_w = sdhci_sirf_readw_le,
 	.platform_execute_tuning = sdhci_sirf_execute_tuning,
 	.set_clock = sdhci_set_clock,
 	.get_max_clock	= sdhci_pltfm_clk_get_max_clock,
Signature · 1 line
2.3.5
Applied
#2 lore raw

PATCH 2/2 mmc: sdhci-sirf: fake version and capbility registers

Quoted 7 lines · Barry Song

From: Weijun Yang <[email protected]>

chips have some issues for version and capbility registers, here we fake them.

Thanks, applied!

Kind regards
Uffe

Quoted 73 lines
---
 drivers/mmc/host/Kconfig      |  1 +
 drivers/mmc/host/sdhci-sirf.c | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
drivers/mmc/host/Kconfig +1 -0
index b1f837e..d5e107b 100644
@@ -219,6 +219,7 @@ config MMC_SDHCI_SIRF
        tristate "SDHCI support on CSR SiRFprimaII and SiRFmarco SoCs"
        depends on ARCH_SIRF
        depends on MMC_SDHCI_PLTFM
+       select MMC_SDHCI_IO_ACCESSORS
        help
          This selects the SDHCI support for SiRF System-on-Chip devices.
 
drivers/mmc/host/sdhci-sirf.c +35 -1
index 2201f76..0110bae 100644
@@ -43,6 +43,39 @@ static void sdhci_sirf_set_bus_width(struct sdhci_host *host, int width)
        sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
 }
 
+static u32 sdhci_sirf_readl_le(struct sdhci_host *host, int reg)
+{
+       u32 val = readl(host->ioaddr + reg);
+
+       if (unlikely((reg == SDHCI_CAPABILITIES_1) &&
+                       (host->mmc->caps & MMC_CAP_UHS_SDR50))) {
+               /* fake CAP_1 register */
+               val = SDHCI_SUPPORT_SDR50 | SDHCI_USE_SDR50_TUNING;
+       }
+
+       if (unlikely(reg == SDHCI_SLOT_INT_STATUS)) {
+               u32 prss = val;
+               /* fake chips as V3.0 host conreoller */
+               prss &= ~(0xFF << 16);
+               val = prss | (SDHCI_SPEC_300 << 16);
+       }
+       return val;
+}
+
+static u16 sdhci_sirf_readw_le(struct sdhci_host *host, int reg)
+{
+       u16 ret = 0;
+
+       ret = readw(host->ioaddr + reg);
+
+       if (unlikely(reg == SDHCI_HOST_VERSION)) {
+               ret = readw(host->ioaddr + SDHCI_HOST_VERSION);
+               ret |= SDHCI_SPEC_300;
+       }
+
+       return ret;
+}
+
 static int sdhci_sirf_execute_tuning(struct sdhci_host *host, u32 opcode)
 {
        int tuning_seq_cnt = 3;
@@ -113,6 +146,8 @@ retry:
 }
 
 static struct sdhci_ops sdhci_sirf_ops = {
+       .read_l = sdhci_sirf_readl_le,
+       .read_w = sdhci_sirf_readw_le,
        .platform_execute_tuning = sdhci_sirf_execute_tuning,
        .set_clock = sdhci_set_clock,
        .get_max_clock  = sdhci_pltfm_clk_get_max_clock,
--

2.3.5

Applied
#3 lore raw

PATCH 1/2 mmc: sdhci-sirf: fix the tuning count in platform_execute_tuning

In reply to Barry Song
Quoted 8 lines · Barry Song

From: Weijun Yang <[email protected]>

hardware has 16bit to record the tuning count, so fix it to 16384. at the same time, tuned_phases[SIRF_TUNING_COUNT] is useless as the array is never used, so move it to a variant.

Thanks, applied!

Kind regards
Uffe

Quoted 55 lines
---
 drivers/mmc/host/sdhci-sirf.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci-sirf.c +5 -5
index 32848eb..2201f76 100644
@@ -17,7 +17,7 @@
 
 #define SDHCI_CLK_DELAY_SETTING 0x4C
 #define SDHCI_SIRF_8BITBUS BIT(3)
-#define SIRF_TUNING_COUNT 128
+#define SIRF_TUNING_COUNT 16384
 
 struct sdhci_sirf_priv {
        int gpio_cd;
@@ -46,7 +46,7 @@ static void sdhci_sirf_set_bus_width(struct sdhci_host *host, int width)
 static int sdhci_sirf_execute_tuning(struct sdhci_host *host, u32 opcode)
 {
        int tuning_seq_cnt = 3;
-       u8 phase, tuned_phases[SIRF_TUNING_COUNT];
+       int phase;
        u8 tuned_phase_cnt = 0;
        int rc = 0, longest_range = 0;
        int start = -1, end = 0, tuning_value = -1, range = 0;
@@ -58,6 +58,7 @@ static int sdhci_sirf_execute_tuning(struct sdhci_host *host, u32 opcode)
 
 retry:
        phase = 0;
+       tuned_phase_cnt = 0;
        do {
                sdhci_writel(host,
                        clock_setting | phase,
@@ -65,7 +66,7 @@ retry:
 
                if (!mmc_send_tuning(mmc)) {
                        /* Tuning is successful at this tuning point */
-                       tuned_phases[tuned_phase_cnt++] = phase;
+                       tuned_phase_cnt++;
                        dev_dbg(mmc_dev(mmc), "%s: Found good phase = %d\n",
                                 mmc_hostname(mmc), phase);
                        if (start == -1)
@@ -85,7 +86,7 @@ retry:
                        start = -1;
                        end = range = 0;
                }
-       } while (++phase < ARRAY_SIZE(tuned_phases));
+       } while (++phase < SIRF_TUNING_COUNT);
 
        if (tuned_phase_cnt && tuning_value > 0) {
                /*
--

2.3.5