From patchwork Tue Apr 23 09:02:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 162670 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3541081jan; Tue, 23 Apr 2019 02:03:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDeYgpmvYGGM4Bv4uMtcrdqYnAcl/gsSXlKw25wFb/8bZsaWtSjn/RV7V7G7uPcnOVHiez X-Received: by 2002:a63:7d0a:: with SMTP id y10mr23271634pgc.292.1556010183656; Tue, 23 Apr 2019 02:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556010183; cv=none; d=google.com; s=arc-20160816; b=ihXNVNKavv/Nf3jcCbeMqOGTqfyJ3n7utObHUAd0tsD5DNLtNfwtG6gvPUlChuAitb HQljBKK/ezzkUEhdhs4kALO3T8ti6HN2NE6gFmQ90qhHSgpUEjrOZltCEEoniReKcp8b S01H1Kpi+kx2ssglHldSBDKZT23EU6EnwftuY1rsukuDG+YIyKgTFl6cNZR0Qpm3zu9z bF6LQJlfpD4nXevTC1YWmu5cy7B4ls6fUX2XOZoDkbDnT1BAEr3OvkAhuin6A7zeMFXJ +cPvCUVpoV9RbLwy8TXVHiXW9f/Mcz6+kYGC8s9GUt9McWdEDL0bVa0O4B1zPR+yKFPP xEHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7O3wIgqarfFHawq5yu8xhv0dh+R+qxDhpOLDHXRq0pw=; b=W8mkS8Pe/6xDD07Z49Y2fPe6QE97SYB401zVfLtqhPYOUs8MfFeeNY4KHkM3kc9U0c 6jgOKiv6KO5ka8ivt+nrTTDaGgL9hslFWmS+g1bty3YV0VWC2Jd6NBMeutq48P5X9SEJ EHMW2ivn43f0CvGlXxofma4MfjlyxFJO81OlHRZad4hQWuFQhwr29bIk5J40DL/L3Jns R6WnvB2x19kullONhAL//N0J40MjXpHAEboD1mlKoCaccksJeTLMIeVsXZOdoSMkRspO ZVdG67n5Hzoy0bE+a2EwU9RFpHDzNCs3yWzG1HRI8Ml1IZATS3UiGUZdYLRmg/wUHqF+ kgHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=EYXX0DSB; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n4si14920910plk.297.2019.04.23.02.03.03; Tue, 23 Apr 2019 02:03:03 -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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=EYXX0DSB; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727224AbfDWJC4 (ORCPT + 30 others); Tue, 23 Apr 2019 05:02:56 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:35537 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727162AbfDWJCx (ORCPT ); Tue, 23 Apr 2019 05:02:53 -0400 Received: by mail-wr1-f66.google.com with SMTP id o12so15839172wrn.2 for ; Tue, 23 Apr 2019 02:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7O3wIgqarfFHawq5yu8xhv0dh+R+qxDhpOLDHXRq0pw=; b=EYXX0DSB5uuxcp29aYUMyf76vuVTa5lzw+kKasn1gcmLgWBtCrDk0cSDcZxW/55KU2 XHKRJ8jLLxXRxyxmpi53+rkruleKq+q3ETmvvTrLgeSFPu3naAY+qm7PgJzXGsD5FBb4 1Rx5XqaTuLY9vZKEcUNn7l8q1Sfxx7T9c487vN702ySJKtfkvWV+DOuOmB0fAz1mzUSY 9dNGhVdXFsuFkCqn5U473kwRsiSOXTHcrzzb005cZ6yM5S0D9swNfiHl/6LPjui+SxBx ltunbGnn7TvgMx6z8bvBicacKIwgZRdDZIq0WjSjr7YssZQZ6I/ayD1gikaEB+itIIJK h//Q== 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:mime-version:content-transfer-encoding; bh=7O3wIgqarfFHawq5yu8xhv0dh+R+qxDhpOLDHXRq0pw=; b=VgjPFtdYDFBlm4YhPNOZ37Wj/l42cN28rgNp6YqlJpePZYuTL0/n1wJTUvtv+P+Clj f9Dc0aqxkzMCH7IOmv9fQKw7whmD3q0OU09gnwrR7WWGZDeUY7wE33Izpslt1prPdmTY NVTzZ+/fZWlxw8Zw/OaTiAePRd9/cINelcPyQq1EgZzT5f0Y0pFKrP8+LNCg+bIwKAb5 kc98qeowq7c7vjcahGPmUiywUcsZfqwH79AyH/TxJ03QLJNAJnCAKkMU8gJQUPWscPUS S2PUbZUknOAZxvbdcmtWfqWNc9onsLTVd2+mzLGpSfdI81yMw03jZ74X6SHkzyPzLtvN 1mmg== X-Gm-Message-State: APjAAAXWvo9quHo8f9tBE9frJFyKJG3jkus85dA6H+hzwJSV+L8k+xxp OZL3sKJkuM1XVVsPZPzLswuW4A== X-Received: by 2002:adf:eb87:: with SMTP id t7mr17162388wrn.39.1556010171982; Tue, 23 Apr 2019 02:02:51 -0700 (PDT) Received: from boomer.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id z23sm12361894wma.0.2019.04.23.02.02.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Apr 2019 02:02:50 -0700 (PDT) From: Jerome Brunet To: Ulf Hansson , Kevin Hilman Cc: Jerome Brunet , linux-mmc@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/7] mmc: meson-gx: avoid clock glitch when switching to DDR modes Date: Tue, 23 Apr 2019 11:02:33 +0200 Message-Id: <20190423090235.17244-6-jbrunet@baylibre.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190423090235.17244-1-jbrunet@baylibre.com> References: <20190423090235.17244-1-jbrunet@baylibre.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Activating DDR in the Amlogic mmc controller, among other things, will divide the output clock by 2. So by activating it with clock on, we are creating a glitch on the output. Instead, let's deal with DDR when the clock output is off, when setting the clock. Signed-off-by: Jerome Brunet --- drivers/mmc/host/meson-gx-mmc.c | 73 +++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 30 deletions(-) -- 2.20.1 diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index 118f09da8dfb..0454021c9ff5 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -169,6 +169,7 @@ struct meson_host { struct clk *rx_clk; struct clk *tx_clk; unsigned long req_rate; + bool ddr; struct pinctrl *pinctrl; struct pinctrl_state *pins_default; @@ -384,16 +385,6 @@ static void meson_mmc_post_req(struct mmc_host *mmc, struct mmc_request *mrq, mmc_get_dma_dir(data)); } -static bool meson_mmc_timing_is_ddr(struct mmc_ios *ios) -{ - if (ios->timing == MMC_TIMING_MMC_DDR52 || - ios->timing == MMC_TIMING_UHS_DDR50 || - ios->timing == MMC_TIMING_MMC_HS400) - return true; - - return false; -} - /* * Gating the clock on this controller is tricky. It seems the mmc clock * is also used by the controller. It may crash during some operation if the @@ -430,36 +421,41 @@ static void meson_mmc_clk_ungate(struct meson_host *host) writel(cfg, host->regs + SD_EMMC_CFG); } -static int meson_mmc_clk_set(struct meson_host *host, struct mmc_ios *ios) +static int meson_mmc_clk_set(struct meson_host *host, unsigned long rate, + bool ddr) { struct mmc_host *mmc = host->mmc; - unsigned long rate = ios->clock; int ret; u32 cfg; - /* DDR modes require higher module clock */ - if (meson_mmc_timing_is_ddr(ios)) - rate <<= 1; - /* Same request - bail-out */ - if (host->req_rate == rate) + if (host->ddr == ddr && host->req_rate == rate) return 0; /* stop clock */ meson_mmc_clk_gate(host); host->req_rate = 0; + mmc->actual_clock = 0; - if (!rate) { - mmc->actual_clock = 0; - /* return with clock being stopped */ + /* return with clock being stopped */ + if (!rate) return 0; - } /* Stop the clock during rate change to avoid glitches */ cfg = readl(host->regs + SD_EMMC_CFG); cfg |= CFG_STOP_CLOCK; writel(cfg, host->regs + SD_EMMC_CFG); + if (ddr) { + /* DDR modes require higher module clock */ + rate <<= 1; + cfg |= CFG_DDR; + } else { + cfg &= ~CFG_DDR; + } + writel(cfg, host->regs + SD_EMMC_CFG); + host->ddr = ddr; + ret = clk_set_rate(host->mmc_clk, rate); if (ret) { dev_err(host->dev, "Unable to set cfg_div_clk to %lu. ret=%d\n", @@ -471,12 +467,14 @@ static int meson_mmc_clk_set(struct meson_host *host, struct mmc_ios *ios) mmc->actual_clock = clk_get_rate(host->mmc_clk); /* We should report the real output frequency of the controller */ - if (meson_mmc_timing_is_ddr(ios)) + if (ddr) { + host->req_rate >>= 1; mmc->actual_clock >>= 1; + } dev_dbg(host->dev, "clk rate: %u Hz\n", mmc->actual_clock); - if (ios->clock != mmc->actual_clock) - dev_dbg(host->dev, "requested rate was %u\n", ios->clock); + if (rate != mmc->actual_clock) + dev_dbg(host->dev, "requested rate was %lu\n", rate); /* (re)start clock */ meson_mmc_clk_ungate(host); @@ -750,6 +748,25 @@ static int meson_mmc_execute_tuning(struct mmc_host *mmc, u32 opcode) return meson_mmc_clk_phase_tuning(mmc, opcode, host->rx_clk); } +static int meson_mmc_prepare_ios_clock(struct meson_host *host, + struct mmc_ios *ios) +{ + bool ddr; + + switch (ios->timing) { + case MMC_TIMING_MMC_DDR52: + case MMC_TIMING_UHS_DDR50: + ddr = true; + break; + + default: + ddr = false; + break; + } + + return meson_mmc_clk_set(host, ios->clock, ddr); +} + static void meson_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) { struct meson_host *host = mmc_priv(mmc); @@ -818,16 +835,12 @@ static void meson_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) val = readl(host->regs + SD_EMMC_CFG); val &= ~CFG_BUS_WIDTH_MASK; val |= FIELD_PREP(CFG_BUS_WIDTH_MASK, bus_width); + writel(val, host->regs + SD_EMMC_CFG); - val &= ~CFG_DDR; - if (meson_mmc_timing_is_ddr(ios)) - val |= CFG_DDR; - - err = meson_mmc_clk_set(host, ios); + err = meson_mmc_prepare_ios_clock(host, ios); if (err) dev_err(host->dev, "Failed to set clock: %d\n,", err); - writel(val, host->regs + SD_EMMC_CFG); dev_dbg(host->dev, "SD_EMMC_CFG: 0x%08x\n", val); }