From patchwork Wed Dec 14 12:00:59 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: 5696 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 88A2423E10 for ; Wed, 14 Dec 2011 11:57:23 +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 7EF63A18401 for ; Wed, 14 Dec 2011 11:57:23 +0000 (UTC) Received: by eaak10 with SMTP id k10so419423eaa.11 for ; Wed, 14 Dec 2011 03:57:23 -0800 (PST) Received: by 10.204.133.213 with SMTP id g21mr539774bkt.126.1323863843296; Wed, 14 Dec 2011 03:57:23 -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 hg2cs6301bkc; Wed, 14 Dec 2011 03:57:22 -0800 (PST) Received: by 10.42.176.8 with SMTP id bc8mr18872490icb.12.1323863841062; Wed, 14 Dec 2011 03:57:21 -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 p7si640228ibh.112.2011.12.14.03.57.20 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Dec 2011 03:57:21 -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 f6so1408948iag.37 for ; Wed, 14 Dec 2011 03:57:20 -0800 (PST) Received: by 10.50.178.68 with SMTP id cw4mr23921089igc.31.1323863840276; Wed, 14 Dec 2011 03:57:20 -0800 (PST) Received: from girishks ([115.113.119.130]) by mx.google.com with ESMTPS id j3sm8386135ibj.1.2011.12.14.03.57.16 (version=SSLv3 cipher=OTHER); Wed, 14 Dec 2011 03:57:18 -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 V1] mmc: core: Add host capability check for power class Date: Wed, 14 Dec 2011 17:30:59 +0530 Message-Id: <1323864059-26966-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 v1: reduced the number of comparisons as per Hein's suggestion drivers/mmc/core/mmc.c | 21 +++++++++++++++++++++ include/linux/mmc/card.h | 4 ++++ 2 files changed, 25 insertions(+), 0 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 006e932..e7f1902 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -688,6 +688,27 @@ 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 if (pwrclass_val >= MMC_MAX_CURRENT_200) + pwrclass_val = MMC_MAX_CURRENT_200; + 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 */