From patchwork Fri Aug 4 17:43:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 109448 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp2475869qge; Fri, 4 Aug 2017 10:45:42 -0700 (PDT) X-Received: by 10.99.9.67 with SMTP id 64mr3196550pgj.12.1501868742437; Fri, 04 Aug 2017 10:45:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501868742; cv=none; d=google.com; s=arc-20160816; b=0YIsqRuUZryKxvEW+5r+CcrGp4N1eUNThWpdKo/c/ufZDufIOIgkH8NaxRxOTv2HJG uFr4/pdiDFBj7zYmB9yFfGPOi5BJoZKyYIuhPD8q6gg46erKESbWFLgYsOYNp9TST+O9 smPsFkh+cZas+jQc63akdFQWHUiishSw7Dus//l0xGpdt75GGCDZHWbrx7AiLSv1+oyc ju46ZPCw/Ptf39JavcGN/GeM41/B9B5+rYovHBVyiB86kHq9deopQL+i968rjGusPfYG 0fpOkm3o8d1JspWfV7irtSC3ZxIqN8W19CmjIh0CFEufP4AQQSompbYumYff+r+JAeoT +waQ== 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:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=qqLbrV5y65mT9er+X5quk8B3A1AvskGyic6svKWldXg=; b=WI2gfVBapGPsm4efvBgSBzGnAwt8twqup7gyv8g2AZOMTgq37xx+RF0yYrHd9R53Vr skpmnZEfCpw1KUwbZf6sGuzoHbZCEk2LynD9l11ADkzvvx7s6uxPMgAgE2GhBkbasb60 ROL/kAskn5WXpesvL4u7OpWLPfLvPcQlyYKR3ulkvkBBMe4Yc+whRtRC6N9qknotB9Jh w/AHw2RqRiGn9FSUylizxJHGP3w+N+SptvIHvgWRAtlUx9y7CAVvM1tysj4WLlFzB8sz 6qzKzkOIgFWd9hE5fvvrG1UHAYj/6PxP2+7qEwrpZmemPYeeUkzsCVb5m5UgyXYzN2CA 9RoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.b=RQ/SUPnP; 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 v6si1302814pfi.382.2017.08.04.10.45.42; Fri, 04 Aug 2017 10:45:42 -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.b=RQ/SUPnP; 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 S1753300AbdHDRpj (ORCPT + 25 others); Fri, 4 Aug 2017 13:45:39 -0400 Received: from mail-wr0-f180.google.com ([209.85.128.180]:38485 "EHLO mail-wr0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753194AbdHDRoR (ORCPT ); Fri, 4 Aug 2017 13:44:17 -0400 Received: by mail-wr0-f180.google.com with SMTP id f21so19228668wrf.5 for ; Fri, 04 Aug 2017 10:44:17 -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=qqLbrV5y65mT9er+X5quk8B3A1AvskGyic6svKWldXg=; b=RQ/SUPnPnNfodPD/1J9Dsal6jA3e9yaK0B22HL1sPASqKNBlV67Oxlh9wxkLID77PW jP7FScBX9P16LAD7w3rv4vFs7BE7DhFYQ+tnFGb5vg8ThbrhUxuSpWZMVcMH3sVTEbFQ hghty4QUFx6re67933q1d9GS/maGpC5nLHmAcSPMxH62V56FvfkoXHhi1M7zbrB+GrQe BS523I6CiYLLfE0ck4DykOwfmVo6MlMB2J4zWNti5C14jfp2QC8h4vsny7cCGbJXXsFg HompSnHJkH5zs2R/yGmGclqzvfKL5xtcqt3GEdK3tDATqI7aB372q4X9ceucucZDZHvP aUaw== 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=qqLbrV5y65mT9er+X5quk8B3A1AvskGyic6svKWldXg=; b=H34IyUHKLvR3D80++zE9PDWVsep6v0KQmpsn5pk18S5YrFlgFsRyun+IZlNW7JLDjc 8pEDOGR6bLZyHyVp8AWJ/3DftaHCW1HU3LYuv+skigz9LZNGO0jbNueF7cKee0vbdb98 5IJ3cNlIbGKY9Bvbg9VsEYq3r82khnIZRiKvt45kXkCpxLHawm54dnKOFETC7mGpKHvG NW7FnI61GwHkQcedYvjbWS+Ue6LVKy01UAG9Wm/1iNLiOApkIIZXO/ZJ0oYMNQJKHHNm zPKkjrp03hRZLltop5ebtF+GbL/lHjK1ToirERy0IMnnzG6NvPQZJQlgPgZ6vLp4eIbn eCrg== X-Gm-Message-State: AIVw110OWb+y4L4Qbv35Z9IPEwyB0E9xws2vLk8pN86FgI/0o/z1ME9V x2LUVajrs9VTRctL X-Received: by 10.223.173.235 with SMTP id w98mr2475564wrc.4.1501868656461; Fri, 04 Aug 2017 10:44:16 -0700 (PDT) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id p17sm996082wma.45.2017.08.04.10.44.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Aug 2017 10:44:16 -0700 (PDT) From: Jerome Brunet To: Ulf Hansson , Kevin Hilman , Carlo Caione Cc: Jerome Brunet , linux-mmc@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/14] mmc: meson-gx: fix dual data rate mode frequencies Date: Fri, 4 Aug 2017 19:43:51 +0200 Message-Id: <20170804174353.16486-13-jbrunet@baylibre.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170804174353.16486-1-jbrunet@baylibre.com> References: <20170804174353.16486-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") Signed-off-by: Jerome Brunet --- drivers/mmc/host/meson-gx-mmc.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) -- 2.9.4 diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index 560de8faea50..f973278a3f8d 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -298,14 +298,29 @@ static void meson_mmc_clk_phase_dflt(struct meson_host *host) writel(val, host->regs + SD_EMMC_CLOCK); } -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 */ @@ -314,25 +329,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->signal_clk, clk_rate); + ret = clk_set_rate(host->signal_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->signal_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); @@ -499,16 +518,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);