From patchwork Sat Feb 15 14:23:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seungwon Jeon X-Patchwork-Id: 3656511 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6AD509F334 for ; Sat, 15 Feb 2014 14:23:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6FA772018B for ; Sat, 15 Feb 2014 14:23:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 061E02015A for ; Sat, 15 Feb 2014 14:23:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753262AbaBOOXn (ORCPT ); Sat, 15 Feb 2014 09:23:43 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:20100 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753153AbaBOOXm (ORCPT ); Sat, 15 Feb 2014 09:23:42 -0500 Received: from epcpsbgr3.samsung.com (u143.gpu120.samsung.co.kr [203.254.230.143]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N1100HPIJZGNH30@mailout1.samsung.com> for linux-mmc@vger.kernel.org; Sat, 15 Feb 2014 23:23:40 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [203.254.230.48]) by epcpsbgr3.samsung.com (EPCPMTA) with SMTP id 2B.3C.10092.C687FF25; Sat, 15 Feb 2014 23:23:40 +0900 (KST) X-AuditID: cbfee68f-b7f156d00000276c-b8-52ff786c031b Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id CA.EC.28157.C687FF25; Sat, 15 Feb 2014 23:23:40 +0900 (KST) Received: from DOTGIHJUN01 ([12.23.118.161]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N110073KJZGJKC0@mmp1.samsung.com>; Sat, 15 Feb 2014 23:23:40 +0900 (KST) From: Seungwon Jeon To: linux-mmc@vger.kernel.org Cc: 'Chris Ball' , 'Ulf Hansson' , 'Jaehoon Chung' , 'Jackey Shen' , 'Alim Akhtar' References: <1383653403-10049-1-git-send-email-ulf.hansson@linaro.org> In-reply-to: Subject: [PATCH RESEND 3/5] mmc: step power class after final selection of bus mode Date: Sat, 15 Feb 2014 23:23:40 +0900 Message-id: <006a01cf2a59$863f6030$92be2090$%jun@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-transfer-encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-index: Ac7aH/uUm1J6MxFOSyaXb4Fx/nx/rAABnFmgDfJZ22AGGh6RYA== Content-language: ko X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFIsWRmVeSWpSXmKPExsVy+t8zA92civ9BBkvm6lk8mLeNzWLC5e2M FhPuTWS1uPGrjdXiyP9+Rovja8Md2DxaL/1l87hzbQ+bx41XC5k8+rasYvT4vEkugDWKyyYl NSezLLVI3y6BK+Pgy4UsBc0aFR1fVjA3MD6V72Lk5JAQMJFo/3+dHcIWk7hwbz1bFyMXh5DA MkaJ6w0nWWCKbhxcywiRWMQosWr/VxYI5w+jxOVpx8Cq2AS0JP6+ecMMYosIyEr8/HMBbBSz wHFGiWtbDoAVCQm4STzpWcIGYnMK8Eis+9MJ1iAsECrRdOs92B0sAqoSp5f/YQKxeQVsJXav XskKYQtK/Jh8D2gOB9BQdYkpU3JBwswC8hKb17xlBglLAIUf/dUFMUUEnCSm/42AqBCR2Pfi Hdj9EgIv2SW2PP8PtUlA4tvkQywQrbISmw4wQ/wrK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WnCSuK8B1utA4UE0hNLUrNTUwtS i2C2MHFwSjUw6jSKZL0r/ra2Mrqh7a2HclDlNH2pfHeTK/uvhGQn84qE6J1XKuZ1Zdx4M/dN R0z3XMkNzU0+sw7FxWbbPNeKecVZMKl6u3RLxJ2AmXmvT7ofeshxglsnVuTI6hMu7Y/F7M7/ OfZVxsW4Rfpthtenc/cqvp48LTT1wz7v9qyLZw1OL3G6m+WqxFKckWioxVxUnAgAg4WgD0oD AAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Power class is changed once only after selection of bus modes including speed and bus-width finishes finally. Signed-off-by: Seungwon Jeon --- drivers/mmc/core/mmc.c | 77 +++++++++++++++++++++++++++++++---------------- 1 files changed, 51 insertions(+), 26 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 1ea155a..0d17395 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -737,8 +737,8 @@ static inline unsigned int mmc_snoop_ddr(struct mmc_card *card) * extended CSD register, select it by executing the * mmc_switch command. */ -static int mmc_select_powerclass(struct mmc_card *card, - unsigned int bus_width) +static int __mmc_select_powerclass(struct mmc_card *card, + unsigned int bus_width, u8 *ext_csd) { int err = 0; unsigned int pwrclass_val = 0; @@ -759,13 +759,13 @@ static int mmc_select_powerclass(struct mmc_card *card, switch (1 << host->ios.vdd) { case MMC_VDD_165_195: - if (host->ios.clock <= 26000000) + if (host->ios.clock <= MMC_HIGH_26_MAX_DTR) pwrclass_val = card->ext_csd.raw_pwr_cl_26_195; - else if (host->ios.clock <= 52000000) + else if (host->ios.clock <= MMC_HIGH_52_MAX_DTR) pwrclass_val = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? card->ext_csd.raw_pwr_cl_52_195 : card->ext_csd.raw_pwr_cl_ddr_52_195; - else if (host->ios.clock <= 200000000) + else if (host->ios.clock <= MMC_HS200_MAX_DTR) pwrclass_val = card->ext_csd.raw_pwr_cl_200_195; break; case MMC_VDD_27_28: @@ -777,13 +777,13 @@ static int mmc_select_powerclass(struct mmc_card *card, case MMC_VDD_33_34: case MMC_VDD_34_35: case MMC_VDD_35_36: - if (host->ios.clock <= 26000000) + if (host->ios.clock <= MMC_HIGH_26_MAX_DTR) pwrclass_val = card->ext_csd.raw_pwr_cl_26_360; - else if (host->ios.clock <= 52000000) + else if (host->ios.clock <= MMC_HIGH_52_MAX_DTR) pwrclass_val = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? card->ext_csd.raw_pwr_cl_52_360 : card->ext_csd.raw_pwr_cl_ddr_52_360; - else if (host->ios.clock <= 200000000) + else if (host->ios.clock <= MMC_HS200_MAX_DTR) pwrclass_val = card->ext_csd.raw_pwr_cl_200_360; break; default: @@ -810,6 +810,44 @@ static int mmc_select_powerclass(struct mmc_card *card, return err; } +static int mmc_select_powerclass(struct mmc_card *card, u8 *ext_csd) +{ + int err, ddr; + u32 bus_width, ext_csd_bits; + struct mmc_host *host; + + BUG_ON(!card); + + host = card->host; + + if (!ext_csd) + return 0; + + /* Power class selection is supported for versions >= 4.0 */ + if (card->csd.mmca_vsn < CSD_SPEC_VER_4) + return 0; + + bus_width = host->ios.bus_width; + /* Power class values are defined only for 4/8 bit bus */ + if (bus_width == MMC_BUS_WIDTH_1) + return 0; + + ddr = mmc_snoop_ddr(card); + if (ddr) + ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ? + EXT_CSD_DDR_BUS_WIDTH_8 : EXT_CSD_DDR_BUS_WIDTH_4; + else + ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ? + EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; + + err = __mmc_select_powerclass(card, ext_csd_bits, ext_csd); + if (err) + pr_warn("%s: power class selection to bus width %d ddr %d failed\n", + mmc_hostname(host), 1 << bus_width, ddr); + + return err; +} + /* * Selects the desired buswidth and switch to the HS200 mode * if bus width set without error @@ -1168,11 +1206,6 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ? EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; - err = mmc_select_powerclass(card, ext_csd_bits); - if (err) - pr_warning("%s: power class selection to bus width %d" - " failed\n", mmc_hostname(card->host), - 1 << bus_width); } /* @@ -1201,12 +1234,6 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, bus_width = bus_widths[idx]; if (bus_width == MMC_BUS_WIDTH_1) ddr = 0; /* no DDR for 1-bit width */ - err = mmc_select_powerclass(card, ext_csd_bits[idx][0]); - if (err) - pr_warning("%s: power class selection to " - "bus width %d failed\n", - mmc_hostname(card->host), - 1 << bus_width); err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, @@ -1231,13 +1258,6 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, } if (!err && ddr) { - err = mmc_select_powerclass(card, ext_csd_bits[idx][1]); - if (err) - pr_warning("%s: power class selection to " - "bus width %d ddr %d failed\n", - mmc_hostname(card->host), - 1 << bus_width, ddr); - err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, ext_csd_bits[idx][1], @@ -1275,6 +1295,11 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, } /* + * Choose the power calss with selected bus interface + */ + mmc_select_powerclass(card, ext_csd); + + /* * Enable HPI feature (if supported) */ if (card->ext_csd.hpi) {