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 | |
Nikita Kiryanov | 224beb8 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 39 | #ifdef CONFIG_NAND_MXS |
| 40 | void setup_gpmi_io_clk(u32 cfg) |
| 41 | { |
| 42 | /* Disable clocks per ERR007177 from MX6 errata */ |
| 43 | clrbits_le32(&imx_ccm->CCGR4, |
| 44 | MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK | |
| 45 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK | |
| 46 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK | |
| 47 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK | |
| 48 | MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK); |
| 49 | |
| 50 | clrbits_le32(&imx_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK); |
| 51 | |
| 52 | clrsetbits_le32(&imx_ccm->cs2cdr, |
| 53 | MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK | |
| 54 | MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK | |
| 55 | MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK, |
| 56 | cfg); |
| 57 | |
| 58 | setbits_le32(&imx_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK); |
| 59 | setbits_le32(&imx_ccm->CCGR4, |
| 60 | MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK | |
| 61 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK | |
| 62 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK | |
| 63 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK | |
| 64 | MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK); |
| 65 | } |
| 66 | #endif |
| 67 | |
Wolfgang Grandegger | 3f46752 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 68 | void enable_usboh3_clk(unsigned char enable) |
| 69 | { |
| 70 | u32 reg; |
| 71 | |
| 72 | reg = __raw_readl(&imx_ccm->CCGR6); |
| 73 | if (enable) |
Eric Nelson | 0bb7e31 | 2012-09-21 07:33:51 +0000 | [diff] [blame] | 74 | reg |= MXC_CCM_CCGR6_USBOH3_MASK; |
Wolfgang Grandegger | 3f46752 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 75 | else |
Eric Nelson | 0bb7e31 | 2012-09-21 07:33:51 +0000 | [diff] [blame] | 76 | reg &= ~(MXC_CCM_CCGR6_USBOH3_MASK); |
Wolfgang Grandegger | 3f46752 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 77 | __raw_writel(reg, &imx_ccm->CCGR6); |
| 78 | |
| 79 | } |
| 80 | |
Stefano Babic | 3d8f179 | 2014-09-10 13:02:40 +0200 | [diff] [blame] | 81 | #if defined(CONFIG_FEC_MXC) && !defined(CONFIG_MX6SX) |
Nikita Kiryanov | 224beb8 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 82 | void enable_enet_clk(unsigned char enable) |
| 83 | { |
| 84 | u32 mask = MXC_CCM_CCGR1_ENET_CLK_ENABLE_MASK; |
| 85 | |
| 86 | if (enable) |
| 87 | setbits_le32(&imx_ccm->CCGR1, mask); |
| 88 | else |
| 89 | clrbits_le32(&imx_ccm->CCGR1, mask); |
| 90 | } |
| 91 | #endif |
| 92 | |
| 93 | #ifdef CONFIG_MXC_UART |
| 94 | void enable_uart_clk(unsigned char enable) |
| 95 | { |
| 96 | u32 mask = MXC_CCM_CCGR5_UART_MASK | MXC_CCM_CCGR5_UART_SERIAL_MASK; |
| 97 | |
| 98 | if (enable) |
| 99 | setbits_le32(&imx_ccm->CCGR5, mask); |
| 100 | else |
| 101 | clrbits_le32(&imx_ccm->CCGR5, mask); |
| 102 | } |
| 103 | #endif |
| 104 | |
| 105 | #ifdef CONFIG_SPI |
| 106 | /* spi_num can be from 0 - 4 */ |
| 107 | int enable_cspi_clock(unsigned char enable, unsigned spi_num) |
| 108 | { |
| 109 | u32 mask; |
| 110 | |
| 111 | if (spi_num > 4) |
| 112 | return -EINVAL; |
| 113 | |
| 114 | mask = MXC_CCM_CCGR_CG_MASK << (spi_num * 2); |
| 115 | if (enable) |
| 116 | setbits_le32(&imx_ccm->CCGR1, mask); |
| 117 | else |
| 118 | clrbits_le32(&imx_ccm->CCGR1, mask); |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | #ifdef CONFIG_MMC |
| 125 | int enable_usdhc_clk(unsigned char enable, unsigned bus_num) |
| 126 | { |
| 127 | u32 mask; |
| 128 | |
| 129 | if (bus_num > 3) |
| 130 | return -EINVAL; |
| 131 | |
| 132 | mask = MXC_CCM_CCGR_CG_MASK << (bus_num * 2 + 2); |
| 133 | if (enable) |
| 134 | setbits_le32(&imx_ccm->CCGR6, mask); |
| 135 | else |
| 136 | clrbits_le32(&imx_ccm->CCGR6, mask); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | #endif |
| 141 | |
trem | fac9640 | 2013-09-21 18:13:35 +0200 | [diff] [blame] | 142 | #ifdef CONFIG_SYS_I2C_MXC |
Troy Kisky | cc54a0f | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 143 | /* i2c_num can be from 0 - 2 */ |
| 144 | int enable_i2c_clk(unsigned char enable, unsigned i2c_num) |
| 145 | { |
| 146 | u32 reg; |
| 147 | u32 mask; |
| 148 | |
| 149 | if (i2c_num > 2) |
| 150 | return -EINVAL; |
Eric Nelson | 0bb7e31 | 2012-09-21 07:33:51 +0000 | [diff] [blame] | 151 | |
| 152 | mask = MXC_CCM_CCGR_CG_MASK |
| 153 | << (MXC_CCM_CCGR2_I2C1_SERIAL_OFFSET + (i2c_num << 1)); |
Troy Kisky | cc54a0f | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 154 | reg = __raw_readl(&imx_ccm->CCGR2); |
| 155 | if (enable) |
| 156 | reg |= mask; |
| 157 | else |
| 158 | reg &= ~mask; |
| 159 | __raw_writel(reg, &imx_ccm->CCGR2); |
| 160 | return 0; |
| 161 | } |
| 162 | #endif |
| 163 | |
Heiko Schocher | a0ae009 | 2014-07-18 06:07:20 +0200 | [diff] [blame] | 164 | /* spi_num can be from 0 - SPI_MAX_NUM */ |
| 165 | int enable_spi_clk(unsigned char enable, unsigned spi_num) |
| 166 | { |
| 167 | u32 reg; |
| 168 | u32 mask; |
| 169 | |
| 170 | if (spi_num > SPI_MAX_NUM) |
| 171 | return -EINVAL; |
| 172 | |
| 173 | mask = MXC_CCM_CCGR_CG_MASK << (spi_num << 1); |
| 174 | reg = __raw_readl(&imx_ccm->CCGR1); |
| 175 | if (enable) |
| 176 | reg |= mask; |
| 177 | else |
| 178 | reg &= ~mask; |
| 179 | __raw_writel(reg, &imx_ccm->CCGR1); |
| 180 | return 0; |
| 181 | } |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 182 | static u32 decode_pll(enum pll_clocks pll, u32 infreq) |
| 183 | { |
| 184 | u32 div; |
| 185 | |
| 186 | switch (pll) { |
| 187 | case PLL_SYS: |
| 188 | div = __raw_readl(&imx_ccm->analog_pll_sys); |
| 189 | div &= BM_ANADIG_PLL_SYS_DIV_SELECT; |
| 190 | |
Andre Renaud | 2eb268f | 2014-06-10 08:47:13 +1200 | [diff] [blame] | 191 | return (infreq * div) >> 1; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 192 | case PLL_BUS: |
| 193 | div = __raw_readl(&imx_ccm->analog_pll_528); |
| 194 | div &= BM_ANADIG_PLL_528_DIV_SELECT; |
| 195 | |
| 196 | return infreq * (20 + (div << 1)); |
| 197 | case PLL_USBOTG: |
| 198 | div = __raw_readl(&imx_ccm->analog_usb1_pll_480_ctrl); |
| 199 | div &= BM_ANADIG_USB1_PLL_480_CTRL_DIV_SELECT; |
| 200 | |
| 201 | return infreq * (20 + (div << 1)); |
| 202 | case PLL_ENET: |
| 203 | div = __raw_readl(&imx_ccm->analog_pll_enet); |
| 204 | div &= BM_ANADIG_PLL_ENET_DIV_SELECT; |
| 205 | |
Fabio Estevam | 89cfd0f | 2013-12-03 18:26:13 -0200 | [diff] [blame] | 206 | return 25000000 * (div + (div >> 1) + 1); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 207 | default: |
| 208 | return 0; |
| 209 | } |
| 210 | /* NOTREACHED */ |
| 211 | } |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 212 | static u32 mxc_get_pll_pfd(enum pll_clocks pll, int pfd_num) |
| 213 | { |
| 214 | u32 div; |
| 215 | u64 freq; |
| 216 | |
| 217 | switch (pll) { |
| 218 | case PLL_BUS: |
| 219 | if (pfd_num == 3) { |
| 220 | /* No PFD3 on PPL2 */ |
| 221 | return 0; |
| 222 | } |
| 223 | div = __raw_readl(&imx_ccm->analog_pfd_528); |
| 224 | freq = (u64)decode_pll(PLL_BUS, MXC_HCLK); |
| 225 | break; |
| 226 | case PLL_USBOTG: |
| 227 | div = __raw_readl(&imx_ccm->analog_pfd_480); |
| 228 | freq = (u64)decode_pll(PLL_USBOTG, MXC_HCLK); |
| 229 | break; |
| 230 | default: |
| 231 | /* No PFD on other PLL */ |
| 232 | return 0; |
| 233 | } |
| 234 | |
Christian Gmeiner | 5a66016 | 2014-01-08 08:24:25 +0100 | [diff] [blame] | 235 | return lldiv(freq * 18, (div & ANATOP_PFD_FRAC_MASK(pfd_num)) >> |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 236 | ANATOP_PFD_FRAC_SHIFT(pfd_num)); |
| 237 | } |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 238 | |
| 239 | static u32 get_mcu_main_clk(void) |
| 240 | { |
| 241 | u32 reg, freq; |
| 242 | |
| 243 | reg = __raw_readl(&imx_ccm->cacrr); |
| 244 | reg &= MXC_CCM_CACRR_ARM_PODF_MASK; |
| 245 | reg >>= MXC_CCM_CACRR_ARM_PODF_OFFSET; |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 246 | freq = decode_pll(PLL_SYS, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 247 | |
| 248 | return freq / (reg + 1); |
| 249 | } |
| 250 | |
Fabio Estevam | 6a37604 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 251 | u32 get_periph_clk(void) |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 252 | { |
| 253 | u32 reg, freq = 0; |
| 254 | |
| 255 | reg = __raw_readl(&imx_ccm->cbcdr); |
| 256 | if (reg & MXC_CCM_CBCDR_PERIPH_CLK_SEL) { |
| 257 | reg = __raw_readl(&imx_ccm->cbcmr); |
| 258 | reg &= MXC_CCM_CBCMR_PERIPH_CLK2_SEL_MASK; |
| 259 | reg >>= MXC_CCM_CBCMR_PERIPH_CLK2_SEL_OFFSET; |
| 260 | |
| 261 | switch (reg) { |
| 262 | case 0: |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 263 | freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 264 | break; |
| 265 | case 1: |
| 266 | case 2: |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 267 | freq = MXC_HCLK; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 268 | break; |
| 269 | default: |
| 270 | break; |
| 271 | } |
| 272 | } else { |
| 273 | reg = __raw_readl(&imx_ccm->cbcmr); |
| 274 | reg &= MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK; |
| 275 | reg >>= MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET; |
| 276 | |
| 277 | switch (reg) { |
| 278 | case 0: |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 279 | freq = decode_pll(PLL_BUS, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 280 | break; |
| 281 | case 1: |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 282 | freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 283 | break; |
| 284 | case 2: |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 285 | freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 286 | break; |
| 287 | case 3: |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 288 | /* static / 2 divider */ |
| 289 | freq = mxc_get_pll_pfd(PLL_BUS, 2) / 2; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 290 | break; |
| 291 | default: |
| 292 | break; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | return freq; |
| 297 | } |
| 298 | |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 299 | static u32 get_ipg_clk(void) |
| 300 | { |
| 301 | u32 reg, ipg_podf; |
| 302 | |
| 303 | reg = __raw_readl(&imx_ccm->cbcdr); |
| 304 | reg &= MXC_CCM_CBCDR_IPG_PODF_MASK; |
| 305 | ipg_podf = reg >> MXC_CCM_CBCDR_IPG_PODF_OFFSET; |
| 306 | |
| 307 | return get_ahb_clk() / (ipg_podf + 1); |
| 308 | } |
| 309 | |
| 310 | static u32 get_ipg_per_clk(void) |
| 311 | { |
| 312 | u32 reg, perclk_podf; |
| 313 | |
| 314 | reg = __raw_readl(&imx_ccm->cscmr1); |
Ye.Li | e68661a | 2014-10-30 18:20:57 +0800 | [diff] [blame] | 315 | #if (defined(CONFIG_MX6SL) || defined(CONFIG_MX6SX)) |
| 316 | if (reg & MXC_CCM_CSCMR1_PER_CLK_SEL_MASK) |
| 317 | return MXC_HCLK; /* OSC 24Mhz */ |
| 318 | #endif |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 319 | perclk_podf = reg & MXC_CCM_CSCMR1_PERCLK_PODF_MASK; |
| 320 | |
| 321 | return get_ipg_clk() / (perclk_podf + 1); |
| 322 | } |
| 323 | |
| 324 | static u32 get_uart_clk(void) |
| 325 | { |
| 326 | u32 reg, uart_podf; |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 327 | u32 freq = decode_pll(PLL_USBOTG, MXC_HCLK) / 6; /* static divider */ |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 328 | reg = __raw_readl(&imx_ccm->cscdr1); |
Fabio Estevam | 05d54b8 | 2014-06-24 17:40:58 -0300 | [diff] [blame] | 329 | #if (defined(CONFIG_MX6SL) || defined(CONFIG_MX6SX)) |
Fabio Estevam | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 330 | if (reg & MXC_CCM_CSCDR1_UART_CLK_SEL) |
| 331 | freq = MXC_HCLK; |
| 332 | #endif |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 333 | reg &= MXC_CCM_CSCDR1_UART_CLK_PODF_MASK; |
| 334 | uart_podf = reg >> MXC_CCM_CSCDR1_UART_CLK_PODF_OFFSET; |
| 335 | |
Fabio Estevam | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 336 | return freq / (uart_podf + 1); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | static u32 get_cspi_clk(void) |
| 340 | { |
| 341 | u32 reg, cspi_podf; |
| 342 | |
| 343 | reg = __raw_readl(&imx_ccm->cscdr2); |
| 344 | reg &= MXC_CCM_CSCDR2_ECSPI_CLK_PODF_MASK; |
| 345 | cspi_podf = reg >> MXC_CCM_CSCDR2_ECSPI_CLK_PODF_OFFSET; |
| 346 | |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 347 | return decode_pll(PLL_USBOTG, MXC_HCLK) / (8 * (cspi_podf + 1)); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | static u32 get_axi_clk(void) |
| 351 | { |
| 352 | u32 root_freq, axi_podf; |
| 353 | u32 cbcdr = __raw_readl(&imx_ccm->cbcdr); |
| 354 | |
| 355 | axi_podf = cbcdr & MXC_CCM_CBCDR_AXI_PODF_MASK; |
| 356 | axi_podf >>= MXC_CCM_CBCDR_AXI_PODF_OFFSET; |
| 357 | |
| 358 | if (cbcdr & MXC_CCM_CBCDR_AXI_SEL) { |
| 359 | if (cbcdr & MXC_CCM_CBCDR_AXI_ALT_SEL) |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 360 | root_freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 361 | else |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 362 | root_freq = mxc_get_pll_pfd(PLL_USBOTG, 1); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 363 | } else |
| 364 | root_freq = get_periph_clk(); |
| 365 | |
| 366 | return root_freq / (axi_podf + 1); |
| 367 | } |
| 368 | |
| 369 | static u32 get_emi_slow_clk(void) |
| 370 | { |
Andrew Gabbasov | d55e0da | 2013-07-04 06:27:32 -0500 | [diff] [blame] | 371 | u32 emi_clk_sel, emi_slow_podf, cscmr1, root_freq = 0; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 372 | |
| 373 | cscmr1 = __raw_readl(&imx_ccm->cscmr1); |
| 374 | emi_clk_sel = cscmr1 & MXC_CCM_CSCMR1_ACLK_EMI_SLOW_MASK; |
| 375 | emi_clk_sel >>= MXC_CCM_CSCMR1_ACLK_EMI_SLOW_OFFSET; |
Andrew Gabbasov | d55e0da | 2013-07-04 06:27:32 -0500 | [diff] [blame] | 376 | emi_slow_podf = cscmr1 & MXC_CCM_CSCMR1_ACLK_EMI_SLOW_PODF_MASK; |
| 377 | emi_slow_podf >>= MXC_CCM_CSCMR1_ACLK_EMI_SLOW_PODF_OFFSET; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 378 | |
| 379 | switch (emi_clk_sel) { |
| 380 | case 0: |
| 381 | root_freq = get_axi_clk(); |
| 382 | break; |
| 383 | case 1: |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 384 | root_freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 385 | break; |
| 386 | case 2: |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 387 | root_freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 388 | break; |
| 389 | case 3: |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 390 | root_freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 391 | break; |
| 392 | } |
| 393 | |
Andrew Gabbasov | d55e0da | 2013-07-04 06:27:32 -0500 | [diff] [blame] | 394 | return root_freq / (emi_slow_podf + 1); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Fabio Estevam | 05d54b8 | 2014-06-24 17:40:58 -0300 | [diff] [blame] | 397 | #if (defined(CONFIG_MX6SL) || defined(CONFIG_MX6SX)) |
Fabio Estevam | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 398 | static u32 get_mmdc_ch0_clk(void) |
| 399 | { |
| 400 | u32 cbcmr = __raw_readl(&imx_ccm->cbcmr); |
| 401 | u32 cbcdr = __raw_readl(&imx_ccm->cbcdr); |
| 402 | u32 freq, podf; |
| 403 | |
| 404 | podf = (cbcdr & MXC_CCM_CBCDR_MMDC_CH1_PODF_MASK) \ |
| 405 | >> MXC_CCM_CBCDR_MMDC_CH1_PODF_OFFSET; |
| 406 | |
| 407 | switch ((cbcmr & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK) >> |
| 408 | MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET) { |
| 409 | case 0: |
| 410 | freq = decode_pll(PLL_BUS, MXC_HCLK); |
| 411 | break; |
| 412 | case 1: |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 413 | freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Fabio Estevam | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 414 | break; |
| 415 | case 2: |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 416 | freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Fabio Estevam | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 417 | break; |
| 418 | case 3: |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 419 | /* static / 2 divider */ |
| 420 | freq = mxc_get_pll_pfd(PLL_BUS, 2) / 2; |
Fabio Estevam | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | return freq / (podf + 1); |
| 424 | |
| 425 | } |
Otavio Salvador | c655b81 | 2013-12-16 20:44:05 -0200 | [diff] [blame] | 426 | #else |
| 427 | static u32 get_mmdc_ch0_clk(void) |
| 428 | { |
| 429 | u32 cbcdr = __raw_readl(&imx_ccm->cbcdr); |
| 430 | u32 mmdc_ch0_podf = (cbcdr & MXC_CCM_CBCDR_MMDC_CH0_PODF_MASK) >> |
| 431 | MXC_CCM_CBCDR_MMDC_CH0_PODF_OFFSET; |
Fabio Estevam | 31f0796 | 2013-09-13 00:36:28 -0300 | [diff] [blame] | 432 | |
Otavio Salvador | c655b81 | 2013-12-16 20:44:05 -0200 | [diff] [blame] | 433 | return get_periph_clk() / (mmdc_ch0_podf + 1); |
| 434 | } |
| 435 | #endif |
| 436 | |
Peng Fan | b93ab2e | 2014-12-31 11:01:38 +0800 | [diff] [blame] | 437 | #ifdef CONFIG_MX6SX |
| 438 | /* qspi_num can be from 0 - 1 */ |
| 439 | void enable_qspi_clk(int qspi_num) |
| 440 | { |
| 441 | u32 reg = 0; |
| 442 | /* Enable QuadSPI clock */ |
| 443 | switch (qspi_num) { |
| 444 | case 0: |
| 445 | /* disable the clock gate */ |
| 446 | clrbits_le32(&imx_ccm->CCGR3, MXC_CCM_CCGR3_QSPI1_MASK); |
| 447 | |
| 448 | /* set 50M : (50 = 396 / 2 / 4) */ |
| 449 | reg = readl(&imx_ccm->cscmr1); |
| 450 | reg &= ~(MXC_CCM_CSCMR1_QSPI1_PODF_MASK | |
| 451 | MXC_CCM_CSCMR1_QSPI1_CLK_SEL_MASK); |
| 452 | reg |= ((1 << MXC_CCM_CSCMR1_QSPI1_PODF_OFFSET) | |
| 453 | (2 << MXC_CCM_CSCMR1_QSPI1_CLK_SEL_OFFSET)); |
| 454 | writel(reg, &imx_ccm->cscmr1); |
| 455 | |
| 456 | /* enable the clock gate */ |
| 457 | setbits_le32(&imx_ccm->CCGR3, MXC_CCM_CCGR3_QSPI1_MASK); |
| 458 | break; |
| 459 | case 1: |
| 460 | /* |
| 461 | * disable the clock gate |
| 462 | * QSPI2 and GPMI_BCH_INPUT_GPMI_IO share the same clock gate, |
| 463 | * disable both of them. |
| 464 | */ |
| 465 | clrbits_le32(&imx_ccm->CCGR4, MXC_CCM_CCGR4_QSPI2_ENFC_MASK | |
| 466 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK); |
| 467 | |
| 468 | /* set 50M : (50 = 396 / 2 / 4) */ |
| 469 | reg = readl(&imx_ccm->cs2cdr); |
| 470 | reg &= ~(MXC_CCM_CS2CDR_QSPI2_CLK_PODF_MASK | |
| 471 | MXC_CCM_CS2CDR_QSPI2_CLK_PRED_MASK | |
| 472 | MXC_CCM_CS2CDR_QSPI2_CLK_SEL_MASK); |
| 473 | reg |= (MXC_CCM_CS2CDR_QSPI2_CLK_PRED(0x1) | |
| 474 | MXC_CCM_CS2CDR_QSPI2_CLK_SEL(0x3)); |
| 475 | writel(reg, &imx_ccm->cs2cdr); |
| 476 | |
| 477 | /*enable the clock gate*/ |
| 478 | setbits_le32(&imx_ccm->CCGR4, MXC_CCM_CCGR4_QSPI2_ENFC_MASK | |
| 479 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK); |
| 480 | break; |
| 481 | default: |
| 482 | break; |
| 483 | } |
| 484 | } |
| 485 | #endif |
| 486 | |
Otavio Salvador | c655b81 | 2013-12-16 20:44:05 -0200 | [diff] [blame] | 487 | #ifdef CONFIG_FEC_MXC |
Fabio Estevam | 5f98d0b | 2014-01-03 15:55:57 -0200 | [diff] [blame] | 488 | int enable_fec_anatop_clock(enum enet_freq freq) |
Fabio Estevam | 31f0796 | 2013-09-13 00:36:28 -0300 | [diff] [blame] | 489 | { |
| 490 | u32 reg = 0; |
| 491 | s32 timeout = 100000; |
| 492 | |
| 493 | struct anatop_regs __iomem *anatop = |
| 494 | (struct anatop_regs __iomem *)ANATOP_BASE_ADDR; |
| 495 | |
Stefan Roese | 7731745 | 2014-11-27 13:46:43 +0100 | [diff] [blame] | 496 | if (freq < ENET_25MHZ || freq > ENET_125MHZ) |
Fabio Estevam | 5f98d0b | 2014-01-03 15:55:57 -0200 | [diff] [blame] | 497 | return -EINVAL; |
| 498 | |
Fabio Estevam | 31f0796 | 2013-09-13 00:36:28 -0300 | [diff] [blame] | 499 | reg = readl(&anatop->pll_enet); |
Fabio Estevam | 5f98d0b | 2014-01-03 15:55:57 -0200 | [diff] [blame] | 500 | reg &= ~BM_ANADIG_PLL_ENET_DIV_SELECT; |
| 501 | reg |= freq; |
| 502 | |
Fabio Estevam | 31f0796 | 2013-09-13 00:36:28 -0300 | [diff] [blame] | 503 | if ((reg & BM_ANADIG_PLL_ENET_POWERDOWN) || |
| 504 | (!(reg & BM_ANADIG_PLL_ENET_LOCK))) { |
| 505 | reg &= ~BM_ANADIG_PLL_ENET_POWERDOWN; |
| 506 | writel(reg, &anatop->pll_enet); |
| 507 | while (timeout--) { |
| 508 | if (readl(&anatop->pll_enet) & BM_ANADIG_PLL_ENET_LOCK) |
| 509 | break; |
| 510 | } |
| 511 | if (timeout < 0) |
| 512 | return -ETIMEDOUT; |
| 513 | } |
| 514 | |
| 515 | /* Enable FEC clock */ |
| 516 | reg |= BM_ANADIG_PLL_ENET_ENABLE; |
| 517 | reg &= ~BM_ANADIG_PLL_ENET_BYPASS; |
| 518 | writel(reg, &anatop->pll_enet); |
| 519 | |
Fabio Estevam | 5c045cd | 2014-08-15 00:24:30 -0300 | [diff] [blame] | 520 | #ifdef CONFIG_MX6SX |
| 521 | /* |
| 522 | * Set enet ahb clock to 200MHz |
| 523 | * pll2_pfd2_396m-> ENET_PODF-> ENET_AHB |
| 524 | */ |
| 525 | reg = readl(&imx_ccm->chsccdr); |
| 526 | reg &= ~(MXC_CCM_CHSCCDR_ENET_PRE_CLK_SEL_MASK |
| 527 | | MXC_CCM_CHSCCDR_ENET_PODF_MASK |
| 528 | | MXC_CCM_CHSCCDR_ENET_CLK_SEL_MASK); |
| 529 | /* PLL2 PFD2 */ |
| 530 | reg |= (4 << MXC_CCM_CHSCCDR_ENET_PRE_CLK_SEL_OFFSET); |
| 531 | /* Div = 2*/ |
| 532 | reg |= (1 << MXC_CCM_CHSCCDR_ENET_PODF_OFFSET); |
| 533 | reg |= (0 << MXC_CCM_CHSCCDR_ENET_CLK_SEL_OFFSET); |
| 534 | writel(reg, &imx_ccm->chsccdr); |
| 535 | |
| 536 | /* Enable enet system clock */ |
| 537 | reg = readl(&imx_ccm->CCGR3); |
| 538 | reg |= MXC_CCM_CCGR3_ENET_MASK; |
| 539 | writel(reg, &imx_ccm->CCGR3); |
| 540 | #endif |
Fabio Estevam | 31f0796 | 2013-09-13 00:36:28 -0300 | [diff] [blame] | 541 | return 0; |
| 542 | } |
Fabio Estevam | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 543 | #endif |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 544 | |
| 545 | static u32 get_usdhc_clk(u32 port) |
| 546 | { |
| 547 | u32 root_freq = 0, usdhc_podf = 0, clk_sel = 0; |
| 548 | u32 cscmr1 = __raw_readl(&imx_ccm->cscmr1); |
| 549 | u32 cscdr1 = __raw_readl(&imx_ccm->cscdr1); |
| 550 | |
| 551 | switch (port) { |
| 552 | case 0: |
| 553 | usdhc_podf = (cscdr1 & MXC_CCM_CSCDR1_USDHC1_PODF_MASK) >> |
| 554 | MXC_CCM_CSCDR1_USDHC1_PODF_OFFSET; |
| 555 | clk_sel = cscmr1 & MXC_CCM_CSCMR1_USDHC1_CLK_SEL; |
| 556 | |
| 557 | break; |
| 558 | case 1: |
| 559 | usdhc_podf = (cscdr1 & MXC_CCM_CSCDR1_USDHC2_PODF_MASK) >> |
| 560 | MXC_CCM_CSCDR1_USDHC2_PODF_OFFSET; |
| 561 | clk_sel = cscmr1 & MXC_CCM_CSCMR1_USDHC2_CLK_SEL; |
| 562 | |
| 563 | break; |
| 564 | case 2: |
| 565 | usdhc_podf = (cscdr1 & MXC_CCM_CSCDR1_USDHC3_PODF_MASK) >> |
| 566 | MXC_CCM_CSCDR1_USDHC3_PODF_OFFSET; |
| 567 | clk_sel = cscmr1 & MXC_CCM_CSCMR1_USDHC3_CLK_SEL; |
| 568 | |
| 569 | break; |
| 570 | case 3: |
| 571 | usdhc_podf = (cscdr1 & MXC_CCM_CSCDR1_USDHC4_PODF_MASK) >> |
| 572 | MXC_CCM_CSCDR1_USDHC4_PODF_OFFSET; |
| 573 | clk_sel = cscmr1 & MXC_CCM_CSCMR1_USDHC4_CLK_SEL; |
| 574 | |
| 575 | break; |
| 576 | default: |
| 577 | break; |
| 578 | } |
| 579 | |
| 580 | if (clk_sel) |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 581 | root_freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 582 | else |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 583 | root_freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 584 | |
| 585 | return root_freq / (usdhc_podf + 1); |
| 586 | } |
| 587 | |
| 588 | u32 imx_get_uartclk(void) |
| 589 | { |
| 590 | return get_uart_clk(); |
| 591 | } |
| 592 | |
Jason Liu | ff167df | 2011-12-16 05:17:06 +0000 | [diff] [blame] | 593 | u32 imx_get_fecclk(void) |
| 594 | { |
Markus Niebel | adadc91 | 2014-02-05 10:51:25 +0100 | [diff] [blame] | 595 | return mxc_get_clock(MXC_IPG_CLK); |
Jason Liu | ff167df | 2011-12-16 05:17:06 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 598 | static int enable_enet_pll(uint32_t en) |
Eric Nelson | 64e7cdb | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 599 | { |
Eric Nelson | 64e7cdb | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 600 | struct mxc_ccm_reg *const imx_ccm |
| 601 | = (struct mxc_ccm_reg *) CCM_BASE_ADDR; |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 602 | s32 timeout = 100000; |
| 603 | u32 reg = 0; |
Eric Nelson | 64e7cdb | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 604 | |
| 605 | /* Enable PLLs */ |
| 606 | reg = readl(&imx_ccm->analog_pll_enet); |
| 607 | reg &= ~BM_ANADIG_PLL_SYS_POWERDOWN; |
| 608 | writel(reg, &imx_ccm->analog_pll_enet); |
| 609 | reg |= BM_ANADIG_PLL_SYS_ENABLE; |
| 610 | while (timeout--) { |
| 611 | if (readl(&imx_ccm->analog_pll_enet) & BM_ANADIG_PLL_SYS_LOCK) |
| 612 | break; |
| 613 | } |
| 614 | if (timeout <= 0) |
| 615 | return -EIO; |
| 616 | reg &= ~BM_ANADIG_PLL_SYS_BYPASS; |
| 617 | writel(reg, &imx_ccm->analog_pll_enet); |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 618 | reg |= en; |
Eric Nelson | 64e7cdb | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 619 | writel(reg, &imx_ccm->analog_pll_enet); |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 620 | return 0; |
| 621 | } |
Eric Nelson | 64e7cdb | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 622 | |
Fabio Estevam | d95b6ab | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 623 | #ifndef CONFIG_MX6SX |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 624 | static void ungate_sata_clock(void) |
| 625 | { |
| 626 | struct mxc_ccm_reg *const imx_ccm = |
| 627 | (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 628 | |
| 629 | /* Enable SATA clock. */ |
| 630 | setbits_le32(&imx_ccm->CCGR5, MXC_CCM_CCGR5_SATA_MASK); |
| 631 | } |
Fabio Estevam | d95b6ab | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 632 | #endif |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 633 | |
| 634 | static void ungate_pcie_clock(void) |
| 635 | { |
| 636 | struct mxc_ccm_reg *const imx_ccm = |
| 637 | (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 638 | |
| 639 | /* Enable PCIe clock. */ |
| 640 | setbits_le32(&imx_ccm->CCGR4, MXC_CCM_CCGR4_PCIE_MASK); |
| 641 | } |
| 642 | |
Fabio Estevam | d95b6ab | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 643 | #ifndef CONFIG_MX6SX |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 644 | int enable_sata_clock(void) |
| 645 | { |
| 646 | ungate_sata_clock(); |
| 647 | return enable_enet_pll(BM_ANADIG_PLL_ENET_ENABLE_SATA); |
| 648 | } |
Nikita Kiryanov | 8d29cef | 2014-11-21 12:47:22 +0200 | [diff] [blame] | 649 | |
| 650 | void disable_sata_clock(void) |
| 651 | { |
| 652 | struct mxc_ccm_reg *const imx_ccm = |
| 653 | (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 654 | |
| 655 | clrbits_le32(&imx_ccm->CCGR5, MXC_CCM_CCGR5_SATA_MASK); |
| 656 | } |
Fabio Estevam | d95b6ab | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 657 | #endif |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 658 | |
| 659 | int enable_pcie_clock(void) |
| 660 | { |
| 661 | struct anatop_regs *anatop_regs = |
| 662 | (struct anatop_regs *)ANATOP_BASE_ADDR; |
| 663 | struct mxc_ccm_reg *ccm_regs = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
Fabio Estevam | 1b8ad74 | 2014-08-25 14:26:45 -0300 | [diff] [blame] | 664 | u32 lvds1_clk_sel; |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 665 | |
| 666 | /* |
| 667 | * Here be dragons! |
| 668 | * |
| 669 | * The register ANATOP_MISC1 is not documented in the Freescale |
| 670 | * MX6RM. The register that is mapped in the ANATOP space and |
| 671 | * marked as ANATOP_MISC1 is actually documented in the PMU section |
| 672 | * of the datasheet as PMU_MISC1. |
| 673 | * |
Fabio Estevam | 1b8ad74 | 2014-08-25 14:26:45 -0300 | [diff] [blame] | 674 | * Switch LVDS clock source to SATA (0xb) on mx6q/dl or PCI (0xa) on |
| 675 | * mx6sx, disable clock INPUT and enable clock OUTPUT. This is important |
| 676 | * for PCI express link that is clocked from the i.MX6. |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 677 | */ |
| 678 | #define ANADIG_ANA_MISC1_LVDSCLK1_IBEN (1 << 12) |
| 679 | #define ANADIG_ANA_MISC1_LVDSCLK1_OBEN (1 << 10) |
| 680 | #define ANADIG_ANA_MISC1_LVDS1_CLK_SEL_MASK 0x0000001F |
Fabio Estevam | 1b8ad74 | 2014-08-25 14:26:45 -0300 | [diff] [blame] | 681 | #define ANADIG_ANA_MISC1_LVDS1_CLK_SEL_PCIE_REF 0xa |
| 682 | #define ANADIG_ANA_MISC1_LVDS1_CLK_SEL_SATA_REF 0xb |
| 683 | |
| 684 | if (is_cpu_type(MXC_CPU_MX6SX)) |
| 685 | lvds1_clk_sel = ANADIG_ANA_MISC1_LVDS1_CLK_SEL_PCIE_REF; |
| 686 | else |
| 687 | lvds1_clk_sel = ANADIG_ANA_MISC1_LVDS1_CLK_SEL_SATA_REF; |
| 688 | |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 689 | clrsetbits_le32(&anatop_regs->ana_misc1, |
| 690 | ANADIG_ANA_MISC1_LVDSCLK1_IBEN | |
| 691 | ANADIG_ANA_MISC1_LVDS1_CLK_SEL_MASK, |
Fabio Estevam | 1b8ad74 | 2014-08-25 14:26:45 -0300 | [diff] [blame] | 692 | ANADIG_ANA_MISC1_LVDSCLK1_OBEN | lvds1_clk_sel); |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 693 | |
| 694 | /* PCIe reference clock sourced from AXI. */ |
| 695 | clrbits_le32(&ccm_regs->cbcmr, MXC_CCM_CBCMR_PCIE_AXI_CLK_SEL); |
| 696 | |
| 697 | /* Party time! Ungate the clock to the PCIe. */ |
Fabio Estevam | d95b6ab | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 698 | #ifndef CONFIG_MX6SX |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 699 | ungate_sata_clock(); |
Fabio Estevam | d95b6ab | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 700 | #endif |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 701 | ungate_pcie_clock(); |
| 702 | |
| 703 | return enable_enet_pll(BM_ANADIG_PLL_ENET_ENABLE_SATA | |
| 704 | BM_ANADIG_PLL_ENET_ENABLE_PCIE); |
Eric Nelson | 64e7cdb | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Nitin Garg | 36c1ca4 | 2014-09-16 13:33:25 -0500 | [diff] [blame] | 707 | #ifdef CONFIG_SECURE_BOOT |
| 708 | void hab_caam_clock_enable(unsigned char enable) |
| 709 | { |
| 710 | u32 reg; |
| 711 | |
| 712 | /* CG4 ~ CG6, CAAM clocks */ |
| 713 | reg = __raw_readl(&imx_ccm->CCGR0); |
| 714 | if (enable) |
| 715 | reg |= (MXC_CCM_CCGR0_CAAM_WRAPPER_IPG_MASK | |
| 716 | MXC_CCM_CCGR0_CAAM_WRAPPER_ACLK_MASK | |
| 717 | MXC_CCM_CCGR0_CAAM_SECURE_MEM_MASK); |
| 718 | else |
| 719 | reg &= ~(MXC_CCM_CCGR0_CAAM_WRAPPER_IPG_MASK | |
| 720 | MXC_CCM_CCGR0_CAAM_WRAPPER_ACLK_MASK | |
| 721 | MXC_CCM_CCGR0_CAAM_SECURE_MEM_MASK); |
| 722 | __raw_writel(reg, &imx_ccm->CCGR0); |
| 723 | |
| 724 | /* EMI slow clk */ |
| 725 | reg = __raw_readl(&imx_ccm->CCGR6); |
| 726 | if (enable) |
| 727 | reg |= MXC_CCM_CCGR6_EMI_SLOW_MASK; |
| 728 | else |
| 729 | reg &= ~MXC_CCM_CCGR6_EMI_SLOW_MASK; |
| 730 | __raw_writel(reg, &imx_ccm->CCGR6); |
| 731 | } |
| 732 | #endif |
| 733 | |
Nitin Garg | cf202d2 | 2014-11-20 21:14:12 +0800 | [diff] [blame] | 734 | static void enable_pll3(void) |
| 735 | { |
| 736 | struct anatop_regs __iomem *anatop = |
| 737 | (struct anatop_regs __iomem *)ANATOP_BASE_ADDR; |
| 738 | |
| 739 | /* make sure pll3 is enabled */ |
| 740 | if ((readl(&anatop->usb1_pll_480_ctrl) & |
| 741 | BM_ANADIG_USB1_PLL_480_CTRL_LOCK) == 0) { |
| 742 | /* enable pll's power */ |
| 743 | writel(BM_ANADIG_USB1_PLL_480_CTRL_POWER, |
| 744 | &anatop->usb1_pll_480_ctrl_set); |
| 745 | writel(0x80, &anatop->ana_misc2_clr); |
| 746 | /* wait for pll lock */ |
| 747 | while ((readl(&anatop->usb1_pll_480_ctrl) & |
| 748 | BM_ANADIG_USB1_PLL_480_CTRL_LOCK) == 0) |
| 749 | ; |
| 750 | /* disable bypass */ |
| 751 | writel(BM_ANADIG_USB1_PLL_480_CTRL_BYPASS, |
| 752 | &anatop->usb1_pll_480_ctrl_clr); |
| 753 | /* enable pll output */ |
| 754 | writel(BM_ANADIG_USB1_PLL_480_CTRL_ENABLE, |
| 755 | &anatop->usb1_pll_480_ctrl_set); |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | void enable_thermal_clk(void) |
| 760 | { |
| 761 | enable_pll3(); |
| 762 | } |
| 763 | |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 764 | unsigned int mxc_get_clock(enum mxc_clock clk) |
| 765 | { |
| 766 | switch (clk) { |
| 767 | case MXC_ARM_CLK: |
| 768 | return get_mcu_main_clk(); |
| 769 | case MXC_PER_CLK: |
| 770 | return get_periph_clk(); |
| 771 | case MXC_AHB_CLK: |
| 772 | return get_ahb_clk(); |
| 773 | case MXC_IPG_CLK: |
| 774 | return get_ipg_clk(); |
| 775 | case MXC_IPG_PERCLK: |
Matthias Weisser | e7bed5c | 2012-09-24 02:46:53 +0000 | [diff] [blame] | 776 | case MXC_I2C_CLK: |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 777 | return get_ipg_per_clk(); |
| 778 | case MXC_UART_CLK: |
| 779 | return get_uart_clk(); |
| 780 | case MXC_CSPI_CLK: |
| 781 | return get_cspi_clk(); |
| 782 | case MXC_AXI_CLK: |
| 783 | return get_axi_clk(); |
| 784 | case MXC_EMI_SLOW_CLK: |
| 785 | return get_emi_slow_clk(); |
| 786 | case MXC_DDR_CLK: |
| 787 | return get_mmdc_ch0_clk(); |
| 788 | case MXC_ESDHC_CLK: |
| 789 | return get_usdhc_clk(0); |
| 790 | case MXC_ESDHC2_CLK: |
| 791 | return get_usdhc_clk(1); |
| 792 | case MXC_ESDHC3_CLK: |
| 793 | return get_usdhc_clk(2); |
| 794 | case MXC_ESDHC4_CLK: |
| 795 | return get_usdhc_clk(3); |
| 796 | case MXC_SATA_CLK: |
| 797 | return get_ahb_clk(); |
| 798 | default: |
Peng Fan | eb412d7 | 2014-11-23 11:52:20 +0800 | [diff] [blame] | 799 | printf("Unsupported MXC CLK: %d\n", clk); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 800 | break; |
| 801 | } |
| 802 | |
Peng Fan | eb412d7 | 2014-11-23 11:52:20 +0800 | [diff] [blame] | 803 | return 0; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | /* |
| 807 | * Dump some core clockes. |
| 808 | */ |
| 809 | int do_mx6_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 810 | { |
| 811 | u32 freq; |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 812 | freq = decode_pll(PLL_SYS, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 813 | printf("PLL_SYS %8d MHz\n", freq / 1000000); |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 814 | freq = decode_pll(PLL_BUS, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 815 | printf("PLL_BUS %8d MHz\n", freq / 1000000); |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 816 | freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 817 | printf("PLL_OTG %8d MHz\n", freq / 1000000); |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 818 | freq = decode_pll(PLL_ENET, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 819 | printf("PLL_NET %8d MHz\n", freq / 1000000); |
| 820 | |
| 821 | printf("\n"); |
| 822 | printf("IPG %8d kHz\n", mxc_get_clock(MXC_IPG_CLK) / 1000); |
| 823 | printf("UART %8d kHz\n", mxc_get_clock(MXC_UART_CLK) / 1000); |
Fabio Estevam | cc44672 | 2012-11-16 01:30:10 +0000 | [diff] [blame] | 824 | #ifdef CONFIG_MXC_SPI |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 825 | printf("CSPI %8d kHz\n", mxc_get_clock(MXC_CSPI_CLK) / 1000); |
Fabio Estevam | cc44672 | 2012-11-16 01:30:10 +0000 | [diff] [blame] | 826 | #endif |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 827 | printf("AHB %8d kHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000); |
| 828 | printf("AXI %8d kHz\n", mxc_get_clock(MXC_AXI_CLK) / 1000); |
| 829 | printf("DDR %8d kHz\n", mxc_get_clock(MXC_DDR_CLK) / 1000); |
| 830 | printf("USDHC1 %8d kHz\n", mxc_get_clock(MXC_ESDHC_CLK) / 1000); |
| 831 | printf("USDHC2 %8d kHz\n", mxc_get_clock(MXC_ESDHC2_CLK) / 1000); |
| 832 | printf("USDHC3 %8d kHz\n", mxc_get_clock(MXC_ESDHC3_CLK) / 1000); |
| 833 | printf("USDHC4 %8d kHz\n", mxc_get_clock(MXC_ESDHC4_CLK) / 1000); |
| 834 | printf("EMI SLOW %8d kHz\n", mxc_get_clock(MXC_EMI_SLOW_CLK) / 1000); |
| 835 | printf("IPG PERCLK %8d kHz\n", mxc_get_clock(MXC_IPG_PERCLK) / 1000); |
| 836 | |
| 837 | return 0; |
| 838 | } |
| 839 | |
Fabio Estevam | d95b6ab | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 840 | #ifndef CONFIG_MX6SX |
Pardeep Kumar Singla | 5ea7f0e | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 841 | void enable_ipu_clock(void) |
| 842 | { |
| 843 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 844 | int reg; |
| 845 | reg = readl(&mxc_ccm->CCGR3); |
Pierre Aubert | a0a0dac | 2013-09-23 13:37:20 +0200 | [diff] [blame] | 846 | reg |= MXC_CCM_CCGR3_IPU1_IPU_MASK; |
Pardeep Kumar Singla | 5ea7f0e | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 847 | writel(reg, &mxc_ccm->CCGR3); |
| 848 | } |
Fabio Estevam | d95b6ab | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 849 | #endif |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 850 | /***************************************************/ |
| 851 | |
| 852 | U_BOOT_CMD( |
| 853 | clocks, CONFIG_SYS_MAXARGS, 1, do_mx6_showclocks, |
| 854 | "display clocks", |
| 855 | "" |
| 856 | ); |