Skip to content

Commit 557011b

Browse files
bnw3000storulf
authored andcommitted
mmc: mediatek: refine msdc timeout api
Extract msdc timeout api common part to have better code architecture and avoid redundant code. Signed-off-by: Chun-Hung Wu <[email protected]> Reviewed-by: Matthias Brugger <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent 7d176b0 commit 557011b

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

drivers/mmc/host/mtk-sd.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -723,21 +723,21 @@ static void msdc_unprepare_data(struct msdc_host *host, struct mmc_request *mrq)
723723
}
724724
}
725725

726-
/* clock control primitives */
727-
static void msdc_set_timeout(struct msdc_host *host, u32 ns, u32 clks)
726+
static u64 msdc_timeout_cal(struct msdc_host *host, u64 ns, u64 clks)
728727
{
729-
u32 timeout, clk_ns;
728+
u64 timeout, clk_ns;
730729
u32 mode = 0;
731730

732-
host->timeout_ns = ns;
733-
host->timeout_clks = clks;
734731
if (host->mmc->actual_clock == 0) {
735732
timeout = 0;
736733
} else {
737-
clk_ns = 1000000000UL / host->mmc->actual_clock;
738-
timeout = (ns + clk_ns - 1) / clk_ns + clks;
734+
clk_ns = 1000000000ULL;
735+
do_div(clk_ns, host->mmc->actual_clock);
736+
timeout = ns + clk_ns - 1;
737+
do_div(timeout, clk_ns);
738+
timeout += clks;
739739
/* in 1048576 sclk cycle unit */
740-
timeout = (timeout + (0x1 << 20) - 1) >> 20;
740+
timeout = DIV_ROUND_UP(timeout, (0x1 << 20));
741741
if (host->dev_comp->clk_div_bits == 8)
742742
sdr_get_field(host->base + MSDC_CFG,
743743
MSDC_CFG_CKMOD, &mode);
@@ -747,9 +747,21 @@ static void msdc_set_timeout(struct msdc_host *host, u32 ns, u32 clks)
747747
/*DDR mode will double the clk cycles for data timeout */
748748
timeout = mode >= 2 ? timeout * 2 : timeout;
749749
timeout = timeout > 1 ? timeout - 1 : 0;
750-
timeout = timeout > 255 ? 255 : timeout;
751750
}
752-
sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC, timeout);
751+
return timeout;
752+
}
753+
754+
/* clock control primitives */
755+
static void msdc_set_timeout(struct msdc_host *host, u64 ns, u64 clks)
756+
{
757+
u64 timeout;
758+
759+
host->timeout_ns = ns;
760+
host->timeout_clks = clks;
761+
762+
timeout = msdc_timeout_cal(host, ns, clks);
763+
sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC,
764+
(u32)(timeout > 255 ? 255 : timeout));
753765
}
754766

755767
static void msdc_gate_clock(struct msdc_host *host)

0 commit comments

Comments
 (0)