From patchwork Fri Apr 15 17:29:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aisheng Dong X-Patchwork-Id: 8854211 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6C4A0BF29F for ; Fri, 15 Apr 2016 17:52:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 81E032021A for ; Fri, 15 Apr 2016 17:52:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7F5FF20211 for ; Fri, 15 Apr 2016 17:52:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750846AbcDORw3 (ORCPT ); Fri, 15 Apr 2016 13:52:29 -0400 Received: from mail-bl2on0069.outbound.protection.outlook.com ([65.55.169.69]:45216 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750820AbcDORw3 (ORCPT ); Fri, 15 Apr 2016 13:52:29 -0400 Received: from CH1PR03CA007.namprd03.prod.outlook.com (10.255.156.152) by CY1PR0301MB0716.namprd03.prod.outlook.com (10.160.159.146) with Microsoft SMTP Server (TLS) id 15.1.453.26; Fri, 15 Apr 2016 17:37:19 +0000 Received: from BN1AFFO11FD041.protection.gbl (10.255.156.132) by CH1PR03CA007.outlook.office365.com (10.255.156.152) with Microsoft SMTP Server (TLS) id 15.1.466.19 via Frontend Transport; Fri, 15 Apr 2016 17:37:19 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; gmail.com; dkim=none (message not signed) header.d=none; gmail.com; dmarc=none action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BN1AFFO11FD041.mail.protection.outlook.com (10.58.52.252) with Microsoft SMTP Server (TLS) id 15.1.472.8 via Frontend Transport; Fri, 15 Apr 2016 17:37:18 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id u3FHb2HF019919; Fri, 15 Apr 2016 10:37:15 -0700 From: Dong Aisheng To: CC: , , , , , , , Subject: [PATCH 04/23] mmc: sdhci: re-factor sdhci_start_signal_voltage() Date: Sat, 16 Apr 2016 01:29:28 +0800 Message-ID: <1460741387-23815-5-git-send-email-aisheng.dong@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460741387-23815-1-git-send-email-aisheng.dong@nxp.com> References: <1460741387-23815-1-git-send-email-aisheng.dong@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131052154388097401; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(50986999)(76176999)(105606002)(50466002)(19580395003)(4326007)(85426001)(2351001)(81166005)(19580405001)(5003940100001)(229853001)(189998001)(87936001)(2906002)(48376002)(50226001)(586003)(106466001)(36756003)(2950100001)(47776003)(6806005)(104016004)(5008740100001)(1096002)(1220700001)(77096005)(11100500001)(86362001)(33646002)(110136002)(92566002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0301MB0716; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD041; 1:oiBxfaaDZUd1Qw8iJ5F2rOBcMv0byQo+DZNhkUaayPKVyI4m39ryNoIcUko5gmyzFpLXgLU++i15oWwSM4mMZ7JZUam1mHoOappLwGdiNJVs4aIqlNFGHn42ElHeN1nOxgxlwXnHI1JhCovRmGVXvG9sEKy8ts6pkFxzaJRmfmSLieAik8BO8M5VDUIUFCVes484xxvZpQhscHiQZyprSoN1D1YgWRx/zQqnYK55cD+D1iQYJ1iTVjygXeBmwhoydAktC99n0q7Pu4evrTJlm/iyEHG0pkeNZ4xBkXx3jDQe/1TBxdTv/u5YlrqOwBrM51/S0prDTeioyXp00HkRm/nfdVG4CTgwuFP2HjukMkdEJI4Cs5iMDz4uh+b0oInkRc2d2UfoQ5shT6Pocic8lh3Q75DwVoYYXKSxShpD1fp2E7JiBL5OVCZHHjwshHS2H0N4xCu5KOE0++7lSjjXhcjlfJk+GZCHEs1eMcjL2e9Ya1iUununPx/iZqs4j3OBTEmf2jwM4AsPVXaZnwPYs1OtDkj66d1uhl5onsu+HorN566NbLi7R99teaXLyAHR673EF03gSIbahfeqiJVvXXbzCi9/TAt0wYqFPK3HWSxRt2SZBeJWiGLDTtWUNHuE MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 3df8b656-5d9e-4c2f-2979-08d3655497d1 X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0716; 2:RdRofLT7RBL2GrHKlO4vcK5leTN+93/8z84XUjX9MaUzYG7wyKk+W6W/VX4UxN24fexxcfuUX2nzrXk/RZ5cYyvlotJ21gwaVB86DlXFaIhDxly9mpUzLiYN7mY9gwmFcXGvv/Yd7+wLWDkLdb+wjzd5EUN5pGkdqdpmliQRT08QwPMxA3JbxvMvcR/I6Ycw; 3:077p4wlcaxDtStS/WRvablM0EDeSiwEQIzTtA/gahhGOAe9m92jwNtsyOiZZ5Kax5lpyGpnoUcw2kzqJW4AjroJ6HHFeiKPVhHig7q4LTMbH60XlDTG9wCpMHDC9Aw447zXzpFvAeU+LP1AY2XCh8GbP+4ZKMSsg3kS/UYmvKNDTUf6YfKeYVxlPc+VixlvAEtkXm9ER8rKNGU+3x+1+2T0uy0csROHwqla1pJ7jGbA=; 25:XrcV/yRguf8pNmxtBsMO4M4RHcV9ksQpSLZAwg2l8jwthLWaaEMHwPzzM4LsIGd+EOr02FQGHTzXNWKBg/x0K5wHNxRX7a5rJNwN3g9KrKn+o66MnGgCXmN/HdXcXL6iRCRRLK2p63R4ypvpvCCN5n+QrxaF0ZdiYo/GbrMUKfKHVlJnBTOBOwlAxreUBopsgILJct4DwAHvNMKTz0Qzr3lwKOVcLrTI2RaZhaDnC1MQuTRH0jjXsO1Srg7NLrYQvJzuv0qRY8fT3tvX0myuUhyTAZMmMT9R/yBxN1NBY+dn8laRsjrUjIdvht/BPIZrYD2gb9t9lMC9UEKrfRBnig== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB0716; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13024025)(13023025)(8121501046)(13018025)(13017025)(13015025)(5005006)(3002001)(10201501046)(6055026); SRVR:CY1PR0301MB0716; BCL:0; PCL:0; RULEID:(400006); SRVR:CY1PR0301MB0716; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0716; 4:2Lohixscbn1DWObLOLkqlqlc3HGOQHoG90qlgobuLnzHNwJ/kXpJqZ9Rtob0ZE7jerDSmftGWZHoZzQreAIKcH/4jr56hVFSPu/haRv57kPawincCpWtWW8OxUK5LUQ7Sip+gW1yuI3S3dTR7/XeFv8l613VI7sehCmPbrsP8tZo9QIQQGG/2LcThvmHSwhQtbODXP79lJJgdUx3JuehH0Pxdf1XHrCKuGLb6aJr3xP0RSPkwOagFN5RQRexBk2eF2H6CCbYJ88TYXNXaQ7SoxbJZDfCLbWFNrnfOdL4AP58lkxFwEC0GfKeLOe7TGWS5yAB244I/LA5O6R78Rttza7G9eZzyobYoVd27LyxjpPR39T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w6vE9CWmLgKRrZCY6/3hfZka+wP1D++E4qJ9+imxyKAmyjHoGTiI2R6yZQ?= =?us-ascii?Q?4M99T71+fAaQQDTp8QBvHYk5A0bAX1cHl5N+T6oeucCNrd2Kvify49AOovUj?= =?us-ascii?Q?Wp9T1i8Ose5GxN2Bg/dhJ2yBwVONq35Btaz49+xWcEDqAv+/sszcaY4VbQEw?= =?us-ascii?Q?6FvLsPfVVLcptF9PkWqpxeSzm3di026buLccRFJ+d+UPW9LRXSkVvFyJAWxe?= =?us-ascii?Q?/cAaW9PLkEB9qL6+rbhfoxsXh44YiwGQZnyLFjvWXC5hhOIdjf89/odpDso+?= =?us-ascii?Q?W+WmJDZ0yMb/XansRnJhF/JI8ra0DshofO1Kb5xun81eKNQ9Wffh7bPfjkUR?= =?us-ascii?Q?WsklSIxc=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0716; 5:6YPodXO1quNbq8E/8NoMxuj/3TNnSBYJJsvRsNp6mDvMF4QgTlLEPEuPCx0EACA3N/xW+L7GHvUa83zPQfRLPzg6DplcWGeV6cjAMTZIP67shO6jANhkTSChMKP7Xxu0OJBuZpXcpKOm03Q5Kxsps9ILQapaSRofVo065pWRzn0=; 24:4yzE4d7Qn7lPs6YFheS2I+NQZI3ebgGbudA/iJMws/UJPeplPkoAninz/XzR7sp2zH9En4148aJGMTYDEVP400+jWo/u3Sk4AYUABOJDdr8= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2016 17:37:18.5757 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB0716 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.9 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 Handle host and regulator signal voltage switch separately. Move host signal voltage switch code into a separated function sdhci_do_signal_voltage_switch() first, the following patches will remove the regulator voltage switch code and use the common mmc_regulator_set_vqmmc() instead. Signed-off-by: Dong Aisheng --- drivers/mmc/host/sdhci.c | 97 ++++++++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 40 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 839aa4c..7f63f5d 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1657,19 +1657,10 @@ static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable) spin_unlock_irqrestore(&host->lock, flags); } -static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, - struct mmc_ios *ios) +static int sdhci_do_signal_voltage_switch(struct sdhci_host *host, + struct mmc_ios *ios) { - struct sdhci_host *host = mmc_priv(mmc); u16 ctrl; - int ret; - - /* - * Signal Voltage Switching is only applicable for Host Controllers - * v3.00 and above. - */ - if (host->version < SDHCI_SPEC_300) - return 0; ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); @@ -1679,15 +1670,6 @@ static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, ctrl &= ~SDHCI_CTRL_VDD_180; sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); - if (!IS_ERR(mmc->supply.vqmmc)) { - ret = regulator_set_voltage(mmc->supply.vqmmc, 2700000, - 3600000); - if (ret) { - pr_warn("%s: Switching to 3.3V signalling voltage failed\n", - mmc_hostname(mmc)); - return -EIO; - } - } /* Wait for 5ms */ usleep_range(5000, 5500); @@ -1697,20 +1679,10 @@ static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, return 0; pr_warn("%s: 3.3V regulator output did not became stable\n", - mmc_hostname(mmc)); + mmc_hostname(host->mmc)); return -EAGAIN; case MMC_SIGNAL_VOLTAGE_180: - if (!IS_ERR(mmc->supply.vqmmc)) { - ret = regulator_set_voltage(mmc->supply.vqmmc, - 1700000, 1950000); - if (ret) { - pr_warn("%s: Switching to 1.8V signalling voltage failed\n", - mmc_hostname(mmc)); - return -EIO; - } - } - /* * Enable 1.8V Signal Enable in the Host Control2 * register @@ -1728,18 +1700,63 @@ static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, return 0; pr_warn("%s: 1.8V regulator output did not became stable\n", - mmc_hostname(mmc)); + mmc_hostname(host->mmc)); return -EAGAIN; + default: + /* No signal voltage switch required */ + return 0; + } +} + +static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, + struct mmc_ios *ios) +{ + struct sdhci_host *host = mmc_priv(mmc); + int ret; + + /* + * Signal Voltage Switching is only applicable for Host Controllers + * v3.00 and above. + */ + if (host->version < SDHCI_SPEC_300) + return 0; + + ret = sdhci_do_signal_voltage_switch(host, ios); + if (ret) + return ret; + + if (IS_ERR(mmc->supply.vqmmc)) + return 0; + + switch (ios->signal_voltage) { + case MMC_SIGNAL_VOLTAGE_330: + ret = regulator_set_voltage(mmc->supply.vqmmc, 2700000, + 3600000); + if (ret) { + pr_warn("%s: Switching to 3.3V signalling voltage failed\n", + mmc_hostname(mmc)); + return -EIO; + } + + return 0; + case MMC_SIGNAL_VOLTAGE_180: + ret = regulator_set_voltage(mmc->supply.vqmmc, + 1700000, 1950000); + if (ret) { + pr_warn("%s: Switching to 1.8V signalling voltage failed\n", + mmc_hostname(mmc)); + return -EIO; + } + + return 0; case MMC_SIGNAL_VOLTAGE_120: - if (!IS_ERR(mmc->supply.vqmmc)) { - ret = regulator_set_voltage(mmc->supply.vqmmc, 1100000, - 1300000); - if (ret) { - pr_warn("%s: Switching to 1.2V signalling voltage failed\n", - mmc_hostname(mmc)); - return -EIO; - } + ret = regulator_set_voltage(mmc->supply.vqmmc, 1100000, + 1300000); + if (ret) { + pr_warn("%s: Switching to 1.2V signalling voltage failed\n", + mmc_hostname(mmc)); + return -EIO; } return 0; default: