From patchwork Fri Apr 18 00:47:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Kryger X-Patchwork-Id: 28601 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5F5D02188F for ; Fri, 18 Apr 2014 00:47:31 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id kq14sf4154682pab.6 for ; Thu, 17 Apr 2014 17:47:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=GPTXN3mWkjFs1xW7hcqlOQkd0vh7UTop91zo6ibPH0k=; b=T/Em2bld3J1Kc2ljRN4mIMkZ+ZR4hgo0t1pkEbkAejYdqG9ds6JaZuwpxjbQqz/iei 51VDsevc+Mo+6HsbnaBZchaYDNesEyTKwHGGY3Yv4bkMdYAkUuykkKX4oRjSBxupHbJz 0iteHkMmpM2Oo7NJk7ozi0wCjSOF2bO8fKmqs8GZMBQ57YEYrcKqRBlT924eGPA3QNbP f6pfszXC3Afs5U47i56RuS375YSMk3p8f07Fw0xSCKoitgXNuvEwMomvROHkJsB8p3rC OfKCcVaWht/Bs9Yct24TqdiQKWv3xfSRhY7IM2vkEFW177r9Ohgg+JGK3FD97f+Kwwwf i0Qg== X-Gm-Message-State: ALoCoQlJTHXtdXJtC5350ieRrfBuqgnSiqEpE0oxCYkGIUTsrQRIhdsrUSSkEWHvXe5kVxbBZcjK X-Received: by 10.66.182.162 with SMTP id ef2mr9489448pac.40.1397782050635; Thu, 17 Apr 2014 17:47:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.42.20 with SMTP id b20ls1285536qga.5.gmail; Thu, 17 Apr 2014 17:47:30 -0700 (PDT) X-Received: by 10.52.23.97 with SMTP id l1mr9491960vdf.11.1397782050510; Thu, 17 Apr 2014 17:47:30 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id fn10si4707313vdc.153.2014.04.17.17.47.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 17 Apr 2014 17:47:30 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id jx11so1663095veb.17 for ; Thu, 17 Apr 2014 17:47:30 -0700 (PDT) X-Received: by 10.58.187.78 with SMTP id fq14mr14204089vec.9.1397782050398; Thu, 17 Apr 2014 17:47:30 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp75546vcb; Thu, 17 Apr 2014 17:47:29 -0700 (PDT) X-Received: by 10.67.23.135 with SMTP id ia7mr18815219pad.5.1397782049610; Thu, 17 Apr 2014 17:47:29 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id il2si15445375pbc.177.2014.04.17.17.47.29; Thu, 17 Apr 2014 17:47:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751217AbaDRArY (ORCPT + 7 others); Thu, 17 Apr 2014 20:47:24 -0400 Received: from mail-gw3-out.broadcom.com ([216.31.210.64]:1699 "EHLO mail-gw3-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750944AbaDRArW (ORCPT ); Thu, 17 Apr 2014 20:47:22 -0400 X-IronPort-AV: E=Sophos;i="4.97,882,1389772800"; d="scan'208";a="24879142" Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw3-out.broadcom.com with ESMTP; 17 Apr 2014 18:05:48 -0700 Received: from IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.174.1; Thu, 17 Apr 2014 17:47:21 -0700 Received: from mail-sj1-12.sj.broadcom.com (10.10.10.20) by IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) with Microsoft SMTP Server id 14.3.174.1; Thu, 17 Apr 2014 17:47:21 -0700 Received: from dhcp-sv1-10-19-114-209.sj.broadcom.com (mps-infra-lab3.sj.broadcom.com [10.19.114.109]) by mail-sj1-12.sj.broadcom.com (Postfix) with ESMTP id 3B7AF27A84; Thu, 17 Apr 2014 17:47:21 -0700 (PDT) Received: by dhcp-sv1-10-19-114-209.sj.broadcom.com (Postfix, from userid 1004) id EB7F92520E7F; Thu, 17 Apr 2014 17:47:20 -0700 (PDT) From: Tim Kryger To: Chris Ball , Ulf Hansson CC: Tim Kryger , Mike Looijmans , Andrew Bresticker , "Linux MMC List" , Linux Kernel Mailing List Subject: [PATCH 2/2] mmc: sdhci: Use common mmc_regulator_get_supply Date: Thu, 17 Apr 2014 17:47:01 -0700 Message-ID: <1397782021-31396-3-git-send-email-tim.kryger@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1397782021-31396-1-git-send-email-tim.kryger@linaro.org> References: <1397782021-31396-1-git-send-email-tim.kryger@linaro.org> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: tim.kryger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Replace some buggy code with a call to mmc_regulator_get_supply. When external regulator provides VDD, ocr_avail is set directly based on the supported voltage range. This allows for the use of regulators that can't provide exactly 1.8v, 3.0v, or 3.3v. Commit cec2e21 had attempted to address this by relaxing the range checks in the SDHCI driver but it set the capabilities as an intermediate step which meant ocr_avail could get bits set for unsupported voltages. Signed-off-by: Tim Kryger --- drivers/mmc/host/sdhci.c | 67 +++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 49 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 16fba66..2d081d8 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1438,7 +1438,8 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios) if (host->flags & SDHCI_DEVICE_DEAD) { spin_unlock_irqrestore(&host->lock, flags); - if (mmc->supply.vmmc && ios->power_mode == MMC_POWER_OFF) + if (!IS_ERR(mmc->supply.vmmc) && + ios->power_mode == MMC_POWER_OFF) mmc_regulator_set_ocr(host->mmc, mmc->supply.vmmc, 0); return; } @@ -1464,7 +1465,7 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios) else vdd_bit = sdhci_set_power(host, ios->vdd); - if (mmc->supply.vmmc && vdd_bit != -1) { + if (!IS_ERR(mmc->supply.vmmc) && vdd_bit != -1) { spin_unlock_irqrestore(&host->lock, flags); mmc_regulator_set_ocr(host->mmc, mmc->supply.vmmc, vdd_bit); spin_lock_irqsave(&host->lock, flags); @@ -1762,7 +1763,7 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host, ctrl &= ~SDHCI_CTRL_VDD_180; sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); - if (mmc->supply.vqmmc) { + if (!IS_ERR(mmc->supply.vqmmc)) { ret = regulator_set_voltage(mmc->supply.vqmmc, 2700000, 3600000); if (ret) { @@ -1784,7 +1785,7 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host, return -EAGAIN; case MMC_SIGNAL_VOLTAGE_180: - if (mmc->supply.vqmmc) { + if (!IS_ERR(mmc->supply.vqmmc)) { ret = regulator_set_voltage(mmc->supply.vqmmc, 1700000, 1950000); if (ret) { @@ -1814,7 +1815,7 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host, return -EAGAIN; case MMC_SIGNAL_VOLTAGE_120: - if (mmc->supply.vqmmc) { + if (!IS_ERR(mmc->supply.vqmmc)) { ret = regulator_set_voltage(mmc->supply.vqmmc, 1100000, 1300000); if (ret) { @@ -2979,15 +2980,12 @@ int sdhci_add_host(struct sdhci_host *host) !(host->mmc->caps & MMC_CAP_NONREMOVABLE)) mmc->caps |= MMC_CAP_NEEDS_POLL; + /* If there are external regulators, get them */ + if (mmc_regulator_get_supply(mmc) == -EPROBE_DEFER) + return -EPROBE_DEFER; + /* If vqmmc regulator and no 1.8V signalling, then there's no UHS */ - mmc->supply.vqmmc = regulator_get_optional(mmc_dev(mmc), "vqmmc"); - if (IS_ERR_OR_NULL(mmc->supply.vqmmc)) { - if (PTR_ERR(mmc->supply.vqmmc) < 0) { - pr_info("%s: no vqmmc regulator found\n", - mmc_hostname(mmc)); - mmc->supply.vqmmc = NULL; - } - } else { + if (!IS_ERR(mmc->supply.vqmmc)) { ret = regulator_enable(mmc->supply.vqmmc); if (!regulator_is_supported_voltage(mmc->supply.vqmmc, 1700000, 1950000)) @@ -3058,34 +3056,6 @@ int sdhci_add_host(struct sdhci_host *host) ocr_avail = 0; - mmc->supply.vmmc = regulator_get_optional(mmc_dev(mmc), "vmmc"); - if (IS_ERR_OR_NULL(mmc->supply.vmmc)) { - if (PTR_ERR(mmc->supply.vmmc) < 0) { - pr_info("%s: no vmmc regulator found\n", - mmc_hostname(mmc)); - mmc->supply.vmmc = NULL; - } - } - -#ifdef CONFIG_REGULATOR - /* - * Voltage range check makes sense only if regulator reports - * any voltage value. - */ - if (mmc->supply.vmmc && regulator_get_voltage(mmc->supply.vmmc) > 0) { - ret = regulator_is_supported_voltage(mmc->supply.vmmc, 2700000, - 3600000); - if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_330))) - caps[0] &= ~SDHCI_CAN_VDD_330; - if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_300))) - caps[0] &= ~SDHCI_CAN_VDD_300; - ret = regulator_is_supported_voltage(mmc->supply.vmmc, 1700000, - 1950000); - if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_180))) - caps[0] &= ~SDHCI_CAN_VDD_180; - } -#endif /* CONFIG_REGULATOR */ - /* * According to SD Host Controller spec v3.00, if the Host System * can afford more than 150mA, Host Driver should set XPC to 1. Also @@ -3094,7 +3064,7 @@ int sdhci_add_host(struct sdhci_host *host) * value. */ max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT); - if (!max_current_caps && mmc->supply.vmmc) { + if (!max_current_caps && !IS_ERR(mmc->supply.vmmc)) { u32 curr = regulator_get_current_limit(mmc->supply.vmmc); if (curr > 0) { @@ -3135,8 +3105,11 @@ int sdhci_add_host(struct sdhci_host *host) SDHCI_MAX_CURRENT_MULTIPLIER; } + if (mmc->ocr_avail) + ocr_avail &= mmc->ocr_avail; + if (host->ocr_mask) - ocr_avail = host->ocr_mask; + ocr_avail &= host->ocr_mask; mmc->ocr_avail = ocr_avail; mmc->ocr_avail_sdio = ocr_avail; @@ -3330,15 +3303,11 @@ void sdhci_remove_host(struct sdhci_host *host, int dead) tasklet_kill(&host->card_tasklet); tasklet_kill(&host->finish_tasklet); - if (mmc->supply.vmmc) { + if (!IS_ERR(mmc->supply.vmmc)) regulator_disable(mmc->supply.vmmc); - regulator_put(mmc->supply.vmmc); - } - if (mmc->supply.vqmmc) { + if (!IS_ERR(mmc->supply.vqmmc)) regulator_disable(mmc->supply.vqmmc); - regulator_put(mmc->supply.vqmmc); - } kfree(host->adma_desc); kfree(host->align_buffer);