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