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