From patchwork Tue Aug 7 06:17:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 143555 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4112049ljj; Mon, 6 Aug 2018 23:18:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfZBg+nQXGcR1txfjwy4FySDXdUukS7F662EO0s+HuXKrDm7hf9gpaQr/3H1+0G7pzf03sk X-Received: by 2002:a17:902:82c7:: with SMTP id u7-v6mr16566530plz.83.1533622693373; Mon, 06 Aug 2018 23:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533622693; cv=none; d=google.com; s=arc-20160816; b=rHFrpHiZ8j8hzYaD+yra6k4AaOhJ3JDJln/bmYAfBM8Jt73fBqXmI3rRgqIyxzlXNe M0XrzvgHHh8Wg0/S9bfpi2rKJfIhGyFnZt/CUx3FvLat8CQL2Y0w+sewh/xfUSw44N5A QSoREWMeMkA+WB6QKV67X9MJY2AU+eHRFlUnYjnPPp9nUpP/OypWQoEJdzzYyc4JBYyQ +myLqxaF5NcRBVMWuOZqPB6ESoI9xFy7xZzld0f5R+DLn7J5JqnSpQbUsHbFJpE5bH1G ub07ewaU9ANLKJktw7PZumnatmxQM7IlkF2F4BkGPibgcvBm7ruqMlg6+1lRn/3sg1i7 f1Ww== 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:dkim-filter :arc-authentication-results; bh=UT3yW58qr1Chvei5JhUZ2J1SyS5PiFdHtTAWn2pGFOk=; b=WyFHX8EgO56uq8tWJkaH8mwbFgnANX6eHOywwHBytpJ09npwTqqaZq+pRgL17ftWAQ FvsAxMtu7CBykQgDKJ5RLLpnneFGJiP9qCT8RuolK29+x3QiMxU7fMrv0rWH8Nz03r3W smpren1T6qOs3Pki/au6VJq7xUn7gY6vrjUrA6Vxgp4eGmju65V80fs3PtMLXIx8bO8T 5W/CRngh4zaOWm21yDN0HLApzTBxOJh8zMgCkyrW8IbXkDL3Aq1c44L9FIYpynj100+i HOGX9Yb7McmRmG1lLU0dcXNkBehyW7qf0y7HVcii8YHXSbBnwozr+tipsPbegi/yHDWz 4s+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=aesdhnqv; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-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 s16-v6si409892plp.317.2018.08.06.23.18.13; Mon, 06 Aug 2018 23:18:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=aesdhnqv; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733047AbeHGIa4 (ORCPT + 5 others); Tue, 7 Aug 2018 04:30:56 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:39156 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730130AbeHGIa4 (ORCPT ); Tue, 7 Aug 2018 04:30:56 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w776HYge009463; Tue, 7 Aug 2018 15:17:36 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w776HYge009463 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1533622657; bh=0DlYWqmSfQfizrK8ba4oRVi8VXNPQXu3RSQHUt+suuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aesdhnqvAeC8WTAbDr5Ft9AB0RGqwFVdEz+yQGhia65AvWMmlpX2PhFdvWICWspKI 6bUeUcJS2soCUFrcSMam2vuK74s5Dbg6HJPvdhGgeeaLVHtX3MqVSLw6JaOsfvSQOT CTxVbe+5vk9nqZ3CCpnZcHXf9bbnQSOPlDmAWL1voZ46XxqxQWMZm64LHbkG5kaSF1 gUoJJGTyEnNIZgVHWlydRN1nXFF3RHZpIFGrsktYjlmrRJHUcVIfDFHnlfGf6nRm60 AGd5UPPb7CjDpFjqAYS0nXj/QI2iN46jVycf9c5ykaRXXjARyMV/tsBUfNBGhlDZoX ZihfsPcbS+dZA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Wolfram Sang , linux-mmc@vger.kernel.org Cc: Ulf Hansson , linux-renesas-soc@vger.kernel.org, Masami Hiramatsu , Jassi Brar , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [v0.1 PATCH 2/7] mmc: tmio: move tmio_mmc_set_clock() to platform hook Date: Tue, 7 Aug 2018 15:17:17 +0900 Message-Id: <1533622642-13989-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533622642-13989-1-git-send-email-yamada.masahiro@socionext.com> References: <1533622642-13989-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org tmio_mmc_set_clock() is full of quirks because different SoC vendors extended this in different ways. The original IP defines the divisor range 1/2 ... 1/512. bit 7 is set: 1/512 bit 6 is set: 1/256 ... bit 0 is set: 1/4 all bits clear: 1/2 It is platform-dependent how to achieve the 1/1 clock. I guess the TMIO-MFD variant uses the clock selector outside of this IP, as far as I see tmio_core_mmc_clk_div() in drivers/mfd/tmio_core.c I guess bit[7:0]=0xff is Renesas-specific extension. Socionext (and Panasonic) uses bit 10 (CLKSEL) for 1/1. Also, newer versions of UniPhier SoC variants use bit 16 for 1/1024. host->clk_update() is only used by the Renesas variants, whereas host->set_clk_div() is only used by the TMIO-MFD variants. To cope with this mess, promote tmio_mmc_set_clock() to a new platform hook ->set_clock(), and melt the old two hooks into it. Signed-off-by: Masahiro Yamada --- drivers/mmc/host/renesas_sdhi_core.c | 50 ++++++++++++++++++++++- drivers/mmc/host/tmio_mmc.c | 48 ++++++++++++++++++++++ drivers/mmc/host/tmio_mmc.h | 4 +- drivers/mmc/host/tmio_mmc_core.c | 79 ++++-------------------------------- 4 files changed, 105 insertions(+), 76 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c index 45c015da..1f4c82e 100644 --- a/drivers/mmc/host/renesas_sdhi_core.c +++ b/drivers/mmc/host/renesas_sdhi_core.c @@ -155,6 +155,54 @@ static unsigned int renesas_sdhi_clk_update(struct tmio_mmc_host *host, return ret == 0 ? best_freq : clk_get_rate(priv->clk); } +static void renesas_sdhi_clk_start(struct tmio_mmc_host *host) +{ + sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN | + sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); + + /* HW engineers overrode docs: no sleep needed on R-Car2+ */ + if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) + usleep_range(10000, 11000); +} + +static void renesas_sdhi_clk_stop(struct tmio_mmc_host *host) +{ + sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & + sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); + + /* HW engineers overrode docs: no sleep needed on R-Car2+ */ + if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) + usleep_range(10000, 11000); +} + +static void renesas_sdhi_set_clock(struct tmio_mmc_host *host, + unsigned int new_clock) +{ + u32 clk = 0, clock; + + if (new_clock == 0) { + renesas_sdhi_clk_stop(host); + return; + } + + clock = renesas_sdhi_clk_update(host, new_clock) / 512; + + for (clk = 0x80000080; new_clock >= (clock << 1); clk >>= 1) + clock <<= 1; + + /* 1/1 clock is option */ + if ((host->pdata->flags & TMIO_MMC_CLK_ACTUAL) && ((clk >> 22) & 0x1)) + clk |= 0xff; + + sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & + sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); + sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk & CLK_CTL_DIV_MASK); + if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) + usleep_range(10000, 11000); + + renesas_sdhi_clk_start(host); +} + static void renesas_sdhi_clk_disable(struct tmio_mmc_host *host) { struct renesas_sdhi *priv = host_to_priv(host); @@ -530,8 +578,8 @@ int renesas_sdhi_probe(struct platform_device *pdev, host->write16_hook = renesas_sdhi_write16_hook; host->clk_enable = renesas_sdhi_clk_enable; - host->clk_update = renesas_sdhi_clk_update; host->clk_disable = renesas_sdhi_clk_disable; + host->set_clock = renesas_sdhi_set_clock; host->multi_io_quirk = renesas_sdhi_multi_io_quirk; host->dma_ops = dma_ops; diff --git a/drivers/mmc/host/tmio_mmc.c b/drivers/mmc/host/tmio_mmc.c index 43a2ea5..b031a77 100644 --- a/drivers/mmc/host/tmio_mmc.c +++ b/drivers/mmc/host/tmio_mmc.c @@ -13,6 +13,7 @@ * published by the Free Software Foundation. */ +#include #include #include #include @@ -23,6 +24,52 @@ #include "tmio_mmc.h" +static void tmio_mmc_clk_start(struct tmio_mmc_host *host) +{ + sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN | + sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); + + usleep_range(10000, 11000); + sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0100); + usleep_range(10000, 11000); +} + +static void tmio_mmc_clk_stop(struct tmio_mmc_host *host) +{ + sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0000); + usleep_range(10000, 11000); + + sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & + sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); + + usleep_range(10000, 11000); +} + +static void tmio_mmc_set_clock(struct tmio_mmc_host *host, + unsigned int new_clock) +{ + u32 clk = 0, clock; + + if (new_clock == 0) { + tmio_mmc_clk_stop(host); + return; + } + + clock = host->mmc->f_min; + + for (clk = 0x80000080; new_clock >= (clock << 1); clk >>= 1) + clock <<= 1; + + host->pdata->set_clk_div(host->pdev, (clk >> 22) & 1); + + sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & + sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); + sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk & CLK_CTL_DIV_MASK); + usleep_range(10000, 11000); + + tmio_mmc_clk_start(host); +} + #ifdef CONFIG_PM_SLEEP static int tmio_mmc_suspend(struct device *dev) { @@ -100,6 +147,7 @@ static int tmio_mmc_probe(struct platform_device *pdev) /* SD control register space size is 0x200, 0x400 for bus_shift=1 */ host->bus_shift = resource_size(res) >> 10; + host->set_clock = tmio_mmc_set_clock; host->mmc->f_max = pdata->hclk; host->mmc->f_min = pdata->hclk / 512; diff --git a/drivers/mmc/host/tmio_mmc.h b/drivers/mmc/host/tmio_mmc.h index e7d6513..e0aa3f9 100644 --- a/drivers/mmc/host/tmio_mmc.h +++ b/drivers/mmc/host/tmio_mmc.h @@ -132,7 +132,6 @@ struct tmio_mmc_host { /* Callbacks for clock / power control */ void (*set_pwr)(struct platform_device *host, int state); - void (*set_clk_div)(struct platform_device *host, int state); /* pio related stuff */ struct scatterlist *sg_ptr; @@ -169,10 +168,9 @@ struct tmio_mmc_host { /* Mandatory callback */ int (*clk_enable)(struct tmio_mmc_host *host); + void (*set_clock)(struct tmio_mmc_host *host, unsigned int clock); /* Optional callbacks */ - unsigned int (*clk_update)(struct tmio_mmc_host *host, - unsigned int new_clock); void (*clk_disable)(struct tmio_mmc_host *host); int (*multi_io_quirk)(struct mmc_card *card, unsigned int direction, int blk_size); diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c index 991b340..74b8972 100644 --- a/drivers/mmc/host/tmio_mmc_core.c +++ b/drivers/mmc/host/tmio_mmc_core.c @@ -160,70 +160,6 @@ static void tmio_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable) } } -static void tmio_mmc_clk_start(struct tmio_mmc_host *host) -{ - sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN | - sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); - - /* HW engineers overrode docs: no sleep needed on R-Car2+ */ - if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) - usleep_range(10000, 11000); - - if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) { - sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0100); - usleep_range(10000, 11000); - } -} - -static void tmio_mmc_clk_stop(struct tmio_mmc_host *host) -{ - if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) { - sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0000); - usleep_range(10000, 11000); - } - - sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & - sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); - - /* HW engineers overrode docs: no sleep needed on R-Car2+ */ - if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) - usleep_range(10000, 11000); -} - -static void tmio_mmc_set_clock(struct tmio_mmc_host *host, - unsigned int new_clock) -{ - u32 clk = 0, clock; - - if (new_clock == 0) { - tmio_mmc_clk_stop(host); - return; - } - - if (host->clk_update) - clock = host->clk_update(host, new_clock) / 512; - else - clock = host->mmc->f_min; - - for (clk = 0x80000080; new_clock >= (clock << 1); clk >>= 1) - clock <<= 1; - - /* 1/1 clock is option */ - if ((host->pdata->flags & TMIO_MMC_CLK_ACTUAL) && ((clk >> 22) & 0x1)) - clk |= 0xff; - - if (host->set_clk_div) - host->set_clk_div(host->pdev, (clk >> 22) & 1); - - sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & - sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); - sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk & CLK_CTL_DIV_MASK); - if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) - usleep_range(10000, 11000); - - tmio_mmc_clk_start(host); -} - static void tmio_mmc_reset(struct tmio_mmc_host *host) { /* FIXME - should we set stop clock reg here */ @@ -1032,15 +968,15 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) switch (ios->power_mode) { case MMC_POWER_OFF: tmio_mmc_power_off(host); - tmio_mmc_set_clock(host, 0); + host->set_clock(host, 0); break; case MMC_POWER_UP: tmio_mmc_power_on(host, ios->vdd); - tmio_mmc_set_clock(host, ios->clock); + host->set_clock(host, ios->clock); tmio_mmc_set_bus_width(host, ios->bus_width); break; case MMC_POWER_ON: - tmio_mmc_set_clock(host, ios->clock); + host->set_clock(host, ios->clock); tmio_mmc_set_bus_width(host, ios->bus_width); break; } @@ -1196,7 +1132,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host) int ret; /* - * Check the sanity of mmc->f_min to prevent tmio_mmc_set_clock() from + * Check the sanity of mmc->f_min to prevent host->set_clock() from * looping forever... */ if (mmc->f_min == 0) @@ -1206,7 +1142,6 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host) _host->write16_hook = NULL; _host->set_pwr = pdata->set_pwr; - _host->set_clk_div = pdata->set_clk_div; ret = tmio_mmc_init_ocr(_host); if (ret < 0) @@ -1269,7 +1204,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host) if (pdata->flags & TMIO_MMC_SDIO_IRQ) _host->sdio_irq_mask = TMIO_SDIO_MASK_ALL; - tmio_mmc_set_clock(_host, 0); + _host->set_clock(_host, 0); tmio_mmc_reset(_host); _host->sdcard_irq_mask = sd_ctrl_read16_and_16_as_32(_host, CTL_IRQ_MASK); @@ -1353,7 +1288,7 @@ int tmio_mmc_host_runtime_suspend(struct device *dev) tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_ALL); if (host->clk_cache) - tmio_mmc_set_clock(host, 0); + host->set_clock(host, 0); tmio_mmc_clk_disable(host); @@ -1374,7 +1309,7 @@ int tmio_mmc_host_runtime_resume(struct device *dev) tmio_mmc_clk_enable(host); if (host->clk_cache) - tmio_mmc_set_clock(host, host->clk_cache); + host->set_clock(host, host->clk_cache); if (host->native_hotplug) tmio_mmc_enable_mmc_irqs(host, From patchwork Tue Aug 7 06:17:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 143554 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4112033ljj; Mon, 6 Aug 2018 23:18:12 -0700 (PDT) X-Google-Smtp-Source: AAOMgpePgKRl7mant/VESUTd8n9a7MFCoQyL/572U3JveGctvPkKVBHwce63U6Z9xxQq0KmQkKrF X-Received: by 2002:a62:a6db:: with SMTP id r88-v6mr20333564pfl.60.1533622692442; Mon, 06 Aug 2018 23:18:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533622692; cv=none; d=google.com; s=arc-20160816; b=anEhzyYXhUF9kdW33N2E8625ynRkk/zC0h64B+N0/+PYlg2lPzUtVOkzKYyoSvdprc IdKj91y4qlIjMyaOmckbyZF26Pt10SdMH9Tk3XPiQ5dSsi7IMBF4BMPzCsMP97kMuQiN ugz1ERPfsVTpdzGVHmkOTibzAzAVCpAcVR4P4SxYuaVBCbCp+DOqtXO/GXCIADXA4Kg/ 1fV3gDvcBrO+46NmkE6HVWznrCeVkJ+B/lyAdtkCeSaVhdXMZ1Q2mjJlRbrVZJrbHQR2 hxUKBT60UUiHeD0/ev/6/gJIZEsbOEO012StXybLxPcJhSChWJ7N6iUR/6jhetAQ6nBZ xfvg== 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:dkim-filter :arc-authentication-results; bh=3851g8x1yTxXIC+JjL3Tt+RgQiz9zZlPaF3kYwhVEPs=; b=osr1FHpkotQnpRR4yEpKybik2huNi0gxkM3GwpZZnroQ34lOWVLgjxUgI6WYOUMXGu NsiaIVJaQucSGkHTQEtBa+qURY3QTRn0oIjKiy4mLg8P5x6ujuWTHHb2Xrf4ZRuiYqU2 Yxdfan7mVk4YVTDsoFoGOPdF8/WDNCXEfCs1nmZP3fLlWf7h4HsGc9xfrGY8jqZOZ7pn QtgsgjcOKedspR3bfNkLKZTKF0KjNGre2AWtQjkSFP+83gVeVzpTOEVjR9fDYVTFgdX6 9Pb5+UOENZNW/VDA45nwL8rzLyqWdD6ea+rM0DqWaleoGGLdgeH3zS4Ih4KNmrnj/ubK 0Bvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=HUOjDLSq; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-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 s16-v6si409892plp.317.2018.08.06.23.18.12; Mon, 06 Aug 2018 23:18:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=HUOjDLSq; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731069AbeHGIaz (ORCPT + 5 others); Tue, 7 Aug 2018 04:30:55 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:39155 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727360AbeHGIaz (ORCPT ); Tue, 7 Aug 2018 04:30:55 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w776HYgh009463; Tue, 7 Aug 2018 15:17:39 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w776HYgh009463 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1533622659; bh=vQ1peXoL5EnrlsDxZywosCdynceuZFw0QzMxHmOSOmQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HUOjDLSqEHUdMDXObfwPPxBmoWtqx1rC0Js8saVMxlz3y6LL5Yy32px66lbD5o9l+ ANX97qAaP/GQxdgXiW0kzCeq7E1PP+ihVXwJq+mEZJiJF/AgTcatiPr8+nLzhGFvyG 5vKA3/vLmo8YHgLJEVowIZWzEdguMEG3iJvyoseYSXFkeQxArsJmCSQv9fjryzc7+x edMSk96D0GYyt4HE3K9FOBCWSb7r1Mo8U8BN2VAWyBXjIkhfA1L7hE79+bdEYwLQ3B cSXihKRK5kiNujZ/xu/GJuPbDBURWsg5bCZcW4bbK39Oa5u+3aQzWJgi9HcKALuhSP fOfwzBBDKZtWQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Wolfram Sang , linux-mmc@vger.kernel.org Cc: Ulf Hansson , linux-renesas-soc@vger.kernel.org, Masami Hiramatsu , Jassi Brar , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [v0.1 PATCH 5/7] mmc: renesas_sdhi: merge clk_{start, stop} functions to set_clock Date: Tue, 7 Aug 2018 15:17:20 +0900 Message-Id: <1533622642-13989-6-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533622642-13989-1-git-send-email-yamada.masahiro@socionext.com> References: <1533622642-13989-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org renesas_sdhi_clk_start() and renesas_sdhi_clk_stop() are now only called from renesas_sdhi_set_clock(). Merge them. Signed-off-by: Masahiro Yamada --- drivers/mmc/host/renesas_sdhi_core.c | 39 +++++++++++------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c index 1f4c82e..a15fb2e 100644 --- a/drivers/mmc/host/renesas_sdhi_core.c +++ b/drivers/mmc/host/renesas_sdhi_core.c @@ -155,35 +155,16 @@ static unsigned int renesas_sdhi_clk_update(struct tmio_mmc_host *host, return ret == 0 ? best_freq : clk_get_rate(priv->clk); } -static void renesas_sdhi_clk_start(struct tmio_mmc_host *host) -{ - sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN | - sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); - - /* HW engineers overrode docs: no sleep needed on R-Car2+ */ - if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) - usleep_range(10000, 11000); -} - -static void renesas_sdhi_clk_stop(struct tmio_mmc_host *host) -{ - sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & - sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); - - /* HW engineers overrode docs: no sleep needed on R-Car2+ */ - if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) - usleep_range(10000, 11000); -} - static void renesas_sdhi_set_clock(struct tmio_mmc_host *host, unsigned int new_clock) { u32 clk = 0, clock; - if (new_clock == 0) { - renesas_sdhi_clk_stop(host); - return; - } + sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & + sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); + + if (new_clock == 0) + goto out; clock = renesas_sdhi_clk_update(host, new_clock) / 512; @@ -194,13 +175,17 @@ static void renesas_sdhi_set_clock(struct tmio_mmc_host *host, if ((host->pdata->flags & TMIO_MMC_CLK_ACTUAL) && ((clk >> 22) & 0x1)) clk |= 0xff; - sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & - sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk & CLK_CTL_DIV_MASK); if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) usleep_range(10000, 11000); - renesas_sdhi_clk_start(host); + sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN | + sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); + +out: + /* HW engineers overrode docs: no sleep needed on R-Car2+ */ + if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2)) + usleep_range(10000, 11000); } static void renesas_sdhi_clk_disable(struct tmio_mmc_host *host) From patchwork Tue Aug 7 06:17:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 143558 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4112399ljj; Mon, 6 Aug 2018 23:18:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdiAa4QHS0SB7M/JdCMm2jXEAduCklp50jgOmnB9odoKwn24dzRPQafUlPZCQ9iFZtSGgYB X-Received: by 2002:a63:da04:: with SMTP id c4-v6mr16610212pgh.398.1533622711094; Mon, 06 Aug 2018 23:18:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533622711; cv=none; d=google.com; s=arc-20160816; b=Z9VS0I3Jdu4unL3grTadF4w3F0eGSOoQ9WQKa41cnF2Kb/VaYl662oQpqbzGYW2IzH wwjALrYzJT1TolaztN0+mVIGXOiErtRvNTaY7ZtzLL2zSZnLTAip/SbivtbfDlroqsMa FLJ0OgQZzivoHxZxYjUVrkH4rFcI+MaW/ewsE5icxXCHMiEBGKTBEKtFrAXhmZ49wyJ4 Eeet8gobu+nWcWRP5Dbwi7CYH6aTTfVbWhI0RHR3WoB4wp/DGLOONNHYfsJrz9ePGbPl OgjWnFo2sERQsexhb2tGI12toxI2Cws6dID4ypNUkvTkgWN4qJKvYDSBwIjQfc030GYt p/Pw== 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:dkim-filter :arc-authentication-results; bh=jX9An6BiMQI7QUXnSHAcO1fNcQi5ghfzqRL6lIcpxes=; b=KKh6TYMNCwtHI2CULpTwRL/ylTyxOEpvSg2e7H+j10udWM2zL6lY8zgzwXC1qAdbtC HR9nwtyK/rAH9aEBwodmZ2g0JpZTbVouGOMI30mTqvvBNHoz09dD4c+2U0jwk/Efl8JR ibhClfsD2cS4A83PlgmfnUCFNo29ZgLMsrD4srWGbeHbOyGfFwBW4X6pMig3DmfLuGaR WFS98PA6QoVE2Kh+D//RQgUTHhCUItx7DG1i6lOzSiefRvzMHS37Po8qrg8ah9GnbYch 2slfq+NXra0V7unHcJVvlWnpPpHybaH2BesdSHYpReaxW6hLYlBMsnC6RudYMdtO1PeE dCyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=Iyq18C3o; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-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 z4-v6si563038pgf.193.2018.08.06.23.18.30; Mon, 06 Aug 2018 23:18:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=Iyq18C3o; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388594AbeHGIbO (ORCPT + 5 others); Tue, 7 Aug 2018 04:31:14 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:39265 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733061AbeHGIa6 (ORCPT ); Tue, 7 Aug 2018 04:30:58 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w776HYgj009463; Tue, 7 Aug 2018 15:17:40 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w776HYgj009463 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1533622661; bh=93n/hdv/fu8dAdRrLAHfmbU88lUWS0mHHs+i79buDAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Iyq18C3o8zluJ9xaZYliAQo9dwvl8LJpz/YLeIT37PFoUCTXMDe0W2DkPz4HDqJ8f pljeYYEypCSbrTh+fV4TpiyVclrtUJfeubpumuGlS2nsAWSETJICW7BrAncHvtc+uV lmNC2zSUQoHUaC4ufAE3uhnudrzAHCg4oGwdmRL588mnPffC+50PXb1wgjtVorGR+F 2B0LEvhgBPiXDHiqcYh6CGCSRfAQZCGXX8I6l+R68n4wNkZt4mYomb3hvolIgvWIoP TbiVpWul0QwLir9Dy7EjxJSDKYXlv1lFQ+9zkfS8e3ENcftVq4BctmiJegx85esiCm H8/kUdtW43ZIA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Wolfram Sang , linux-mmc@vger.kernel.org Cc: Ulf Hansson , linux-renesas-soc@vger.kernel.org, Masami Hiramatsu , Jassi Brar , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [v0.1 PATCH 7/7] mmc: tmio: refactor CLK_CTL bit calculation Date: Tue, 7 Aug 2018 15:17:22 +0900 Message-Id: <1533622642-13989-8-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533622642-13989-1-git-send-email-yamada.masahiro@socionext.com> References: <1533622642-13989-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org for (clk = 0x80000080; new_clock >= (clock << 1); clk >>= 1) clock <<= 1; ... is too tricky, hence I replaced with roundup_pow_of_two(divisor) >> 2 '(clk >> 22) & 0x1' is the bit test for the 1/1 divisor, but it is not clear. 'divisor <= 1' is easier to understand. Signed-off-by: Masahiro Yamada --- drivers/mmc/host/tmio_mmc.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/host/tmio_mmc.c b/drivers/mmc/host/tmio_mmc.c index b031a77..e04c322 100644 --- a/drivers/mmc/host/tmio_mmc.c +++ b/drivers/mmc/host/tmio_mmc.c @@ -48,19 +48,27 @@ static void tmio_mmc_clk_stop(struct tmio_mmc_host *host) static void tmio_mmc_set_clock(struct tmio_mmc_host *host, unsigned int new_clock) { - u32 clk = 0, clock; + unsigned int clock, divisor; + u32 clk = 0; + int clk_sel; if (new_clock == 0) { tmio_mmc_clk_stop(host); return; } - clock = host->mmc->f_min; + divisor = host->pdata->hclk / new_clock; - for (clk = 0x80000080; new_clock >= (clock << 1); clk >>= 1) - clock <<= 1; + if (divisor <= 1) { + clk_sel = 1; + clk = 0; + } else { + clk_sel = 0; + /* bit7 set: 1/512, ... bit0 set:1/4, all bits clear: 1/2 */ + clk = roundup_pow_of_two(divisor) >> 2; + } - host->pdata->set_clk_div(host->pdev, (clk >> 22) & 1); + host->pdata->set_clk_div(host->pdev, clk_sel); sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));