blob: 5fa57b623b8fc07b3e51a1afeb391592a874f82f [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 Brunetb2496232018-12-21 17:02:38 +010012/* AO Configuration Clock registers offsets */
13#define AO_RTI_PWR_CNTL_REG1 0x0c
14#define AO_RTI_PWR_CNTL_REG0 0x10
15#define AO_RTI_GEN_CNTL_REG0 0x40
16#define AO_OSCIN_CNTL 0x58
17#define AO_CRT_CLK_CNTL1 0x68
18#define AO_RTC_ALT_CLK_CNTL0 0x94
19#define AO_RTC_ALT_CLK_CNTL1 0x98
20
Neil Armstrongf8c11f72016-08-18 12:08:46 +020021#define GXBB_AO_GATE(_name, _bit) \
Jerome Brunet81c7fca2018-02-12 15:58:33 +010022static struct clk_regmap _name##_ao = { \
23 .data = &(struct clk_regmap_gate_data) { \
24 .offset = AO_RTI_GEN_CNTL_REG0, \
25 .bit_idx = (_bit), \
26 }, \
Neil Armstrongf8c11f72016-08-18 12:08:46 +020027 .hw.init = &(struct clk_init_data) { \
28 .name = #_name "_ao", \
Jerome Brunet81c7fca2018-02-12 15:58:33 +010029 .ops = &clk_regmap_gate_ops, \
Neil Armstrongf8c11f72016-08-18 12:08:46 +020030 .parent_names = (const char *[]){ "clk81" }, \
31 .num_parents = 1, \
Yixun Lan24a2e672018-05-03 21:26:24 +080032 .flags = CLK_IGNORE_UNUSED, \
Neil Armstrongf8c11f72016-08-18 12:08:46 +020033 }, \
34}
35
36GXBB_AO_GATE(remote, 0);
37GXBB_AO_GATE(i2c_master, 1);
38GXBB_AO_GATE(i2c_slave, 2);
39GXBB_AO_GATE(uart1, 3);
40GXBB_AO_GATE(uart2, 5);
41GXBB_AO_GATE(ir_blaster, 6);
42
Jerome Brunetb2496232018-12-21 17:02:38 +010043static struct clk_regmap ao_cts_oscin = {
44 .data = &(struct clk_regmap_gate_data){
45 .offset = AO_RTI_PWR_CNTL_REG0,
46 .bit_idx = 6,
47 },
48 .hw.init = &(struct clk_init_data){
49 .name = "ao_cts_oscin",
50 .ops = &clk_regmap_gate_ro_ops,
Neil Armstrong62ec0b92017-08-01 13:56:59 +020051 .parent_names = (const char *[]){ "xtal" },
52 .num_parents = 1,
Jerome Brunetb2496232018-12-21 17:02:38 +010053 },
54};
55
56static struct clk_regmap ao_32k_pre = {
57 .data = &(struct clk_regmap_gate_data){
58 .offset = AO_RTC_ALT_CLK_CNTL0,
59 .bit_idx = 31,
60 },
61 .hw.init = &(struct clk_init_data){
62 .name = "ao_32k_pre",
63 .ops = &clk_regmap_gate_ops,
64 .parent_names = (const char *[]){ "ao_cts_oscin" },
65 .num_parents = 1,
66 },
67};
68
69static const struct meson_clk_dualdiv_param gxbb_32k_div_table[] = {
70 {
71 .dual = 1,
72 .n1 = 733,
73 .m1 = 8,
74 .n2 = 732,
75 .m2 = 11,
76 }, {}
77};
78
79static struct clk_regmap ao_32k_div = {
80 .data = &(struct meson_clk_dualdiv_data){
81 .n1 = {
82 .reg_off = AO_RTC_ALT_CLK_CNTL0,
83 .shift = 0,
84 .width = 12,
85 },
86 .n2 = {
87 .reg_off = AO_RTC_ALT_CLK_CNTL0,
88 .shift = 12,
89 .width = 12,
90 },
91 .m1 = {
92 .reg_off = AO_RTC_ALT_CLK_CNTL1,
93 .shift = 0,
94 .width = 12,
95 },
96 .m2 = {
97 .reg_off = AO_RTC_ALT_CLK_CNTL1,
98 .shift = 12,
99 .width = 12,
100 },
101 .dual = {
102 .reg_off = AO_RTC_ALT_CLK_CNTL0,
103 .shift = 28,
104 .width = 1,
105 },
106 .table = gxbb_32k_div_table,
107 },
108 .hw.init = &(struct clk_init_data){
109 .name = "ao_32k_div",
110 .ops = &meson_clk_dualdiv_ops,
111 .parent_names = (const char *[]){ "ao_32k_pre" },
112 .num_parents = 1,
113 },
114};
115
116static struct clk_regmap ao_32k_sel = {
117 .data = &(struct clk_regmap_mux_data) {
118 .offset = AO_RTC_ALT_CLK_CNTL1,
119 .mask = 0x1,
120 .shift = 24,
121 .flags = CLK_MUX_ROUND_CLOSEST,
122 },
123 .hw.init = &(struct clk_init_data){
124 .name = "ao_32k_sel",
125 .ops = &clk_regmap_mux_ops,
126 .parent_names = (const char *[]){ "ao_32k_div",
127 "ao_32k_pre" },
128 .num_parents = 2,
129 .flags = CLK_SET_RATE_PARENT,
130 },
131};
132
133static struct clk_regmap ao_32k = {
134 .data = &(struct clk_regmap_gate_data){
135 .offset = AO_RTC_ALT_CLK_CNTL0,
136 .bit_idx = 30,
137 },
138 .hw.init = &(struct clk_init_data){
139 .name = "ao_32k",
140 .ops = &clk_regmap_gate_ops,
141 .parent_names = (const char *[]){ "ao_32k_sel" },
142 .num_parents = 1,
143 .flags = CLK_SET_RATE_PARENT,
144 },
145};
146
147static struct clk_regmap ao_cts_rtc_oscin = {
148 .data = &(struct clk_regmap_mux_data) {
149 .offset = AO_RTI_PWR_CNTL_REG0,
150 .mask = 0x7,
151 .shift = 10,
152 .table = (u32[]){ 1, 2, 3, 4 },
153 .flags = CLK_MUX_ROUND_CLOSEST,
154 },
155 .hw.init = &(struct clk_init_data){
156 .name = "ao_cts_rtc_oscin",
157 .ops = &clk_regmap_mux_ops,
158 .parent_names = (const char *[]){ "ext_32k_0",
159 "ext_32k_1",
160 "ext_32k_2",
161 "ao_32k" },
162 .num_parents = 4,
163 .flags = CLK_SET_RATE_PARENT,
164 },
165};
166
167static struct clk_regmap ao_clk81 = {
168 .data = &(struct clk_regmap_mux_data) {
169 .offset = AO_RTI_PWR_CNTL_REG0,
170 .mask = 0x1,
171 .shift = 0,
172 .flags = CLK_MUX_ROUND_CLOSEST,
173 },
174 .hw.init = &(struct clk_init_data){
175 .name = "ao_clk81",
176 .ops = &clk_regmap_mux_ro_ops,
177 .parent_names = (const char *[]){ "clk81",
178 "ao_cts_rtc_oscin" },
179 .num_parents = 2,
180 .flags = CLK_SET_RATE_PARENT,
181 },
182};
183
184static struct clk_regmap ao_cts_cec = {
185 .data = &(struct clk_regmap_mux_data) {
186 .offset = AO_CRT_CLK_CNTL1,
187 .mask = 0x1,
188 .shift = 27,
189 .flags = CLK_MUX_ROUND_CLOSEST,
190 },
191 .hw.init = &(struct clk_init_data){
192 .name = "ao_cts_cec",
193 .ops = &clk_regmap_mux_ops,
194 /*
195 * FIXME: The 'fixme' parent obviously does not exist.
196 *
197 * ATM, CCF won't call get_parent() if num_parents is 1. It
198 * does not allow NULL as a parent name either.
199 *
200 * On this particular mux, we only know the input #1 parent
201 * but, on boot, unknown input #0 is set, so it is critical
202 * to call .get_parent() on it
203 *
204 * Until CCF gets fixed, adding this fake parent that won't
205 * ever be registered should work around the problem
206 */
207 .parent_names = (const char *[]){ "fixme",
208 "ao_cts_rtc_oscin" },
209 .num_parents = 2,
210 .flags = CLK_SET_RATE_PARENT,
Neil Armstrong62ec0b92017-08-01 13:56:59 +0200211 },
212};
213
Yixun Lan88e2da82018-05-03 21:26:20 +0800214static const unsigned int gxbb_aoclk_reset[] = {
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200215 [RESET_AO_REMOTE] = 16,
216 [RESET_AO_I2C_MASTER] = 18,
217 [RESET_AO_I2C_SLAVE] = 19,
218 [RESET_AO_UART1] = 17,
219 [RESET_AO_UART2] = 22,
220 [RESET_AO_IR_BLASTER] = 23,
221};
222
Jerome Brunetb2496232018-12-21 17:02:38 +0100223static struct clk_regmap *gxbb_aoclk[] = {
224 &remote_ao,
225 &i2c_master_ao,
226 &i2c_slave_ao,
227 &uart1_ao,
228 &uart2_ao,
229 &ir_blaster_ao,
230 &ao_cts_oscin,
231 &ao_32k_pre,
232 &ao_32k_div,
233 &ao_32k_sel,
234 &ao_32k,
235 &ao_cts_rtc_oscin,
236 &ao_clk81,
237 &ao_cts_cec,
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200238};
239
Yixun Lan88e2da82018-05-03 21:26:20 +0800240static const struct clk_hw_onecell_data gxbb_aoclk_onecell_data = {
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200241 .hws = {
242 [CLKID_AO_REMOTE] = &remote_ao.hw,
243 [CLKID_AO_I2C_MASTER] = &i2c_master_ao.hw,
244 [CLKID_AO_I2C_SLAVE] = &i2c_slave_ao.hw,
245 [CLKID_AO_UART1] = &uart1_ao.hw,
246 [CLKID_AO_UART2] = &uart2_ao.hw,
247 [CLKID_AO_IR_BLASTER] = &ir_blaster_ao.hw,
Jerome Brunetb2496232018-12-21 17:02:38 +0100248 [CLKID_AO_CEC_32K] = &ao_cts_cec.hw,
249 [CLKID_AO_CTS_OSCIN] = &ao_cts_oscin.hw,
250 [CLKID_AO_32K_PRE] = &ao_32k_pre.hw,
251 [CLKID_AO_32K_DIV] = &ao_32k_div.hw,
252 [CLKID_AO_32K_SEL] = &ao_32k_sel.hw,
253 [CLKID_AO_32K] = &ao_32k.hw,
254 [CLKID_AO_CTS_RTC_OSCIN] = &ao_cts_rtc_oscin.hw,
255 [CLKID_AO_CLK81] = &ao_clk81.hw,
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200256 },
Yixun Lan88e2da82018-05-03 21:26:20 +0800257 .num = NR_CLKS,
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200258};
259
Yixun Lan88e2da82018-05-03 21:26:20 +0800260static const struct meson_aoclk_data gxbb_aoclkc_data = {
261 .reset_reg = AO_RTI_GEN_CNTL_REG0,
262 .num_reset = ARRAY_SIZE(gxbb_aoclk_reset),
263 .reset = gxbb_aoclk_reset,
Jerome Brunetb2496232018-12-21 17:02:38 +0100264 .num_clks = ARRAY_SIZE(gxbb_aoclk),
265 .clks = gxbb_aoclk,
Yixun Lan88e2da82018-05-03 21:26:20 +0800266 .hw_data = &gxbb_aoclk_onecell_data,
267};
268
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200269static const struct of_device_id gxbb_aoclkc_match_table[] = {
Yixun Lan88e2da82018-05-03 21:26:20 +0800270 {
271 .compatible = "amlogic,meson-gx-aoclkc",
272 .data = &gxbb_aoclkc_data,
273 },
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200274 { }
275};
276
277static struct platform_driver gxbb_aoclkc_driver = {
Jerome Brunetb2496232018-12-21 17:02:38 +0100278 .probe = meson_aoclkc_probe,
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200279 .driver = {
280 .name = "gxbb-aoclkc",
281 .of_match_table = gxbb_aoclkc_match_table,
282 },
283};
284builtin_platform_driver(gxbb_aoclkc_driver);