Peng Fan | 525c876 | 2019-08-19 07:54:04 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright 2019 NXP |
| 4 | * Peng Fan <peng.fan@nxp.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <clk.h> |
| 9 | #include <clk-uclass.h> |
| 10 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Peng Fan | 525c876 | 2019-08-19 07:54:04 +0000 | [diff] [blame] | 12 | #include <asm/arch/clock.h> |
| 13 | #include <asm/arch/imx-regs.h> |
| 14 | #include <dt-bindings/clock/imx8mm-clock.h> |
| 15 | |
| 16 | #include "clk.h" |
| 17 | |
| 18 | #define PLL_1416X_RATE(_rate, _m, _p, _s) \ |
| 19 | { \ |
| 20 | .rate = (_rate), \ |
| 21 | .mdiv = (_m), \ |
| 22 | .pdiv = (_p), \ |
| 23 | .sdiv = (_s), \ |
| 24 | } |
| 25 | |
| 26 | #define PLL_1443X_RATE(_rate, _m, _p, _s, _k) \ |
| 27 | { \ |
| 28 | .rate = (_rate), \ |
| 29 | .mdiv = (_m), \ |
| 30 | .pdiv = (_p), \ |
| 31 | .sdiv = (_s), \ |
| 32 | .kdiv = (_k), \ |
| 33 | } |
| 34 | |
| 35 | static const struct imx_pll14xx_rate_table imx8mm_pll1416x_tbl[] = { |
| 36 | PLL_1416X_RATE(1800000000U, 225, 3, 0), |
| 37 | PLL_1416X_RATE(1600000000U, 200, 3, 0), |
| 38 | PLL_1416X_RATE(1200000000U, 300, 3, 1), |
| 39 | PLL_1416X_RATE(1000000000U, 250, 3, 1), |
| 40 | PLL_1416X_RATE(800000000U, 200, 3, 1), |
| 41 | PLL_1416X_RATE(750000000U, 250, 2, 2), |
| 42 | PLL_1416X_RATE(700000000U, 350, 3, 2), |
| 43 | PLL_1416X_RATE(600000000U, 300, 3, 2), |
| 44 | }; |
| 45 | |
| 46 | static const struct imx_pll14xx_rate_table imx8mm_drampll_tbl[] = { |
| 47 | PLL_1443X_RATE(650000000U, 325, 3, 2, 0), |
| 48 | }; |
| 49 | |
| 50 | static struct imx_pll14xx_clk imx8mm_dram_pll __initdata = { |
| 51 | .type = PLL_1443X, |
| 52 | .rate_table = imx8mm_drampll_tbl, |
| 53 | .rate_count = ARRAY_SIZE(imx8mm_drampll_tbl), |
| 54 | }; |
| 55 | |
| 56 | static struct imx_pll14xx_clk imx8mm_arm_pll __initdata = { |
| 57 | .type = PLL_1416X, |
| 58 | .rate_table = imx8mm_pll1416x_tbl, |
| 59 | .rate_count = ARRAY_SIZE(imx8mm_pll1416x_tbl), |
| 60 | }; |
| 61 | |
| 62 | static struct imx_pll14xx_clk imx8mm_sys_pll __initdata = { |
| 63 | .type = PLL_1416X, |
| 64 | .rate_table = imx8mm_pll1416x_tbl, |
| 65 | .rate_count = ARRAY_SIZE(imx8mm_pll1416x_tbl), |
| 66 | }; |
| 67 | |
| 68 | static const char *pll_ref_sels[] = { "clock-osc-24m", "dummy", "dummy", "dummy", }; |
| 69 | static const char *dram_pll_bypass_sels[] = {"dram_pll", "dram_pll_ref_sel", }; |
| 70 | static const char *arm_pll_bypass_sels[] = {"arm_pll", "arm_pll_ref_sel", }; |
| 71 | static const char *sys_pll1_bypass_sels[] = {"sys_pll1", "sys_pll1_ref_sel", }; |
| 72 | static const char *sys_pll2_bypass_sels[] = {"sys_pll2", "sys_pll2_ref_sel", }; |
| 73 | static const char *sys_pll3_bypass_sels[] = {"sys_pll3", "sys_pll3_ref_sel", }; |
| 74 | |
| 75 | static const char *imx8mm_a53_sels[] = {"clock-osc-24m", "arm_pll_out", "sys_pll2_500m", "sys_pll2_1000m", |
| 76 | "sys_pll1_800m", "sys_pll1_400m", "audio_pll1_out", "sys_pll3_out", }; |
| 77 | |
Frieder Schrempf | 2d82cf8 | 2019-10-23 16:36:44 +0000 | [diff] [blame] | 78 | static const char *imx8mm_ahb_sels[] = {"clock-osc-24m", "sys_pll1_133m", "sys_pll1_800m", "sys_pll1_400m", |
Peng Fan | 525c876 | 2019-08-19 07:54:04 +0000 | [diff] [blame] | 79 | "sys_pll2_125m", "sys_pll3_out", "audio_pll1_out", "video_pll1_out", }; |
| 80 | |
| 81 | static const char *imx8mm_enet_axi_sels[] = {"clock-osc-24m", "sys_pll1_266m", "sys_pll1_800m", "sys_pll2_250m", |
| 82 | "sys_pll2_200m", "audio_pll1_out", "video_pll1_out", "sys_pll3_out", }; |
| 83 | |
Peng Fan | ee5515d | 2019-10-22 03:29:48 +0000 | [diff] [blame] | 84 | #ifndef CONFIG_SPL_BUILD |
| 85 | static const char *imx8mm_enet_ref_sels[] = {"clock-osc-24m", "sys_pll2_125m", "sys_pll2_50m", "sys_pll2_100m", |
| 86 | "sys_pll1_160m", "audio_pll1_out", "video_pll1_out", "clk_ext4", }; |
| 87 | |
| 88 | static const char *imx8mm_enet_timer_sels[] = {"clock-osc-24m", "sys_pll2_100m", "audio_pll1_out", "clk_ext1", "clk_ext2", |
| 89 | "clk_ext3", "clk_ext4", "video_pll1_out", }; |
| 90 | |
| 91 | static const char *imx8mm_enet_phy_sels[] = {"clock-osc-24m", "sys_pll2_50m", "sys_pll2_125m", "sys_pll2_200m", |
| 92 | "sys_pll2_500m", "video_pll1_out", "audio_pll2_out", }; |
| 93 | #endif |
| 94 | |
Peng Fan | 525c876 | 2019-08-19 07:54:04 +0000 | [diff] [blame] | 95 | static const char *imx8mm_nand_usdhc_sels[] = {"clock-osc-24m", "sys_pll1_266m", "sys_pll1_800m", "sys_pll2_200m", |
| 96 | "sys_pll1_133m", "sys_pll3_out", "sys_pll2_250m", "audio_pll1_out", }; |
| 97 | |
| 98 | static const char *imx8mm_usdhc1_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m", "sys_pll2_500m", |
| 99 | "sys_pll3_out", "sys_pll1_266m", "audio_pll2_out", "sys_pll1_100m", }; |
| 100 | |
| 101 | static const char *imx8mm_usdhc2_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m", "sys_pll2_500m", |
| 102 | "sys_pll3_out", "sys_pll1_266m", "audio_pll2_out", "sys_pll1_100m", }; |
| 103 | |
| 104 | static const char *imx8mm_i2c1_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m", "sys_pll3_out", "audio_pll1_out", |
| 105 | "video_pll1_out", "audio_pll2_out", "sys_pll1_133m", }; |
| 106 | |
| 107 | static const char *imx8mm_i2c2_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m", "sys_pll3_out", "audio_pll1_out", |
| 108 | "video_pll1_out", "audio_pll2_out", "sys_pll1_133m", }; |
| 109 | |
| 110 | static const char *imx8mm_i2c3_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m", "sys_pll3_out", "audio_pll1_out", |
| 111 | "video_pll1_out", "audio_pll2_out", "sys_pll1_133m", }; |
| 112 | |
| 113 | static const char *imx8mm_i2c4_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m", "sys_pll3_out", "audio_pll1_out", |
| 114 | "video_pll1_out", "audio_pll2_out", "sys_pll1_133m", }; |
| 115 | |
| 116 | static const char *imx8mm_wdog_sels[] = {"clock-osc-24m", "sys_pll1_133m", "sys_pll1_160m", "vpu_pll_out", |
| 117 | "sys_pll2_125m", "sys_pll3_out", "sys_pll1_80m", "sys_pll2_166m", }; |
| 118 | |
| 119 | static const char *imx8mm_usdhc3_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m", "sys_pll2_500m", |
| 120 | "sys_pll3_out", "sys_pll1_266m", "audio_pll2_clk", "sys_pll1_100m", }; |
| 121 | |
Peng Fan | 2dff879 | 2020-06-27 15:49:28 +0800 | [diff] [blame^] | 122 | static const char *imx8mm_qspi_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll2_333m", "sys_pll2_500m", |
| 123 | "audio_pll2_out", "sys_pll1_266m", "sys_pll3_out", "sys_pll1_100m", }; |
| 124 | |
Peng Fan | 525c876 | 2019-08-19 07:54:04 +0000 | [diff] [blame] | 125 | static ulong imx8mm_clk_get_rate(struct clk *clk) |
| 126 | { |
| 127 | struct clk *c; |
| 128 | int ret; |
| 129 | |
| 130 | debug("%s(#%lu)\n", __func__, clk->id); |
| 131 | |
| 132 | ret = clk_get_by_id(clk->id, &c); |
| 133 | if (ret) |
| 134 | return ret; |
| 135 | |
| 136 | return clk_get_rate(c); |
| 137 | } |
| 138 | |
| 139 | static ulong imx8mm_clk_set_rate(struct clk *clk, unsigned long rate) |
| 140 | { |
| 141 | struct clk *c; |
| 142 | int ret; |
| 143 | |
| 144 | debug("%s(#%lu), rate: %lu\n", __func__, clk->id, rate); |
| 145 | |
| 146 | ret = clk_get_by_id(clk->id, &c); |
| 147 | if (ret) |
| 148 | return ret; |
| 149 | |
| 150 | return clk_set_rate(c, rate); |
| 151 | } |
| 152 | |
| 153 | static int __imx8mm_clk_enable(struct clk *clk, bool enable) |
| 154 | { |
| 155 | struct clk *c; |
| 156 | int ret; |
| 157 | |
| 158 | debug("%s(#%lu) en: %d\n", __func__, clk->id, enable); |
| 159 | |
| 160 | ret = clk_get_by_id(clk->id, &c); |
| 161 | if (ret) |
| 162 | return ret; |
| 163 | |
| 164 | if (enable) |
| 165 | ret = clk_enable(c); |
| 166 | else |
| 167 | ret = clk_disable(c); |
| 168 | |
| 169 | return ret; |
| 170 | } |
| 171 | |
| 172 | static int imx8mm_clk_disable(struct clk *clk) |
| 173 | { |
| 174 | return __imx8mm_clk_enable(clk, 0); |
| 175 | } |
| 176 | |
| 177 | static int imx8mm_clk_enable(struct clk *clk) |
| 178 | { |
| 179 | return __imx8mm_clk_enable(clk, 1); |
| 180 | } |
| 181 | |
Peng Fan | 7adf587 | 2019-10-22 03:29:51 +0000 | [diff] [blame] | 182 | static int imx8mm_clk_set_parent(struct clk *clk, struct clk *parent) |
| 183 | { |
| 184 | struct clk *c, *cp; |
| 185 | int ret; |
| 186 | |
| 187 | debug("%s(#%lu), parent: %lu\n", __func__, clk->id, parent->id); |
| 188 | |
| 189 | ret = clk_get_by_id(clk->id, &c); |
| 190 | if (ret) |
| 191 | return ret; |
| 192 | |
| 193 | ret = clk_get_by_id(parent->id, &cp); |
| 194 | if (ret) |
| 195 | return ret; |
| 196 | |
Peng Fan | 6088c51 | 2020-06-27 15:48:04 +0800 | [diff] [blame] | 197 | ret = clk_set_parent(c, cp); |
| 198 | c->dev->parent = cp->dev; |
| 199 | |
| 200 | return ret; |
Peng Fan | 7adf587 | 2019-10-22 03:29:51 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Peng Fan | 525c876 | 2019-08-19 07:54:04 +0000 | [diff] [blame] | 203 | static struct clk_ops imx8mm_clk_ops = { |
| 204 | .set_rate = imx8mm_clk_set_rate, |
| 205 | .get_rate = imx8mm_clk_get_rate, |
| 206 | .enable = imx8mm_clk_enable, |
| 207 | .disable = imx8mm_clk_disable, |
Peng Fan | 7adf587 | 2019-10-22 03:29:51 +0000 | [diff] [blame] | 208 | .set_parent = imx8mm_clk_set_parent, |
Peng Fan | 525c876 | 2019-08-19 07:54:04 +0000 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | static int imx8mm_clk_probe(struct udevice *dev) |
| 212 | { |
| 213 | void __iomem *base; |
| 214 | |
| 215 | base = (void *)ANATOP_BASE_ADDR; |
| 216 | |
| 217 | clk_dm(IMX8MM_DRAM_PLL_REF_SEL, |
| 218 | imx_clk_mux("dram_pll_ref_sel", base + 0x50, 0, 2, |
| 219 | pll_ref_sels, ARRAY_SIZE(pll_ref_sels))); |
| 220 | clk_dm(IMX8MM_ARM_PLL_REF_SEL, |
| 221 | imx_clk_mux("arm_pll_ref_sel", base + 0x84, 0, 2, |
| 222 | pll_ref_sels, ARRAY_SIZE(pll_ref_sels))); |
| 223 | clk_dm(IMX8MM_SYS_PLL1_REF_SEL, |
| 224 | imx_clk_mux("sys_pll1_ref_sel", base + 0x94, 0, 2, |
| 225 | pll_ref_sels, ARRAY_SIZE(pll_ref_sels))); |
| 226 | clk_dm(IMX8MM_SYS_PLL2_REF_SEL, |
| 227 | imx_clk_mux("sys_pll2_ref_sel", base + 0x104, 0, 2, |
| 228 | pll_ref_sels, ARRAY_SIZE(pll_ref_sels))); |
| 229 | clk_dm(IMX8MM_SYS_PLL3_REF_SEL, |
| 230 | imx_clk_mux("sys_pll3_ref_sel", base + 0x114, 0, 2, |
| 231 | pll_ref_sels, ARRAY_SIZE(pll_ref_sels))); |
| 232 | |
| 233 | clk_dm(IMX8MM_DRAM_PLL, |
| 234 | imx_clk_pll14xx("dram_pll", "dram_pll_ref_sel", |
| 235 | base + 0x50, &imx8mm_dram_pll)); |
| 236 | clk_dm(IMX8MM_ARM_PLL, |
| 237 | imx_clk_pll14xx("arm_pll", "arm_pll_ref_sel", |
| 238 | base + 0x84, &imx8mm_arm_pll)); |
| 239 | clk_dm(IMX8MM_SYS_PLL1, |
| 240 | imx_clk_pll14xx("sys_pll1", "sys_pll1_ref_sel", |
| 241 | base + 0x94, &imx8mm_sys_pll)); |
| 242 | clk_dm(IMX8MM_SYS_PLL2, |
| 243 | imx_clk_pll14xx("sys_pll2", "sys_pll2_ref_sel", |
| 244 | base + 0x104, &imx8mm_sys_pll)); |
| 245 | clk_dm(IMX8MM_SYS_PLL3, |
| 246 | imx_clk_pll14xx("sys_pll3", "sys_pll3_ref_sel", |
| 247 | base + 0x114, &imx8mm_sys_pll)); |
| 248 | |
| 249 | /* PLL bypass out */ |
| 250 | clk_dm(IMX8MM_DRAM_PLL_BYPASS, |
| 251 | imx_clk_mux_flags("dram_pll_bypass", base + 0x50, 4, 1, |
| 252 | dram_pll_bypass_sels, |
| 253 | ARRAY_SIZE(dram_pll_bypass_sels), |
| 254 | CLK_SET_RATE_PARENT)); |
| 255 | clk_dm(IMX8MM_ARM_PLL_BYPASS, |
| 256 | imx_clk_mux_flags("arm_pll_bypass", base + 0x84, 4, 1, |
| 257 | arm_pll_bypass_sels, |
| 258 | ARRAY_SIZE(arm_pll_bypass_sels), |
| 259 | CLK_SET_RATE_PARENT)); |
| 260 | clk_dm(IMX8MM_SYS_PLL1_BYPASS, |
| 261 | imx_clk_mux_flags("sys_pll1_bypass", base + 0x94, 4, 1, |
| 262 | sys_pll1_bypass_sels, |
| 263 | ARRAY_SIZE(sys_pll1_bypass_sels), |
| 264 | CLK_SET_RATE_PARENT)); |
| 265 | clk_dm(IMX8MM_SYS_PLL2_BYPASS, |
| 266 | imx_clk_mux_flags("sys_pll2_bypass", base + 0x104, 4, 1, |
| 267 | sys_pll2_bypass_sels, |
| 268 | ARRAY_SIZE(sys_pll2_bypass_sels), |
| 269 | CLK_SET_RATE_PARENT)); |
| 270 | clk_dm(IMX8MM_SYS_PLL3_BYPASS, |
| 271 | imx_clk_mux_flags("sys_pll3_bypass", base + 0x114, 4, 1, |
| 272 | sys_pll3_bypass_sels, |
| 273 | ARRAY_SIZE(sys_pll3_bypass_sels), |
| 274 | CLK_SET_RATE_PARENT)); |
| 275 | |
| 276 | /* PLL out gate */ |
| 277 | clk_dm(IMX8MM_DRAM_PLL_OUT, |
| 278 | imx_clk_gate("dram_pll_out", "dram_pll_bypass", |
| 279 | base + 0x50, 13)); |
| 280 | clk_dm(IMX8MM_ARM_PLL_OUT, |
| 281 | imx_clk_gate("arm_pll_out", "arm_pll_bypass", |
| 282 | base + 0x84, 11)); |
| 283 | clk_dm(IMX8MM_SYS_PLL1_OUT, |
| 284 | imx_clk_gate("sys_pll1_out", "sys_pll1_bypass", |
| 285 | base + 0x94, 11)); |
| 286 | clk_dm(IMX8MM_SYS_PLL2_OUT, |
| 287 | imx_clk_gate("sys_pll2_out", "sys_pll2_bypass", |
| 288 | base + 0x104, 11)); |
| 289 | clk_dm(IMX8MM_SYS_PLL3_OUT, |
| 290 | imx_clk_gate("sys_pll3_out", "sys_pll3_bypass", |
| 291 | base + 0x114, 11)); |
| 292 | |
| 293 | /* SYS PLL fixed output */ |
| 294 | clk_dm(IMX8MM_SYS_PLL1_40M, |
| 295 | imx_clk_fixed_factor("sys_pll1_40m", "sys_pll1_out", 1, 20)); |
| 296 | clk_dm(IMX8MM_SYS_PLL1_80M, |
| 297 | imx_clk_fixed_factor("sys_pll1_80m", "sys_pll1_out", 1, 10)); |
| 298 | clk_dm(IMX8MM_SYS_PLL1_100M, |
| 299 | imx_clk_fixed_factor("sys_pll1_100m", "sys_pll1_out", 1, 8)); |
| 300 | clk_dm(IMX8MM_SYS_PLL1_133M, |
| 301 | imx_clk_fixed_factor("sys_pll1_133m", "sys_pll1_out", 1, 6)); |
| 302 | clk_dm(IMX8MM_SYS_PLL1_160M, |
| 303 | imx_clk_fixed_factor("sys_pll1_160m", "sys_pll1_out", 1, 5)); |
| 304 | clk_dm(IMX8MM_SYS_PLL1_200M, |
| 305 | imx_clk_fixed_factor("sys_pll1_200m", "sys_pll1_out", 1, 4)); |
| 306 | clk_dm(IMX8MM_SYS_PLL1_266M, |
| 307 | imx_clk_fixed_factor("sys_pll1_266m", "sys_pll1_out", 1, 3)); |
| 308 | clk_dm(IMX8MM_SYS_PLL1_400M, |
| 309 | imx_clk_fixed_factor("sys_pll1_400m", "sys_pll1_out", 1, 2)); |
| 310 | clk_dm(IMX8MM_SYS_PLL1_800M, |
| 311 | imx_clk_fixed_factor("sys_pll1_800m", "sys_pll1_out", 1, 1)); |
| 312 | |
| 313 | clk_dm(IMX8MM_SYS_PLL2_50M, |
| 314 | imx_clk_fixed_factor("sys_pll2_50m", "sys_pll2_out", 1, 20)); |
| 315 | clk_dm(IMX8MM_SYS_PLL2_100M, |
| 316 | imx_clk_fixed_factor("sys_pll2_100m", "sys_pll2_out", 1, 10)); |
| 317 | clk_dm(IMX8MM_SYS_PLL2_125M, |
| 318 | imx_clk_fixed_factor("sys_pll2_125m", "sys_pll2_out", 1, 8)); |
| 319 | clk_dm(IMX8MM_SYS_PLL2_166M, |
| 320 | imx_clk_fixed_factor("sys_pll2_166m", "sys_pll2_out", 1, 6)); |
| 321 | clk_dm(IMX8MM_SYS_PLL2_200M, |
| 322 | imx_clk_fixed_factor("sys_pll2_200m", "sys_pll2_out", 1, 5)); |
| 323 | clk_dm(IMX8MM_SYS_PLL2_250M, |
| 324 | imx_clk_fixed_factor("sys_pll2_250m", "sys_pll2_out", 1, 4)); |
| 325 | clk_dm(IMX8MM_SYS_PLL2_333M, |
| 326 | imx_clk_fixed_factor("sys_pll2_333m", "sys_pll2_out", 1, 3)); |
| 327 | clk_dm(IMX8MM_SYS_PLL2_500M, |
| 328 | imx_clk_fixed_factor("sys_pll2_500m", "sys_pll2_out", 1, 2)); |
| 329 | clk_dm(IMX8MM_SYS_PLL2_1000M, |
| 330 | imx_clk_fixed_factor("sys_pll2_1000m", "sys_pll2_out", 1, 1)); |
| 331 | |
| 332 | base = dev_read_addr_ptr(dev); |
Sean Anderson | b58106d | 2019-12-24 23:57:47 -0500 | [diff] [blame] | 333 | if (!base) |
Peng Fan | 525c876 | 2019-08-19 07:54:04 +0000 | [diff] [blame] | 334 | return -EINVAL; |
| 335 | |
| 336 | clk_dm(IMX8MM_CLK_A53_SRC, |
| 337 | imx_clk_mux2("arm_a53_src", base + 0x8000, 24, 3, |
| 338 | imx8mm_a53_sels, ARRAY_SIZE(imx8mm_a53_sels))); |
| 339 | clk_dm(IMX8MM_CLK_A53_CG, |
| 340 | imx_clk_gate3("arm_a53_cg", "arm_a53_src", base + 0x8000, 28)); |
| 341 | clk_dm(IMX8MM_CLK_A53_DIV, |
| 342 | imx_clk_divider2("arm_a53_div", "arm_a53_cg", |
| 343 | base + 0x8000, 0, 3)); |
| 344 | |
| 345 | clk_dm(IMX8MM_CLK_AHB, |
| 346 | imx8m_clk_composite_critical("ahb", imx8mm_ahb_sels, |
| 347 | base + 0x9000)); |
| 348 | clk_dm(IMX8MM_CLK_IPG_ROOT, |
| 349 | imx_clk_divider2("ipg_root", "ahb", base + 0x9080, 0, 1)); |
| 350 | |
| 351 | clk_dm(IMX8MM_CLK_ENET_AXI, |
| 352 | imx8m_clk_composite("enet_axi", imx8mm_enet_axi_sels, |
| 353 | base + 0x8880)); |
| 354 | clk_dm(IMX8MM_CLK_NAND_USDHC_BUS, |
| 355 | imx8m_clk_composite_critical("nand_usdhc_bus", |
| 356 | imx8mm_nand_usdhc_sels, |
| 357 | base + 0x8900)); |
| 358 | |
| 359 | /* IP */ |
| 360 | clk_dm(IMX8MM_CLK_USDHC1, |
| 361 | imx8m_clk_composite("usdhc1", imx8mm_usdhc1_sels, |
| 362 | base + 0xac00)); |
| 363 | clk_dm(IMX8MM_CLK_USDHC2, |
| 364 | imx8m_clk_composite("usdhc2", imx8mm_usdhc2_sels, |
| 365 | base + 0xac80)); |
| 366 | clk_dm(IMX8MM_CLK_I2C1, |
| 367 | imx8m_clk_composite("i2c1", imx8mm_i2c1_sels, base + 0xad00)); |
| 368 | clk_dm(IMX8MM_CLK_I2C2, |
| 369 | imx8m_clk_composite("i2c2", imx8mm_i2c2_sels, base + 0xad80)); |
| 370 | clk_dm(IMX8MM_CLK_I2C3, |
| 371 | imx8m_clk_composite("i2c3", imx8mm_i2c3_sels, base + 0xae00)); |
| 372 | clk_dm(IMX8MM_CLK_I2C4, |
| 373 | imx8m_clk_composite("i2c4", imx8mm_i2c4_sels, base + 0xae80)); |
| 374 | clk_dm(IMX8MM_CLK_WDOG, |
| 375 | imx8m_clk_composite("wdog", imx8mm_wdog_sels, base + 0xb900)); |
| 376 | clk_dm(IMX8MM_CLK_USDHC3, |
| 377 | imx8m_clk_composite("usdhc3", imx8mm_usdhc3_sels, |
| 378 | base + 0xbc80)); |
Peng Fan | 2dff879 | 2020-06-27 15:49:28 +0800 | [diff] [blame^] | 379 | clk_dm(IMX8MM_CLK_QSPI, |
| 380 | imx8m_clk_composite("qspi", imx8mm_qspi_sels, base + 0xab80)); |
Peng Fan | 525c876 | 2019-08-19 07:54:04 +0000 | [diff] [blame] | 381 | |
| 382 | clk_dm(IMX8MM_CLK_I2C1_ROOT, |
| 383 | imx_clk_gate4("i2c1_root_clk", "i2c1", base + 0x4170, 0)); |
| 384 | clk_dm(IMX8MM_CLK_I2C2_ROOT, |
| 385 | imx_clk_gate4("i2c2_root_clk", "i2c2", base + 0x4180, 0)); |
| 386 | clk_dm(IMX8MM_CLK_I2C3_ROOT, |
| 387 | imx_clk_gate4("i2c3_root_clk", "i2c3", base + 0x4190, 0)); |
| 388 | clk_dm(IMX8MM_CLK_I2C4_ROOT, |
| 389 | imx_clk_gate4("i2c4_root_clk", "i2c4", base + 0x41a0, 0)); |
| 390 | clk_dm(IMX8MM_CLK_OCOTP_ROOT, |
| 391 | imx_clk_gate4("ocotp_root_clk", "ipg_root", base + 0x4220, 0)); |
| 392 | clk_dm(IMX8MM_CLK_USDHC1_ROOT, |
| 393 | imx_clk_gate4("usdhc1_root_clk", "usdhc1", base + 0x4510, 0)); |
| 394 | clk_dm(IMX8MM_CLK_USDHC2_ROOT, |
| 395 | imx_clk_gate4("usdhc2_root_clk", "usdhc2", base + 0x4520, 0)); |
| 396 | clk_dm(IMX8MM_CLK_WDOG1_ROOT, |
| 397 | imx_clk_gate4("wdog1_root_clk", "wdog", base + 0x4530, 0)); |
| 398 | clk_dm(IMX8MM_CLK_WDOG2_ROOT, |
| 399 | imx_clk_gate4("wdog2_root_clk", "wdog", base + 0x4540, 0)); |
| 400 | clk_dm(IMX8MM_CLK_WDOG3_ROOT, |
| 401 | imx_clk_gate4("wdog3_root_clk", "wdog", base + 0x4550, 0)); |
| 402 | clk_dm(IMX8MM_CLK_USDHC3_ROOT, |
| 403 | imx_clk_gate4("usdhc3_root_clk", "usdhc3", base + 0x45e0, 0)); |
Peng Fan | 2dff879 | 2020-06-27 15:49:28 +0800 | [diff] [blame^] | 404 | clk_dm(IMX8MM_CLK_QSPI_ROOT, |
| 405 | imx_clk_gate4("qspi_root_clk", "qspi", base + 0x42f0, 0)); |
Peng Fan | 525c876 | 2019-08-19 07:54:04 +0000 | [diff] [blame] | 406 | |
Peng Fan | ee5515d | 2019-10-22 03:29:48 +0000 | [diff] [blame] | 407 | /* clks not needed in SPL stage */ |
| 408 | #ifndef CONFIG_SPL_BUILD |
| 409 | clk_dm(IMX8MM_CLK_ENET_REF, |
| 410 | imx8m_clk_composite("enet_ref", imx8mm_enet_ref_sels, |
| 411 | base + 0xa980)); |
| 412 | clk_dm(IMX8MM_CLK_ENET_TIMER, |
| 413 | imx8m_clk_composite("enet_timer", imx8mm_enet_timer_sels, |
| 414 | base + 0xaa00)); |
| 415 | clk_dm(IMX8MM_CLK_ENET_PHY_REF, |
| 416 | imx8m_clk_composite("enet_phy", imx8mm_enet_phy_sels, |
| 417 | base + 0xaa80)); |
| 418 | clk_dm(IMX8MM_CLK_ENET1_ROOT, |
| 419 | imx_clk_gate4("enet1_root_clk", "enet_axi", |
| 420 | base + 0x40a0, 0)); |
| 421 | #endif |
| 422 | |
Peng Fan | 525c876 | 2019-08-19 07:54:04 +0000 | [diff] [blame] | 423 | #ifdef CONFIG_SPL_BUILD |
| 424 | struct clk *clkp, *clkp1; |
| 425 | |
| 426 | clk_get_by_id(IMX8MM_CLK_WDOG1_ROOT, &clkp); |
| 427 | clk_enable(clkp); |
| 428 | clk_get_by_id(IMX8MM_CLK_WDOG2_ROOT, &clkp); |
| 429 | clk_enable(clkp); |
| 430 | clk_get_by_id(IMX8MM_CLK_WDOG3_ROOT, &clkp); |
| 431 | clk_enable(clkp); |
| 432 | |
| 433 | /* Configure SYS_PLL3 to 750MHz */ |
| 434 | clk_get_by_id(IMX8MM_SYS_PLL3, &clkp); |
| 435 | clk_set_rate(clkp, 750000000UL); |
| 436 | clk_enable(clkp); |
| 437 | |
| 438 | /* Configure ARM to sys_pll2_500m */ |
| 439 | clk_get_by_id(IMX8MM_CLK_A53_SRC, &clkp); |
| 440 | clk_get_by_id(IMX8MM_SYS_PLL2_OUT, &clkp1); |
| 441 | clk_enable(clkp1); |
| 442 | clk_get_by_id(IMX8MM_SYS_PLL2_500M, &clkp1); |
| 443 | clk_set_parent(clkp, clkp1); |
| 444 | |
| 445 | /* Configure ARM PLL to 1.2GHz */ |
| 446 | clk_get_by_id(IMX8MM_ARM_PLL, &clkp1); |
| 447 | clk_set_rate(clkp1, 1200000000UL); |
| 448 | clk_get_by_id(IMX8MM_ARM_PLL_OUT, &clkp1); |
| 449 | clk_enable(clkp1); |
| 450 | clk_set_parent(clkp, clkp1); |
| 451 | |
| 452 | /* Configure DIV to 1.2GHz */ |
| 453 | clk_get_by_id(IMX8MM_CLK_A53_DIV, &clkp1); |
| 454 | clk_set_rate(clkp1, 1200000000UL); |
| 455 | #endif |
| 456 | |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | static const struct udevice_id imx8mm_clk_ids[] = { |
| 461 | { .compatible = "fsl,imx8mm-ccm" }, |
| 462 | { }, |
| 463 | }; |
| 464 | |
| 465 | U_BOOT_DRIVER(imx8mm_clk) = { |
| 466 | .name = "clk_imx8mm", |
| 467 | .id = UCLASS_CLK, |
| 468 | .of_match = imx8mm_clk_ids, |
| 469 | .ops = &imx8mm_clk_ops, |
| 470 | .probe = imx8mm_clk_probe, |
| 471 | .flags = DM_FLAG_PRE_RELOC, |
| 472 | }; |