Skip to content

Commit e373315

Browse files
Frank Oltmannswens
authored andcommitted
clk: sunxi-ng: Add helper function to find closest rate
The default behaviour of clocks in the sunxi-ng driver is to select a clock rate that is closest to but less than the requested rate. Add the ccu_is_better_rate() helper function that - depending on the fact if thc CCU_FEATURE_CLOSEST_RATE flag is set - decides if a rate is closer than another rate. Acked-by: Maxime Ripard <[email protected]> Reviewed-by: Jernej Skrabec <[email protected]> Signed-off-by: Frank Oltmanns <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Chen-Yu Tsai <[email protected]>
1 parent 48fb70c commit e373315

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

drivers/clk/sunxi-ng/ccu_common.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock)
3939
}
4040
EXPORT_SYMBOL_NS_GPL(ccu_helper_wait_for_lock, SUNXI_CCU);
4141

42+
bool ccu_is_better_rate(struct ccu_common *common,
43+
unsigned long target_rate,
44+
unsigned long current_rate,
45+
unsigned long best_rate)
46+
{
47+
if (common->features & CCU_FEATURE_CLOSEST_RATE)
48+
return abs(current_rate - target_rate) < abs(best_rate - target_rate);
49+
50+
return current_rate <= target_rate && current_rate > best_rate;
51+
}
52+
EXPORT_SYMBOL_NS_GPL(ccu_is_better_rate, SUNXI_CCU);
53+
4254
/*
4355
* This clock notifier is called when the frequency of a PLL clock is
4456
* changed. In common PLL designs, changes to the dividers take effect

drivers/clk/sunxi-ng/ccu_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ struct sunxi_ccu_desc {
5353

5454
void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock);
5555

56+
bool ccu_is_better_rate(struct ccu_common *common,
57+
unsigned long target_rate,
58+
unsigned long current_rate,
59+
unsigned long best_rate);
60+
5661
struct ccu_pll_nb {
5762
struct notifier_block clk_nb;
5863
struct ccu_common *common;

0 commit comments

Comments
 (0)