From patchwork Mon Jun 23 10:45:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuvaraj CD X-Patchwork-Id: 4401231 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 19929BEEAA for ; Mon, 23 Jun 2014 10:45:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 218E220211 for ; Mon, 23 Jun 2014 10:45:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B3882201FA for ; Mon, 23 Jun 2014 10:45:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753215AbaFWKpo (ORCPT ); Mon, 23 Jun 2014 06:45:44 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:57670 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753100AbaFWKpn (ORCPT ); Mon, 23 Jun 2014 06:45:43 -0400 Received: by mail-pa0-f43.google.com with SMTP id lf10so5731319pab.30 for ; Mon, 23 Jun 2014 03:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ElhtofMlnv8U/EDRho1Rou/NtLplCeOuqGry1vpSTf0=; b=sb/i6mf6vXr/q2BkFm+CjFhR+0yKVUZ3Xm6tllTkZ/uhXkDeQf8u8k/vcOaXcl3hjQ IPrDKVhwFuUtGeb7oVWOV+Agsvv2283F7uzj2ideJBa/x//vBJvX5loBwkJDVXC1BFl/ g7AU+PvcGhN9JAt1zG1TplJtm5loJtFUY22r1s5Qj86SzEcdjvy3W7s/Z1IjJXDbssbF w/UiAX0YroBsZ3CkN90qwoR/YqGNGeYOzidfqj+uh/GBdnDYC6OnpsYgw9akEdTeHhKK ITJSDNiWlnxwc1MRxz+ibgnvSu4LjPapQMzqya/J2UKb3qUDTmxPepPe9X3XdaMDq9Li fsgA== X-Received: by 10.69.31.107 with SMTP id kl11mr20259059pbd.70.1403520342603; Mon, 23 Jun 2014 03:45:42 -0700 (PDT) Received: from localhost.localdomain ([14.140.216.146]) by mx.google.com with ESMTPSA id qj3sm26243034pbc.91.2014.06.23.03.45.37 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 23 Jun 2014 03:45:41 -0700 (PDT) From: Yuvaraj Kumar C D X-Google-Original-From: Yuvaraj Kumar C D To: linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jh80.chung@samsung.com, cjb@laptop.org, tgih.jun@samsung.com, linux-mmc@vger.kernel.org, ulf.hansson@linaro.org Cc: sonnyrao@chromium.org, t.figa@samsung.com, kgene.kim@samsung.com, joshi@samsung.com, ks.giri@samsung.com, prashanth.g@samsung.com, alim.akhtar@samsung.com, Yuvaraj Kumar C D Subject: [PATCH 1/3] mmc: dw_mmc: use mmc_regulator_get_supply to handle regulators Date: Mon, 23 Jun 2014 16:15:19 +0530 Message-Id: <1403520321-2431-2-git-send-email-yuvaraj.cd@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1403520321-2431-1-git-send-email-yuvaraj.cd@samsung.com> References: <1403520321-2431-1-git-send-email-yuvaraj.cd@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch makes use of mmc_regulator_get_supply() to handle the vmmc and vqmmc regulators.Also it moves the code handling the these regulators to dw_mci_set_ios().It turned on the vmmc and vqmmc during MMC_POWER_UP and MMC_POWER_ON,and turned off during MMC_POWER_OFF. Signed-off-by: Yuvaraj Kumar C D --- drivers/mmc/host/dw_mmc.c | 71 ++++++++++++++++++++++----------------------- drivers/mmc/host/dw_mmc.h | 2 ++ 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 1ac227c..f5cabce 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -937,6 +937,7 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) struct dw_mci_slot *slot = mmc_priv(mmc); const struct dw_mci_drv_data *drv_data = slot->host->drv_data; u32 regs; + int ret; switch (ios->bus_width) { case MMC_BUS_WIDTH_4: @@ -975,16 +976,41 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) switch (ios->power_mode) { case MMC_POWER_UP: + if ((!IS_ERR(mmc->supply.vmmc)) && + !test_bit(DW_MMC_CARD_POWERED, &slot->flags)) { + ret = regulator_enable(mmc->supply.vmmc); + if (!ret) + set_bit(DW_MMC_CARD_POWERED, &slot->flags); + } set_bit(DW_MMC_CARD_NEED_INIT, &slot->flags); regs = mci_readl(slot->host, PWREN); regs |= (1 << slot->id); mci_writel(slot->host, PWREN, regs); break; case MMC_POWER_OFF: + if (!IS_ERR(mmc->supply.vqmmc) && + test_bit(DW_MMC_IO_POWERED, &slot->flags)) { + ret = regulator_disable(mmc->supply.vqmmc); + if (!ret) + clear_bit(DW_MMC_IO_POWERED, &slot->flags); + } + if (!IS_ERR(mmc->supply.vmmc) && + test_bit(DW_MMC_CARD_POWERED, &slot->flags)) { + ret = regulator_disable(mmc->supply.vmmc); + if (!ret) + clear_bit(DW_MMC_CARD_POWERED, &slot->flags); + } regs = mci_readl(slot->host, PWREN); regs &= ~(1 << slot->id); mci_writel(slot->host, PWREN, regs); break; + case MMC_POWER_ON: + if (!IS_ERR(mmc->supply.vqmmc) && + !test_bit(DW_MMC_IO_POWERED, &slot->flags)) { + ret = regulator_enable(mmc->supply.vqmmc); + if (!ret) + set_bit(DW_MMC_IO_POWERED, &slot->flags); + } default: break; } @@ -2067,7 +2093,13 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id) mmc->f_max = freq[1]; } - mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; + /*if there are external regulators, get them*/ + ret = mmc_regulator_get_supply(mmc); + if (ret == -EPROBE_DEFER) + goto err_setup_bus; + + if (!mmc->ocr_avail) + mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; if (host->pdata->caps) mmc->caps = host->pdata->caps; @@ -2133,7 +2165,7 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id) err_setup_bus: mmc_free_host(mmc); - return -EINVAL; + return ret; } static void dw_mci_cleanup_slot(struct dw_mci_slot *slot, unsigned int id) @@ -2375,24 +2407,6 @@ int dw_mci_probe(struct dw_mci *host) } } - host->vmmc = devm_regulator_get_optional(host->dev, "vmmc"); - if (IS_ERR(host->vmmc)) { - ret = PTR_ERR(host->vmmc); - if (ret == -EPROBE_DEFER) - goto err_clk_ciu; - - dev_info(host->dev, "no vmmc regulator found: %d\n", ret); - host->vmmc = NULL; - } else { - ret = regulator_enable(host->vmmc); - if (ret) { - if (ret != -EPROBE_DEFER) - dev_err(host->dev, - "regulator_enable fail: %d\n", ret); - goto err_clk_ciu; - } - } - host->quirks = host->pdata->quirks; spin_lock_init(&host->lock); @@ -2536,8 +2550,6 @@ err_workqueue: err_dmaunmap: if (host->use_dma && host->dma_ops->exit) host->dma_ops->exit(host); - if (host->vmmc) - regulator_disable(host->vmmc); err_clk_ciu: if (!IS_ERR(host->ciu_clk)) @@ -2573,9 +2585,6 @@ void dw_mci_remove(struct dw_mci *host) if (host->use_dma && host->dma_ops->exit) host->dma_ops->exit(host); - if (host->vmmc) - regulator_disable(host->vmmc); - if (!IS_ERR(host->ciu_clk)) clk_disable_unprepare(host->ciu_clk); @@ -2592,9 +2601,6 @@ EXPORT_SYMBOL(dw_mci_remove); */ int dw_mci_suspend(struct dw_mci *host) { - if (host->vmmc) - regulator_disable(host->vmmc); - return 0; } EXPORT_SYMBOL(dw_mci_suspend); @@ -2603,15 +2609,6 @@ int dw_mci_resume(struct dw_mci *host) { int i, ret; - if (host->vmmc) { - ret = regulator_enable(host->vmmc); - if (ret) { - dev_err(host->dev, - "failed to enable regulator: %d\n", ret); - return ret; - } - } - if (!dw_mci_ctrl_all_reset(host)) { ret = -ENODEV; return ret; diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h index 738fa24..5c95d00 100644 --- a/drivers/mmc/host/dw_mmc.h +++ b/drivers/mmc/host/dw_mmc.h @@ -225,6 +225,8 @@ struct dw_mci_slot { unsigned long flags; #define DW_MMC_CARD_PRESENT 0 #define DW_MMC_CARD_NEED_INIT 1 +#define DW_MMC_CARD_POWERED 2 +#define DW_MMC_IO_POWERED 3 int id; int last_detect_state; };