From patchwork Thu Dec 15 03:58:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Girish K S X-Patchwork-Id: 5742 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 4C64323E19 for ; Thu, 15 Dec 2011 03:54:51 +0000 (UTC) Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180]) by fiordland.canonical.com (Postfix) with ESMTP id 26FA1A18149 for ; Thu, 15 Dec 2011 03:54:51 +0000 (UTC) Received: by eaak10 with SMTP id k10so1622017eaa.11 for ; Wed, 14 Dec 2011 19:54:51 -0800 (PST) Received: by 10.204.157.12 with SMTP id z12mr367369bkw.18.1323921290869; Wed, 14 Dec 2011 19:54:50 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.129.2 with SMTP id hg2cs27797bkc; Wed, 14 Dec 2011 19:54:50 -0800 (PST) Received: by 10.42.72.135 with SMTP id o7mr1133464icj.45.1323921289197; Wed, 14 Dec 2011 19:54:49 -0800 (PST) Received: from mail-iy0-f178.google.com (mail-iy0-f178.google.com [209.85.210.178]) by mx.google.com with ESMTPS id z19si1214417ibk.39.2011.12.14.19.54.48 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Dec 2011 19:54:49 -0800 (PST) Received-SPF: neutral (google.com: 209.85.210.178 is neither permitted nor denied by best guess record for domain of girish.shivananjappa@linaro.org) client-ip=209.85.210.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.178 is neither permitted nor denied by best guess record for domain of girish.shivananjappa@linaro.org) smtp.mail=girish.shivananjappa@linaro.org Received: by iagf6 with SMTP id f6so2733089iag.37 for ; Wed, 14 Dec 2011 19:54:48 -0800 (PST) Received: by 10.50.15.130 with SMTP id x2mr1395869igc.21.1323921288483; Wed, 14 Dec 2011 19:54:48 -0800 (PST) Received: from girishks ([115.113.119.130]) by mx.google.com with ESMTPS id wo4sm8013875igc.5.2011.12.14.19.54.44 (version=SSLv3 cipher=OTHER); Wed, 14 Dec 2011 19:54:46 -0800 (PST) From: Girish K S To: linux-mmc@vger.kernel.org Cc: patches@linaro.org, linux-samsung-soc@vger.kernel.org, subhashj@codeaurora.org, Girish K S , Chris Ball Subject: [PATCH V2] mmc: core: Add host capability check for power class Date: Thu, 15 Dec 2011 09:28:37 +0530 Message-Id: <1323921517-31241-1-git-send-email-girish.shivananjappa@linaro.org> X-Mailer: git-send-email 1.7.1 This patch adds a check whether the host supports maximum current value obtained from the device's extended csd register for a selected interface voltage and frequency. cc: Chris Ball Signed-off-by: Girish K S --- Changes in v2: deleted a unnecessary if else condition identified by subhash J Changes in v1: reduced the number of comparisons as per Hein's suggestion drivers/mmc/core/mmc.c | 19 +++++++++++++++++++ include/linux/mmc/card.h | 4 ++++ 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 006e932..b9ef777 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -688,6 +688,25 @@ static int mmc_select_powerclass(struct mmc_card *card, pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_4BIT_MASK) >> EXT_CSD_PWR_CL_4BIT_SHIFT; + if (pwrclass_val >= MMC_MAX_CURRENT_800) + pwrclass_val = MMC_MAX_CURRENT_800; + else if (pwrclass_val >= MMC_MAX_CURRENT_600) + pwrclass_val = MMC_MAX_CURRENT_600; + else if (pwrclass_val >= MMC_MAX_CURRENT_400) + pwrclass_val = MMC_MAX_CURRENT_400; + else + pwrclass_val = MMC_MAX_CURRENT_200; + + if ((pwrclass_val == MMC_MAX_CURRENT_800) && + !(card->host->caps & MMC_CAP_MAX_CURRENT_800)) + pwrclass_val = MMC_MAX_CURRENT_600; + if ((pwrclass_val == MMC_MAX_CURRENT_600) && + !(card->host->caps & MMC_CAP_MAX_CURRENT_600)) + pwrclass_val = MMC_MAX_CURRENT_400; + if ((pwrclass_val == MMC_MAX_CURRENT_400) && + !(card->host->caps & MMC_CAP_MAX_CURRENT_400)) + pwrclass_val = MMC_MAX_CURRENT_200; + /* If the power class is different from the default value */ if (pwrclass_val > 0) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 9478a6b..c5e031a 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -195,6 +195,10 @@ struct mmc_part { #define MMC_BLK_DATA_AREA_GP (1<<2) }; +#define MMC_MAX_CURRENT_200 (0) +#define MMC_MAX_CURRENT_400 (7) +#define MMC_MAX_CURRENT_600 (11) +#define MMC_MAX_CURRENT_800 (13) /* * MMC device */