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); |
| 333 | pcc_clock_sel(5, DSI_PCC5_SLOT, PLL4_PFD3_DIV2); |
| 334 | pcc_clock_div_config(5, DSI_PCC5_SLOT, 0, 6); |
| 335 | pcc_clock_enable(5, DSI_PCC5_SLOT, true); |
| 336 | pcc_reset_peripheral(5, DSI_PCC5_SLOT, false); |
| 337 | } else { |
| 338 | pcc_clock_enable(5, DSI_PCC5_SLOT, false); |
| 339 | pcc_reset_peripheral(5, DSI_PCC5_SLOT, true); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | void mxs_set_lcdclk(u32 base_addr, u32 freq_in_khz) |
| 344 | { |
| 345 | u8 pcd, best_pcd = 0; |
| 346 | u32 frac, rate, parent_rate, pfd, div; |
| 347 | u32 best_pfd = 0, best_frac = 0, best = 0, best_div = 0; |
| 348 | u32 pll4_rate; |
| 349 | |
| 350 | pcc_clock_enable(5, DCNANO_PCC5_SLOT, false); |
| 351 | |
| 352 | pll4_rate = cgc_clk_get_rate(PLL4); |
| 353 | pll4_rate = pll4_rate / 1000; /* Change to khz*/ |
| 354 | |
| 355 | debug("PLL4 rate %ukhz\n", pll4_rate); |
| 356 | |
| 357 | for (pfd = 12; pfd <= 35; pfd++) { |
| 358 | parent_rate = pll4_rate; |
| 359 | parent_rate = parent_rate * 18 / pfd; |
| 360 | |
| 361 | for (div = 1; div <= 64; div++) { |
| 362 | parent_rate = parent_rate / div; |
| 363 | |
| 364 | for (pcd = 0; pcd < 8; pcd++) { |
| 365 | for (frac = 0; frac < 2; frac++) { |
| 366 | if (pcd == 0 && frac == 1) |
| 367 | continue; |
| 368 | |
| 369 | rate = parent_rate * (frac + 1) / (pcd + 1); |
| 370 | if (rate > freq_in_khz) |
| 371 | continue; |
| 372 | |
| 373 | if (best == 0 || rate > best) { |
| 374 | best = rate; |
| 375 | best_pfd = pfd; |
| 376 | best_frac = frac; |
| 377 | best_pcd = pcd; |
| 378 | best_div = div; |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | if (best == 0) { |
| 386 | printf("Can't find parent clock for LCDIF, target freq: %u\n", freq_in_khz); |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | debug("LCD target rate %ukhz, best rate %ukhz, frac %u, pcd %u, best_pfd %u, best_div %u\n", |
| 391 | freq_in_khz, best, best_frac, best_pcd, best_pfd, best_div); |
| 392 | |
| 393 | cgc2_pll4_pfd_config(PLL4_PFD0, best_pfd); |
| 394 | cgc2_pll4_pfddiv_config(PLL4_PFD0_DIV1, best_div - 1); |
| 395 | |
| 396 | pcc_clock_sel(5, DCNANO_PCC5_SLOT, PLL4_PFD0_DIV1); |
| 397 | pcc_clock_div_config(5, DCNANO_PCC5_SLOT, best_frac, best_pcd + 1); |
| 398 | pcc_clock_enable(5, DCNANO_PCC5_SLOT, true); |
| 399 | pcc_reset_peripheral(5, DCNANO_PCC5_SLOT, false); |
| 400 | } |
| 401 | |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 402 | u32 mxc_get_clock(enum mxc_clock clk) |
| 403 | { |
| 404 | switch (clk) { |
| 405 | case MXC_ESDHC_CLK: |
| 406 | return pcc_clock_get_rate(4, SDHC0_PCC4_SLOT); |
| 407 | case MXC_ESDHC2_CLK: |
| 408 | return pcc_clock_get_rate(4, SDHC1_PCC4_SLOT); |
| 409 | case MXC_ESDHC3_CLK: |
| 410 | return pcc_clock_get_rate(4, SDHC2_PCC4_SLOT); |
| 411 | case MXC_ARM_CLK: |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 412 | return cgc_clk_get_rate(PLL2); |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 413 | default: |
| 414 | return 0; |
| 415 | } |
| 416 | } |
| 417 | |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 418 | u32 get_lpuart_clk(void) |
| 419 | { |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 420 | int index = 0; |
| 421 | |
| 422 | const u32 lpuart_array[] = { |
| 423 | LPUART4_RBASE, |
| 424 | LPUART5_RBASE, |
| 425 | LPUART6_RBASE, |
| 426 | LPUART7_RBASE, |
| 427 | }; |
| 428 | |
| 429 | const u32 lpuart_pcc_slots[] = { |
| 430 | LPUART4_PCC3_SLOT, |
| 431 | LPUART5_PCC3_SLOT, |
| 432 | LPUART6_PCC4_SLOT, |
| 433 | LPUART7_PCC4_SLOT, |
| 434 | }; |
| 435 | |
| 436 | const u32 lpuart_pcc[] = { |
| 437 | 3, 3, 4, 4, |
| 438 | }; |
| 439 | |
| 440 | for (index = 0; index < 4; index++) { |
| 441 | if (lpuart_array[index] == LPUART_BASE) |
| 442 | break; |
| 443 | } |
| 444 | |
| 445 | if (index > 3) |
| 446 | return 0; |
| 447 | |
| 448 | return pcc_clock_get_rate(lpuart_pcc[index], lpuart_pcc_slots[index]); |
| 449 | } |
| 450 | |
| 451 | #ifndef CONFIG_SPL_BUILD |
| 452 | /* |
| 453 | * Dump some core clockes. |
| 454 | */ |
| 455 | int do_mx8ulp_showclocks(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) |
| 456 | { |
| 457 | printf("SDHC0 %8d MHz\n", pcc_clock_get_rate(4, SDHC0_PCC4_SLOT) / 1000000); |
| 458 | printf("SDHC1 %8d MHz\n", pcc_clock_get_rate(4, SDHC1_PCC4_SLOT) / 1000000); |
| 459 | printf("SDHC2 %8d MHz\n", pcc_clock_get_rate(4, SDHC2_PCC4_SLOT) / 1000000); |
| 460 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 461 | printf("SOSC %8d MHz\n", cgc_clk_get_rate(SOSC) / 1000000); |
| 462 | printf("FRO %8d MHz\n", cgc_clk_get_rate(FRO) / 1000000); |
| 463 | printf("PLL2 %8d MHz\n", cgc_clk_get_rate(PLL2) / 1000000); |
| 464 | printf("PLL3 %8d MHz\n", cgc_clk_get_rate(PLL3) / 1000000); |
| 465 | printf("PLL3_VCODIV %8d MHz\n", cgc_clk_get_rate(PLL3_VCODIV) / 1000000); |
| 466 | printf("PLL3_PFD0 %8d MHz\n", cgc_clk_get_rate(PLL3_PFD0) / 1000000); |
| 467 | printf("PLL3_PFD1 %8d MHz\n", cgc_clk_get_rate(PLL3_PFD1) / 1000000); |
| 468 | printf("PLL3_PFD2 %8d MHz\n", cgc_clk_get_rate(PLL3_PFD2) / 1000000); |
| 469 | printf("PLL3_PFD3 %8d MHz\n", cgc_clk_get_rate(PLL3_PFD3) / 1000000); |
| 470 | |
| 471 | printf("PLL4_PFD0 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD0) / 1000000); |
| 472 | printf("PLL4_PFD1 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD1) / 1000000); |
| 473 | printf("PLL4_PFD2 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD2) / 1000000); |
| 474 | printf("PLL4_PFD3 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD3) / 1000000); |
| 475 | |
| 476 | printf("PLL4_PFD0_DIV1 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD0_DIV1) / 1000000); |
| 477 | printf("PLL4_PFD0_DIV2 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD0_DIV2) / 1000000); |
| 478 | printf("PLL4_PFD1_DIV1 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD1_DIV1) / 1000000); |
| 479 | printf("PLL4_PFD1_DIV2 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD1_DIV2) / 1000000); |
| 480 | |
| 481 | printf("PLL4_PFD2_DIV1 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD2_DIV1) / 1000000); |
| 482 | printf("PLL4_PFD2_DIV2 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD2_DIV2) / 1000000); |
| 483 | printf("PLL4_PFD3_DIV1 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD3_DIV1) / 1000000); |
| 484 | printf("PLL4_PFD3_DIV2 %8d MHz\n", cgc_clk_get_rate(PLL4_PFD3_DIV2) / 1000000); |
| 485 | |
| 486 | printf("LPAV_AXICLK %8d MHz\n", cgc_clk_get_rate(LPAV_AXICLK) / 1000000); |
| 487 | printf("LPAV_AHBCLK %8d MHz\n", cgc_clk_get_rate(LPAV_AHBCLK) / 1000000); |
| 488 | printf("LPAV_BUSCLK %8d MHz\n", cgc_clk_get_rate(LPAV_BUSCLK) / 1000000); |
| 489 | 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] | 490 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 491 | printf("NIC_PERCLK %8d MHz\n", cgc_clk_get_rate(NIC_PERCLK) / 1000000); |
| 492 | printf("XBAR_APCLK %8d MHz\n", cgc_clk_get_rate(XBAR_APCLK) / 1000000); |
| 493 | printf("XBAR_BUSCLK %8d MHz\n", cgc_clk_get_rate(XBAR_BUSCLK) / 1000000); |
| 494 | 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] | 495 | return 0; |
Peng Fan | b15705a | 2021-08-07 16:00:35 +0800 | [diff] [blame] | 496 | } |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 497 | |
| 498 | U_BOOT_CMD( |
| 499 | clocks, CONFIG_SYS_MAXARGS, 1, do_mx8ulp_showclocks, |
| 500 | "display clocks", |
| 501 | "" |
| 502 | ); |
| 503 | #endif |