blob: 75197664a7ee87b214ec7b9f4b4b815b5546f677 [file] [log] [blame]
Michael Turquette738f66d2016-05-23 15:44:26 -07001/*
Paul Gortmaker1f501d632016-07-04 17:12:12 -04002 * AmLogic S905 / GXBB Clock Controller Driver
3 *
Michael Turquette738f66d2016-05-23 15:44:26 -07004 * Copyright (c) 2016 AmLogic, Inc.
5 * Michael Turquette <mturquette@baylibre.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/clk.h>
21#include <linux/clk-provider.h>
22#include <linux/of_address.h>
Neil Armstrong0d48fc52017-03-22 11:32:25 +010023#include <linux/of_device.h>
Michael Turquette738f66d2016-05-23 15:44:26 -070024#include <linux/platform_device.h>
Paul Gortmaker1f501d632016-07-04 17:12:12 -040025#include <linux/init.h>
Michael Turquette738f66d2016-05-23 15:44:26 -070026
27#include "clkc.h"
28#include "gxbb.h"
29
30static DEFINE_SPINLOCK(clk_lock);
31
32static const struct pll_rate_table sys_pll_rate_table[] = {
33 PLL_RATE(24000000, 56, 1, 2),
34 PLL_RATE(48000000, 64, 1, 2),
35 PLL_RATE(72000000, 72, 1, 2),
36 PLL_RATE(96000000, 64, 1, 2),
37 PLL_RATE(120000000, 80, 1, 2),
38 PLL_RATE(144000000, 96, 1, 2),
39 PLL_RATE(168000000, 56, 1, 1),
40 PLL_RATE(192000000, 64, 1, 1),
41 PLL_RATE(216000000, 72, 1, 1),
42 PLL_RATE(240000000, 80, 1, 1),
43 PLL_RATE(264000000, 88, 1, 1),
44 PLL_RATE(288000000, 96, 1, 1),
45 PLL_RATE(312000000, 52, 1, 2),
46 PLL_RATE(336000000, 56, 1, 2),
47 PLL_RATE(360000000, 60, 1, 2),
48 PLL_RATE(384000000, 64, 1, 2),
49 PLL_RATE(408000000, 68, 1, 2),
50 PLL_RATE(432000000, 72, 1, 2),
51 PLL_RATE(456000000, 76, 1, 2),
52 PLL_RATE(480000000, 80, 1, 2),
53 PLL_RATE(504000000, 84, 1, 2),
54 PLL_RATE(528000000, 88, 1, 2),
55 PLL_RATE(552000000, 92, 1, 2),
56 PLL_RATE(576000000, 96, 1, 2),
57 PLL_RATE(600000000, 50, 1, 1),
58 PLL_RATE(624000000, 52, 1, 1),
59 PLL_RATE(648000000, 54, 1, 1),
60 PLL_RATE(672000000, 56, 1, 1),
61 PLL_RATE(696000000, 58, 1, 1),
62 PLL_RATE(720000000, 60, 1, 1),
63 PLL_RATE(744000000, 62, 1, 1),
64 PLL_RATE(768000000, 64, 1, 1),
65 PLL_RATE(792000000, 66, 1, 1),
66 PLL_RATE(816000000, 68, 1, 1),
67 PLL_RATE(840000000, 70, 1, 1),
68 PLL_RATE(864000000, 72, 1, 1),
69 PLL_RATE(888000000, 74, 1, 1),
70 PLL_RATE(912000000, 76, 1, 1),
71 PLL_RATE(936000000, 78, 1, 1),
72 PLL_RATE(960000000, 80, 1, 1),
73 PLL_RATE(984000000, 82, 1, 1),
74 PLL_RATE(1008000000, 84, 1, 1),
75 PLL_RATE(1032000000, 86, 1, 1),
76 PLL_RATE(1056000000, 88, 1, 1),
77 PLL_RATE(1080000000, 90, 1, 1),
78 PLL_RATE(1104000000, 92, 1, 1),
79 PLL_RATE(1128000000, 94, 1, 1),
80 PLL_RATE(1152000000, 96, 1, 1),
81 PLL_RATE(1176000000, 98, 1, 1),
82 PLL_RATE(1200000000, 50, 1, 0),
83 PLL_RATE(1224000000, 51, 1, 0),
84 PLL_RATE(1248000000, 52, 1, 0),
85 PLL_RATE(1272000000, 53, 1, 0),
86 PLL_RATE(1296000000, 54, 1, 0),
87 PLL_RATE(1320000000, 55, 1, 0),
88 PLL_RATE(1344000000, 56, 1, 0),
89 PLL_RATE(1368000000, 57, 1, 0),
90 PLL_RATE(1392000000, 58, 1, 0),
91 PLL_RATE(1416000000, 59, 1, 0),
92 PLL_RATE(1440000000, 60, 1, 0),
93 PLL_RATE(1464000000, 61, 1, 0),
94 PLL_RATE(1488000000, 62, 1, 0),
95 PLL_RATE(1512000000, 63, 1, 0),
96 PLL_RATE(1536000000, 64, 1, 0),
97 PLL_RATE(1560000000, 65, 1, 0),
98 PLL_RATE(1584000000, 66, 1, 0),
99 PLL_RATE(1608000000, 67, 1, 0),
100 PLL_RATE(1632000000, 68, 1, 0),
101 PLL_RATE(1656000000, 68, 1, 0),
102 PLL_RATE(1680000000, 68, 1, 0),
103 PLL_RATE(1704000000, 68, 1, 0),
104 PLL_RATE(1728000000, 69, 1, 0),
105 PLL_RATE(1752000000, 69, 1, 0),
106 PLL_RATE(1776000000, 69, 1, 0),
107 PLL_RATE(1800000000, 69, 1, 0),
108 PLL_RATE(1824000000, 70, 1, 0),
109 PLL_RATE(1848000000, 70, 1, 0),
110 PLL_RATE(1872000000, 70, 1, 0),
111 PLL_RATE(1896000000, 70, 1, 0),
112 PLL_RATE(1920000000, 71, 1, 0),
113 PLL_RATE(1944000000, 71, 1, 0),
114 PLL_RATE(1968000000, 71, 1, 0),
115 PLL_RATE(1992000000, 71, 1, 0),
116 PLL_RATE(2016000000, 72, 1, 0),
117 PLL_RATE(2040000000, 72, 1, 0),
118 PLL_RATE(2064000000, 72, 1, 0),
119 PLL_RATE(2088000000, 72, 1, 0),
120 PLL_RATE(2112000000, 73, 1, 0),
121 { /* sentinel */ },
122};
123
Neil Armstrong0d48fc52017-03-22 11:32:25 +0100124static const struct pll_rate_table gxbb_gp0_pll_rate_table[] = {
Michael Turquette738f66d2016-05-23 15:44:26 -0700125 PLL_RATE(96000000, 32, 1, 3),
126 PLL_RATE(99000000, 33, 1, 3),
127 PLL_RATE(102000000, 34, 1, 3),
128 PLL_RATE(105000000, 35, 1, 3),
129 PLL_RATE(108000000, 36, 1, 3),
130 PLL_RATE(111000000, 37, 1, 3),
131 PLL_RATE(114000000, 38, 1, 3),
132 PLL_RATE(117000000, 39, 1, 3),
133 PLL_RATE(120000000, 40, 1, 3),
134 PLL_RATE(123000000, 41, 1, 3),
135 PLL_RATE(126000000, 42, 1, 3),
136 PLL_RATE(129000000, 43, 1, 3),
137 PLL_RATE(132000000, 44, 1, 3),
138 PLL_RATE(135000000, 45, 1, 3),
139 PLL_RATE(138000000, 46, 1, 3),
140 PLL_RATE(141000000, 47, 1, 3),
141 PLL_RATE(144000000, 48, 1, 3),
142 PLL_RATE(147000000, 49, 1, 3),
143 PLL_RATE(150000000, 50, 1, 3),
144 PLL_RATE(153000000, 51, 1, 3),
145 PLL_RATE(156000000, 52, 1, 3),
146 PLL_RATE(159000000, 53, 1, 3),
147 PLL_RATE(162000000, 54, 1, 3),
148 PLL_RATE(165000000, 55, 1, 3),
149 PLL_RATE(168000000, 56, 1, 3),
150 PLL_RATE(171000000, 57, 1, 3),
151 PLL_RATE(174000000, 58, 1, 3),
152 PLL_RATE(177000000, 59, 1, 3),
153 PLL_RATE(180000000, 60, 1, 3),
154 PLL_RATE(183000000, 61, 1, 3),
155 PLL_RATE(186000000, 62, 1, 3),
156 PLL_RATE(192000000, 32, 1, 2),
157 PLL_RATE(198000000, 33, 1, 2),
158 PLL_RATE(204000000, 34, 1, 2),
159 PLL_RATE(210000000, 35, 1, 2),
160 PLL_RATE(216000000, 36, 1, 2),
161 PLL_RATE(222000000, 37, 1, 2),
162 PLL_RATE(228000000, 38, 1, 2),
163 PLL_RATE(234000000, 39, 1, 2),
164 PLL_RATE(240000000, 40, 1, 2),
165 PLL_RATE(246000000, 41, 1, 2),
166 PLL_RATE(252000000, 42, 1, 2),
167 PLL_RATE(258000000, 43, 1, 2),
168 PLL_RATE(264000000, 44, 1, 2),
169 PLL_RATE(270000000, 45, 1, 2),
170 PLL_RATE(276000000, 46, 1, 2),
171 PLL_RATE(282000000, 47, 1, 2),
172 PLL_RATE(288000000, 48, 1, 2),
173 PLL_RATE(294000000, 49, 1, 2),
174 PLL_RATE(300000000, 50, 1, 2),
175 PLL_RATE(306000000, 51, 1, 2),
176 PLL_RATE(312000000, 52, 1, 2),
177 PLL_RATE(318000000, 53, 1, 2),
178 PLL_RATE(324000000, 54, 1, 2),
179 PLL_RATE(330000000, 55, 1, 2),
180 PLL_RATE(336000000, 56, 1, 2),
181 PLL_RATE(342000000, 57, 1, 2),
182 PLL_RATE(348000000, 58, 1, 2),
183 PLL_RATE(354000000, 59, 1, 2),
184 PLL_RATE(360000000, 60, 1, 2),
185 PLL_RATE(366000000, 61, 1, 2),
186 PLL_RATE(372000000, 62, 1, 2),
187 PLL_RATE(384000000, 32, 1, 1),
188 PLL_RATE(396000000, 33, 1, 1),
189 PLL_RATE(408000000, 34, 1, 1),
190 PLL_RATE(420000000, 35, 1, 1),
191 PLL_RATE(432000000, 36, 1, 1),
192 PLL_RATE(444000000, 37, 1, 1),
193 PLL_RATE(456000000, 38, 1, 1),
194 PLL_RATE(468000000, 39, 1, 1),
195 PLL_RATE(480000000, 40, 1, 1),
196 PLL_RATE(492000000, 41, 1, 1),
197 PLL_RATE(504000000, 42, 1, 1),
198 PLL_RATE(516000000, 43, 1, 1),
199 PLL_RATE(528000000, 44, 1, 1),
200 PLL_RATE(540000000, 45, 1, 1),
201 PLL_RATE(552000000, 46, 1, 1),
202 PLL_RATE(564000000, 47, 1, 1),
203 PLL_RATE(576000000, 48, 1, 1),
204 PLL_RATE(588000000, 49, 1, 1),
205 PLL_RATE(600000000, 50, 1, 1),
206 PLL_RATE(612000000, 51, 1, 1),
207 PLL_RATE(624000000, 52, 1, 1),
208 PLL_RATE(636000000, 53, 1, 1),
209 PLL_RATE(648000000, 54, 1, 1),
210 PLL_RATE(660000000, 55, 1, 1),
211 PLL_RATE(672000000, 56, 1, 1),
212 PLL_RATE(684000000, 57, 1, 1),
213 PLL_RATE(696000000, 58, 1, 1),
214 PLL_RATE(708000000, 59, 1, 1),
215 PLL_RATE(720000000, 60, 1, 1),
216 PLL_RATE(732000000, 61, 1, 1),
217 PLL_RATE(744000000, 62, 1, 1),
218 PLL_RATE(768000000, 32, 1, 0),
219 PLL_RATE(792000000, 33, 1, 0),
220 PLL_RATE(816000000, 34, 1, 0),
221 PLL_RATE(840000000, 35, 1, 0),
222 PLL_RATE(864000000, 36, 1, 0),
223 PLL_RATE(888000000, 37, 1, 0),
224 PLL_RATE(912000000, 38, 1, 0),
225 PLL_RATE(936000000, 39, 1, 0),
226 PLL_RATE(960000000, 40, 1, 0),
227 PLL_RATE(984000000, 41, 1, 0),
228 PLL_RATE(1008000000, 42, 1, 0),
229 PLL_RATE(1032000000, 43, 1, 0),
230 PLL_RATE(1056000000, 44, 1, 0),
231 PLL_RATE(1080000000, 45, 1, 0),
232 PLL_RATE(1104000000, 46, 1, 0),
233 PLL_RATE(1128000000, 47, 1, 0),
234 PLL_RATE(1152000000, 48, 1, 0),
235 PLL_RATE(1176000000, 49, 1, 0),
236 PLL_RATE(1200000000, 50, 1, 0),
237 PLL_RATE(1224000000, 51, 1, 0),
238 PLL_RATE(1248000000, 52, 1, 0),
239 PLL_RATE(1272000000, 53, 1, 0),
240 PLL_RATE(1296000000, 54, 1, 0),
241 PLL_RATE(1320000000, 55, 1, 0),
242 PLL_RATE(1344000000, 56, 1, 0),
243 PLL_RATE(1368000000, 57, 1, 0),
244 PLL_RATE(1392000000, 58, 1, 0),
245 PLL_RATE(1416000000, 59, 1, 0),
246 PLL_RATE(1440000000, 60, 1, 0),
247 PLL_RATE(1464000000, 61, 1, 0),
248 PLL_RATE(1488000000, 62, 1, 0),
249 { /* sentinel */ },
250};
251
Neil Armstrong0d48fc52017-03-22 11:32:25 +0100252static const struct pll_rate_table gxl_gp0_pll_rate_table[] = {
253 PLL_RATE(504000000, 42, 1, 1),
254 PLL_RATE(516000000, 43, 1, 1),
255 PLL_RATE(528000000, 44, 1, 1),
256 PLL_RATE(540000000, 45, 1, 1),
257 PLL_RATE(552000000, 46, 1, 1),
258 PLL_RATE(564000000, 47, 1, 1),
259 PLL_RATE(576000000, 48, 1, 1),
260 PLL_RATE(588000000, 49, 1, 1),
261 PLL_RATE(600000000, 50, 1, 1),
262 PLL_RATE(612000000, 51, 1, 1),
263 PLL_RATE(624000000, 52, 1, 1),
264 PLL_RATE(636000000, 53, 1, 1),
265 PLL_RATE(648000000, 54, 1, 1),
266 PLL_RATE(660000000, 55, 1, 1),
267 PLL_RATE(672000000, 56, 1, 1),
268 PLL_RATE(684000000, 57, 1, 1),
269 PLL_RATE(696000000, 58, 1, 1),
270 PLL_RATE(708000000, 59, 1, 1),
271 PLL_RATE(720000000, 60, 1, 1),
272 PLL_RATE(732000000, 61, 1, 1),
273 PLL_RATE(744000000, 62, 1, 1),
274 PLL_RATE(756000000, 63, 1, 1),
275 PLL_RATE(768000000, 64, 1, 1),
276 PLL_RATE(780000000, 65, 1, 1),
277 PLL_RATE(792000000, 66, 1, 1),
278 { /* sentinel */ },
279};
280
Michael Turquette738f66d2016-05-23 15:44:26 -0700281static const struct clk_div_table cpu_div_table[] = {
282 { .val = 1, .div = 1 },
283 { .val = 2, .div = 2 },
284 { .val = 3, .div = 3 },
285 { .val = 2, .div = 4 },
286 { .val = 3, .div = 6 },
287 { .val = 4, .div = 8 },
288 { .val = 5, .div = 10 },
289 { .val = 6, .div = 12 },
290 { .val = 7, .div = 14 },
291 { .val = 8, .div = 16 },
292 { /* sentinel */ },
293};
294
295static struct meson_clk_pll gxbb_fixed_pll = {
296 .m = {
297 .reg_off = HHI_MPLL_CNTL,
298 .shift = 0,
299 .width = 9,
300 },
301 .n = {
302 .reg_off = HHI_MPLL_CNTL,
303 .shift = 9,
304 .width = 5,
305 },
306 .od = {
307 .reg_off = HHI_MPLL_CNTL,
308 .shift = 16,
309 .width = 2,
310 },
311 .lock = &clk_lock,
312 .hw.init = &(struct clk_init_data){
313 .name = "fixed_pll",
314 .ops = &meson_clk_pll_ro_ops,
315 .parent_names = (const char *[]){ "xtal" },
316 .num_parents = 1,
317 .flags = CLK_GET_RATE_NOCACHE,
318 },
319};
320
321static struct meson_clk_pll gxbb_hdmi_pll = {
322 .m = {
323 .reg_off = HHI_HDMI_PLL_CNTL,
324 .shift = 0,
325 .width = 9,
326 },
327 .n = {
328 .reg_off = HHI_HDMI_PLL_CNTL,
329 .shift = 9,
330 .width = 5,
331 },
332 .frac = {
333 .reg_off = HHI_HDMI_PLL_CNTL2,
334 .shift = 0,
335 .width = 12,
336 },
337 .od = {
338 .reg_off = HHI_HDMI_PLL_CNTL2,
339 .shift = 16,
340 .width = 2,
341 },
342 .od2 = {
343 .reg_off = HHI_HDMI_PLL_CNTL2,
344 .shift = 22,
345 .width = 2,
346 },
347 .lock = &clk_lock,
348 .hw.init = &(struct clk_init_data){
349 .name = "hdmi_pll",
350 .ops = &meson_clk_pll_ro_ops,
351 .parent_names = (const char *[]){ "xtal" },
352 .num_parents = 1,
353 .flags = CLK_GET_RATE_NOCACHE,
354 },
355};
356
357static struct meson_clk_pll gxbb_sys_pll = {
358 .m = {
359 .reg_off = HHI_SYS_PLL_CNTL,
360 .shift = 0,
361 .width = 9,
362 },
363 .n = {
364 .reg_off = HHI_SYS_PLL_CNTL,
365 .shift = 9,
366 .width = 5,
367 },
368 .od = {
369 .reg_off = HHI_SYS_PLL_CNTL,
370 .shift = 10,
371 .width = 2,
372 },
373 .rate_table = sys_pll_rate_table,
374 .rate_count = ARRAY_SIZE(sys_pll_rate_table),
375 .lock = &clk_lock,
376 .hw.init = &(struct clk_init_data){
377 .name = "sys_pll",
378 .ops = &meson_clk_pll_ro_ops,
379 .parent_names = (const char *[]){ "xtal" },
380 .num_parents = 1,
381 .flags = CLK_GET_RATE_NOCACHE,
382 },
383};
384
Neil Armstronge194401c2017-03-22 11:32:24 +0100385struct pll_params_table gxbb_gp0_params_table[] = {
386 PLL_PARAM(HHI_GP0_PLL_CNTL, 0x6a000228),
387 PLL_PARAM(HHI_GP0_PLL_CNTL2, 0x69c80000),
388 PLL_PARAM(HHI_GP0_PLL_CNTL3, 0x0a5590c4),
389 PLL_PARAM(HHI_GP0_PLL_CNTL4, 0x0000500d),
390};
391
Michael Turquette738f66d2016-05-23 15:44:26 -0700392static struct meson_clk_pll gxbb_gp0_pll = {
393 .m = {
394 .reg_off = HHI_GP0_PLL_CNTL,
395 .shift = 0,
396 .width = 9,
397 },
398 .n = {
399 .reg_off = HHI_GP0_PLL_CNTL,
400 .shift = 9,
401 .width = 5,
402 },
403 .od = {
404 .reg_off = HHI_GP0_PLL_CNTL,
405 .shift = 16,
406 .width = 2,
407 },
Neil Armstronge194401c2017-03-22 11:32:24 +0100408 .params = {
409 .params_table = gxbb_gp0_params_table,
410 .params_count = ARRAY_SIZE(gxbb_gp0_params_table),
411 .no_init_reset = true,
412 .clear_reset_for_lock = true,
413 },
Neil Armstrong0d48fc52017-03-22 11:32:25 +0100414 .rate_table = gxbb_gp0_pll_rate_table,
415 .rate_count = ARRAY_SIZE(gxbb_gp0_pll_rate_table),
416 .lock = &clk_lock,
417 .hw.init = &(struct clk_init_data){
418 .name = "gp0_pll",
419 .ops = &meson_clk_pll_ops,
420 .parent_names = (const char *[]){ "xtal" },
421 .num_parents = 1,
422 .flags = CLK_GET_RATE_NOCACHE,
423 },
424};
425
426struct pll_params_table gxl_gp0_params_table[] = {
427 PLL_PARAM(HHI_GP0_PLL_CNTL, 0x40010250),
428 PLL_PARAM(HHI_GP0_PLL_CNTL1, 0xc084a000),
429 PLL_PARAM(HHI_GP0_PLL_CNTL2, 0xb75020be),
430 PLL_PARAM(HHI_GP0_PLL_CNTL3, 0x0a59a288),
431 PLL_PARAM(HHI_GP0_PLL_CNTL4, 0xc000004d),
432 PLL_PARAM(HHI_GP0_PLL_CNTL5, 0x00078000),
433};
434
435static struct meson_clk_pll gxl_gp0_pll = {
436 .m = {
437 .reg_off = HHI_GP0_PLL_CNTL,
438 .shift = 0,
439 .width = 9,
440 },
441 .n = {
442 .reg_off = HHI_GP0_PLL_CNTL,
443 .shift = 9,
444 .width = 5,
445 },
446 .od = {
447 .reg_off = HHI_GP0_PLL_CNTL,
448 .shift = 16,
449 .width = 2,
450 },
451 .params = {
452 .params_table = gxl_gp0_params_table,
453 .params_count = ARRAY_SIZE(gxl_gp0_params_table),
454 .no_init_reset = true,
455 .reset_lock_loop = true,
456 },
457 .rate_table = gxl_gp0_pll_rate_table,
458 .rate_count = ARRAY_SIZE(gxl_gp0_pll_rate_table),
Michael Turquette738f66d2016-05-23 15:44:26 -0700459 .lock = &clk_lock,
460 .hw.init = &(struct clk_init_data){
461 .name = "gp0_pll",
462 .ops = &meson_clk_pll_ops,
463 .parent_names = (const char *[]){ "xtal" },
464 .num_parents = 1,
465 .flags = CLK_GET_RATE_NOCACHE,
466 },
467};
468
469static struct clk_fixed_factor gxbb_fclk_div2 = {
470 .mult = 1,
471 .div = 2,
472 .hw.init = &(struct clk_init_data){
473 .name = "fclk_div2",
474 .ops = &clk_fixed_factor_ops,
475 .parent_names = (const char *[]){ "fixed_pll" },
476 .num_parents = 1,
477 },
478};
479
480static struct clk_fixed_factor gxbb_fclk_div3 = {
481 .mult = 1,
482 .div = 3,
483 .hw.init = &(struct clk_init_data){
484 .name = "fclk_div3",
485 .ops = &clk_fixed_factor_ops,
486 .parent_names = (const char *[]){ "fixed_pll" },
487 .num_parents = 1,
488 },
489};
490
491static struct clk_fixed_factor gxbb_fclk_div4 = {
492 .mult = 1,
493 .div = 4,
494 .hw.init = &(struct clk_init_data){
495 .name = "fclk_div4",
496 .ops = &clk_fixed_factor_ops,
497 .parent_names = (const char *[]){ "fixed_pll" },
498 .num_parents = 1,
499 },
500};
501
502static struct clk_fixed_factor gxbb_fclk_div5 = {
503 .mult = 1,
504 .div = 5,
505 .hw.init = &(struct clk_init_data){
506 .name = "fclk_div5",
507 .ops = &clk_fixed_factor_ops,
508 .parent_names = (const char *[]){ "fixed_pll" },
509 .num_parents = 1,
510 },
511};
512
513static struct clk_fixed_factor gxbb_fclk_div7 = {
514 .mult = 1,
515 .div = 7,
516 .hw.init = &(struct clk_init_data){
517 .name = "fclk_div7",
518 .ops = &clk_fixed_factor_ops,
519 .parent_names = (const char *[]){ "fixed_pll" },
520 .num_parents = 1,
521 },
522};
523
524static struct meson_clk_mpll gxbb_mpll0 = {
525 .sdm = {
526 .reg_off = HHI_MPLL_CNTL7,
527 .shift = 0,
528 .width = 14,
529 },
Jerome Brunet007e6e52017-03-09 11:41:50 +0100530 .sdm_en = {
531 .reg_off = HHI_MPLL_CNTL7,
532 .shift = 15,
533 .width = 1,
534 },
Michael Turquette738f66d2016-05-23 15:44:26 -0700535 .n2 = {
536 .reg_off = HHI_MPLL_CNTL7,
537 .shift = 16,
538 .width = 9,
539 },
Jerome Brunet007e6e52017-03-09 11:41:50 +0100540 .en = {
541 .reg_off = HHI_MPLL_CNTL7,
542 .shift = 14,
543 .width = 1,
544 },
Michael Turquette738f66d2016-05-23 15:44:26 -0700545 .lock = &clk_lock,
546 .hw.init = &(struct clk_init_data){
547 .name = "mpll0",
Jerome Brunet05b43aa2017-03-09 11:41:51 +0100548 .ops = &meson_clk_mpll_ops,
Michael Turquette738f66d2016-05-23 15:44:26 -0700549 .parent_names = (const char *[]){ "fixed_pll" },
550 .num_parents = 1,
551 },
552};
553
554static struct meson_clk_mpll gxbb_mpll1 = {
555 .sdm = {
556 .reg_off = HHI_MPLL_CNTL8,
557 .shift = 0,
558 .width = 14,
559 },
Jerome Brunet007e6e52017-03-09 11:41:50 +0100560 .sdm_en = {
561 .reg_off = HHI_MPLL_CNTL8,
562 .shift = 15,
563 .width = 1,
564 },
Michael Turquette738f66d2016-05-23 15:44:26 -0700565 .n2 = {
566 .reg_off = HHI_MPLL_CNTL8,
567 .shift = 16,
568 .width = 9,
569 },
Jerome Brunet007e6e52017-03-09 11:41:50 +0100570 .en = {
571 .reg_off = HHI_MPLL_CNTL8,
572 .shift = 14,
573 .width = 1,
574 },
Michael Turquette738f66d2016-05-23 15:44:26 -0700575 .lock = &clk_lock,
576 .hw.init = &(struct clk_init_data){
577 .name = "mpll1",
Jerome Brunet05b43aa2017-03-09 11:41:51 +0100578 .ops = &meson_clk_mpll_ops,
Michael Turquette738f66d2016-05-23 15:44:26 -0700579 .parent_names = (const char *[]){ "fixed_pll" },
580 .num_parents = 1,
581 },
582};
583
584static struct meson_clk_mpll gxbb_mpll2 = {
585 .sdm = {
586 .reg_off = HHI_MPLL_CNTL9,
587 .shift = 0,
588 .width = 14,
589 },
Jerome Brunet007e6e52017-03-09 11:41:50 +0100590 .sdm_en = {
591 .reg_off = HHI_MPLL_CNTL9,
592 .shift = 15,
593 .width = 1,
594 },
Michael Turquette738f66d2016-05-23 15:44:26 -0700595 .n2 = {
596 .reg_off = HHI_MPLL_CNTL9,
597 .shift = 16,
598 .width = 9,
599 },
Jerome Brunet007e6e52017-03-09 11:41:50 +0100600 .en = {
601 .reg_off = HHI_MPLL_CNTL9,
602 .shift = 14,
603 .width = 1,
604 },
Michael Turquette738f66d2016-05-23 15:44:26 -0700605 .lock = &clk_lock,
606 .hw.init = &(struct clk_init_data){
607 .name = "mpll2",
Jerome Brunet05b43aa2017-03-09 11:41:51 +0100608 .ops = &meson_clk_mpll_ops,
Michael Turquette738f66d2016-05-23 15:44:26 -0700609 .parent_names = (const char *[]){ "fixed_pll" },
610 .num_parents = 1,
611 },
612};
613
614/*
615 * FIXME cpu clocks and the legacy composite clocks (e.g. clk81) are both PLL
616 * post-dividers and should be modeled with their respective PLLs via the
617 * forthcoming coordinated clock rates feature
618 */
619static struct meson_clk_cpu gxbb_cpu_clk = {
620 .reg_off = HHI_SYS_CPU_CLK_CNTL1,
621 .div_table = cpu_div_table,
622 .clk_nb.notifier_call = meson_clk_cpu_notifier_cb,
623 .hw.init = &(struct clk_init_data){
624 .name = "cpu_clk",
625 .ops = &meson_clk_cpu_ops,
626 .parent_names = (const char *[]){ "sys_pll" },
627 .num_parents = 1,
628 },
629};
630
631static u32 mux_table_clk81[] = { 6, 5, 7 };
632
633static struct clk_mux gxbb_mpeg_clk_sel = {
634 .reg = (void *)HHI_MPEG_CLK_CNTL,
635 .mask = 0x7,
636 .shift = 12,
637 .flags = CLK_MUX_READ_ONLY,
638 .table = mux_table_clk81,
639 .lock = &clk_lock,
640 .hw.init = &(struct clk_init_data){
641 .name = "mpeg_clk_sel",
642 .ops = &clk_mux_ro_ops,
643 /*
644 * FIXME bits 14:12 selects from 8 possible parents:
645 * xtal, 1'b0 (wtf), fclk_div7, mpll_clkout1, mpll_clkout2,
646 * fclk_div4, fclk_div3, fclk_div5
647 */
648 .parent_names = (const char *[]){ "fclk_div3", "fclk_div4",
649 "fclk_div5" },
650 .num_parents = 3,
651 .flags = (CLK_SET_RATE_NO_REPARENT | CLK_IGNORE_UNUSED),
652 },
653};
654
655static struct clk_divider gxbb_mpeg_clk_div = {
656 .reg = (void *)HHI_MPEG_CLK_CNTL,
657 .shift = 0,
658 .width = 7,
659 .lock = &clk_lock,
660 .hw.init = &(struct clk_init_data){
661 .name = "mpeg_clk_div",
662 .ops = &clk_divider_ops,
663 .parent_names = (const char *[]){ "mpeg_clk_sel" },
664 .num_parents = 1,
665 .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED),
666 },
667};
668
669/* the mother of dragons^W gates */
670static struct clk_gate gxbb_clk81 = {
671 .reg = (void *)HHI_MPEG_CLK_CNTL,
672 .bit_idx = 7,
673 .lock = &clk_lock,
674 .hw.init = &(struct clk_init_data){
675 .name = "clk81",
676 .ops = &clk_gate_ops,
677 .parent_names = (const char *[]){ "mpeg_clk_div" },
678 .num_parents = 1,
679 .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED | CLK_IS_CRITICAL),
680 },
681};
682
Martin Blumenstingl33d0fcdf2017-01-19 15:58:20 +0100683static struct clk_mux gxbb_sar_adc_clk_sel = {
684 .reg = (void *)HHI_SAR_CLK_CNTL,
685 .mask = 0x3,
686 .shift = 9,
687 .lock = &clk_lock,
688 .hw.init = &(struct clk_init_data){
689 .name = "sar_adc_clk_sel",
690 .ops = &clk_mux_ops,
691 /* NOTE: The datasheet doesn't list the parents for bit 10 */
692 .parent_names = (const char *[]){ "xtal", "clk81", },
693 .num_parents = 2,
694 },
695};
696
697static struct clk_divider gxbb_sar_adc_clk_div = {
698 .reg = (void *)HHI_SAR_CLK_CNTL,
699 .shift = 0,
700 .width = 8,
701 .lock = &clk_lock,
702 .hw.init = &(struct clk_init_data){
703 .name = "sar_adc_clk_div",
704 .ops = &clk_divider_ops,
705 .parent_names = (const char *[]){ "sar_adc_clk_sel" },
706 .num_parents = 1,
707 },
708};
709
710static struct clk_gate gxbb_sar_adc_clk = {
711 .reg = (void *)HHI_SAR_CLK_CNTL,
712 .bit_idx = 8,
713 .lock = &clk_lock,
714 .hw.init = &(struct clk_init_data){
715 .name = "sar_adc_clk",
716 .ops = &clk_gate_ops,
717 .parent_names = (const char *[]){ "sar_adc_clk_div" },
718 .num_parents = 1,
719 .flags = CLK_SET_RATE_PARENT,
720 },
721};
722
Neil Armstrongfac9a552017-03-22 11:18:54 +0100723/*
724 * The MALI IP is clocked by two identical clocks (mali_0 and mali_1)
725 * muxed by a glitch-free switch.
726 */
727
728static u32 mux_table_mali_0_1[] = {0, 1, 2, 3, 4, 5, 6, 7};
729static const char *gxbb_mali_0_1_parent_names[] = {
730 "xtal", "gp0_pll", "mpll2", "mpll1", "fclk_div7",
731 "fclk_div4", "fclk_div3", "fclk_div5"
732};
733
734static struct clk_mux gxbb_mali_0_sel = {
735 .reg = (void *)HHI_MALI_CLK_CNTL,
736 .mask = 0x7,
737 .shift = 9,
738 .table = mux_table_mali_0_1,
739 .lock = &clk_lock,
740 .hw.init = &(struct clk_init_data){
741 .name = "mali_0_sel",
742 .ops = &clk_mux_ops,
743 /*
744 * bits 10:9 selects from 8 possible parents:
745 * xtal, gp0_pll, mpll2, mpll1, fclk_div7,
746 * fclk_div4, fclk_div3, fclk_div5
747 */
748 .parent_names = gxbb_mali_0_1_parent_names,
749 .num_parents = 8,
750 .flags = CLK_SET_RATE_NO_REPARENT,
751 },
752};
753
754static struct clk_divider gxbb_mali_0_div = {
755 .reg = (void *)HHI_MALI_CLK_CNTL,
756 .shift = 0,
757 .width = 7,
758 .lock = &clk_lock,
759 .hw.init = &(struct clk_init_data){
760 .name = "mali_0_div",
761 .ops = &clk_divider_ops,
762 .parent_names = (const char *[]){ "mali_0_sel" },
763 .num_parents = 1,
764 .flags = CLK_SET_RATE_NO_REPARENT,
765 },
766};
767
768static struct clk_gate gxbb_mali_0 = {
769 .reg = (void *)HHI_MALI_CLK_CNTL,
770 .bit_idx = 8,
771 .lock = &clk_lock,
772 .hw.init = &(struct clk_init_data){
773 .name = "mali_0",
774 .ops = &clk_gate_ops,
775 .parent_names = (const char *[]){ "mali_0_div" },
776 .num_parents = 1,
777 .flags = CLK_SET_RATE_PARENT,
778 },
779};
780
781static struct clk_mux gxbb_mali_1_sel = {
782 .reg = (void *)HHI_MALI_CLK_CNTL,
783 .mask = 0x7,
784 .shift = 25,
785 .table = mux_table_mali_0_1,
786 .lock = &clk_lock,
787 .hw.init = &(struct clk_init_data){
788 .name = "mali_1_sel",
789 .ops = &clk_mux_ops,
790 /*
791 * bits 10:9 selects from 8 possible parents:
792 * xtal, gp0_pll, mpll2, mpll1, fclk_div7,
793 * fclk_div4, fclk_div3, fclk_div5
794 */
795 .parent_names = gxbb_mali_0_1_parent_names,
796 .num_parents = 8,
797 .flags = CLK_SET_RATE_NO_REPARENT,
798 },
799};
800
801static struct clk_divider gxbb_mali_1_div = {
802 .reg = (void *)HHI_MALI_CLK_CNTL,
803 .shift = 16,
804 .width = 7,
805 .lock = &clk_lock,
806 .hw.init = &(struct clk_init_data){
807 .name = "mali_1_div",
808 .ops = &clk_divider_ops,
809 .parent_names = (const char *[]){ "mali_1_sel" },
810 .num_parents = 1,
811 .flags = CLK_SET_RATE_NO_REPARENT,
812 },
813};
814
815static struct clk_gate gxbb_mali_1 = {
816 .reg = (void *)HHI_MALI_CLK_CNTL,
817 .bit_idx = 24,
818 .lock = &clk_lock,
819 .hw.init = &(struct clk_init_data){
820 .name = "mali_1",
821 .ops = &clk_gate_ops,
822 .parent_names = (const char *[]){ "mali_1_div" },
823 .num_parents = 1,
824 .flags = CLK_SET_RATE_PARENT,
825 },
826};
827
828static u32 mux_table_mali[] = {0, 1};
829static const char *gxbb_mali_parent_names[] = {
830 "mali_0", "mali_1"
831};
832
833static struct clk_mux gxbb_mali = {
834 .reg = (void *)HHI_MALI_CLK_CNTL,
835 .mask = 1,
836 .shift = 31,
837 .table = mux_table_mali,
838 .lock = &clk_lock,
839 .hw.init = &(struct clk_init_data){
840 .name = "mali",
841 .ops = &clk_mux_ops,
842 .parent_names = gxbb_mali_parent_names,
843 .num_parents = 2,
844 .flags = CLK_SET_RATE_NO_REPARENT,
845 },
846};
847
Michael Turquette738f66d2016-05-23 15:44:26 -0700848/* Everything Else (EE) domain gates */
Alexander Müller7ba64d82016-08-27 19:40:53 +0200849static MESON_GATE(gxbb_ddr, HHI_GCLK_MPEG0, 0);
850static MESON_GATE(gxbb_dos, HHI_GCLK_MPEG0, 1);
851static MESON_GATE(gxbb_isa, HHI_GCLK_MPEG0, 5);
852static MESON_GATE(gxbb_pl301, HHI_GCLK_MPEG0, 6);
853static MESON_GATE(gxbb_periphs, HHI_GCLK_MPEG0, 7);
854static MESON_GATE(gxbb_spicc, HHI_GCLK_MPEG0, 8);
855static MESON_GATE(gxbb_i2c, HHI_GCLK_MPEG0, 9);
856static MESON_GATE(gxbb_sar_adc, HHI_GCLK_MPEG0, 10);
857static MESON_GATE(gxbb_smart_card, HHI_GCLK_MPEG0, 11);
858static MESON_GATE(gxbb_rng0, HHI_GCLK_MPEG0, 12);
859static MESON_GATE(gxbb_uart0, HHI_GCLK_MPEG0, 13);
860static MESON_GATE(gxbb_sdhc, HHI_GCLK_MPEG0, 14);
861static MESON_GATE(gxbb_stream, HHI_GCLK_MPEG0, 15);
862static MESON_GATE(gxbb_async_fifo, HHI_GCLK_MPEG0, 16);
863static MESON_GATE(gxbb_sdio, HHI_GCLK_MPEG0, 17);
864static MESON_GATE(gxbb_abuf, HHI_GCLK_MPEG0, 18);
865static MESON_GATE(gxbb_hiu_iface, HHI_GCLK_MPEG0, 19);
866static MESON_GATE(gxbb_assist_misc, HHI_GCLK_MPEG0, 23);
867static MESON_GATE(gxbb_emmc_a, HHI_GCLK_MPEG0, 24);
868static MESON_GATE(gxbb_emmc_b, HHI_GCLK_MPEG0, 25);
869static MESON_GATE(gxbb_emmc_c, HHI_GCLK_MPEG0, 26);
870static MESON_GATE(gxbb_spi, HHI_GCLK_MPEG0, 30);
Michael Turquette738f66d2016-05-23 15:44:26 -0700871
Alexander Müller7ba64d82016-08-27 19:40:53 +0200872static MESON_GATE(gxbb_i2s_spdif, HHI_GCLK_MPEG1, 2);
873static MESON_GATE(gxbb_eth, HHI_GCLK_MPEG1, 3);
874static MESON_GATE(gxbb_demux, HHI_GCLK_MPEG1, 4);
875static MESON_GATE(gxbb_aiu_glue, HHI_GCLK_MPEG1, 6);
876static MESON_GATE(gxbb_iec958, HHI_GCLK_MPEG1, 7);
877static MESON_GATE(gxbb_i2s_out, HHI_GCLK_MPEG1, 8);
878static MESON_GATE(gxbb_amclk, HHI_GCLK_MPEG1, 9);
879static MESON_GATE(gxbb_aififo2, HHI_GCLK_MPEG1, 10);
880static MESON_GATE(gxbb_mixer, HHI_GCLK_MPEG1, 11);
881static MESON_GATE(gxbb_mixer_iface, HHI_GCLK_MPEG1, 12);
882static MESON_GATE(gxbb_adc, HHI_GCLK_MPEG1, 13);
883static MESON_GATE(gxbb_blkmv, HHI_GCLK_MPEG1, 14);
884static MESON_GATE(gxbb_aiu, HHI_GCLK_MPEG1, 15);
885static MESON_GATE(gxbb_uart1, HHI_GCLK_MPEG1, 16);
886static MESON_GATE(gxbb_g2d, HHI_GCLK_MPEG1, 20);
887static MESON_GATE(gxbb_usb0, HHI_GCLK_MPEG1, 21);
888static MESON_GATE(gxbb_usb1, HHI_GCLK_MPEG1, 22);
889static MESON_GATE(gxbb_reset, HHI_GCLK_MPEG1, 23);
890static MESON_GATE(gxbb_nand, HHI_GCLK_MPEG1, 24);
891static MESON_GATE(gxbb_dos_parser, HHI_GCLK_MPEG1, 25);
892static MESON_GATE(gxbb_usb, HHI_GCLK_MPEG1, 26);
893static MESON_GATE(gxbb_vdin1, HHI_GCLK_MPEG1, 28);
894static MESON_GATE(gxbb_ahb_arb0, HHI_GCLK_MPEG1, 29);
895static MESON_GATE(gxbb_efuse, HHI_GCLK_MPEG1, 30);
896static MESON_GATE(gxbb_boot_rom, HHI_GCLK_MPEG1, 31);
Michael Turquette738f66d2016-05-23 15:44:26 -0700897
Alexander Müller7ba64d82016-08-27 19:40:53 +0200898static MESON_GATE(gxbb_ahb_data_bus, HHI_GCLK_MPEG2, 1);
899static MESON_GATE(gxbb_ahb_ctrl_bus, HHI_GCLK_MPEG2, 2);
900static MESON_GATE(gxbb_hdmi_intr_sync, HHI_GCLK_MPEG2, 3);
901static MESON_GATE(gxbb_hdmi_pclk, HHI_GCLK_MPEG2, 4);
902static MESON_GATE(gxbb_usb1_ddr_bridge, HHI_GCLK_MPEG2, 8);
903static MESON_GATE(gxbb_usb0_ddr_bridge, HHI_GCLK_MPEG2, 9);
904static MESON_GATE(gxbb_mmc_pclk, HHI_GCLK_MPEG2, 11);
905static MESON_GATE(gxbb_dvin, HHI_GCLK_MPEG2, 12);
906static MESON_GATE(gxbb_uart2, HHI_GCLK_MPEG2, 15);
907static MESON_GATE(gxbb_sana, HHI_GCLK_MPEG2, 22);
908static MESON_GATE(gxbb_vpu_intr, HHI_GCLK_MPEG2, 25);
909static MESON_GATE(gxbb_sec_ahb_ahb3_bridge, HHI_GCLK_MPEG2, 26);
910static MESON_GATE(gxbb_clk81_a53, HHI_GCLK_MPEG2, 29);
Michael Turquette738f66d2016-05-23 15:44:26 -0700911
Alexander Müller7ba64d82016-08-27 19:40:53 +0200912static MESON_GATE(gxbb_vclk2_venci0, HHI_GCLK_OTHER, 1);
913static MESON_GATE(gxbb_vclk2_venci1, HHI_GCLK_OTHER, 2);
914static MESON_GATE(gxbb_vclk2_vencp0, HHI_GCLK_OTHER, 3);
915static MESON_GATE(gxbb_vclk2_vencp1, HHI_GCLK_OTHER, 4);
916static MESON_GATE(gxbb_gclk_venci_int0, HHI_GCLK_OTHER, 8);
917static MESON_GATE(gxbb_gclk_vencp_int, HHI_GCLK_OTHER, 9);
918static MESON_GATE(gxbb_dac_clk, HHI_GCLK_OTHER, 10);
919static MESON_GATE(gxbb_aoclk_gate, HHI_GCLK_OTHER, 14);
920static MESON_GATE(gxbb_iec958_gate, HHI_GCLK_OTHER, 16);
921static MESON_GATE(gxbb_enc480p, HHI_GCLK_OTHER, 20);
922static MESON_GATE(gxbb_rng1, HHI_GCLK_OTHER, 21);
923static MESON_GATE(gxbb_gclk_venci_int1, HHI_GCLK_OTHER, 22);
924static MESON_GATE(gxbb_vclk2_venclmcc, HHI_GCLK_OTHER, 24);
925static MESON_GATE(gxbb_vclk2_vencl, HHI_GCLK_OTHER, 25);
926static MESON_GATE(gxbb_vclk_other, HHI_GCLK_OTHER, 26);
927static MESON_GATE(gxbb_edp, HHI_GCLK_OTHER, 31);
Michael Turquette738f66d2016-05-23 15:44:26 -0700928
929/* Always On (AO) domain gates */
930
Alexander Müller7ba64d82016-08-27 19:40:53 +0200931static MESON_GATE(gxbb_ao_media_cpu, HHI_GCLK_AO, 0);
932static MESON_GATE(gxbb_ao_ahb_sram, HHI_GCLK_AO, 1);
933static MESON_GATE(gxbb_ao_ahb_bus, HHI_GCLK_AO, 2);
934static MESON_GATE(gxbb_ao_iface, HHI_GCLK_AO, 3);
935static MESON_GATE(gxbb_ao_i2c, HHI_GCLK_AO, 4);
Michael Turquette738f66d2016-05-23 15:44:26 -0700936
937/* Array of all clocks provided by this provider */
938
939static struct clk_hw_onecell_data gxbb_hw_onecell_data = {
940 .hws = {
941 [CLKID_SYS_PLL] = &gxbb_sys_pll.hw,
942 [CLKID_CPUCLK] = &gxbb_cpu_clk.hw,
943 [CLKID_HDMI_PLL] = &gxbb_hdmi_pll.hw,
944 [CLKID_FIXED_PLL] = &gxbb_fixed_pll.hw,
945 [CLKID_FCLK_DIV2] = &gxbb_fclk_div2.hw,
946 [CLKID_FCLK_DIV3] = &gxbb_fclk_div3.hw,
947 [CLKID_FCLK_DIV4] = &gxbb_fclk_div4.hw,
948 [CLKID_FCLK_DIV5] = &gxbb_fclk_div5.hw,
949 [CLKID_FCLK_DIV7] = &gxbb_fclk_div7.hw,
950 [CLKID_GP0_PLL] = &gxbb_gp0_pll.hw,
951 [CLKID_MPEG_SEL] = &gxbb_mpeg_clk_sel.hw,
952 [CLKID_MPEG_DIV] = &gxbb_mpeg_clk_div.hw,
953 [CLKID_CLK81] = &gxbb_clk81.hw,
954 [CLKID_MPLL0] = &gxbb_mpll0.hw,
955 [CLKID_MPLL1] = &gxbb_mpll1.hw,
956 [CLKID_MPLL2] = &gxbb_mpll2.hw,
957 [CLKID_DDR] = &gxbb_ddr.hw,
958 [CLKID_DOS] = &gxbb_dos.hw,
959 [CLKID_ISA] = &gxbb_isa.hw,
960 [CLKID_PL301] = &gxbb_pl301.hw,
961 [CLKID_PERIPHS] = &gxbb_periphs.hw,
962 [CLKID_SPICC] = &gxbb_spicc.hw,
963 [CLKID_I2C] = &gxbb_i2c.hw,
964 [CLKID_SAR_ADC] = &gxbb_sar_adc.hw,
965 [CLKID_SMART_CARD] = &gxbb_smart_card.hw,
966 [CLKID_RNG0] = &gxbb_rng0.hw,
967 [CLKID_UART0] = &gxbb_uart0.hw,
968 [CLKID_SDHC] = &gxbb_sdhc.hw,
969 [CLKID_STREAM] = &gxbb_stream.hw,
970 [CLKID_ASYNC_FIFO] = &gxbb_async_fifo.hw,
971 [CLKID_SDIO] = &gxbb_sdio.hw,
972 [CLKID_ABUF] = &gxbb_abuf.hw,
973 [CLKID_HIU_IFACE] = &gxbb_hiu_iface.hw,
974 [CLKID_ASSIST_MISC] = &gxbb_assist_misc.hw,
975 [CLKID_SPI] = &gxbb_spi.hw,
976 [CLKID_I2S_SPDIF] = &gxbb_i2s_spdif.hw,
977 [CLKID_ETH] = &gxbb_eth.hw,
978 [CLKID_DEMUX] = &gxbb_demux.hw,
979 [CLKID_AIU_GLUE] = &gxbb_aiu_glue.hw,
980 [CLKID_IEC958] = &gxbb_iec958.hw,
981 [CLKID_I2S_OUT] = &gxbb_i2s_out.hw,
982 [CLKID_AMCLK] = &gxbb_amclk.hw,
983 [CLKID_AIFIFO2] = &gxbb_aififo2.hw,
984 [CLKID_MIXER] = &gxbb_mixer.hw,
985 [CLKID_MIXER_IFACE] = &gxbb_mixer_iface.hw,
986 [CLKID_ADC] = &gxbb_adc.hw,
987 [CLKID_BLKMV] = &gxbb_blkmv.hw,
988 [CLKID_AIU] = &gxbb_aiu.hw,
989 [CLKID_UART1] = &gxbb_uart1.hw,
990 [CLKID_G2D] = &gxbb_g2d.hw,
991 [CLKID_USB0] = &gxbb_usb0.hw,
992 [CLKID_USB1] = &gxbb_usb1.hw,
993 [CLKID_RESET] = &gxbb_reset.hw,
994 [CLKID_NAND] = &gxbb_nand.hw,
995 [CLKID_DOS_PARSER] = &gxbb_dos_parser.hw,
996 [CLKID_USB] = &gxbb_usb.hw,
997 [CLKID_VDIN1] = &gxbb_vdin1.hw,
998 [CLKID_AHB_ARB0] = &gxbb_ahb_arb0.hw,
999 [CLKID_EFUSE] = &gxbb_efuse.hw,
1000 [CLKID_BOOT_ROM] = &gxbb_boot_rom.hw,
1001 [CLKID_AHB_DATA_BUS] = &gxbb_ahb_data_bus.hw,
1002 [CLKID_AHB_CTRL_BUS] = &gxbb_ahb_ctrl_bus.hw,
1003 [CLKID_HDMI_INTR_SYNC] = &gxbb_hdmi_intr_sync.hw,
1004 [CLKID_HDMI_PCLK] = &gxbb_hdmi_pclk.hw,
1005 [CLKID_USB1_DDR_BRIDGE] = &gxbb_usb1_ddr_bridge.hw,
1006 [CLKID_USB0_DDR_BRIDGE] = &gxbb_usb0_ddr_bridge.hw,
1007 [CLKID_MMC_PCLK] = &gxbb_mmc_pclk.hw,
1008 [CLKID_DVIN] = &gxbb_dvin.hw,
1009 [CLKID_UART2] = &gxbb_uart2.hw,
1010 [CLKID_SANA] = &gxbb_sana.hw,
1011 [CLKID_VPU_INTR] = &gxbb_vpu_intr.hw,
1012 [CLKID_SEC_AHB_AHB3_BRIDGE] = &gxbb_sec_ahb_ahb3_bridge.hw,
1013 [CLKID_CLK81_A53] = &gxbb_clk81_a53.hw,
1014 [CLKID_VCLK2_VENCI0] = &gxbb_vclk2_venci0.hw,
1015 [CLKID_VCLK2_VENCI1] = &gxbb_vclk2_venci1.hw,
1016 [CLKID_VCLK2_VENCP0] = &gxbb_vclk2_vencp0.hw,
1017 [CLKID_VCLK2_VENCP1] = &gxbb_vclk2_vencp1.hw,
1018 [CLKID_GCLK_VENCI_INT0] = &gxbb_gclk_venci_int0.hw,
1019 [CLKID_GCLK_VENCI_INT] = &gxbb_gclk_vencp_int.hw,
1020 [CLKID_DAC_CLK] = &gxbb_dac_clk.hw,
1021 [CLKID_AOCLK_GATE] = &gxbb_aoclk_gate.hw,
1022 [CLKID_IEC958_GATE] = &gxbb_iec958_gate.hw,
1023 [CLKID_ENC480P] = &gxbb_enc480p.hw,
1024 [CLKID_RNG1] = &gxbb_rng1.hw,
1025 [CLKID_GCLK_VENCI_INT1] = &gxbb_gclk_venci_int1.hw,
1026 [CLKID_VCLK2_VENCLMCC] = &gxbb_vclk2_venclmcc.hw,
1027 [CLKID_VCLK2_VENCL] = &gxbb_vclk2_vencl.hw,
1028 [CLKID_VCLK_OTHER] = &gxbb_vclk_other.hw,
1029 [CLKID_EDP] = &gxbb_edp.hw,
1030 [CLKID_AO_MEDIA_CPU] = &gxbb_ao_media_cpu.hw,
1031 [CLKID_AO_AHB_SRAM] = &gxbb_ao_ahb_sram.hw,
1032 [CLKID_AO_AHB_BUS] = &gxbb_ao_ahb_bus.hw,
1033 [CLKID_AO_IFACE] = &gxbb_ao_iface.hw,
1034 [CLKID_AO_I2C] = &gxbb_ao_i2c.hw,
Kevin Hilman33608dc2016-08-02 14:40:11 -07001035 [CLKID_SD_EMMC_A] = &gxbb_emmc_a.hw,
1036 [CLKID_SD_EMMC_B] = &gxbb_emmc_b.hw,
1037 [CLKID_SD_EMMC_C] = &gxbb_emmc_c.hw,
Martin Blumenstingl33d0fcdf2017-01-19 15:58:20 +01001038 [CLKID_SAR_ADC_CLK] = &gxbb_sar_adc_clk.hw,
1039 [CLKID_SAR_ADC_SEL] = &gxbb_sar_adc_clk_sel.hw,
1040 [CLKID_SAR_ADC_DIV] = &gxbb_sar_adc_clk_div.hw,
Neil Armstrongfac9a552017-03-22 11:18:54 +01001041 [CLKID_MALI_0_SEL] = &gxbb_mali_0_sel.hw,
1042 [CLKID_MALI_0_DIV] = &gxbb_mali_0_div.hw,
1043 [CLKID_MALI_0] = &gxbb_mali_0.hw,
1044 [CLKID_MALI_1_SEL] = &gxbb_mali_1_sel.hw,
1045 [CLKID_MALI_1_DIV] = &gxbb_mali_1_div.hw,
1046 [CLKID_MALI_1] = &gxbb_mali_1.hw,
1047 [CLKID_MALI] = &gxbb_mali.hw,
Michael Turquette738f66d2016-05-23 15:44:26 -07001048 },
1049 .num = NR_CLKS,
1050};
1051
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001052static struct clk_hw_onecell_data gxl_hw_onecell_data = {
1053 .hws = {
1054 [CLKID_SYS_PLL] = &gxbb_sys_pll.hw,
1055 [CLKID_CPUCLK] = &gxbb_cpu_clk.hw,
1056 [CLKID_HDMI_PLL] = &gxbb_hdmi_pll.hw,
1057 [CLKID_FIXED_PLL] = &gxbb_fixed_pll.hw,
1058 [CLKID_FCLK_DIV2] = &gxbb_fclk_div2.hw,
1059 [CLKID_FCLK_DIV3] = &gxbb_fclk_div3.hw,
1060 [CLKID_FCLK_DIV4] = &gxbb_fclk_div4.hw,
1061 [CLKID_FCLK_DIV5] = &gxbb_fclk_div5.hw,
1062 [CLKID_FCLK_DIV7] = &gxbb_fclk_div7.hw,
1063 [CLKID_GP0_PLL] = &gxl_gp0_pll.hw,
1064 [CLKID_MPEG_SEL] = &gxbb_mpeg_clk_sel.hw,
1065 [CLKID_MPEG_DIV] = &gxbb_mpeg_clk_div.hw,
1066 [CLKID_CLK81] = &gxbb_clk81.hw,
1067 [CLKID_MPLL0] = &gxbb_mpll0.hw,
1068 [CLKID_MPLL1] = &gxbb_mpll1.hw,
1069 [CLKID_MPLL2] = &gxbb_mpll2.hw,
1070 [CLKID_DDR] = &gxbb_ddr.hw,
1071 [CLKID_DOS] = &gxbb_dos.hw,
1072 [CLKID_ISA] = &gxbb_isa.hw,
1073 [CLKID_PL301] = &gxbb_pl301.hw,
1074 [CLKID_PERIPHS] = &gxbb_periphs.hw,
1075 [CLKID_SPICC] = &gxbb_spicc.hw,
1076 [CLKID_I2C] = &gxbb_i2c.hw,
1077 [CLKID_SAR_ADC] = &gxbb_sar_adc.hw,
1078 [CLKID_SMART_CARD] = &gxbb_smart_card.hw,
1079 [CLKID_RNG0] = &gxbb_rng0.hw,
1080 [CLKID_UART0] = &gxbb_uart0.hw,
1081 [CLKID_SDHC] = &gxbb_sdhc.hw,
1082 [CLKID_STREAM] = &gxbb_stream.hw,
1083 [CLKID_ASYNC_FIFO] = &gxbb_async_fifo.hw,
1084 [CLKID_SDIO] = &gxbb_sdio.hw,
1085 [CLKID_ABUF] = &gxbb_abuf.hw,
1086 [CLKID_HIU_IFACE] = &gxbb_hiu_iface.hw,
1087 [CLKID_ASSIST_MISC] = &gxbb_assist_misc.hw,
1088 [CLKID_SPI] = &gxbb_spi.hw,
1089 [CLKID_I2S_SPDIF] = &gxbb_i2s_spdif.hw,
1090 [CLKID_ETH] = &gxbb_eth.hw,
1091 [CLKID_DEMUX] = &gxbb_demux.hw,
1092 [CLKID_AIU_GLUE] = &gxbb_aiu_glue.hw,
1093 [CLKID_IEC958] = &gxbb_iec958.hw,
1094 [CLKID_I2S_OUT] = &gxbb_i2s_out.hw,
1095 [CLKID_AMCLK] = &gxbb_amclk.hw,
1096 [CLKID_AIFIFO2] = &gxbb_aififo2.hw,
1097 [CLKID_MIXER] = &gxbb_mixer.hw,
1098 [CLKID_MIXER_IFACE] = &gxbb_mixer_iface.hw,
1099 [CLKID_ADC] = &gxbb_adc.hw,
1100 [CLKID_BLKMV] = &gxbb_blkmv.hw,
1101 [CLKID_AIU] = &gxbb_aiu.hw,
1102 [CLKID_UART1] = &gxbb_uart1.hw,
1103 [CLKID_G2D] = &gxbb_g2d.hw,
1104 [CLKID_USB0] = &gxbb_usb0.hw,
1105 [CLKID_USB1] = &gxbb_usb1.hw,
1106 [CLKID_RESET] = &gxbb_reset.hw,
1107 [CLKID_NAND] = &gxbb_nand.hw,
1108 [CLKID_DOS_PARSER] = &gxbb_dos_parser.hw,
1109 [CLKID_USB] = &gxbb_usb.hw,
1110 [CLKID_VDIN1] = &gxbb_vdin1.hw,
1111 [CLKID_AHB_ARB0] = &gxbb_ahb_arb0.hw,
1112 [CLKID_EFUSE] = &gxbb_efuse.hw,
1113 [CLKID_BOOT_ROM] = &gxbb_boot_rom.hw,
1114 [CLKID_AHB_DATA_BUS] = &gxbb_ahb_data_bus.hw,
1115 [CLKID_AHB_CTRL_BUS] = &gxbb_ahb_ctrl_bus.hw,
1116 [CLKID_HDMI_INTR_SYNC] = &gxbb_hdmi_intr_sync.hw,
1117 [CLKID_HDMI_PCLK] = &gxbb_hdmi_pclk.hw,
1118 [CLKID_USB1_DDR_BRIDGE] = &gxbb_usb1_ddr_bridge.hw,
1119 [CLKID_USB0_DDR_BRIDGE] = &gxbb_usb0_ddr_bridge.hw,
1120 [CLKID_MMC_PCLK] = &gxbb_mmc_pclk.hw,
1121 [CLKID_DVIN] = &gxbb_dvin.hw,
1122 [CLKID_UART2] = &gxbb_uart2.hw,
1123 [CLKID_SANA] = &gxbb_sana.hw,
1124 [CLKID_VPU_INTR] = &gxbb_vpu_intr.hw,
1125 [CLKID_SEC_AHB_AHB3_BRIDGE] = &gxbb_sec_ahb_ahb3_bridge.hw,
1126 [CLKID_CLK81_A53] = &gxbb_clk81_a53.hw,
1127 [CLKID_VCLK2_VENCI0] = &gxbb_vclk2_venci0.hw,
1128 [CLKID_VCLK2_VENCI1] = &gxbb_vclk2_venci1.hw,
1129 [CLKID_VCLK2_VENCP0] = &gxbb_vclk2_vencp0.hw,
1130 [CLKID_VCLK2_VENCP1] = &gxbb_vclk2_vencp1.hw,
1131 [CLKID_GCLK_VENCI_INT0] = &gxbb_gclk_venci_int0.hw,
1132 [CLKID_GCLK_VENCI_INT] = &gxbb_gclk_vencp_int.hw,
1133 [CLKID_DAC_CLK] = &gxbb_dac_clk.hw,
1134 [CLKID_AOCLK_GATE] = &gxbb_aoclk_gate.hw,
1135 [CLKID_IEC958_GATE] = &gxbb_iec958_gate.hw,
1136 [CLKID_ENC480P] = &gxbb_enc480p.hw,
1137 [CLKID_RNG1] = &gxbb_rng1.hw,
1138 [CLKID_GCLK_VENCI_INT1] = &gxbb_gclk_venci_int1.hw,
1139 [CLKID_VCLK2_VENCLMCC] = &gxbb_vclk2_venclmcc.hw,
1140 [CLKID_VCLK2_VENCL] = &gxbb_vclk2_vencl.hw,
1141 [CLKID_VCLK_OTHER] = &gxbb_vclk_other.hw,
1142 [CLKID_EDP] = &gxbb_edp.hw,
1143 [CLKID_AO_MEDIA_CPU] = &gxbb_ao_media_cpu.hw,
1144 [CLKID_AO_AHB_SRAM] = &gxbb_ao_ahb_sram.hw,
1145 [CLKID_AO_AHB_BUS] = &gxbb_ao_ahb_bus.hw,
1146 [CLKID_AO_IFACE] = &gxbb_ao_iface.hw,
1147 [CLKID_AO_I2C] = &gxbb_ao_i2c.hw,
1148 [CLKID_SD_EMMC_A] = &gxbb_emmc_a.hw,
1149 [CLKID_SD_EMMC_B] = &gxbb_emmc_b.hw,
1150 [CLKID_SD_EMMC_C] = &gxbb_emmc_c.hw,
1151 [CLKID_SAR_ADC_CLK] = &gxbb_sar_adc_clk.hw,
1152 [CLKID_SAR_ADC_SEL] = &gxbb_sar_adc_clk_sel.hw,
1153 [CLKID_SAR_ADC_DIV] = &gxbb_sar_adc_clk_div.hw,
1154 [CLKID_MALI_0_SEL] = &gxbb_mali_0_sel.hw,
1155 [CLKID_MALI_0_DIV] = &gxbb_mali_0_div.hw,
1156 [CLKID_MALI_0] = &gxbb_mali_0.hw,
1157 [CLKID_MALI_1_SEL] = &gxbb_mali_1_sel.hw,
1158 [CLKID_MALI_1_DIV] = &gxbb_mali_1_div.hw,
1159 [CLKID_MALI_1] = &gxbb_mali_1.hw,
1160 [CLKID_MALI] = &gxbb_mali.hw,
1161 },
1162 .num = NR_CLKS,
1163};
1164
Michael Turquette738f66d2016-05-23 15:44:26 -07001165/* Convenience tables to populate base addresses in .probe */
1166
1167static struct meson_clk_pll *const gxbb_clk_plls[] = {
1168 &gxbb_fixed_pll,
1169 &gxbb_hdmi_pll,
1170 &gxbb_sys_pll,
1171 &gxbb_gp0_pll,
1172};
1173
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001174static struct meson_clk_pll *const gxl_clk_plls[] = {
1175 &gxbb_fixed_pll,
1176 &gxbb_hdmi_pll,
1177 &gxbb_sys_pll,
1178 &gxl_gp0_pll,
1179};
1180
Michael Turquette738f66d2016-05-23 15:44:26 -07001181static struct meson_clk_mpll *const gxbb_clk_mplls[] = {
1182 &gxbb_mpll0,
1183 &gxbb_mpll1,
1184 &gxbb_mpll2,
1185};
1186
Jerome Brunetf7e3a822017-03-09 11:41:47 +01001187static struct clk_gate *const gxbb_clk_gates[] = {
Michael Turquette738f66d2016-05-23 15:44:26 -07001188 &gxbb_clk81,
1189 &gxbb_ddr,
1190 &gxbb_dos,
1191 &gxbb_isa,
1192 &gxbb_pl301,
1193 &gxbb_periphs,
1194 &gxbb_spicc,
1195 &gxbb_i2c,
1196 &gxbb_sar_adc,
1197 &gxbb_smart_card,
1198 &gxbb_rng0,
1199 &gxbb_uart0,
1200 &gxbb_sdhc,
1201 &gxbb_stream,
1202 &gxbb_async_fifo,
1203 &gxbb_sdio,
1204 &gxbb_abuf,
1205 &gxbb_hiu_iface,
1206 &gxbb_assist_misc,
1207 &gxbb_spi,
1208 &gxbb_i2s_spdif,
1209 &gxbb_eth,
1210 &gxbb_demux,
1211 &gxbb_aiu_glue,
1212 &gxbb_iec958,
1213 &gxbb_i2s_out,
1214 &gxbb_amclk,
1215 &gxbb_aififo2,
1216 &gxbb_mixer,
1217 &gxbb_mixer_iface,
1218 &gxbb_adc,
1219 &gxbb_blkmv,
1220 &gxbb_aiu,
1221 &gxbb_uart1,
1222 &gxbb_g2d,
1223 &gxbb_usb0,
1224 &gxbb_usb1,
1225 &gxbb_reset,
1226 &gxbb_nand,
1227 &gxbb_dos_parser,
1228 &gxbb_usb,
1229 &gxbb_vdin1,
1230 &gxbb_ahb_arb0,
1231 &gxbb_efuse,
1232 &gxbb_boot_rom,
1233 &gxbb_ahb_data_bus,
1234 &gxbb_ahb_ctrl_bus,
1235 &gxbb_hdmi_intr_sync,
1236 &gxbb_hdmi_pclk,
1237 &gxbb_usb1_ddr_bridge,
1238 &gxbb_usb0_ddr_bridge,
1239 &gxbb_mmc_pclk,
1240 &gxbb_dvin,
1241 &gxbb_uart2,
1242 &gxbb_sana,
1243 &gxbb_vpu_intr,
1244 &gxbb_sec_ahb_ahb3_bridge,
1245 &gxbb_clk81_a53,
1246 &gxbb_vclk2_venci0,
1247 &gxbb_vclk2_venci1,
1248 &gxbb_vclk2_vencp0,
1249 &gxbb_vclk2_vencp1,
1250 &gxbb_gclk_venci_int0,
1251 &gxbb_gclk_vencp_int,
1252 &gxbb_dac_clk,
1253 &gxbb_aoclk_gate,
1254 &gxbb_iec958_gate,
1255 &gxbb_enc480p,
1256 &gxbb_rng1,
1257 &gxbb_gclk_venci_int1,
1258 &gxbb_vclk2_venclmcc,
1259 &gxbb_vclk2_vencl,
1260 &gxbb_vclk_other,
1261 &gxbb_edp,
1262 &gxbb_ao_media_cpu,
1263 &gxbb_ao_ahb_sram,
1264 &gxbb_ao_ahb_bus,
1265 &gxbb_ao_iface,
1266 &gxbb_ao_i2c,
Kevin Hilman33608dc2016-08-02 14:40:11 -07001267 &gxbb_emmc_a,
1268 &gxbb_emmc_b,
1269 &gxbb_emmc_c,
Martin Blumenstingl33d0fcdf2017-01-19 15:58:20 +01001270 &gxbb_sar_adc_clk,
Neil Armstrongfac9a552017-03-22 11:18:54 +01001271 &gxbb_mali_0,
1272 &gxbb_mali_1,
Michael Turquette738f66d2016-05-23 15:44:26 -07001273};
1274
Jerome Brunetb92332e2017-03-09 11:41:49 +01001275static struct clk_mux *const gxbb_clk_muxes[] = {
1276 &gxbb_mpeg_clk_sel,
1277 &gxbb_sar_adc_clk_sel,
Neil Armstrongfac9a552017-03-22 11:18:54 +01001278 &gxbb_mali_0_sel,
1279 &gxbb_mali_1_sel,
1280 &gxbb_mali,
Jerome Brunetb92332e2017-03-09 11:41:49 +01001281};
1282
1283static struct clk_divider *const gxbb_clk_dividers[] = {
1284 &gxbb_mpeg_clk_div,
1285 &gxbb_sar_adc_clk_div,
Neil Armstrongfac9a552017-03-22 11:18:54 +01001286 &gxbb_mali_0_div,
1287 &gxbb_mali_1_div,
Jerome Brunetb92332e2017-03-09 11:41:49 +01001288};
1289
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001290struct clkc_data {
1291 struct clk_gate *const *clk_gates;
1292 unsigned int clk_gates_count;
1293 struct meson_clk_mpll *const *clk_mplls;
1294 unsigned int clk_mplls_count;
1295 struct meson_clk_pll *const *clk_plls;
1296 unsigned int clk_plls_count;
1297 struct clk_mux *const *clk_muxes;
1298 unsigned int clk_muxes_count;
1299 struct clk_divider *const *clk_dividers;
1300 unsigned int clk_dividers_count;
1301 struct meson_clk_cpu *cpu_clk;
1302 struct clk_hw_onecell_data *hw_onecell_data;
1303};
1304
1305static const struct clkc_data gxbb_clkc_data = {
1306 .clk_gates = gxbb_clk_gates,
1307 .clk_gates_count = ARRAY_SIZE(gxbb_clk_gates),
1308 .clk_mplls = gxbb_clk_mplls,
1309 .clk_mplls_count = ARRAY_SIZE(gxbb_clk_mplls),
1310 .clk_plls = gxbb_clk_plls,
1311 .clk_plls_count = ARRAY_SIZE(gxbb_clk_plls),
1312 .clk_muxes = gxbb_clk_muxes,
1313 .clk_muxes_count = ARRAY_SIZE(gxbb_clk_muxes),
1314 .clk_dividers = gxbb_clk_dividers,
1315 .clk_dividers_count = ARRAY_SIZE(gxbb_clk_dividers),
1316 .cpu_clk = &gxbb_cpu_clk,
1317 .hw_onecell_data = &gxbb_hw_onecell_data,
1318};
1319
1320static const struct clkc_data gxl_clkc_data = {
1321 .clk_gates = gxbb_clk_gates,
1322 .clk_gates_count = ARRAY_SIZE(gxbb_clk_gates),
1323 .clk_mplls = gxbb_clk_mplls,
1324 .clk_mplls_count = ARRAY_SIZE(gxbb_clk_mplls),
1325 .clk_plls = gxl_clk_plls,
1326 .clk_plls_count = ARRAY_SIZE(gxl_clk_plls),
1327 .clk_muxes = gxbb_clk_muxes,
1328 .clk_muxes_count = ARRAY_SIZE(gxbb_clk_muxes),
1329 .clk_dividers = gxbb_clk_dividers,
1330 .clk_dividers_count = ARRAY_SIZE(gxbb_clk_dividers),
1331 .cpu_clk = &gxbb_cpu_clk,
1332 .hw_onecell_data = &gxl_hw_onecell_data,
1333};
1334
1335static const struct of_device_id clkc_match_table[] = {
1336 { .compatible = "amlogic,gxbb-clkc", .data = &gxbb_clkc_data },
1337 { .compatible = "amlogic,gxl-clkc", .data = &gxl_clkc_data },
1338 {},
1339};
1340
Michael Turquette738f66d2016-05-23 15:44:26 -07001341static int gxbb_clkc_probe(struct platform_device *pdev)
1342{
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001343 const struct clkc_data *clkc_data;
Michael Turquette738f66d2016-05-23 15:44:26 -07001344 void __iomem *clk_base;
1345 int ret, clkid, i;
1346 struct clk_hw *parent_hw;
1347 struct clk *parent_clk;
1348 struct device *dev = &pdev->dev;
1349
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001350 clkc_data = of_device_get_match_data(&pdev->dev);
1351 if (!clkc_data)
1352 return -EINVAL;
1353
Michael Turquette738f66d2016-05-23 15:44:26 -07001354 /* Generic clocks and PLLs */
1355 clk_base = of_iomap(dev->of_node, 0);
1356 if (!clk_base) {
1357 pr_err("%s: Unable to map clk base\n", __func__);
1358 return -ENXIO;
1359 }
1360
1361 /* Populate base address for PLLs */
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001362 for (i = 0; i < clkc_data->clk_plls_count; i++)
1363 clkc_data->clk_plls[i]->base = clk_base;
Michael Turquette738f66d2016-05-23 15:44:26 -07001364
1365 /* Populate base address for MPLLs */
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001366 for (i = 0; i < clkc_data->clk_mplls_count; i++)
1367 clkc_data->clk_mplls[i]->base = clk_base;
Michael Turquette738f66d2016-05-23 15:44:26 -07001368
1369 /* Populate the base address for CPU clk */
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001370 clkc_data->cpu_clk->base = clk_base;
Michael Turquette738f66d2016-05-23 15:44:26 -07001371
Michael Turquette738f66d2016-05-23 15:44:26 -07001372 /* Populate base address for gates */
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001373 for (i = 0; i < clkc_data->clk_gates_count; i++)
1374 clkc_data->clk_gates[i]->reg = clk_base +
1375 (u64)clkc_data->clk_gates[i]->reg;
Michael Turquette738f66d2016-05-23 15:44:26 -07001376
Jerome Brunetb92332e2017-03-09 11:41:49 +01001377 /* Populate base address for muxes */
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001378 for (i = 0; i < clkc_data->clk_muxes_count; i++)
1379 clkc_data->clk_muxes[i]->reg = clk_base +
1380 (u64)clkc_data->clk_muxes[i]->reg;
Jerome Brunetb92332e2017-03-09 11:41:49 +01001381
1382 /* Populate base address for dividers */
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001383 for (i = 0; i < clkc_data->clk_dividers_count; i++)
1384 clkc_data->clk_dividers[i]->reg = clk_base +
1385 (u64)clkc_data->clk_dividers[i]->reg;
Jerome Brunetb92332e2017-03-09 11:41:49 +01001386
Michael Turquette738f66d2016-05-23 15:44:26 -07001387 /*
1388 * register all clks
1389 */
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001390 for (clkid = 0; clkid < clkc_data->hw_onecell_data->num; clkid++) {
1391 ret = devm_clk_hw_register(dev,
1392 clkc_data->hw_onecell_data->hws[clkid]);
Michael Turquette738f66d2016-05-23 15:44:26 -07001393 if (ret)
1394 goto iounmap;
1395 }
1396
1397 /*
1398 * Register CPU clk notifier
1399 *
1400 * FIXME this is wrong for a lot of reasons. First, the muxes should be
1401 * struct clk_hw objects. Second, we shouldn't program the muxes in
1402 * notifier handlers. The tricky programming sequence will be handled
1403 * by the forthcoming coordinated clock rates mechanism once that
1404 * feature is released.
1405 *
1406 * Furthermore, looking up the parent this way is terrible. At some
1407 * point we will stop allocating a default struct clk when registering
1408 * a new clk_hw, and this hack will no longer work. Releasing the ccr
1409 * feature before that time solves the problem :-)
1410 */
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001411 parent_hw = clk_hw_get_parent(&clkc_data->cpu_clk->hw);
Michael Turquette738f66d2016-05-23 15:44:26 -07001412 parent_clk = parent_hw->clk;
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001413 ret = clk_notifier_register(parent_clk, &clkc_data->cpu_clk->clk_nb);
Michael Turquette738f66d2016-05-23 15:44:26 -07001414 if (ret) {
1415 pr_err("%s: failed to register clock notifier for cpu_clk\n",
1416 __func__);
1417 goto iounmap;
1418 }
1419
1420 return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001421 clkc_data->hw_onecell_data);
Michael Turquette738f66d2016-05-23 15:44:26 -07001422
1423iounmap:
1424 iounmap(clk_base);
1425 return ret;
1426}
1427
Michael Turquette738f66d2016-05-23 15:44:26 -07001428static struct platform_driver gxbb_driver = {
1429 .probe = gxbb_clkc_probe,
1430 .driver = {
1431 .name = "gxbb-clkc",
Neil Armstrong0d48fc52017-03-22 11:32:25 +01001432 .of_match_table = clkc_match_table,
Michael Turquette738f66d2016-05-23 15:44:26 -07001433 },
1434};
1435
Wei Yongjun00746f12016-08-08 13:55:20 +00001436builtin_platform_driver(gxbb_driver);