From patchwork Thu Apr 10 23:31:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Kryger X-Patchwork-Id: 28244 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 E6967212DC for ; Thu, 10 Apr 2014 23:32:57 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id kq14sf15379478pab.10 for ; Thu, 10 Apr 2014 16:32:57 -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 :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=HzAB6g5nlmPLiyJU+ukBQZLkI0CjJXfCDcHWCDE8c88=; b=DZttlcJkHizP0Wxn0XuFsm/HOcri0Ki/ArSaQ2dOdaFephdW65Ff9kcFozogrIs/ah Q+4QsQ44vSJDW0aEpl9Nt2JkVDPbUYibbdTN6BXzj5bu7qrj1n1RIOHICdbuShIuyPf+ KfPOw3LweXPS9aUkC9c3LSMLGlr7M0DGxFZtYXZzRSQ52+hzG/SYD151FfVp+Cx7ELTP GYmHpvaynV5MRqAlD4B0uwyMZLff4rDeSEy943bRrbki6S+w9Xgde7TL8LRLBLICueNI CAtlRa1WG+U3fXZcOMYd/iv8KodVPyol5OSyF8yyyKb4OLLumZ7KOTrEUGahgPtOHSHp 3UCg== X-Gm-Message-State: ALoCoQm9M7BD/At+7JwYSPqwN636RIs2pXqC5qGrwnTVuVxm5KEFYtfcbHXPbdKScwuNg2sfsc13 X-Received: by 10.68.201.7 with SMTP id jw7mr9630347pbc.8.1397172777136; Thu, 10 Apr 2014 16:32:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.88.72 with SMTP id s66ls1417294qgd.11.gmail; Thu, 10 Apr 2014 16:32:57 -0700 (PDT) X-Received: by 10.52.99.168 with SMTP id er8mr3270258vdb.26.1397172777004; Thu, 10 Apr 2014 16:32:57 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id wg4si971539vcb.38.2014.04.10.16.32.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 10 Apr 2014 16:32:56 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hu19so4224415vcb.1 for ; Thu, 10 Apr 2014 16:32:56 -0700 (PDT) X-Received: by 10.52.165.105 with SMTP id yx9mr14033852vdb.22.1397172776918; Thu, 10 Apr 2014 16:32:56 -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 ib8csp145vcb; Thu, 10 Apr 2014 16:32:56 -0700 (PDT) X-Received: by 10.66.153.80 with SMTP id ve16mr23009661pab.143.1397172733310; Thu, 10 Apr 2014 16:32:13 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id tj6si3005834pbc.511.2014.04.10.16.32.09; Thu, 10 Apr 2014 16:32:09 -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 S1754076AbaDJXcH (ORCPT + 8 others); Thu, 10 Apr 2014 19:32:07 -0400 Received: from mail-gw3-out.broadcom.com ([216.31.210.64]:25865 "EHLO mail-gw3-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753845AbaDJXcG (ORCPT ); Thu, 10 Apr 2014 19:32:06 -0400 X-IronPort-AV: E=Sophos;i="4.97,837,1389772800"; d="scan'208";a="23714300" Received: from irvexchcas06.broadcom.com (HELO IRVEXCHCAS06.corp.ad.broadcom.com) ([10.9.208.53]) by mail-gw3-out.broadcom.com with ESMTP; 10 Apr 2014 16:49:31 -0700 Received: from IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) by IRVEXCHCAS06.corp.ad.broadcom.com (10.9.208.53) with Microsoft SMTP Server (TLS) id 14.3.174.1; Thu, 10 Apr 2014 16:32:04 -0700 Received: from mail-sj1-12.sj.broadcom.com (10.10.10.20) by IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) with Microsoft SMTP Server id 14.3.174.1; Thu, 10 Apr 2014 16:32:04 -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 3EC0B27A84; Thu, 10 Apr 2014 16:32:04 -0700 (PDT) Received: by dhcp-sv1-10-19-114-209.sj.broadcom.com (Postfix, from userid 1004) id 037B42520E7E; Thu, 10 Apr 2014 16:32:03 -0700 (PDT) From: Tim Kryger To: Chris Ball , Ulf Hansson CC: Tim Kryger , Linux MMC Mailing List , Linux Kernel Mailing List Subject: [PATCH] mmc: sdhci: Set ocr_avail directly based on vmmc Date: Thu, 10 Apr 2014 16:31:48 -0700 Message-ID: <1397172708-19735-1-git-send-email-tim.kryger@linaro.org> X-Mailer: git-send-email 1.7.9.5 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.220.170 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: , When an external regulator provides VDD, set ocr_avail 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 and ensures that ocr_avil bits are only set for supported voltage ranges. Commit cec2e21 had attempted to relax the range checks but because it relied on setting capabilities as an intermediate step, ocr_avail could easily get a bit set that the host couldn't support. Signed-off-by: Tim Kryger --- drivers/mmc/host/sdhci.c | 107 +++++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 49 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 9a79fc4..4d56fbe 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -2769,6 +2769,29 @@ struct sdhci_host *sdhci_alloc_host(struct device *dev, EXPORT_SYMBOL_GPL(sdhci_alloc_host); +static unsigned int sdhci_get_ocr_avail_from_vmmc(struct sdhci_host *host) +{ + unsigned int ocr_avail = 0; + struct regulator *vmmc = host->vmmc; + + if (regulator_is_supported_voltage(vmmc, 1650000, 1950000) > 0) + ocr_avail |= MMC_VDD_165_195; + + if (regulator_is_supported_voltage(vmmc, 2900000, 3000000) > 0) + ocr_avail |= MMC_VDD_29_30; + + if (regulator_is_supported_voltage(vmmc, 3000000, 3100000) > 0) + ocr_avail |= MMC_VDD_30_31; + + if (regulator_is_supported_voltage(vmmc, 3200000, 3300000) > 0) + ocr_avail |= MMC_VDD_32_33; + + if (regulator_is_supported_voltage(vmmc, 3300000, 3400000) > 0) + ocr_avail |= MMC_VDD_33_34; + + return ocr_avail; +} + int sdhci_add_host(struct sdhci_host *host) { struct mmc_host *mmc; @@ -3063,24 +3086,39 @@ int sdhci_add_host(struct sdhci_host *host) } } -#ifdef CONFIG_REGULATOR - /* - * Voltage range check makes sense only if regulator reports - * any voltage value. - */ + /* If using external regulator, check supported voltage ranges */ if (host->vmmc && regulator_get_voltage(host->vmmc) > 0) { - ret = regulator_is_supported_voltage(host->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(host->vmmc, 1700000, - 1950000); - if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_180))) - caps[0] &= ~SDHCI_CAN_VDD_180; - } -#endif /* CONFIG_REGULATOR */ + ocr_avail = sdhci_get_ocr_avail_from_vmmc(host); + } else { + if (caps[0] & SDHCI_CAN_VDD_330) + ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34; + if (caps[0] & SDHCI_CAN_VDD_300) + ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31; + if (caps[0] & SDHCI_CAN_VDD_180) + ocr_avail |= MMC_VDD_165_195; + } + + if (host->ocr_mask) + ocr_avail = host->ocr_mask; + + mmc->ocr_avail = ocr_avail; + mmc->ocr_avail_sdio = ocr_avail; + if (host->ocr_avail_sdio) + mmc->ocr_avail_sdio &= host->ocr_avail_sdio; + mmc->ocr_avail_sd = ocr_avail; + if (host->ocr_avail_sd) + mmc->ocr_avail_sd &= host->ocr_avail_sd; + else /* normal SD controllers don't support 1.8V */ + mmc->ocr_avail_sd &= ~MMC_VDD_165_195; + mmc->ocr_avail_mmc = ocr_avail; + if (host->ocr_avail_mmc) + mmc->ocr_avail_mmc &= host->ocr_avail_mmc; + + if (mmc->ocr_avail == 0) { + pr_err("%s: Hardware doesn't report any support voltages.\n", + mmc_hostname(mmc)); + return -ENODEV; + } /* * According to SD Host Controller spec v3.00, if the Host System @@ -3106,52 +3144,23 @@ int sdhci_add_host(struct sdhci_host *host) } } - if (caps[0] & SDHCI_CAN_VDD_330) { - ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34; - + if (ocr_avail & (MMC_VDD_32_33 | MMC_VDD_33_34)) mmc->max_current_330 = ((max_current_caps & SDHCI_MAX_CURRENT_330_MASK) >> SDHCI_MAX_CURRENT_330_SHIFT) * SDHCI_MAX_CURRENT_MULTIPLIER; - } - if (caps[0] & SDHCI_CAN_VDD_300) { - ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31; + if (ocr_avail & (MMC_VDD_29_30 | MMC_VDD_30_31)) mmc->max_current_300 = ((max_current_caps & SDHCI_MAX_CURRENT_300_MASK) >> SDHCI_MAX_CURRENT_300_SHIFT) * SDHCI_MAX_CURRENT_MULTIPLIER; - } - if (caps[0] & SDHCI_CAN_VDD_180) { - ocr_avail |= MMC_VDD_165_195; + if (ocr_avail & MMC_VDD_165_195) mmc->max_current_180 = ((max_current_caps & SDHCI_MAX_CURRENT_180_MASK) >> SDHCI_MAX_CURRENT_180_SHIFT) * SDHCI_MAX_CURRENT_MULTIPLIER; - } - - if (host->ocr_mask) - ocr_avail = host->ocr_mask; - - mmc->ocr_avail = ocr_avail; - mmc->ocr_avail_sdio = ocr_avail; - if (host->ocr_avail_sdio) - mmc->ocr_avail_sdio &= host->ocr_avail_sdio; - mmc->ocr_avail_sd = ocr_avail; - if (host->ocr_avail_sd) - mmc->ocr_avail_sd &= host->ocr_avail_sd; - else /* normal SD controllers don't support 1.8V */ - mmc->ocr_avail_sd &= ~MMC_VDD_165_195; - mmc->ocr_avail_mmc = ocr_avail; - if (host->ocr_avail_mmc) - mmc->ocr_avail_mmc &= host->ocr_avail_mmc; - - if (mmc->ocr_avail == 0) { - pr_err("%s: Hardware doesn't report any " - "support voltages.\n", mmc_hostname(mmc)); - return -ENODEV; - } spin_lock_init(&host->lock);