OSDN Git Service

clk: samsung: Prevent potential endless loop in the PLL ops
authorSylwester Nawrocki <s.nawrocki@samsung.com>
Fri, 20 Nov 2020 15:57:31 +0000 (16:57 +0100)
committerSylwester Nawrocki <s.nawrocki@samsung.com>
Mon, 23 Nov 2020 10:14:04 +0000 (11:14 +0100)
commit44a9e78f9242872c889f176782777fa2ed535650
tree57385b47c75db197240f68601f82d62a251317dc
parente44cdff05145b84293e3f424daa17e4f3ce0109c
clk: samsung: Prevent potential endless loop in the PLL ops

The PLL status polling loops in the set_rate callbacks of some PLLs
have no timeout detection and may become endless loops when something
goes wrong with the PLL.

For some PLLs there is already the ktime API based timeout detection,
but it will not work in all conditions when .set_rate gets called.
In particular, before the clocksource is initialized or when the
timekeeping is suspended.

This patch adds a common helper with the PLL status bit polling and
timeout detection. For conditions where the timekeeping API should not
be used a simple readl_relaxed/cpu_relax() busy loop is added with the
iterations limit derived from measurements of readl_relaxed() execution
time for various PLL types and Exynos SoCs variants.

Actual PLL lock time depends on the P divider value, the VCO frequency
and a constant PLL type specific LOCK_FACTOR and can be calculated as

 lock_time = Pdiv * LOCK_FACTOR / VCO_freq

For the ktime API use cases a common timeout value of 20 ms is applied
for all the PLLs with an assumption that maximum possible value of Pdiv
is 64, maximum possible LOCK_FACTOR value is 3000 and minimum VCO
frequency is 24 MHz.

Link: https://lore.kernel.org/r/20201120155731.26898-1-s.nawrocki@samsung.com
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
drivers/clk/samsung/clk-pll.c