Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: sdhci: track whether preset mode is currently enabled in hardware

Track whether preset mode is currently enabled in hardware, and use that
when making decisions elsewhere in the code rather than reading the
register and checking the bit.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Tested-by: Markus Pargmann <mpa@pengutronix.de>
Tested-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <chris@printf.net>

authored by

Russell King and committed by
Chris Ball
da91a8f9 24fbb3ca

+27 -18
+26 -18
drivers/mmc/host/sdhci.c
··· 205 205 206 206 host->ops->reset(host, mask); 207 207 208 - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { 209 - if ((host->ops->enable_dma) && (mask & SDHCI_RESET_ALL)) 210 - host->ops->enable_dma(host); 208 + if (mask & SDHCI_RESET_ALL) { 209 + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { 210 + if (host->ops->enable_dma) 211 + host->ops->enable_dma(host); 212 + } 213 + 214 + /* Resetting the controller clears many */ 215 + host->preset_enabled = false; 211 216 } 212 217 } 213 218 ··· 1131 1126 return; 1132 1127 1133 1128 if (host->version >= SDHCI_SPEC_300) { 1134 - if (sdhci_readw(host, SDHCI_HOST_CONTROL2) & 1135 - SDHCI_CTRL_PRESET_VAL_ENABLE) { 1129 + if (host->preset_enabled) { 1136 1130 u16 pre_val; 1137 1131 1138 1132 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); ··· 1497 1493 (ios->timing == MMC_TIMING_UHS_SDR25)) 1498 1494 ctrl |= SDHCI_CTRL_HISPD; 1499 1495 1500 - ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1501 - if (!(ctrl_2 & SDHCI_CTRL_PRESET_VAL_ENABLE)) { 1496 + if (!host->preset_enabled) { 1502 1497 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); 1503 1498 /* 1504 1499 * We only need to set Driver Strength if the 1505 1500 * preset value enable is not set. 1506 1501 */ 1502 + ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1507 1503 ctrl_2 &= ~SDHCI_CTRL_DRV_TYPE_MASK; 1508 1504 if (ios->drv_type == MMC_SET_DRIVER_TYPE_A) 1509 1505 ctrl_2 |= SDHCI_CTRL_DRV_TYPE_A; ··· 2022 2018 2023 2019 static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable) 2024 2020 { 2025 - u16 ctrl; 2026 - 2027 2021 /* Host Controller v3.00 defines preset value registers */ 2028 2022 if (host->version < SDHCI_SPEC_300) 2029 2023 return; 2030 - 2031 - ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 2032 2024 2033 2025 /* 2034 2026 * We only enable or disable Preset Value if they are not already 2035 2027 * enabled or disabled respectively. Otherwise, we bail out. 2036 2028 */ 2037 - if (enable && !(ctrl & SDHCI_CTRL_PRESET_VAL_ENABLE)) { 2038 - ctrl |= SDHCI_CTRL_PRESET_VAL_ENABLE; 2029 + if (host->preset_enabled != enable) { 2030 + u16 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 2031 + 2032 + if (enable) 2033 + ctrl |= SDHCI_CTRL_PRESET_VAL_ENABLE; 2034 + else 2035 + ctrl &= ~SDHCI_CTRL_PRESET_VAL_ENABLE; 2036 + 2039 2037 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 2040 - host->flags |= SDHCI_PV_ENABLED; 2041 - } else if (!enable && (ctrl & SDHCI_CTRL_PRESET_VAL_ENABLE)) { 2042 - ctrl &= ~SDHCI_CTRL_PRESET_VAL_ENABLE; 2043 - sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 2044 - host->flags &= ~SDHCI_PV_ENABLED; 2038 + 2039 + if (enable) 2040 + host->flags |= SDHCI_PV_ENABLED; 2041 + else 2042 + host->flags &= ~SDHCI_PV_ENABLED; 2043 + 2044 + host->preset_enabled = enable; 2045 2045 } 2046 2046 } 2047 2047
+1
include/linux/mmc/sdhci.h
··· 143 143 144 144 bool runtime_suspended; /* Host is runtime suspended */ 145 145 bool bus_on; /* Bus power prevents runtime suspend */ 146 + bool preset_enabled; /* Preset is enabled */ 146 147 147 148 struct mmc_request *mrq; /* Current request */ 148 149 struct mmc_command *cmd; /* Current command */