From patchwork Tue Apr 11 05:10:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangbo Lu X-Patchwork-Id: 9674569 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 986E060381 for ; Tue, 11 Apr 2017 05:25:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87B1E28450 for ; Tue, 11 Apr 2017 05:25:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C909284DA; Tue, 11 Apr 2017 05:25:25 +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 6234D28450 for ; Tue, 11 Apr 2017 05:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752179AbdDKFZX (ORCPT ); Tue, 11 Apr 2017 01:25:23 -0400 Received: from mail-sn1nam01on0080.outbound.protection.outlook.com ([104.47.32.80]:57642 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753440AbdDKFZU (ORCPT ); Tue, 11 Apr 2017 01:25:20 -0400 Received: from BN3PR0301CA0023.namprd03.prod.outlook.com (10.160.180.161) by CO2PR03MB2279.namprd03.prod.outlook.com (10.166.92.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1019.17; Tue, 11 Apr 2017 05:25:14 +0000 Received: from BY2FFO11FD038.protection.gbl (2a01:111:f400:7c0c::100) by BN3PR0301CA0023.outlook.office365.com (2a01:111:e400:4000::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1019.17 via Frontend Transport; Tue, 11 Apr 2017 05:25:13 +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 BY2FFO11FD038.mail.protection.outlook.com (10.1.14.223) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1019.14 via Frontend Transport; Tue, 11 Apr 2017 05:25:12 +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 v3B5P7p8017167; Mon, 10 Apr 2017 22:25:10 -0700 From: Yangbo Lu To: , , Adrian Hunter CC: Xiaobo Xie , Yangbo Lu Subject: [v4, 1/5] mmc: sdhci-of-esdhc: add peripheral clock support Date: Tue, 11 Apr 2017 13:10:27 +0800 Message-ID: <1491887431-31894-2-git-send-email-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.1.0.27.g96db324 In-Reply-To: <1491887431-31894-1-git-send-email-yangbo.lu@nxp.com> References: <1491887431-31894-1-git-send-email-yangbo.lu@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131363619131175831; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(39850400002)(39380400002)(39410400002)(39860400002)(39400400002)(39450400003)(39840400002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(9170700003)(6666003)(106466001)(85426001)(2950100002)(105606002)(230783001)(5003940100001)(305945005)(38730400002)(8936002)(81166006)(54906002)(8676002)(189998001)(356003)(33646002)(53936002)(77096006)(86362001)(50226002)(48376002)(76176999)(50986999)(36756003)(5660300001)(104016004)(8656002)(4326008)(50466002)(2906002)(47776003); DIR:OUT; SFP:1101; SCL:1; SRVR:CO2PR03MB2279; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:ovrnspm; MX:1; A:1; PTR:InfoDomainNonexistent; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD038; 1:3Og34qfZKPkzzftAznnk9LAMCjzjVJz52nfSz4A13ViZb8zsNCmfRxxHt9UQlTE9P1flOhWpQKJWpHZDuF2mF4fSWPU6x5x/y2hgF5OuifJ9i9iiTSGH0NrCGYJyUxnmhDvks5MFHVm64hMA5oOwWF828bZC8dOnBU5029M9KD8iLCtHSMlItAUP8C+Gs4Ltu+Bv9hIcvCJ+V9zjSQ6/eWOcGgPUf3cRGfFWYrRNX82hfkNxxOsMDMsfB4QEEzE7+cOLv37VCVaz50hMd2EepZGNTkU+VH2//qZtbrlL4kSNuHbmu6JAoLbLv62wZY7uFs48fP6noMg3f7Qv332vTi+XLummIkuAv9O5S4qMwHXmjdj5LklFoy5Vtpb2i7tttxK4lquXvetVbWRKrABSl8w/ii+3Ud4DPPtmO+e0Kmz04aA2/UcVPFQnn+5pMLJ0AQ7mx3HsMjoUiDWZm0+S8P84aTmcSJ92ji6vwPaUyYuCmcDllU8gov5WObhICkOS/XZZdvcmVsdwPQCy//lzVS0XsH8+tm9+xZAR16bHKNrAGmpt8MRNt8LKHYZxBBjXIksXHhtE7RT07MinifNp/wdi/N5+TlwDVSs8zyZqUB3wyKWlceeReu1yHUdLMVRWhTDjgceSlLVrQNwc2yg0C2LrHdHoIX9+2RVLseVAWsaW8xPqJpuJ5UD7ZRUHz3nIGcQMOBKGxnNdKVeUTmz3GX9ct4/RpstYMvB9pTFgAUaWfRo4FdsD1m5wwAngIjZb9iqWcLQKyHSGH6eNgRfNLQ== MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 3e013929-c9f1-4c6b-3397-08d4809b2130 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131430075)(201703131517081); SRVR:CO2PR03MB2279; X-Microsoft-Exchange-Diagnostics: 1; CO2PR03MB2279; 3:X0qAVB04eFQ0naz1tMazvOWC8S/P2lzD0CqUd81zhiNCEC0bw184RAeag35mPAjwoWVw7qr+KAlm209Cpkdu64npQP1KDvEpGmOvyTquBTKAr0dCwQVddeLbT6GUZtvKJK04KWBBwOZVZWOVASTSA6xxh2KwmnwxKzMvxJze3c/hEnB53ytxdBnnto67D+bAgbxoMYPLuJD8Se7SrzGTnmMbR+RPQm8z8Iqlt/vOHdaDGInb8HDqhPmKS1MCNlHc5ddmVPHQrQFjUmJ7t79NybuOyLtGhKKAe+GKMI9Rd44exV/3eJ1ouWm3u9jqUcFrodxNjSe8CzQcdYjsKZFkmynzn9XSgXxkaiYkuPwrNPAO8Ldyr+VNxkfy9SzlEHy19k7Ig3rGu/NoLE+Ma5SGFIIeqmbUjgh6OWcHPlWrHHyFEwzqu+x0kq3d40HHi24R; 25:paLmW0DX+ERF6418p28igTQKd4ZRD4OTigjiWQx7QuVwzlPEyL5oSWsz3RN2/XpjVCMAWUxm64XXKisbsI2pLwNtvk/jTdHglD1p2Xd00jatgsVtQEoTVJBKBbTd6qZga1yLIi28OIgb0IiXv7VAmrSxsuDmOnlx5qvBX859q16tTZKQyWqrRKeR5yauumZYGj0sSQK8LEryJ+o9Rt+DFYf067ZPUBrzU8CIuaJE1zaZ56HBitIjuVU0YzE0TzxyGZnvpY/fpqzOS2Fpwm40O8NTaJh1z7ahu2wPvSVAHxBmpYAnaBrXp0Wy550cXLN0SLHnC7u6EZnVPK1lIFG00rgd6a1YIOT0JXO7hSEukZJ43V9T8NYebpSjHyZEidpB67wUYtghBEgoFszAH8Ch/T1QY+IFGkoNmn0UbA1gPOSlPrlNXAJBEykbWMTLPRZBcZiZcaJISA0kBRqU9lZpJg== X-Microsoft-Exchange-Diagnostics: 1; CO2PR03MB2279; 31:esQfbR7DOBhHFwDcfEdIUqMrH86clsIsVMl0v+5gpNVC2qEEmjIDT+NQ2DLiIkC6mkMxEpcvuiME8DoMXfwRl0g5KnsfS4unYhVcffFELFfYXEo3wnkjozli30mSWC40HXF2QAyDDULf/q8Lur4K/jXyiJ3aT3J5omVzD8pqtpYwpft2i4QFwfAWYPWPXOlfOGRK6xOFJv1to0Z4wRc8ijrTCYhzmCJKclLieDQFZ3Lbg0Cp/M86EXVupbJsVcFn5Z+cJtzZK6gLFzkuWe9SpfFjGE0OhUfQ7Mu1h7PDZ/s= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095135)(601004)(2401047)(13017025)(13018025)(13024025)(13023025)(13015025)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(6055026)(6096035)(201703131430075)(201703131441075)(201703131448075)(201703131433075)(201703161259075)(20161123561025)(20161123556025)(20161123563025)(20161123565025); SRVR:CO2PR03MB2279; BCL:0; PCL:0; RULEID:(400006); SRVR:CO2PR03MB2279; X-Microsoft-Exchange-Diagnostics: 1; CO2PR03MB2279; 4:0jIwwae1l8U55qyhTfaP6ulauJIEjCsOQS04k7A/S8HB08VacsegIeCe7XDeWVU2T7jWti52xIBm7LyoX9OEsS6jJMCyccokou6eSZA6ZC3HOakhSXyfl72JBqMiG5oOshMdfk8nZsmNrM6YEAg7g+7ct9NIvWhQm3i5o7i2Swgxbp7oja0ykqIDJpA+cfi9aSpVpfY1FyS92pW6XqX22SSNGHT2t0A/R6S6kDQvi3MTdz8kiAoRAs5MnJRd7kQiqbn83kvBEChgRzmxTOKot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QSwDbRXLvqoJ+jEKRQU9FQS+CyjA5Thr9GNyy3LoXErkgipxSdMbTEBKhQPrlKgrUmsTGEhozby4aT/qde1PUxfyuKw/kZt2KuGyllhOzPUN4H1Pa+VkeDnXh6Ysb9gZTXli1Xm1lIb/KH/tgf0c6cmXVwX2od19kdoLS9wqX3HNING5/bJJLsR13c0fVZmvrz+Ze+fZUmIBvzsJut3RyI34INGqOAfrPRK+YCWGwP6LdjF84DPs+FxtqA90fTcLme2mylnMV0cQ8ww== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2017 05:25:12.9303 (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: CO2PR03MB2279 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 eSDHC could select peripheral clock or platform clock as clock source by the PCS bit of eSDHC Control Register, and this bit couldn't be reset by software reset for all. In default, the platform clock is used. But we have to use peripheral clock since it has a higher frequency to support eMMC HS200 mode and SD UHS-I mode. This patch is to add peripheral clock support and use it instead of platform clock if it's declared in eSDHC dts node. Signed-off-by: Yangbo Lu Acked-by: Adrian Hunter --- Changes for v2: - None Changes for v3: - None Changes for v4: - Added clk_put() - Used udelay() to poll ESDHC_CLOCK_STABLE --- drivers/mmc/host/sdhci-esdhc.h | 1 + drivers/mmc/host/sdhci-of-esdhc.c | 72 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/sdhci-esdhc.h b/drivers/mmc/host/sdhci-esdhc.h index ece8b37..5343fc0 100644 --- a/drivers/mmc/host/sdhci-esdhc.h +++ b/drivers/mmc/host/sdhci-esdhc.h @@ -54,6 +54,7 @@ /* Control Register for DMA transfer */ #define ESDHC_DMA_SYSCTL 0x40c +#define ESDHC_PERIPHERAL_CLK_SEL 0x00080000 #define ESDHC_DMA_SNOOP 0x00000040 #endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */ diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c index ff37e74..6d024b6 100644 --- a/drivers/mmc/host/sdhci-of-esdhc.c +++ b/drivers/mmc/host/sdhci-of-esdhc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "sdhci-pltfm.h" #include "sdhci-esdhc.h" @@ -30,6 +31,7 @@ struct sdhci_esdhc { u8 vendor_ver; u8 spec_ver; bool quirk_incorrect_hostver; + unsigned int peripheral_clock; }; /** @@ -414,15 +416,25 @@ static int esdhc_of_enable_dma(struct sdhci_host *host) static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host) { struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); + struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); - return pltfm_host->clock; + if (esdhc->peripheral_clock) + return esdhc->peripheral_clock; + else + return pltfm_host->clock; } static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host) { struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); + struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host); + unsigned int clock; - return pltfm_host->clock / 256 / 16; + if (esdhc->peripheral_clock) + clock = esdhc->peripheral_clock; + else + clock = pltfm_host->clock; + return clock / 256 / 16; } static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock) @@ -512,6 +524,33 @@ 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); @@ -613,6 +652,9 @@ static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host) { struct sdhci_pltfm_host *pltfm_host; struct sdhci_esdhc *esdhc; + struct device_node *np; + struct clk *clk; + u32 val; u16 host_ver; pltfm_host = sdhci_priv(host); @@ -626,6 +668,32 @@ static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host) esdhc->quirk_incorrect_hostver = true; else esdhc->quirk_incorrect_hostver = false; + + np = pdev->dev.of_node; + clk = of_clk_get(np, 0); + if (!IS_ERR(clk)) { + /* + * esdhc->peripheral_clock would be assigned with a value + * which is eSDHC base clock when use periperal clock. + * For ls1046a, the clock value got by common clk API is + * peripheral clock while the eSDHC base clock is 1/2 + * peripheral clock. + */ + if (of_device_is_compatible(np, "fsl,ls1046a-esdhc")) + esdhc->peripheral_clock = clk_get_rate(clk) / 2; + else + esdhc->peripheral_clock = clk_get_rate(clk); + + clk_put(clk); + } + + if (esdhc->peripheral_clock) { + esdhc_clock_enable(host, false); + val = sdhci_readl(host, ESDHC_DMA_SYSCTL); + val |= ESDHC_PERIPHERAL_CLK_SEL; + sdhci_writel(host, val, ESDHC_DMA_SYSCTL); + esdhc_clock_enable(host, true); + } } static int sdhci_esdhc_probe(struct platform_device *pdev)