Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2010-2011 Freescale Semiconductor, Inc. |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Christian Gmeiner | 5a66016 | 2014-01-08 08:24:25 +0100 | [diff] [blame] | 7 | #include <div64.h> |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 8 | #include <asm/io.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 9 | #include <linux/errno.h> |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 10 | #include <asm/arch/imx-regs.h> |
Fabio Estevam | 6a37604 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 11 | #include <asm/arch/crm_regs.h> |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 12 | #include <asm/arch/clock.h> |
Fabio Estevam | 6a37604 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 13 | #include <asm/arch/sys_proto.h> |
Jason Liu | 23608e2 | 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 | 9ba18ff | 2016-01-06 11:06:31 +0800 | [diff] [blame] | 20 | PLL_AUDIO, /* AUDIO PLL */ |
Anatolij Gustschin | ff3a5fc | 2017-08-02 16:05:12 +0200 | [diff] [blame] | 21 | PLL_VIDEO, /* VIDEO PLL */ |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
Fabio Estevam | 6a37604 | 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 | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 25 | |
Benoît Thébaudeau | 112fd2e | 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 | 224beb8 | 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 | 90447ef | 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 | 224beb8 | 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 | 90447ef | 2015-01-12 16:46:17 +0800 | [diff] [blame] | 71 | #endif |
Nikita Kiryanov | 224beb8 | 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 | 3f46752 | 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 | 0bb7e31 | 2012-09-21 07:33:51 +0000 | [diff] [blame] | 87 | reg |= MXC_CCM_CCGR6_USBOH3_MASK; |
Wolfgang Grandegger | 3f46752 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 88 | else |
Eric Nelson | 0bb7e31 | 2012-09-21 07:33:51 +0000 | [diff] [blame] | 89 | reg &= ~(MXC_CCM_CCGR6_USBOH3_MASK); |
Wolfgang Grandegger | 3f46752 | 2012-02-08 22:33:25 +0000 | [diff] [blame] | 90 | __raw_writel(reg, &imx_ccm->CCGR6); |
| 91 | |
| 92 | } |
| 93 | |
Stefano Babic | 3d8f179 | 2014-09-10 13:02:40 +0200 | [diff] [blame] | 94 | #if defined(CONFIG_FEC_MXC) && !defined(CONFIG_MX6SX) |
Nikita Kiryanov | 224beb8 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 95 | void enable_enet_clk(unsigned char enable) |
| 96 | { |
Peng Fan | 43cb127 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 97 | u32 mask, *addr; |
| 98 | |
Peng Fan | 3974b7f | 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 | 43cb127 | 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 | 224beb8 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 109 | |
| 110 | if (enable) |
Peng Fan | 43cb127 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 111 | setbits_le32(addr, mask); |
Nikita Kiryanov | 224beb8 | 2014-08-20 15:08:49 +0300 | [diff] [blame] | 112 | else |
Peng Fan | 43cb127 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 113 | clrbits_le32(addr, mask); |
Nikita Kiryanov | 224beb8 | 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 | 43cb127 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 120 | u32 mask; |
| 121 | |
Peng Fan | 3974b7f | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 122 | if (is_mx6ul() || is_mx6ull()) |
Peng Fan | 43cb127 | 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 | 224beb8 | 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 | 224beb8 | 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; |
| 149 | } |
| 150 | #endif |
| 151 | |
trem | fac9640 | 2013-09-21 18:13:35 +0200 | [diff] [blame] | 152 | #ifdef CONFIG_SYS_I2C_MXC |
Heiko Schocher | 21a2694 | 2015-05-18 10:56:24 +0200 | [diff] [blame] | 153 | /* i2c_num can be from 0 - 3 */ |
Troy Kisky | cc54a0f | 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 | 19c6ec7 | 2015-07-01 17:01:50 +0800 | [diff] [blame] | 158 | u32 *addr; |
Troy Kisky | cc54a0f | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 159 | |
Heiko Schocher | 21a2694 | 2015-05-18 10:56:24 +0200 | [diff] [blame] | 160 | if (i2c_num > 3) |
Troy Kisky | cc54a0f | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 161 | return -EINVAL; |
Heiko Schocher | 21a2694 | 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 | dfca246 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 173 | if (is_mx6sll()) |
| 174 | return -EINVAL; |
Peng Fan | 3974b7f | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 175 | if (is_mx6sx() || is_mx6ul() || is_mx6ull()) { |
Peng Fan | 19c6ec7 | 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 | 21a2694 | 2015-05-18 10:56:24 +0200 | [diff] [blame] | 183 | if (enable) |
| 184 | reg |= mask; |
| 185 | else |
| 186 | reg &= ~mask; |
Peng Fan | 19c6ec7 | 2015-07-01 17:01:50 +0800 | [diff] [blame] | 187 | __raw_writel(reg, addr); |
Heiko Schocher | 21a2694 | 2015-05-18 10:56:24 +0200 | [diff] [blame] | 188 | } |
Troy Kisky | cc54a0f | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | #endif |
| 192 | |
Heiko Schocher | a0ae009 | 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 | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 211 | static u32 decode_pll(enum pll_clocks pll, u32 infreq) |
| 212 | { |
Peng Fan | 9ba18ff | 2016-01-06 11:06:31 +0800 | [diff] [blame] | 213 | u32 div, test_div, pll_num, pll_denom; |
Jason Liu | 23608e2 | 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 | 2eb268f | 2014-06-10 08:47:13 +1200 | [diff] [blame] | 220 | return (infreq * div) >> 1; |
Jason Liu | 23608e2 | 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 | 89cfd0f | 2013-12-03 18:26:13 -0200 | [diff] [blame] | 235 | return 25000000 * (div + (div >> 1) + 1); |
Peng Fan | 9ba18ff | 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 | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 274 | default: |
| 275 | return 0; |
| 276 | } |
| 277 | /* NOTREACHED */ |
| 278 | } |
Pierre Aubert | 762a88c | 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 | 3974b7f | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 286 | if (!is_mx6ul() && !is_mx6ull()) { |
Peng Fan | 43cb127 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 287 | if (pfd_num == 3) { |
Peng Fan | 1f17562 | 2016-06-30 21:08:00 +0800 | [diff] [blame] | 288 | /* No PFD3 on PLL2 */ |
Peng Fan | 43cb127 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 289 | return 0; |
| 290 | } |
Pierre Aubert | 762a88c | 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 | 5a66016 | 2014-01-08 08:24:25 +0100 | [diff] [blame] | 304 | return lldiv(freq * 18, (div & ANATOP_PFD_FRAC_MASK(pfd_num)) >> |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 305 | ANATOP_PFD_FRAC_SHIFT(pfd_num)); |
| 306 | } |
Jason Liu | 23608e2 | 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 | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 315 | freq = decode_pll(PLL_SYS, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 316 | |
| 317 | return freq / (reg + 1); |
| 318 | } |
| 319 | |
Fabio Estevam | 6a37604 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 320 | u32 get_periph_clk(void) |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 321 | { |
Peng Fan | 43cb127 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 322 | u32 reg, div = 0, freq = 0; |
Jason Liu | 23608e2 | 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 | 43cb127 | 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 | 23608e2 | 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 | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 334 | freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 335 | break; |
| 336 | case 1: |
| 337 | case 2: |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 338 | freq = MXC_HCLK; |
Jason Liu | 23608e2 | 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 | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 350 | freq = decode_pll(PLL_BUS, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 351 | break; |
| 352 | case 1: |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 353 | freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 354 | break; |
| 355 | case 2: |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 356 | freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 357 | break; |
| 358 | case 3: |
Pierre Aubert | 762a88c | 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 | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 361 | break; |
| 362 | default: |
| 363 | break; |
| 364 | } |
| 365 | } |
| 366 | |
Peng Fan | 43cb127 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 367 | return freq / (div + 1); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Jason Liu | 23608e2 | 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 | dfca246 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 386 | if (is_mx6sll() || is_mx6sl() || is_mx6sx() || |
Peng Fan | 3974b7f | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 387 | is_mx6dqp() || is_mx6ul() || is_mx6ull()) { |
Peng Fan | e1c2d68 | 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 | 23608e2 | 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 | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 400 | u32 freq = decode_pll(PLL_USBOTG, MXC_HCLK) / 6; /* static divider */ |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 401 | reg = __raw_readl(&imx_ccm->cscdr1); |
Peng Fan | e1c2d68 | 2015-07-11 11:38:43 +0800 | [diff] [blame] | 402 | |
Peng Fan | 3974b7f | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 403 | if (is_mx6sl() || is_mx6sx() || is_mx6dqp() || is_mx6ul() || |
Peng Fan | dfca246 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 404 | is_mx6sll() || is_mx6ull()) { |
Peng Fan | e1c2d68 | 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 | 23608e2 | 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 | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 412 | return freq / (uart_podf + 1); |
Jason Liu | 23608e2 | 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 | e1c2d68 | 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 | 3974b7f | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 423 | if (is_mx6dqp() || is_mx6sl() || is_mx6sx() || is_mx6ul() || |
Peng Fan | dfca246 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 424 | is_mx6sll() || is_mx6ull()) { |
Peng Fan | e1c2d68 | 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 | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 428 | |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 429 | return decode_pll(PLL_USBOTG, MXC_HCLK) / (8 * (cspi_podf + 1)); |
Jason Liu | 23608e2 | 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 | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 442 | root_freq = mxc_get_pll_pfd(PLL_USBOTG, 1); |
Fabio Estevam | 8f2e2f1 | 2016-07-18 10:19:28 -0300 | [diff] [blame] | 443 | else |
| 444 | root_freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | 23608e2 | 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 | d55e0da | 2013-07-04 06:27:32 -0500 | [diff] [blame] | 453 | u32 emi_clk_sel, emi_slow_podf, cscmr1, root_freq = 0; |
Jason Liu | 23608e2 | 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 | d55e0da | 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 | 23608e2 | 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 | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 466 | root_freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 467 | break; |
| 468 | case 2: |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 469 | root_freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 470 | break; |
| 471 | case 3: |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 472 | root_freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 473 | break; |
| 474 | } |
| 475 | |
Andrew Gabbasov | d55e0da | 2013-07-04 06:27:32 -0500 | [diff] [blame] | 476 | return root_freq / (emi_slow_podf + 1); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Fabio Estevam | 25b4aa1 | 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 | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 483 | |
Peng Fan | 9ba18ff | 2016-01-06 11:06:31 +0800 | [diff] [blame] | 484 | u32 freq, podf, per2_clk2_podf, pmu_misc2_audio_div; |
Fabio Estevam | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 485 | |
Peng Fan | dfca246 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 486 | if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl() || |
| 487 | is_mx6sll()) { |
Peng Fan | 43cb127 | 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 | b949fd2 | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 493 | if (is_mx6sl()) { |
Peng Fan | 43cb127 | 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 | 0e81982 | 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 | 9ba18ff | 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 | 43cb127 | 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 | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 547 | } |
Fabio Estevam | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 548 | } |
Fabio Estevam | 31f0796 | 2013-09-13 00:36:28 -0300 | [diff] [blame] | 549 | |
Peng Fan | ad15378 | 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 | dfca246 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 630 | if (!is_mx6sx() && !is_mx6ul() && !is_mx6ull() && !is_mx6sl() && |
| 631 | !is_mx6sll()) { |
Peng Fan | ad15378 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 632 | debug("This chip not support lcd!\n"); |
| 633 | return; |
| 634 | } |
| 635 | |
Peng Fan | e332623 | 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 | ad15378 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 643 | } |
| 644 | |
Peng Fan | b949fd2 | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 645 | if (is_mx6sx()) { |
Peng Fan | ad15378 | 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 | ad15378 | 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 | 708f692 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 713 | enable_lcdif_clock(base_addr, 0); |
Peng Fan | e332623 | 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 | ad15378 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 722 | |
Peng Fan | e332623 | 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 | 708f692 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 743 | |
| 744 | enable_lcdif_clock(base_addr, 1); |
Peng Fan | b949fd2 | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 745 | } else if (is_mx6sx()) { |
Peng Fan | ad15378 | 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 | 708f692 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 750 | enable_lcdif_clock(base_addr, 0); |
Peng Fan | ad15378 | 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 | 708f692 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 764 | |
| 765 | enable_lcdif_clock(base_addr, 1); |
Peng Fan | ad15378 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | |
Peng Fan | 708f692 | 2016-12-11 19:24:28 +0800 | [diff] [blame] | 769 | int enable_lcdif_clock(u32 base_addr, bool enable) |
Peng Fan | ad15378 | 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 | b949fd2 | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 774 | if (is_mx6sx()) { |
Ye Li | 9655ebd | 2016-01-26 22:01:57 +0800 | [diff] [blame] | 775 | if ((base_addr != LCDIF1_BASE_ADDR) && |
| 776 | (base_addr != LCDIF2_BASE_ADDR)) { |
Peng Fan | ad15378 | 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 | dfca246 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 789 | } else if (is_mx6ul() || is_mx6ull() || is_mx6sll()) { |
Peng Fan | ad15378 | 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 | e332623 | 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 | 708f692 | 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 | e332623 | 2016-12-11 19:24:27 +0800 | [diff] [blame] | 813 | |
Peng Fan | 708f692 | 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 | e332623 | 2016-12-11 19:24:27 +0800 | [diff] [blame] | 819 | |
| 820 | return 0; |
Peng Fan | ad15378 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 821 | } else { |
| 822 | return 0; |
| 823 | } |
| 824 | |
Peng Fan | 70ac169 | 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 | 708f692 | 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 | ad15378 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 839 | |
Peng Fan | 708f692 | 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 | ad15378 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 844 | |
Peng Fan | 708f692 | 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 | 0ff47e5 | 2015-11-29 18:30:34 +0100 | [diff] [blame] | 849 | |
| 850 | return 0; |
Peng Fan | ad15378 | 2015-10-29 15:54:47 +0800 | [diff] [blame] | 851 | } |
| 852 | #endif |
| 853 | |
Peng Fan | 43cb127 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 854 | #ifdef CONFIG_FSL_QSPI |
Peng Fan | b93ab2e | 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 | c655b81 | 2013-12-16 20:44:05 -0200 | [diff] [blame] | 904 | #ifdef CONFIG_FEC_MXC |
Peng Fan | 6d97dc1 | 2015-08-12 17:46:50 +0800 | [diff] [blame] | 905 | int enable_fec_anatop_clock(int fec_id, enum enet_freq freq) |
Fabio Estevam | 31f0796 | 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 | 7731745 | 2014-11-27 13:46:43 +0100 | [diff] [blame] | 913 | if (freq < ENET_25MHZ || freq > ENET_125MHZ) |
Fabio Estevam | 5f98d0b | 2014-01-03 15:55:57 -0200 | [diff] [blame] | 914 | return -EINVAL; |
| 915 | |
Peng Fan | e2748b4 | 2015-09-06 17:15:47 +0800 | [diff] [blame] | 916 | reg = readl(&anatop->pll_enet); |
| 917 | |
Peng Fan | 6d97dc1 | 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 | 3974b7f | 2016-08-11 14:02:47 +0800 | [diff] [blame] | 923 | if (!(is_mx6sx() || is_mx6ul() || is_mx6ull())) |
Peng Fan | 6d97dc1 | 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 | 5f98d0b | 2014-01-03 15:55:57 -0200 | [diff] [blame] | 930 | |
Fabio Estevam | 31f0796 | 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 | 6d97dc1 | 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 | 31f0796 | 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 | 5c045cd | 2014-08-15 00:24:30 -0300 | [diff] [blame] | 951 | #ifdef CONFIG_MX6SX |
Ye.Li | 27e3a3c | 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 | 5c045cd | 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 | 31f0796 | 2013-09-13 00:36:28 -0300 | [diff] [blame] | 977 | return 0; |
| 978 | } |
Fabio Estevam | 25b4aa1 | 2013-04-10 09:32:57 +0000 | [diff] [blame] | 979 | #endif |
Jason Liu | 23608e2 | 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 | dfca246 | 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 | 23608e2 | 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 | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 1027 | root_freq = mxc_get_pll_pfd(PLL_BUS, 0); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1028 | else |
Pierre Aubert | 762a88c | 2013-09-19 17:48:59 +0200 | [diff] [blame] | 1029 | root_freq = mxc_get_pll_pfd(PLL_BUS, 2); |
Jason Liu | 23608e2 | 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 | ff167df | 2011-12-16 05:17:06 +0000 | [diff] [blame] | 1039 | u32 imx_get_fecclk(void) |
| 1040 | { |
Markus Niebel | adadc91 | 2014-02-05 10:51:25 +0100 | [diff] [blame] | 1041 | return mxc_get_clock(MXC_IPG_CLK); |
Jason Liu | ff167df | 2011-12-16 05:17:06 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
Simon Glass | 10e40d5 | 2017-06-14 21:28:25 -0600 | [diff] [blame] | 1044 | #if defined(CONFIG_SATA) || defined(CONFIG_PCIE_IMX) |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1045 | static int enable_enet_pll(uint32_t en) |
Eric Nelson | 64e7cdb | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 1046 | { |
Eric Nelson | 64e7cdb | 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 | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1049 | s32 timeout = 100000; |
| 1050 | u32 reg = 0; |
Eric Nelson | 64e7cdb | 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 | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1065 | reg |= en; |
Eric Nelson | 64e7cdb | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 1066 | writel(reg, &imx_ccm->analog_pll_enet); |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1067 | return 0; |
| 1068 | } |
Peng Fan | 43cb127 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 1069 | #endif |
Eric Nelson | 64e7cdb | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 1070 | |
Simon Glass | 10e40d5 | 2017-06-14 21:28:25 -0600 | [diff] [blame] | 1071 | #ifdef CONFIG_SATA |
Marek Vasut | 7981449 | 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 | 7981449 | 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 | 8d29cef | 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 | d95b6ab | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 1094 | #endif |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1095 | |
Peng Fan | 43cb127 | 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 | 7981449 | 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 | 1b8ad74 | 2014-08-25 14:26:45 -0300 | [diff] [blame] | 1111 | u32 lvds1_clk_sel; |
Marek Vasut | 7981449 | 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 | 1b8ad74 | 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 | 7981449 | 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 | 1b8ad74 | 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 | b949fd2 | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 1131 | if (is_mx6sx()) |
Fabio Estevam | 1b8ad74 | 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 | 7981449 | 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 | 1b8ad74 | 2014-08-25 14:26:45 -0300 | [diff] [blame] | 1139 | ANADIG_ANA_MISC1_LVDSCLK1_OBEN | lvds1_clk_sel); |
Marek Vasut | 7981449 | 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 | 10e40d5 | 2017-06-14 21:28:25 -0600 | [diff] [blame] | 1145 | #ifdef CONFIG_SATA |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1146 | ungate_sata_clock(); |
Fabio Estevam | d95b6ab | 2014-06-24 17:41:00 -0300 | [diff] [blame] | 1147 | #endif |
Marek Vasut | 7981449 | 2013-12-14 06:27:26 +0100 | [diff] [blame] | 1148 | ungate_pcie_clock(); |
| 1149 | |
| 1150 | return enable_enet_pll(BM_ANADIG_PLL_ENET_ENABLE_SATA | |
| 1151 | BM_ANADIG_PLL_ENET_ENABLE_PCIE); |
Eric Nelson | 64e7cdb | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 1152 | } |
Peng Fan | 43cb127 | 2015-07-20 19:28:27 +0800 | [diff] [blame] | 1153 | #endif |
Eric Nelson | 64e7cdb | 2012-03-27 09:52:21 +0000 | [diff] [blame] | 1154 | |
Stefano Babic | d714a75 | 2019-09-20 08:47:53 +0200 | [diff] [blame] | 1155 | #ifdef CONFIG_IMX_HAB |
Nitin Garg | 36c1ca4 | 2014-09-16 13:33:25 -0500 | [diff] [blame] | 1156 | void hab_caam_clock_enable(unsigned char enable) |
| 1157 | { |
| 1158 | u32 reg; |
| 1159 | |
Peng Fan | dfca246 | 2016-12-11 19:24:29 +0800 | [diff] [blame] | 1160 | if (is_mx6ull() || is_mx6sll()) { |
Peng Fan | 3974b7f | 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 | 36c1ca4 | 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 | cf202d2 | 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 | 38df370 | 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 | 23608e2 | 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 | e7bed5c | 2012-09-24 02:46:53 +0000 | [diff] [blame] | 1248 | case MXC_I2C_CLK: |
Jason Liu | 23608e2 | 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 | eb412d7 | 2014-11-23 11:52:20 +0800 | [diff] [blame] | 1271 | printf("Unsupported MXC CLK: %d\n", clk); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1272 | break; |
| 1273 | } |
| 1274 | |
Peng Fan | eb412d7 | 2014-11-23 11:52:20 +0800 | [diff] [blame] | 1275 | return 0; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
Fabio Estevam | b8bffab | 2019-07-12 09:10:35 -0300 | [diff] [blame] | 1278 | #ifndef CONFIG_MX6SX |
| 1279 | void enable_ipu_clock(void) |
| 1280 | { |
| 1281 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
Fabio Estevam | 1be51fe | 2019-07-12 09:32:22 -0300 | [diff] [blame] | 1282 | |
| 1283 | setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_IPU1_IPU_MASK); |
Fabio Estevam | b8bffab | 2019-07-12 09:10:35 -0300 | [diff] [blame] | 1284 | |
| 1285 | if (is_mx6dqp()) { |
| 1286 | setbits_le32(&mxc_ccm->CCGR6, MXC_CCM_CCGR6_PRG_CLK0_MASK); |
| 1287 | setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_IPU2_IPU_MASK); |
| 1288 | } |
| 1289 | } |
Fabio Estevam | fa64df4 | 2019-07-12 09:32:23 -0300 | [diff] [blame] | 1290 | |
| 1291 | void disable_ipu_clock(void) |
| 1292 | { |
| 1293 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 1294 | |
| 1295 | clrbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_IPU1_IPU_MASK); |
| 1296 | |
| 1297 | if (is_mx6dqp()) { |
| 1298 | clrbits_le32(&mxc_ccm->CCGR6, MXC_CCM_CCGR6_PRG_CLK0_MASK); |
| 1299 | clrbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_IPU2_IPU_MASK); |
| 1300 | } |
| 1301 | } |
Fabio Estevam | b8bffab | 2019-07-12 09:10:35 -0300 | [diff] [blame] | 1302 | #endif |
| 1303 | |
Anatolij Gustschin | 38df370 | 2017-08-28 21:46:26 +0200 | [diff] [blame] | 1304 | #ifndef CONFIG_SPL_BUILD |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1305 | /* |
| 1306 | * Dump some core clockes. |
| 1307 | */ |
| 1308 | int do_mx6_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 1309 | { |
| 1310 | u32 freq; |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 1311 | freq = decode_pll(PLL_SYS, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1312 | printf("PLL_SYS %8d MHz\n", freq / 1000000); |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 1313 | freq = decode_pll(PLL_BUS, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1314 | printf("PLL_BUS %8d MHz\n", freq / 1000000); |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 1315 | freq = decode_pll(PLL_USBOTG, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1316 | printf("PLL_OTG %8d MHz\n", freq / 1000000); |
Benoît Thébaudeau | 833b643 | 2012-09-27 10:19:58 +0000 | [diff] [blame] | 1317 | freq = decode_pll(PLL_ENET, MXC_HCLK); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1318 | printf("PLL_NET %8d MHz\n", freq / 1000000); |
| 1319 | |
| 1320 | printf("\n"); |
Peng Fan | d78e7f2 | 2016-03-09 16:44:38 +0800 | [diff] [blame] | 1321 | printf("ARM %8d kHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1322 | printf("IPG %8d kHz\n", mxc_get_clock(MXC_IPG_CLK) / 1000); |
| 1323 | printf("UART %8d kHz\n", mxc_get_clock(MXC_UART_CLK) / 1000); |
Fabio Estevam | cc44672 | 2012-11-16 01:30:10 +0000 | [diff] [blame] | 1324 | #ifdef CONFIG_MXC_SPI |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1325 | printf("CSPI %8d kHz\n", mxc_get_clock(MXC_CSPI_CLK) / 1000); |
Fabio Estevam | cc44672 | 2012-11-16 01:30:10 +0000 | [diff] [blame] | 1326 | #endif |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1327 | printf("AHB %8d kHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000); |
| 1328 | printf("AXI %8d kHz\n", mxc_get_clock(MXC_AXI_CLK) / 1000); |
| 1329 | printf("DDR %8d kHz\n", mxc_get_clock(MXC_DDR_CLK) / 1000); |
| 1330 | printf("USDHC1 %8d kHz\n", mxc_get_clock(MXC_ESDHC_CLK) / 1000); |
| 1331 | printf("USDHC2 %8d kHz\n", mxc_get_clock(MXC_ESDHC2_CLK) / 1000); |
| 1332 | printf("USDHC3 %8d kHz\n", mxc_get_clock(MXC_ESDHC3_CLK) / 1000); |
| 1333 | printf("USDHC4 %8d kHz\n", mxc_get_clock(MXC_ESDHC4_CLK) / 1000); |
| 1334 | printf("EMI SLOW %8d kHz\n", mxc_get_clock(MXC_EMI_SLOW_CLK) / 1000); |
| 1335 | printf("IPG PERCLK %8d kHz\n", mxc_get_clock(MXC_IPG_PERCLK) / 1000); |
| 1336 | |
| 1337 | return 0; |
| 1338 | } |
| 1339 | |
Akshay Bhat | 90d7cc4 | 2016-04-12 18:13:56 -0400 | [diff] [blame] | 1340 | #if defined(CONFIG_MX6Q) || defined(CONFIG_MX6D) || defined(CONFIG_MX6DL) || \ |
| 1341 | defined(CONFIG_MX6S) |
| 1342 | static void disable_ldb_di_clock_sources(void) |
| 1343 | { |
| 1344 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 1345 | int reg; |
| 1346 | |
| 1347 | /* Make sure PFDs are disabled at boot. */ |
| 1348 | reg = readl(&mxc_ccm->analog_pfd_528); |
| 1349 | /* Cannot disable pll2_pfd2_396M, as it is the MMDC clock in iMX6DL */ |
Peng Fan | b949fd2 | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 1350 | if (is_mx6sdl()) |
Akshay Bhat | 90d7cc4 | 2016-04-12 18:13:56 -0400 | [diff] [blame] | 1351 | reg |= 0x80008080; |
| 1352 | else |
| 1353 | reg |= 0x80808080; |
| 1354 | writel(reg, &mxc_ccm->analog_pfd_528); |
| 1355 | |
| 1356 | /* Disable PLL3 PFDs */ |
| 1357 | reg = readl(&mxc_ccm->analog_pfd_480); |
| 1358 | reg |= 0x80808080; |
| 1359 | writel(reg, &mxc_ccm->analog_pfd_480); |
| 1360 | |
| 1361 | /* Disable PLL5 */ |
| 1362 | reg = readl(&mxc_ccm->analog_pll_video); |
| 1363 | reg &= ~(1 << 13); |
| 1364 | writel(reg, &mxc_ccm->analog_pll_video); |
| 1365 | } |
| 1366 | |
| 1367 | static void enable_ldb_di_clock_sources(void) |
| 1368 | { |
| 1369 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 1370 | int reg; |
| 1371 | |
| 1372 | reg = readl(&mxc_ccm->analog_pfd_528); |
Peng Fan | b949fd2 | 2016-05-23 18:35:54 +0800 | [diff] [blame] | 1373 | if (is_mx6sdl()) |
Akshay Bhat | 90d7cc4 | 2016-04-12 18:13:56 -0400 | [diff] [blame] | 1374 | reg &= ~(0x80008080); |
| 1375 | else |
| 1376 | reg &= ~(0x80808080); |
| 1377 | writel(reg, &mxc_ccm->analog_pfd_528); |
| 1378 | |
| 1379 | reg = readl(&mxc_ccm->analog_pfd_480); |
| 1380 | reg &= ~(0x80808080); |
| 1381 | writel(reg, &mxc_ccm->analog_pfd_480); |
| 1382 | } |
| 1383 | |
| 1384 | /* |
| 1385 | * Try call this function as early in the boot process as possible since the |
| 1386 | * function temporarily disables PLL2 PFD's, PLL3 PFD's and PLL5. |
| 1387 | */ |
| 1388 | void select_ldb_di_clock_source(enum ldb_di_clock clk) |
| 1389 | { |
| 1390 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 1391 | int reg; |
| 1392 | |
| 1393 | /* |
| 1394 | * Need to follow a strict procedure when changing the LDB |
| 1395 | * clock, else we can introduce a glitch. Things to keep in |
| 1396 | * mind: |
| 1397 | * 1. The current and new parent clocks must be disabled. |
| 1398 | * 2. The default clock for ldb_dio_clk is mmdc_ch1 which has |
| 1399 | * no CG bit. |
| 1400 | * 3. In the RTL implementation of the LDB_DI_CLK_SEL mux |
| 1401 | * the top four options are in one mux and the PLL3 option along |
| 1402 | * with another option is in the second mux. There is third mux |
| 1403 | * used to decide between the first and second mux. |
| 1404 | * The code below switches the parent to the bottom mux first |
| 1405 | * and then manipulates the top mux. This ensures that no glitch |
| 1406 | * will enter the divider. |
| 1407 | * |
| 1408 | * Need to disable MMDC_CH1 clock manually as there is no CG bit |
| 1409 | * for this clock. The only way to disable this clock is to move |
| 1410 | * it to pll3_sw_clk and then to disable pll3_sw_clk |
| 1411 | * Make sure periph2_clk2_sel is set to pll3_sw_clk |
| 1412 | */ |
| 1413 | |
| 1414 | /* Disable all ldb_di clock parents */ |
| 1415 | disable_ldb_di_clock_sources(); |
| 1416 | |
| 1417 | /* Set MMDC_CH1 mask bit */ |
| 1418 | reg = readl(&mxc_ccm->ccdr); |
| 1419 | reg |= MXC_CCM_CCDR_MMDC_CH1_HS_MASK; |
| 1420 | writel(reg, &mxc_ccm->ccdr); |
| 1421 | |
| 1422 | /* Set periph2_clk2_sel to be sourced from PLL3_sw_clk */ |
| 1423 | reg = readl(&mxc_ccm->cbcmr); |
| 1424 | reg &= ~MXC_CCM_CBCMR_PERIPH2_CLK2_SEL; |
| 1425 | writel(reg, &mxc_ccm->cbcmr); |
| 1426 | |
| 1427 | /* |
| 1428 | * Set the periph2_clk_sel to the top mux so that |
| 1429 | * mmdc_ch1 is from pll3_sw_clk. |
| 1430 | */ |
| 1431 | reg = readl(&mxc_ccm->cbcdr); |
| 1432 | reg |= MXC_CCM_CBCDR_PERIPH2_CLK_SEL; |
| 1433 | writel(reg, &mxc_ccm->cbcdr); |
| 1434 | |
| 1435 | /* Wait for the clock switch */ |
| 1436 | while (readl(&mxc_ccm->cdhipr)) |
| 1437 | ; |
| 1438 | /* Disable pll3_sw_clk by selecting bypass clock source */ |
| 1439 | reg = readl(&mxc_ccm->ccsr); |
| 1440 | reg |= MXC_CCM_CCSR_PLL3_SW_CLK_SEL; |
| 1441 | writel(reg, &mxc_ccm->ccsr); |
| 1442 | |
| 1443 | /* Set the ldb_di0_clk and ldb_di1_clk to 111b */ |
| 1444 | reg = readl(&mxc_ccm->cs2cdr); |
| 1445 | reg |= ((7 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET) |
| 1446 | | (7 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)); |
| 1447 | writel(reg, &mxc_ccm->cs2cdr); |
| 1448 | |
| 1449 | /* Set the ldb_di0_clk and ldb_di1_clk to 100b */ |
| 1450 | reg = readl(&mxc_ccm->cs2cdr); |
| 1451 | reg &= ~(MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK |
| 1452 | | MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK); |
| 1453 | reg |= ((4 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET) |
| 1454 | | (4 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)); |
| 1455 | writel(reg, &mxc_ccm->cs2cdr); |
| 1456 | |
| 1457 | /* Set the ldb_di0_clk and ldb_di1_clk to desired source */ |
| 1458 | reg = readl(&mxc_ccm->cs2cdr); |
| 1459 | reg &= ~(MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK |
| 1460 | | MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK); |
| 1461 | reg |= ((clk << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET) |
| 1462 | | (clk << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)); |
| 1463 | writel(reg, &mxc_ccm->cs2cdr); |
| 1464 | |
| 1465 | /* Unbypass pll3_sw_clk */ |
| 1466 | reg = readl(&mxc_ccm->ccsr); |
| 1467 | reg &= ~MXC_CCM_CCSR_PLL3_SW_CLK_SEL; |
| 1468 | writel(reg, &mxc_ccm->ccsr); |
| 1469 | |
| 1470 | /* |
| 1471 | * Set the periph2_clk_sel back to the bottom mux so that |
| 1472 | * mmdc_ch1 is from its original parent. |
| 1473 | */ |
| 1474 | reg = readl(&mxc_ccm->cbcdr); |
| 1475 | reg &= ~MXC_CCM_CBCDR_PERIPH2_CLK_SEL; |
| 1476 | writel(reg, &mxc_ccm->cbcdr); |
| 1477 | |
| 1478 | /* Wait for the clock switch */ |
| 1479 | while (readl(&mxc_ccm->cdhipr)) |
| 1480 | ; |
| 1481 | /* Clear MMDC_CH1 mask bit */ |
| 1482 | reg = readl(&mxc_ccm->ccdr); |
| 1483 | reg &= ~MXC_CCM_CCDR_MMDC_CH1_HS_MASK; |
| 1484 | writel(reg, &mxc_ccm->ccdr); |
| 1485 | |
| 1486 | enable_ldb_di_clock_sources(); |
| 1487 | } |
| 1488 | #endif |
| 1489 | |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 1490 | /***************************************************/ |
| 1491 | |
| 1492 | U_BOOT_CMD( |
| 1493 | clocks, CONFIG_SYS_MAXARGS, 1, do_mx6_showclocks, |
| 1494 | "display clocks", |
| 1495 | "" |
| 1496 | ); |
Anatolij Gustschin | 38df370 | 2017-08-28 21:46:26 +0200 | [diff] [blame] | 1497 | #endif |