Skip to content

Commit 92a2173

Browse files
Veerabhadrarao BadigantiUlf Hansson
authored andcommitted
mmc: sdhci-msm: Use internal voltage control
On qcom SD host controllers voltage switching be done after the HW is ready for it. The HW informs its readiness through power irq. The voltage switching should happen only then. Use the internal voltage switching and then control the voltage switching using power irq. IO-bus supply of eMMC would be kept always-on. So set the load for this supply to configure it in LPM when eMMC is suspend state and in HPM when eMMC is active. Co-developed-by: Asutosh Das <asutoshd@codeaurora.org> Signed-off-by: Asutosh Das <asutoshd@codeaurora.org> Co-developed-by: Vijay Viswanath <vviswana@codeaurora.org> Signed-off-by: Vijay Viswanath <vviswana@codeaurora.org> Co-developed-by: Veerabhadrarao Badiganti <vbadigan@codeaurora.org> Signed-off-by: Veerabhadrarao Badiganti <vbadigan@codeaurora.org> Link: https://lore.kernel.org/r/1592919288-1020-4-git-send-email-vbadigan@codeaurora.org Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent ed54ef9 commit 92a2173

1 file changed

Lines changed: 197 additions & 9 deletions

File tree

‎drivers/mmc/host/sdhci-msm.c‎

Lines changed: 197 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
#define CORE_PWRCTL_IO_LOW BIT(2)
3838
#define CORE_PWRCTL_IO_HIGH BIT(3)
3939
#define CORE_PWRCTL_BUS_SUCCESS BIT(0)
40+
#define CORE_PWRCTL_BUS_FAIL BIT(1)
4041
#define CORE_PWRCTL_IO_SUCCESS BIT(2)
42+
#define CORE_PWRCTL_IO_FAIL BIT(3)
4143
#define REQ_BUS_OFF BIT(0)
4244
#define REQ_BUS_ON BIT(1)
4345
#define REQ_IO_LOW BIT(2)
@@ -127,6 +129,9 @@
127129
/* Timeout value to avoid infinite waiting for pwr_irq */
128130
#define MSM_PWR_IRQ_TIMEOUT_MS 5000
129131

132+
/* Max load for eMMC Vdd-io supply */
133+
#define MMC_VQMMC_MAX_LOAD_UA 325000
134+
130135
#define msm_host_readl(msm_host, host, offset) \
131136
msm_host->var_ops->msm_readl_relaxed(host, offset)
132137

@@ -278,6 +283,7 @@ struct sdhci_msm_host {
278283
bool uses_tassadar_dll;
279284
u32 dll_config;
280285
u32 ddr_config;
286+
bool vqmmc_enabled;
281287
};
282288

283289
static const struct sdhci_msm_offset *sdhci_priv_msm_offset(struct sdhci_host *host)
@@ -1347,6 +1353,95 @@ static void sdhci_msm_set_uhs_signaling(struct sdhci_host *host,
13471353
sdhci_msm_hs400(host, &mmc->ios);
13481354
}
13491355

