aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/mmc/host/sdhci.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 447eef8217c7..47055f3f01b8 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -1823,7 +1823,6 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1823 struct sdhci_host *host = mmc_priv(mmc); 1823 struct sdhci_host *host = mmc_priv(mmc);
1824 u16 ctrl; 1824 u16 ctrl;
1825 int tuning_loop_counter = MAX_TUNING_LOOP; 1825 int tuning_loop_counter = MAX_TUNING_LOOP;
1826 unsigned long timeout;
1827 int err = 0; 1826 int err = 0;
1828 unsigned long flags; 1827 unsigned long flags;
1829 1828
@@ -1882,14 +1881,10 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1882 * Issue CMD19 repeatedly till Execute Tuning is set to 0 or the number 1881 * Issue CMD19 repeatedly till Execute Tuning is set to 0 or the number
1883 * of loops reaches 40 times or a timeout of 150ms occurs. 1882 * of loops reaches 40 times or a timeout of 150ms occurs.
1884 */ 1883 */
1885 timeout = 150;
1886 do { 1884 do {
1887 struct mmc_command cmd = {0}; 1885 struct mmc_command cmd = {0};
1888 struct mmc_request mrq = {NULL}; 1886 struct mmc_request mrq = {NULL};
1889 1887
1890 if (!tuning_loop_counter && !timeout)
1891 break;
1892
1893 cmd.opcode = opcode; 1888 cmd.opcode = opcode;
1894 cmd.arg = 0; 1889 cmd.arg = 0;
1895 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 1890 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
@@ -1897,6 +1892,9 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1897 cmd.data = NULL; 1892 cmd.data = NULL;
1898 cmd.error = 0; 1893 cmd.error = 0;
1899 1894
1895 if (tuning_loop_counter-- == 0)
1896 break;
1897
1900 mrq.cmd = &cmd; 1898 mrq.cmd = &cmd;
1901 host->mrq = &mrq; 1899 host->mrq = &mrq;
1902 1900
@@ -1954,8 +1952,6 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1954 host->tuning_done = 0; 1952 host->tuning_done = 0;
1955 1953
1956 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1954 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1957 tuning_loop_counter--;
1958 timeout--;
1959 1955
1960 /* eMMC spec does not require a delay between tuning cycles */ 1956 /* eMMC spec does not require a delay between tuning cycles */
1961 if (opcode == MMC_SEND_TUNING_BLOCK) 1957 if (opcode == MMC_SEND_TUNING_BLOCK)
@@ -1966,17 +1962,15 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1966 * The Host Driver has exhausted the maximum number of loops allowed, 1962 * The Host Driver has exhausted the maximum number of loops allowed,
1967 * so use fixed sampling frequency. 1963 * so use fixed sampling frequency.
1968 */ 1964 */
1969 if (!tuning_loop_counter || !timeout) { 1965 if (tuning_loop_counter < 0) {
1970 ctrl &= ~SDHCI_CTRL_TUNED_CLK; 1966 ctrl &= ~SDHCI_CTRL_TUNED_CLK;
1971 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 1967 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1968 }
1969 if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) {
1970 pr_info(DRIVER_NAME ": Tuning procedure"
1971 " failed, falling back to fixed sampling"
1972 " clock\n");
1972 err = -EIO; 1973 err = -EIO;
1973 } else {
1974 if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) {
1975 pr_info(DRIVER_NAME ": Tuning procedure"
1976 " failed, falling back to fixed sampling"
1977 " clock\n");
1978 err = -EIO;
1979 }
1980 } 1974 }
1981 1975
1982out: 1976out: