From patchwork Thu Sep 21 08:43:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangbo Lu X-Patchwork-Id: 9963573 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E254B6056A for ; Thu, 21 Sep 2017 09:01:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4CEC2941A for ; Thu, 21 Sep 2017 09:01:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C99E92942D; Thu, 21 Sep 2017 09:01:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39DBC29429 for ; Thu, 21 Sep 2017 09:01:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751840AbdIUJBD (ORCPT ); Thu, 21 Sep 2017 05:01:03 -0400 Received: from mail-by2nam03on0048.outbound.protection.outlook.com ([104.47.42.48]:55156 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751764AbdIUJBB (ORCPT ); Thu, 21 Sep 2017 05:01:01 -0400 Received: from MWHPR03CA0032.namprd03.prod.outlook.com (10.174.173.149) by DM5PR03MB2699.namprd03.prod.outlook.com (10.168.197.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Thu, 21 Sep 2017 09:00:59 +0000 Received: from BY2FFO11FD041.protection.gbl (2a01:111:f400:7c0c::147) by MWHPR03CA0032.outlook.office365.com (2603:10b6:301:3b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.56.8 via Frontend Transport; Thu, 21 Sep 2017 09:00:59 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD041.mail.protection.outlook.com (10.1.14.226) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.35.14 via Frontend Transport; Thu, 21 Sep 2017 09:00:58 +0000 Received: from titan.ap.freescale.net ([10.192.208.233]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id v8L90tJA015780; Thu, 21 Sep 2017 02:00:56 -0700 From: Yangbo Lu To: , , Adrian Hunter CC: Yangbo Lu Subject: [v2] mmc: sdhci-of-esdhc: disable SD clock for clock value 0 Date: Thu, 21 Sep 2017 16:43:31 +0800 Message-ID: <20170921084331.23169-1-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.14.1 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131504580590298338; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(979002)(6009001)(336005)(39860400002)(39380400002)(376002)(346002)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(104016004)(356003)(2906002)(68736007)(48376002)(33646002)(97736004)(1076002)(50226002)(498600001)(105606002)(106466001)(85426001)(8656003)(86362001)(50466002)(77096006)(47776003)(16586007)(8676002)(230783001)(5660300001)(110136005)(6666003)(81156014)(189998001)(81166006)(50986999)(4326008)(53936002)(305945005)(5003940100001)(36756003)(8936002)(316002)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB2699; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD041; 1:oPpj5CNJx9DxplvKS3ytcus1/UXm+TPZt6AHMyVbkLTKK8Q5H6z0Yu/9t4qVjx0B0gHs6uJu/yXe9+IKGx9pwUpPEHOkIyUlm6xELcI/sgijG7iNl4KfqBQvyH/VbVVi MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e282f76b-66d5-4713-8385-08d500cf46e0 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(300000503095)(300135400095)(2017052603199)(201703131430075)(201703131517081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DM5PR03MB2699; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2699; 3:pR5H+zuL+j+HAwaYh1jhAZc7EyydqrRoSR5Bw/iVJR30sk4VTh5CZRZBPFl69l/P3yln1nKUqjFxK81yqrKR8XxlzBC0k3i0U1iSRqotiGYflJagB4OzNz+/MGS5a2tE3wOMUJUzFqgExtAXDKE5WfnlE9Gt6vr+jZj38+lsP2jxIwPjFYdR0bOHCAM/ekTlh5ifU+l+fhdV+cSMl3R1OJETV1KlZXtcf5wYhcLVP0BHlaPboR3a3oprKYinlrj5e6rzMOlXlZFpDFTXA1iVQ6VyRVSJ67dxwxdZMoMoxARZIGT7Gxt6Ys7lXIRsB/2I1T1yC9l27f3ERNdebYH8u89UiDY1L5+t9g5E5kxiMkA=; 25:wTiWak7b0awHEq7RtXjVOF91lv5d51AXMzlHI8I8LvGKRdBul2oC/Jhq4Wvu0yGbJg06K7YXxRerNg+upyfSFbKGfoenOc/DXuw1dOthi7RtiMGlPzEUMm6wJ3Cu70IavBV9l2IB0C7zsOeTdYE7vpzdNOWeCsMjigJgorcxMzfUKcEPrbjoaUXe2CwXnTI96pdScnI/JmaFiNecZ1cbQRSXPYpsVbiHI0mowxdw5qBjY4xHE7ZDW95AqRdTx+1aFGmkNuZzstWVIwN3AsveWNhyuwh5EzhsaGYkf1ELRZOUv1eERjQ+o54L9jijpRgQ+WYoCZnwflcM4HP2ZgF3xg== X-MS-TrafficTypeDiagnostic: DM5PR03MB2699: X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2699; 31:h9NO8EBNR6rD0o0YLVEm9zADF7UR5iY5IXFdGrCYO3V/plTupL/pczLO/wXoTXkaKqghH14+zFHxkIp067EIqIo/hNJ8KpGH0tR2Y8TBJ8xcKHIkWufvB3ZM5Px0quSYTt9DwbJ5MYIAyOrHnhDJdfwzj54xmhkyQji/7GKh+L53Uxd+PNEJSxggmBDCPsjI0cEVOHREqmUn/z35bZppREXL4HgGWY3Felml6rfT/Mw=; 4:pwSVKwTTq2q+rmsoxvE3VX7U9USzOzP34ramJEBgraazdMEri75V9tcU2CZAHFq1s9hlbPDdxN+Oa9E3SgLWwyIpIUTtS4J5zo+elFz2s+0vbAIHHojTDhb9oDdlKHgTWNcv7DGb4Va6Ev8xs0P9J04ysKh5WhraAg1cn44n4z/m0TeBtjX77zGb5QQ5SFd8X76jJvXdkMI00bmR4xEGBoTdhiJSVdgstYopgaG5ZF/CnqXkloJc+PvNathRQ1QJ2VJQU0GYc1ohKw6Brs0dxEoLDS7SbKd6cqLvrcl4hlAppClu95rITEiZnLGgtUXv3LAGNnIsjYwuyTZEy7bOJg== X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(228905959029699); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(6055026)(6096035)(201703131430075)(201703131448075)(201703131433075)(201703161259150)(201703151042153)(20161123565025)(20161123563025)(20161123559100)(20161123561025)(20161123556025)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM5PR03MB2699; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM5PR03MB2699; X-Forefront-PRVS: 04371797A5 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR03MB2699; 23:vmoy7fs0QY4cg6EHLtMTe5fPEQyv20+84ZAtN34Ny?= =?us-ascii?Q?Ll5t30MzvkSdnOYgOPT5CebRFQjOA52VYEkcjhfS1ZD4gnDmxEU5j1CdETKL?= =?us-ascii?Q?TxW4AA+CSW6zijQt+WCQkqlp1Of8icMQBqzSHY2MzuQyvsMBhMRcac1JubTD?= =?us-ascii?Q?Hqn7VRQlkFwPAqpgph5m+AmmfEZ+qDq3DOgo2/bL6GqR0TFo0mAEVTpAAfn1?= =?us-ascii?Q?HSXxbx9DKcx7BAahuujB4ODOjQAMjGQOB38rWW+mkvxI1SeedoUFaCncHrP0?= =?us-ascii?Q?kO/OKUHSdBy5yxeCBZ3yPhJujbu86sswFabsVH3PtAiKZaIisnAQ75YNDLNS?= =?us-ascii?Q?gPZZBz1+3Hyj9HhSIcDQ5MejOA1ZkrgGHLPv3RLbHntdmnQAyl0miYRLntld?= =?us-ascii?Q?Q68G6FB62ODx89IsHGORYsWHAIb2ur36LRkgbEaAc63zPEG9n7ffoTs5IgzX?= =?us-ascii?Q?ADICvyRnFd/P/Bq2AGe/3AdCipfXy7OLYXEwGOTPKQYM54jS6tfETFaaFOGa?= =?us-ascii?Q?Tsl4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pNFwOsEj/T0b9T3LAB9HJYDm0tMzjzA6oEiAzOYAj8BhgLYrVys8gIGH0ocoN1mcazbmvzxSH2uNMcHWSge3gHxg4bx5An6yOBpWWs5JbqJ57L+9mDw2/S2FYChdFP09tEfmrtUMfadyHj+hUX7M4YEFtnVIQ==; 5:YsozZ5L1xYXdZLE9KWIS09zya+E3jm2lLwkHQXQyBUNlUMj3Y5LbDk44xoSBnduHatUdzXsBYBG18+kD0BpfpT9PZ4TsT4h9wtqMkDuAzerJD7cu5xBe3SHZlQgkFbHFXuZzzykgNoUOAMDDDAwpbQ==; 24:ZUcnd/mW7YkcVnvDub4+HSqeT9sv6bVShY8Q1885Dloo/tidqK+TI4IrRRc9EXzq+1cVIJ8HZVoT7wzK2KqL5ts1a0BylSC4KsC481LBQFs=; 7:0Wqwyy2tINi5rNoGeVF+KXkeK2eaQAQXVDF4Txo5o8eWB8vN6sa0Q2lbzcC4ziTaP5yzf82xAXLnAE7g8IRbFrLfcQ/nfXxeFR5XH9O73dWWKBcAXc6MhhYvKhpYaPrso0jPfiM+nrIdiJEpEo1w7EQLPp9Oo4RWP8fBgq7Gv7+VbP4f1g+XHbCUV1G65wVjynN96r3u9l1hnjw7SvD7EEffeeytYozehXCJ8S+zdRc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2017 09:00:58.8270 (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.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2699 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP SD clock should be disabled for clock value 0. It's not right to just return. This may cause failure of signal voltage switching. Signed-off-by: Yangbo Lu Acked-by: Adrian Hunter --- Changes for v2: - Moved esdhc_clock_enable() instead of forware declaring. - Added "Acked-by: Adrian Hunter". --- drivers/mmc/host/sdhci-of-esdhc.c | 58 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c index d96a057a7db8..1f424374bbbb 100644 --- a/drivers/mmc/host/sdhci-of-esdhc.c +++ b/drivers/mmc/host/sdhci-of-esdhc.c @@ -458,6 +458,33 @@ static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host) return clock / 256 / 16; } +static void esdhc_clock_enable(struct sdhci_host *host, bool enable) +{ + u32 val; + ktime_t timeout; + + val = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); + + if (enable) + val |= ESDHC_CLOCK_SDCLKEN; + else + val &= ~ESDHC_CLOCK_SDCLKEN; + + sdhci_writel(host, val, ESDHC_SYSTEM_CONTROL); + + /* Wait max 20 ms */ + timeout = ktime_add_ms(ktime_get(), 20); + val = ESDHC_CLOCK_STABLE; + while (!(sdhci_readl(host, ESDHC_PRSSTAT) & val)) { + if (ktime_after(ktime_get(), timeout)) { + pr_err("%s: Internal clock never stabilised.\n", + mmc_hostname(host->mmc)); + break; + } + udelay(10); + } +} + static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock) { struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); @@ -469,8 +496,10 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock) host->mmc->actual_clock = 0; - if (clock == 0) + if (clock == 0) { + esdhc_clock_enable(host, false); return; + } /* Workaround to start pre_div at 2 for VNN < VENDOR_V_23 */ if (esdhc->vendor_ver < VENDOR_V_23) @@ -558,33 +587,6 @@ static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width) sdhci_writel(host, ctrl, ESDHC_PROCTL); } -static void esdhc_clock_enable(struct sdhci_host *host, bool enable) -{ - u32 val; - ktime_t timeout; - - val = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); - - if (enable) - val |= ESDHC_CLOCK_SDCLKEN; - else - val &= ~ESDHC_CLOCK_SDCLKEN; - - sdhci_writel(host, val, ESDHC_SYSTEM_CONTROL); - - /* Wait max 20 ms */ - timeout = ktime_add_ms(ktime_get(), 20); - val = ESDHC_CLOCK_STABLE; - while (!(sdhci_readl(host, ESDHC_PRSSTAT) & val)) { - if (ktime_after(ktime_get(), timeout)) { - pr_err("%s: Internal clock never stabilised.\n", - mmc_hostname(host->mmc)); - break; - } - udelay(10); - } -} - static void esdhc_reset(struct sdhci_host *host, u8 mask) { sdhci_reset(host, mask);