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