1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
3 * Copyright (c) 2016 BayLibre, SAS.
6 #include <linux/platform_device.h>
7 #include <linux/mfd/syscon.h>
8 #include <linux/module.h>
9 #include "meson-aoclk.h"
10 #include "gxbb-aoclk.h"
12 #include "clk-regmap.h"
13 #include "clk-dualdiv.h"
15 /* AO Configuration Clock registers offsets */
16 #define AO_RTI_PWR_CNTL_REG1 0x0c
17 #define AO_RTI_PWR_CNTL_REG0 0x10
18 #define AO_RTI_GEN_CNTL_REG0 0x40
19 #define AO_OSCIN_CNTL 0x58
20 #define AO_CRT_CLK_CNTL1 0x68
21 #define AO_RTC_ALT_CLK_CNTL0 0x94
22 #define AO_RTC_ALT_CLK_CNTL1 0x98
24 #define GXBB_AO_GATE(_name, _bit) \
25 static struct clk_regmap _name##_ao = { \
26 .data = &(struct clk_regmap_gate_data) { \
27 .offset = AO_RTI_GEN_CNTL_REG0, \
30 .hw.init = &(struct clk_init_data) { \
31 .name = #_name "_ao", \
32 .ops = &clk_regmap_gate_ops, \
33 .parent_data = &(const struct clk_parent_data) { \
34 .fw_name = "mpeg-clk", \
37 .flags = CLK_IGNORE_UNUSED, \
41 GXBB_AO_GATE(remote, 0);
42 GXBB_AO_GATE(i2c_master, 1);
43 GXBB_AO_GATE(i2c_slave, 2);
44 GXBB_AO_GATE(uart1, 3);
45 GXBB_AO_GATE(uart2, 5);
46 GXBB_AO_GATE(ir_blaster, 6);
48 static struct clk_regmap ao_cts_oscin = {
49 .data = &(struct clk_regmap_gate_data){
50 .offset = AO_RTI_PWR_CNTL_REG0,
53 .hw.init = &(struct clk_init_data){
54 .name = "ao_cts_oscin",
55 .ops = &clk_regmap_gate_ro_ops,
56 .parent_data = &(const struct clk_parent_data) {
63 static struct clk_regmap ao_32k_pre = {
64 .data = &(struct clk_regmap_gate_data){
65 .offset = AO_RTC_ALT_CLK_CNTL0,
68 .hw.init = &(struct clk_init_data){
70 .ops = &clk_regmap_gate_ops,
71 .parent_hws = (const struct clk_hw *[]) { &ao_cts_oscin.hw },
76 static const struct meson_clk_dualdiv_param gxbb_32k_div_table[] = {
86 static struct clk_regmap ao_32k_div = {
87 .data = &(struct meson_clk_dualdiv_data){
89 .reg_off = AO_RTC_ALT_CLK_CNTL0,
94 .reg_off = AO_RTC_ALT_CLK_CNTL0,
99 .reg_off = AO_RTC_ALT_CLK_CNTL1,
104 .reg_off = AO_RTC_ALT_CLK_CNTL1,
109 .reg_off = AO_RTC_ALT_CLK_CNTL0,
113 .table = gxbb_32k_div_table,
115 .hw.init = &(struct clk_init_data){
116 .name = "ao_32k_div",
117 .ops = &meson_clk_dualdiv_ops,
118 .parent_hws = (const struct clk_hw *[]) { &ao_32k_pre.hw },
123 static struct clk_regmap ao_32k_sel = {
124 .data = &(struct clk_regmap_mux_data) {
125 .offset = AO_RTC_ALT_CLK_CNTL1,
128 .flags = CLK_MUX_ROUND_CLOSEST,
130 .hw.init = &(struct clk_init_data){
131 .name = "ao_32k_sel",
132 .ops = &clk_regmap_mux_ops,
133 .parent_hws = (const struct clk_hw *[]) {
138 .flags = CLK_SET_RATE_PARENT,
142 static struct clk_regmap ao_32k = {
143 .data = &(struct clk_regmap_gate_data){
144 .offset = AO_RTC_ALT_CLK_CNTL0,
147 .hw.init = &(struct clk_init_data){
149 .ops = &clk_regmap_gate_ops,
150 .parent_hws = (const struct clk_hw *[]) { &ao_32k_sel.hw },
152 .flags = CLK_SET_RATE_PARENT,
156 static struct clk_regmap ao_cts_rtc_oscin = {
157 .data = &(struct clk_regmap_mux_data) {
158 .offset = AO_RTI_PWR_CNTL_REG0,
161 .table = (u32[]){ 1, 2, 3, 4 },
162 .flags = CLK_MUX_ROUND_CLOSEST,
164 .hw.init = &(struct clk_init_data){
165 .name = "ao_cts_rtc_oscin",
166 .ops = &clk_regmap_mux_ops,
167 .parent_data = (const struct clk_parent_data []) {
168 { .fw_name = "ext-32k-0", },
169 { .fw_name = "ext-32k-1", },
170 { .fw_name = "ext-32k-2", },
171 { .hw = &ao_32k.hw },
174 .flags = CLK_SET_RATE_PARENT,
178 static struct clk_regmap ao_clk81 = {
179 .data = &(struct clk_regmap_mux_data) {
180 .offset = AO_RTI_PWR_CNTL_REG0,
183 .flags = CLK_MUX_ROUND_CLOSEST,
185 .hw.init = &(struct clk_init_data){
187 .ops = &clk_regmap_mux_ro_ops,
188 .parent_data = (const struct clk_parent_data []) {
189 { .fw_name = "mpeg-clk", },
190 { .hw = &ao_cts_rtc_oscin.hw },
193 .flags = CLK_SET_RATE_PARENT,
197 static struct clk_regmap ao_cts_cec = {
198 .data = &(struct clk_regmap_mux_data) {
199 .offset = AO_CRT_CLK_CNTL1,
202 .flags = CLK_MUX_ROUND_CLOSEST,
204 .hw.init = &(struct clk_init_data){
205 .name = "ao_cts_cec",
206 .ops = &clk_regmap_mux_ops,
208 * FIXME: The 'fixme' parent obviously does not exist.
210 * ATM, CCF won't call get_parent() if num_parents is 1. It
211 * does not allow NULL as a parent name either.
213 * On this particular mux, we only know the input #1 parent
214 * but, on boot, unknown input #0 is set, so it is critical
215 * to call .get_parent() on it
217 * Until CCF gets fixed, adding this fake parent that won't
218 * ever be registered should work around the problem
220 .parent_data = (const struct clk_parent_data []) {
221 { .name = "fixme", .index = -1, },
222 { .hw = &ao_cts_rtc_oscin.hw },
225 .flags = CLK_SET_RATE_PARENT,
229 static const unsigned int gxbb_aoclk_reset[] = {
230 [RESET_AO_REMOTE] = 16,
231 [RESET_AO_I2C_MASTER] = 18,
232 [RESET_AO_I2C_SLAVE] = 19,
233 [RESET_AO_UART1] = 17,
234 [RESET_AO_UART2] = 22,
235 [RESET_AO_IR_BLASTER] = 23,
238 static struct clk_regmap *gxbb_aoclk[] = {
255 static const struct clk_hw_onecell_data gxbb_aoclk_onecell_data = {
257 [CLKID_AO_REMOTE] = &remote_ao.hw,
258 [CLKID_AO_I2C_MASTER] = &i2c_master_ao.hw,
259 [CLKID_AO_I2C_SLAVE] = &i2c_slave_ao.hw,
260 [CLKID_AO_UART1] = &uart1_ao.hw,
261 [CLKID_AO_UART2] = &uart2_ao.hw,
262 [CLKID_AO_IR_BLASTER] = &ir_blaster_ao.hw,
263 [CLKID_AO_CEC_32K] = &ao_cts_cec.hw,
264 [CLKID_AO_CTS_OSCIN] = &ao_cts_oscin.hw,
265 [CLKID_AO_32K_PRE] = &ao_32k_pre.hw,
266 [CLKID_AO_32K_DIV] = &ao_32k_div.hw,
267 [CLKID_AO_32K_SEL] = &ao_32k_sel.hw,
268 [CLKID_AO_32K] = &ao_32k.hw,
269 [CLKID_AO_CTS_RTC_OSCIN] = &ao_cts_rtc_oscin.hw,
270 [CLKID_AO_CLK81] = &ao_clk81.hw,
275 static const struct meson_aoclk_data gxbb_aoclkc_data = {
276 .reset_reg = AO_RTI_GEN_CNTL_REG0,
277 .num_reset = ARRAY_SIZE(gxbb_aoclk_reset),
278 .reset = gxbb_aoclk_reset,
279 .num_clks = ARRAY_SIZE(gxbb_aoclk),
281 .hw_data = &gxbb_aoclk_onecell_data,
284 static const struct of_device_id gxbb_aoclkc_match_table[] = {
286 .compatible = "amlogic,meson-gx-aoclkc",
287 .data = &gxbb_aoclkc_data,
291 MODULE_DEVICE_TABLE(of, gxbb_aoclkc_match_table);
293 static struct platform_driver gxbb_aoclkc_driver = {
294 .probe = meson_aoclkc_probe,
296 .name = "gxbb-aoclkc",
297 .of_match_table = gxbb_aoclkc_match_table,
300 module_platform_driver(gxbb_aoclkc_driver);
301 MODULE_LICENSE("GPL v2");