Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2020 NXP |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 7 | #include <command.h> |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 8 | #include <div64.h> |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 9 | #include <asm/arch/imx-regs.h> |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <errno.h> |
| 12 | #include <asm/arch/clock.h> |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 13 | #include <asm/arch/pcc.h> |
| 14 | #include <asm/arch/cgc.h> |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 15 | #include <asm/arch/sys_proto.h> |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 16 | #include <asm/global_data.h> |
| 17 | #include <linux/delay.h> |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 21 | #define PLL_USB_EN_USB_CLKS_MASK (0x01 << 6) |
| 22 | #define PLL_USB_PWR_MASK (0x01 << 12) |
| 23 | #define PLL_USB_ENABLE_MASK (0x01 << 13) |
| 24 | #define PLL_USB_BYPASS_MASK (0x01 << 16) |
| 25 | #define PLL_USB_REG_ENABLE_MASK (0x01 << 21) |
| 26 | #define PLL_USB_DIV_SEL_MASK (0x07 << 22) |
| 27 | #define PLL_USB_LOCK_MASK (0x01 << 31) |
| 28 | #define PCC5_LPDDR4_ADDR 0x2da70108 |
| 29 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 30 | static void lpuart_set_clk(u32 index, enum cgc_clk clk) |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 31 | { |
| 32 | const u32 lpuart_pcc_slots[] = { |
| 33 | LPUART4_PCC3_SLOT, |
| 34 | LPUART5_PCC3_SLOT, |
| 35 | LPUART6_PCC4_SLOT, |
| 36 | LPUART7_PCC4_SLOT, |
| 37 | }; |
| 38 | |
| 39 | const u32 lpuart_pcc[] = { |
| 40 | 3, 3, 4, 4, |
| 41 | }; |
| 42 | |
| 43 | if (index > 3) |
| 44 | return; |
| 45 | |
| 46 | pcc_clock_enable(lpuart_pcc[index], lpuart_pcc_slots[index], false); |
| 47 | pcc_clock_sel(lpuart_pcc[index], lpuart_pcc_slots[index], clk); |
| 48 | pcc_clock_enable(lpuart_pcc[index], lpuart_pcc_slots[index], true); |
| 49 | |
| 50 | pcc_reset_peripheral(lpuart_pcc[index], lpuart_pcc_slots[index], false); |
| 51 | } |
| 52 | |
| 53 | static void init_clk_lpuart(void) |
| 54 | { |
| 55 | u32 index = 0, i; |
| 56 | |
| 57 | const u32 lpuart_array[] = { |
| 58 | LPUART4_RBASE, |
| 59 | LPUART5_RBASE, |
| 60 | LPUART6_RBASE, |
| 61 | LPUART7_RBASE, |
| 62 | }; |
| 63 | |
| 64 | for (i = 0; i < 4; i++) { |
| 65 | if (lpuart_array[i] == LPUART_BASE) { |
| 66 | index = i; |
| 67 | break; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | lpuart_set_clk(index, SOSC_DIV2); |
| 72 | } |
| 73 | |
| 74 | void init_clk_fspi(int index) |
| 75 | { |
| 76 | pcc_clock_enable(4, FLEXSPI2_PCC4_SLOT, false); |
| 77 | pcc_clock_sel(4, FLEXSPI2_PCC4_SLOT, PLL3_PFD2_DIV1); |
| 78 | pcc_clock_div_config(4, FLEXSPI2_PCC4_SLOT, false, 8); |
| 79 | pcc_clock_enable(4, FLEXSPI2_PCC4_SLOT, true); |
| 80 | pcc_reset_peripheral(4, FLEXSPI2_PCC4_SLOT, false); |
| 81 | } |
| 82 | |
| 83 | void setclkout_ddr(void) |
| 84 | { |
| 85 | writel(0x12800000, 0x2DA60020); |
| 86 | writel(0xa00, 0x298C0000); /* PTD0 */ |
| 87 | } |
| 88 | |
| 89 | void ddrphy_pll_lock(void) |
| 90 | { |
| 91 | writel(0x00011542, 0x2E065964); |
| 92 | writel(0x00011542, 0x2E06586C); |
| 93 | |
| 94 | writel(0x00000B01, 0x2E062000); |
| 95 | writel(0x00000B01, 0x2E060000); |
| 96 | } |
| 97 | |
| 98 | void init_clk_ddr(void) |
| 99 | { |
Ye Li | 328f201 | 2021-10-29 09:46:26 +0800 | [diff] [blame] | 100 | /* disable the ddr pcc */ |
| 101 | writel(0xc0000000, PCC5_LPDDR4_ADDR); |
| 102 | |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 103 | /* enable pll4 and ddrclk*/ |
| 104 | cgc2_pll4_init(); |
| 105 | cgc2_ddrclk_config(1, 1); |
| 106 | |
| 107 | /* enable ddr pcc */ |
| 108 | writel(0xd0000000, PCC5_LPDDR4_ADDR); |
| 109 | |
| 110 | /* for debug */ |
| 111 | /* setclkout_ddr(); */ |
| 112 | } |
| 113 | |
| 114 | int set_ddr_clk(u32 phy_freq_mhz) |
| 115 | { |
| 116 | debug("%s %u\n", __func__, phy_freq_mhz); |
| 117 | |
| 118 | if (phy_freq_mhz == 48) { |
| 119 | writel(0x90000000, PCC5_LPDDR4_ADDR); /* disable ddr pcc */ |
| 120 | cgc2_ddrclk_config(2, 0); /* 24Mhz DDR clock */ |
| 121 | writel(0xd0000000, PCC5_LPDDR4_ADDR); /* enable ddr pcc */ |
| 122 | } else if (phy_freq_mhz == 384) { |
| 123 | writel(0x90000000, PCC5_LPDDR4_ADDR); /* disable ddr pcc */ |
| 124 | cgc2_ddrclk_config(0, 0); /* 192Mhz DDR clock */ |
| 125 | writel(0xd0000000, PCC5_LPDDR4_ADDR); /* enable ddr pcc */ |
| 126 | } else if (phy_freq_mhz == 528) { |
| 127 | writel(0x90000000, PCC5_LPDDR4_ADDR); /* disable ddr pcc */ |
| 128 | cgc2_ddrclk_config(4, 1); /* 264Mhz DDR clock */ |
| 129 | writel(0xd0000000, PCC5_LPDDR4_ADDR); /* enable ddr pcc */ |
| 130 | } else if (phy_freq_mhz == 264) { |
| 131 | writel(0x90000000, PCC5_LPDDR4_ADDR); /* disable ddr pcc */ |
| 132 | cgc2_ddrclk_config(4, 3); /* 132Mhz DDR clock */ |
| 133 | writel(0xd0000000, PCC5_LPDDR4_ADDR); /* enable ddr pcc */ |
| 134 | } else if (phy_freq_mhz == 192) { |
| 135 | writel(0x90000000, PCC5_LPDDR4_ADDR); /* disable ddr pcc */ |
| 136 | cgc2_ddrclk_config(0, 1); /* 96Mhz DDR clock */ |
| 137 | writel(0xd0000000, PCC5_LPDDR4_ADDR); /* enable ddr pcc */ |
| 138 | } else if (phy_freq_mhz == 96) { |
| 139 | writel(0x90000000, PCC5_LPDDR4_ADDR); /* disable ddr pcc */ |
| 140 | cgc2_ddrclk_config(0, 3); /* 48Mhz DDR clock */ |
| 141 | writel(0xd0000000, PCC5_LPDDR4_ADDR); /* enable ddr pcc */ |
| 142 | } else { |
| 143 | printf("ddr phy clk %uMhz is not supported\n", phy_freq_mhz); |
| 144 | return -EINVAL; |
| 145 | } |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 150 | void clock_init(void) |
| 151 | { |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 152 | cgc1_soscdiv_init(); |
| 153 | cgc1_init_core_clk(); |
| 154 | |
| 155 | init_clk_lpuart(); |
| 156 | |
| 157 | pcc_clock_enable(4, SDHC0_PCC4_SLOT, false); |
| 158 | pcc_clock_sel(4, SDHC0_PCC4_SLOT, PLL3_PFD1_DIV2); |
| 159 | pcc_clock_enable(4, SDHC0_PCC4_SLOT, true); |
| 160 | pcc_reset_peripheral(4, SDHC0_PCC4_SLOT, false); |
| 161 | |
| 162 | pcc_clock_enable(4, SDHC1_PCC4_SLOT, false); |
| 163 | pcc_clock_sel(4, SDHC1_PCC4_SLOT, PLL3_PFD2_DIV1); |
| 164 | pcc_clock_enable(4, SDHC1_PCC4_SLOT, true); |
| 165 | pcc_reset_peripheral(4, SDHC1_PCC4_SLOT, false); |
| 166 | |
| 167 | pcc_clock_enable(4, SDHC2_PCC4_SLOT, false); |
| 168 | pcc_clock_sel(4, SDHC2_PCC4_SLOT, PLL3_PFD2_DIV1); |
| 169 | pcc_clock_enable(4, SDHC2_PCC4_SLOT, true); |
| 170 | pcc_reset_peripheral(4, SDHC2_PCC4_SLOT, false); |
| 171 | |
| 172 | /* Enable upower mu1 clk */ |
| 173 | pcc_clock_enable(3, UPOWER_PCC3_SLOT, true); |
| 174 | |
| 175 | /* |
| 176 | * Enable clock division |
| 177 | * TODO: may not needed after ROM ready. |
| 178 | */ |
| 179 | } |
| 180 | |
| 181 | #if IS_ENABLED(CONFIG_SYS_I2C_IMX_LPI2C) |
| 182 | int enable_i2c_clk(unsigned char enable, u32 i2c_num) |
| 183 | { |
| 184 | /* Set parent to FIRC DIV2 clock */ |
| 185 | const u32 lpi2c_pcc_clks[] = { |
| 186 | LPI2C4_PCC3_SLOT << 8 | 3, |
| 187 | LPI2C5_PCC3_SLOT << 8 | 3, |
| 188 | LPI2C6_PCC4_SLOT << 8 | 4, |
| 189 | LPI2C7_PCC4_SLOT << 8 | 4, |
| 190 | }; |
| 191 | |
Ye Li | 27666ca | 2021-10-29 09:46:21 +0800 | [diff] [blame] | 192 | if (i2c_num == 0) |
| 193 | return 0; |
| 194 | |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 195 | if (i2c_num < 4 || i2c_num > 7) |
| 196 | return -EINVAL; |
| 197 | |
| 198 | if (enable) { |
| 199 | pcc_clock_enable(lpi2c_pcc_clks[i2c_num - 4] & 0xff, |
| 200 | lpi2c_pcc_clks[i2c_num - 4] >> 8, false); |
| 201 | pcc_clock_sel(lpi2c_pcc_clks[i2c_num - 4] & 0xff, |
| 202 | lpi2c_pcc_clks[i2c_num - 4] >> 8, SOSC_DIV2); |
| 203 | pcc_clock_enable(lpi2c_pcc_clks[i2c_num - 4] & 0xff, |
| 204 | lpi2c_pcc_clks[i2c_num - 4] >> 8, true); |
| 205 | pcc_reset_peripheral(lpi2c_pcc_clks[i2c_num - 4] & 0xff, |
| 206 | lpi2c_pcc_clks[i2c_num - 4] >> 8, false); |
| 207 | } else { |
| 208 | pcc_clock_enable(lpi2c_pcc_clks[i2c_num - 4] & 0xff, |
| 209 | lpi2c_pcc_clks[i2c_num - 4] >> 8, false); |
| 210 | } |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | u32 imx_get_i2cclk(u32 i2c_num) |
| 215 | { |
| 216 | const u32 lpi2c_pcc_clks[] = { |
| 217 | LPI2C4_PCC3_SLOT << 8 | 3, |
| 218 | LPI2C5_PCC3_SLOT << 8 | 3, |
| 219 | LPI2C6_PCC4_SLOT << 8 | 4, |
| 220 | LPI2C7_PCC4_SLOT << 8 | 4, |
| 221 | }; |
| 222 | |
Ye Li | 27666ca | 2021-10-29 09:46:21 +0800 | [diff] [blame] | 223 | if (i2c_num == 0) |
| 224 | return 24000000; |
| 225 | |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 226 | if (i2c_num < 4 || i2c_num > 7) |
| 227 | return 0; |
| 228 | |
| 229 | return pcc_clock_get_rate(lpi2c_pcc_clks[i2c_num - 4] & 0xff, |
| 230 | lpi2c_pcc_clks[i2c_num - 4] >> 8); |
| 231 | } |
| 232 | #endif |
| 233 | |
| 234 | void enable_usboh3_clk(unsigned char enable) |
| 235 | { |
| 236 | if (enable) { |
| 237 | pcc_clock_enable(4, USB0_PCC4_SLOT, true); |
| 238 | pcc_clock_enable(4, USBPHY_PCC4_SLOT, true); |
| 239 | pcc_reset_peripheral(4, USB0_PCC4_SLOT, false); |
| 240 | pcc_reset_peripheral(4, USBPHY_PCC4_SLOT, false); |
| 241 | |
| 242 | #ifdef CONFIG_USB_MAX_CONTROLLER_COUNT |
| 243 | if (CONFIG_USB_MAX_CONTROLLER_COUNT > 1) { |
| 244 | pcc_clock_enable(4, USB1_PCC4_SLOT, true); |
| 245 | pcc_clock_enable(4, USB1PHY_PCC4_SLOT, true); |
| 246 | pcc_reset_peripheral(4, USB1_PCC4_SLOT, false); |
| 247 | pcc_reset_peripheral(4, USB1PHY_PCC4_SLOT, false); |
| 248 | } |
| 249 | #endif |
| 250 | |
| 251 | pcc_clock_enable(4, USB_XBAR_PCC4_SLOT, true); |
| 252 | } else { |
| 253 | pcc_clock_enable(4, USB0_PCC4_SLOT, false); |
| 254 | pcc_clock_enable(4, USB1_PCC4_SLOT, false); |
| 255 | pcc_clock_enable(4, USBPHY_PCC4_SLOT, false); |
| 256 | pcc_clock_enable(4, USB1PHY_PCC4_SLOT, false); |
| 257 | pcc_clock_enable(4, USB_XBAR_PCC4_SLOT, false); |
| 258 | } |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 259 | } |
| 260 | |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 261 | int enable_usb_pll(ulong usb_phy_base) |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 262 | { |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 263 | u32 sosc_rate; |
| 264 | s32 timeout = 1000000; |
| 265 | |
| 266 | struct usbphy_regs *usbphy = |
| 267 | (struct usbphy_regs *)usb_phy_base; |
| 268 | |
| 269 | sosc_rate = cgc1_sosc_div(SOSC); |
| 270 | if (!sosc_rate) |
| 271 | return -EPERM; |
| 272 | |
| 273 | if (!(readl(&usbphy->usb1_pll_480_ctrl) & PLL_USB_LOCK_MASK)) { |
| 274 | writel(0x1c00000, &usbphy->usb1_pll_480_ctrl_clr); |
| 275 | |
| 276 | switch (sosc_rate) { |
| 277 | case 24000000: |
| 278 | writel(0xc00000, &usbphy->usb1_pll_480_ctrl_set); |
| 279 | break; |
| 280 | |
| 281 | case 30000000: |
| 282 | writel(0x800000, &usbphy->usb1_pll_480_ctrl_set); |
| 283 | break; |
| 284 | |
| 285 | case 19200000: |
| 286 | writel(0x1400000, &usbphy->usb1_pll_480_ctrl_set); |
| 287 | break; |
| 288 | |
| 289 | default: |
| 290 | writel(0xc00000, &usbphy->usb1_pll_480_ctrl_set); |
| 291 | break; |
| 292 | } |
| 293 | |
| 294 | /* Enable the regulator first */ |
| 295 | writel(PLL_USB_REG_ENABLE_MASK, |
| 296 | &usbphy->usb1_pll_480_ctrl_set); |
| 297 | |
| 298 | /* Wait at least 15us */ |
| 299 | udelay(15); |
| 300 | |
| 301 | /* Enable the power */ |
| 302 | writel(PLL_USB_PWR_MASK, &usbphy->usb1_pll_480_ctrl_set); |
| 303 | |
| 304 | /* Wait lock */ |
| 305 | while (timeout--) { |
| 306 | if (readl(&usbphy->usb1_pll_480_ctrl) & |
| 307 | PLL_USB_LOCK_MASK) |
| 308 | break; |
| 309 | } |
| 310 | |
| 311 | if (timeout <= 0) { |
| 312 | /* If timeout, we power down the pll */ |
| 313 | writel(PLL_USB_PWR_MASK, |
| 314 | &usbphy->usb1_pll_480_ctrl_clr); |
| 315 | return -ETIME; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | /* Clear the bypass */ |
| 320 | writel(PLL_USB_BYPASS_MASK, &usbphy->usb1_pll_480_ctrl_clr); |
| 321 | |
| 322 | /* Enable the PLL clock out to USB */ |
| 323 | writel((PLL_USB_EN_USB_CLKS_MASK | PLL_USB_ENABLE_MASK), |
| 324 | &usbphy->usb1_pll_480_ctrl_set); |
| 325 | |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 326 | return 0; |
| 327 | } |
| 328 | |
Ye Li | 3d3dfb0 | 2021-10-29 09:46:19 +0800 | [diff] [blame] | 329 | void enable_mipi_dsi_clk(unsigned char enable) |
| 330 | { |
| 331 | if (enable) { |
| 332 | pcc_clock_enable(5, DSI_PCC5_SLOT, false); |
Ye Li | cb7e375 | 2021-10-29 09:46:27 +0800 | [diff] [blame] | 333 | pcc_reset_peripheral(5, DSI_PCC5_SLOT, true); |
Ye Li | 3d3dfb0 | 2021-10-29 09:46:19 +0800 | [diff] [blame] | 334 | pcc_clock_sel(5, DSI_PCC5_SLOT, PLL4_PFD3_DIV2); |
| 335 | pcc_clock_div_config(5, DSI_PCC5_SLOT, 0, 6); |
| 336 | pcc_clock_enable(5, DSI_PCC5_SLOT, true); |
| 337 | pcc_reset_peripheral(5, DSI_PCC5_SLOT, false); |
| 338 | } else { |
| 339 | pcc_clock_enable(5, DSI_PCC5_SLOT, false); |
| 340 | pcc_reset_peripheral(5, DSI_PCC5_SLOT, true); |
| 341 | } |
| 342 | } |
| 343 | |
Alice Guo | 23ee0e1 | 2021-10-29 09:46:29 +0800 | [diff] [blame^] | 344 | void enable_adc1_clk(bool enable) |
| 345 | { |
| 346 | if (enable) { |
| 347 | pcc_clock_enable(1, ADC1_PCC1_SLOT, false); |
| 348 | pcc_clock_sel(1, ADC1_PCC1_SLOT, CM33_BUSCLK); |
| 349 | pcc_clock_enable(1, ADC1_PCC1_SLOT, true); |
| 350 | pcc_reset_peripheral(1, ADC1_PCC1_SLOT, false); |
| 351 | } else { |
| 352 | pcc_clock_enable(1, ADC1_PCC1_SLOT, false); |
| 353 | } |
| 354 | } |
| 355 | |
Ye Li | cb7e375 | 2021-10-29 09:46:27 +0800 | [diff] [blame] | 356 | void reset_lcdclk(void) |
| 357 | { |
| 358 | /* Disable clock and reset dcnano*/ |
| 359 | pcc_clock_enable(5, DCNANO_PCC5_SLOT, false); |
| 360 | pcc_reset_peripheral(5, DCNANO_PCC5_SLOT, true); |
| 361 | } |
| 362 | |
Ye Li | 3d3dfb0 | 2021-10-29 09:46:19 +0800 | [diff] [blame] | 363 | void mxs_set_lcdclk(u32 base_addr, u32 freq_in_khz) |
| 364 | { |
| 365 | u8 pcd, best_pcd = 0; |
| 366 | u32 frac, rate, parent_rate, pfd, div; |
| 367 | u32 best_pfd = 0, best_frac = 0, best = 0, best_div = 0; |
| 368 | u32 pll4_rate; |
| 369 | |
| 370 | pcc_clock_enable(5, DCNANO_PCC5_SLOT, false); |
| 371 | |
| 372 | pll4_rate = cgc_clk_get_rate(PLL4); |
| 373 | pll4_rate = pll4_rate / 1000; /* Change to khz*/ |
| 374 | |
| 375 | debug("PLL4 rate %ukhz\n", pll4_rate); |
| 376 | |
| 377 | for (pfd = 12; pfd <= 35; pfd++) { |
| 378 | parent_rate = pll4_rate; |
| 379 | parent_rate = parent_rate * 18 / pfd; |
| 380 | |
| 381 | for (div = 1; div <= 64; div++) { |
| 382 | parent_rate = parent_rate / div; |
| 383 | |
| 384 | for (pcd = 0; pcd < 8; pcd++) { |
| 385 | for (frac = 0; frac < 2; frac++) { |
| 386 | if (pcd == 0 && frac == 1) |
| 387 | continue; |
| 388 | |
| 389 | rate = parent_rate * (frac + 1) / (pcd + 1); |
| 390 | if (rate > freq_in_khz) |
| 391 | continue; |
| 392 | |
| 393 | if (best == 0 || rate > best) { |
| 394 | best = rate; |
| 395 | best_pfd = pfd; |
| 396 | best_frac = frac; |
| 397 | best_pcd = pcd; |
| 398 | best_div = div; |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | if (best == 0) { |
| 406 | printf("Can't find parent clock for LCDIF, target freq: %u\n", freq_in_khz); |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | debug("LCD target rate %ukhz, best rate %ukhz, frac %u, pcd %u, best_pfd %u, best_div %u\n", |
| 411 | freq_in_khz, best, best_frac, best_pcd, best_pfd, best_div); |
| 412 | |
| 413 | cgc2_pll4_pfd_config(PLL4_PFD0, best_pfd); |
| 414 | cgc2_pll4_pfddiv_config(PLL4_PFD0_DIV1, best_div - 1); |
| 415 | |
| 416 | pcc_clock_sel(5, DCNANO_PCC5_SLOT, PLL4_PFD0_DIV1); |
| 417 | pcc_clock_div_config(5, DCNANO_PCC5_SLOT, best_frac, best_pcd + 1); |
| 418 | pcc_clock_enable(5, DCNANO_PCC5_SLOT, true); |
| 419 | pcc_reset_peripheral(5, DCNANO_PCC5_SLOT, false); |
| 420 | } |
| 421 | |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 422 | u32 mxc_get_clock(enum mxc_clock clk) |
| 423 | { |
| 424 | switch (clk) { |
| 425 | case MXC_ESDHC_CLK: |
| 426 | return pcc_clock_get_rate(4, SDHC0_PCC4_SLOT); |
| 427 | case MXC_ESDHC2_CLK: |
| 428 | return pcc_clock_get_rate(4, SDHC1_PCC4_SLOT); |
| 429 | case MXC_ESDHC3_CLK: |
| 430 | return pcc_clock_get_rate(4, SDHC2_PCC4_SLOT); |
| 431 | case MXC_ARM_CLK: |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 432 | return cgc_clk_get_rate(PLL2); |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 433 | default: |
| 434 | return 0; |
| 435 | } |
| 436 | } |
| 437 | |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 438 | u32 get_lpuart_clk(void) |
| 439 | { |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 440 | int index = 0; |
| 441 | |
| 442 | const u32 lpuart_array[] = { |
| 443 | LPUART4_RBASE, |
| 444 | LPUART5_RBASE, |
| 445 | LPUART6_RBASE, |
| 446 | LPUART7_RBASE, |
| 447 | }; |
| 448 | |
| 449 | const u32 lpuart_pcc_slots[] = { |
| 450 | LPUART4_PCC3_SLOT, |
| 451 | LPUART5_PCC3_SLOT, |
| 452 | LPUART6_PCC4_SLOT, |
| 453 | LPUART7_PCC4_SLOT, |
| 454 | }; |
| 455 | |
| 456 | const u32 lpuart_pcc[] = { |
| 457 | 3, 3, 4, 4, |
| 458 | }; |
| 459 | |
| 460 | for (index = 0; index < 4; index++) { |
| 461 | if (lpuart_array[index] == LPUART_BASE) |
| 462 | break; |
| 463 | } |
| 464 | |
| 465 | if (index > 3) |
| 466 | return 0; |
| 467 | |
| 468 | return pcc_clock_get_rate(lpuart_pcc[index], lpuart_pcc_slots[index]); |
| 469 | } |
| 470 | |
| 471 | #ifndef CONFIG_SPL_BUILD |
| 472 | /* |
| 473 | * Dump some core clockes. |
| 474 | */ |
| 475 | int do_mx8ulp_showclocks(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) |
| 476 | { |
| 477 | printf("SDHC0 %8d MHz\n", pcc_clock_get_rate(4, SDHC0_PCC4_SLOT) / 1000000); |
| 478 | printf("SDHC1 %8d MHz\n", pcc_clock_get_rate(4, SDHC1_PCC4_SLOT) / 1000000); |
| 479 | printf("SDHC2 %8d MHz\n", pcc_clock_get_rate(4, SDHC2_PCC4_SLOT) / 1000000); |
| 480 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 481 | printf("SOSC %8d MHz\n", cgc_clk_get_rate(SOSC) / 1000000); |
| 482 | printf("FRO %8d MHz\n", cgc_clk_get_rate(FRO) / 1000000); |
| 483 | printf("PLL2 %8d MHz\n", cgc_clk_get_rate(PLL2) / 1000000); |
| 484 | printf("PLL3 %8d MHz\n", cgc_clk_get_rate(PLL3) / 1000000); |
| 485 | printf("PLL3_VCODIV %8d MHz\n", cgc_clk_get_rate(PLL3_VCODIV) / 1000000); |
| 486 | printf("PLL3_PFD0 %8d MHz\n", cgc_clk_get_rate(PLL3_PFD0) / 1000000); |
| 487 | printf("PLL3_PFD1 %8d MHz\n", cgc_clk_get_rate(PLL3_PFD1) / 1000000); |
| 488 | printf("PLL3_PFD2 %8d MHz\n", cgc_clk_get_rate(PLL3_PFD2) / 1000000); |
| 489 | printf("PLL3_PFD3 %8d MHz\n", cgc_clk_get_rate(PLL3_PFD3) / 1000000); |
| 490 | |
| 491 | printf("PLL4_PFD0 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD0) / 1000000); |
| 492 | printf("PLL4_PFD1 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD1) / 1000000); |
| 493 | printf("PLL4_PFD2 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD2) / 1000000); |
| 494 | printf("PLL4_PFD3 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD3) / 1000000); |
| 495 | |
| 496 | printf("PLL4_PFD0_DIV1 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD0_DIV1) / 1000000); |
| 497 | printf("PLL4_PFD0_DIV2 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD0_DIV2) / 1000000); |
| 498 | printf("PLL4_PFD1_DIV1 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD1_DIV1) / 1000000); |
| 499 | printf("PLL4_PFD1_DIV2 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD1_DIV2) / 1000000); |
| 500 | |
| 501 | printf("PLL4_PFD2_DIV1 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD2_DIV1) / 1000000); |
| 502 | printf("PLL4_PFD2_DIV2 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD2_DIV2) / 1000000); |
| 503 | printf("PLL4_PFD3_DIV1 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD3_DIV1) / 1000000); |
| 504 | printf("PLL4_PFD3_DIV2 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD3_DIV2) / 1000000); |
| 505 | |
| 506 | printf("LPAV_AXICLK %8d MHz\n", cgc_clk_get_rate(LPAV_AXICLK) / 1000000); |
| 507 | printf("LPAV_AHBCLK %8d MHz\n", cgc_clk_get_rate(LPAV_AHBCLK) / 1000000); |
| 508 | printf("LPAV_BUSCLK %8d MHz\n", cgc_clk_get_rate(LPAV_BUSCLK) / 1000000); |
| 509 | printf("NIC_APCLK %8d MHz\n", cgc_clk_get_rate(NIC_APCLK) / 1000000); |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 510 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 511 | printf("NIC_PERCLK %8d MHz\n", cgc_clk_get_rate(NIC_PERCLK) / 1000000); |
| 512 | printf("XBAR_APCLK %8d MHz\n", cgc_clk_get_rate(XBAR_APCLK) / 1000000); |
| 513 | printf("XBAR_BUSCLK %8d MHz\n", cgc_clk_get_rate(XBAR_BUSCLK) / 1000000); |
| 514 | printf("AD_SLOWCLK %8d MHz\n", cgc_clk_get_rate(AD_SLOWCLK) / 1000000); |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 515 | return 0; |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 516 | } |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 517 | |
| 518 | U_BOOT_CMD( |
| 519 | clocks, CONFIG_SYS_MAXARGS, 1, do_mx8ulp_showclocks, |
| 520 | "display clocks", |
| 521 | "" |
| 522 | ); |
| 523 | #endif |