blob: 510b6a7d2f1811b1f3bad5cae489950df5093c68 [file] [log] [blame]
Jerome Brunet22f65a32018-05-16 10:50:40 +02001// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
Neil Armstrongf8c11f72016-08-18 12:08:46 +02002/*
Neil Armstrongf8c11f72016-08-18 12:08:46 +02003 * Copyright (c) 2016 BayLibre, SAS.
4 * Author: Neil Armstrong <narmstrong@baylibre.com>
Neil Armstrongf8c11f72016-08-18 12:08:46 +02005 */
Neil Armstrongf8c11f72016-08-18 12:08:46 +02006#include <linux/platform_device.h>
Neil Armstrongffb13e32017-08-01 13:56:57 +02007#include <linux/mfd/syscon.h>
Jerome Brunetb2496232018-12-21 17:02:38 +01008#include "clkc.h"
Yixun Lan88e2da82018-05-03 21:26:20 +08009#include "meson-aoclk.h"
Neil Armstrongffb13e32017-08-01 13:56:57 +020010#include "gxbb-aoclk.h"
Neil Armstrongf8c11f72016-08-18 12:08:46 +020011
Jerome Brunet439a6bb2019-01-16 18:54:35 +010012#define IN_PREFIX "ao-in-"
13
Jerome Brunetb2496232018-12-21 17:02:38 +010014/* AO Configuration Clock registers offsets */
15#define AO_RTI_PWR_CNTL_REG1 0x0c
16#define AO_RTI_PWR_CNTL_REG0 0x10
17#define AO_RTI_GEN_CNTL_REG0 0x40
18#define AO_OSCIN_CNTL 0x58
19#define AO_CRT_CLK_CNTL1 0x68
20#define AO_RTC_ALT_CLK_CNTL0 0x94
21#define AO_RTC_ALT_CLK_CNTL1 0x98
22
Neil Armstrongf8c11f72016-08-18 12:08:46 +020023#define GXBB_AO_GATE(_name, _bit) \
Jerome Brunet81c7fca2018-02-12 15:58:33 +010024static struct clk_regmap _name##_ao = { \
25 .data = &(struct clk_regmap_gate_data) { \
26 .offset = AO_RTI_GEN_CNTL_REG0, \
27 .bit_idx = (_bit), \
28 }, \
Neil Armstrongf8c11f72016-08-18 12:08:46 +020029 .hw.init = &(struct clk_init_data) { \
30 .name = #_name "_ao", \
Jerome Brunet81c7fca2018-02-12 15:58:33 +010031 .ops = &clk_regmap_gate_ops, \
Jerome Brunet439a6bb2019-01-16 18:54:35 +010032 .parent_names = (const char *[]){ IN_PREFIX "mpeg-clk" }, \
Neil Armstrongf8c11f72016-08-18 12:08:46 +020033 .num_parents = 1, \
Yixun Lan24a2e672018-05-03 21:26:24 +080034 .flags = CLK_IGNORE_UNUSED, \
Neil Armstrongf8c11f72016-08-18 12:08:46 +020035 }, \
36}
37
38GXBB_AO_GATE(remote, 0);
39GXBB_AO_GATE(i2c_master, 1);
40GXBB_AO_GATE(i2c_slave, 2);
41GXBB_AO_GATE(uart1, 3);
42GXBB_AO_GATE(uart2, 5);
43GXBB_AO_GATE(ir_blaster, 6);
44
Jerome Brunetb2496232018-12-21 17:02:38 +010045static struct clk_regmap ao_cts_oscin = {
46 .data = &(struct clk_regmap_gate_data){
47 .offset = AO_RTI_PWR_CNTL_REG0,
48 .bit_idx = 6,
49 },
50 .hw.init = &(struct clk_init_data){
51 .name = "ao_cts_oscin",
52 .ops = &clk_regmap_gate_ro_ops,
Jerome Brunet439a6bb2019-01-16 18:54:35 +010053 .parent_names = (const char *[]){ IN_PREFIX "xtal" },
Neil Armstrong62ec0b92017-08-01 13:56:59 +020054 .num_parents = 1,
Jerome Brunetb2496232018-12-21 17:02:38 +010055 },
56};
57
58static struct clk_regmap ao_32k_pre = {
59 .data = &(struct clk_regmap_gate_data){
60 .offset = AO_RTC_ALT_CLK_CNTL0,
61 .bit_idx = 31,
62 },
63 .hw.init = &(struct clk_init_data){
64 .name = "ao_32k_pre",
65 .ops = &clk_regmap_gate_ops,
66 .parent_names = (const char *[]){ "ao_cts_oscin" },
67 .num_parents = 1,
68 },
69};
70
71static const struct meson_clk_dualdiv_param gxbb_32k_div_table[] = {
72 {
73 .dual = 1,
74 .n1 = 733,
75 .m1 = 8,
76 .n2 = 732,
77 .m2 = 11,
78 }, {}
79};
80
81static struct clk_regmap ao_32k_div = {
82 .data = &(struct meson_clk_dualdiv_data){
83 .n1 = {
84 .reg_off = AO_RTC_ALT_CLK_CNTL0,
85 .shift = 0,
86 .width = 12,
87 },
88 .n2 = {
89 .reg_off = AO_RTC_ALT_CLK_CNTL0,
90 .shift = 12,
91 .width = 12,
92 },
93 .m1 = {
94 .reg_off = AO_RTC_ALT_CLK_CNTL1,
95 .shift = 0,
96 .width = 12,
97 },
98 .m2 = {
99 .reg_off = AO_RTC_ALT_CLK_CNTL1,
100 .shift = 12,
101 .width = 12,
102 },
103 .dual = {
104 .reg_off = AO_RTC_ALT_CLK_CNTL0,
105 .shift = 28,
106 .width = 1,
107 },
108 .table = gxbb_32k_div_table,
109 },
110 .hw.init = &(struct clk_init_data){
111 .name = "ao_32k_div",
112 .ops = &meson_clk_dualdiv_ops,
113 .parent_names = (const char *[]){ "ao_32k_pre" },
114 .num_parents = 1,
115 },
116};
117
118static struct clk_regmap ao_32k_sel = {
119 .data = &(struct clk_regmap_mux_data) {
120 .offset = AO_RTC_ALT_CLK_CNTL1,
121 .mask = 0x1,
122 .shift = 24,
123 .flags = CLK_MUX_ROUND_CLOSEST,
124 },
125 .hw.init = &(struct clk_init_data){
126 .name = "ao_32k_sel",
127 .ops = &clk_regmap_mux_ops,
128 .parent_names = (const char *[]){ "ao_32k_div",
129 "ao_32k_pre" },
130 .num_parents = 2,
131 .flags = CLK_SET_RATE_PARENT,
132 },
133};
134
135static struct clk_regmap ao_32k = {
136 .data = &(struct clk_regmap_gate_data){
137 .offset = AO_RTC_ALT_CLK_CNTL0,
138 .bit_idx = 30,
139 },
140 .hw.init = &(struct clk_init_data){
141 .name = "ao_32k",
142 .ops = &clk_regmap_gate_ops,
143 .parent_names = (const char *[]){ "ao_32k_sel" },
144 .num_parents = 1,
145 .flags = CLK_SET_RATE_PARENT,
146 },
147};
148
149static struct clk_regmap ao_cts_rtc_oscin = {
150 .data = &(struct clk_regmap_mux_data) {
151 .offset = AO_RTI_PWR_CNTL_REG0,
152 .mask = 0x7,
153 .shift = 10,
154 .table = (u32[]){ 1, 2, 3, 4 },
155 .flags = CLK_MUX_ROUND_CLOSEST,
156 },
157 .hw.init = &(struct clk_init_data){
158 .name = "ao_cts_rtc_oscin",
159 .ops = &clk_regmap_mux_ops,
Jerome Brunet439a6bb2019-01-16 18:54:35 +0100160 .parent_names = (const char *[]){ IN_PREFIX "ext-32k-0",
161 IN_PREFIX "ext-32k-1",
162 IN_PREFIX "ext-32k-2",
Jerome Brunetb2496232018-12-21 17:02:38 +0100163 "ao_32k" },
164 .num_parents = 4,
165 .flags = CLK_SET_RATE_PARENT,
166 },
167};
168
169static struct clk_regmap ao_clk81 = {
170 .data = &(struct clk_regmap_mux_data) {
171 .offset = AO_RTI_PWR_CNTL_REG0,
172 .mask = 0x1,
173 .shift = 0,
174 .flags = CLK_MUX_ROUND_CLOSEST,
175 },
176 .hw.init = &(struct clk_init_data){
177 .name = "ao_clk81",
178 .ops = &clk_regmap_mux_ro_ops,
Jerome Brunet439a6bb2019-01-16 18:54:35 +0100179 .parent_names = (const char *[]){ IN_PREFIX "mpeg-clk",
Jerome Brunetb2496232018-12-21 17:02:38 +0100180 "ao_cts_rtc_oscin" },
181 .num_parents = 2,
182 .flags = CLK_SET_RATE_PARENT,
183 },
184};
185
186static struct clk_regmap ao_cts_cec = {
187 .data = &(struct clk_regmap_mux_data) {
188 .offset = AO_CRT_CLK_CNTL1,
189 .mask = 0x1,
190 .shift = 27,
191 .flags = CLK_MUX_ROUND_CLOSEST,
192 },
193 .hw.init = &(struct clk_init_data){
194 .name = "ao_cts_cec",
195 .ops = &clk_regmap_mux_ops,
196 /*
197 * FIXME: The 'fixme' parent obviously does not exist.
198 *
199 * ATM, CCF won't call get_parent() if num_parents is 1. It
200 * does not allow NULL as a parent name either.
201 *
202 * On this particular mux, we only know the input #1 parent
203 * but, on boot, unknown input #0 is set, so it is critical
204 * to call .get_parent() on it
205 *
206 * Until CCF gets fixed, adding this fake parent that won't
207 * ever be registered should work around the problem
208 */
209 .parent_names = (const char *[]){ "fixme",
210 "ao_cts_rtc_oscin" },
211 .num_parents = 2,
212 .flags = CLK_SET_RATE_PARENT,
Neil Armstrong62ec0b92017-08-01 13:56:59 +0200213 },
214};
215
Yixun Lan88e2da82018-05-03 21:26:20 +0800216static const unsigned int gxbb_aoclk_reset[] = {
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200217 [RESET_AO_REMOTE] = 16,
218 [RESET_AO_I2C_MASTER] = 18,
219 [RESET_AO_I2C_SLAVE] = 19,
220 [RESET_AO_UART1] = 17,
221 [RESET_AO_UART2] = 22,
222 [RESET_AO_IR_BLASTER] = 23,
223};
224
Jerome Brunetb2496232018-12-21 17:02:38 +0100225static struct clk_regmap *gxbb_aoclk[] = {
226 &remote_ao,
227 &i2c_master_ao,
228 &i2c_slave_ao,
229 &uart1_ao,
230 &uart2_ao,
231 &ir_blaster_ao,
232 &ao_cts_oscin,
233 &ao_32k_pre,
234 &ao_32k_div,
235 &ao_32k_sel,
236 &ao_32k,
237 &ao_cts_rtc_oscin,
238 &ao_clk81,
239 &ao_cts_cec,
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200240};
241
Yixun Lan88e2da82018-05-03 21:26:20 +0800242static const struct clk_hw_onecell_data gxbb_aoclk_onecell_data = {
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200243 .hws = {
244 [CLKID_AO_REMOTE] = &remote_ao.hw,
245 [CLKID_AO_I2C_MASTER] = &i2c_master_ao.hw,
246 [CLKID_AO_I2C_SLAVE] = &i2c_slave_ao.hw,
247 [CLKID_AO_UART1] = &uart1_ao.hw,
248 [CLKID_AO_UART2] = &uart2_ao.hw,
249 [CLKID_AO_IR_BLASTER] = &ir_blaster_ao.hw,
Jerome Brunetb2496232018-12-21 17:02:38 +0100250 [CLKID_AO_CEC_32K] = &ao_cts_cec.hw,
251 [CLKID_AO_CTS_OSCIN] = &ao_cts_oscin.hw,
252 [CLKID_AO_32K_PRE] = &ao_32k_pre.hw,
253 [CLKID_AO_32K_DIV] = &ao_32k_div.hw,
254 [CLKID_AO_32K_SEL] = &ao_32k_sel.hw,
255 [CLKID_AO_32K] = &ao_32k.hw,
256 [CLKID_AO_CTS_RTC_OSCIN] = &ao_cts_rtc_oscin.hw,
257 [CLKID_AO_CLK81] = &ao_clk81.hw,
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200258 },
Yixun Lan88e2da82018-05-03 21:26:20 +0800259 .num = NR_CLKS,
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200260};
261
Jerome Brunet439a6bb2019-01-16 18:54:35 +0100262static const struct meson_aoclk_input gxbb_aoclk_inputs[] = {
263 { .name = "xtal", .required = true, },
264 { .name = "mpeg-clk", .required = true, },
265 {. name = "ext-32k-0", .required = false, },
266 {. name = "ext-32k-1", .required = false, },
267 {. name = "ext-32k-2", .required = false, },
268};
269
Yixun Lan88e2da82018-05-03 21:26:20 +0800270static const struct meson_aoclk_data gxbb_aoclkc_data = {
271 .reset_reg = AO_RTI_GEN_CNTL_REG0,
272 .num_reset = ARRAY_SIZE(gxbb_aoclk_reset),
273 .reset = gxbb_aoclk_reset,
Jerome Brunetb2496232018-12-21 17:02:38 +0100274 .num_clks = ARRAY_SIZE(gxbb_aoclk),
275 .clks = gxbb_aoclk,
Yixun Lan88e2da82018-05-03 21:26:20 +0800276 .hw_data = &gxbb_aoclk_onecell_data,
Jerome Brunet439a6bb2019-01-16 18:54:35 +0100277 .inputs = gxbb_aoclk_inputs,
278 .num_inputs = ARRAY_SIZE(gxbb_aoclk_inputs),
279 .input_prefix = IN_PREFIX,
Yixun Lan88e2da82018-05-03 21:26:20 +0800280};
281
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200282static const struct of_device_id gxbb_aoclkc_match_table[] = {
Yixun Lan88e2da82018-05-03 21:26:20 +0800283 {
284 .compatible = "amlogic,meson-gx-aoclkc",
285 .data = &gxbb_aoclkc_data,
286 },
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200287 { }
288};
289
290static struct platform_driver gxbb_aoclkc_driver = {
Jerome Brunetb2496232018-12-21 17:02:38 +0100291 .probe = meson_aoclkc_probe,
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200292 .driver = {
293 .name = "gxbb-aoclkc",
294 .of_match_table = gxbb_aoclkc_match_table,
295 },
296};
297builtin_platform_driver(gxbb_aoclkc_driver);