Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Sascha Hauer, Pengutronix |
| 4 | * |
| 5 | * (C) Copyright 2009 Freescale Semiconductor, Inc. |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <asm/io.h> |
| 28 | #include <asm/errno.h> |
| 29 | #include <asm/arch/imx-regs.h> |
| 30 | #include <asm/arch/crm_regs.h> |
Stefano Babic | ac41d4d | 2010-03-05 17:54:37 +0100 | [diff] [blame] | 31 | #include <asm/arch/clock.h> |
Marek Vasut | 3c844f3 | 2011-09-23 11:43:47 +0200 | [diff] [blame] | 32 | #include <div64.h> |
Fabio Estevam | 6479f51 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 33 | #include <asm/arch/sys_proto.h> |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 34 | |
| 35 | enum pll_clocks { |
| 36 | PLL1_CLOCK = 0, |
| 37 | PLL2_CLOCK, |
| 38 | PLL3_CLOCK, |
Marek Vasut | 3c844f3 | 2011-09-23 11:43:47 +0200 | [diff] [blame] | 39 | PLL4_CLOCK, |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 40 | PLL_CLOCKS, |
| 41 | }; |
| 42 | |
| 43 | struct mxc_pll_reg *mxc_plls[PLL_CLOCKS] = { |
| 44 | [PLL1_CLOCK] = (struct mxc_pll_reg *)PLL1_BASE_ADDR, |
| 45 | [PLL2_CLOCK] = (struct mxc_pll_reg *)PLL2_BASE_ADDR, |
| 46 | [PLL3_CLOCK] = (struct mxc_pll_reg *)PLL3_BASE_ADDR, |
Marek Vasut | 3c844f3 | 2011-09-23 11:43:47 +0200 | [diff] [blame] | 47 | #ifdef CONFIG_MX53 |
| 48 | [PLL4_CLOCK] = (struct mxc_pll_reg *)PLL4_BASE_ADDR, |
| 49 | #endif |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 50 | }; |
| 51 | |
Fabio Estevam | b412101 | 2012-04-30 08:12:02 +0000 | [diff] [blame] | 52 | #define AHB_CLK_ROOT 133333333 |
| 53 | #define SZ_DEC_1M 1000000 |
| 54 | #define PLL_PD_MAX 16 /* Actual pd+1 */ |
| 55 | #define PLL_MFI_MAX 15 |
| 56 | #define PLL_MFI_MIN 5 |
| 57 | #define ARM_DIV_MAX 8 |
| 58 | #define IPG_DIV_MAX 4 |
| 59 | #define AHB_DIV_MAX 8 |
| 60 | #define EMI_DIV_MAX 8 |
| 61 | #define NFC_DIV_MAX 8 |
| 62 | |
| 63 | #define MX5_CBCMR 0x00015154 |
| 64 | #define MX5_CBCDR 0x02888945 |
| 65 | |
| 66 | struct fixed_pll_mfd { |
| 67 | u32 ref_clk_hz; |
| 68 | u32 mfd; |
| 69 | }; |
| 70 | |
| 71 | const struct fixed_pll_mfd fixed_mfd[] = { |
| 72 | {CONFIG_SYS_MX5_HCLK, 24 * 16}, |
| 73 | }; |
| 74 | |
| 75 | struct pll_param { |
| 76 | u32 pd; |
| 77 | u32 mfi; |
| 78 | u32 mfn; |
| 79 | u32 mfd; |
| 80 | }; |
| 81 | |
| 82 | #define PLL_FREQ_MAX(ref_clk) (4 * (ref_clk) * PLL_MFI_MAX) |
| 83 | #define PLL_FREQ_MIN(ref_clk) \ |
| 84 | ((2 * (ref_clk) * (PLL_MFI_MIN - 1)) / PLL_PD_MAX) |
| 85 | #define MAX_DDR_CLK 420000000 |
| 86 | #define NFC_CLK_MAX 34000000 |
| 87 | |
Stefano Babic | ac41d4d | 2010-03-05 17:54:37 +0100 | [diff] [blame] | 88 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE; |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 89 | |
Wolfgang Grandegger | 8c1e4d3 | 2011-11-11 14:03:34 +0100 | [diff] [blame] | 90 | void set_usboh3_clk(void) |
| 91 | { |
| 92 | unsigned int reg; |
| 93 | |
| 94 | reg = readl(&mxc_ccm->cscmr1) & |
| 95 | ~MXC_CCM_CSCMR1_USBOH3_CLK_SEL_MASK; |
| 96 | reg |= 1 << MXC_CCM_CSCMR1_USBOH3_CLK_SEL_OFFSET; |
| 97 | writel(reg, &mxc_ccm->cscmr1); |
| 98 | |
| 99 | reg = readl(&mxc_ccm->cscdr1); |
| 100 | reg &= ~MXC_CCM_CSCDR1_USBOH3_CLK_PODF_MASK; |
| 101 | reg &= ~MXC_CCM_CSCDR1_USBOH3_CLK_PRED_MASK; |
| 102 | reg |= 4 << MXC_CCM_CSCDR1_USBOH3_CLK_PRED_OFFSET; |
| 103 | reg |= 1 << MXC_CCM_CSCDR1_USBOH3_CLK_PODF_OFFSET; |
| 104 | |
| 105 | writel(reg, &mxc_ccm->cscdr1); |
| 106 | } |
| 107 | |
| 108 | void enable_usboh3_clk(unsigned char enable) |
| 109 | { |
| 110 | unsigned int reg; |
| 111 | |
| 112 | reg = readl(&mxc_ccm->CCGR2); |
| 113 | if (enable) |
| 114 | reg |= 1 << MXC_CCM_CCGR2_CG14_OFFSET; |
| 115 | else |
| 116 | reg &= ~(1 << MXC_CCM_CCGR2_CG14_OFFSET); |
| 117 | writel(reg, &mxc_ccm->CCGR2); |
| 118 | } |
| 119 | |
Troy Kisky | d4fdc99 | 2012-07-19 08:18:25 +0000 | [diff] [blame] | 120 | #ifdef CONFIG_I2C_MXC |
| 121 | /* i2c_num can be from 0 - 2 */ |
| 122 | int enable_i2c_clk(unsigned char enable, unsigned i2c_num) |
| 123 | { |
| 124 | u32 reg; |
| 125 | u32 mask; |
| 126 | |
| 127 | if (i2c_num > 2) |
| 128 | return -EINVAL; |
| 129 | mask = MXC_CCM_CCGR_CG_MASK << ((i2c_num + 9) << 1); |
| 130 | reg = __raw_readl(&mxc_ccm->CCGR1); |
| 131 | if (enable) |
| 132 | reg |= mask; |
| 133 | else |
| 134 | reg &= ~mask; |
| 135 | __raw_writel(reg, &mxc_ccm->CCGR1); |
| 136 | return 0; |
| 137 | } |
| 138 | #endif |
| 139 | |
Wolfgang Grandegger | 8c1e4d3 | 2011-11-11 14:03:34 +0100 | [diff] [blame] | 140 | void set_usb_phy1_clk(void) |
| 141 | { |
| 142 | unsigned int reg; |
| 143 | |
| 144 | reg = readl(&mxc_ccm->cscmr1); |
| 145 | reg &= ~MXC_CCM_CSCMR1_USB_PHY_CLK_SEL; |
| 146 | writel(reg, &mxc_ccm->cscmr1); |
| 147 | } |
| 148 | |
| 149 | void enable_usb_phy1_clk(unsigned char enable) |
| 150 | { |
| 151 | unsigned int reg; |
| 152 | |
| 153 | reg = readl(&mxc_ccm->CCGR4); |
| 154 | if (enable) |
| 155 | reg |= 1 << MXC_CCM_CCGR4_CG5_OFFSET; |
| 156 | else |
| 157 | reg &= ~(1 << MXC_CCM_CCGR4_CG5_OFFSET); |
| 158 | writel(reg, &mxc_ccm->CCGR4); |
| 159 | } |
| 160 | |
| 161 | void set_usb_phy2_clk(void) |
| 162 | { |
| 163 | unsigned int reg; |
| 164 | |
| 165 | reg = readl(&mxc_ccm->cscmr1); |
| 166 | reg &= ~MXC_CCM_CSCMR1_USB_PHY_CLK_SEL; |
| 167 | writel(reg, &mxc_ccm->cscmr1); |
| 168 | } |
| 169 | |
| 170 | void enable_usb_phy2_clk(unsigned char enable) |
| 171 | { |
| 172 | unsigned int reg; |
| 173 | |
| 174 | reg = readl(&mxc_ccm->CCGR4); |
| 175 | if (enable) |
| 176 | reg |= 1 << MXC_CCM_CCGR4_CG6_OFFSET; |
| 177 | else |
| 178 | reg &= ~(1 << MXC_CCM_CCGR4_CG6_OFFSET); |
| 179 | writel(reg, &mxc_ccm->CCGR4); |
| 180 | } |
| 181 | |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 182 | /* |
Marek Vasut | 3c844f3 | 2011-09-23 11:43:47 +0200 | [diff] [blame] | 183 | * Calculate the frequency of PLLn. |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 184 | */ |
Marek Vasut | 3c844f3 | 2011-09-23 11:43:47 +0200 | [diff] [blame] | 185 | static uint32_t decode_pll(struct mxc_pll_reg *pll, uint32_t infreq) |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 186 | { |
Marek Vasut | 3c844f3 | 2011-09-23 11:43:47 +0200 | [diff] [blame] | 187 | uint32_t ctrl, op, mfd, mfn, mfi, pdf, ret; |
| 188 | uint64_t refclk, temp; |
| 189 | int32_t mfn_abs; |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 190 | |
Marek Vasut | 3c844f3 | 2011-09-23 11:43:47 +0200 | [diff] [blame] | 191 | ctrl = readl(&pll->ctrl); |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 192 | |
Marek Vasut | 3c844f3 | 2011-09-23 11:43:47 +0200 | [diff] [blame] | 193 | if (ctrl & MXC_DPLLC_CTL_HFSM) { |
| 194 | mfn = __raw_readl(&pll->hfs_mfn); |
| 195 | mfd = __raw_readl(&pll->hfs_mfd); |
| 196 | op = __raw_readl(&pll->hfs_op); |
| 197 | } else { |
| 198 | mfn = __raw_readl(&pll->mfn); |
| 199 | mfd = __raw_readl(&pll->mfd); |
| 200 | op = __raw_readl(&pll->op); |
| 201 | } |
| 202 | |
| 203 | mfd &= MXC_DPLLC_MFD_MFD_MASK; |
| 204 | mfn &= MXC_DPLLC_MFN_MFN_MASK; |
| 205 | pdf = op & MXC_DPLLC_OP_PDF_MASK; |
| 206 | mfi = (op & MXC_DPLLC_OP_MFI_MASK) >> MXC_DPLLC_OP_MFI_OFFSET; |
| 207 | |
| 208 | /* 21.2.3 */ |
| 209 | if (mfi < 5) |
| 210 | mfi = 5; |
| 211 | |
| 212 | /* Sign extend */ |
| 213 | if (mfn >= 0x04000000) { |
| 214 | mfn |= 0xfc000000; |
| 215 | mfn_abs = -mfn; |
| 216 | } else |
| 217 | mfn_abs = mfn; |
| 218 | |
| 219 | refclk = infreq * 2; |
| 220 | if (ctrl & MXC_DPLLC_CTL_DPDCK0_2_EN) |
| 221 | refclk *= 2; |
| 222 | |
Simon Glass | 3d55788 | 2011-11-05 04:25:22 +0000 | [diff] [blame] | 223 | do_div(refclk, pdf + 1); |
Marek Vasut | 3c844f3 | 2011-09-23 11:43:47 +0200 | [diff] [blame] | 224 | temp = refclk * mfn_abs; |
| 225 | do_div(temp, mfd + 1); |
| 226 | ret = refclk * mfi; |
| 227 | |
| 228 | if ((int)mfn < 0) |
| 229 | ret -= temp; |
| 230 | else |
| 231 | ret += temp; |
| 232 | |
| 233 | return ret; |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Get mcu main rate |
| 238 | */ |
| 239 | u32 get_mcu_main_clk(void) |
| 240 | { |
| 241 | u32 reg, freq; |
| 242 | |
| 243 | reg = (__raw_readl(&mxc_ccm->cacrr) & MXC_CCM_CACRR_ARM_PODF_MASK) >> |
| 244 | MXC_CCM_CACRR_ARM_PODF_OFFSET; |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 245 | freq = decode_pll(mxc_plls[PLL1_CLOCK], CONFIG_SYS_MX5_HCLK); |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 246 | return freq / (reg + 1); |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * Get the rate of peripheral's root clock. |
| 251 | */ |
Fabio Estevam | 6479f51 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 252 | u32 get_periph_clk(void) |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 253 | { |
| 254 | u32 reg; |
| 255 | |
| 256 | reg = __raw_readl(&mxc_ccm->cbcdr); |
| 257 | if (!(reg & MXC_CCM_CBCDR_PERIPH_CLK_SEL)) |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 258 | return decode_pll(mxc_plls[PLL2_CLOCK], CONFIG_SYS_MX5_HCLK); |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 259 | reg = __raw_readl(&mxc_ccm->cbcmr); |
| 260 | switch ((reg & MXC_CCM_CBCMR_PERIPH_CLK_SEL_MASK) >> |
| 261 | MXC_CCM_CBCMR_PERIPH_CLK_SEL_OFFSET) { |
| 262 | case 0: |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 263 | return decode_pll(mxc_plls[PLL1_CLOCK], CONFIG_SYS_MX5_HCLK); |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 264 | case 1: |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 265 | return decode_pll(mxc_plls[PLL3_CLOCK], CONFIG_SYS_MX5_HCLK); |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 266 | default: |
| 267 | return 0; |
| 268 | } |
| 269 | /* NOTREACHED */ |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | * Get the rate of ipg clock. |
| 274 | */ |
| 275 | static u32 get_ipg_clk(void) |
| 276 | { |
Marek Vasut | 6674bf5 | 2011-09-22 09:20:37 +0000 | [diff] [blame] | 277 | uint32_t freq, reg, div; |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 278 | |
Marek Vasut | 6674bf5 | 2011-09-22 09:20:37 +0000 | [diff] [blame] | 279 | freq = get_ahb_clk(); |
| 280 | |
| 281 | reg = __raw_readl(&mxc_ccm->cbcdr); |
| 282 | div = ((reg & MXC_CCM_CBCDR_IPG_PODF_MASK) >> |
| 283 | MXC_CCM_CBCDR_IPG_PODF_OFFSET) + 1; |
| 284 | |
| 285 | return freq / div; |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /* |
| 289 | * Get the rate of ipg_per clock. |
| 290 | */ |
| 291 | static u32 get_ipg_per_clk(void) |
| 292 | { |
| 293 | u32 pred1, pred2, podf; |
| 294 | |
| 295 | if (__raw_readl(&mxc_ccm->cbcmr) & MXC_CCM_CBCMR_PERCLK_IPG_CLK_SEL) |
| 296 | return get_ipg_clk(); |
| 297 | /* Fixme: not handle what about lpm*/ |
| 298 | podf = __raw_readl(&mxc_ccm->cbcdr); |
| 299 | pred1 = (podf & MXC_CCM_CBCDR_PERCLK_PRED1_MASK) >> |
| 300 | MXC_CCM_CBCDR_PERCLK_PRED1_OFFSET; |
| 301 | pred2 = (podf & MXC_CCM_CBCDR_PERCLK_PRED2_MASK) >> |
| 302 | MXC_CCM_CBCDR_PERCLK_PRED2_OFFSET; |
| 303 | podf = (podf & MXC_CCM_CBCDR_PERCLK_PODF_MASK) >> |
| 304 | MXC_CCM_CBCDR_PERCLK_PODF_OFFSET; |
| 305 | |
| 306 | return get_periph_clk() / ((pred1 + 1) * (pred2 + 1) * (podf + 1)); |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | * Get the rate of uart clk. |
| 311 | */ |
| 312 | static u32 get_uart_clk(void) |
| 313 | { |
| 314 | unsigned int freq, reg, pred, podf; |
| 315 | |
| 316 | reg = __raw_readl(&mxc_ccm->cscmr1); |
| 317 | switch ((reg & MXC_CCM_CSCMR1_UART_CLK_SEL_MASK) >> |
| 318 | MXC_CCM_CSCMR1_UART_CLK_SEL_OFFSET) { |
| 319 | case 0x0: |
| 320 | freq = decode_pll(mxc_plls[PLL1_CLOCK], |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 321 | CONFIG_SYS_MX5_HCLK); |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 322 | break; |
| 323 | case 0x1: |
| 324 | freq = decode_pll(mxc_plls[PLL2_CLOCK], |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 325 | CONFIG_SYS_MX5_HCLK); |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 326 | break; |
| 327 | case 0x2: |
| 328 | freq = decode_pll(mxc_plls[PLL3_CLOCK], |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 329 | CONFIG_SYS_MX5_HCLK); |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 330 | break; |
| 331 | default: |
| 332 | return 66500000; |
| 333 | } |
| 334 | |
| 335 | reg = __raw_readl(&mxc_ccm->cscdr1); |
| 336 | |
| 337 | pred = (reg & MXC_CCM_CSCDR1_UART_CLK_PRED_MASK) >> |
| 338 | MXC_CCM_CSCDR1_UART_CLK_PRED_OFFSET; |
| 339 | |
| 340 | podf = (reg & MXC_CCM_CSCDR1_UART_CLK_PODF_MASK) >> |
| 341 | MXC_CCM_CSCDR1_UART_CLK_PODF_OFFSET; |
| 342 | freq /= (pred + 1) * (podf + 1); |
| 343 | |
| 344 | return freq; |
| 345 | } |
| 346 | |
| 347 | /* |
| 348 | * This function returns the low power audio clock. |
| 349 | */ |
Fabio Estevam | b412101 | 2012-04-30 08:12:02 +0000 | [diff] [blame] | 350 | static u32 get_lp_apm(void) |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 351 | { |
| 352 | u32 ret_val = 0; |
| 353 | u32 ccsr = __raw_readl(&mxc_ccm->ccsr); |
| 354 | |
| 355 | if (((ccsr >> 9) & 1) == 0) |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 356 | ret_val = CONFIG_SYS_MX5_HCLK; |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 357 | else |
| 358 | ret_val = ((32768 * 1024)); |
| 359 | |
| 360 | return ret_val; |
| 361 | } |
| 362 | |
| 363 | /* |
| 364 | * get cspi clock rate. |
| 365 | */ |
Fabio Estevam | b412101 | 2012-04-30 08:12:02 +0000 | [diff] [blame] | 366 | static u32 imx_get_cspiclk(void) |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 367 | { |
| 368 | u32 ret_val = 0, pdf, pre_pdf, clk_sel; |
| 369 | u32 cscmr1 = __raw_readl(&mxc_ccm->cscmr1); |
| 370 | u32 cscdr2 = __raw_readl(&mxc_ccm->cscdr2); |
| 371 | |
| 372 | pre_pdf = (cscdr2 & MXC_CCM_CSCDR2_CSPI_CLK_PRED_MASK) \ |
| 373 | >> MXC_CCM_CSCDR2_CSPI_CLK_PRED_OFFSET; |
| 374 | pdf = (cscdr2 & MXC_CCM_CSCDR2_CSPI_CLK_PODF_MASK) \ |
| 375 | >> MXC_CCM_CSCDR2_CSPI_CLK_PODF_OFFSET; |
| 376 | clk_sel = (cscmr1 & MXC_CCM_CSCMR1_CSPI_CLK_SEL_MASK) \ |
| 377 | >> MXC_CCM_CSCMR1_CSPI_CLK_SEL_OFFSET; |
| 378 | |
| 379 | switch (clk_sel) { |
| 380 | case 0: |
| 381 | ret_val = decode_pll(mxc_plls[PLL1_CLOCK], |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 382 | CONFIG_SYS_MX5_HCLK) / |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 383 | ((pre_pdf + 1) * (pdf + 1)); |
| 384 | break; |
| 385 | case 1: |
| 386 | ret_val = decode_pll(mxc_plls[PLL2_CLOCK], |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 387 | CONFIG_SYS_MX5_HCLK) / |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 388 | ((pre_pdf + 1) * (pdf + 1)); |
| 389 | break; |
| 390 | case 2: |
| 391 | ret_val = decode_pll(mxc_plls[PLL3_CLOCK], |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 392 | CONFIG_SYS_MX5_HCLK) / |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 393 | ((pre_pdf + 1) * (pdf + 1)); |
| 394 | break; |
| 395 | default: |
| 396 | ret_val = get_lp_apm() / ((pre_pdf + 1) * (pdf + 1)); |
| 397 | break; |
| 398 | } |
| 399 | |
| 400 | return ret_val; |
| 401 | } |
| 402 | |
Fabio Estevam | b412101 | 2012-04-30 08:12:02 +0000 | [diff] [blame] | 403 | static u32 get_axi_a_clk(void) |
| 404 | { |
| 405 | u32 cbcdr = __raw_readl(&mxc_ccm->cbcdr); |
| 406 | u32 pdf = (cbcdr & MXC_CCM_CBCDR_AXI_A_PODF_MASK) \ |
| 407 | >> MXC_CCM_CBCDR_AXI_A_PODF_OFFSET; |
| 408 | |
| 409 | return get_periph_clk() / (pdf + 1); |
| 410 | } |
| 411 | |
| 412 | static u32 get_axi_b_clk(void) |
| 413 | { |
| 414 | u32 cbcdr = __raw_readl(&mxc_ccm->cbcdr); |
| 415 | u32 pdf = (cbcdr & MXC_CCM_CBCDR_AXI_B_PODF_MASK) \ |
| 416 | >> MXC_CCM_CBCDR_AXI_B_PODF_OFFSET; |
| 417 | |
| 418 | return get_periph_clk() / (pdf + 1); |
| 419 | } |
| 420 | |
| 421 | static u32 get_emi_slow_clk(void) |
| 422 | { |
| 423 | u32 cbcdr = __raw_readl(&mxc_ccm->cbcdr); |
| 424 | u32 emi_clk_sel = cbcdr & MXC_CCM_CBCDR_EMI_CLK_SEL; |
| 425 | u32 pdf = (cbcdr & MXC_CCM_CBCDR_EMI_PODF_MASK) \ |
| 426 | >> MXC_CCM_CBCDR_EMI_PODF_OFFSET; |
| 427 | |
| 428 | if (emi_clk_sel) |
| 429 | return get_ahb_clk() / (pdf + 1); |
| 430 | |
| 431 | return get_periph_clk() / (pdf + 1); |
| 432 | } |
| 433 | |
| 434 | static u32 get_ddr_clk(void) |
| 435 | { |
| 436 | u32 ret_val = 0; |
| 437 | u32 cbcmr = __raw_readl(&mxc_ccm->cbcmr); |
| 438 | u32 ddr_clk_sel = (cbcmr & MXC_CCM_CBCMR_DDR_CLK_SEL_MASK) \ |
| 439 | >> MXC_CCM_CBCMR_DDR_CLK_SEL_OFFSET; |
| 440 | #ifdef CONFIG_MX51 |
| 441 | u32 cbcdr = __raw_readl(&mxc_ccm->cbcdr); |
| 442 | if (cbcdr & MXC_CCM_CBCDR_DDR_HIFREQ_SEL) { |
| 443 | u32 ddr_clk_podf = (cbcdr & MXC_CCM_CBCDR_DDR_PODF_MASK) >> \ |
| 444 | MXC_CCM_CBCDR_DDR_PODF_OFFSET; |
| 445 | |
| 446 | ret_val = decode_pll(mxc_plls[PLL1_CLOCK], CONFIG_SYS_MX5_HCLK); |
| 447 | ret_val /= ddr_clk_podf + 1; |
| 448 | |
| 449 | return ret_val; |
| 450 | } |
| 451 | #endif |
| 452 | switch (ddr_clk_sel) { |
| 453 | case 0: |
| 454 | ret_val = get_axi_a_clk(); |
| 455 | break; |
| 456 | case 1: |
| 457 | ret_val = get_axi_b_clk(); |
| 458 | break; |
| 459 | case 2: |
| 460 | ret_val = get_emi_slow_clk(); |
| 461 | break; |
| 462 | case 3: |
| 463 | ret_val = get_ahb_clk(); |
| 464 | break; |
| 465 | default: |
| 466 | break; |
| 467 | } |
| 468 | |
| 469 | return ret_val; |
| 470 | } |
| 471 | |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 472 | /* |
Fabio Estevam | b412101 | 2012-04-30 08:12:02 +0000 | [diff] [blame] | 473 | * The API of get mxc clocks. |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 474 | */ |
| 475 | unsigned int mxc_get_clock(enum mxc_clock clk) |
| 476 | { |
| 477 | switch (clk) { |
| 478 | case MXC_ARM_CLK: |
| 479 | return get_mcu_main_clk(); |
| 480 | case MXC_AHB_CLK: |
Marek Vasut | 6674bf5 | 2011-09-22 09:20:37 +0000 | [diff] [blame] | 481 | return get_ahb_clk(); |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 482 | case MXC_IPG_CLK: |
| 483 | return get_ipg_clk(); |
| 484 | case MXC_IPG_PERCLK: |
| 485 | return get_ipg_per_clk(); |
| 486 | case MXC_UART_CLK: |
| 487 | return get_uart_clk(); |
| 488 | case MXC_CSPI_CLK: |
| 489 | return imx_get_cspiclk(); |
| 490 | case MXC_FEC_CLK: |
| 491 | return decode_pll(mxc_plls[PLL1_CLOCK], |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 492 | CONFIG_SYS_MX5_HCLK); |
Stefano Babic | d38db76 | 2012-02-22 00:24:36 +0000 | [diff] [blame] | 493 | case MXC_SATA_CLK: |
| 494 | return get_ahb_clk(); |
Fabio Estevam | b412101 | 2012-04-30 08:12:02 +0000 | [diff] [blame] | 495 | case MXC_DDR_CLK: |
| 496 | return get_ddr_clk(); |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 497 | default: |
| 498 | break; |
| 499 | } |
Fabio Estevam | b412101 | 2012-04-30 08:12:02 +0000 | [diff] [blame] | 500 | return -EINVAL; |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | u32 imx_get_uartclk(void) |
| 504 | { |
| 505 | return get_uart_clk(); |
| 506 | } |
| 507 | |
| 508 | |
| 509 | u32 imx_get_fecclk(void) |
| 510 | { |
| 511 | return mxc_get_clock(MXC_IPG_CLK); |
| 512 | } |
| 513 | |
Fabio Estevam | b412101 | 2012-04-30 08:12:02 +0000 | [diff] [blame] | 514 | static int gcd(int m, int n) |
| 515 | { |
| 516 | int t; |
| 517 | while (m > 0) { |
| 518 | if (n > m) { |
| 519 | t = m; |
| 520 | m = n; |
| 521 | n = t; |
| 522 | } /* swap */ |
| 523 | m -= n; |
| 524 | } |
| 525 | return n; |
| 526 | } |
| 527 | |
| 528 | /* |
| 529 | * This is to calculate various parameters based on reference clock and |
| 530 | * targeted clock based on the equation: |
| 531 | * t_clk = 2*ref_freq*(mfi + mfn/(mfd+1))/(pd+1) |
| 532 | * This calculation is based on a fixed MFD value for simplicity. |
| 533 | */ |
| 534 | static int calc_pll_params(u32 ref, u32 target, struct pll_param *pll) |
| 535 | { |
| 536 | u64 pd, mfi = 1, mfn, mfd, t1; |
| 537 | u32 n_target = target; |
| 538 | u32 n_ref = ref, i; |
| 539 | |
| 540 | /* |
| 541 | * Make sure targeted freq is in the valid range. |
| 542 | * Otherwise the following calculation might be wrong!!! |
| 543 | */ |
| 544 | if (n_target < PLL_FREQ_MIN(ref) || |
| 545 | n_target > PLL_FREQ_MAX(ref)) { |
| 546 | printf("Targeted peripheral clock should be" |
| 547 | "within [%d - %d]\n", |
| 548 | PLL_FREQ_MIN(ref) / SZ_DEC_1M, |
| 549 | PLL_FREQ_MAX(ref) / SZ_DEC_1M); |
| 550 | return -EINVAL; |
| 551 | } |
| 552 | |
| 553 | for (i = 0; i < ARRAY_SIZE(fixed_mfd); i++) { |
| 554 | if (fixed_mfd[i].ref_clk_hz == ref) { |
| 555 | mfd = fixed_mfd[i].mfd; |
| 556 | break; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | if (i == ARRAY_SIZE(fixed_mfd)) |
| 561 | return -EINVAL; |
| 562 | |
| 563 | /* Use n_target and n_ref to avoid overflow */ |
| 564 | for (pd = 1; pd <= PLL_PD_MAX; pd++) { |
| 565 | t1 = n_target * pd; |
| 566 | do_div(t1, (4 * n_ref)); |
| 567 | mfi = t1; |
| 568 | if (mfi > PLL_MFI_MAX) |
| 569 | return -EINVAL; |
| 570 | else if (mfi < 5) |
| 571 | continue; |
| 572 | break; |
| 573 | } |
| 574 | /* |
| 575 | * Now got pd and mfi already |
| 576 | * |
| 577 | * mfn = (((n_target * pd) / 4 - n_ref * mfi) * mfd) / n_ref; |
| 578 | */ |
| 579 | t1 = n_target * pd; |
| 580 | do_div(t1, 4); |
| 581 | t1 -= n_ref * mfi; |
| 582 | t1 *= mfd; |
| 583 | do_div(t1, n_ref); |
| 584 | mfn = t1; |
| 585 | debug("ref=%d, target=%d, pd=%d," "mfi=%d,mfn=%d, mfd=%d\n", |
| 586 | ref, n_target, (u32)pd, (u32)mfi, (u32)mfn, (u32)mfd); |
| 587 | i = 1; |
| 588 | if (mfn != 0) |
| 589 | i = gcd(mfd, mfn); |
| 590 | pll->pd = (u32)pd; |
| 591 | pll->mfi = (u32)mfi; |
| 592 | do_div(mfn, i); |
| 593 | pll->mfn = (u32)mfn; |
| 594 | do_div(mfd, i); |
| 595 | pll->mfd = (u32)mfd; |
| 596 | |
| 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | #define calc_div(tgt_clk, src_clk, limit) ({ \ |
| 601 | u32 v = 0; \ |
| 602 | if (((src_clk) % (tgt_clk)) <= 100) \ |
| 603 | v = (src_clk) / (tgt_clk); \ |
| 604 | else \ |
| 605 | v = ((src_clk) / (tgt_clk)) + 1;\ |
| 606 | if (v > limit) \ |
| 607 | v = limit; \ |
| 608 | (v - 1); \ |
| 609 | }) |
| 610 | |
| 611 | #define CHANGE_PLL_SETTINGS(pll, pd, fi, fn, fd) \ |
| 612 | { \ |
| 613 | __raw_writel(0x1232, &pll->ctrl); \ |
| 614 | __raw_writel(0x2, &pll->config); \ |
| 615 | __raw_writel((((pd) - 1) << 0) | ((fi) << 4), \ |
| 616 | &pll->op); \ |
| 617 | __raw_writel(fn, &(pll->mfn)); \ |
| 618 | __raw_writel((fd) - 1, &pll->mfd); \ |
| 619 | __raw_writel((((pd) - 1) << 0) | ((fi) << 4), \ |
| 620 | &pll->hfs_op); \ |
| 621 | __raw_writel(fn, &pll->hfs_mfn); \ |
| 622 | __raw_writel((fd) - 1, &pll->hfs_mfd); \ |
| 623 | __raw_writel(0x1232, &pll->ctrl); \ |
| 624 | while (!__raw_readl(&pll->ctrl) & 0x1) \ |
| 625 | ;\ |
| 626 | } |
| 627 | |
| 628 | static int config_pll_clk(enum pll_clocks index, struct pll_param *pll_param) |
| 629 | { |
| 630 | u32 ccsr = __raw_readl(&mxc_ccm->ccsr); |
| 631 | struct mxc_pll_reg *pll = mxc_plls[index]; |
| 632 | |
| 633 | switch (index) { |
| 634 | case PLL1_CLOCK: |
| 635 | /* Switch ARM to PLL2 clock */ |
| 636 | __raw_writel(ccsr | 0x4, &mxc_ccm->ccsr); |
| 637 | CHANGE_PLL_SETTINGS(pll, pll_param->pd, |
| 638 | pll_param->mfi, pll_param->mfn, |
| 639 | pll_param->mfd); |
| 640 | /* Switch back */ |
| 641 | __raw_writel(ccsr & ~0x4, &mxc_ccm->ccsr); |
| 642 | break; |
| 643 | case PLL2_CLOCK: |
| 644 | /* Switch to pll2 bypass clock */ |
| 645 | __raw_writel(ccsr | 0x2, &mxc_ccm->ccsr); |
| 646 | CHANGE_PLL_SETTINGS(pll, pll_param->pd, |
| 647 | pll_param->mfi, pll_param->mfn, |
| 648 | pll_param->mfd); |
| 649 | /* Switch back */ |
| 650 | __raw_writel(ccsr & ~0x2, &mxc_ccm->ccsr); |
| 651 | break; |
| 652 | case PLL3_CLOCK: |
| 653 | /* Switch to pll3 bypass clock */ |
| 654 | __raw_writel(ccsr | 0x1, &mxc_ccm->ccsr); |
| 655 | CHANGE_PLL_SETTINGS(pll, pll_param->pd, |
| 656 | pll_param->mfi, pll_param->mfn, |
| 657 | pll_param->mfd); |
| 658 | /* Switch back */ |
| 659 | __raw_writel(ccsr & ~0x1, &mxc_ccm->ccsr); |
| 660 | break; |
| 661 | case PLL4_CLOCK: |
| 662 | /* Switch to pll4 bypass clock */ |
| 663 | __raw_writel(ccsr | 0x20, &mxc_ccm->ccsr); |
| 664 | CHANGE_PLL_SETTINGS(pll, pll_param->pd, |
| 665 | pll_param->mfi, pll_param->mfn, |
| 666 | pll_param->mfd); |
| 667 | /* Switch back */ |
| 668 | __raw_writel(ccsr & ~0x20, &mxc_ccm->ccsr); |
| 669 | break; |
| 670 | default: |
| 671 | return -EINVAL; |
| 672 | } |
| 673 | |
| 674 | return 0; |
| 675 | } |
| 676 | |
| 677 | /* Config CPU clock */ |
| 678 | static int config_core_clk(u32 ref, u32 freq) |
| 679 | { |
| 680 | int ret = 0; |
| 681 | struct pll_param pll_param; |
| 682 | |
| 683 | memset(&pll_param, 0, sizeof(struct pll_param)); |
| 684 | |
| 685 | /* The case that periph uses PLL1 is not considered here */ |
| 686 | ret = calc_pll_params(ref, freq, &pll_param); |
| 687 | if (ret != 0) { |
| 688 | printf("Error:Can't find pll parameters: %d\n", ret); |
| 689 | return ret; |
| 690 | } |
| 691 | |
| 692 | return config_pll_clk(PLL1_CLOCK, &pll_param); |
| 693 | } |
| 694 | |
| 695 | static int config_nfc_clk(u32 nfc_clk) |
| 696 | { |
| 697 | u32 reg; |
| 698 | u32 parent_rate = get_emi_slow_clk(); |
| 699 | u32 div = parent_rate / nfc_clk; |
| 700 | |
| 701 | if (nfc_clk <= 0) |
| 702 | return -EINVAL; |
| 703 | if (div == 0) |
| 704 | div++; |
| 705 | if (parent_rate / div > NFC_CLK_MAX) |
| 706 | div++; |
| 707 | reg = __raw_readl(&mxc_ccm->cbcdr); |
| 708 | reg &= ~MXC_CCM_CBCDR_NFC_PODF_MASK; |
| 709 | reg |= (div - 1) << MXC_CCM_CBCDR_NFC_PODF_OFFSET; |
| 710 | __raw_writel(reg, &mxc_ccm->cbcdr); |
| 711 | while (__raw_readl(&mxc_ccm->cdhipr) != 0) |
| 712 | ; |
| 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | /* Config main_bus_clock for periphs */ |
| 717 | static int config_periph_clk(u32 ref, u32 freq) |
| 718 | { |
| 719 | int ret = 0; |
| 720 | struct pll_param pll_param; |
| 721 | |
| 722 | memset(&pll_param, 0, sizeof(struct pll_param)); |
| 723 | |
| 724 | if (__raw_readl(&mxc_ccm->cbcdr) & MXC_CCM_CBCDR_PERIPH_CLK_SEL) { |
| 725 | ret = calc_pll_params(ref, freq, &pll_param); |
| 726 | if (ret != 0) { |
| 727 | printf("Error:Can't find pll parameters: %d\n", |
| 728 | ret); |
| 729 | return ret; |
| 730 | } |
| 731 | switch ((__raw_readl(&mxc_ccm->cbcmr) & \ |
| 732 | MXC_CCM_CBCMR_PERIPH_CLK_SEL_MASK) >> \ |
| 733 | MXC_CCM_CBCMR_PERIPH_CLK_SEL_OFFSET) { |
| 734 | case 0: |
| 735 | return config_pll_clk(PLL1_CLOCK, &pll_param); |
| 736 | break; |
| 737 | case 1: |
| 738 | return config_pll_clk(PLL3_CLOCK, &pll_param); |
| 739 | break; |
| 740 | default: |
| 741 | return -EINVAL; |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | static int config_ddr_clk(u32 emi_clk) |
| 749 | { |
| 750 | u32 clk_src; |
| 751 | s32 shift = 0, clk_sel, div = 1; |
| 752 | u32 cbcmr = __raw_readl(&mxc_ccm->cbcmr); |
| 753 | u32 cbcdr = __raw_readl(&mxc_ccm->cbcdr); |
| 754 | |
| 755 | if (emi_clk > MAX_DDR_CLK) { |
| 756 | printf("Warning:DDR clock should not exceed %d MHz\n", |
| 757 | MAX_DDR_CLK / SZ_DEC_1M); |
| 758 | emi_clk = MAX_DDR_CLK; |
| 759 | } |
| 760 | |
| 761 | clk_src = get_periph_clk(); |
| 762 | /* Find DDR clock input */ |
| 763 | clk_sel = (cbcmr >> 10) & 0x3; |
| 764 | switch (clk_sel) { |
| 765 | case 0: |
| 766 | shift = 16; |
| 767 | break; |
| 768 | case 1: |
| 769 | shift = 19; |
| 770 | break; |
| 771 | case 2: |
| 772 | shift = 22; |
| 773 | break; |
| 774 | case 3: |
| 775 | shift = 10; |
| 776 | break; |
| 777 | default: |
| 778 | return -EINVAL; |
| 779 | } |
| 780 | |
| 781 | if ((clk_src % emi_clk) < 10000000) |
| 782 | div = clk_src / emi_clk; |
| 783 | else |
| 784 | div = (clk_src / emi_clk) + 1; |
| 785 | if (div > 8) |
| 786 | div = 8; |
| 787 | |
| 788 | cbcdr = cbcdr & ~(0x7 << shift); |
| 789 | cbcdr |= ((div - 1) << shift); |
| 790 | __raw_writel(cbcdr, &mxc_ccm->cbcdr); |
| 791 | while (__raw_readl(&mxc_ccm->cdhipr) != 0) |
| 792 | ; |
| 793 | __raw_writel(0x0, &mxc_ccm->ccdr); |
| 794 | |
| 795 | return 0; |
| 796 | } |
| 797 | |
| 798 | /* |
| 799 | * This function assumes the expected core clock has to be changed by |
| 800 | * modifying the PLL. This is NOT true always but for most of the times, |
| 801 | * it is. So it assumes the PLL output freq is the same as the expected |
| 802 | * core clock (presc=1) unless the core clock is less than PLL_FREQ_MIN. |
| 803 | * In the latter case, it will try to increase the presc value until |
| 804 | * (presc*core_clk) is greater than PLL_FREQ_MIN. It then makes call to |
| 805 | * calc_pll_params() and obtains the values of PD, MFI,MFN, MFD based |
| 806 | * on the targeted PLL and reference input clock to the PLL. Lastly, |
| 807 | * it sets the register based on these values along with the dividers. |
| 808 | * Note 1) There is no value checking for the passed-in divider values |
| 809 | * so the caller has to make sure those values are sensible. |
| 810 | * 2) Also adjust the NFC divider such that the NFC clock doesn't |
| 811 | * exceed NFC_CLK_MAX. |
| 812 | * 3) IPU HSP clock is independent of AHB clock. Even it can go up to |
| 813 | * 177MHz for higher voltage, this function fixes the max to 133MHz. |
| 814 | * 4) This function should not have allowed diag_printf() calls since |
| 815 | * the serial driver has been stoped. But leave then here to allow |
| 816 | * easy debugging by NOT calling the cyg_hal_plf_serial_stop(). |
| 817 | */ |
| 818 | int mxc_set_clock(u32 ref, u32 freq, enum mxc_clock clk) |
| 819 | { |
| 820 | freq *= SZ_DEC_1M; |
| 821 | |
| 822 | switch (clk) { |
| 823 | case MXC_ARM_CLK: |
| 824 | if (config_core_clk(ref, freq)) |
| 825 | return -EINVAL; |
| 826 | break; |
| 827 | case MXC_PERIPH_CLK: |
| 828 | if (config_periph_clk(ref, freq)) |
| 829 | return -EINVAL; |
| 830 | break; |
| 831 | case MXC_DDR_CLK: |
| 832 | if (config_ddr_clk(freq)) |
| 833 | return -EINVAL; |
| 834 | break; |
| 835 | case MXC_NFC_CLK: |
| 836 | if (config_nfc_clk(freq)) |
| 837 | return -EINVAL; |
| 838 | break; |
| 839 | default: |
| 840 | printf("Warning:Unsupported or invalid clock type\n"); |
| 841 | } |
| 842 | |
| 843 | return 0; |
| 844 | } |
| 845 | |
Stefano Babic | c378abf | 2012-02-22 00:24:38 +0000 | [diff] [blame] | 846 | #ifdef CONFIG_MX53 |
| 847 | /* |
| 848 | * The clock for the external interface can be set to use internal clock |
| 849 | * if fuse bank 4, row 3, bit 2 is set. |
| 850 | * This is an undocumented feature and it was confirmed by Freescale's support: |
| 851 | * Fuses (but not pins) may be used to configure SATA clocks. |
| 852 | * Particularly the i.MX53 Fuse_Map contains the next information |
| 853 | * about configuring SATA clocks : SATA_ALT_REF_CLK[1:0] (offset 0x180C) |
| 854 | * '00' - 100MHz (External) |
| 855 | * '01' - 50MHz (External) |
| 856 | * '10' - 120MHz, internal (USB PHY) |
| 857 | * '11' - Reserved |
| 858 | */ |
| 859 | void mxc_set_sata_internal_clock(void) |
| 860 | { |
| 861 | u32 *tmp_base = |
| 862 | (u32 *)(IIM_BASE_ADDR + 0x180c); |
| 863 | |
| 864 | set_usb_phy1_clk(); |
| 865 | |
Fabio Estevam | cd7ec87 | 2012-05-11 14:39:11 +0000 | [diff] [blame] | 866 | writel((readl(tmp_base) & (~0x6)) | 0x4, tmp_base); |
Stefano Babic | c378abf | 2012-02-22 00:24:38 +0000 | [diff] [blame] | 867 | } |
| 868 | #endif |
| 869 | |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 870 | /* |
| 871 | * Dump some core clockes. |
| 872 | */ |
Stefano Babic | 6eb9010 | 2010-10-28 11:08:52 +0200 | [diff] [blame] | 873 | int do_mx5_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 874 | { |
| 875 | u32 freq; |
| 876 | |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 877 | freq = decode_pll(mxc_plls[PLL1_CLOCK], CONFIG_SYS_MX5_HCLK); |
Marek Vasut | 421bf45 | 2011-09-14 14:09:04 +0000 | [diff] [blame] | 878 | printf("PLL1 %8d MHz\n", freq / 1000000); |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 879 | freq = decode_pll(mxc_plls[PLL2_CLOCK], CONFIG_SYS_MX5_HCLK); |
Marek Vasut | 421bf45 | 2011-09-14 14:09:04 +0000 | [diff] [blame] | 880 | printf("PLL2 %8d MHz\n", freq / 1000000); |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 881 | freq = decode_pll(mxc_plls[PLL3_CLOCK], CONFIG_SYS_MX5_HCLK); |
Marek Vasut | 421bf45 | 2011-09-14 14:09:04 +0000 | [diff] [blame] | 882 | printf("PLL3 %8d MHz\n", freq / 1000000); |
Marek Vasut | 3c844f3 | 2011-09-23 11:43:47 +0200 | [diff] [blame] | 883 | #ifdef CONFIG_MX53 |
| 884 | freq = decode_pll(mxc_plls[PLL4_CLOCK], CONFIG_SYS_MX5_HCLK); |
Marek Vasut | 421bf45 | 2011-09-14 14:09:04 +0000 | [diff] [blame] | 885 | printf("PLL4 %8d MHz\n", freq / 1000000); |
Marek Vasut | 3c844f3 | 2011-09-23 11:43:47 +0200 | [diff] [blame] | 886 | #endif |
Marek Vasut | 421bf45 | 2011-09-14 14:09:04 +0000 | [diff] [blame] | 887 | |
| 888 | printf("\n"); |
| 889 | printf("AHB %8d kHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000); |
| 890 | printf("IPG %8d kHz\n", mxc_get_clock(MXC_IPG_CLK) / 1000); |
| 891 | printf("IPG PERCLK %8d kHz\n", mxc_get_clock(MXC_IPG_PERCLK) / 1000); |
Fabio Estevam | b412101 | 2012-04-30 08:12:02 +0000 | [diff] [blame] | 892 | printf("DDR %8d kHz\n", mxc_get_clock(MXC_DDR_CLK) / 1000); |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
| 897 | /***************************************************/ |
| 898 | |
| 899 | U_BOOT_CMD( |
Stefano Babic | c8a02c3 | 2011-08-17 17:52:40 +0200 | [diff] [blame] | 900 | clocks, CONFIG_SYS_MAXARGS, 1, do_mx5_showclocks, |
| 901 | "display clocks", |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 902 | "" |
| 903 | ); |