From patchwork Wed Apr 1 19:57:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 11469495 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 436AE92C for ; Wed, 1 Apr 2020 19:57:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1D2A120719 for ; Wed, 1 Apr 2020 19:57:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732728AbgDAT5u (ORCPT ); Wed, 1 Apr 2020 15:57:50 -0400 Received: from mail-out.m-online.net ([212.18.0.9]:55144 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732780AbgDAT5u (ORCPT ); Wed, 1 Apr 2020 15:57:50 -0400 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 48sxnQ0MVWz1qrLT; Wed, 1 Apr 2020 21:57:45 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 48sxnP56Fpz1r0cc; Wed, 1 Apr 2020 21:57:45 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 210JVslIAnS6; Wed, 1 Apr 2020 21:57:43 +0200 (CEST) X-Auth-Info: dPOQSMtZ/hOyv/EFlEgFhITIcVya3DR+6Zw6uASdfiA= Received: from desktop.lan (ip-86-49-35-8.net.upcbroadband.cz [86.49.35.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Wed, 1 Apr 2020 21:57:43 +0200 (CEST) From: Marek Vasut To: linux-mmc@vger.kernel.org Cc: Marek Vasut , Alexandre Torgue , Linus Walleij , Ludovic Barre , Manivannan Sadhasivam , Maxime Coquelin , Patrice Chotard , Patrick Delaunay , Russell King , Ulf Hansson , linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH 1/3] mmc: Prepare all code for mmc_set_signal_voltage() returning > 0 Date: Wed, 1 Apr 2020 21:57:20 +0200 Message-Id: <20200401195722.208157-1-marex@denx.de> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Patch all drivers and core code which uses mmc_set_signal_voltage() and prepare it for the fact that mmc_set_signal_voltage() can return a value > 0, which would happen if the signal voltage switch did NOT happen, because the voltage was already set correctly. Signed-off-by: Marek Vasut Cc: Alexandre Torgue Cc: Linus Walleij Cc: Ludovic Barre Cc: Manivannan Sadhasivam Cc: Maxime Coquelin Cc: Patrice Chotard Cc: Patrick Delaunay Cc: Russell King Cc: Ulf Hansson Cc: linux-stm32@st-md-mailman.stormreply.com To: linux-mmc@vger.kernel.org --- drivers/mmc/core/core.c | 10 +++++----- drivers/mmc/core/mmc.c | 16 ++++++++-------- drivers/mmc/host/dw_mmc-k3.c | 2 +- drivers/mmc/host/dw_mmc.c | 3 +-- drivers/mmc/host/mtk-sd.c | 2 +- drivers/mmc/host/renesas_sdhi_core.c | 2 +- drivers/mmc/host/sdhci-sprd.c | 2 +- drivers/mmc/host/sdhci.c | 6 +++--- 8 files changed, 21 insertions(+), 22 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 4c5de6d37ac7..98a3552205cb 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1142,7 +1142,7 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage) if (host->ops->start_signal_voltage_switch) err = host->ops->start_signal_voltage_switch(host, &host->ios); - if (err) + if (err < 0) host->ios.signal_voltage = old_signal_voltage; return err; @@ -1152,11 +1152,11 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage) void mmc_set_initial_signal_voltage(struct mmc_host *host) { /* Try to set signal voltage to 3.3V but fall back to 1.8v or 1.2v */ - if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330)) + if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330) >= 0) dev_dbg(mmc_dev(host), "Initial signal voltage of 3.3v\n"); - else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) + else if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180) >= 0) dev_dbg(mmc_dev(host), "Initial signal voltage of 1.8v\n"); - else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120)) + else if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120) >= 0) dev_dbg(mmc_dev(host), "Initial signal voltage of 1.2v\n"); } @@ -1172,7 +1172,7 @@ int mmc_host_set_uhs_voltage(struct mmc_host *host) host->ios.clock = 0; mmc_set_ios(host); - if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) + if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180) < 0) return -EAGAIN; /* Keep clock gated for at least 10 ms, though spec only says 5 ms */ diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index de94fbe629bd..9f5aae051f6d 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -1121,7 +1121,7 @@ static int mmc_select_hs_ddr(struct mmc_card *card) */ if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_1_2V) { err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120); - if (!err) + if (err >= 0) return 0; } @@ -1130,7 +1130,7 @@ static int mmc_select_hs_ddr(struct mmc_card *card) err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180); /* make sure vccq is 3.3v after switching disaster */ - if (err) + if (err < 0) err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330); return err; @@ -1339,11 +1339,11 @@ static int mmc_select_hs400es(struct mmc_card *card) if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_2V) err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120); - if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_8V) + if (err < 0 && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_8V) err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180); /* If fails try again during next card power cycle */ - if (err) + if (err < 0) goto out_err; err = mmc_select_bus_width(card); @@ -1437,11 +1437,11 @@ static int mmc_select_hs200(struct mmc_card *card) if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_2V) err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120); - if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_8V) + if (err < 0 && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_8V) err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180); /* If fails try again during next card power cycle */ - if (err) + if (err < 0) return err; mmc_select_driver_type(card); @@ -1480,7 +1480,7 @@ static int mmc_select_hs200(struct mmc_card *card) err: if (err) { /* fall back to the old signal voltage, if fails report error */ - if (mmc_set_signal_voltage(host, old_signal_voltage)) + if (mmc_set_signal_voltage(host, old_signal_voltage) < 0) err = -EIO; pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), @@ -1769,7 +1769,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, err = mmc_select_bus_width(card); if (err > 0 && mmc_card_hs(card)) { err = mmc_select_hs_ddr(card); - if (err) + if (err < 0) goto free_card; } } diff --git a/drivers/mmc/host/dw_mmc-k3.c b/drivers/mmc/host/dw_mmc-k3.c index 23b6f65b3785..50977ff18074 100644 --- a/drivers/mmc/host/dw_mmc-k3.c +++ b/drivers/mmc/host/dw_mmc-k3.c @@ -424,7 +424,7 @@ static int dw_mci_hi3660_switch_voltage(struct mmc_host *mmc, if (!IS_ERR(mmc->supply.vqmmc)) { ret = mmc_regulator_set_vqmmc(mmc, ios); - if (ret) { + if (ret < 0) { dev_err(host->dev, "Regulator set error %d\n", ret); return ret; } diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index bc5278ab5707..5d1f8a3ec3a5 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -1546,8 +1546,7 @@ static int dw_mci_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios) if (!IS_ERR(mmc->supply.vqmmc)) { ret = mmc_regulator_set_vqmmc(mmc, ios); - - if (ret) { + if (ret < 0) { dev_dbg(&mmc->class_dev, "Regulator set error %d - %s V\n", ret, uhs & v18 ? "1.8" : "3.3"); diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c index b221c02cc71f..dc6710f9f36f 100644 --- a/drivers/mmc/host/mtk-sd.c +++ b/drivers/mmc/host/mtk-sd.c @@ -1379,7 +1379,7 @@ static int msdc_ops_switch_volt(struct mmc_host *mmc, struct mmc_ios *ios) } ret = mmc_regulator_set_vqmmc(mmc, ios); - if (ret) { + if (ret < 0) { dev_dbg(host->dev, "Regulator set error %d (%d)\n", ret, ios->signal_voltage); } else { diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c index df826661366f..08952b6681f1 100644 --- a/drivers/mmc/host/renesas_sdhi_core.c +++ b/drivers/mmc/host/renesas_sdhi_core.c @@ -237,7 +237,7 @@ static int renesas_sdhi_start_signal_voltage_switch(struct mmc_host *mmc, MMC_SIGNAL_VOLTAGE_330 ? 0 : -EINVAL; ret = mmc_regulator_set_vqmmc(host->mmc, ios); - if (ret) + if (ret < 0) return ret; return pinctrl_select_state(priv->pinctrl, pin_state); diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c index 2ab42c59e4f8..f6c7666e8fa4 100644 --- a/drivers/mmc/host/sdhci-sprd.c +++ b/drivers/mmc/host/sdhci-sprd.c @@ -434,7 +434,7 @@ static int sdhci_sprd_voltage_switch(struct mmc_host *mmc, struct mmc_ios *ios) if (!IS_ERR(mmc->supply.vqmmc)) { ret = mmc_regulator_set_vqmmc(mmc, ios); - if (ret) { + if (ret < 0) { pr_err("%s: Switching signalling voltage failed\n", mmc_hostname(mmc)); return ret; diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 3f716466fcfd..5f9d4c8d24f8 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -2411,7 +2411,7 @@ int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, if (!IS_ERR(mmc->supply.vqmmc)) { ret = mmc_regulator_set_vqmmc(mmc, ios); - if (ret) { + if (ret < 0) { pr_warn("%s: Switching to 3.3V signalling voltage failed\n", mmc_hostname(mmc)); return -EIO; @@ -2434,7 +2434,7 @@ int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, return -EINVAL; if (!IS_ERR(mmc->supply.vqmmc)) { ret = mmc_regulator_set_vqmmc(mmc, ios); - if (ret) { + if (ret < 0) { pr_warn("%s: Switching to 1.8V signalling voltage failed\n", mmc_hostname(mmc)); return -EIO; @@ -2466,7 +2466,7 @@ int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, return -EINVAL; if (!IS_ERR(mmc->supply.vqmmc)) { ret = mmc_regulator_set_vqmmc(mmc, ios); - if (ret) { + if (ret < 0) { pr_warn("%s: Switching to 1.2V signalling voltage failed\n", mmc_hostname(mmc)); return -EIO; From patchwork Wed Apr 1 19:57:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 11469493 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C6CCB159A for ; Wed, 1 Apr 2020 19:57:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ADEAF20719 for ; Wed, 1 Apr 2020 19:57:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732560AbgDAT5t (ORCPT ); Wed, 1 Apr 2020 15:57:49 -0400 Received: from mail-out.m-online.net ([212.18.0.9]:55007 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732397AbgDAT5s (ORCPT ); Wed, 1 Apr 2020 15:57:48 -0400 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 48sxnR3JPMz1qrM1; Wed, 1 Apr 2020 21:57:47 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 48sxnR216bz1r0cc; Wed, 1 Apr 2020 21:57:47 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id KNV0hCM_tGEZ; Wed, 1 Apr 2020 21:57:45 +0200 (CEST) X-Auth-Info: jQiO9NpYBSZHs6DTFZLZ5C7RkVKt6h5mPpQXku8TjTs= Received: from desktop.lan (ip-86-49-35-8.net.upcbroadband.cz [86.49.35.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Wed, 1 Apr 2020 21:57:45 +0200 (CEST) From: Marek Vasut To: linux-mmc@vger.kernel.org Cc: Marek Vasut , Alexandre Torgue , Linus Walleij , Ludovic Barre , Manivannan Sadhasivam , Maxime Coquelin , Patrice Chotard , Patrick Delaunay , Russell King , Ulf Hansson , linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH 2/3] mmc: Return 1 from mmc_set_signal_voltage() if switch skipped Date: Wed, 1 Apr 2020 21:57:21 +0200 Message-Id: <20200401195722.208157-2-marex@denx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200401195722.208157-1-marex@denx.de> References: <20200401195722.208157-1-marex@denx.de> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Adjust mmc_set_signal_voltage() to return 1 if the voltage switch was skipped because the regulator voltage was already correct. This allows drivers to detect such condition and possibly skip various voltage switching extras. Signed-off-by: Marek Vasut Cc: Alexandre Torgue Cc: Linus Walleij Cc: Ludovic Barre Cc: Manivannan Sadhasivam Cc: Maxime Coquelin Cc: Patrice Chotard Cc: Patrick Delaunay Cc: Russell King Cc: Ulf Hansson Cc: linux-stm32@st-md-mailman.stormreply.com To: linux-mmc@vger.kernel.org --- drivers/mmc/core/regulator.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/mmc/core/regulator.c b/drivers/mmc/core/regulator.c index b6febbcf8978..2805ea8a070e 100644 --- a/drivers/mmc/core/regulator.c +++ b/drivers/mmc/core/regulator.c @@ -136,6 +136,8 @@ static int mmc_regulator_set_voltage_if_supported(struct regulator *regulator, int min_uV, int target_uV, int max_uV) { + int curr_voltage; + /* * Check if supported first to avoid errors since we may try several * signal levels during power up and don't want to show errors. @@ -143,6 +145,14 @@ static int mmc_regulator_set_voltage_if_supported(struct regulator *regulator, if (!regulator_is_supported_voltage(regulator, min_uV, max_uV)) return -EINVAL; + /* + * The voltage is already set, no need to switch. + * Return 1 to indicate that no switch happened. + */ + curr_voltage = regulator_get_voltage(regulator); + if (curr_voltage == target_uV) + return 1; + return regulator_set_voltage_triplet(regulator, min_uV, target_uV, max_uV); } From patchwork Wed Apr 1 19:57:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 11469497 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BEE792C for ; Wed, 1 Apr 2020 19:57:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 00C76206F6 for ; Wed, 1 Apr 2020 19:57:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732780AbgDAT5v (ORCPT ); Wed, 1 Apr 2020 15:57:51 -0400 Received: from mail-out.m-online.net ([212.18.0.9]:40894 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732397AbgDAT5v (ORCPT ); Wed, 1 Apr 2020 15:57:51 -0400 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 48sxnT0GlGz1qrM4; Wed, 1 Apr 2020 21:57:49 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 48sxnS72hDz1r0cc; Wed, 1 Apr 2020 21:57:48 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id vkW5HCdeRclL; Wed, 1 Apr 2020 21:57:47 +0200 (CEST) X-Auth-Info: 7/hv+VCPFKvVjy94/A1BvDumeSgcAfnzFKsYwubnSIY= Received: from desktop.lan (ip-86-49-35-8.net.upcbroadband.cz [86.49.35.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Wed, 1 Apr 2020 21:57:47 +0200 (CEST) From: Marek Vasut To: linux-mmc@vger.kernel.org Cc: Marek Vasut , Alexandre Torgue , Linus Walleij , Ludovic Barre , Manivannan Sadhasivam , Maxime Coquelin , Patrice Chotard , Patrick Delaunay , Russell King , Ulf Hansson , linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH 3/3] mmc: mmci: Switch to mmc_set_signal_voltage() Date: Wed, 1 Apr 2020 21:57:22 +0200 Message-Id: <20200401195722.208157-3-marex@denx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200401195722.208157-1-marex@denx.de> References: <20200401195722.208157-1-marex@denx.de> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Instead of reimplementing the logic in mmc_set_signal_voltage(), use the mmc code function directly. This fixes a real issue on STM32MP1 where, if the eMMC is supplied with VccQ=1.8 V, the post voltage switch code will spin indefinitelly waiting for the voltage switch to complete, even though no voltage switch really happened. But since mmc_set_signal_voltage() would return 0, then the condition for calling .post_sig_volt_switch() is not satisfied if the switch did not happen. Signed-off-by: Marek Vasut Cc: Alexandre Torgue Cc: Linus Walleij Cc: Ludovic Barre Cc: Manivannan Sadhasivam Cc: Maxime Coquelin Cc: Patrice Chotard Cc: Patrick Delaunay Cc: Russell King Cc: Ulf Hansson Cc: linux-stm32@st-md-mailman.stormreply.com To: linux-mmc@vger.kernel.org --- drivers/mmc/host/mmci.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 647567def612..b8c8f0e623de 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -1861,31 +1861,15 @@ static int mmci_get_cd(struct mmc_host *mmc) static int mmci_sig_volt_switch(struct mmc_host *mmc, struct mmc_ios *ios) { struct mmci_host *host = mmc_priv(mmc); - int ret = 0; - - if (!IS_ERR(mmc->supply.vqmmc)) { + int ret; - switch (ios->signal_voltage) { - case MMC_SIGNAL_VOLTAGE_330: - ret = regulator_set_voltage(mmc->supply.vqmmc, - 2700000, 3600000); - break; - case MMC_SIGNAL_VOLTAGE_180: - ret = regulator_set_voltage(mmc->supply.vqmmc, - 1700000, 1950000); - break; - case MMC_SIGNAL_VOLTAGE_120: - ret = regulator_set_voltage(mmc->supply.vqmmc, - 1100000, 1300000); - break; - } + ret = mmc_regulator_set_vqmmc(mmc, ios); - if (!ret && host->ops && host->ops->post_sig_volt_switch) - ret = host->ops->post_sig_volt_switch(host, ios); + if (!ret && host->ops && host->ops->post_sig_volt_switch) + ret = host->ops->post_sig_volt_switch(host, ios); - if (ret) - dev_warn(mmc_dev(mmc), "Voltage switch failed\n"); - } + if (ret < 0) + dev_warn(mmc_dev(mmc), "Voltage switch failed\n"); return ret; }