blob: 6ec512ad259805c34b57be3ee96eddef149599ee [file] [log] [blame]
Carlo Caione28b9fcd2015-06-01 13:13:55 +02001/*
Martin Blumenstingl855f06a2017-06-04 20:33:39 +02002 * AmLogic S802 (Meson8) / S805 (Meson8b) / S812 (Meson8m2) Clock Controller
3 * Driver
Paul Gortmakera718ce32016-07-04 17:12:11 -04004 *
Carlo Caione28b9fcd2015-06-01 13:13:55 +02005 * Copyright (c) 2015 Endless Mobile, Inc.
6 * Author: Carlo Caione <carlo@endlessm.com>
7 *
Michael Turquette796b9aa2016-05-11 11:11:18 -07008 * Copyright (c) 2016 BayLibre, Inc.
9 * Michael Turquette <mturquette@baylibre.com>
10 *
Carlo Caione28b9fcd2015-06-01 13:13:55 +020011 * This program is free software; you can redistribute it and/or modify it
12 * under the terms and conditions of the GNU General Public License,
13 * version 2, as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
Michael Turquette55d42c42016-04-30 12:47:36 -070024#include <linux/clk.h>
Carlo Caione28b9fcd2015-06-01 13:13:55 +020025#include <linux/clk-provider.h>
Carlo Caione28b9fcd2015-06-01 13:13:55 +020026#include <linux/of_address.h>
Michael Turquette796b9aa2016-05-11 11:11:18 -070027#include <linux/platform_device.h>
Paul Gortmakera718ce32016-07-04 17:12:11 -040028#include <linux/init.h>
Carlo Caione28b9fcd2015-06-01 13:13:55 +020029
30#include "clkc.h"
Alexander Müllerd0c175d2016-08-27 19:40:50 +020031#include "meson8b.h"
Carlo Caione28b9fcd2015-06-01 13:13:55 +020032
Michael Turquettec0daa3e2016-04-28 12:01:51 -070033static DEFINE_SPINLOCK(clk_lock);
34
Carlo Caione28b9fcd2015-06-01 13:13:55 +020035static const struct pll_rate_table sys_pll_rate_table[] = {
36 PLL_RATE(312000000, 52, 1, 2),
37 PLL_RATE(336000000, 56, 1, 2),
38 PLL_RATE(360000000, 60, 1, 2),
39 PLL_RATE(384000000, 64, 1, 2),
40 PLL_RATE(408000000, 68, 1, 2),
41 PLL_RATE(432000000, 72, 1, 2),
42 PLL_RATE(456000000, 76, 1, 2),
43 PLL_RATE(480000000, 80, 1, 2),
44 PLL_RATE(504000000, 84, 1, 2),
45 PLL_RATE(528000000, 88, 1, 2),
46 PLL_RATE(552000000, 92, 1, 2),
47 PLL_RATE(576000000, 96, 1, 2),
48 PLL_RATE(600000000, 50, 1, 1),
49 PLL_RATE(624000000, 52, 1, 1),
50 PLL_RATE(648000000, 54, 1, 1),
51 PLL_RATE(672000000, 56, 1, 1),
52 PLL_RATE(696000000, 58, 1, 1),
53 PLL_RATE(720000000, 60, 1, 1),
54 PLL_RATE(744000000, 62, 1, 1),
55 PLL_RATE(768000000, 64, 1, 1),
56 PLL_RATE(792000000, 66, 1, 1),
57 PLL_RATE(816000000, 68, 1, 1),
58 PLL_RATE(840000000, 70, 1, 1),
59 PLL_RATE(864000000, 72, 1, 1),
60 PLL_RATE(888000000, 74, 1, 1),
61 PLL_RATE(912000000, 76, 1, 1),
62 PLL_RATE(936000000, 78, 1, 1),
63 PLL_RATE(960000000, 80, 1, 1),
64 PLL_RATE(984000000, 82, 1, 1),
65 PLL_RATE(1008000000, 84, 1, 1),
66 PLL_RATE(1032000000, 86, 1, 1),
67 PLL_RATE(1056000000, 88, 1, 1),
68 PLL_RATE(1080000000, 90, 1, 1),
69 PLL_RATE(1104000000, 92, 1, 1),
70 PLL_RATE(1128000000, 94, 1, 1),
71 PLL_RATE(1152000000, 96, 1, 1),
72 PLL_RATE(1176000000, 98, 1, 1),
73 PLL_RATE(1200000000, 50, 1, 0),
74 PLL_RATE(1224000000, 51, 1, 0),
75 PLL_RATE(1248000000, 52, 1, 0),
76 PLL_RATE(1272000000, 53, 1, 0),
77 PLL_RATE(1296000000, 54, 1, 0),
78 PLL_RATE(1320000000, 55, 1, 0),
79 PLL_RATE(1344000000, 56, 1, 0),
80 PLL_RATE(1368000000, 57, 1, 0),
81 PLL_RATE(1392000000, 58, 1, 0),
82 PLL_RATE(1416000000, 59, 1, 0),
83 PLL_RATE(1440000000, 60, 1, 0),
84 PLL_RATE(1464000000, 61, 1, 0),
85 PLL_RATE(1488000000, 62, 1, 0),
86 PLL_RATE(1512000000, 63, 1, 0),
87 PLL_RATE(1536000000, 64, 1, 0),
88 { /* sentinel */ },
89};
90
91static const struct clk_div_table cpu_div_table[] = {
92 { .val = 1, .div = 1 },
93 { .val = 2, .div = 2 },
94 { .val = 3, .div = 3 },
95 { .val = 2, .div = 4 },
96 { .val = 3, .div = 6 },
97 { .val = 4, .div = 8 },
98 { .val = 5, .div = 10 },
99 { .val = 6, .div = 12 },
100 { .val = 7, .div = 14 },
101 { .val = 8, .div = 16 },
102 { /* sentinel */ },
103};
104
Michael Turquettee92f7cc2016-04-28 12:00:52 -0700105static struct clk_fixed_rate meson8b_xtal = {
106 .fixed_rate = 24000000,
107 .hw.init = &(struct clk_init_data){
108 .name = "xtal",
109 .num_parents = 0,
110 .ops = &clk_fixed_rate_ops,
111 },
112};
113
Michael Turquetteec623f22016-04-28 12:01:42 -0700114static struct meson_clk_pll meson8b_fixed_pll = {
115 .m = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200116 .reg_off = HHI_MPLL_CNTL,
Michael Turquetteec623f22016-04-28 12:01:42 -0700117 .shift = 0,
118 .width = 9,
119 },
120 .n = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200121 .reg_off = HHI_MPLL_CNTL,
Michael Turquetteec623f22016-04-28 12:01:42 -0700122 .shift = 9,
123 .width = 5,
124 },
125 .od = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200126 .reg_off = HHI_MPLL_CNTL,
Michael Turquetteec623f22016-04-28 12:01:42 -0700127 .shift = 16,
128 .width = 2,
129 },
130 .lock = &clk_lock,
131 .hw.init = &(struct clk_init_data){
132 .name = "fixed_pll",
133 .ops = &meson_clk_pll_ro_ops,
134 .parent_names = (const char *[]){ "xtal" },
135 .num_parents = 1,
136 .flags = CLK_GET_RATE_NOCACHE,
137 },
138};
139
140static struct meson_clk_pll meson8b_vid_pll = {
141 .m = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200142 .reg_off = HHI_VID_PLL_CNTL,
Michael Turquetteec623f22016-04-28 12:01:42 -0700143 .shift = 0,
144 .width = 9,
145 },
146 .n = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200147 .reg_off = HHI_VID_PLL_CNTL,
Michael Turquetteec623f22016-04-28 12:01:42 -0700148 .shift = 9,
149 .width = 5,
150 },
151 .od = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200152 .reg_off = HHI_VID_PLL_CNTL,
Michael Turquetteec623f22016-04-28 12:01:42 -0700153 .shift = 16,
154 .width = 2,
155 },
156 .lock = &clk_lock,
157 .hw.init = &(struct clk_init_data){
158 .name = "vid_pll",
159 .ops = &meson_clk_pll_ro_ops,
160 .parent_names = (const char *[]){ "xtal" },
161 .num_parents = 1,
162 .flags = CLK_GET_RATE_NOCACHE,
163 },
164};
165
166static struct meson_clk_pll meson8b_sys_pll = {
167 .m = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200168 .reg_off = HHI_SYS_PLL_CNTL,
Michael Turquetteec623f22016-04-28 12:01:42 -0700169 .shift = 0,
170 .width = 9,
171 },
172 .n = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200173 .reg_off = HHI_SYS_PLL_CNTL,
Michael Turquetteec623f22016-04-28 12:01:42 -0700174 .shift = 9,
175 .width = 5,
176 },
177 .od = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200178 .reg_off = HHI_SYS_PLL_CNTL,
Michael Turquetteec623f22016-04-28 12:01:42 -0700179 .shift = 16,
180 .width = 2,
181 },
182 .rate_table = sys_pll_rate_table,
183 .rate_count = ARRAY_SIZE(sys_pll_rate_table),
184 .lock = &clk_lock,
185 .hw.init = &(struct clk_init_data){
186 .name = "sys_pll",
187 .ops = &meson_clk_pll_ops,
188 .parent_names = (const char *[]){ "xtal" },
189 .num_parents = 1,
190 .flags = CLK_GET_RATE_NOCACHE,
191 },
192};
193
Michael Turquette6282a2d2016-04-28 12:01:58 -0700194static struct clk_fixed_factor meson8b_fclk_div2 = {
195 .mult = 1,
196 .div = 2,
197 .hw.init = &(struct clk_init_data){
198 .name = "fclk_div2",
199 .ops = &clk_fixed_factor_ops,
200 .parent_names = (const char *[]){ "fixed_pll" },
201 .num_parents = 1,
202 },
203};
204
205static struct clk_fixed_factor meson8b_fclk_div3 = {
206 .mult = 1,
207 .div = 3,
208 .hw.init = &(struct clk_init_data){
209 .name = "fclk_div3",
210 .ops = &clk_fixed_factor_ops,
211 .parent_names = (const char *[]){ "fixed_pll" },
212 .num_parents = 1,
213 },
214};
215
216static struct clk_fixed_factor meson8b_fclk_div4 = {
217 .mult = 1,
218 .div = 4,
219 .hw.init = &(struct clk_init_data){
220 .name = "fclk_div4",
221 .ops = &clk_fixed_factor_ops,
222 .parent_names = (const char *[]){ "fixed_pll" },
223 .num_parents = 1,
224 },
225};
226
227static struct clk_fixed_factor meson8b_fclk_div5 = {
228 .mult = 1,
229 .div = 5,
230 .hw.init = &(struct clk_init_data){
231 .name = "fclk_div5",
232 .ops = &clk_fixed_factor_ops,
233 .parent_names = (const char *[]){ "fixed_pll" },
234 .num_parents = 1,
235 },
236};
237
238static struct clk_fixed_factor meson8b_fclk_div7 = {
239 .mult = 1,
240 .div = 7,
241 .hw.init = &(struct clk_init_data){
242 .name = "fclk_div7",
243 .ops = &clk_fixed_factor_ops,
244 .parent_names = (const char *[]){ "fixed_pll" },
245 .num_parents = 1,
246 },
247};
248
Jerome Brunetb778f742017-03-09 11:41:52 +0100249static struct meson_clk_mpll meson8b_mpll0 = {
250 .sdm = {
251 .reg_off = HHI_MPLL_CNTL7,
252 .shift = 0,
253 .width = 14,
254 },
255 .sdm_en = {
256 .reg_off = HHI_MPLL_CNTL7,
257 .shift = 15,
258 .width = 1,
259 },
260 .n2 = {
261 .reg_off = HHI_MPLL_CNTL7,
262 .shift = 16,
263 .width = 9,
264 },
265 .en = {
266 .reg_off = HHI_MPLL_CNTL7,
267 .shift = 14,
268 .width = 1,
269 },
Jerome Brunet1f737ff2017-07-28 18:32:28 +0200270 .ssen = {
271 .reg_off = HHI_MPLL_CNTL,
272 .shift = 25,
273 .width = 1,
274 },
Jerome Brunetb778f742017-03-09 11:41:52 +0100275 .lock = &clk_lock,
276 .hw.init = &(struct clk_init_data){
277 .name = "mpll0",
278 .ops = &meson_clk_mpll_ops,
279 .parent_names = (const char *[]){ "fixed_pll" },
280 .num_parents = 1,
281 },
282};
283
284static struct meson_clk_mpll meson8b_mpll1 = {
285 .sdm = {
286 .reg_off = HHI_MPLL_CNTL8,
287 .shift = 0,
288 .width = 14,
289 },
290 .sdm_en = {
291 .reg_off = HHI_MPLL_CNTL8,
292 .shift = 15,
293 .width = 1,
294 },
295 .n2 = {
296 .reg_off = HHI_MPLL_CNTL8,
297 .shift = 16,
298 .width = 9,
299 },
300 .en = {
301 .reg_off = HHI_MPLL_CNTL8,
302 .shift = 14,
303 .width = 1,
304 },
305 .lock = &clk_lock,
306 .hw.init = &(struct clk_init_data){
307 .name = "mpll1",
308 .ops = &meson_clk_mpll_ops,
309 .parent_names = (const char *[]){ "fixed_pll" },
310 .num_parents = 1,
311 },
312};
313
314static struct meson_clk_mpll meson8b_mpll2 = {
315 .sdm = {
316 .reg_off = HHI_MPLL_CNTL9,
317 .shift = 0,
318 .width = 14,
319 },
320 .sdm_en = {
321 .reg_off = HHI_MPLL_CNTL9,
322 .shift = 15,
323 .width = 1,
324 },
325 .n2 = {
326 .reg_off = HHI_MPLL_CNTL9,
327 .shift = 16,
328 .width = 9,
329 },
330 .en = {
331 .reg_off = HHI_MPLL_CNTL9,
332 .shift = 14,
333 .width = 1,
334 },
335 .lock = &clk_lock,
336 .hw.init = &(struct clk_init_data){
337 .name = "mpll2",
338 .ops = &meson_clk_mpll_ops,
339 .parent_names = (const char *[]){ "fixed_pll" },
340 .num_parents = 1,
341 },
342};
343
Michael Turquettec0daa3e2016-04-28 12:01:51 -0700344/*
345 * FIXME cpu clocks and the legacy composite clocks (e.g. clk81) are both PLL
346 * post-dividers and should be modeled with their respective PLLs via the
347 * forthcoming coordinated clock rates feature
348 */
Michael Turquette55d42c42016-04-30 12:47:36 -0700349static struct meson_clk_cpu meson8b_cpu_clk = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200350 .reg_off = HHI_SYS_CPU_CLK_CNTL1,
Michael Turquette55d42c42016-04-30 12:47:36 -0700351 .div_table = cpu_div_table,
352 .clk_nb.notifier_call = meson_clk_cpu_notifier_cb,
353 .hw.init = &(struct clk_init_data){
354 .name = "cpu_clk",
355 .ops = &meson_clk_cpu_ops,
356 .parent_names = (const char *[]){ "sys_pll" },
357 .num_parents = 1,
358 },
359};
360
Michael Turquettec0daa3e2016-04-28 12:01:51 -0700361static u32 mux_table_clk81[] = { 6, 5, 7 };
362
363struct clk_mux meson8b_mpeg_clk_sel = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200364 .reg = (void *)HHI_MPEG_CLK_CNTL,
Michael Turquettec0daa3e2016-04-28 12:01:51 -0700365 .mask = 0x7,
366 .shift = 12,
367 .flags = CLK_MUX_READ_ONLY,
368 .table = mux_table_clk81,
369 .lock = &clk_lock,
370 .hw.init = &(struct clk_init_data){
371 .name = "mpeg_clk_sel",
372 .ops = &clk_mux_ro_ops,
373 /*
374 * FIXME bits 14:12 selects from 8 possible parents:
375 * xtal, 1'b0 (wtf), fclk_div7, mpll_clkout1, mpll_clkout2,
376 * fclk_div4, fclk_div3, fclk_div5
377 */
378 .parent_names = (const char *[]){ "fclk_div3", "fclk_div4",
379 "fclk_div5" },
380 .num_parents = 3,
381 .flags = (CLK_SET_RATE_NO_REPARENT | CLK_IGNORE_UNUSED),
382 },
Carlo Caione28b9fcd2015-06-01 13:13:55 +0200383};
384
Michael Turquettec0daa3e2016-04-28 12:01:51 -0700385struct clk_divider meson8b_mpeg_clk_div = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200386 .reg = (void *)HHI_MPEG_CLK_CNTL,
Michael Turquettec0daa3e2016-04-28 12:01:51 -0700387 .shift = 0,
388 .width = 7,
389 .lock = &clk_lock,
390 .hw.init = &(struct clk_init_data){
391 .name = "mpeg_clk_div",
392 .ops = &clk_divider_ops,
393 .parent_names = (const char *[]){ "mpeg_clk_sel" },
394 .num_parents = 1,
395 .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED),
396 },
397};
398
399struct clk_gate meson8b_clk81 = {
Alexander Müllere0818a32016-08-27 19:40:51 +0200400 .reg = (void *)HHI_MPEG_CLK_CNTL,
Michael Turquettec0daa3e2016-04-28 12:01:51 -0700401 .bit_idx = 7,
402 .lock = &clk_lock,
403 .hw.init = &(struct clk_init_data){
404 .name = "clk81",
405 .ops = &clk_gate_ops,
406 .parent_names = (const char *[]){ "mpeg_clk_div" },
407 .num_parents = 1,
Martin Blumenstinglbe58e492017-05-24 11:39:31 +0200408 .flags = (CLK_SET_RATE_PARENT | CLK_IS_CRITICAL),
Michael Turquettec0daa3e2016-04-28 12:01:51 -0700409 },
410};
411
Alexander Müllere31a1902016-08-27 19:40:54 +0200412/* Everything Else (EE) domain gates */
413
414static MESON_GATE(meson8b_ddr, HHI_GCLK_MPEG0, 0);
415static MESON_GATE(meson8b_dos, HHI_GCLK_MPEG0, 1);
416static MESON_GATE(meson8b_isa, HHI_GCLK_MPEG0, 5);
417static MESON_GATE(meson8b_pl301, HHI_GCLK_MPEG0, 6);
418static MESON_GATE(meson8b_periphs, HHI_GCLK_MPEG0, 7);
419static MESON_GATE(meson8b_spicc, HHI_GCLK_MPEG0, 8);
420static MESON_GATE(meson8b_i2c, HHI_GCLK_MPEG0, 9);
421static MESON_GATE(meson8b_sar_adc, HHI_GCLK_MPEG0, 10);
422static MESON_GATE(meson8b_smart_card, HHI_GCLK_MPEG0, 11);
423static MESON_GATE(meson8b_rng0, HHI_GCLK_MPEG0, 12);
424static MESON_GATE(meson8b_uart0, HHI_GCLK_MPEG0, 13);
425static MESON_GATE(meson8b_sdhc, HHI_GCLK_MPEG0, 14);
426static MESON_GATE(meson8b_stream, HHI_GCLK_MPEG0, 15);
427static MESON_GATE(meson8b_async_fifo, HHI_GCLK_MPEG0, 16);
428static MESON_GATE(meson8b_sdio, HHI_GCLK_MPEG0, 17);
429static MESON_GATE(meson8b_abuf, HHI_GCLK_MPEG0, 18);
430static MESON_GATE(meson8b_hiu_iface, HHI_GCLK_MPEG0, 19);
431static MESON_GATE(meson8b_assist_misc, HHI_GCLK_MPEG0, 23);
432static MESON_GATE(meson8b_spi, HHI_GCLK_MPEG0, 30);
433
434static MESON_GATE(meson8b_i2s_spdif, HHI_GCLK_MPEG1, 2);
435static MESON_GATE(meson8b_eth, HHI_GCLK_MPEG1, 3);
436static MESON_GATE(meson8b_demux, HHI_GCLK_MPEG1, 4);
437static MESON_GATE(meson8b_aiu_glue, HHI_GCLK_MPEG1, 6);
438static MESON_GATE(meson8b_iec958, HHI_GCLK_MPEG1, 7);
439static MESON_GATE(meson8b_i2s_out, HHI_GCLK_MPEG1, 8);
440static MESON_GATE(meson8b_amclk, HHI_GCLK_MPEG1, 9);
441static MESON_GATE(meson8b_aififo2, HHI_GCLK_MPEG1, 10);
442static MESON_GATE(meson8b_mixer, HHI_GCLK_MPEG1, 11);
443static MESON_GATE(meson8b_mixer_iface, HHI_GCLK_MPEG1, 12);
444static MESON_GATE(meson8b_adc, HHI_GCLK_MPEG1, 13);
445static MESON_GATE(meson8b_blkmv, HHI_GCLK_MPEG1, 14);
446static MESON_GATE(meson8b_aiu, HHI_GCLK_MPEG1, 15);
447static MESON_GATE(meson8b_uart1, HHI_GCLK_MPEG1, 16);
448static MESON_GATE(meson8b_g2d, HHI_GCLK_MPEG1, 20);
449static MESON_GATE(meson8b_usb0, HHI_GCLK_MPEG1, 21);
450static MESON_GATE(meson8b_usb1, HHI_GCLK_MPEG1, 22);
451static MESON_GATE(meson8b_reset, HHI_GCLK_MPEG1, 23);
452static MESON_GATE(meson8b_nand, HHI_GCLK_MPEG1, 24);
453static MESON_GATE(meson8b_dos_parser, HHI_GCLK_MPEG1, 25);
454static MESON_GATE(meson8b_usb, HHI_GCLK_MPEG1, 26);
455static MESON_GATE(meson8b_vdin1, HHI_GCLK_MPEG1, 28);
456static MESON_GATE(meson8b_ahb_arb0, HHI_GCLK_MPEG1, 29);
457static MESON_GATE(meson8b_efuse, HHI_GCLK_MPEG1, 30);
458static MESON_GATE(meson8b_boot_rom, HHI_GCLK_MPEG1, 31);
459
460static MESON_GATE(meson8b_ahb_data_bus, HHI_GCLK_MPEG2, 1);
461static MESON_GATE(meson8b_ahb_ctrl_bus, HHI_GCLK_MPEG2, 2);
462static MESON_GATE(meson8b_hdmi_intr_sync, HHI_GCLK_MPEG2, 3);
463static MESON_GATE(meson8b_hdmi_pclk, HHI_GCLK_MPEG2, 4);
464static MESON_GATE(meson8b_usb1_ddr_bridge, HHI_GCLK_MPEG2, 8);
465static MESON_GATE(meson8b_usb0_ddr_bridge, HHI_GCLK_MPEG2, 9);
466static MESON_GATE(meson8b_mmc_pclk, HHI_GCLK_MPEG2, 11);
467static MESON_GATE(meson8b_dvin, HHI_GCLK_MPEG2, 12);
468static MESON_GATE(meson8b_uart2, HHI_GCLK_MPEG2, 15);
469static MESON_GATE(meson8b_sana, HHI_GCLK_MPEG2, 22);
470static MESON_GATE(meson8b_vpu_intr, HHI_GCLK_MPEG2, 25);
471static MESON_GATE(meson8b_sec_ahb_ahb3_bridge, HHI_GCLK_MPEG2, 26);
472static MESON_GATE(meson8b_clk81_a9, HHI_GCLK_MPEG2, 29);
473
474static MESON_GATE(meson8b_vclk2_venci0, HHI_GCLK_OTHER, 1);
475static MESON_GATE(meson8b_vclk2_venci1, HHI_GCLK_OTHER, 2);
476static MESON_GATE(meson8b_vclk2_vencp0, HHI_GCLK_OTHER, 3);
477static MESON_GATE(meson8b_vclk2_vencp1, HHI_GCLK_OTHER, 4);
478static MESON_GATE(meson8b_gclk_venci_int, HHI_GCLK_OTHER, 8);
479static MESON_GATE(meson8b_gclk_vencp_int, HHI_GCLK_OTHER, 9);
480static MESON_GATE(meson8b_dac_clk, HHI_GCLK_OTHER, 10);
481static MESON_GATE(meson8b_aoclk_gate, HHI_GCLK_OTHER, 14);
482static MESON_GATE(meson8b_iec958_gate, HHI_GCLK_OTHER, 16);
483static MESON_GATE(meson8b_enc480p, HHI_GCLK_OTHER, 20);
484static MESON_GATE(meson8b_rng1, HHI_GCLK_OTHER, 21);
485static MESON_GATE(meson8b_gclk_vencl_int, HHI_GCLK_OTHER, 22);
486static MESON_GATE(meson8b_vclk2_venclmcc, HHI_GCLK_OTHER, 24);
487static MESON_GATE(meson8b_vclk2_vencl, HHI_GCLK_OTHER, 25);
488static MESON_GATE(meson8b_vclk2_other, HHI_GCLK_OTHER, 26);
489static MESON_GATE(meson8b_edp, HHI_GCLK_OTHER, 31);
490
491/* Always On (AO) domain gates */
492
493static MESON_GATE(meson8b_ao_media_cpu, HHI_GCLK_AO, 0);
494static MESON_GATE(meson8b_ao_ahb_sram, HHI_GCLK_AO, 1);
495static MESON_GATE(meson8b_ao_ahb_bus, HHI_GCLK_AO, 2);
496static MESON_GATE(meson8b_ao_iface, HHI_GCLK_AO, 3);
497
Michael Turquettee92f7cc2016-04-28 12:00:52 -0700498static struct clk_hw_onecell_data meson8b_hw_onecell_data = {
499 .hws = {
500 [CLKID_XTAL] = &meson8b_xtal.hw,
Michael Turquetteec623f22016-04-28 12:01:42 -0700501 [CLKID_PLL_FIXED] = &meson8b_fixed_pll.hw,
502 [CLKID_PLL_VID] = &meson8b_vid_pll.hw,
503 [CLKID_PLL_SYS] = &meson8b_sys_pll.hw,
Michael Turquette6282a2d2016-04-28 12:01:58 -0700504 [CLKID_FCLK_DIV2] = &meson8b_fclk_div2.hw,
505 [CLKID_FCLK_DIV3] = &meson8b_fclk_div3.hw,
506 [CLKID_FCLK_DIV4] = &meson8b_fclk_div4.hw,
507 [CLKID_FCLK_DIV5] = &meson8b_fclk_div5.hw,
508 [CLKID_FCLK_DIV7] = &meson8b_fclk_div7.hw,
Michael Turquette55d42c42016-04-30 12:47:36 -0700509 [CLKID_CPUCLK] = &meson8b_cpu_clk.hw,
Michael Turquettec0daa3e2016-04-28 12:01:51 -0700510 [CLKID_MPEG_SEL] = &meson8b_mpeg_clk_sel.hw,
511 [CLKID_MPEG_DIV] = &meson8b_mpeg_clk_div.hw,
512 [CLKID_CLK81] = &meson8b_clk81.hw,
Alexander Müllere31a1902016-08-27 19:40:54 +0200513 [CLKID_DDR] = &meson8b_ddr.hw,
514 [CLKID_DOS] = &meson8b_dos.hw,
515 [CLKID_ISA] = &meson8b_isa.hw,
516 [CLKID_PL301] = &meson8b_pl301.hw,
517 [CLKID_PERIPHS] = &meson8b_periphs.hw,
518 [CLKID_SPICC] = &meson8b_spicc.hw,
519 [CLKID_I2C] = &meson8b_i2c.hw,
520 [CLKID_SAR_ADC] = &meson8b_sar_adc.hw,
521 [CLKID_SMART_CARD] = &meson8b_smart_card.hw,
522 [CLKID_RNG0] = &meson8b_rng0.hw,
523 [CLKID_UART0] = &meson8b_uart0.hw,
524 [CLKID_SDHC] = &meson8b_sdhc.hw,
525 [CLKID_STREAM] = &meson8b_stream.hw,
526 [CLKID_ASYNC_FIFO] = &meson8b_async_fifo.hw,
527 [CLKID_SDIO] = &meson8b_sdio.hw,
528 [CLKID_ABUF] = &meson8b_abuf.hw,
529 [CLKID_HIU_IFACE] = &meson8b_hiu_iface.hw,
530 [CLKID_ASSIST_MISC] = &meson8b_assist_misc.hw,
531 [CLKID_SPI] = &meson8b_spi.hw,
532 [CLKID_I2S_SPDIF] = &meson8b_i2s_spdif.hw,
533 [CLKID_ETH] = &meson8b_eth.hw,
534 [CLKID_DEMUX] = &meson8b_demux.hw,
535 [CLKID_AIU_GLUE] = &meson8b_aiu_glue.hw,
536 [CLKID_IEC958] = &meson8b_iec958.hw,
537 [CLKID_I2S_OUT] = &meson8b_i2s_out.hw,
538 [CLKID_AMCLK] = &meson8b_amclk.hw,
539 [CLKID_AIFIFO2] = &meson8b_aififo2.hw,
540 [CLKID_MIXER] = &meson8b_mixer.hw,
541 [CLKID_MIXER_IFACE] = &meson8b_mixer_iface.hw,
542 [CLKID_ADC] = &meson8b_adc.hw,
543 [CLKID_BLKMV] = &meson8b_blkmv.hw,
544 [CLKID_AIU] = &meson8b_aiu.hw,
545 [CLKID_UART1] = &meson8b_uart1.hw,
546 [CLKID_G2D] = &meson8b_g2d.hw,
547 [CLKID_USB0] = &meson8b_usb0.hw,
548 [CLKID_USB1] = &meson8b_usb1.hw,
549 [CLKID_RESET] = &meson8b_reset.hw,
550 [CLKID_NAND] = &meson8b_nand.hw,
551 [CLKID_DOS_PARSER] = &meson8b_dos_parser.hw,
552 [CLKID_USB] = &meson8b_usb.hw,
553 [CLKID_VDIN1] = &meson8b_vdin1.hw,
554 [CLKID_AHB_ARB0] = &meson8b_ahb_arb0.hw,
555 [CLKID_EFUSE] = &meson8b_efuse.hw,
556 [CLKID_BOOT_ROM] = &meson8b_boot_rom.hw,
557 [CLKID_AHB_DATA_BUS] = &meson8b_ahb_data_bus.hw,
558 [CLKID_AHB_CTRL_BUS] = &meson8b_ahb_ctrl_bus.hw,
559 [CLKID_HDMI_INTR_SYNC] = &meson8b_hdmi_intr_sync.hw,
560 [CLKID_HDMI_PCLK] = &meson8b_hdmi_pclk.hw,
561 [CLKID_USB1_DDR_BRIDGE] = &meson8b_usb1_ddr_bridge.hw,
562 [CLKID_USB0_DDR_BRIDGE] = &meson8b_usb0_ddr_bridge.hw,
563 [CLKID_MMC_PCLK] = &meson8b_mmc_pclk.hw,
564 [CLKID_DVIN] = &meson8b_dvin.hw,
565 [CLKID_UART2] = &meson8b_uart2.hw,
566 [CLKID_SANA] = &meson8b_sana.hw,
567 [CLKID_VPU_INTR] = &meson8b_vpu_intr.hw,
568 [CLKID_SEC_AHB_AHB3_BRIDGE] = &meson8b_sec_ahb_ahb3_bridge.hw,
569 [CLKID_CLK81_A9] = &meson8b_clk81_a9.hw,
570 [CLKID_VCLK2_VENCI0] = &meson8b_vclk2_venci0.hw,
571 [CLKID_VCLK2_VENCI1] = &meson8b_vclk2_venci1.hw,
572 [CLKID_VCLK2_VENCP0] = &meson8b_vclk2_vencp0.hw,
573 [CLKID_VCLK2_VENCP1] = &meson8b_vclk2_vencp1.hw,
574 [CLKID_GCLK_VENCI_INT] = &meson8b_gclk_venci_int.hw,
Arnd Bergmann0d5aa652016-09-06 15:01:10 +0200575 [CLKID_GCLK_VENCP_INT] = &meson8b_gclk_vencp_int.hw,
Alexander Müllere31a1902016-08-27 19:40:54 +0200576 [CLKID_DAC_CLK] = &meson8b_dac_clk.hw,
577 [CLKID_AOCLK_GATE] = &meson8b_aoclk_gate.hw,
578 [CLKID_IEC958_GATE] = &meson8b_iec958_gate.hw,
579 [CLKID_ENC480P] = &meson8b_enc480p.hw,
580 [CLKID_RNG1] = &meson8b_rng1.hw,
581 [CLKID_GCLK_VENCL_INT] = &meson8b_gclk_vencl_int.hw,
582 [CLKID_VCLK2_VENCLMCC] = &meson8b_vclk2_venclmcc.hw,
583 [CLKID_VCLK2_VENCL] = &meson8b_vclk2_vencl.hw,
584 [CLKID_VCLK2_OTHER] = &meson8b_vclk2_other.hw,
585 [CLKID_EDP] = &meson8b_edp.hw,
586 [CLKID_AO_MEDIA_CPU] = &meson8b_ao_media_cpu.hw,
587 [CLKID_AO_AHB_SRAM] = &meson8b_ao_ahb_sram.hw,
588 [CLKID_AO_AHB_BUS] = &meson8b_ao_ahb_bus.hw,
589 [CLKID_AO_IFACE] = &meson8b_ao_iface.hw,
Jerome Brunetb778f742017-03-09 11:41:52 +0100590 [CLKID_MPLL0] = &meson8b_mpll0.hw,
591 [CLKID_MPLL1] = &meson8b_mpll1.hw,
592 [CLKID_MPLL2] = &meson8b_mpll2.hw,
Michael Turquettee92f7cc2016-04-28 12:00:52 -0700593 },
594 .num = CLK_NR_CLKS,
595};
596
Michael Turquetteec623f22016-04-28 12:01:42 -0700597static struct meson_clk_pll *const meson8b_clk_plls[] = {
598 &meson8b_fixed_pll,
599 &meson8b_vid_pll,
600 &meson8b_sys_pll,
601};
602
Jerome Brunetb778f742017-03-09 11:41:52 +0100603static struct meson_clk_mpll *const meson8b_clk_mplls[] = {
604 &meson8b_mpll0,
605 &meson8b_mpll1,
606 &meson8b_mpll2,
607};
608
Jerome Brunetf7e3a822017-03-09 11:41:47 +0100609static struct clk_gate *const meson8b_clk_gates[] = {
Alexander Müllere31a1902016-08-27 19:40:54 +0200610 &meson8b_clk81,
611 &meson8b_ddr,
612 &meson8b_dos,
613 &meson8b_isa,
614 &meson8b_pl301,
615 &meson8b_periphs,
616 &meson8b_spicc,
617 &meson8b_i2c,
618 &meson8b_sar_adc,
619 &meson8b_smart_card,
620 &meson8b_rng0,
621 &meson8b_uart0,
622 &meson8b_sdhc,
623 &meson8b_stream,
624 &meson8b_async_fifo,
625 &meson8b_sdio,
626 &meson8b_abuf,
627 &meson8b_hiu_iface,
628 &meson8b_assist_misc,
629 &meson8b_spi,
630 &meson8b_i2s_spdif,
631 &meson8b_eth,
632 &meson8b_demux,
633 &meson8b_aiu_glue,
634 &meson8b_iec958,
635 &meson8b_i2s_out,
636 &meson8b_amclk,
637 &meson8b_aififo2,
638 &meson8b_mixer,
639 &meson8b_mixer_iface,
640 &meson8b_adc,
641 &meson8b_blkmv,
642 &meson8b_aiu,
643 &meson8b_uart1,
644 &meson8b_g2d,
645 &meson8b_usb0,
646 &meson8b_usb1,
647 &meson8b_reset,
648 &meson8b_nand,
649 &meson8b_dos_parser,
650 &meson8b_usb,
651 &meson8b_vdin1,
652 &meson8b_ahb_arb0,
653 &meson8b_efuse,
654 &meson8b_boot_rom,
655 &meson8b_ahb_data_bus,
656 &meson8b_ahb_ctrl_bus,
657 &meson8b_hdmi_intr_sync,
658 &meson8b_hdmi_pclk,
659 &meson8b_usb1_ddr_bridge,
660 &meson8b_usb0_ddr_bridge,
661 &meson8b_mmc_pclk,
662 &meson8b_dvin,
663 &meson8b_uart2,
664 &meson8b_sana,
665 &meson8b_vpu_intr,
666 &meson8b_sec_ahb_ahb3_bridge,
667 &meson8b_clk81_a9,
668 &meson8b_vclk2_venci0,
669 &meson8b_vclk2_venci1,
670 &meson8b_vclk2_vencp0,
671 &meson8b_vclk2_vencp1,
672 &meson8b_gclk_venci_int,
673 &meson8b_gclk_vencp_int,
674 &meson8b_dac_clk,
675 &meson8b_aoclk_gate,
676 &meson8b_iec958_gate,
677 &meson8b_enc480p,
678 &meson8b_rng1,
679 &meson8b_gclk_vencl_int,
680 &meson8b_vclk2_venclmcc,
681 &meson8b_vclk2_vencl,
682 &meson8b_vclk2_other,
683 &meson8b_edp,
684 &meson8b_ao_media_cpu,
685 &meson8b_ao_ahb_sram,
686 &meson8b_ao_ahb_bus,
687 &meson8b_ao_iface,
688};
689
Jerome Brunete988aae2017-03-09 11:41:48 +0100690static struct clk_mux *const meson8b_clk_muxes[] = {
691 &meson8b_mpeg_clk_sel,
692};
693
694static struct clk_divider *const meson8b_clk_dividers[] = {
695 &meson8b_mpeg_clk_div,
696};
697
Michael Turquette796b9aa2016-05-11 11:11:18 -0700698static int meson8b_clkc_probe(struct platform_device *pdev)
Carlo Caione28b9fcd2015-06-01 13:13:55 +0200699{
700 void __iomem *clk_base;
Michael Turquetteec623f22016-04-28 12:01:42 -0700701 int ret, clkid, i;
Michael Turquette55d42c42016-04-30 12:47:36 -0700702 struct clk_hw *parent_hw;
703 struct clk *parent_clk;
Michael Turquette796b9aa2016-05-11 11:11:18 -0700704 struct device *dev = &pdev->dev;
Carlo Caione28b9fcd2015-06-01 13:13:55 +0200705
Carlo Caione28b9fcd2015-06-01 13:13:55 +0200706 /* Generic clocks and PLLs */
Michael Turquette796b9aa2016-05-11 11:11:18 -0700707 clk_base = of_iomap(dev->of_node, 1);
Carlo Caione28b9fcd2015-06-01 13:13:55 +0200708 if (!clk_base) {
709 pr_err("%s: Unable to map clk base\n", __func__);
Michael Turquette796b9aa2016-05-11 11:11:18 -0700710 return -ENXIO;
Carlo Caione28b9fcd2015-06-01 13:13:55 +0200711 }
712
Michael Turquetteec623f22016-04-28 12:01:42 -0700713 /* Populate base address for PLLs */
714 for (i = 0; i < ARRAY_SIZE(meson8b_clk_plls); i++)
715 meson8b_clk_plls[i]->base = clk_base;
716
Jerome Brunetb778f742017-03-09 11:41:52 +0100717 /* Populate base address for MPLLs */
718 for (i = 0; i < ARRAY_SIZE(meson8b_clk_mplls); i++)
719 meson8b_clk_mplls[i]->base = clk_base;
720
Michael Turquette55d42c42016-04-30 12:47:36 -0700721 /* Populate the base address for CPU clk */
722 meson8b_cpu_clk.base = clk_base;
723
Alexander Müllere31a1902016-08-27 19:40:54 +0200724 /* Populate base address for gates */
725 for (i = 0; i < ARRAY_SIZE(meson8b_clk_gates); i++)
726 meson8b_clk_gates[i]->reg = clk_base +
727 (u32)meson8b_clk_gates[i]->reg;
728
Jerome Brunete988aae2017-03-09 11:41:48 +0100729 /* Populate base address for muxes */
730 for (i = 0; i < ARRAY_SIZE(meson8b_clk_muxes); i++)
731 meson8b_clk_muxes[i]->reg = clk_base +
732 (u32)meson8b_clk_muxes[i]->reg;
733
734 /* Populate base address for dividers */
735 for (i = 0; i < ARRAY_SIZE(meson8b_clk_dividers); i++)
736 meson8b_clk_dividers[i]->reg = clk_base +
737 (u32)meson8b_clk_dividers[i]->reg;
738
Michael Turquettee92f7cc2016-04-28 12:00:52 -0700739 /*
740 * register all clks
741 * CLKID_UNUSED = 0, so skip it and start with CLKID_XTAL = 1
742 */
743 for (clkid = CLKID_XTAL; clkid < CLK_NR_CLKS; clkid++) {
744 /* array might be sparse */
745 if (!meson8b_hw_onecell_data.hws[clkid])
746 continue;
747
748 /* FIXME convert to devm_clk_register */
Michael Turquette796b9aa2016-05-11 11:11:18 -0700749 ret = devm_clk_hw_register(dev, meson8b_hw_onecell_data.hws[clkid]);
Michael Turquettee92f7cc2016-04-28 12:00:52 -0700750 if (ret)
Michael Turquette796b9aa2016-05-11 11:11:18 -0700751 goto iounmap;
Michael Turquettee92f7cc2016-04-28 12:00:52 -0700752 }
753
Michael Turquette55d42c42016-04-30 12:47:36 -0700754 /*
755 * Register CPU clk notifier
756 *
757 * FIXME this is wrong for a lot of reasons. First, the muxes should be
758 * struct clk_hw objects. Second, we shouldn't program the muxes in
759 * notifier handlers. The tricky programming sequence will be handled
760 * by the forthcoming coordinated clock rates mechanism once that
761 * feature is released.
762 *
763 * Furthermore, looking up the parent this way is terrible. At some
764 * point we will stop allocating a default struct clk when registering
765 * a new clk_hw, and this hack will no longer work. Releasing the ccr
766 * feature before that time solves the problem :-)
767 */
768 parent_hw = clk_hw_get_parent(&meson8b_cpu_clk.hw);
769 parent_clk = parent_hw->clk;
770 ret = clk_notifier_register(parent_clk, &meson8b_cpu_clk.clk_nb);
771 if (ret) {
772 pr_err("%s: failed to register clock notifier for cpu_clk\n",
773 __func__);
Michael Turquette796b9aa2016-05-11 11:11:18 -0700774 goto iounmap;
Michael Turquette55d42c42016-04-30 12:47:36 -0700775 }
776
Michael Turquette796b9aa2016-05-11 11:11:18 -0700777 return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
778 &meson8b_hw_onecell_data);
Michael Turquettee92f7cc2016-04-28 12:00:52 -0700779
Michael Turquette796b9aa2016-05-11 11:11:18 -0700780iounmap:
781 iounmap(clk_base);
782 return ret;
Carlo Caione28b9fcd2015-06-01 13:13:55 +0200783}
Michael Turquette796b9aa2016-05-11 11:11:18 -0700784
785static const struct of_device_id meson8b_clkc_match_table[] = {
Martin Blumenstingl855f06a2017-06-04 20:33:39 +0200786 { .compatible = "amlogic,meson8-clkc" },
Michael Turquette796b9aa2016-05-11 11:11:18 -0700787 { .compatible = "amlogic,meson8b-clkc" },
Martin Blumenstingl855f06a2017-06-04 20:33:39 +0200788 { .compatible = "amlogic,meson8m2-clkc" },
Michael Turquette796b9aa2016-05-11 11:11:18 -0700789 { }
790};
Michael Turquette796b9aa2016-05-11 11:11:18 -0700791
792static struct platform_driver meson8b_driver = {
793 .probe = meson8b_clkc_probe,
794 .driver = {
795 .name = "meson8b-clkc",
796 .of_match_table = meson8b_clkc_match_table,
797 },
798};
799
Wei Yongjun8edeae52016-09-10 12:02:49 +0000800builtin_platform_driver(meson8b_driver);