From patchwork Thu Apr 20 08:14:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangbo Lu X-Patchwork-Id: 9689875 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 20A6A600C8 for ; Thu, 20 Apr 2017 08:29:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1072E223B2 for ; Thu, 20 Apr 2017 08:29:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04EE328459; Thu, 20 Apr 2017 08:29:55 +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 5BDA7223B2 for ; Thu, 20 Apr 2017 08:29:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967573AbdDTI3w (ORCPT ); Thu, 20 Apr 2017 04:29:52 -0400 Received: from mail-co1nam03on0062.outbound.protection.outlook.com ([104.47.40.62]:23714 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S967402AbdDTI3q (ORCPT ); Thu, 20 Apr 2017 04:29:46 -0400 Received: from BY2PR03CA055.namprd03.prod.outlook.com (10.141.249.28) by CY1PR03MB2394.namprd03.prod.outlook.com (10.167.8.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.10; Thu, 20 Apr 2017 08:29:43 +0000 Received: from BN1BFFO11FD036.protection.gbl (2a01:111:f400:7c10::1:142) by BY2PR03CA055.outlook.office365.com (2a01:111:e400:2c5d::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1047.13 via Frontend Transport; Thu, 20 Apr 2017 08:29:43 +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 BN1BFFO11FD036.mail.protection.outlook.com (10.58.144.99) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1019.14 via Frontend Transport; Thu, 20 Apr 2017 08:29:42 +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 v3K8Tbd0002714; Thu, 20 Apr 2017 01:29:40 -0700 From: Yangbo Lu To: , , Adrian Hunter CC: Xiaobo Xie , Yangbo Lu Subject: [v5, 1/5] mmc: sdhci-of-esdhc: add peripheral clock support Date: Thu, 20 Apr 2017 16:14:40 +0800 Message-ID: <1492676084-28218-2-git-send-email-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.1.0.27.g96db324 In-Reply-To: <1492676084-28218-1-git-send-email-yangbo.lu@nxp.com> References: <1492676084-28218-1-git-send-email-yangbo.lu@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131371505831838642; (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)(39380400002)(39860400002)(39850400002)(39400400002)(39410400002)(39840400002)(39450400003)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(9170700003)(47776003)(104016004)(5660300001)(106466001)(4326008)(189998001)(2906002)(77096006)(85426001)(8656002)(230783001)(105606002)(86362001)(76176999)(50986999)(53936002)(54906002)(356003)(33646002)(38730400002)(305945005)(5003940100001)(8936002)(36756003)(50226002)(2950100002)(8676002)(50466002)(81166006)(48376002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR03MB2394; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:ovrnspm; MX:1; A:1; PTR:InfoDomainNonexistent; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD036; 1:9/CHUAPxaGJ24NDcBgYkfJgot3IBpNe9lfJnH7WEafWOcJwddr3K4BsDR4nQcY9yTs+/wOxgJku7AsB8+AMM6Ca8thxZdTx5NSB1luZw+PvQH3Lp/657lnP81tQBinUwgSzM8R+2fDxxdKbgBfnw4nAQ3ufAttEu8Apar5tIdA/Hk6J1xvPUFw6PClYPLQ8AJJYqXf8plLwogZNrrbyCZNia0F58XijD45R1jKg4zdBFtxRWKmaea/M08eis7zFrPx/PrN+YcEMIzHAXgrUkidfuUWTd8/KHwhXpwdfVI7Zog6d6E49sShUc5/vhAm3OgTONmHpn+vrs1LhnBZ0ygQasT0A516VA+LmILgAQ7DWYuuIL7ooQHuSs4aHMtBNzpvVzdCixoGTms+20B6XH8l639NErZKJ9D/2bynxAf+Xk58KvOBcVwtgyGX7qtla8FALGCQhCdiQdaF/FO/ZdIKEz5j9EnwPagAufIsgBtuJyaJ5/rP2cOzGCu36KckvK1hi0iW98YioJav6xTmXkU0PKRvU2gcV4Ilyf3/iHdK1NZZ/kPnXyLE0f+zHuG7WvuptmE0e7CDXr6o/yJ2+BrmUPpMiFsY5LitSDfm4RM+O/f45WLAvj+TyWqe19LkmsymsNc2LJXGQSJrt8VYU+p3Kx/60WEVmj0/xL+N1nT1P4kWmNnQ9uDbsiCBRB+zOrSNmVP8Yep9QQwn7x06q77pC1KmsD1QKZmN7DWcvgdh47s5wvCWVv0pmd/NIR+2YXLHXxuKOw2yvw5Ww/kca5VQ== MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ce2f4245-05b9-4377-a251-08d487c7652b X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131430075)(201703131517081); SRVR:CY1PR03MB2394; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2394; 3:+VBEvSATAD5JgbeAIJV40QDg7YqipnkvHz4quaryHDPbyZiXzkhgtuIQ2Du2yznNDSNBnDf2V5c4lykZaSuDeNLRcjeNu6z2regg5GSkF8XksKkXuBnYAhULDO4JWlzLoEI4vwA89QNty+6C53gFRoyczMy9vneKwE72y964cjvR54yorWatz3kUE18XbiiGP4HgOQ8G3TsKCYImYFDWkl2ydS6V1IUHgWRFw3U+kicumZ3laZaYC2tEPoTkimhaCes165mfaACHuwuKIPmKBaLYjKj/GWUb8iV8NeakiV1U1H1JKauZ9JL50T42sPywl97yQyXNK8m30PaNv0pl6lUsuAzzi5g+fusIgReNOPMwqo1oClQ19F5Kv4ao/x5K2IBKtWTxRpnuS4RplNNxMa354HB8VLcc5F7TvymH4rk8Jllxx6KZu25QiZWnwBcF; 25:n4yMVRNbAex2w4qqFBOCyEoaiMIvrV0q1wx3EvjiIrA16ixgTZ2tWAeUjaSBgV8lDUqUsDEAEQnzKfCrf+OR3byVq//FTPtV8sQ356BI8b/Y9Hjt3k/GpnKQCzgLK1RNeaQq1KzPMNwp6Y1F11Xw7ytDYS95aGUZnqcGSGQdd7jJrBHGBDl1xUq35v2OAVXR7LeABAGf4/WRfUfbsyR0wSFRVHBLxxiQJN+/WoB4vFS0kZOIANfT8ljSV157AOwsaR7+/buT7v0XVdI6eyWWTJe1rLd/mcxxZXeo6Lg3DBwm5H3vBEgVN6PvglGOai1TtEjP28N5O0lg7eDKzwuERLgQDdvZ0hOtB4LLboDPBPure+kHEItYE1DrY5Zcuz/iTszUuRKWOEFvWWcccI7gw0djSdrwrhNVYCWmTWGC3N8BH6jAq/wL08SgdTPzGxRIqE7r1O00uO8xf1/aaMPgmw== X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2394; 31:Kud3Cfxc//37RWL+6q1VbmGZwHnQbyX5tkF+v/EBR2KvJHnK3o+hwuMCZ1IQYwhOrBF3grZSnT8BUg80ASd0PVtbN4PLcsFmzw6qmf02hFMfESdz11fK6eX+3kBzkRPxGxdAHZPQxAgCIqtzaPzlfqFoZR8dlxSiglnyZquhk9liSS/yOis6qtZn2IS0L7y0wsJecN7WkGDJrI0XeCNf1KuyxK9vZptFAbSWK8kBdp+C/9LvVBw1U4jep0VMf8TNfDeCMPRGAp5oenGtm5R6tA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095135)(601004)(2401047)(13017025)(8121501046)(5005006)(13015025)(13023025)(13024025)(13018025)(93006095)(93001095)(3002001)(10201501046)(6055026)(6096035)(20161123561025)(20161123565025)(20161123556025)(20161123563025)(201703131430075)(201703131433075)(201703131448075)(201703161259150); SRVR:CY1PR03MB2394; BCL:0; PCL:0; RULEID:(400006); SRVR:CY1PR03MB2394; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2394; 4:mhESl38X4qOrzCY/mLhO/ZlQxQSkebWzqdNoJ/A4GH5v89Oy3ULAx1MgtB9lHEkk+ooOGmjmGOkN0TcAJosdt3mqE7JPntLre/oJIDNgYbOE2Kvq/EEJQ8ZzOSqaoxl3BtxeFqkugnwx8CWNfwvBw2pixzLrfnjY8RAzhKUGmJsSu/cZoyQFNIVfUhxci+3+3jgaWYgaqHB21kRiInhUnc9enBpy4oZWrK7TJ2nBX5faZ+sPsgfhaAKLrM/1qQ/+lEEKHaSqfyki3pWAKb8cnKHYXSZD3dbyvIDCF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ebOVU+ZmWDe9k4u3liWV9c4/o7rBwr+Nz3KH+sQzZhXb6K/PaE0Z/t3wrEitMEafS97yrDxWn+usolrzHopgXgVPZT9oUSRn0G5vLYsry9wWVhvAKIbJVPfociwvVCfz16zTLOQwkcaUx9zU0E2/gu7hjqhf+TKsQTZW2WaC5ADynlqRCkYlZSfWHMwR/pRZBf6kBWxjfBCMbc9uKs+y2/7ZoNmPETCtP/e2Iv85Y+skM11ghorpwgNw== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2017 08:29:42.9966 (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: CY1PR03MB2394 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 Changes for v5: - Included ktime.h - Added Adrian's ACK --- drivers/mmc/host/sdhci-esdhc.h | 1 + drivers/mmc/host/sdhci-of-esdhc.c | 73 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 72 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..0b3f05a 100644 --- a/drivers/mmc/host/sdhci-of-esdhc.c +++ b/drivers/mmc/host/sdhci-of-esdhc.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include "sdhci-pltfm.h" #include "sdhci-esdhc.h" @@ -30,6 +32,7 @@ struct sdhci_esdhc { u8 vendor_ver; u8 spec_ver; bool quirk_incorrect_hostver; + unsigned int peripheral_clock; }; /** @@ -414,15 +417,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 +525,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 +653,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 +669,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)