1 From ef18a69d3765aeb4dfec3fa4fe4c166ee5a57758 Mon Sep 17 00:00:00 2001
2 From: Jonathan Bell <jonathan@raspberrypi.com>
3 Date: Wed, 6 Mar 2024 10:14:50 +0000
4 Subject: [PATCH 0929/1085] drivers: clk: rp1: constrain clock divider outputs
7 Overclocking peripherals is generally a bad thing to do - so reject any
8 attempt to set a clock output higher than it should be.
10 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
12 drivers/clk/clk-rp1.c | 36 +++++++++++++++++++++++++++++++++++-
13 1 file changed, 35 insertions(+), 1 deletion(-)
15 --- a/drivers/clk/clk-rp1.c
16 +++ b/drivers/clk/clk-rp1.c
17 @@ -361,6 +361,7 @@ struct rp1_clock_data {
21 + unsigned long max_freq;
25 @@ -1211,7 +1212,15 @@ static void rp1_clock_choose_div_and_pra
26 /* Recalculate to account for rounding errors */
27 tmp = (u64)*prate << CLK_DIV_FRAC_BITS;
28 tmp = div_u64(tmp, div);
31 + * Prevent overclocks - if all parent choices result in
32 + * a downstream clock in excess of the maximum, then the
33 + * call to set the clock will fail.
35 + if (tmp > clock->data->max_freq)
41 static int rp1_clock_determine_rate(struct clk_hw *hw,
42 @@ -1672,6 +1681,7 @@ static const struct rp1_clk_desc clk_des
43 .div_int_reg = CLK_SYS_DIV_INT,
44 .sel_reg = CLK_SYS_SEL,
45 .div_int_max = DIV_INT_24BIT_MAX,
46 + .max_freq = 200 * MHz,
47 .fc0_src = FC_NUM(0, 4),
50 @@ -1685,6 +1695,7 @@ static const struct rp1_clk_desc clk_des
51 .div_int_reg = CLK_SLOW_SYS_DIV_INT,
52 .sel_reg = CLK_SLOW_SYS_SEL,
53 .div_int_max = DIV_INT_8BIT_MAX,
54 + .max_freq = 50 * MHz,
55 .fc0_src = FC_NUM(1, 4),
58 @@ -1706,6 +1717,7 @@ static const struct rp1_clk_desc clk_des
59 .div_int_reg = CLK_UART_DIV_INT,
60 .sel_reg = CLK_UART_SEL,
61 .div_int_max = DIV_INT_8BIT_MAX,
62 + .max_freq = 100 * MHz,
63 .fc0_src = FC_NUM(6, 7),
66 @@ -1726,6 +1738,7 @@ static const struct rp1_clk_desc clk_des
67 .div_int_reg = CLK_ETH_DIV_INT,
68 .sel_reg = CLK_ETH_SEL,
69 .div_int_max = DIV_INT_8BIT_MAX,
70 + .max_freq = 125 * MHz,
71 .fc0_src = FC_NUM(4, 6),
74 @@ -1747,6 +1760,7 @@ static const struct rp1_clk_desc clk_des
75 .div_frac_reg = CLK_PWM0_DIV_FRAC,
76 .sel_reg = CLK_PWM0_SEL,
77 .div_int_max = DIV_INT_16BIT_MAX,
78 + .max_freq = 76800 * KHz,
79 .fc0_src = FC_NUM(0, 5),
82 @@ -1768,6 +1782,7 @@ static const struct rp1_clk_desc clk_des
83 .div_frac_reg = CLK_PWM1_DIV_FRAC,
84 .sel_reg = CLK_PWM1_SEL,
85 .div_int_max = DIV_INT_16BIT_MAX,
86 + .max_freq = 76800 * KHz,
87 .fc0_src = FC_NUM(1, 5),
90 @@ -1790,6 +1805,7 @@ static const struct rp1_clk_desc clk_des
91 .div_int_reg = CLK_AUDIO_IN_DIV_INT,
92 .sel_reg = CLK_AUDIO_IN_SEL,
93 .div_int_max = DIV_INT_8BIT_MAX,
94 + .max_freq = 76800 * KHz,
95 .fc0_src = FC_NUM(2, 5),
98 @@ -1811,6 +1827,7 @@ static const struct rp1_clk_desc clk_des
99 .div_int_reg = CLK_AUDIO_OUT_DIV_INT,
100 .sel_reg = CLK_AUDIO_OUT_SEL,
101 .div_int_max = DIV_INT_8BIT_MAX,
102 + .max_freq = 153600 * KHz,
103 .fc0_src = FC_NUM(3, 5),
106 @@ -1831,6 +1848,7 @@ static const struct rp1_clk_desc clk_des
107 .div_int_reg = CLK_I2S_DIV_INT,
108 .sel_reg = CLK_I2S_SEL,
109 .div_int_max = DIV_INT_8BIT_MAX,
110 + .max_freq = 50 * MHz,
111 .fc0_src = FC_NUM(4, 4),
114 @@ -1843,6 +1861,7 @@ static const struct rp1_clk_desc clk_des
115 .div_int_reg = CLK_MIPI0_CFG_DIV_INT,
116 .sel_reg = CLK_MIPI0_CFG_SEL,
117 .div_int_max = DIV_INT_8BIT_MAX,
118 + .max_freq = 50 * MHz,
119 .fc0_src = FC_NUM(4, 5),
122 @@ -1856,6 +1875,7 @@ static const struct rp1_clk_desc clk_des
123 .sel_reg = CLK_MIPI1_CFG_SEL,
125 .div_int_max = DIV_INT_8BIT_MAX,
126 + .max_freq = 50 * MHz,
127 .fc0_src = FC_NUM(5, 6),
130 @@ -1875,6 +1895,7 @@ static const struct rp1_clk_desc clk_des
131 .div_int_reg = CLK_ETH_TSU_DIV_INT,
132 .sel_reg = CLK_ETH_TSU_SEL,
133 .div_int_max = DIV_INT_8BIT_MAX,
134 + .max_freq = 50 * MHz,
135 .fc0_src = FC_NUM(5, 7),
138 @@ -1894,6 +1915,7 @@ static const struct rp1_clk_desc clk_des
139 .div_int_reg = CLK_ADC_DIV_INT,
140 .sel_reg = CLK_ADC_SEL,
141 .div_int_max = DIV_INT_8BIT_MAX,
142 + .max_freq = 50 * MHz,
143 .fc0_src = FC_NUM(5, 5),
146 @@ -1906,6 +1928,7 @@ static const struct rp1_clk_desc clk_des
147 .div_int_reg = CLK_SDIO_TIMER_DIV_INT,
148 .sel_reg = CLK_SDIO_TIMER_SEL,
149 .div_int_max = DIV_INT_8BIT_MAX,
150 + .max_freq = 50 * MHz,
151 .fc0_src = FC_NUM(3, 4),
154 @@ -1918,6 +1941,7 @@ static const struct rp1_clk_desc clk_des
155 .div_int_reg = CLK_SDIO_ALT_SRC_DIV_INT,
156 .sel_reg = CLK_SDIO_ALT_SRC_SEL,
157 .div_int_max = DIV_INT_8BIT_MAX,
158 + .max_freq = 200 * MHz,
159 .fc0_src = FC_NUM(5, 4),
162 @@ -1947,6 +1971,7 @@ static const struct rp1_clk_desc clk_des
163 .div_frac_reg = CLK_GP0_DIV_FRAC,
164 .sel_reg = CLK_GP0_SEL,
165 .div_int_max = DIV_INT_16BIT_MAX,
166 + .max_freq = 100 * MHz,
167 .fc0_src = FC_NUM(0, 1),
170 @@ -1976,6 +2001,7 @@ static const struct rp1_clk_desc clk_des
171 .div_frac_reg = CLK_GP1_DIV_FRAC,
172 .sel_reg = CLK_GP1_SEL,
173 .div_int_max = DIV_INT_16BIT_MAX,
174 + .max_freq = 100 * MHz,
175 .fc0_src = FC_NUM(1, 1),
178 @@ -2005,6 +2031,7 @@ static const struct rp1_clk_desc clk_des
179 .div_frac_reg = CLK_GP2_DIV_FRAC,
180 .sel_reg = CLK_GP2_SEL,
181 .div_int_max = DIV_INT_16BIT_MAX,
182 + .max_freq = 100 * MHz,
183 .fc0_src = FC_NUM(2, 1),
186 @@ -2034,6 +2061,7 @@ static const struct rp1_clk_desc clk_des
187 .div_frac_reg = CLK_GP3_DIV_FRAC,
188 .sel_reg = CLK_GP3_SEL,
189 .div_int_max = DIV_INT_16BIT_MAX,
190 + .max_freq = 100 * MHz,
191 .fc0_src = FC_NUM(3, 1),
194 @@ -2064,6 +2092,7 @@ static const struct rp1_clk_desc clk_des
195 .div_frac_reg = CLK_GP4_DIV_FRAC,
196 .sel_reg = CLK_GP4_SEL,
197 .div_int_max = DIV_INT_16BIT_MAX,
198 + .max_freq = 100 * MHz,
199 .fc0_src = FC_NUM(4, 1),
202 @@ -2093,6 +2122,7 @@ static const struct rp1_clk_desc clk_des
203 .div_frac_reg = CLK_GP5_DIV_FRAC,
204 .sel_reg = CLK_GP5_SEL,
205 .div_int_max = DIV_INT_16BIT_MAX,
206 + .max_freq = 100 * MHz,
207 .fc0_src = FC_NUM(5, 1),
210 @@ -2113,6 +2143,7 @@ static const struct rp1_clk_desc clk_des
211 .sel_reg = VIDEO_CLK_VEC_SEL,
212 .flags = CLK_SET_RATE_NO_REPARENT, /* Let VEC driver set parent */
213 .div_int_max = DIV_INT_8BIT_MAX,
214 + .max_freq = 108 * MHz,
215 .fc0_src = FC_NUM(0, 6),
218 @@ -2133,6 +2164,7 @@ static const struct rp1_clk_desc clk_des
219 .sel_reg = VIDEO_CLK_DPI_SEL,
220 .flags = CLK_SET_RATE_NO_REPARENT, /* Let DPI driver set parent */
221 .div_int_max = DIV_INT_8BIT_MAX,
222 + .max_freq = 200 * MHz,
223 .fc0_src = FC_NUM(1, 6),
226 @@ -2154,6 +2186,7 @@ static const struct rp1_clk_desc clk_des
227 .sel_reg = VIDEO_CLK_MIPI0_DPI_SEL,
228 .flags = CLK_SET_RATE_NO_REPARENT, /* Let DSI driver set parent */
229 .div_int_max = DIV_INT_8BIT_MAX,
230 + .max_freq = 200 * MHz,
231 .fc0_src = FC_NUM(2, 6),
234 @@ -2175,6 +2208,7 @@ static const struct rp1_clk_desc clk_des
235 .sel_reg = VIDEO_CLK_MIPI1_DPI_SEL,
236 .flags = CLK_SET_RATE_NO_REPARENT, /* Let DSI driver set parent */
237 .div_int_max = DIV_INT_8BIT_MAX,
238 + .max_freq = 200 * MHz,
239 .fc0_src = FC_NUM(3, 6),