bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0865-clk-Add-clk_get_rate_range.patch
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
5
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.
9
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.
13
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.
18
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
21 clock.
22
23 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
24 ---
25 drivers/clk/clk.c | 18 ++++++++++++++
26 include/linux/clk.h | 59 +++++++++++++++++++++++++++++++++++++++++++++
27 2 files changed, 77 insertions(+)
28
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);
33
34 /**
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
39 + *
40 + * Fills the @min and @max variables with the minimum and maximum that
41 + * the clock source can reach.
42 + */
43 +void clk_get_rate_range(struct clk *clk, unsigned long *min, unsigned long *max)
44 +{
45 + if (!clk || !min || !max)
46 + return;
47 +
48 + clk_core_get_boundaries(clk->core, min, max);
49 +}
50 +EXPORT_SYMBOL_GPL(clk_get_rate_range);
51 +
52 +/**
53 * clk_get_parent - return the parent of a clk
54 * @clk: the clk whose parent gets returned
55 *
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);
60
61 /**
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
66 + *
67 + * Fills the @min and @max variables with the minimum and maximum that
68 + * the clock source can reach.
69 + */
70 +void clk_get_rate_range(struct clk *clk, unsigned long *min, unsigned long *max);
71 +
72 +/**
73 * clk_set_min_rate - set a minimum clock rate for a clock source
74 * @clk: clock source
75 * @rate: desired minimum clock rate in Hz, inclusive
76 @@ -909,6 +920,16 @@ static inline int clk_set_rate_range(str
77 return 0;
78 }
79
80 +static inline void clk_get_rate_range(struct clk *clk, unsigned long *min,
81 + unsigned long *max)
82 +{
83 + if (!min || !max)
84 + return;
85 +
86 + *min = 0;
87 + *max = ULONG_MAX;
88 +}
89 +
90 static inline int clk_set_min_rate(struct clk *clk, unsigned long rate)
91 {
92 return 0;
93 @@ -999,6 +1020,44 @@ static inline int clk_drop_range(struct
94 }
95
96 /**
97 + * clk_get_min_rate - returns the minimum clock rate for a clock source
98 + * @clk: clock source
99 + *
100 + * Returns either the minimum clock rate in Hz that clock source can
101 + * reach, or 0 on error.
102 + */
103 +static inline unsigned long clk_get_min_rate(struct clk *clk)
104 +{
105 + unsigned long min, max;
106 +
107 + if (!clk)
108 + return 0;
109 +
110 + clk_get_rate_range(clk, &min, &max);
111 +
112 + return min;
113 +}
114 +
115 +/**
116 + * clk_get_max_rate - returns the maximum clock rate for a clock source
117 + * @clk: clock source
118 + *
119 + * Returns either the maximum clock rate in Hz that clock source can
120 + * reach, or 0 on error.
121 + */
122 +static inline unsigned long clk_get_max_rate(struct clk *clk)
123 +{
124 + unsigned long min, max;
125 +
126 + if (!clk)
127 + return 0;
128 +
129 + clk_get_rate_range(clk, &min, &max);
130 +
131 + return max;
132 +}
133 +
134 +/**
135 * clk_get_optional - lookup and obtain a reference to an optional clock
136 * producer.
137 * @dev: device for clock "consumer"