1 From 1008f7a86f470914e78a54a2a75cf8bbc8b8f9db Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Fri, 15 Apr 2022 14:17:41 +0200
4 Subject: [PATCH] clk: Add clk_get_rate_range
6 With the recent introduction of clock drivers that will force their
7 clock rate to either the minimum or maximum boundaries, it becomes
8 harder for clock users to discover either boundary of their clock.
10 Indeed, the best way to do that previously was to call clk_round_rate()
11 on either 0 or ULONG_MAX and count on the driver to clamp the rate to
12 the current boundary, but that won't work anymore.
14 Since any other alternative (calling clk_set_rate_range() and looking at
15 the returned value, calling clk_round_rate() still, or just doing
16 nothing) depends on how the driver will behaves, we actually are
17 punching a hole through the abstraction provided by the clock framework.
19 In order to avoid any abstraction violation, let's create a bunch of
20 accessors that will return the current minimum and maximum for a given
23 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
25 drivers/clk/clk.c | 18 ++++++++++++++
26 include/linux/clk.h | 59 +++++++++++++++++++++++++++++++++++++++++++++
27 2 files changed, 77 insertions(+)
29 --- a/drivers/clk/clk.c
30 +++ b/drivers/clk/clk.c
31 @@ -2576,6 +2576,24 @@ int clk_set_max_rate(struct clk *clk, un
32 EXPORT_SYMBOL_GPL(clk_set_max_rate);
35 + * clk_get_rate_range - returns the clock rate range for a clock source
36 + * @clk: clock source
37 + * @min: Pointer to the variable that will hold the minimum
38 + * @max: Pointer to the variable that will hold the maximum
40 + * Fills the @min and @max variables with the minimum and maximum that
41 + * the clock source can reach.
43 +void clk_get_rate_range(struct clk *clk, unsigned long *min, unsigned long *max)
45 + if (!clk || !min || !max)
48 + clk_core_get_boundaries(clk->core, min, max);
50 +EXPORT_SYMBOL_GPL(clk_get_rate_range);
53 * clk_get_parent - return the parent of a clk
54 * @clk: the clk whose parent gets returned
56 --- a/include/linux/clk.h
57 +++ b/include/linux/clk.h
58 @@ -714,6 +714,17 @@ bool clk_has_parent(struct clk *clk, str
59 int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max);
62 + * clk_get_rate_range - returns the clock rate range for a clock source
63 + * @clk: clock source
64 + * @min: Pointer to the variable that will hold the minimum
65 + * @max: Pointer to the variable that will hold the maximum
67 + * Fills the @min and @max variables with the minimum and maximum that
68 + * the clock source can reach.
70 +void clk_get_rate_range(struct clk *clk, unsigned long *min, unsigned long *max);
73 * clk_set_min_rate - set a minimum clock rate for a clock source
75 * @rate: desired minimum clock rate in Hz, inclusive
76 @@ -909,6 +920,16 @@ static inline int clk_set_rate_range(str
80 +static inline void clk_get_rate_range(struct clk *clk, unsigned long *min,
90 static inline int clk_set_min_rate(struct clk *clk, unsigned long rate)
93 @@ -999,6 +1020,44 @@ static inline int clk_drop_range(struct
97 + * clk_get_min_rate - returns the minimum clock rate for a clock source
98 + * @clk: clock source
100 + * Returns either the minimum clock rate in Hz that clock source can
101 + * reach, or 0 on error.
103 +static inline unsigned long clk_get_min_rate(struct clk *clk)
105 + unsigned long min, max;
110 + clk_get_rate_range(clk, &min, &max);
116 + * clk_get_max_rate - returns the maximum clock rate for a clock source
117 + * @clk: clock source
119 + * Returns either the maximum clock rate in Hz that clock source can
120 + * reach, or 0 on error.
122 +static inline unsigned long clk_get_max_rate(struct clk *clk)
124 + unsigned long min, max;
129 + clk_get_rate_range(clk, &min, &max);
135 * clk_get_optional - lookup and obtain a reference to an optional clock
137 * @dev: device for clock "consumer"