From patchwork Mon Aug 21 16:02:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 9913241 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 093BC603F9 for ; Mon, 21 Aug 2017 16:10:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2521287CB for ; Mon, 21 Aug 2017 16:10:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E74C3287C1; Mon, 21 Aug 2017 16:10:41 +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=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 975B1287C0 for ; Mon, 21 Aug 2017 16:10:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=NXTNAnNBAPGUz+f5AkHIbS4Q9PjH6bu7jTz35HMldKE=; b=K1oSPXRniVqAWypH9YtoWzHuO0 uAXnBAL8qK7ckib0sFyaztn7JCLFwsa7Xwu/iv19Wupvc83pB6RrbHEg+qqFfmD5UTSctPdR2pczS DxyKT8XVl4wdvJJDhd9uZ3x1KHdbSIFkeS0IUUNee/Y9dnj2ZbV6tL2RIgKd48CjwYSwE8eEWGjZm OFMTTmnwKZWWzaaT/FfJhIePZorVLlObqLH0to7dUsfxLOaNfWnFcvPmRADAyXRGWcA9KrnhQO82/ 3IMXJ8bnOnNSO2ooUHoKaU+6Kwsi9TppVqCpLrhHpb1pu5UbRA4/JZFOEWTJQjH4OodDVbVzKGWdD gInzutKQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1djpHk-0000BG-Jf; Mon, 21 Aug 2017 16:10:40 +0000 Received: from mail-wr0-x230.google.com ([2a00:1450:400c:c0c::230]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1djpAq-0001FY-Jy for linux-arm-kernel@lists.infradead.org; Mon, 21 Aug 2017 16:03:45 +0000 Received: by mail-wr0-x230.google.com with SMTP id p8so39040781wrf.5 for ; Mon, 21 Aug 2017 09:03:16 -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; bh=8orKs8W+Q75qYO/NcwW7xDykSq2M3fMc9q3KExqPgXw=; b=BrY6nf2ktVZfZp7cMIvVCH57qjYSuLDcYoTSkUdpHfmwlMXCHiAr248lFt69N68DHm gvg/ccpVjP04xg/qFOBFnm/n9qhZO5/0aSpC8KbC4XoTnwad2+R5zU2QYwFUFgYdhRre aeAZpFCu6Fm7zmfAgdgvnT7mtzk5egptDDarZDJEyu12tzI9Ahfsv6hwVRvce7qNNpGL mEvZLmAf9yiA7A8mZ3IB4lugzCxTtZB5d2Iw+4tWjBK2LrvS97UvITnGnXMofcusEGIA R1TQn9aKCrCd8Tu4jFgDSNA25o9pY2COEHawa5FpT6H4cVDbBnsoIlv3RMR3fVSyRnQb RHGA== 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; bh=8orKs8W+Q75qYO/NcwW7xDykSq2M3fMc9q3KExqPgXw=; b=FpMI9NaMGqWqmlafh2aUQRux0lGPhTh0TvaVzWPA6CdYpzrjVVIaImAvIHIjsi6fTB MWNW9st971+is0biF7mtLBdWqY+e4w0qrHYBPYd/Rj/NvXAH5vlP2CD0f+pkW9aGOCyV 3+NZR8Mcne8rGbJFI6vjQpk4mJTgiUjCjW4r8R24oYRCu+uUwQblAfgfnaxg1klwIzMR c5WLiGDEXNKG08nfY7BVKELg3Mvg5iM8aIy/Xn+eXJ9cUB1H0RVZFD5lSf9NNtyZJboi MSZOYK4J8ZUakwqXQp8lM/x74Acz2qe5I4x4hiy88dU74ItvDRJRhVDeJ+aIqv9oJkDw GwiA== X-Gm-Message-State: AHYfb5juZqEqWS67abIPMukojiWM/FeXMhGx0J19CcsI7S0S6LO73o5B 6t/wNqXhniLWTDsJ X-Received: by 10.223.146.195 with SMTP id 61mr12065813wrn.169.1503331395280; Mon, 21 Aug 2017 09:03:15 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.googlemail.com with ESMTPSA id 63sm8120063wra.30.2017.08.21.09.03.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Aug 2017 09:03:14 -0700 (PDT) From: Jerome Brunet To: Ulf Hansson , Kevin Hilman , Carlo Caione Subject: [PATCH v2 09/16] mmc: meson-gx: fix dual data rate mode frequencies Date: Mon, 21 Aug 2017 18:02:54 +0200 Message-Id: <20170821160301.21899-10-jbrunet@baylibre.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20170821160301.21899-1-jbrunet@baylibre.com> References: <20170821160301.21899-1-jbrunet@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170821_090333_276161_128D7489 X-CRM114-Status: GOOD ( 14.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jerome Brunet MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In DDR modes, meson mmc controller requires an input rate twice as fast as the output rate Fixes: 51c5d8447bd7 ("MMC: meson: initial support for GX platforms") Reviewed-by: Kevin Hilman Signed-off-by: Jerome Brunet --- drivers/mmc/host/meson-gx-mmc.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index 2f45daa5d510..0d3416dae8cf 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -262,14 +262,29 @@ static void meson_mmc_post_req(struct mmc_host *mmc, struct mmc_request *mrq, mmc_get_dma_dir(data)); } -static int meson_mmc_clk_set(struct meson_host *host, unsigned long clk_rate) +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; +} + +static int meson_mmc_clk_set(struct meson_host *host, struct mmc_ios *ios) { 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 == clk_rate) + if (host->req_rate == rate) return 0; /* stop clock */ @@ -278,25 +293,29 @@ static int meson_mmc_clk_set(struct meson_host *host, unsigned long clk_rate) writel(cfg, host->regs + SD_EMMC_CFG); host->req_rate = 0; - if (!clk_rate) { + if (!rate) { mmc->actual_clock = 0; /* return with clock being stopped */ return 0; } - ret = clk_set_rate(host->mmc_clk, clk_rate); + 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", - clk_rate, ret); + rate, ret); return ret; } - host->req_rate = clk_rate; + host->req_rate = rate; 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)) + mmc->actual_clock >>= 1; + dev_dbg(host->dev, "clk rate: %u Hz\n", mmc->actual_clock); - if (clk_rate != mmc->actual_clock) - dev_dbg(host->dev, "requested rate was %lu\n", clk_rate); + if (ios->clock != mmc->actual_clock) + dev_dbg(host->dev, "requested rate was %u\n", ios->clock); /* (re)start clock */ cfg = readl(host->regs + SD_EMMC_CFG); @@ -490,16 +509,14 @@ static void meson_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) val |= FIELD_PREP(CFG_BUS_WIDTH_MASK, bus_width); val &= ~CFG_DDR; - if (ios->timing == MMC_TIMING_UHS_DDR50 || - ios->timing == MMC_TIMING_MMC_DDR52 || - ios->timing == MMC_TIMING_MMC_HS400) + if (meson_mmc_timing_is_ddr(ios)) val |= CFG_DDR; val &= ~CFG_CHK_DS; if (ios->timing == MMC_TIMING_MMC_HS400) val |= CFG_CHK_DS; - err = meson_mmc_clk_set(host, ios->clock); + err = meson_mmc_clk_set(host, ios); if (err) dev_err(host->dev, "Failed to set clock: %d\n,", err);