From patchwork Tue Jun 4 08:14:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 165714 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp5523395ili; Tue, 4 Jun 2019 01:15:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZ8afR8uD2pLtMM1ojJ6cpkJCO4HZCdUeruCRUTZt95klGVn6yt8xWB25Wvij67E+HjwFJ X-Received: by 2002:a63:4f07:: with SMTP id d7mr33107127pgb.77.1559636121374; Tue, 04 Jun 2019 01:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559636121; cv=none; d=google.com; s=arc-20160816; b=rZ3G27LDvfPHJZ3cieVDqUj5EfnfeF++X9oeun7Jt3ndghABbsEXpOisXXDZByFjrn crvPTtRy0me3uHRS+J/4lMF87dzOy2LZy4cgcorKNeNSMEXEZBGiIJAovkkLx0qBFUrL wJJHljcnYUEiLPBWhlv1qi+6jKkBUi6fu+Oyv+GNzTtwdNvFWqERqvzysD1vbAxVxyno sM71RvfrMvTE5984V3pA9t6qIrAkVCq5PuJMtnsQsEY9ei/4kTVmFGjNE3lqUW3CG+ck j1mNaEPboeGE19N5GTHMEoPAc5qXJR++edJ9iv85GhEXB8h74juqV/l63Lua0LiN05O9 l3tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=Fv2whIvWWtuvlrntuYk8WF1rR93EthhOFv6VYDGUqK0=; b=u7h5z16GLRgHL1plgz7Y6mX52fEwWEoDXi7UsnDUzEBd/8DYKpBB8ebRr5Vtp0MchU amRlYVjn1Dg7y/WJGQ8GrTWUb4mKep0/KGzZN4IW3H9pnOsmieAWwvFym95/ApI2WW0h y5JBRw5PGo31bslJQediG74CUVt/m4z/nro+NfTId+ywLUimYhvIqJNCFTYponD10MPM R9jgkwJ1xW++TJQenl2ug0ffpHwAKNSe5pX9vpyI8pGFB9MbztzSJt1spcvZmx9P2vhE 28/PCslrN1l8mAVZ+ChuCXs5sEbgKumuZ/LkLFpsgfkmsuXrMtudAfWr86o35B36aYBZ 1acA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H3U36xsC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v19si22021193plo.413.2019.06.04.01.15.21; Tue, 04 Jun 2019 01:15:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H3U36xsC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727179AbfFDIPU (ORCPT + 30 others); Tue, 4 Jun 2019 04:15:20 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36938 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727144AbfFDIPQ (ORCPT ); Tue, 4 Jun 2019 04:15:16 -0400 Received: by mail-pl1-f196.google.com with SMTP id bh12so1960137plb.4 for ; Tue, 04 Jun 2019 01:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Fv2whIvWWtuvlrntuYk8WF1rR93EthhOFv6VYDGUqK0=; b=H3U36xsCUdBFRm3KPZyTSWH//zyS50ZT4XZXXWDgwO3Va81kNw7pvlth33eG7dWzrH omDFCLKePr2nlgYtOe4W0MyTeJ4hTspfMvXK5YJB64ESExZnjLJlF4IykS6Q6+qbySr0 zZdBNXibIrWEfD6IroCEc0ndnzGDzqBeIt0hnnv2CuM8D9y+lSHrDjc1ZMTR/GHVCo8W t8xBkc6ke362zGEgylzJz4/lIqJ8LwGOolPoY+xSvA8VNzKy2m+syMXqzJNrYUu8XKZA IICbKWPnqI21SxfiOPG5/wasSwdfVBzvFuastyGFb12nknN9hTFgpcQM+85KeTbthNc6 gK/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=Fv2whIvWWtuvlrntuYk8WF1rR93EthhOFv6VYDGUqK0=; b=NNSLky/nIfm0LUIqB++IZu2rPK/cOIMHTDEJrLGckYtAmT8QLso6n2CpSRS07OhvG1 iT8tjFMEFlmCB5Y1J3CHR7bXbsudcz7/fd0t6XOju/hEqb+ZTX3jMCOeSDqMOqw5G1ny ayVeSzxiwt8u5ehW/hTBIgOvBQ7GGtm1U8wuDrG0oHxVt5dt+LoNqyHUZI940ggkzzWc Yx6DCozG9ksbK7dBFWfU3UOGehB3ngcWZnqIhypbRYBJI/7N91Lo+QYNPXIv+KGFTwgz zSfm9zmoKFrSOF+oDEmAvxBPx465Iwkr1Ua1c39fkTmCXNzH+lc89n169m/ctAnRkBEr WR8g== X-Gm-Message-State: APjAAAWY2dFjatA9UV7STHReETMOQBA2dg8jh5XB52Xf8VsNteNYWHdk tN4Vmxi8XQpqLbJ1M5MeKcoofw== X-Received: by 2002:a17:902:b584:: with SMTP id a4mr35666871pls.333.1559636116089; Tue, 04 Jun 2019 01:15:16 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id j4sm14818804pgc.56.2019.06.04.01.15.12 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Jun 2019 01:15:15 -0700 (PDT) From: Baolin Wang To: adrian.hunter@intel.com, ulf.hansson@linaro.org, zhang.lyra@gmail.com, orsonzhai@gmail.com, robh+dt@kernel.org, mark.rutland@arm.com, arnd@arndb.de, olof@lixom.net Cc: baolin.wang@linaro.org, vincent.guittot@linaro.org, arm@kernel.org, linux-arm-kernel@lists.infradead.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 6/9] mmc: sdhci-sprd: Enable PHY DLL to make clock stable Date: Tue, 4 Jun 2019 16:14:26 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For the Spreadtrum SD host controller, when we changed the clock to be more than 52M, we should enable the PHY DLL which is used to track the clock frequency to make the clock work more stable. Otherwise deviation may occur of the higher clock. Signed-off-by: Baolin Wang Acked-by: Adrian Hunter --- drivers/mmc/host/sdhci-sprd.c | 44 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) -- 1.7.9.5 diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c index edec197..e6eda13 100644 --- a/drivers/mmc/host/sdhci-sprd.c +++ b/drivers/mmc/host/sdhci-sprd.c @@ -22,6 +22,13 @@ /* SDHCI_ARGUMENT2 register high 16bit */ #define SDHCI_SPRD_ARG2_STUFF GENMASK(31, 16) +#define SDHCI_SPRD_REG_32_DLL_CFG 0x200 +#define SDHCI_SPRD_DLL_ALL_CPST_EN (BIT(18) | BIT(24) | BIT(25) | BIT(26) | BIT(27)) +#define SDHCI_SPRD_DLL_EN BIT(21) +#define SDHCI_SPRD_DLL_SEARCH_MODE BIT(16) +#define SDHCI_SPRD_DLL_INIT_COUNT 0xc00 +#define SDHCI_SPRD_DLL_PHASE_INTERNAL 0x3 + #define SDHCI_SPRD_REG_32_DLL_DLY_OFFSET 0x208 #define SDHCIBSPRD_IT_WR_DLY_INV BIT(5) #define SDHCI_SPRD_BIT_CMD_DLY_INV BIT(13) @@ -56,6 +63,7 @@ #define SDHCI_SPRD_CLK_MAX_DIV 1023 #define SDHCI_SPRD_CLK_DEF_RATE 26000000 +#define SDHCI_SPRD_PHY_DLL_CLK 52000000 struct sdhci_sprd_host { u32 version; @@ -200,9 +208,33 @@ static inline void _sdhci_sprd_set_clock(struct sdhci_host *host, } } +static void sdhci_sprd_enable_phy_dll(struct sdhci_host *host) +{ + u32 tmp; + + tmp = sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_CFG); + tmp &= ~(SDHCI_SPRD_DLL_EN | SDHCI_SPRD_DLL_ALL_CPST_EN); + sdhci_writel(host, tmp, SDHCI_SPRD_REG_32_DLL_CFG); + /* wait 1ms */ + usleep_range(1000, 1250); + + tmp = sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_CFG); + tmp |= SDHCI_SPRD_DLL_ALL_CPST_EN | SDHCI_SPRD_DLL_SEARCH_MODE | + SDHCI_SPRD_DLL_INIT_COUNT | SDHCI_SPRD_DLL_PHASE_INTERNAL; + sdhci_writel(host, tmp, SDHCI_SPRD_REG_32_DLL_CFG); + /* wait 1ms */ + usleep_range(1000, 1250); + + tmp = sdhci_readl(host, SDHCI_SPRD_REG_32_DLL_CFG); + tmp |= SDHCI_SPRD_DLL_EN; + sdhci_writel(host, tmp, SDHCI_SPRD_REG_32_DLL_CFG); + /* wait 1ms */ + usleep_range(1000, 1250); +} + static void sdhci_sprd_set_clock(struct sdhci_host *host, unsigned int clock) { - bool en = false; + bool en = false, clk_changed = false; if (clock == 0) { sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL); @@ -214,9 +246,19 @@ static void sdhci_sprd_set_clock(struct sdhci_host *host, unsigned int clock) en = true; sdhci_sprd_set_dll_invert(host, SDHCI_SPRD_BIT_CMD_DLY_INV | SDHCI_SPRD_BIT_POSRD_DLY_INV, en); + clk_changed = true; } else { _sdhci_sprd_set_clock(host, clock); } + + /* + * According to the Spreadtrum SD host specification, when we changed + * the clock to be more than 52M, we should enable the PHY DLL which + * is used to track the clock frequency to make the clock work more + * stable. Otherwise deviation may occur of the higher clock. + */ + if (clk_changed && clock > SDHCI_SPRD_PHY_DLL_CLK) + sdhci_sprd_enable_phy_dll(host); } static unsigned int sdhci_sprd_get_max_clock(struct sdhci_host *host)