Skip to content

Commit b914ec3

Browse files
Frank Oltmannsjernejsk
authored andcommitted
clk: sunxi-ng: common: Support minimum and maximum rate
The Allwinner SoC's typically have an upper and lower limit for their clocks' rates. Up until now, support for that has been implemented separately for each clock type. Implement that functionality in the sunxi-ng's common part making use of the CCF rate liming capabilities, so that it is available for all clock types. Suggested-by: Maxime Ripard <[email protected]> Signed-off-by: Frank Oltmanns <[email protected]> Cc: [email protected] Reviewed-by: Jernej Skrabec <[email protected]> Acked-by: Maxime Ripard <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jernej Skrabec <[email protected]>
1 parent 7e91ed7 commit b914ec3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

drivers/clk/sunxi-ng/ccu_common.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ bool ccu_is_better_rate(struct ccu_common *common,
4444
unsigned long current_rate,
4545
unsigned long best_rate)
4646
{
47+
unsigned long min_rate, max_rate;
48+
49+
clk_hw_get_rate_range(&common->hw, &min_rate, &max_rate);
50+
51+
if (current_rate > max_rate)
52+
return false;
53+
54+
if (current_rate < min_rate)
55+
return false;
56+
4757
if (common->features & CCU_FEATURE_CLOSEST_RATE)
4858
return abs(current_rate - target_rate) < abs(best_rate - target_rate);
4959

@@ -122,6 +132,7 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
122132

123133
for (i = 0; i < desc->hw_clks->num ; i++) {
124134
struct clk_hw *hw = desc->hw_clks->hws[i];
135+
struct ccu_common *common = hw_to_ccu_common(hw);
125136
const char *name;
126137

127138
if (!hw)
@@ -136,6 +147,14 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
136147
pr_err("Couldn't register clock %d - %s\n", i, name);
137148
goto err_clk_unreg;
138149
}
150+
151+
if (common->max_rate)
152+
clk_hw_set_rate_range(hw, common->min_rate,
153+
common->max_rate);
154+
else
155+
WARN(common->min_rate,
156+
"No max_rate, ignoring min_rate of clock %d - %s\n",
157+
i, name);
139158
}
140159

141160
ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get,

drivers/clk/sunxi-ng/ccu_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ struct ccu_common {
3131
u16 lock_reg;
3232
u32 prediv;
3333

34+
unsigned long min_rate;
35+
unsigned long max_rate;
36+
3437
unsigned long features;
3538
spinlock_t *lock;
3639
struct clk_hw hw;

0 commit comments

Comments
 (0)