Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2010-2011 Freescale Semiconductor, Inc. |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Christian Gmeiner | e584814 | 2014-01-08 08:24:25 +0100 | [diff] [blame] | 7 | #include <div64.h> |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 8 | #include <asm/io.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 9 | #include <linux/errno.h> |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 10 | #include <asm/arch/imx-regs.h> |
Fabio Estevam | 6479f51 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 11 | #include <asm/arch/crm_regs.h> |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 12 | #include <asm/arch/clock.h> |
Fabio Estevam | 6479f51 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 13 | #include <asm/arch/sys_proto.h> |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 14 | |
| 15 | enum pll_clocks { |
| 16 | PLL_SYS, /* System PLL */ |
| 17 | PLL_BUS, /* System Bus PLL*/ |
| 18 | PLL_USBOTG, /* OTG USB PLL */ |
| 19 | PLL_ENET, /* ENET PLL */ |
Peng Fan | bd0c46f | 2016-01-06 11:06:31 +0800 | [diff] [blame] | 20 | PLL_AUDIO, /* AUDIO PLL */ |
Anatolij Gustschin | 705d5d7 | 2017-08-02 16:05:12 +0200 | [diff] [blame] | 21 | PLL_VIDEO, /* VIDEO PLL */ |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
Fabio Estevam | 6479f51 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 24 | 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] | 25 | |
Benoît Thébaudeau | 20db631 | 2013-04-23 10:17:44 +0000 | [diff] [blame] | 26 | #ifdef CONFIG_MXC_OCOTP |
| 27 | void enable_ocotp_clk(unsigned char enable) |
| 28 | { |
| 29 | u32 reg; |
| 30 | |
| 31 | reg = __raw_readl(&imx_ccm->CCGR2); |
| 32 | if (enable) |
| 33 | reg |= MXC_CCM_CCGR2_OCOTP_CTRL_MASK; |
| 34 | else |
| 35 | reg &= ~MXC_CCM_CCGR2_OCOTP_CTRL_MASK; |
| 36 | __raw_writel(reg, &imx_ccm->CCGR2); |
| 37 | } |
| 38 | #endif |
| 39 | |
Nikita Kiryanov | 98b76b4 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 40 | #ifdef CONFIG_NAND_MXS |
| 41 | void setup_gpmi_io_clk(u32 cfg) |
| 42 | { |
| 43 | /* Disable clocks per ERR007177 from MX6 errata */ |
| 44 | clrbits_le32(&imx_ccm->CCGR4, |
| 45 | MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK | |
| 46 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK | |
| 47 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK | |
| 48 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK | |
| 49 | MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK); |
| 50 | |
Ye.Li | 1475bff | 2015-01-12 16:46:17 +0800 | [diff] [blame] | 51 | #if defined(CONFIG_MX6SX) |
| 52 | clrbits_le32(&imx_ccm->CCGR4, MXC_CCM_CCGR4_QSPI2_ENFC_MASK); |
| 53 | |
| 54 | clrsetbits_le32(&imx_ccm->cs2cdr, |
| 55 | MXC_CCM_CS2CDR_QSPI2_CLK_PODF_MASK | |
| 56 | MXC_CCM_CS2CDR_QSPI2_CLK_PRED_MASK | |
| 57 | MXC_CCM_CS2CDR_QSPI2_CLK_SEL_MASK, |
| 58 | cfg); |
| 59 | |
| 60 | setbits_le32(&imx_ccm->CCGR4, MXC_CCM_CCGR4_QSPI2_ENFC_MASK); |
| 61 | #else |
Nikita Kiryanov | 98b76b4 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 62 | clrbits_le32(&imx_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK); |
| 63 | |
| 64 | clrsetbits_le32(&imx_ccm->cs2cdr, |
| 65 | MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK | |
| 66 | MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK | |
| 67 | MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK, |
| 68 | cfg); |
| 69 | |
| 70 | setbits_le32(&imx_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK); |
Ye.Li | 1475bff | 2015-01-12 16:46:17 +0800 | [diff] [blame] | 71 | #endif |
Nikita Kiryanov | 98b76b4 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 72 | setbits_le32(&imx_ccm->CCGR4, |
| 73 | MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK | |
| 74 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK | |
| 75 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK | |
| 76 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK | |
| 77 | MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK); |
| 78 | } |
| 79 | #endif |
| 80 | |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 81 | void enable_usboh3_clk(unsigned char enable) |
| 82 | { |
| 83 | u32 reg; |
| 84 | |
| 85 | reg = __raw_readl(&imx_ccm->CCGR6); |
| 86 | if (enable) |
Eric Nelson | e427954 | 2012-09-21 07:33:51 +0000 | [diff] [blame] | 87 | reg |= MXC_CCM_CCGR6_USBOH3_MASK; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 88 | else |
Eric Nelson | e427954 | 2012-09-21 07:33:51 +0000 | [diff] [blame] | 89 | reg &= ~(MXC_CCM_CCGR6_USBOH3_MASK); |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 90 | __raw_writel(reg, &imx_ccm->CCGR6); |
| 91 | |
Nikita Kiryanov | 98b76b4 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 92 | } |
| 93 | |
Stefano Babic | 198249b | 2014-09-10 13:02:40 +0200 | [diff] [blame] | 94 | #if defined(CONFIG_FEC_MXC) && !defined(CONFIG_MX6SX) |
Nikita Kiryanov | 98b76b4 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 95 | void enable_enet_clk(unsigned char enable) |
| 96 | { |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 97 | u32 mask, *addr; |
| 98 | |
Peng Fan | ce7a712 | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 99 | if (is_mx6ull()) { |
| 100 | mask = MXC_CCM_CCGR0_ENET_CLK_ENABLE_MASK; |
| 101 | addr = &imx_ccm->CCGR0; |
| 102 | } else if (is_mx6ul()) { |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 103 | mask = MXC_CCM_CCGR3_ENET_MASK; |
| 104 | addr = &imx_ccm->CCGR3; |
| 105 | } else { |
| 106 | mask = MXC_CCM_CCGR1_ENET_MASK; |
| 107 | addr = &imx_ccm->CCGR1; |
| 108 | } |
Nikita Kiryanov | 98b76b4 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 109 | |
| 110 | if (enable) |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 111 | setbits_le32(addr, mask); |
Nikita Kiryanov | 98b76b4 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 112 | else |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 113 | clrbits_le32(addr, mask); |
Nikita Kiryanov | 98b76b4 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 114 | } |
| 115 | #endif |
| 116 | |
| 117 | #ifdef CONFIG_MXC_UART |
| 118 | void enable_uart_clk(unsigned char enable) |
| 119 | { |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 120 | u32 mask; |
| 121 | |
Peng Fan | ce7a712 | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 122 | if (is_mx6ul() || is_mx6ull()) |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 123 | mask = MXC_CCM_CCGR5_UART_MASK; |
| 124 | else |
| 125 | mask = MXC_CCM_CCGR5_UART_MASK | MXC_CCM_CCGR5_UART_SERIAL_MASK; |
Nikita Kiryanov | 98b76b4 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 126 | |
| 127 | if (enable) |
| 128 | setbits_le32(&imx_ccm->CCGR5, mask); |
| 129 | else |
| 130 | clrbits_le32(&imx_ccm->CCGR5, mask); |
| 131 | } |
| 132 | #endif |
| 133 | |
Nikita Kiryanov | 98b76b4 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 134 | #ifdef CONFIG_MMC |
| 135 | int enable_usdhc_clk(unsigned char enable, unsigned bus_num) |
| 136 | { |
| 137 | u32 mask; |
| 138 | |
| 139 | if (bus_num > 3) |
| 140 | return -EINVAL; |
| 141 | |
| 142 | mask = MXC_CCM_CCGR_CG_MASK << (bus_num * 2 + 2); |
| 143 | if (enable) |
| 144 | setbits_le32(&imx_ccm->CCGR6, mask); |
| 145 | else |
| 146 | clrbits_le32(&imx_ccm->CCGR6, mask); |
| 147 | |
| 148 | return 0; |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 149 | } |
Nikita Kiryanov | 98b76b4 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 150 | #endif |
Wolfgang Grandegger | 1859b70 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 151 | |
trem | a49f40a | 2013-09-21 18:13:35 +0200 | [diff] [blame] | 152 | #ifdef CONFIG_SYS_I2C_MXC |
Heiko Schocher | 5c4b1e9 | 2015-05-18 10:56:24 +0200 | [diff] [blame] | 153 | /* i2c_num can be from 0 - 3 */ |
Troy Kisky | d4fdc99 | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 154 | int enable_i2c_clk(unsigned char enable, unsigned i2c_num) |
| 155 | { |
| 156 | u32 reg; |
| 157 | u32 mask; |
Peng Fan | d847db7 | 2015-07-01 17:01:50 +0800 | [diff] [blame] | 158 | u32 *addr; |
Troy Kisky | d4fdc99 | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 159 | |
Heiko Schocher | 5c4b1e9 | 2015-05-18 10:56:24 +0200 | [diff] [blame] | 160 | if (i2c_num > 3) |
Troy Kisky | d4fdc99 | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 161 | return -EINVAL; |
Heiko Schocher | 5c4b1e9 | 2015-05-18 10:56:24 +0200 | [diff] [blame] | 162 | if (i2c_num < 3) { |
| 163 | mask = MXC_CCM_CCGR_CG_MASK |
| 164 | << (MXC_CCM_CCGR2_I2C1_SERIAL_OFFSET |
| 165 | + (i2c_num << 1)); |
| 166 | reg = __raw_readl(&imx_ccm->CCGR2); |
| 167 | if (enable) |
| 168 | reg |= mask; |
| 169 | else |
| 170 | reg &= ~mask; |
| 171 | __raw_writel(reg, &imx_ccm->CCGR2); |
| 172 | } else { |
Peng Fan | 7e2e209 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 173 | if (is_mx6sll()) |
| 174 | return -EINVAL; |
Peng Fan | ce7a712 | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 175 | if (is_mx6sx() || is_mx6ul() || is_mx6ull()) { |
Peng Fan | d847db7 | 2015-07-01 17:01:50 +0800 | [diff] [blame] | 176 | mask = MXC_CCM_CCGR6_I2C4_MASK; |
| 177 | addr = &imx_ccm->CCGR6; |
| 178 | } else { |
| 179 | mask = MXC_CCM_CCGR1_I2C4_SERIAL_MASK; |
| 180 | addr = &imx_ccm->CCGR1; |
| 181 | } |
| 182 | reg = __raw_readl(addr); |
Heiko Schocher | 5c4b1e9 | 2015-05-18 10:56:24 +0200 | [diff] [blame] | 183 | if (enable) |
| 184 | reg |= mask; |
| 185 | else |
| 186 | reg &= ~mask; |
Peng Fan | d847db7 | 2015-07-01 17:01:50 +0800 | [diff] [blame] | 187 | __raw_writel(reg, addr); |
Heiko Schocher | 5c4b1e9 | 2015-05-18 10:56:24 +0200 | [diff] [blame] | 188 | } |
Troy Kisky | d4fdc99 | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | #endif |
| 192 | |
Heiko Schocher | 472a68f | 2014-07-18 06:07:20 +0200 | [diff] [blame] | 193 | /* spi_num can be from 0 - SPI_MAX_NUM */ |
| 194 | int enable_spi_clk(unsigned char enable, unsigned spi_num) |
| 195 | { |
| 196 | u32 reg; |
| 197 | u32 mask; |
| 198 | |
| 199 | if (spi_num > SPI_MAX_NUM) |
| 200 | return -EINVAL; |
| 201 | |
| 202 | mask = MXC_CCM_CCGR_CG_MASK << (spi_num << 1); |
| 203 | reg = __raw_readl(&imx_ccm->CCGR1); |
| 204 | if (enable) |
| 205 | reg |= mask; |
| 206 | else |
| 207 | reg &= ~mask; |
| 208 | __raw_writel(reg, &imx_ccm->CCGR1); |
| 209 | return 0; |
| 210 | } |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 211 | static u32 decode_pll(enum pll_clocks pll, u32 infreq) |
| 212 | { |
Peng Fan | bd0c46f | 2016-01-06 11:06:31 +0800 | [diff] [blame] | 213 | u32 div, test_div, pll_num, pll_denom; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 214 | |
| 215 | switch (pll) { |
| 216 | case PLL_SYS: |
| 217 | div = __raw_readl(&imx_ccm->analog_pll_sys); |
| 218 | div &= BM_ANADIG_PLL_SYS_DIV_SELECT; |
| 219 | |
Andre Renaud | b0be82e | 2014-06-10 08:47:13 +1200 | [diff] [blame] | 220 | return (infreq * div) >> 1; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 221 | case PLL_BUS: |
| 222 | div = __raw_readl(&imx_ccm->analog_pll_528); |
| 223 | div &= BM_ANADIG_PLL_528_DIV_SELECT; |
| 224 | |
| 225 | return infreq * (20 + (div << 1)); |
| 226 | case PLL_USBOTG: |
| 227 | div = __raw_readl(&imx_ccm->analog_usb1_pll_480_ctrl); |
| 228 | div &= BM_ANADIG_USB1_PLL_480_CTRL_DIV_SELECT; |
| 229 | |
| 230 | return infreq * (20 + (div << 1)); |
| 231 | case PLL_ENET: |
| 232 | div = __raw_readl(&imx_ccm->analog_pll_enet); |
| 233 | div &= BM_ANADIG_PLL_ENET_DIV_SELECT; |
| 234 | |
Fabio Estevam | 93bc8ea | 2013-12-03 18:26:13 -0200 | [diff] [blame] | 235 | return 25000000 * (div + (div >> 1) + 1); |
Peng Fan | bd0c46f | 2016-01-06 11:06:31 +0800 | [diff] [blame] | 236 | case PLL_AUDIO: |
| 237 | div = __raw_readl(&imx_ccm->analog_pll_audio); |
| 238 | if (!(div & BM_ANADIG_PLL_AUDIO_ENABLE)) |
| 239 | return 0; |
| 240 | /* BM_ANADIG_PLL_AUDIO_BYPASS_CLK_SRC is ignored */ |
| 241 | if (div & BM_ANADIG_PLL_AUDIO_BYPASS) |
| 242 | return MXC_HCLK; |
| 243 | pll_num = __raw_readl(&imx_ccm->analog_pll_audio_num); |
| 244 | pll_denom = __raw_readl(&imx_ccm->analog_pll_audio_denom); |
| 245 | test_div = (div & BM_ANADIG_PLL_AUDIO_TEST_DIV_SELECT) >> |
| 246 | BP_ANADIG_PLL_AUDIO_TEST_DIV_SELECT; |
| 247 | div &= BM_ANADIG_PLL_AUDIO_DIV_SELECT; |
| 248 | if (test_div == 3) { |
| 249 | debug("Error test_div\n"); |
| 250 | return 0; |
| 251 | } |
| 252 | test_div = 1 << (2 - test_div); |
| 253 | |
| 254 | return infreq * (div + pll_num / pll_denom) / test_div; |
| 255 | case PLL_VIDEO: |
| 256 | div = __raw_readl(&imx_ccm->analog_pll_video); |
| 257 | if (!(div & BM_ANADIG_PLL_VIDEO_ENABLE)) |
| 258 | return 0; |
| 259 | /* BM_ANADIG_PLL_AUDIO_BYPASS_CLK_SRC is ignored */ |
| 260 | if (div & BM_ANADIG_PLL_VIDEO_BYPASS) |
| 261 | return MXC_HCLK; |
| 262 | pll_num = __raw_readl(&imx_ccm->analog_pll_video_num); |
| 263 | pll_denom = __raw_readl(&imx_ccm->analog_pll_video_denom); |
| 264 | test_div = (div & BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT) >> |
| 265 | BP_ANADIG_PLL_VIDEO_POST_DIV_SELECT; |
| 266 | div &= BM_ANADIG_PLL_VIDEO_DIV_SELECT; |
| 267 | if (test_div == 3) { |
| 268 | debug("Error test_div\n"); |
| 269 | return 0; |
| 270 | } |
| 271 | test_div = 1 << (2 - test_div); |
| 272 | |
| 273 | return infreq * (div + pll_num / pll_denom) / test_div; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 274 | default: |
| 275 | return 0; |
| 276 | } |
| 277 | /* NOTREACHED */ |
| 278 | } |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 279 | static u32 mxc_get_pll_pfd(enum pll_clocks pll, int pfd_num) |
| 280 | { |
| 281 | u32 div; |
| 282 | u64 freq; |
| 283 | |
| 284 | switch (pll) { |
| 285 | case PLL_BUS: |
Peng Fan | ce7a712 | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 286 | if (!is_mx6ul() && !is_mx6ull()) { |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 287 | if (pfd_num == 3) { |
Peng Fan | 8bed5f9 | 2016-06-30 21:08:00 +0800 | [diff] [blame] | 288 | /* No PFD3 on PLL2 */ |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 289 | return 0; |
| 290 | } |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 291 | } |
| 292 | div = __raw_readl(&imx_ccm->analog_pfd_528); |
| 293 | freq = (u64)decode_pll(PLL_BUS, MXC_HCLK); |
| 294 | break; |
| 295 | case PLL_USBOTG: |
| 296 | div = __raw_readl(&imx_ccm->analog_pfd_480); |
| 297 | freq = (u64)decode_pll(PLL_USBOTG, MXC_HCLK); |
| 298 | break; |
| 299 | default: |
| 300 | /* No PFD on other PLL */ |
| 301 | return 0; |
| 302 | } |
| 303 | |
Christian Gmeiner | e584814 | 2014-01-08 08:24:25 +0100 | [diff] [blame] | 304 | return lldiv(freq * 18, (div & ANATOP_PFD_FRAC_MASK(pfd_num)) >> |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 305 | ANATOP_PFD_FRAC_SHIFT(pfd_num)); |
| 306 | } |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 307 | |
| 308 | static u32 get_mcu_main_clk(void) |
| 309 | { |
| 310 | u32 reg, freq; |
| 311 | |
| 312 | reg = __raw_readl(&imx_ccm->cacrr); |
| 313 | reg &= MXC_CCM_CACRR_ARM_PODF_MASK; |
| 314 | reg >>= MXC_CCM_CACRR_ARM_PODF_OFFSET; |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 315 | freq = decode_pll(PLL_SYS, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 316 | |
| 317 | return freq / (reg + 1); |
| 318 | } |
| 319 | |
Fabio Estevam | 6479f51 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 320 | u32 get_periph_clk(void) |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 321 | { |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 322 | u32 reg, div = 0, freq = 0; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 323 | |
| 324 | reg = __raw_readl(&imx_ccm->cbcdr); |
| 325 | if (reg & MXC_CCM_CBCDR_PERIPH_CLK_SEL) { |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 326 | div = (reg & MXC_CCM_CBCDR_PERIPH_CLK2_PODF_MASK) >> |
| 327 | MXC_CCM_CBCDR_PERIPH_CLK2_PODF_OFFSET; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 328 | reg = __raw_readl(&imx_ccm->cbcmr); |
| 329 | reg &= MXC_CCM_CBCMR_PERIPH_CLK2_SEL_MASK; |
| 330 | reg >>= MXC_CCM_CBCMR_PERIPH_CLK2_SEL_OFFSET; |
| 331 | |
| 332 | switch (reg) { |
| 333 | case 0: |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 334 | freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 335 | break; |
| 336 | case 1: |
| 337 | case 2: |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 338 | freq = MXC_HCLK; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 339 | break; |
| 340 | default: |
| 341 | break; |
| 342 | } |
| 343 | } else { |
| 344 | reg = __raw_readl(&imx_ccm->cbcmr); |
| 345 | reg &= MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK; |
| 346 | reg >>= MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET; |
| 347 | |
| 348 | switch (reg) { |
| 349 | case 0: |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 350 | freq = decode_pll(PLL_BUS, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 351 | break; |
| 352 | case 1: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 353 | freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 354 | break; |
| 355 | case 2: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 356 | freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 357 | break; |
| 358 | case 3: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 359 | /* static / 2 divider */ |
| 360 | freq = mxc_get_pll_pfd(PLL_BUS, 2) / 2; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 361 | break; |
| 362 | default: |
| 363 | break; |
| 364 | } |
| 365 | } |
| 366 | |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 367 | return freq / (div + 1); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 370 | static u32 get_ipg_clk(void) |
| 371 | { |
| 372 | u32 reg, ipg_podf; |
| 373 | |
| 374 | reg = __raw_readl(&imx_ccm->cbcdr); |
| 375 | reg &= MXC_CCM_CBCDR_IPG_PODF_MASK; |
| 376 | ipg_podf = reg >> MXC_CCM_CBCDR_IPG_PODF_OFFSET; |
| 377 | |
| 378 | return get_ahb_clk() / (ipg_podf + 1); |
| 379 | } |
| 380 | |
| 381 | static u32 get_ipg_per_clk(void) |
| 382 | { |
| 383 | u32 reg, perclk_podf; |
| 384 | |
| 385 | reg = __raw_readl(&imx_ccm->cscmr1); |
Peng Fan | 7e2e209 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 386 | if (is_mx6sll() || is_mx6sl() || is_mx6sx() || |
Peng Fan | ce7a712 | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 387 | is_mx6dqp() || is_mx6ul() || is_mx6ull()) { |
Peng Fan | 53f3c9e | 2015-07-11 11:38:43 +0800 | [diff] [blame] | 388 | if (reg & MXC_CCM_CSCMR1_PER_CLK_SEL_MASK) |
| 389 | return MXC_HCLK; /* OSC 24Mhz */ |
| 390 | } |
| 391 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 392 | perclk_podf = reg & MXC_CCM_CSCMR1_PERCLK_PODF_MASK; |
| 393 | |
| 394 | return get_ipg_clk() / (perclk_podf + 1); |
| 395 | } |
| 396 | |
| 397 | static u32 get_uart_clk(void) |
| 398 | { |
| 399 | u32 reg, uart_podf; |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 400 | u32 freq = decode_pll(PLL_USBOTG, MXC_HCLK) / 6; /* static divider */ |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 401 | reg = __raw_readl(&imx_ccm->cscdr1); |
Peng Fan | 53f3c9e | 2015-07-11 11:38:43 +0800 | [diff] [blame] | 402 | |
Peng Fan | ce7a712 | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 403 | if (is_mx6sl() || is_mx6sx() || is_mx6dqp() || is_mx6ul() || |
Peng Fan | 7e2e209 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 404 | is_mx6sll() || is_mx6ull()) { |
Peng Fan | 53f3c9e | 2015-07-11 11:38:43 +0800 | [diff] [blame] | 405 | if (reg & MXC_CCM_CSCDR1_UART_CLK_SEL) |
| 406 | freq = MXC_HCLK; |
| 407 | } |
| 408 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 409 | reg &= MXC_CCM_CSCDR1_UART_CLK_PODF_MASK; |
| 410 | uart_podf = reg >> MXC_CCM_CSCDR1_UART_CLK_PODF_OFFSET; |
| 411 | |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 412 | return freq / (uart_podf + 1); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static u32 get_cspi_clk(void) |
| 416 | { |
| 417 | u32 reg, cspi_podf; |
| 418 | |
| 419 | reg = __raw_readl(&imx_ccm->cscdr2); |
Peng Fan | 53f3c9e | 2015-07-11 11:38:43 +0800 | [diff] [blame] | 420 | cspi_podf = (reg & MXC_CCM_CSCDR2_ECSPI_CLK_PODF_MASK) >> |
| 421 | MXC_CCM_CSCDR2_ECSPI_CLK_PODF_OFFSET; |
| 422 | |
Peng Fan | ce7a712 | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 423 | if (is_mx6dqp() || is_mx6sl() || is_mx6sx() || is_mx6ul() || |
Peng Fan | 7e2e209 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 424 | is_mx6sll() || is_mx6ull()) { |
Peng Fan | 53f3c9e | 2015-07-11 11:38:43 +0800 | [diff] [blame] | 425 | if (reg & MXC_CCM_CSCDR2_ECSPI_CLK_SEL_MASK) |
| 426 | return MXC_HCLK / (cspi_podf + 1); |
| 427 | } |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 428 | |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 429 | return decode_pll(PLL_USBOTG, MXC_HCLK) / (8 * (cspi_podf + 1)); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | static u32 get_axi_clk(void) |
| 433 | { |
| 434 | u32 root_freq, axi_podf; |
| 435 | u32 cbcdr = __raw_readl(&imx_ccm->cbcdr); |
| 436 | |
| 437 | axi_podf = cbcdr & MXC_CCM_CBCDR_AXI_PODF_MASK; |
| 438 | axi_podf >>= MXC_CCM_CBCDR_AXI_PODF_OFFSET; |
| 439 | |
| 440 | if (cbcdr & MXC_CCM_CBCDR_AXI_SEL) { |
| 441 | if (cbcdr & MXC_CCM_CBCDR_AXI_ALT_SEL) |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 442 | root_freq = mxc_get_pll_pfd(PLL_USBOTG, 1); |
Fabio Estevam | 50f78c9 | 2016-07-18 10:19:28 -0300 | [diff] [blame] | 443 | else |
| 444 | root_freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 445 | } else |
| 446 | root_freq = get_periph_clk(); |
| 447 | |
| 448 | return root_freq / (axi_podf + 1); |
| 449 | } |
| 450 | |
| 451 | static u32 get_emi_slow_clk(void) |
| 452 | { |
Andrew Gabbasov | 4740e24 | 2013-07-04 06:27:32 -0500 | [diff] [blame] | 453 | u32 emi_clk_sel, emi_slow_podf, cscmr1, root_freq = 0; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 454 | |
| 455 | cscmr1 = __raw_readl(&imx_ccm->cscmr1); |
| 456 | emi_clk_sel = cscmr1 & MXC_CCM_CSCMR1_ACLK_EMI_SLOW_MASK; |
| 457 | emi_clk_sel >>= MXC_CCM_CSCMR1_ACLK_EMI_SLOW_OFFSET; |
Andrew Gabbasov | 4740e24 | 2013-07-04 06:27:32 -0500 | [diff] [blame] | 458 | emi_slow_podf = cscmr1 & MXC_CCM_CSCMR1_ACLK_EMI_SLOW_PODF_MASK; |
| 459 | emi_slow_podf >>= MXC_CCM_CSCMR1_ACLK_EMI_SLOW_PODF_OFFSET; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 460 | |
| 461 | switch (emi_clk_sel) { |
| 462 | case 0: |
| 463 | root_freq = get_axi_clk(); |
| 464 | break; |
| 465 | case 1: |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 466 | root_freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 467 | break; |
| 468 | case 2: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 469 | root_freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 470 | break; |
| 471 | case 3: |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 472 | root_freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 473 | break; |
| 474 | } |
| 475 | |
Andrew Gabbasov | 4740e24 | 2013-07-04 06:27:32 -0500 | [diff] [blame] | 476 | return root_freq / (emi_slow_podf + 1); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 479 | static u32 get_mmdc_ch0_clk(void) |
| 480 | { |
| 481 | u32 cbcmr = __raw_readl(&imx_ccm->cbcmr); |
| 482 | u32 cbcdr = __raw_readl(&imx_ccm->cbcdr); |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 483 | |
Peng Fan | bd0c46f | 2016-01-06 11:06:31 +0800 | [diff] [blame] | 484 | u32 freq, podf, per2_clk2_podf, pmu_misc2_audio_div; |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 485 | |
Peng Fan | 7e2e209 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 486 | if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl() || |
| 487 | is_mx6sll()) { |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 488 | podf = (cbcdr & MXC_CCM_CBCDR_MMDC_CH1_PODF_MASK) >> |
| 489 | MXC_CCM_CBCDR_MMDC_CH1_PODF_OFFSET; |
| 490 | if (cbcdr & MXC_CCM_CBCDR_PERIPH2_CLK_SEL) { |
| 491 | per2_clk2_podf = (cbcdr & MXC_CCM_CBCDR_PERIPH2_CLK2_PODF_MASK) >> |
| 492 | MXC_CCM_CBCDR_PERIPH2_CLK2_PODF_OFFSET; |
Peng Fan | 6861c5a | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 493 | if (is_mx6sl()) { |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 494 | if (cbcmr & MXC_CCM_CBCMR_PERIPH2_CLK2_SEL) |
| 495 | freq = MXC_HCLK; |
| 496 | else |
| 497 | freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
| 498 | } else { |
| 499 | if (cbcmr & MXC_CCM_CBCMR_PERIPH2_CLK2_SEL) |
| 500 | freq = decode_pll(PLL_BUS, MXC_HCLK); |
| 501 | else |
| 502 | freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
| 503 | } |
| 504 | } else { |
| 505 | per2_clk2_podf = 0; |
| 506 | switch ((cbcmr & |
| 507 | MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK) >> |
| 508 | MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET) { |
| 509 | case 0: |
| 510 | freq = decode_pll(PLL_BUS, MXC_HCLK); |
| 511 | break; |
| 512 | case 1: |
| 513 | freq = mxc_get_pll_pfd(PLL_BUS, 2); |
| 514 | break; |
| 515 | case 2: |
| 516 | freq = mxc_get_pll_pfd(PLL_BUS, 0); |
| 517 | break; |
| 518 | case 3: |
Peng Fan | 5dbddb1 | 2016-12-11 19:24:25 +0800 | [diff] [blame] | 519 | if (is_mx6sl()) { |
| 520 | freq = mxc_get_pll_pfd(PLL_BUS, 2) >> 1; |
| 521 | break; |
| 522 | } |
| 523 | |
Peng Fan | bd0c46f | 2016-01-06 11:06:31 +0800 | [diff] [blame] | 524 | pmu_misc2_audio_div = PMU_MISC2_AUDIO_DIV(__raw_readl(&imx_ccm->pmu_misc2)); |
| 525 | switch (pmu_misc2_audio_div) { |
| 526 | case 0: |
| 527 | case 2: |
| 528 | pmu_misc2_audio_div = 1; |
| 529 | break; |
| 530 | case 1: |
| 531 | pmu_misc2_audio_div = 2; |
| 532 | break; |
| 533 | case 3: |
| 534 | pmu_misc2_audio_div = 4; |
| 535 | break; |
| 536 | } |
| 537 | freq = decode_pll(PLL_AUDIO, MXC_HCLK) / |
| 538 | pmu_misc2_audio_div; |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 539 | break; |
| 540 | } |
| 541 | } |
| 542 | return freq / (podf + 1) / (per2_clk2_podf + 1); |
| 543 | } else { |
| 544 | podf = (cbcdr & MXC_CCM_CBCDR_MMDC_CH0_PODF_MASK) >> |
| 545 | MXC_CCM_CBCDR_MMDC_CH0_PODF_OFFSET; |
| 546 | return get_periph_clk() / (podf + 1); |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 547 | } |
Otavio Salvador | dc07443 | 2013-12-16 20:44:05 -0200 | [diff] [blame] | 548 | } |
Otavio Salvador | dc07443 | 2013-12-16 20:44:05 -0200 | [diff] [blame] | 549 | |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 550 | #if defined(CONFIG_VIDEO_MXS) |
| 551 | static int enable_pll_video(u32 pll_div, u32 pll_num, u32 pll_denom, |
| 552 | u32 post_div) |
| 553 | { |
| 554 | u32 reg = 0; |
| 555 | ulong start; |
| 556 | |
| 557 | debug("pll5 div = %d, num = %d, denom = %d\n", |
| 558 | pll_div, pll_num, pll_denom); |
| 559 | |
| 560 | /* Power up PLL5 video */ |
| 561 | writel(BM_ANADIG_PLL_VIDEO_POWERDOWN | |
| 562 | BM_ANADIG_PLL_VIDEO_BYPASS | |
| 563 | BM_ANADIG_PLL_VIDEO_DIV_SELECT | |
| 564 | BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT, |
| 565 | &imx_ccm->analog_pll_video_clr); |
| 566 | |
| 567 | /* Set div, num and denom */ |
| 568 | switch (post_div) { |
| 569 | case 1: |
| 570 | writel(BF_ANADIG_PLL_VIDEO_DIV_SELECT(pll_div) | |
| 571 | BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(0x2), |
| 572 | &imx_ccm->analog_pll_video_set); |
| 573 | break; |
| 574 | case 2: |
| 575 | writel(BF_ANADIG_PLL_VIDEO_DIV_SELECT(pll_div) | |
| 576 | BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(0x1), |
| 577 | &imx_ccm->analog_pll_video_set); |
| 578 | break; |
| 579 | case 4: |
| 580 | writel(BF_ANADIG_PLL_VIDEO_DIV_SELECT(pll_div) | |
| 581 | BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(0x0), |
| 582 | &imx_ccm->analog_pll_video_set); |
| 583 | break; |
| 584 | default: |
| 585 | puts("Wrong test_div!\n"); |
| 586 | return -EINVAL; |
| 587 | } |
| 588 | |
| 589 | writel(BF_ANADIG_PLL_VIDEO_NUM_A(pll_num), |
| 590 | &imx_ccm->analog_pll_video_num); |
| 591 | writel(BF_ANADIG_PLL_VIDEO_DENOM_B(pll_denom), |
| 592 | &imx_ccm->analog_pll_video_denom); |
| 593 | |
| 594 | /* Wait PLL5 lock */ |
| 595 | start = get_timer(0); /* Get current timestamp */ |
| 596 | |
| 597 | do { |
| 598 | reg = readl(&imx_ccm->analog_pll_video); |
| 599 | if (reg & BM_ANADIG_PLL_VIDEO_LOCK) { |
| 600 | /* Enable PLL out */ |
| 601 | writel(BM_ANADIG_PLL_VIDEO_ENABLE, |
| 602 | &imx_ccm->analog_pll_video_set); |
| 603 | return 0; |
| 604 | } |
| 605 | } while (get_timer(0) < (start + 10)); /* Wait 10ms */ |
| 606 | |
| 607 | puts("Lock PLL5 timeout\n"); |
| 608 | |
| 609 | return -ETIME; |
| 610 | } |
| 611 | |
| 612 | /* |
| 613 | * 24M--> PLL_VIDEO -> LCDIFx_PRED -> LCDIFx_PODF -> LCD |
| 614 | * |
| 615 | * 'freq' using KHz as unit, see driver/video/mxsfb.c. |
| 616 | */ |
| 617 | void mxs_set_lcdclk(u32 base_addr, u32 freq) |
| 618 | { |
| 619 | u32 reg = 0; |
| 620 | u32 hck = MXC_HCLK / 1000; |
| 621 | /* DIV_SELECT ranges from 27 to 54 */ |
| 622 | u32 min = hck * 27; |
| 623 | u32 max = hck * 54; |
| 624 | u32 temp, best = 0; |
| 625 | u32 i, j, max_pred = 8, max_postd = 8, pred = 1, postd = 1; |
| 626 | u32 pll_div, pll_num, pll_denom, post_div = 1; |
| 627 | |
| 628 | debug("mxs_set_lcdclk, freq = %dKHz\n", freq); |
| 629 | |
Peng Fan | 7e2e209 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 630 | if (!is_mx6sx() && !is_mx6ul() && !is_mx6ull() && !is_mx6sl() && |
| 631 | !is_mx6sll()) { |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 632 | debug("This chip not support lcd!\n"); |
| 633 | return; |
| 634 | } |
| 635 | |
Peng Fan | 9fa509a | 2016-12-11 19:24:27 +0800 | [diff] [blame] | 636 | if (!is_mx6sl()) { |
| 637 | if (base_addr == LCDIF1_BASE_ADDR) { |
| 638 | reg = readl(&imx_ccm->cscdr2); |
| 639 | /* Can't change clocks when clock not from pre-mux */ |
| 640 | if ((reg & MXC_CCM_CSCDR2_LCDIF1_CLK_SEL_MASK) != 0) |
| 641 | return; |
| 642 | } |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 643 | } |
| 644 | |
Peng Fan | 6861c5a | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 645 | if (is_mx6sx()) { |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 646 | reg = readl(&imx_ccm->cscdr2); |
| 647 | /* Can't change clocks when clock not from pre-mux */ |
| 648 | if ((reg & MXC_CCM_CSCDR2_LCDIF2_CLK_SEL_MASK) != 0) |
| 649 | return; |
| 650 | } |
| 651 | |
| 652 | temp = freq * max_pred * max_postd; |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 653 | if (temp < min) { |
| 654 | /* |
| 655 | * Register: PLL_VIDEO |
| 656 | * Bit Field: POST_DIV_SELECT |
| 657 | * 00 — Divide by 4. |
| 658 | * 01 — Divide by 2. |
| 659 | * 10 — Divide by 1. |
| 660 | * 11 — Reserved |
| 661 | * No need to check post_div(1) |
| 662 | */ |
| 663 | for (post_div = 2; post_div <= 4; post_div <<= 1) { |
| 664 | if ((temp * post_div) > min) { |
| 665 | freq *= post_div; |
| 666 | break; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | if (post_div > 4) { |
| 671 | printf("Fail to set rate to %dkhz", freq); |
| 672 | return; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | /* Choose the best pred and postd to match freq for lcd */ |
| 677 | for (i = 1; i <= max_pred; i++) { |
| 678 | for (j = 1; j <= max_postd; j++) { |
| 679 | temp = freq * i * j; |
| 680 | if (temp > max || temp < min) |
| 681 | continue; |
| 682 | if (best == 0 || temp < best) { |
| 683 | best = temp; |
| 684 | pred = i; |
| 685 | postd = j; |
| 686 | } |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | if (best == 0) { |
| 691 | printf("Fail to set rate to %dKHz", freq); |
| 692 | return; |
| 693 | } |
| 694 | |
| 695 | debug("best %d, pred = %d, postd = %d\n", best, pred, postd); |
| 696 | |
| 697 | pll_div = best / hck; |
| 698 | pll_denom = 1000000; |
| 699 | pll_num = (best - hck * pll_div) * pll_denom / hck; |
| 700 | |
| 701 | /* |
| 702 | * pll_num |
| 703 | * (24MHz * (pll_div + --------- )) |
| 704 | * pll_denom |
| 705 | *freq KHz = -------------------------------- |
| 706 | * post_div * pred * postd * 1000 |
| 707 | */ |
| 708 | |
| 709 | if (base_addr == LCDIF1_BASE_ADDR) { |
| 710 | if (enable_pll_video(pll_div, pll_num, pll_denom, post_div)) |
| 711 | return; |
| 712 | |
Peng Fan | 4bbd742 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 713 | enable_lcdif_clock(base_addr, 0); |
Peng Fan | 9fa509a | 2016-12-11 19:24:27 +0800 | [diff] [blame] | 714 | if (!is_mx6sl()) { |
| 715 | /* Select pre-lcd clock to PLL5 and set pre divider */ |
| 716 | clrsetbits_le32(&imx_ccm->cscdr2, |
| 717 | MXC_CCM_CSCDR2_LCDIF1_PRED_SEL_MASK | |
| 718 | MXC_CCM_CSCDR2_LCDIF1_PRE_DIV_MASK, |
| 719 | (0x2 << MXC_CCM_CSCDR2_LCDIF1_PRED_SEL_OFFSET) | |
| 720 | ((pred - 1) << |
| 721 | MXC_CCM_CSCDR2_LCDIF1_PRE_DIV_OFFSET)); |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 722 | |
Peng Fan | 9fa509a | 2016-12-11 19:24:27 +0800 | [diff] [blame] | 723 | /* Set the post divider */ |
| 724 | clrsetbits_le32(&imx_ccm->cbcmr, |
| 725 | MXC_CCM_CBCMR_LCDIF1_PODF_MASK, |
| 726 | ((postd - 1) << |
| 727 | MXC_CCM_CBCMR_LCDIF1_PODF_OFFSET)); |
| 728 | } else { |
| 729 | /* Select pre-lcd clock to PLL5 and set pre divider */ |
| 730 | clrsetbits_le32(&imx_ccm->cscdr2, |
| 731 | MXC_CCM_CSCDR2_LCDIF_PIX_CLK_SEL_MASK | |
| 732 | MXC_CCM_CSCDR2_LCDIF_PIX_PRE_DIV_MASK, |
| 733 | (0x2 << MXC_CCM_CSCDR2_LCDIF_PIX_CLK_SEL_OFFSET) | |
| 734 | ((pred - 1) << |
| 735 | MXC_CCM_CSCDR2_LCDIF_PIX_PRE_DIV_OFFSET)); |
| 736 | |
| 737 | /* Set the post divider */ |
| 738 | clrsetbits_le32(&imx_ccm->cscmr1, |
| 739 | MXC_CCM_CSCMR1_LCDIF_PIX_PODF_MASK, |
| 740 | (((postd - 1)^0x6) << |
| 741 | MXC_CCM_CSCMR1_LCDIF_PIX_PODF_OFFSET)); |
| 742 | } |
Peng Fan | 4bbd742 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 743 | |
| 744 | enable_lcdif_clock(base_addr, 1); |
Peng Fan | 6861c5a | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 745 | } else if (is_mx6sx()) { |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 746 | /* Setting LCDIF2 for i.MX6SX */ |
| 747 | if (enable_pll_video(pll_div, pll_num, pll_denom, post_div)) |
| 748 | return; |
| 749 | |
Peng Fan | 4bbd742 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 750 | enable_lcdif_clock(base_addr, 0); |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 751 | /* Select pre-lcd clock to PLL5 and set pre divider */ |
| 752 | clrsetbits_le32(&imx_ccm->cscdr2, |
| 753 | MXC_CCM_CSCDR2_LCDIF2_PRED_SEL_MASK | |
| 754 | MXC_CCM_CSCDR2_LCDIF2_PRE_DIV_MASK, |
| 755 | (0x2 << MXC_CCM_CSCDR2_LCDIF2_PRED_SEL_OFFSET) | |
| 756 | ((pred - 1) << |
| 757 | MXC_CCM_CSCDR2_LCDIF2_PRE_DIV_OFFSET)); |
| 758 | |
| 759 | /* Set the post divider */ |
| 760 | clrsetbits_le32(&imx_ccm->cscmr1, |
| 761 | MXC_CCM_CSCMR1_LCDIF2_PODF_MASK, |
| 762 | ((postd - 1) << |
| 763 | MXC_CCM_CSCMR1_LCDIF2_PODF_OFFSET)); |
Peng Fan | 4bbd742 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 764 | |
| 765 | enable_lcdif_clock(base_addr, 1); |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | |
Peng Fan | 4bbd742 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 769 | int enable_lcdif_clock(u32 base_addr, bool enable) |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 770 | { |
| 771 | u32 reg = 0; |
| 772 | u32 lcdif_clk_sel_mask, lcdif_ccgr3_mask; |
| 773 | |
Peng Fan | 6861c5a | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 774 | if (is_mx6sx()) { |
Ye Li | e9534c3 | 2016-01-26 22:01:57 +0800 | [diff] [blame] | 775 | if ((base_addr != LCDIF1_BASE_ADDR) && |
| 776 | (base_addr != LCDIF2_BASE_ADDR)) { |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 777 | puts("Wrong LCD interface!\n"); |
| 778 | return -EINVAL; |
| 779 | } |
| 780 | /* Set to pre-mux clock at default */ |
| 781 | lcdif_clk_sel_mask = (base_addr == LCDIF2_BASE_ADDR) ? |
| 782 | MXC_CCM_CSCDR2_LCDIF2_CLK_SEL_MASK : |
| 783 | MXC_CCM_CSCDR2_LCDIF1_CLK_SEL_MASK; |
| 784 | lcdif_ccgr3_mask = (base_addr == LCDIF2_BASE_ADDR) ? |
| 785 | (MXC_CCM_CCGR3_LCDIF2_PIX_MASK | |
| 786 | MXC_CCM_CCGR3_DISP_AXI_MASK) : |
| 787 | (MXC_CCM_CCGR3_LCDIF1_PIX_MASK | |
| 788 | MXC_CCM_CCGR3_DISP_AXI_MASK); |
Peng Fan | 7e2e209 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 789 | } else if (is_mx6ul() || is_mx6ull() || is_mx6sll()) { |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 790 | if (base_addr != LCDIF1_BASE_ADDR) { |
| 791 | puts("Wrong LCD interface!\n"); |
| 792 | return -EINVAL; |
| 793 | } |
| 794 | /* Set to pre-mux clock at default */ |
| 795 | lcdif_clk_sel_mask = MXC_CCM_CSCDR2_LCDIF1_CLK_SEL_MASK; |
| 796 | lcdif_ccgr3_mask = MXC_CCM_CCGR3_LCDIF1_PIX_MASK; |
Peng Fan | 9fa509a | 2016-12-11 19:24:27 +0800 | [diff] [blame] | 797 | } else if (is_mx6sl()) { |
| 798 | if (base_addr != LCDIF1_BASE_ADDR) { |
| 799 | puts("Wrong LCD interface!\n"); |
| 800 | return -EINVAL; |
| 801 | } |
| 802 | |
| 803 | reg = readl(&imx_ccm->CCGR3); |
| 804 | reg &= ~(MXC_CCM_CCGR3_LCDIF_AXI_MASK | |
| 805 | MXC_CCM_CCGR3_LCDIF_PIX_MASK); |
| 806 | writel(reg, &imx_ccm->CCGR3); |
| 807 | |
Peng Fan | 4bbd742 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 808 | if (enable) { |
| 809 | reg = readl(&imx_ccm->cscdr3); |
| 810 | reg &= ~MXC_CCM_CSCDR3_LCDIF_AXI_CLK_SEL_MASK; |
| 811 | reg |= 1 << MXC_CCM_CSCDR3_LCDIF_AXI_CLK_SEL_OFFSET; |
| 812 | writel(reg, &imx_ccm->cscdr3); |
Peng Fan | 9fa509a | 2016-12-11 19:24:27 +0800 | [diff] [blame] | 813 | |
Peng Fan | 4bbd742 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 814 | reg = readl(&imx_ccm->CCGR3); |
| 815 | reg |= MXC_CCM_CCGR3_LCDIF_AXI_MASK | |
| 816 | MXC_CCM_CCGR3_LCDIF_PIX_MASK; |
| 817 | writel(reg, &imx_ccm->CCGR3); |
| 818 | } |
Peng Fan | 9fa509a | 2016-12-11 19:24:27 +0800 | [diff] [blame] | 819 | |
| 820 | return 0; |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 821 | } else { |
| 822 | return 0; |
| 823 | } |
| 824 | |
Peng Fan | 690fb4e | 2016-12-11 19:24:26 +0800 | [diff] [blame] | 825 | /* Gate LCDIF clock first */ |
| 826 | reg = readl(&imx_ccm->CCGR3); |
| 827 | reg &= ~lcdif_ccgr3_mask; |
| 828 | writel(reg, &imx_ccm->CCGR3); |
| 829 | |
| 830 | reg = readl(&imx_ccm->CCGR2); |
| 831 | reg &= ~MXC_CCM_CCGR2_LCD_MASK; |
| 832 | writel(reg, &imx_ccm->CCGR2); |
| 833 | |
Peng Fan | 4bbd742 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 834 | if (enable) { |
| 835 | /* Select pre-mux */ |
| 836 | reg = readl(&imx_ccm->cscdr2); |
| 837 | reg &= ~lcdif_clk_sel_mask; |
| 838 | writel(reg, &imx_ccm->cscdr2); |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 839 | |
Peng Fan | 4bbd742 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 840 | /* Enable the LCDIF pix clock */ |
| 841 | reg = readl(&imx_ccm->CCGR3); |
| 842 | reg |= lcdif_ccgr3_mask; |
| 843 | writel(reg, &imx_ccm->CCGR3); |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 844 | |
Peng Fan | 4bbd742 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 845 | reg = readl(&imx_ccm->CCGR2); |
| 846 | reg |= MXC_CCM_CCGR2_LCD_MASK; |
| 847 | writel(reg, &imx_ccm->CCGR2); |
| 848 | } |
Jeroen Hofstee | b1a4ac6 | 2015-11-29 18:30:34 +0100 | [diff] [blame] | 849 | |
| 850 | return 0; |
Peng Fan | 53ebda8 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 851 | } |
| 852 | #endif |
| 853 | |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 854 | #ifdef CONFIG_FSL_QSPI |
Peng Fan | 828e468 | 2014-12-31 11:01:38 +0800 | [diff] [blame] | 855 | /* qspi_num can be from 0 - 1 */ |
| 856 | void enable_qspi_clk(int qspi_num) |
| 857 | { |
| 858 | u32 reg = 0; |
| 859 | /* Enable QuadSPI clock */ |
| 860 | switch (qspi_num) { |
| 861 | case 0: |
| 862 | /* disable the clock gate */ |
| 863 | clrbits_le32(&imx_ccm->CCGR3, MXC_CCM_CCGR3_QSPI1_MASK); |
| 864 | |
| 865 | /* set 50M : (50 = 396 / 2 / 4) */ |
| 866 | reg = readl(&imx_ccm->cscmr1); |
| 867 | reg &= ~(MXC_CCM_CSCMR1_QSPI1_PODF_MASK | |
| 868 | MXC_CCM_CSCMR1_QSPI1_CLK_SEL_MASK); |
| 869 | reg |= ((1 << MXC_CCM_CSCMR1_QSPI1_PODF_OFFSET) | |
| 870 | (2 << MXC_CCM_CSCMR1_QSPI1_CLK_SEL_OFFSET)); |
| 871 | writel(reg, &imx_ccm->cscmr1); |
| 872 | |
| 873 | /* enable the clock gate */ |
| 874 | setbits_le32(&imx_ccm->CCGR3, MXC_CCM_CCGR3_QSPI1_MASK); |
| 875 | break; |
| 876 | case 1: |
| 877 | /* |
| 878 | * disable the clock gate |
| 879 | * QSPI2 and GPMI_BCH_INPUT_GPMI_IO share the same clock gate, |
| 880 | * disable both of them. |
| 881 | */ |
| 882 | clrbits_le32(&imx_ccm->CCGR4, MXC_CCM_CCGR4_QSPI2_ENFC_MASK | |
| 883 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK); |
| 884 | |
| 885 | /* set 50M : (50 = 396 / 2 / 4) */ |
| 886 | reg = readl(&imx_ccm->cs2cdr); |
| 887 | reg &= ~(MXC_CCM_CS2CDR_QSPI2_CLK_PODF_MASK | |
| 888 | MXC_CCM_CS2CDR_QSPI2_CLK_PRED_MASK | |
| 889 | MXC_CCM_CS2CDR_QSPI2_CLK_SEL_MASK); |
| 890 | reg |= (MXC_CCM_CS2CDR_QSPI2_CLK_PRED(0x1) | |
| 891 | MXC_CCM_CS2CDR_QSPI2_CLK_SEL(0x3)); |
| 892 | writel(reg, &imx_ccm->cs2cdr); |
| 893 | |
| 894 | /*enable the clock gate*/ |
| 895 | setbits_le32(&imx_ccm->CCGR4, MXC_CCM_CCGR4_QSPI2_ENFC_MASK | |
| 896 | MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK); |
| 897 | break; |
| 898 | default: |
| 899 | break; |
| 900 | } |
| 901 | } |
| 902 | #endif |
| 903 | |
Otavio Salvador | dc07443 | 2013-12-16 20:44:05 -0200 | [diff] [blame] | 904 | #ifdef CONFIG_FEC_MXC |
Peng Fan | 967a83b | 2015-08-12 17:46:50 +0800 | [diff] [blame] | 905 | int enable_fec_anatop_clock(int fec_id, enum enet_freq freq) |
Fabio Estevam | 67b8b9d | 2013-09-13 00:36:28 -0300 | [diff] [blame] | 906 | { |
| 907 | u32 reg = 0; |
| 908 | s32 timeout = 100000; |
| 909 | |
| 910 | struct anatop_regs __iomem *anatop = |
| 911 | (struct anatop_regs __iomem *)ANATOP_BASE_ADDR; |
| 912 | |
Stefan Roese | d7e0731 | 2014-11-27 13:46:43 +0100 | [diff] [blame] | 913 | if (freq < ENET_25MHZ || freq > ENET_125MHZ) |
Fabio Estevam | b2903ae | 2014-01-03 15:55:57 -0200 | [diff] [blame] | 914 | return -EINVAL; |
| 915 | |
Peng Fan | f868f9f | 2015-09-06 17:15:47 +0800 | [diff] [blame] | 916 | reg = readl(&anatop->pll_enet); |
| 917 | |
Peng Fan | 967a83b | 2015-08-12 17:46:50 +0800 | [diff] [blame] | 918 | if (fec_id == 0) { |
| 919 | reg &= ~BM_ANADIG_PLL_ENET_DIV_SELECT; |
| 920 | reg |= BF_ANADIG_PLL_ENET_DIV_SELECT(freq); |
| 921 | } else if (fec_id == 1) { |
| 922 | /* Only i.MX6SX/UL support ENET2 */ |
Peng Fan | ce7a712 | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 923 | if (!(is_mx6sx() || is_mx6ul() || is_mx6ull())) |
Peng Fan | 967a83b | 2015-08-12 17:46:50 +0800 | [diff] [blame] | 924 | return -EINVAL; |
| 925 | reg &= ~BM_ANADIG_PLL_ENET2_DIV_SELECT; |
| 926 | reg |= BF_ANADIG_PLL_ENET2_DIV_SELECT(freq); |
| 927 | } else { |
| 928 | return -EINVAL; |
| 929 | } |
Fabio Estevam | b2903ae | 2014-01-03 15:55:57 -0200 | [diff] [blame] | 930 | |
Fabio Estevam | 67b8b9d | 2013-09-13 00:36:28 -0300 | [diff] [blame] | 931 | if ((reg & BM_ANADIG_PLL_ENET_POWERDOWN) || |
| 932 | (!(reg & BM_ANADIG_PLL_ENET_LOCK))) { |
| 933 | reg &= ~BM_ANADIG_PLL_ENET_POWERDOWN; |
| 934 | writel(reg, &anatop->pll_enet); |
| 935 | while (timeout--) { |
| 936 | if (readl(&anatop->pll_enet) & BM_ANADIG_PLL_ENET_LOCK) |
| 937 | break; |
| 938 | } |
| 939 | if (timeout < 0) |
| 940 | return -ETIMEDOUT; |
| 941 | } |
| 942 | |
| 943 | /* Enable FEC clock */ |
Peng Fan | 967a83b | 2015-08-12 17:46:50 +0800 | [diff] [blame] | 944 | if (fec_id == 0) |
| 945 | reg |= BM_ANADIG_PLL_ENET_ENABLE; |
| 946 | else |
| 947 | reg |= BM_ANADIG_PLL_ENET2_ENABLE; |
Fabio Estevam | 67b8b9d | 2013-09-13 00:36:28 -0300 | [diff] [blame] | 948 | reg &= ~BM_ANADIG_PLL_ENET_BYPASS; |
| 949 | writel(reg, &anatop->pll_enet); |
| 950 | |
Fabio Estevam | d4d6038 | 2014-08-15 00:24:30 -0300 | [diff] [blame] | 951 | #ifdef CONFIG_MX6SX |
Ye.Li | e91df61 | 2016-10-08 16:58:29 +0800 | [diff] [blame] | 952 | /* Disable enet system clcok before switching clock parent */ |
| 953 | reg = readl(&imx_ccm->CCGR3); |
| 954 | reg &= ~MXC_CCM_CCGR3_ENET_MASK; |
| 955 | writel(reg, &imx_ccm->CCGR3); |
| 956 | |
Fabio Estevam | d4d6038 | 2014-08-15 00:24:30 -0300 | [diff] [blame] | 957 | /* |
| 958 | * Set enet ahb clock to 200MHz |
| 959 | * pll2_pfd2_396m-> ENET_PODF-> ENET_AHB |
| 960 | */ |
| 961 | reg = readl(&imx_ccm->chsccdr); |
| 962 | reg &= ~(MXC_CCM_CHSCCDR_ENET_PRE_CLK_SEL_MASK |
| 963 | | MXC_CCM_CHSCCDR_ENET_PODF_MASK |
| 964 | | MXC_CCM_CHSCCDR_ENET_CLK_SEL_MASK); |
| 965 | /* PLL2 PFD2 */ |
| 966 | reg |= (4 << MXC_CCM_CHSCCDR_ENET_PRE_CLK_SEL_OFFSET); |
| 967 | /* Div = 2*/ |
| 968 | reg |= (1 << MXC_CCM_CHSCCDR_ENET_PODF_OFFSET); |
| 969 | reg |= (0 << MXC_CCM_CHSCCDR_ENET_CLK_SEL_OFFSET); |
| 970 | writel(reg, &imx_ccm->chsccdr); |
| 971 | |
| 972 | /* Enable enet system clock */ |
| 973 | reg = readl(&imx_ccm->CCGR3); |
| 974 | reg |= MXC_CCM_CCGR3_ENET_MASK; |
| 975 | writel(reg, &imx_ccm->CCGR3); |
| 976 | #endif |
Fabio Estevam | 67b8b9d | 2013-09-13 00:36:28 -0300 | [diff] [blame] | 977 | return 0; |
| 978 | } |
Fabio Estevam | f7b9ac2 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 979 | #endif |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 980 | |
| 981 | static u32 get_usdhc_clk(u32 port) |
| 982 | { |
| 983 | u32 root_freq = 0, usdhc_podf = 0, clk_sel = 0; |
| 984 | u32 cscmr1 = __raw_readl(&imx_ccm->cscmr1); |
| 985 | u32 cscdr1 = __raw_readl(&imx_ccm->cscdr1); |
| 986 | |
Peng Fan | 7e2e209 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 987 | if (is_mx6ul() || is_mx6ull()) { |
| 988 | if (port > 1) |
| 989 | return 0; |
| 990 | } |
| 991 | |
| 992 | if (is_mx6sll()) { |
| 993 | if (port > 2) |
| 994 | return 0; |
| 995 | } |
| 996 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 997 | switch (port) { |
| 998 | case 0: |
| 999 | usdhc_podf = (cscdr1 & MXC_CCM_CSCDR1_USDHC1_PODF_MASK) >> |
| 1000 | MXC_CCM_CSCDR1_USDHC1_PODF_OFFSET; |
| 1001 | clk_sel = cscmr1 & MXC_CCM_CSCMR1_USDHC1_CLK_SEL; |
| 1002 | |
| 1003 | break; |
| 1004 | case 1: |
| 1005 | usdhc_podf = (cscdr1 & MXC_CCM_CSCDR1_USDHC2_PODF_MASK) >> |
| 1006 | MXC_CCM_CSCDR1_USDHC2_PODF_OFFSET; |
| 1007 | clk_sel = cscmr1 & MXC_CCM_CSCMR1_USDHC2_CLK_SEL; |
| 1008 | |
| 1009 | break; |
| 1010 | case 2: |
| 1011 | usdhc_podf = (cscdr1 & MXC_CCM_CSCDR1_USDHC3_PODF_MASK) >> |
| 1012 | MXC_CCM_CSCDR1_USDHC3_PODF_OFFSET; |
| 1013 | clk_sel = cscmr1 & MXC_CCM_CSCMR1_USDHC3_CLK_SEL; |
| 1014 | |
| 1015 | break; |
| 1016 | case 3: |
| 1017 | usdhc_podf = (cscdr1 & MXC_CCM_CSCDR1_USDHC4_PODF_MASK) >> |
| 1018 | MXC_CCM_CSCDR1_USDHC4_PODF_OFFSET; |
| 1019 | clk_sel = cscmr1 & MXC_CCM_CSCMR1_USDHC4_CLK_SEL; |
| 1020 | |
| 1021 | break; |
| 1022 | default: |
| 1023 | break; |
| 1024 | } |
| 1025 | |
| 1026 | if (clk_sel) |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 1027 | root_freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1028 | else |
Pierre Aubert | e8e62a7 | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 1029 | root_freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1030 | |
| 1031 | return root_freq / (usdhc_podf + 1); |
| 1032 | } |
| 1033 | |
| 1034 | u32 imx_get_uartclk(void) |
| 1035 | { |
| 1036 | return get_uart_clk(); |
| 1037 | } |
| 1038 | |
Jason Liu | 92aa90b | 2011-12-16 05:17:06 +0000 | [diff] [blame] | 1039 | u32 imx_get_fecclk(void) |
| 1040 | { |
Markus Niebel | 6c109b8 | 2014-02-05 10:51:25 +0100 | [diff] [blame] | 1041 | return mxc_get_clock(MXC_IPG_CLK); |
Jason Liu | 92aa90b | 2011-12-16 05:17:06 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
Simon Glass | ab3055a | 2017-06-14 21:28:25 -0600 | [diff] [blame] | 1044 | #if defined(CONFIG_SATA) || defined(CONFIG_PCIE_IMX) |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1045 | static int enable_enet_pll(uint32_t en) |
Eric Nelson | fdba076 | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 1046 | { |
Eric Nelson | fdba076 | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 1047 | struct mxc_ccm_reg *const imx_ccm |
| 1048 | = (struct mxc_ccm_reg *) CCM_BASE_ADDR; |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1049 | s32 timeout = 100000; |
| 1050 | u32 reg = 0; |
Eric Nelson | fdba076 | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 1051 | |
| 1052 | /* Enable PLLs */ |
| 1053 | reg = readl(&imx_ccm->analog_pll_enet); |
| 1054 | reg &= ~BM_ANADIG_PLL_SYS_POWERDOWN; |
| 1055 | writel(reg, &imx_ccm->analog_pll_enet); |
| 1056 | reg |= BM_ANADIG_PLL_SYS_ENABLE; |
| 1057 | while (timeout--) { |
| 1058 | if (readl(&imx_ccm->analog_pll_enet) & BM_ANADIG_PLL_SYS_LOCK) |
| 1059 | break; |
| 1060 | } |
| 1061 | if (timeout <= 0) |
| 1062 | return -EIO; |
| 1063 | reg &= ~BM_ANADIG_PLL_SYS_BYPASS; |
| 1064 | writel(reg, &imx_ccm->analog_pll_enet); |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1065 | reg |= en; |
Eric Nelson | fdba076 | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 1066 | writel(reg, &imx_ccm->analog_pll_enet); |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1067 | return 0; |
| 1068 | } |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 1069 | #endif |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1070 | |
Simon Glass | ab3055a | 2017-06-14 21:28:25 -0600 | [diff] [blame] | 1071 | #ifdef CONFIG_SATA |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1072 | static void ungate_sata_clock(void) |
| 1073 | { |
| 1074 | struct mxc_ccm_reg *const imx_ccm = |
| 1075 | (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 1076 | |
| 1077 | /* Enable SATA clock. */ |
| 1078 | setbits_le32(&imx_ccm->CCGR5, MXC_CCM_CCGR5_SATA_MASK); |
| 1079 | } |
| 1080 | |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1081 | int enable_sata_clock(void) |
| 1082 | { |
| 1083 | ungate_sata_clock(); |
| 1084 | return enable_enet_pll(BM_ANADIG_PLL_ENET_ENABLE_SATA); |
| 1085 | } |
Nikita Kiryanov | 63659b7 | 2014-11-21 12:47:22 +0200 | [diff] [blame] | 1086 | |
| 1087 | void disable_sata_clock(void) |
| 1088 | { |
| 1089 | struct mxc_ccm_reg *const imx_ccm = |
| 1090 | (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 1091 | |
| 1092 | clrbits_le32(&imx_ccm->CCGR5, MXC_CCM_CCGR5_SATA_MASK); |
| 1093 | } |
Fabio Estevam | 15af733 | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 1094 | #endif |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1095 | |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 1096 | #ifdef CONFIG_PCIE_IMX |
| 1097 | static void ungate_pcie_clock(void) |
| 1098 | { |
| 1099 | struct mxc_ccm_reg *const imx_ccm = |
| 1100 | (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 1101 | |
| 1102 | /* Enable PCIe clock. */ |
| 1103 | setbits_le32(&imx_ccm->CCGR4, MXC_CCM_CCGR4_PCIE_MASK); |
| 1104 | } |
| 1105 | |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1106 | int enable_pcie_clock(void) |
| 1107 | { |
| 1108 | struct anatop_regs *anatop_regs = |
| 1109 | (struct anatop_regs *)ANATOP_BASE_ADDR; |
| 1110 | 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] | 1111 | u32 lvds1_clk_sel; |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1112 | |
| 1113 | /* |
| 1114 | * Here be dragons! |
| 1115 | * |
| 1116 | * The register ANATOP_MISC1 is not documented in the Freescale |
| 1117 | * MX6RM. The register that is mapped in the ANATOP space and |
| 1118 | * marked as ANATOP_MISC1 is actually documented in the PMU section |
| 1119 | * of the datasheet as PMU_MISC1. |
| 1120 | * |
Fabio Estevam | 211a490 | 2014-08-25 14:26:45 -0300 | [diff] [blame] | 1121 | * Switch LVDS clock source to SATA (0xb) on mx6q/dl or PCI (0xa) on |
| 1122 | * mx6sx, disable clock INPUT and enable clock OUTPUT. This is important |
| 1123 | * for PCI express link that is clocked from the i.MX6. |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1124 | */ |
| 1125 | #define ANADIG_ANA_MISC1_LVDSCLK1_IBEN (1 << 12) |
| 1126 | #define ANADIG_ANA_MISC1_LVDSCLK1_OBEN (1 << 10) |
| 1127 | #define ANADIG_ANA_MISC1_LVDS1_CLK_SEL_MASK 0x0000001F |
Fabio Estevam | 211a490 | 2014-08-25 14:26:45 -0300 | [diff] [blame] | 1128 | #define ANADIG_ANA_MISC1_LVDS1_CLK_SEL_PCIE_REF 0xa |
| 1129 | #define ANADIG_ANA_MISC1_LVDS1_CLK_SEL_SATA_REF 0xb |
| 1130 | |
Peng Fan | 6861c5a | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 1131 | if (is_mx6sx()) |
Fabio Estevam | 211a490 | 2014-08-25 14:26:45 -0300 | [diff] [blame] | 1132 | lvds1_clk_sel = ANADIG_ANA_MISC1_LVDS1_CLK_SEL_PCIE_REF; |
| 1133 | else |
| 1134 | lvds1_clk_sel = ANADIG_ANA_MISC1_LVDS1_CLK_SEL_SATA_REF; |
| 1135 | |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1136 | clrsetbits_le32(&anatop_regs->ana_misc1, |
| 1137 | ANADIG_ANA_MISC1_LVDSCLK1_IBEN | |
| 1138 | ANADIG_ANA_MISC1_LVDS1_CLK_SEL_MASK, |
Fabio Estevam | 211a490 | 2014-08-25 14:26:45 -0300 | [diff] [blame] | 1139 | ANADIG_ANA_MISC1_LVDSCLK1_OBEN | lvds1_clk_sel); |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1140 | |
| 1141 | /* PCIe reference clock sourced from AXI. */ |
| 1142 | clrbits_le32(&ccm_regs->cbcmr, MXC_CCM_CBCMR_PCIE_AXI_CLK_SEL); |
| 1143 | |
| 1144 | /* Party time! Ungate the clock to the PCIe. */ |
Simon Glass | ab3055a | 2017-06-14 21:28:25 -0600 | [diff] [blame] | 1145 | #ifdef CONFIG_SATA |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1146 | ungate_sata_clock(); |
Fabio Estevam | 15af733 | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 1147 | #endif |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1148 | ungate_pcie_clock(); |
Eric Nelson | fdba076 | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 1149 | |
Marek Vasut | 563dfb2 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1150 | return enable_enet_pll(BM_ANADIG_PLL_ENET_ENABLE_SATA | |
| 1151 | BM_ANADIG_PLL_ENET_ENABLE_PCIE); |
Eric Nelson | fdba076 | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 1152 | } |
Peng Fan | 40a6ed1 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 1153 | #endif |
Eric Nelson | fdba076 | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 1154 | |
Nitin Garg | b1ce701 | 2014-09-16 13:33:25 -0500 | [diff] [blame] | 1155 | #ifdef CONFIG_SECURE_BOOT |
| 1156 | void hab_caam_clock_enable(unsigned char enable) |
| 1157 | { |
| 1158 | u32 reg; |
| 1159 | |
Peng Fan | 7e2e209 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 1160 | if (is_mx6ull() || is_mx6sll()) { |
Peng Fan | ce7a712 | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 1161 | /* CG5, DCP clock */ |
| 1162 | reg = __raw_readl(&imx_ccm->CCGR0); |
| 1163 | if (enable) |
| 1164 | reg |= MXC_CCM_CCGR0_DCP_CLK_MASK; |
| 1165 | else |
| 1166 | reg &= ~MXC_CCM_CCGR0_DCP_CLK_MASK; |
| 1167 | __raw_writel(reg, &imx_ccm->CCGR0); |
| 1168 | } else { |
| 1169 | /* CG4 ~ CG6, CAAM clocks */ |
| 1170 | reg = __raw_readl(&imx_ccm->CCGR0); |
| 1171 | if (enable) |
| 1172 | reg |= (MXC_CCM_CCGR0_CAAM_WRAPPER_IPG_MASK | |
| 1173 | MXC_CCM_CCGR0_CAAM_WRAPPER_ACLK_MASK | |
| 1174 | MXC_CCM_CCGR0_CAAM_SECURE_MEM_MASK); |
| 1175 | else |
| 1176 | reg &= ~(MXC_CCM_CCGR0_CAAM_WRAPPER_IPG_MASK | |
| 1177 | MXC_CCM_CCGR0_CAAM_WRAPPER_ACLK_MASK | |
| 1178 | MXC_CCM_CCGR0_CAAM_SECURE_MEM_MASK); |
| 1179 | __raw_writel(reg, &imx_ccm->CCGR0); |
| 1180 | } |
Nitin Garg | b1ce701 | 2014-09-16 13:33:25 -0500 | [diff] [blame] | 1181 | |
| 1182 | /* EMI slow clk */ |
| 1183 | reg = __raw_readl(&imx_ccm->CCGR6); |
| 1184 | if (enable) |
| 1185 | reg |= MXC_CCM_CCGR6_EMI_SLOW_MASK; |
| 1186 | else |
| 1187 | reg &= ~MXC_CCM_CCGR6_EMI_SLOW_MASK; |
| 1188 | __raw_writel(reg, &imx_ccm->CCGR6); |
| 1189 | } |
| 1190 | #endif |
| 1191 | |
Nitin Garg | 59f3be3 | 2014-11-20 21:14:12 +0800 | [diff] [blame] | 1192 | static void enable_pll3(void) |
| 1193 | { |
| 1194 | struct anatop_regs __iomem *anatop = |
| 1195 | (struct anatop_regs __iomem *)ANATOP_BASE_ADDR; |
| 1196 | |
| 1197 | /* make sure pll3 is enabled */ |
| 1198 | if ((readl(&anatop->usb1_pll_480_ctrl) & |
| 1199 | BM_ANADIG_USB1_PLL_480_CTRL_LOCK) == 0) { |
| 1200 | /* enable pll's power */ |
| 1201 | writel(BM_ANADIG_USB1_PLL_480_CTRL_POWER, |
| 1202 | &anatop->usb1_pll_480_ctrl_set); |
| 1203 | writel(0x80, &anatop->ana_misc2_clr); |
| 1204 | /* wait for pll lock */ |
| 1205 | while ((readl(&anatop->usb1_pll_480_ctrl) & |
| 1206 | BM_ANADIG_USB1_PLL_480_CTRL_LOCK) == 0) |
| 1207 | ; |
| 1208 | /* disable bypass */ |
| 1209 | writel(BM_ANADIG_USB1_PLL_480_CTRL_BYPASS, |
| 1210 | &anatop->usb1_pll_480_ctrl_clr); |
| 1211 | /* enable pll output */ |
| 1212 | writel(BM_ANADIG_USB1_PLL_480_CTRL_ENABLE, |
| 1213 | &anatop->usb1_pll_480_ctrl_set); |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | void enable_thermal_clk(void) |
| 1218 | { |
| 1219 | enable_pll3(); |
| 1220 | } |
| 1221 | |
Anatolij Gustschin | 03dd986 | 2017-08-28 21:46:26 +0200 | [diff] [blame] | 1222 | #ifdef CONFIG_MTD_NOR_FLASH |
| 1223 | void enable_eim_clk(unsigned char enable) |
| 1224 | { |
| 1225 | u32 reg; |
| 1226 | |
| 1227 | reg = __raw_readl(&imx_ccm->CCGR6); |
| 1228 | if (enable) |
| 1229 | reg |= MXC_CCM_CCGR6_EMI_SLOW_MASK; |
| 1230 | else |
| 1231 | reg &= ~MXC_CCM_CCGR6_EMI_SLOW_MASK; |
| 1232 | __raw_writel(reg, &imx_ccm->CCGR6); |
| 1233 | } |
| 1234 | #endif |
| 1235 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1236 | unsigned int mxc_get_clock(enum mxc_clock clk) |
| 1237 | { |
| 1238 | switch (clk) { |
| 1239 | case MXC_ARM_CLK: |
| 1240 | return get_mcu_main_clk(); |
| 1241 | case MXC_PER_CLK: |
| 1242 | return get_periph_clk(); |
| 1243 | case MXC_AHB_CLK: |
| 1244 | return get_ahb_clk(); |
| 1245 | case MXC_IPG_CLK: |
| 1246 | return get_ipg_clk(); |
| 1247 | case MXC_IPG_PERCLK: |
Matthias Weisser | 99ba342 | 2012-09-24 02:46:53 +0000 | [diff] [blame] | 1248 | case MXC_I2C_CLK: |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1249 | return get_ipg_per_clk(); |
| 1250 | case MXC_UART_CLK: |
| 1251 | return get_uart_clk(); |
| 1252 | case MXC_CSPI_CLK: |
| 1253 | return get_cspi_clk(); |
| 1254 | case MXC_AXI_CLK: |
| 1255 | return get_axi_clk(); |
| 1256 | case MXC_EMI_SLOW_CLK: |
| 1257 | return get_emi_slow_clk(); |
| 1258 | case MXC_DDR_CLK: |
| 1259 | return get_mmdc_ch0_clk(); |
| 1260 | case MXC_ESDHC_CLK: |
| 1261 | return get_usdhc_clk(0); |
| 1262 | case MXC_ESDHC2_CLK: |
| 1263 | return get_usdhc_clk(1); |
| 1264 | case MXC_ESDHC3_CLK: |
| 1265 | return get_usdhc_clk(2); |
| 1266 | case MXC_ESDHC4_CLK: |
| 1267 | return get_usdhc_clk(3); |
| 1268 | case MXC_SATA_CLK: |
| 1269 | return get_ahb_clk(); |
| 1270 | default: |
Peng Fan | 3c7cb49 | 2014-11-23 11:52:20 +0800 | [diff] [blame] | 1271 | printf("Unsupported MXC CLK: %d\n", clk); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1272 | break; |
| 1273 | } |
| 1274 | |
Peng Fan | 3c7cb49 | 2014-11-23 11:52:20 +0800 | [diff] [blame] | 1275 | return 0; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
Anatolij Gustschin | 03dd986 | 2017-08-28 21:46:26 +0200 | [diff] [blame] | 1278 | #ifndef CONFIG_SPL_BUILD |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1279 | /* |
| 1280 | * Dump some core clockes. |
| 1281 | */ |
| 1282 | int do_mx6_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 1283 | { |
| 1284 | u32 freq; |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 1285 | freq = decode_pll(PLL_SYS, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1286 | printf("PLL_SYS %8d MHz\n", freq / 1000000); |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 1287 | freq = decode_pll(PLL_BUS, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1288 | printf("PLL_BUS %8d MHz\n", freq / 1000000); |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 1289 | freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1290 | printf("PLL_OTG %8d MHz\n", freq / 1000000); |
Benoît Thébaudeau | afac165 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 1291 | freq = decode_pll(PLL_ENET, MXC_HCLK); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1292 | printf("PLL_NET %8d MHz\n", freq / 1000000); |
| 1293 | |
| 1294 | printf("\n"); |
Peng Fan | 219e8c8 | 2016-03-09 16:44:38 +0800 | [diff] [blame] | 1295 | printf("ARM %8d kHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1296 | printf("IPG %8d kHz\n", mxc_get_clock(MXC_IPG_CLK) / 1000); |
| 1297 | printf("UART %8d kHz\n", mxc_get_clock(MXC_UART_CLK) / 1000); |
Fabio Estevam | f6fde41 | 2012-11-16 01:30:10 +0000 | [diff] [blame] | 1298 | #ifdef CONFIG_MXC_SPI |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1299 | printf("CSPI %8d kHz\n", mxc_get_clock(MXC_CSPI_CLK) / 1000); |
Fabio Estevam | f6fde41 | 2012-11-16 01:30:10 +0000 | [diff] [blame] | 1300 | #endif |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1301 | printf("AHB %8d kHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000); |
| 1302 | printf("AXI %8d kHz\n", mxc_get_clock(MXC_AXI_CLK) / 1000); |
| 1303 | printf("DDR %8d kHz\n", mxc_get_clock(MXC_DDR_CLK) / 1000); |
| 1304 | printf("USDHC1 %8d kHz\n", mxc_get_clock(MXC_ESDHC_CLK) / 1000); |
| 1305 | printf("USDHC2 %8d kHz\n", mxc_get_clock(MXC_ESDHC2_CLK) / 1000); |
| 1306 | printf("USDHC3 %8d kHz\n", mxc_get_clock(MXC_ESDHC3_CLK) / 1000); |
| 1307 | printf("USDHC4 %8d kHz\n", mxc_get_clock(MXC_ESDHC4_CLK) / 1000); |
| 1308 | printf("EMI SLOW %8d kHz\n", mxc_get_clock(MXC_EMI_SLOW_CLK) / 1000); |
| 1309 | printf("IPG PERCLK %8d kHz\n", mxc_get_clock(MXC_IPG_PERCLK) / 1000); |
| 1310 | |
| 1311 | return 0; |
| 1312 | } |
| 1313 | |
Fabio Estevam | 15af733 | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 1314 | #ifndef CONFIG_MX6SX |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 1315 | void enable_ipu_clock(void) |
| 1316 | { |
| 1317 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 1318 | int reg; |
| 1319 | reg = readl(&mxc_ccm->CCGR3); |
Pierre Aubert | 2cb5c38 | 2013-09-23 13:37:20 +0200 | [diff] [blame] | 1320 | reg |= MXC_CCM_CCGR3_IPU1_IPU_MASK; |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 1321 | writel(reg, &mxc_ccm->CCGR3); |
Peng Fan | 5a62fcc | 2015-07-11 11:38:45 +0800 | [diff] [blame] | 1322 | |
| 1323 | if (is_mx6dqp()) { |
| 1324 | setbits_le32(&mxc_ccm->CCGR6, MXC_CCM_CCGR6_PRG_CLK0_MASK); |
| 1325 | setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_IPU2_IPU_MASK); |
| 1326 | } |
Pardeep Kumar Singla | c1fa130 | 2013-07-25 12:12:13 -0500 | [diff] [blame] | 1327 | } |
Fabio Estevam | 15af733 | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 1328 | #endif |
Akshay Bhat | 4e364e6 | 2016-04-12 18:13:56 -0400 | [diff] [blame] | 1329 | |
| 1330 | #if defined(CONFIG_MX6Q) || defined(CONFIG_MX6D) || defined(CONFIG_MX6DL) || \ |
| 1331 | defined(CONFIG_MX6S) |
| 1332 | static void disable_ldb_di_clock_sources(void) |
| 1333 | { |
| 1334 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 1335 | int reg; |
| 1336 | |
| 1337 | /* Make sure PFDs are disabled at boot. */ |
| 1338 | reg = readl(&mxc_ccm->analog_pfd_528); |
| 1339 | /* Cannot disable pll2_pfd2_396M, as it is the MMDC clock in iMX6DL */ |
Peng Fan | 6861c5a | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 1340 | if (is_mx6sdl()) |
Akshay Bhat | 4e364e6 | 2016-04-12 18:13:56 -0400 | [diff] [blame] | 1341 | reg |= 0x80008080; |
| 1342 | else |
| 1343 | reg |= 0x80808080; |
| 1344 | writel(reg, &mxc_ccm->analog_pfd_528); |
| 1345 | |
| 1346 | /* Disable PLL3 PFDs */ |
| 1347 | reg = readl(&mxc_ccm->analog_pfd_480); |
| 1348 | reg |= 0x80808080; |
| 1349 | writel(reg, &mxc_ccm->analog_pfd_480); |
| 1350 | |
| 1351 | /* Disable PLL5 */ |
| 1352 | reg = readl(&mxc_ccm->analog_pll_video); |
| 1353 | reg &= ~(1 << 13); |
| 1354 | writel(reg, &mxc_ccm->analog_pll_video); |
| 1355 | } |
| 1356 | |
| 1357 | static void enable_ldb_di_clock_sources(void) |
| 1358 | { |
| 1359 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 1360 | int reg; |
| 1361 | |
| 1362 | reg = readl(&mxc_ccm->analog_pfd_528); |
Peng Fan | 6861c5a | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 1363 | if (is_mx6sdl()) |
Akshay Bhat | 4e364e6 | 2016-04-12 18:13:56 -0400 | [diff] [blame] | 1364 | reg &= ~(0x80008080); |
| 1365 | else |
| 1366 | reg &= ~(0x80808080); |
| 1367 | writel(reg, &mxc_ccm->analog_pfd_528); |
| 1368 | |
| 1369 | reg = readl(&mxc_ccm->analog_pfd_480); |
| 1370 | reg &= ~(0x80808080); |
| 1371 | writel(reg, &mxc_ccm->analog_pfd_480); |
| 1372 | } |
| 1373 | |
| 1374 | /* |
| 1375 | * Try call this function as early in the boot process as possible since the |
| 1376 | * function temporarily disables PLL2 PFD's, PLL3 PFD's and PLL5. |
| 1377 | */ |
| 1378 | void select_ldb_di_clock_source(enum ldb_di_clock clk) |
| 1379 | { |
| 1380 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 1381 | int reg; |
| 1382 | |
| 1383 | /* |
| 1384 | * Need to follow a strict procedure when changing the LDB |
| 1385 | * clock, else we can introduce a glitch. Things to keep in |
| 1386 | * mind: |
| 1387 | * 1. The current and new parent clocks must be disabled. |
| 1388 | * 2. The default clock for ldb_dio_clk is mmdc_ch1 which has |
| 1389 | * no CG bit. |
| 1390 | * 3. In the RTL implementation of the LDB_DI_CLK_SEL mux |
| 1391 | * the top four options are in one mux and the PLL3 option along |
| 1392 | * with another option is in the second mux. There is third mux |
| 1393 | * used to decide between the first and second mux. |
| 1394 | * The code below switches the parent to the bottom mux first |
| 1395 | * and then manipulates the top mux. This ensures that no glitch |
| 1396 | * will enter the divider. |
| 1397 | * |
| 1398 | * Need to disable MMDC_CH1 clock manually as there is no CG bit |
| 1399 | * for this clock. The only way to disable this clock is to move |
| 1400 | * it to pll3_sw_clk and then to disable pll3_sw_clk |
| 1401 | * Make sure periph2_clk2_sel is set to pll3_sw_clk |
| 1402 | */ |
| 1403 | |
| 1404 | /* Disable all ldb_di clock parents */ |
| 1405 | disable_ldb_di_clock_sources(); |
| 1406 | |
| 1407 | /* Set MMDC_CH1 mask bit */ |
| 1408 | reg = readl(&mxc_ccm->ccdr); |
| 1409 | reg |= MXC_CCM_CCDR_MMDC_CH1_HS_MASK; |
| 1410 | writel(reg, &mxc_ccm->ccdr); |
| 1411 | |
| 1412 | /* Set periph2_clk2_sel to be sourced from PLL3_sw_clk */ |
| 1413 | reg = readl(&mxc_ccm->cbcmr); |
| 1414 | reg &= ~MXC_CCM_CBCMR_PERIPH2_CLK2_SEL; |
| 1415 | writel(reg, &mxc_ccm->cbcmr); |
| 1416 | |
| 1417 | /* |
| 1418 | * Set the periph2_clk_sel to the top mux so that |
| 1419 | * mmdc_ch1 is from pll3_sw_clk. |
| 1420 | */ |
| 1421 | reg = readl(&mxc_ccm->cbcdr); |
| 1422 | reg |= MXC_CCM_CBCDR_PERIPH2_CLK_SEL; |
| 1423 | writel(reg, &mxc_ccm->cbcdr); |
| 1424 | |
| 1425 | /* Wait for the clock switch */ |
| 1426 | while (readl(&mxc_ccm->cdhipr)) |
| 1427 | ; |
| 1428 | /* Disable pll3_sw_clk by selecting bypass clock source */ |
| 1429 | reg = readl(&mxc_ccm->ccsr); |
| 1430 | reg |= MXC_CCM_CCSR_PLL3_SW_CLK_SEL; |
| 1431 | writel(reg, &mxc_ccm->ccsr); |
| 1432 | |
| 1433 | /* Set the ldb_di0_clk and ldb_di1_clk to 111b */ |
| 1434 | reg = readl(&mxc_ccm->cs2cdr); |
| 1435 | reg |= ((7 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET) |
| 1436 | | (7 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)); |
| 1437 | writel(reg, &mxc_ccm->cs2cdr); |
| 1438 | |
| 1439 | /* Set the ldb_di0_clk and ldb_di1_clk to 100b */ |
| 1440 | reg = readl(&mxc_ccm->cs2cdr); |
| 1441 | reg &= ~(MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK |
| 1442 | | MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK); |
| 1443 | reg |= ((4 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET) |
| 1444 | | (4 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)); |
| 1445 | writel(reg, &mxc_ccm->cs2cdr); |
| 1446 | |
| 1447 | /* Set the ldb_di0_clk and ldb_di1_clk to desired source */ |
| 1448 | reg = readl(&mxc_ccm->cs2cdr); |
| 1449 | reg &= ~(MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK |
| 1450 | | MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK); |
| 1451 | reg |= ((clk << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET) |
| 1452 | | (clk << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)); |
| 1453 | writel(reg, &mxc_ccm->cs2cdr); |
| 1454 | |
| 1455 | /* Unbypass pll3_sw_clk */ |
| 1456 | reg = readl(&mxc_ccm->ccsr); |
| 1457 | reg &= ~MXC_CCM_CCSR_PLL3_SW_CLK_SEL; |
| 1458 | writel(reg, &mxc_ccm->ccsr); |
| 1459 | |
| 1460 | /* |
| 1461 | * Set the periph2_clk_sel back to the bottom mux so that |
| 1462 | * mmdc_ch1 is from its original parent. |
| 1463 | */ |
| 1464 | reg = readl(&mxc_ccm->cbcdr); |
| 1465 | reg &= ~MXC_CCM_CBCDR_PERIPH2_CLK_SEL; |
| 1466 | writel(reg, &mxc_ccm->cbcdr); |
| 1467 | |
| 1468 | /* Wait for the clock switch */ |
| 1469 | while (readl(&mxc_ccm->cdhipr)) |
| 1470 | ; |
| 1471 | /* Clear MMDC_CH1 mask bit */ |
| 1472 | reg = readl(&mxc_ccm->ccdr); |
| 1473 | reg &= ~MXC_CCM_CCDR_MMDC_CH1_HS_MASK; |
| 1474 | writel(reg, &mxc_ccm->ccdr); |
| 1475 | |
| 1476 | enable_ldb_di_clock_sources(); |
| 1477 | } |
| 1478 | #endif |
| 1479 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1480 | /***************************************************/ |
| 1481 | |
| 1482 | U_BOOT_CMD( |
| 1483 | clocks, CONFIG_SYS_MAXARGS, 1, do_mx6_showclocks, |
| 1484 | "display clocks", |
| 1485 | "" |
| 1486 | ); |
Anatolij Gustschin | 03dd986 | 2017-08-28 21:46:26 +0200 | [diff] [blame] | 1487 | #endif |