1356+
static int sdhci_msm_set_vmmc(struct mmc_host *mmc)
1357+
{
1358+
if (IS_ERR(mmc->supply.vmmc))
1359+
return 0;
1360+
1361+
return mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, mmc->ios.vdd);
1362+
}
1363+
1364+
static int msm_toggle_vqmmc(struct sdhci_msm_host *msm_host,
1365+
struct mmc_host *mmc, bool level)
1366+
{
1367+
int ret;
1368+
struct mmc_ios ios;
1369+
1370+
if (msm_host->vqmmc_enabled == level)
1371+
return 0;
1372+
1373+
if (level) {
1374+
/* Set the IO voltage regulator to default voltage level */
1375+
if (msm_host->caps_0 & CORE_3_0V_SUPPORT)
1376+
ios.signal_voltage = MMC_SIGNAL_VOLTAGE_330;
1377+
else if (msm_host->caps_0 & CORE_1_8V_SUPPORT)
1378+
ios.signal_voltage = MMC_SIGNAL_VOLTAGE_180;
1379+
1380+
if (msm_host->caps_0 & CORE_VOLT_SUPPORT) {
1381+
ret = mmc_regulator_set_vqmmc(mmc, &ios);
1382+
if (ret < 0) {
1383+
dev_err(mmc_dev(mmc), "%s: vqmmc set volgate failed: %d\n",
1384+
mmc_hostname(mmc), ret);
1385+
goto out;
1386+
}
1387+
}
1388+
ret = regulator_enable(mmc->supply.vqmmc);
1389+
} else {
1390+
ret = regulator_disable(mmc->supply.vqmmc);
1391+
}
1392+
1393+
if (ret)
1394+
dev_err(mmc_dev(mmc), "%s: vqmm %sable failed: %d\n",
1395+
mmc_hostname(mmc), level ? "en":"dis", ret);
1396+
else
1397+
msm_host->vqmmc_enabled = level;
1398+
out:
1399+
return ret;
1400+
}
1401+
1402+
static int msm_config_vqmmc_mode(struct sdhci_msm_host *msm_host,
1403+
struct mmc_host *mmc, bool hpm)
1404+
{
1405+
int load, ret;
1406+
1407+
load = hpm ? MMC_VQMMC_MAX_LOAD_UA : 0;
1408+
ret = regulator_set_load(mmc->supply.vqmmc, load);
1409+
if (ret)
1410+
dev_err(mmc_dev(mmc), "%s: vqmmc set load failed: %d\n",
1411+
mmc_hostname(mmc), ret);
1412+
return ret;
1413+
}
1414+
1415+
static int sdhci_msm_set_vqmmc(struct sdhci_msm_host *msm_host,
1416+
struct mmc_host *mmc, bool level)
1417+
{
1418+
int ret;
1419+
bool always_on;
1420+
1421+
if (IS_ERR(mmc->supply.vqmmc) ||
1422+
(mmc->ios.power_mode == MMC_POWER_UNDEFINED))
1423+
return 0;
1424+
/*
1425+
* For eMMC don't turn off Vqmmc, Instead just configure it in LPM
1426+
* and HPM modes by setting the corresponding load.
1427+
*
1428+
* Till eMMC is initialized (i.e. always_on == 0), just turn on/off
1429+
* Vqmmc. Vqmmc gets turned off only if init fails and mmc_power_off
1430+
* gets invoked. Once eMMC is initialized (i.e. always_on == 1),
1431+
* Vqmmc should remain ON, So just set the load instead of turning it
1432+
* off/on.
1433+
*/
1434+
always_on = !mmc_card_is_removable(mmc) &&
1435+
mmc->card && mmc_card_mmc(mmc->card);
1436+
1437+
if (always_on)
1438+
ret = msm_config_vqmmc_mode(msm_host, mmc, level);
1439+
else
1440+
ret = msm_toggle_vqmmc(msm_host, mmc, level);
1441+
1442+
return ret;
1443+
}
1444+
13501445
static inline void sdhci_msm_init_pwr_irq_wait(struct sdhci_msm_host *msm_host)
13511446
{
13521447
init_waitqueue_head(&msm_host->pwr_irq_wait);
@@ -1450,8 +1545,9 @@ static void sdhci_msm_handle_pwr_irq(struct sdhci_host *host, int irq)
14501545
{
14511546
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
14521547
struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
1548+
struct mmc_host *mmc = host->mmc;
14531549
u32 irq_status, irq_ack = 0;
1454-
int retry = 10;
1550+
int retry = 10, ret;
14551551
u32 pwr_state = 0, io_level = 0;
14561552
u32 config;
14571553
const struct sdhci_msm_offset *msm_offset = msm_host->offset;
@@ -1489,21 +1585,42 @@ static void sdhci_msm_handle_pwr_irq(struct sdhci_host *host, int irq)
14891585
if (irq_status & CORE_PWRCTL_BUS_ON) {
14901586
pwr_state = REQ_BUS_ON;
14911587
io_level = REQ_IO_HIGH;
1492-
irq_ack |= CORE_PWRCTL_BUS_SUCCESS;
14931588
}
14941589
if (irq_status & CORE_PWRCTL_BUS_OFF) {
14951590
pwr_state = REQ_BUS_OFF;
14961591
io_level = REQ_IO_LOW;
1497-
irq_ack |= CORE_PWRCTL_BUS_SUCCESS;
14981592
}
1593+
1594+
if (pwr_state) {
1595+
ret = sdhci_msm_set_vmmc(mmc);
1596+
if (!ret)
1597+
ret = sdhci_msm_set_vqmmc(msm_host, mmc,
1598+
pwr_state & REQ_BUS_ON);
1599+
if (!ret)
1600+
irq_ack |= CORE_PWRCTL_BUS_SUCCESS;
1601+
else
1602+
irq_ack |= CORE_PWRCTL_BUS_FAIL;
1603+
}
1604+
14991605
/* Handle IO LOW/HIGH */
1500-
if (irq_status & CORE_PWRCTL_IO_LOW) {
1606+
if (irq_status & CORE_PWRCTL_IO_LOW)
15011607
io_level = REQ_IO_LOW;
1502-
irq_ack |= CORE_PWRCTL_IO_SUCCESS;
1503-
}
1504-
if (irq_status & CORE_PWRCTL_IO_HIGH) {
1608+
1609+
if (irq_status & CORE_PWRCTL_IO_HIGH)
15051610
io_level = REQ_IO_HIGH;
1611+
1612+
if (io_level)
15061613
irq_ack |= CORE_PWRCTL_IO_SUCCESS;
1614+
1615+
if (io_level && !IS_ERR(mmc->supply.vqmmc) && !pwr_state) {
1616+
ret = mmc_regulator_set_vqmmc(mmc, &mmc->ios);
1617+
if (ret < 0) {
1618+
dev_err(mmc_dev(mmc), "%s: IO_level setting failed(%d). signal_voltage: %d, vdd: %d irq_status: 0x%08x\n",
1619+
mmc_hostname(mmc), ret,
1620+
mmc->ios.signal_voltage, mmc->ios.vdd,
1621+
irq_status);
1622+
irq_ack |= CORE_PWRCTL_IO_FAIL;
1623+
}
15071624
}
15081625

15091626
/*
@@ -1552,7 +1669,7 @@ static void sdhci_msm_handle_pwr_irq(struct sdhci_host *host, int irq)
15521669
if (io_level)
15531670
msm_host->curr_io_level = io_level;
15541671

1555-
pr_debug("%s: %s: Handled IRQ(%d), irq_status=0x%x, ack=0x%x\n",
1672+
dev_dbg(mmc_dev(mmc), "%s: %s: Handled IRQ(%d), irq_status=0x%x, ack=0x%x\n",
15561673
mmc_hostname(msm_host->mmc), __func__, irq, irq_status,
15571674
irq_ack);
15581675
}
@@ -1882,6 +1999,71 @@ static void sdhci_msm_reset(struct sdhci_host *host, u8 mask)
18821999
sdhci_reset(host, mask);
18832000
}
18842001

2002+
static int sdhci_msm_register_vreg(struct sdhci_msm_host *msm_host)
2003+
{
2004+
int ret;
2005+
2006+
ret = mmc_regulator_get_supply(msm_host->mmc);
2007+
if (ret)
2008+
return ret;
2009+
2010+
sdhci_msm_set_regulator_caps(msm_host);
2011+
2012+
return 0;
2013+
}
2014+
2015+
static int sdhci_msm_start_signal_voltage_switch(struct mmc_host *mmc,
2016+
struct mmc_ios *ios)
2017+
{
2018+
struct sdhci_host *host = mmc_priv(mmc);
2019+
u16 ctrl, status;
2020+
2021+
/*
2022+
* Signal Voltage Switching is only applicable for Host Controllers
2023+
* v3.00 and above.
2024+
*/
2025+
if (host->version < SDHCI_SPEC_300)
2026+
return 0;
2027+
2028+
ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
2029+
2030+
switch (ios->signal_voltage) {
2031+
case MMC_SIGNAL_VOLTAGE_330:
2032+
if (!(host->flags & SDHCI_SIGNALING_330))
2033+
return -EINVAL;
2034+
2035+
/* Set 1.8V Signal Enable in the Host Control2 register to 0 */
2036+
ctrl &= ~SDHCI_CTRL_VDD_180;
2037+
break;
2038+
case MMC_SIGNAL_VOLTAGE_180:
2039+
if (!(host->flags & SDHCI_SIGNALING_180))
2040+
return -EINVAL;
2041+
2042+
/* Enable 1.8V Signal Enable in the Host Control2 register */
2043+
ctrl |= SDHCI_CTRL_VDD_180;
2044+
break;
2045+
2046+
default:
2047+
return -EINVAL;
2048+
}
2049+
2050+
sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
2051+
2052+
/* Wait for 5ms */
2053+
usleep_range(5000, 5500);
2054+
2055+
/* regulator output should be stable within 5 ms */
2056+
status = ctrl & SDHCI_CTRL_VDD_180;
2057+
ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
2058+
if ((ctrl & SDHCI_CTRL_VDD_180) == status)
2059+
return 0;
2060+
2061+
dev_warn(mmc_dev(mmc), "%s: Regulator output did not became stable\n",
2062+
mmc_hostname(mmc));
2063+
2064+
return -EAGAIN;
2065+
}
2066+
18852067
#define DRIVER_NAME "sdhci_msm"
18862068
#define SDHCI_MSM_DUMP(f, x...) \
18872069
pr_err("%s: " DRIVER_NAME ": " f, mmc_hostname(host->mmc), ## x)
@@ -1968,6 +2150,7 @@ static const struct sdhci_ops sdhci_msm_ops = {
19682150
.write_b = sdhci_msm_writeb,
19692151
.irq = sdhci_msm_cqe_irq,
19702152
.dump_vendor_regs = sdhci_msm_dump_vendor_regs,
2153+
.set_power = sdhci_set_power_noreg,
19712154
};
19722155

19732156
static const struct sdhci_pltfm_data sdhci_msm_pdata = {
@@ -2182,6 +2365,10 @@ static int sdhci_msm_probe(struct platform_device *pdev)
21822365
if (core_major == 1 && core_minor >= 0x49)
21832366
msm_host->updated_ddr_cfg = true;
21842367

2368+
ret = sdhci_msm_register_vreg(msm_host);
2369+
if (ret)
2370+
goto clk_disable;
2371+
21852372
/*
21862373
* Power on reset state may trigger power irq if previous status of
21872374
* PWRCTL was either BUS_ON or IO_HIGH_V. So before enabling pwr irq
@@ -2226,14 +2413,15 @@ static int sdhci_msm_probe(struct platform_device *pdev)
22262413
MSM_MMC_AUTOSUSPEND_DELAY_MS);
22272414
pm_runtime_use_autosuspend(&pdev->dev);
22282415

2416+
host->mmc_host_ops.start_signal_voltage_switch =
2417+
sdhci_msm_start_signal_voltage_switch;
22292418
host->mmc_host_ops.execute_tuning = sdhci_msm_execute_tuning;
22302419
if (of_property_read_bool(node, "supports-cqe"))
22312420
ret = sdhci_msm_cqe_add_host(host, pdev);
22322421
else
22332422
ret = sdhci_add_host(host);
22342423
if (ret)
22352424
goto pm_runtime_disable;
2236-
sdhci_msm_set_regulator_caps(msm_host);
22372425

22382426
pm_runtime_mark_last_busy(&pdev->dev);
22392427
pm_runtime_put_autosuspend(&pdev->dev);

0 commit comments

Comments
 (0)