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: 9881853 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 C4E54602B8 for ; Fri, 4 Aug 2017 17:47:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B19D62891F for ; Fri, 4 Aug 2017 17:47:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4FB328964; Fri, 4 Aug 2017 17:47:26 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE 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 1FC862891F for ; Fri, 4 Aug 2017 17:47:26 +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=2S9QCgDQqGobYVVeLPfwvHlKhO7iolhueSh3vi9qK4g=; b=ayjR1E/qGdQVo8vv1T64vvtlMd dXxPZuSnmSR+3j/ufsdsaKVuwdstn2S+rFWYNw5g1dhStBoTSbRxYWli9p9mX7U7UxxmQEQH83A/6 RaV/afVg35fVzpJSMouFdAdMft5HLy43XAFB03wqko2Jxd/6NnvO2WGiYEJVurkBilp79LCBZw72N y3IXugU1LSje3TJT82wfvXgFF0RYzruKapg0FfEMyVsBF8rQXB4r3+J/1Gqv4J4b7BgRxo9LBHibL Mbjx/1m+jgo2BILpHyTDri2vVXu7gwStCeJBIuYw4v6hMLjvBoI++MkDIXykbsdyy6HXtGzGo5OSA +RaTgijw==; 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 1ddgh0-0001IP-K4; Fri, 04 Aug 2017 17:47:22 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ddgeP-0006Yo-Cx for linux-arm-kernel@bombadil.infradead.org; Fri, 04 Aug 2017 17:44:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=qqLbrV5y65mT9er+X5quk8B3A1AvskGyic6svKWldXg=; b=RpNpN1r8izPZiJxF/U2lcfqNa 2GKLeKB2UVVuXTC/PlW5/FltEwJu0myoeAFpIKLSq2JloOaTvAKDDaMbtWQlxGtfL65SLhTVQbdky Hzs9hS6LKU3MNnAzVY92gNmgcxxkHUD4gozGyryVlpp3JhLI8lcE9HA0OZFTyX8pHhADneL6R4UuA HUyoJf6mdNKMofmZOdWLAacQQbCsHtpRNqdLG3lgMNfbE/S2mjM00HGbMgI50Ywt9kknfZIMQ2HiP 17wsbPb/ir84H4iLFNo8qJUMVfFMoHxj9JZ1PXccq7KM8ZlMviRM6OwK6wjqtH1iKaTNSUXoEQsEN 6wNF3BhDw==; Received: from mail-wr0-x236.google.com ([2a00:1450:400c:c0c::236]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ddgeM-0005gi-Lw for linux-arm-kernel@lists.infradead.org; Fri, 04 Aug 2017 17:44:40 +0000 Received: by mail-wr0-x236.google.com with SMTP id k71so19264209wrc.2 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=c3T1S08ybbqxvAwiiLGDK8CmC5O9ZF0x6wfwKDDDTXenEZ4wOnl9Q20sl8zew3wMfV rRftVtSKfYNb1Ktasf0/J+vC/IMSkNSxE1KyT27jYT6BsW7bNGnzVXJ2s6sNdHEjepBH hIjDVpoywb0dL5o5QkHIGvuQM6SN0eNjj6buYp3Jb35wz810DoKvRIzmWYWwiL2jLm29 Eel917QEb14ILaugY6iBmL5zM4B20ghWlp06ZRhj+uDZAZHS1Vx0WX1/ZpkK3IFQHng4 8oLrb6+zgAyyAzbV8x+DSmsgrP3I5FjfR0jt7u2Ob4xMnfzYRdVK5JhHmrPs+a+vIu2f fGMQ== X-Gm-Message-State: AIVw110AaBgtwnl0Dr5y2g21kHkWgLG1XVpR3NFwwcZjLN+79Q/BoxMb qraUuR8+ilsL5gmLEpw= 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170804_184438_795630_6BBA29AE X-CRM114-Status: GOOD ( 15.63 ) 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") 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 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);