Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010-2011 Freescale Semiconductor, Inc. |
| 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
| 9 | #include <asm/errno.h> |
| 10 | #include <asm/arch/imx-regs.h> |
Fabio Estevam | 6479f51 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 11 | #include <asm/arch/crm_regs.h> |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 12 | #include <asm/arch/clock.h> |
Fabio Estevam | 6479f51 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 13 | #include <asm/arch/sys_proto.h> |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 14 | |
| 15 | enum pll_clocks { |
| 16 | PLL_SYS, /* System PLL */ |
| 17 | PLL_BUS, /* System Bus PLL*/ |
| 18 | PLL_USBOTG, /* OTG USB PLL */ |
| 19 | PLL_ENET, /* ENET PLL */ |
| 20 | }; |
| 21 | |
Fabio Estevam | 6479f51 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 22 | struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 23 | |
Benoît Thébaudeau | 20db631 | 2013-04-23 10:17:44 +0000 | [diff] [blame] | 24 | #ifdef CONFIG_MXC_OCOTP |
| 25 | void enable_ocotp_clk(unsigned char enable) |
| 26 | { |
| 27 | u32 reg; |
| 28 | |
| 29 | reg = __raw_readl(&imx_ccm->CCGR2); |
| 30 | if (enable) |
| 31 | reg |= MXC_CCM_CCGR2_OCOTP_CTRL_MASK; |
| 32 | else |
| 33 | reg &= ~MXC_CCM_CCGR2_OCOTP_CTRL_MASK; |
| 34 | __raw_writel(reg, &imx_ccm->CCGR2); |
| 35 | } |
| 36 | #endif |
| 37 | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 38 | void enable_usboh3_clk(unsigned char enable) |
| 39 | { |
| 40 | u32 reg; |
| 41 | |
| 42 | reg = __raw_readl(&imx_ccm->CCGR6); |
| 43 | if (enable) |
Eric Nelson | e427954 | 2012-09-21 07:33:51 +0000 | [diff] [blame] | 44 | reg |= MXC_CCM_CCGR6_USBOH3_MASK; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 45 | else |
Eric Nelson | e427954 | 2012-09-21 07:33:51 +0000 | [diff] [blame] | 46 | reg &= ~(MXC_CCM_CCGR6_USBOH3_MASK); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 47 | __raw_writel(reg, &imx_ccm->CCGR6); |
| 48 | |
| 49 | } |
| 50 | |
Troy Kisky | d4fdc99 | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 51 | #ifdef CONFIG_I2C_MXC |
| 52 | /* i2c_num can be from 0 - 2 */ |
| 53 | int enable_i2c_clk(unsigned char enable, unsigned i2c_num) |
| 54 | { |
| 55 | u32 reg; |
| 56 | u32 mask; |
| 57 | |
| 58 | if (i2c_num > 2) |
| 59 | return -EINVAL; |
Eric Nelson | e427954 | 2012-09-21 07:33:51 +0000 | [diff] [blame] | 60 | |
| 61 | mask = MXC_CCM_CCGR_CG_MASK |
| 62 | << (MXC_CCM_CCGR2_I2C1_SERIAL_OFFSET + (i2c_num << 1)); |
Troy Kisky | d4fdc99 | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 63 | reg = __raw_readl(&imx_ccm->CCGR2); |
| 64 | if (enable) |
| 65 | reg |= mask; |
| 66 | else |
| 67 | reg &= ~mask; |
| 68 | __raw_writel(reg, &imx_ccm->CCGR2); |
| 69 | return 0; |
| 70 | } |
| 71 | #endif |
| 72 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 73 | static u32 decode_pll(enum pll_clocks pll, u32 infreq) |
| 74 | { |
| 75 | u32 div; |
| 76 | |
| 77 | switch (pll) { |
| 78 | case PLL_SYS: |
| 79 | div = __raw_readl(&imx_ccm->analog_pll_sys); |
| 80 | div &= BM_ANADIG_PLL_SYS_DIV_SELECT; |
| 81 | |
| 82 | return infreq * (div >> 1); |
| 83 | case PLL_BUS: |
| 84 | div = __raw_readl(&imx_ccm->analog_pll_528); |
| 85 | div &= BM_ANADIG_PLL_528_DIV_SELECT; |
| 86 | |
| 87 | return infreq * (20 + (div << 1)); |
| 88 | case PLL_USBOTG: |
| 89 | div = __raw_readl(&imx_ccm->analog_usb1_pll_480_ctrl); |
| 90 | div &= BM_ANADIG_USB1_PLL_480_CTRL_DIV_SELECT; |
| 91 | |
| 92 | return infreq * (20 + (div << 1)); |
| 93 | case PLL_ENET: |
| 94 | div = __raw_readl(&imx_ccm->analog_pll_enet); |
| 95 | div &= BM_ANADIG_PLL_ENET_DIV_SELECT; |
| 96 | |
| 97 | return (div == 3 ? 125000000 : 25000000 * (div << 1)); |
| 98 | default: |
| 99 | return 0; |
| 100 | } |
| 101 | /* NOTREACHED */ |
| 102 | } |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 103 | static u32 mxc_get_pll_pfd(enum pll_clocks pll, int pfd_num) |
| 104 | { |
| 105 | u32 div; |
| 106 | u64 freq; |
| 107 | |
| 108 | switch (pll) { |
| 109 | case PLL_BUS: |
| 110 | if (pfd_num == 3) { |
| 111 | /* No PFD3 on PPL2 */ |
| 112 | return 0; |
| 113 | } |
| 114 | div = __raw_readl(&imx_ccm->analog_pfd_528); |
| 115 | freq = (u64)decode_pll(PLL_BUS, MXC_HCLK); |
| 116 | break; |
| 117 | case PLL_USBOTG: |
| 118 | div = __raw_readl(&imx_ccm->analog_pfd_480); |
| 119 | freq = (u64)decode_pll(PLL_USBOTG, MXC_HCLK); |
| 120 | break; |
| 121 | default: |
| 122 | /* No PFD on other PLL */ |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | return (freq * 18) / ((div & ANATOP_PFD_FRAC_MASK(pfd_num)) >> |
| 127 | ANATOP_PFD_FRAC_SHIFT(pfd_num)); |
| 128 | } |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 129 | |
| 130 | static u32 get_mcu_main_clk(void) |
| 131 | { |
| 132 | u32 reg, freq; |
| 133 | |
| 134 | reg = __raw_readl(&imx_ccm->cacrr); |
| 135 | reg &= MXC_CCM_CACRR_ARM_PODF_MASK; |
| 136 | reg >>= MXC_CCM_CACRR_ARM_PODF_OFFSET; |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 137 | freq = decode_pll(PLL_SYS, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 138 | |
| 139 | return freq / (reg + 1); |
| 140 | } |
| 141 | |
Fabio Estevam | 6479f51 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 142 | u32 get_periph_clk(void) |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 143 | { |
| 144 | u32 reg, freq = 0; |
| 145 | |
| 146 | reg = __raw_readl(&imx_ccm->cbcdr); |
| 147 | if (reg & MXC_CCM_CBCDR_PERIPH_CLK_SEL) { |
| 148 | reg = __raw_readl(&imx_ccm->cbcmr); |
| 149 | reg &= MXC_CCM_CBCMR_PERIPH_CLK2_SEL_MASK; |
| 150 | reg >>= MXC_CCM_CBCMR_PERIPH_CLK2_SEL_OFFSET; |
| 151 | |
| 152 | switch (reg) { |
| 153 | case 0: |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 154 | freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 155 | break; |
| 156 | case 1: |
| 157 | case 2: |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 158 | freq = MXC_HCLK; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 159 | break; |
| 160 | default: |
| 161 | break; |
| 162 | } |
| 163 | } else { |
| 164 | reg = __raw_readl(&imx_ccm->cbcmr); |
| 165 | reg &= MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK; |
| 166 | reg >>= MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET; |
| 167 | |
| 168 | switch (reg) { |
| 169 | case 0: |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 170 | freq = decode_pll(PLL_BUS, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 171 | break; |
| 172 | case 1: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 173 | freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 174 | break; |
| 175 | case 2: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 176 | freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 177 | break; |
| 178 | case 3: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 179 | /* static / 2 divider */ |
| 180 | freq = mxc_get_pll_pfd(PLL_BUS, 2) / 2; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 181 | break; |
| 182 | default: |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | return freq; |
| 188 | } |
| 189 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 190 | static u32 get_ipg_clk(void) |
| 191 | { |
| 192 | u32 reg, ipg_podf; |
| 193 | |
| 194 | reg = __raw_readl(&imx_ccm->cbcdr); |
| 195 | reg &= MXC_CCM_CBCDR_IPG_PODF_MASK; |
| 196 | ipg_podf = reg >> MXC_CCM_CBCDR_IPG_PODF_OFFSET; |
| 197 | |
| 198 | return get_ahb_clk() / (ipg_podf + 1); |
| 199 | } |
| 200 | |
| 201 | static u32 get_ipg_per_clk(void) |
| 202 | { |
| 203 | u32 reg, perclk_podf; |
| 204 | |
| 205 | reg = __raw_readl(&imx_ccm->cscmr1); |
| 206 | perclk_podf = reg & MXC_CCM_CSCMR1_PERCLK_PODF_MASK; |
| 207 | |
| 208 | return get_ipg_clk() / (perclk_podf + 1); |
| 209 | } |
| 210 | |
| 211 | static u32 get_uart_clk(void) |
| 212 | { |
| 213 | u32 reg, uart_podf; |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 214 | u32 freq = decode_pll(PLL_USBOTG, MXC_HCLK) / 6; /* static divider */ |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 215 | reg = __raw_readl(&imx_ccm->cscdr1); |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 216 | #ifdef CONFIG_MX6SL |
| 217 | if (reg & MXC_CCM_CSCDR1_UART_CLK_SEL) |
| 218 | freq = MXC_HCLK; |
| 219 | #endif |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 220 | reg &= MXC_CCM_CSCDR1_UART_CLK_PODF_MASK; |
| 221 | uart_podf = reg >> MXC_CCM_CSCDR1_UART_CLK_PODF_OFFSET; |
| 222 | |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 223 | return freq / (uart_podf + 1); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static u32 get_cspi_clk(void) |
| 227 | { |
| 228 | u32 reg, cspi_podf; |
| 229 | |
| 230 | reg = __raw_readl(&imx_ccm->cscdr2); |
| 231 | reg &= MXC_CCM_CSCDR2_ECSPI_CLK_PODF_MASK; |
| 232 | cspi_podf = reg >> MXC_CCM_CSCDR2_ECSPI_CLK_PODF_OFFSET; |
| 233 | |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 234 | return decode_pll(PLL_USBOTG, MXC_HCLK) / (8 * (cspi_podf + 1)); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static u32 get_axi_clk(void) |
| 238 | { |
| 239 | u32 root_freq, axi_podf; |
| 240 | u32 cbcdr = __raw_readl(&imx_ccm->cbcdr); |
| 241 | |
| 242 | axi_podf = cbcdr & MXC_CCM_CBCDR_AXI_PODF_MASK; |
| 243 | axi_podf >>= MXC_CCM_CBCDR_AXI_PODF_OFFSET; |
| 244 | |
| 245 | if (cbcdr & MXC_CCM_CBCDR_AXI_SEL) { |
| 246 | if (cbcdr & MXC_CCM_CBCDR_AXI_ALT_SEL) |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 247 | root_freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 248 | else |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 249 | root_freq = mxc_get_pll_pfd(PLL_USBOTG, 1); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 250 | } else |
| 251 | root_freq = get_periph_clk(); |
| 252 | |
| 253 | return root_freq / (axi_podf + 1); |
| 254 | } |
| 255 | |
| 256 | static u32 get_emi_slow_clk(void) |
| 257 | { |
Andrew Gabbasov | 4740e24 | 2013-07-04 06:27:32 -0500 | [diff] [blame] | 258 | u32 emi_clk_sel, emi_slow_podf, cscmr1, root_freq = 0; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 259 | |
| 260 | cscmr1 = __raw_readl(&imx_ccm->cscmr1); |
| 261 | emi_clk_sel = cscmr1 & MXC_CCM_CSCMR1_ACLK_EMI_SLOW_MASK; |
| 262 | emi_clk_sel >>= MXC_CCM_CSCMR1_ACLK_EMI_SLOW_OFFSET; |
Andrew Gabbasov | 4740e24 | 2013-07-04 06:27:32 -0500 | [diff] [blame] | 263 | emi_slow_podf = cscmr1 & MXC_CCM_CSCMR1_ACLK_EMI_SLOW_PODF_MASK; |
| 264 | emi_slow_podf >>= MXC_CCM_CSCMR1_ACLK_EMI_SLOW_PODF_OFFSET; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 265 | |
| 266 | switch (emi_clk_sel) { |
| 267 | case 0: |
| 268 | root_freq = get_axi_clk(); |
| 269 | break; |
| 270 | case 1: |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 271 | root_freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 272 | break; |
| 273 | case 2: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 274 | root_freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 275 | break; |
| 276 | case 3: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 277 | root_freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 278 | break; |
| 279 | } |
| 280 | |
Andrew Gabbasov | 4740e24 | 2013-07-04 06:27:32 -0500 | [diff] [blame] | 281 | return root_freq / (emi_slow_podf + 1); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 284 | #ifdef CONFIG_MX6SL |
| 285 | static u32 get_mmdc_ch0_clk(void) |
| 286 | { |
| 287 | u32 cbcmr = __raw_readl(&imx_ccm->cbcmr); |
| 288 | u32 cbcdr = __raw_readl(&imx_ccm->cbcdr); |
| 289 | u32 freq, podf; |
| 290 | |
| 291 | podf = (cbcdr & MXC_CCM_CBCDR_MMDC_CH1_PODF_MASK) \ |
| 292 | >> MXC_CCM_CBCDR_MMDC_CH1_PODF_OFFSET; |
| 293 | |
| 294 | switch ((cbcmr & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK) >> |
| 295 | MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET) { |
| 296 | case 0: |
| 297 | freq = decode_pll(PLL_BUS, MXC_HCLK); |
| 298 | break; |
| 299 | case 1: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 300 | freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 301 | break; |
| 302 | case 2: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 303 | freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 304 | break; |
| 305 | case 3: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 306 | /* static / 2 divider */ |
| 307 | freq = mxc_get_pll_pfd(PLL_BUS, 2) / 2; |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | return freq / (podf + 1); |
| 311 | |
| 312 | } |
Fabio Estevam | 67b8b9d | 2013-09-13 00:36:28 -0300 | [diff] [blame] | 313 | |
| 314 | int enable_fec_anatop_clock(void) |
| 315 | { |
| 316 | u32 reg = 0; |
| 317 | s32 timeout = 100000; |
| 318 | |
| 319 | struct anatop_regs __iomem *anatop = |
| 320 | (struct anatop_regs __iomem *)ANATOP_BASE_ADDR; |
| 321 | |
| 322 | reg = readl(&anatop->pll_enet); |
| 323 | if ((reg & BM_ANADIG_PLL_ENET_POWERDOWN) || |
| 324 | (!(reg & BM_ANADIG_PLL_ENET_LOCK))) { |
| 325 | reg &= ~BM_ANADIG_PLL_ENET_POWERDOWN; |
| 326 | writel(reg, &anatop->pll_enet); |
| 327 | while (timeout--) { |
| 328 | if (readl(&anatop->pll_enet) & BM_ANADIG_PLL_ENET_LOCK) |
| 329 | break; |
| 330 | } |
| 331 | if (timeout < 0) |
| 332 | return -ETIMEDOUT; |
| 333 | } |
| 334 | |
| 335 | /* Enable FEC clock */ |
| 336 | reg |= BM_ANADIG_PLL_ENET_ENABLE; |
| 337 | reg &= ~BM_ANADIG_PLL_ENET_BYPASS; |
| 338 | writel(reg, &anatop->pll_enet); |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 343 | #else |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 344 | static u32 get_mmdc_ch0_clk(void) |
| 345 | { |
| 346 | u32 cbcdr = __raw_readl(&imx_ccm->cbcdr); |
| 347 | u32 mmdc_ch0_podf = (cbcdr & MXC_CCM_CBCDR_MMDC_CH0_PODF_MASK) >> |
| 348 | MXC_CCM_CBCDR_MMDC_CH0_PODF_OFFSET; |
| 349 | |
| 350 | return get_periph_clk() / (mmdc_ch0_podf + 1); |
| 351 | } |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 352 | #endif |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 353 | |
| 354 | static u32 get_usdhc_clk(u32 port) |
| 355 | { |
| 356 | u32 root_freq = 0, usdhc_podf = 0, clk_sel = 0; |
| 357 | u32 cscmr1 = __raw_readl(&imx_ccm->cscmr1); |
| 358 | u32 cscdr1 = __raw_readl(&imx_ccm->cscdr1); |
| 359 | |
| 360 | switch (port) { |
| 361 | case 0: |
| 362 | usdhc_podf = (cscdr1 & MXC_CCM_CSCDR1_USDHC1_PODF_MASK) >> |
| 363 | MXC_CCM_CSCDR1_USDHC1_PODF_OFFSET; |
| 364 | clk_sel = cscmr1 & MXC_CCM_CSCMR1_USDHC1_CLK_SEL; |
| 365 | |
| 366 | break; |
| 367 | case 1: |
| 368 | usdhc_podf = (cscdr1 & MXC_CCM_CSCDR1_USDHC2_PODF_MASK) >> |
| 369 | MXC_CCM_CSCDR1_USDHC2_PODF_OFFSET; |
| 370 | clk_sel = cscmr1 & MXC_CCM_CSCMR1_USDHC2_CLK_SEL; |
| 371 | |
| 372 | break; |
| 373 | case 2: |
| 374 | usdhc_podf = (cscdr1 & MXC_CCM_CSCDR1_USDHC3_PODF_MASK) >> |
| 375 | MXC_CCM_CSCDR1_USDHC3_PODF_OFFSET; |
| 376 | clk_sel = cscmr1 & MXC_CCM_CSCMR1_USDHC3_CLK_SEL; |
| 377 | |
| 378 | break; |
| 379 | case 3: |
| 380 | usdhc_podf = (cscdr1 & MXC_CCM_CSCDR1_USDHC4_PODF_MASK) >> |
| 381 | MXC_CCM_CSCDR1_USDHC4_PODF_OFFSET; |
| 382 | clk_sel = cscmr1 & MXC_CCM_CSCMR1_USDHC4_CLK_SEL; |
| 383 | |
| 384 | break; |
| 385 | default: |
| 386 | break; |
| 387 | } |
| 388 | |
| 389 | if (clk_sel) |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 390 | root_freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 391 | else |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame^] | 392 | root_freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 393 | |
| 394 | return root_freq / (usdhc_podf + 1); |
| 395 | } |
| 396 | |
| 397 | u32 imx_get_uartclk(void) |
| 398 | { |
| 399 | return get_uart_clk(); |
| 400 | } |
| 401 | |
Jason Liu | 92aa90b | 2011-12-16 05:17:06 +0000 | [diff] [blame] | 402 | u32 imx_get_fecclk(void) |
| 403 | { |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 404 | return decode_pll(PLL_ENET, MXC_HCLK); |
Jason Liu | 92aa90b | 2011-12-16 05:17:06 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Eric Nelson | fdba076 | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 407 | int enable_sata_clock(void) |
| 408 | { |
| 409 | u32 reg = 0; |
| 410 | s32 timeout = 100000; |
| 411 | struct mxc_ccm_reg *const imx_ccm |
| 412 | = (struct mxc_ccm_reg *) CCM_BASE_ADDR; |
| 413 | |
| 414 | /* Enable sata clock */ |
| 415 | reg = readl(&imx_ccm->CCGR5); /* CCGR5 */ |
Eric Nelson | e427954 | 2012-09-21 07:33:51 +0000 | [diff] [blame] | 416 | reg |= MXC_CCM_CCGR5_SATA_MASK; |
Eric Nelson | fdba076 | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 417 | writel(reg, &imx_ccm->CCGR5); |
| 418 | |
| 419 | /* Enable PLLs */ |
| 420 | reg = readl(&imx_ccm->analog_pll_enet); |
| 421 | reg &= ~BM_ANADIG_PLL_SYS_POWERDOWN; |
| 422 | writel(reg, &imx_ccm->analog_pll_enet); |
| 423 | reg |= BM_ANADIG_PLL_SYS_ENABLE; |
| 424 | while (timeout--) { |
| 425 | if (readl(&imx_ccm->analog_pll_enet) & BM_ANADIG_PLL_SYS_LOCK) |
| 426 | break; |
| 427 | } |
| 428 | if (timeout <= 0) |
| 429 | return -EIO; |
| 430 | reg &= ~BM_ANADIG_PLL_SYS_BYPASS; |
| 431 | writel(reg, &imx_ccm->analog_pll_enet); |
| 432 | reg |= BM_ANADIG_PLL_ENET_ENABLE_SATA; |
| 433 | writel(reg, &imx_ccm->analog_pll_enet); |
| 434 | |
| 435 | return 0 ; |
| 436 | } |
| 437 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 438 | unsigned int mxc_get_clock(enum mxc_clock clk) |
| 439 | { |
| 440 | switch (clk) { |
| 441 | case MXC_ARM_CLK: |
| 442 | return get_mcu_main_clk(); |
| 443 | case MXC_PER_CLK: |
| 444 | return get_periph_clk(); |
| 445 | case MXC_AHB_CLK: |
| 446 | return get_ahb_clk(); |
| 447 | case MXC_IPG_CLK: |
| 448 | return get_ipg_clk(); |
| 449 | case MXC_IPG_PERCLK: |
Matthias Weisser | 99ba342 | 2012-09-24 02:46:53 +0000 | [diff] [blame] | 450 | case MXC_I2C_CLK: |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 451 | return get_ipg_per_clk(); |
| 452 | case MXC_UART_CLK: |
| 453 | return get_uart_clk(); |
| 454 | case MXC_CSPI_CLK: |
| 455 | return get_cspi_clk(); |
| 456 | case MXC_AXI_CLK: |
| 457 | return get_axi_clk(); |
| 458 | case MXC_EMI_SLOW_CLK: |
| 459 | return get_emi_slow_clk(); |
| 460 | case MXC_DDR_CLK: |
| 461 | return get_mmdc_ch0_clk(); |
| 462 | case MXC_ESDHC_CLK: |
| 463 | return get_usdhc_clk(0); |
| 464 | case MXC_ESDHC2_CLK: |
| 465 | return get_usdhc_clk(1); |
| 466 | case MXC_ESDHC3_CLK: |
| 467 | return get_usdhc_clk(2); |
| 468 | case MXC_ESDHC4_CLK: |
| 469 | return get_usdhc_clk(3); |
| 470 | case MXC_SATA_CLK: |
| 471 | return get_ahb_clk(); |
| 472 | default: |
| 473 | break; |
| 474 | } |
| 475 | |
| 476 | return -1; |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * Dump some core clockes. |
| 481 | */ |
| 482 | int do_mx6_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 483 | { |
| 484 | u32 freq; |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 485 | freq = decode_pll(PLL_SYS, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 486 | printf("PLL_SYS %8d MHz\n", freq / 1000000); |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 487 | freq = decode_pll(PLL_BUS, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 488 | printf("PLL_BUS %8d MHz\n", freq / 1000000); |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 489 | freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 490 | printf("PLL_OTG %8d MHz\n", freq / 1000000); |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 491 | freq = decode_pll(PLL_ENET, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 492 | printf("PLL_NET %8d MHz\n", freq / 1000000); |
| 493 | |
| 494 | printf("\n"); |
| 495 | printf("IPG %8d kHz\n", mxc_get_clock(MXC_IPG_CLK) / 1000); |
| 496 | printf("UART %8d kHz\n", mxc_get_clock(MXC_UART_CLK) / 1000); |
Fabio Estevam | f6fde41 | 2012-11-16 01:30:10 +0000 | [diff] [blame] | 497 | #ifdef CONFIG_MXC_SPI |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 498 | printf("CSPI %8d kHz\n", mxc_get_clock(MXC_CSPI_CLK) / 1000); |
Fabio Estevam | f6fde41 | 2012-11-16 01:30:10 +0000 | [diff] [blame] | 499 | #endif |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 500 | printf("AHB %8d kHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000); |
| 501 | printf("AXI %8d kHz\n", mxc_get_clock(MXC_AXI_CLK) / 1000); |
| 502 | printf("DDR %8d kHz\n", mxc_get_clock(MXC_DDR_CLK) / 1000); |
| 503 | printf("USDHC1 %8d kHz\n", mxc_get_clock(MXC_ESDHC_CLK) / 1000); |
| 504 | printf("USDHC2 %8d kHz\n", mxc_get_clock(MXC_ESDHC2_CLK) / 1000); |
| 505 | printf("USDHC3 %8d kHz\n", mxc_get_clock(MXC_ESDHC3_CLK) / 1000); |
| 506 | printf("USDHC4 %8d kHz\n", mxc_get_clock(MXC_ESDHC4_CLK) / 1000); |
| 507 | printf("EMI SLOW %8d kHz\n", mxc_get_clock(MXC_EMI_SLOW_CLK) / 1000); |
| 508 | printf("IPG PERCLK %8d kHz\n", mxc_get_clock(MXC_IPG_PERCLK) / 1000); |
| 509 | |
| 510 | return 0; |
| 511 | } |
| 512 | |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 513 | void enable_ipu_clock(void) |
| 514 | { |
| 515 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 516 | int reg; |
| 517 | reg = readl(&mxc_ccm->CCGR3); |
Pierre Aubert | 2cb5c38 | 2013-09-23 13:37:20 +0200 | [diff] [blame] | 518 | reg |= MXC_CCM_CCGR3_IPU1_IPU_MASK; |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 519 | writel(reg, &mxc_ccm->CCGR3); |
| 520 | } |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 521 | /***************************************************/ |
| 522 | |
| 523 | U_BOOT_CMD( |
| 524 | clocks, CONFIG_SYS_MAXARGS, 1, do_mx6_showclocks, |
| 525 | "display clocks", |
| 526 | "" |
| 527 | ); |