Jerome Brunet | 22f65a3 | 2018-05-16 10:50:40 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 2 | /* |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 3 | * Copyright (c) 2016 BayLibre, SAS. |
| 4 | * Author: Neil Armstrong <narmstrong@baylibre.com> |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 5 | */ |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 6 | #include <linux/platform_device.h> |
Neil Armstrong | ffb13e3 | 2017-08-01 13:56:57 +0200 | [diff] [blame] | 7 | #include <linux/mfd/syscon.h> |
Jerome Brunet | b249623 | 2018-12-21 17:02:38 +0100 | [diff] [blame^] | 8 | #include "clkc.h" |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 9 | #include "meson-aoclk.h" |
Neil Armstrong | ffb13e3 | 2017-08-01 13:56:57 +0200 | [diff] [blame] | 10 | #include "gxbb-aoclk.h" |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 11 | |
Jerome Brunet | b249623 | 2018-12-21 17:02:38 +0100 | [diff] [blame^] | 12 | /* 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 Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 21 | #define GXBB_AO_GATE(_name, _bit) \ |
Jerome Brunet | 81c7fca | 2018-02-12 15:58:33 +0100 | [diff] [blame] | 22 | static 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 Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 27 | .hw.init = &(struct clk_init_data) { \ |
| 28 | .name = #_name "_ao", \ |
Jerome Brunet | 81c7fca | 2018-02-12 15:58:33 +0100 | [diff] [blame] | 29 | .ops = &clk_regmap_gate_ops, \ |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 30 | .parent_names = (const char *[]){ "clk81" }, \ |
| 31 | .num_parents = 1, \ |
Yixun Lan | 24a2e67 | 2018-05-03 21:26:24 +0800 | [diff] [blame] | 32 | .flags = CLK_IGNORE_UNUSED, \ |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 33 | }, \ |
| 34 | } |
| 35 | |
| 36 | GXBB_AO_GATE(remote, 0); |
| 37 | GXBB_AO_GATE(i2c_master, 1); |
| 38 | GXBB_AO_GATE(i2c_slave, 2); |
| 39 | GXBB_AO_GATE(uart1, 3); |
| 40 | GXBB_AO_GATE(uart2, 5); |
| 41 | GXBB_AO_GATE(ir_blaster, 6); |
| 42 | |
Jerome Brunet | b249623 | 2018-12-21 17:02:38 +0100 | [diff] [blame^] | 43 | static 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 Armstrong | 62ec0b9 | 2017-08-01 13:56:59 +0200 | [diff] [blame] | 51 | .parent_names = (const char *[]){ "xtal" }, |
| 52 | .num_parents = 1, |
Jerome Brunet | b249623 | 2018-12-21 17:02:38 +0100 | [diff] [blame^] | 53 | }, |
| 54 | }; |
| 55 | |
| 56 | static 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 | |
| 69 | static 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 | |
| 79 | static 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 | |
| 116 | static 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 | |
| 133 | static 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 | |
| 147 | static 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 | |
| 167 | static 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 | |
| 184 | static 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 Armstrong | 62ec0b9 | 2017-08-01 13:56:59 +0200 | [diff] [blame] | 211 | }, |
| 212 | }; |
| 213 | |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 214 | static const unsigned int gxbb_aoclk_reset[] = { |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 215 | [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 Brunet | b249623 | 2018-12-21 17:02:38 +0100 | [diff] [blame^] | 223 | static 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 Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 238 | }; |
| 239 | |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 240 | static const struct clk_hw_onecell_data gxbb_aoclk_onecell_data = { |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 241 | .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 Brunet | b249623 | 2018-12-21 17:02:38 +0100 | [diff] [blame^] | 248 | [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 Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 256 | }, |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 257 | .num = NR_CLKS, |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 258 | }; |
| 259 | |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 260 | static 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 Brunet | b249623 | 2018-12-21 17:02:38 +0100 | [diff] [blame^] | 264 | .num_clks = ARRAY_SIZE(gxbb_aoclk), |
| 265 | .clks = gxbb_aoclk, |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 266 | .hw_data = &gxbb_aoclk_onecell_data, |
| 267 | }; |
| 268 | |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 269 | static const struct of_device_id gxbb_aoclkc_match_table[] = { |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 270 | { |
| 271 | .compatible = "amlogic,meson-gx-aoclkc", |
| 272 | .data = &gxbb_aoclkc_data, |
| 273 | }, |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 274 | { } |
| 275 | }; |
| 276 | |
| 277 | static struct platform_driver gxbb_aoclkc_driver = { |
Jerome Brunet | b249623 | 2018-12-21 17:02:38 +0100 | [diff] [blame^] | 278 | .probe = meson_aoclkc_probe, |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 279 | .driver = { |
| 280 | .name = "gxbb-aoclkc", |
| 281 | .of_match_table = gxbb_aoclkc_match_table, |
| 282 | }, |
| 283 | }; |
| 284 | builtin_platform_driver(gxbb_aoclkc_driver); |