[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1588076927.730.2.camel@mhfsdcap03>
Date: Tue, 28 Apr 2020 20:28:47 +0800
From: "yong.mao@...iatek.com" <yong.mao@...iatek.com>
To: Chun-Hung Wu <chun-hung.wu@...iatek.com>
CC: <mirq-linux@...e.qmqm.pl>, Jonathan Hunter <jonathanh@...dia.com>,
"Al Cooper" <alcooperx@...il.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Florian Fainelli <f.fainelli@...il.com>,
<bcm-kernel-feedback-list@...adcom.com>,
Andy Gross <agross@...nel.org>,
Bjorn Andersson <bjorn.andersson@...aro.org>,
Michal Simek <michal.simek@...inx.com>,
Thierry Reding <thierry.reding@...il.com>,
Chaotian Jing <chaotian.jing@...iatek.com>,
Ulf Hansson <ulf.hansson@...aro.org>,
Rob Herring <robh+dt@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Matthias Brugger <matthias.bgg@...il.com>,
"Linus Walleij" <linus.walleij@...aro.org>,
Pavel Machek <pavel@....cz>,
"Kate Stewart" <kstewart@...uxfoundation.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Martin Blumenstingl <martin.blumenstingl@...glemail.com>,
Pan Bian <bianpan2016@....com>,
Thomas Gleixner <tglx@...utronix.de>,
Allison Randal <allison@...utok.net>,
Mathieu Malaterre <malat@...ian.org>,
Stanley Chu <stanley.chu@...iatek.com>,
Kuohong Wang <kuohong.wang@...iatek.com>,
<devicetree@...r.kernel.org>, <wsd_upstream@...iatek.com>,
<linux-arm-msm@...r.kernel.org>, <linux-mmc@...r.kernel.org>,
<linux-kernel@...r.kernel.org>,
<linux-mediatek@...ts.infradead.org>,
<linux-tegra@...r.kernel.org>, <kernel-team@...roid.com>,
<linux-arm-kernel@...ts.infradead.org>
Subject: Re: [PATCH v5 3/5] mmc: mediatek: refine msdc timeout api
On Tue, 2020-04-28 at 07:56 +0800, Chun-Hung Wu wrote:
> Extract msdc timeout api common part to have
> better code architecture and avoid redundent
please correct the word "redundant" in next version
> code.
>
> Signed-off-by: Chun-Hung Wu <chun-hung.wu@...iatek.com>
Acked-by: Yong Mao <yong.mao@...iatek.com>
> ---
> drivers/mmc/host/mtk-sd.c | 32 ++++++++++++++++++++++----------
> 1 file changed, 22 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
> index 7726dcf..a2328fb 100644
> --- a/drivers/mmc/host/mtk-sd.c
> +++ b/drivers/mmc/host/mtk-sd.c
> @@ -699,21 +699,21 @@ static void msdc_unprepare_data(struct msdc_host *host, struct mmc_request *mrq)
> }
> }
>
> -/* clock control primitives */
> -static void msdc_set_timeout(struct msdc_host *host, u32 ns, u32 clks)
> +static u64 msdc_timeout_cal(struct msdc_host *host, u64 ns, u64 clks)
> {
> - u32 timeout, clk_ns;
> + u64 timeout, clk_ns;
> u32 mode = 0;
>
> - host->timeout_ns = ns;
> - host->timeout_clks = clks;
> if (host->mmc->actual_clock == 0) {
> timeout = 0;
> } else {
> - clk_ns = 1000000000UL / host->mmc->actual_clock;
> - timeout = (ns + clk_ns - 1) / clk_ns + clks;
> + clk_ns = 1000000000ULL;
> + do_div(clk_ns, host->mmc->actual_clock);
> + timeout = ns + clk_ns - 1;
> + do_div(timeout, clk_ns);
> + timeout += clks;
> /* in 1048576 sclk cycle unit */
> - timeout = (timeout + (0x1 << 20) - 1) >> 20;
> + timeout = DIV_ROUND_UP(timeout, (0x1 << 20));
> if (host->dev_comp->clk_div_bits == 8)
> sdr_get_field(host->base + MSDC_CFG,
> MSDC_CFG_CKMOD, &mode);
> @@ -723,9 +723,21 @@ static void msdc_set_timeout(struct msdc_host *host, u32 ns, u32 clks)
> /*DDR mode will double the clk cycles for data timeout */
> timeout = mode >= 2 ? timeout * 2 : timeout;
> timeout = timeout > 1 ? timeout - 1 : 0;
> - timeout = timeout > 255 ? 255 : timeout;
> }
> - sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC, timeout);
> + return timeout;
> +}
> +
> +/* clock control primitives */
> +static void msdc_set_timeout(struct msdc_host *host, u64 ns, u64 clks)
> +{
> + u64 timeout;
> +
> + host->timeout_ns = ns;
> + host->timeout_clks = clks;
> +
> + timeout = msdc_timeout_cal(host, ns, clks);
> + sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC,
> + (u32)(timeout > 255 ? 255 : timeout));
> }
>
> static void msdc_gate_clock(struct msdc_host *host)
Powered by blists - more mailing lists