From patchwork Wed Jan 15 14:14:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seungwon Jeon X-Patchwork-Id: 3492061 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 2471D9F32F for ; Wed, 15 Jan 2014 14:14:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EA1E120122 for ; Wed, 15 Jan 2014 14:14:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9A93D200E9 for ; Wed, 15 Jan 2014 14:14:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751744AbaAOOOg (ORCPT ); Wed, 15 Jan 2014 09:14:36 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:57381 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751964AbaAOOOe (ORCPT ); Wed, 15 Jan 2014 09:14:34 -0500 Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MZG007Y94W9XE50@mailout2.samsung.com> for linux-mmc@vger.kernel.org; Wed, 15 Jan 2014 23:14:33 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [203.254.230.50]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id DE.06.09028.9C796D25; Wed, 15 Jan 2014 23:14:33 +0900 (KST) X-AuditID: cbfee68e-b7f566d000002344-ab-52d697c903f7 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 4D.C3.29263.9C796D25; Wed, 15 Jan 2014 23:14:33 +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 <0MZG00GFI4W8AR60@mmp1.samsung.com>; Wed, 15 Jan 2014 23:14:32 +0900 (KST) From: Seungwon Jeon To: 'Chris Ball' , 'Ulf Hansson' , 'Jaehoon Chung' , 'Jackey Shen' , 'Alim Akhtar' Cc: linux-mmc@vger.kernel.org References: <1383653403-10049-1-git-send-email-ulf.hansson@linaro.org> In-reply-to: Subject: [PATCH 3/5] mmc: step power class after final selection of bus mode Date: Wed, 15 Jan 2014 23:14:32 +0900 Message-id: <002901cf11fc$1cd81df0$568859d0$%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/rAABnFmgDfJZ22A= Content-language: ko X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrJIsWRmVeSWpSXmKPExsVy+t8zI92T068FGWzYLmjxYN42NosJl7cz Wky4N5HV4savNlaLI//7GS2Orw13YPNovfSXzePOtT1sHjdeLWTy6NuyitHj8ya5ANYoLpuU 1JzMstQifbsErozD07YzFjRrVFzd08LYwPhUvouRk0NCwERiweWlzBC2mMSFe+vZuhi5OIQE ljFKrOidwdTFyAFWdKabAyK+iFFi8dbpLBDOH0aJI6e/sYB0swloSfx984YZJCEicJxR4lX/ MbAEs4CsxMX9VxlBbCEBN4knPUvYQGxOAR6JdX86wVYLC/hIrN3zESzOIqAqMXtaOxOIzStg K3H+4DoWCFtQ4sfkeywgFzELqEtMmZILMV5eYvOat8wQh6pLPPqrC2KKCFhJdM00hKgQkdj3 4h0jyGUSAm/ZJe58hNkkIPFt8iEWiFZZiU0HoOEgKXFwxQ2WCYwSs5DsnYWwdxaSvb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J5YkpqdmlqQ WgSzhYmDU6qBcRE/V8vykMJbZloOPsoX4gPmMCyex8Jak/d69uup8Z/FZqp0m/3Ofatz75N1 +NvCsJMu9g8fbWI9vWu9YfV3i6o7xSuYpqh6KweY3AtaKMVzfF7qvHMycZX8t/9FFHcqnDn5 37hnnanXdhGuc9pzT77nmLaY7WVE49cjl2/v//LKW/jImZUfnimxFGckGmoxFxUnAgBZy2RL SQMAAA== 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.2 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..92aa004 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) {