blob: 610098c175e9f8891db0a6a1805b604d62d91528 [file] [log] [blame]
Stefano Babica521a772010-01-20 18:19:32 +01001/*
2 * (C) Copyright 2007
3 * Sascha Hauer, Pengutronix
4 *
5 * (C) Copyright 2009 Freescale Semiconductor, Inc.
6 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Stefano Babica521a772010-01-20 18:19:32 +01008 */
9
10#include <common.h>
11#include <asm/io.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090012#include <linux/errno.h>
Stefano Babica521a772010-01-20 18:19:32 +010013#include <asm/arch/imx-regs.h>
14#include <asm/arch/crm_regs.h>
Stefano Babicac41d4d2010-03-05 17:54:37 +010015#include <asm/arch/clock.h>
Marek Vasut3c844f32011-09-23 11:43:47 +020016#include <div64.h>
Fabio Estevam6479f512012-04-29 08:11:13 +000017#include <asm/arch/sys_proto.h>
Stefano Babica521a772010-01-20 18:19:32 +010018
19enum pll_clocks {
20 PLL1_CLOCK = 0,
21 PLL2_CLOCK,
22 PLL3_CLOCK,
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +000023#ifdef CONFIG_MX53
Marek Vasut3c844f32011-09-23 11:43:47 +020024 PLL4_CLOCK,
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +000025#endif
Stefano Babica521a772010-01-20 18:19:32 +010026 PLL_CLOCKS,
27};
28
29struct mxc_pll_reg *mxc_plls[PLL_CLOCKS] = {
30 [PLL1_CLOCK] = (struct mxc_pll_reg *)PLL1_BASE_ADDR,
31 [PLL2_CLOCK] = (struct mxc_pll_reg *)PLL2_BASE_ADDR,
32 [PLL3_CLOCK] = (struct mxc_pll_reg *)PLL3_BASE_ADDR,
Marek Vasut3c844f32011-09-23 11:43:47 +020033#ifdef CONFIG_MX53
34 [PLL4_CLOCK] = (struct mxc_pll_reg *)PLL4_BASE_ADDR,
35#endif
Stefano Babica521a772010-01-20 18:19:32 +010036};
37
Fabio Estevamb4121012012-04-30 08:12:02 +000038#define AHB_CLK_ROOT 133333333
39#define SZ_DEC_1M 1000000
40#define PLL_PD_MAX 16 /* Actual pd+1 */
41#define PLL_MFI_MAX 15
42#define PLL_MFI_MIN 5
43#define ARM_DIV_MAX 8
44#define IPG_DIV_MAX 4
45#define AHB_DIV_MAX 8
46#define EMI_DIV_MAX 8
47#define NFC_DIV_MAX 8
48
49#define MX5_CBCMR 0x00015154
50#define MX5_CBCDR 0x02888945
51
52struct fixed_pll_mfd {
53 u32 ref_clk_hz;
54 u32 mfd;
55};
56
57const struct fixed_pll_mfd fixed_mfd[] = {
Benoît Thébaudeauafac1652012-09-27 10:19:58 +000058 {MXC_HCLK, 24 * 16},
Fabio Estevamb4121012012-04-30 08:12:02 +000059};
60
61struct pll_param {
62 u32 pd;
63 u32 mfi;
64 u32 mfn;
65 u32 mfd;
66};
67
68#define PLL_FREQ_MAX(ref_clk) (4 * (ref_clk) * PLL_MFI_MAX)
69#define PLL_FREQ_MIN(ref_clk) \
70 ((2 * (ref_clk) * (PLL_MFI_MIN - 1)) / PLL_PD_MAX)
71#define MAX_DDR_CLK 420000000
72#define NFC_CLK_MAX 34000000
73
Stefano Babicac41d4d2010-03-05 17:54:37 +010074struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
Stefano Babica521a772010-01-20 18:19:32 +010075
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +010076void set_usboh3_clk(void)
77{
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +000078 clrsetbits_le32(&mxc_ccm->cscmr1,
79 MXC_CCM_CSCMR1_USBOH3_CLK_SEL_MASK,
80 MXC_CCM_CSCMR1_USBOH3_CLK_SEL(1));
81 clrsetbits_le32(&mxc_ccm->cscdr1,
82 MXC_CCM_CSCDR1_USBOH3_CLK_PODF_MASK |
83 MXC_CCM_CSCDR1_USBOH3_CLK_PRED_MASK,
84 MXC_CCM_CSCDR1_USBOH3_CLK_PRED(4) |
85 MXC_CCM_CSCDR1_USBOH3_CLK_PODF(1));
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +010086}
87
Fabio Estevam800cb812013-07-26 13:54:28 -030088void enable_usboh3_clk(bool enable)
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +010089{
Benoît Thébaudeau6dfc6302012-09-27 10:21:22 +000090 unsigned int cg = enable ? MXC_CCM_CCGR_CG_ON : MXC_CCM_CCGR_CG_OFF;
91
92 clrsetbits_le32(&mxc_ccm->CCGR2,
93 MXC_CCM_CCGR2_USBOH3_60M(MXC_CCM_CCGR_CG_MASK),
94 MXC_CCM_CCGR2_USBOH3_60M(cg));
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +010095}
96
trema49f40a2013-09-21 18:13:35 +020097#ifdef CONFIG_SYS_I2C_MXC
Benoît Thébaudeaua23408c2012-09-27 10:24:13 +000098/* i2c_num can be from 0, to 1 for i.MX51 and 2 for i.MX53 */
Troy Kiskyd4fdc992012-07-19 08:18:25 +000099int enable_i2c_clk(unsigned char enable, unsigned i2c_num)
100{
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000101 u32 mask;
102
Benoît Thébaudeaua23408c2012-09-27 10:24:13 +0000103#if defined(CONFIG_MX51)
104 if (i2c_num > 1)
105#elif defined(CONFIG_MX53)
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000106 if (i2c_num > 2)
Benoît Thébaudeaua23408c2012-09-27 10:24:13 +0000107#endif
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000108 return -EINVAL;
Benoît Thébaudeau461a00a2012-09-27 10:21:00 +0000109 mask = MXC_CCM_CCGR_CG_MASK <<
110 (MXC_CCM_CCGR1_I2C1_OFFSET + (i2c_num << 1));
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000111 if (enable)
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000112 setbits_le32(&mxc_ccm->CCGR1, mask);
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000113 else
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000114 clrbits_le32(&mxc_ccm->CCGR1, mask);
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000115 return 0;
116}
117#endif
118
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000119void set_usb_phy_clk(void)
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100120{
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000121 clrbits_le32(&mxc_ccm->cscmr1, MXC_CCM_CSCMR1_USB_PHY_CLK_SEL);
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100122}
123
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000124#if defined(CONFIG_MX51)
Fabio Estevam800cb812013-07-26 13:54:28 -0300125void enable_usb_phy1_clk(bool enable)
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100126{
Benoît Thébaudeau6dfc6302012-09-27 10:21:22 +0000127 unsigned int cg = enable ? MXC_CCM_CCGR_CG_ON : MXC_CCM_CCGR_CG_OFF;
128
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000129 clrsetbits_le32(&mxc_ccm->CCGR2,
130 MXC_CCM_CCGR2_USB_PHY(MXC_CCM_CCGR_CG_MASK),
131 MXC_CCM_CCGR2_USB_PHY(cg));
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100132}
133
Fabio Estevam800cb812013-07-26 13:54:28 -0300134void enable_usb_phy2_clk(bool enable)
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100135{
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000136 /* i.MX51 has a single USB PHY clock, so do nothing here. */
137}
138#elif defined(CONFIG_MX53)
Fabio Estevam800cb812013-07-26 13:54:28 -0300139void enable_usb_phy1_clk(bool enable)
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000140{
141 unsigned int cg = enable ? MXC_CCM_CCGR_CG_ON : MXC_CCM_CCGR_CG_OFF;
142
143 clrsetbits_le32(&mxc_ccm->CCGR4,
144 MXC_CCM_CCGR4_USB_PHY1(MXC_CCM_CCGR_CG_MASK),
145 MXC_CCM_CCGR4_USB_PHY1(cg));
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100146}
147
Fabio Estevam800cb812013-07-26 13:54:28 -0300148void enable_usb_phy2_clk(bool enable)
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100149{
Benoît Thébaudeau6dfc6302012-09-27 10:21:22 +0000150 unsigned int cg = enable ? MXC_CCM_CCGR_CG_ON : MXC_CCM_CCGR_CG_OFF;
151
152 clrsetbits_le32(&mxc_ccm->CCGR4,
153 MXC_CCM_CCGR4_USB_PHY2(MXC_CCM_CCGR_CG_MASK),
154 MXC_CCM_CCGR4_USB_PHY2(cg));
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100155}
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000156#endif
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100157
Stefano Babica521a772010-01-20 18:19:32 +0100158/*
Marek Vasut3c844f32011-09-23 11:43:47 +0200159 * Calculate the frequency of PLLn.
Stefano Babica521a772010-01-20 18:19:32 +0100160 */
Marek Vasut3c844f32011-09-23 11:43:47 +0200161static uint32_t decode_pll(struct mxc_pll_reg *pll, uint32_t infreq)
Stefano Babica521a772010-01-20 18:19:32 +0100162{
Marek Vasut3c844f32011-09-23 11:43:47 +0200163 uint32_t ctrl, op, mfd, mfn, mfi, pdf, ret;
164 uint64_t refclk, temp;
165 int32_t mfn_abs;
Stefano Babica521a772010-01-20 18:19:32 +0100166
Marek Vasut3c844f32011-09-23 11:43:47 +0200167 ctrl = readl(&pll->ctrl);
Stefano Babica521a772010-01-20 18:19:32 +0100168
Marek Vasut3c844f32011-09-23 11:43:47 +0200169 if (ctrl & MXC_DPLLC_CTL_HFSM) {
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000170 mfn = readl(&pll->hfs_mfn);
171 mfd = readl(&pll->hfs_mfd);
172 op = readl(&pll->hfs_op);
Marek Vasut3c844f32011-09-23 11:43:47 +0200173 } else {
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000174 mfn = readl(&pll->mfn);
175 mfd = readl(&pll->mfd);
176 op = readl(&pll->op);
Marek Vasut3c844f32011-09-23 11:43:47 +0200177 }
178
179 mfd &= MXC_DPLLC_MFD_MFD_MASK;
180 mfn &= MXC_DPLLC_MFN_MFN_MASK;
181 pdf = op & MXC_DPLLC_OP_PDF_MASK;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000182 mfi = MXC_DPLLC_OP_MFI_RD(op);
Marek Vasut3c844f32011-09-23 11:43:47 +0200183
184 /* 21.2.3 */
185 if (mfi < 5)
186 mfi = 5;
187
188 /* Sign extend */
189 if (mfn >= 0x04000000) {
190 mfn |= 0xfc000000;
191 mfn_abs = -mfn;
192 } else
193 mfn_abs = mfn;
194
195 refclk = infreq * 2;
196 if (ctrl & MXC_DPLLC_CTL_DPDCK0_2_EN)
197 refclk *= 2;
198
Simon Glass3d557882011-11-05 04:25:22 +0000199 do_div(refclk, pdf + 1);
Marek Vasut3c844f32011-09-23 11:43:47 +0200200 temp = refclk * mfn_abs;
201 do_div(temp, mfd + 1);
202 ret = refclk * mfi;
203
204 if ((int)mfn < 0)
205 ret -= temp;
206 else
207 ret += temp;
208
209 return ret;
Stefano Babica521a772010-01-20 18:19:32 +0100210}
211
Benoît Thébaudeau9c05cc72012-09-27 10:22:37 +0000212#ifdef CONFIG_MX51
213/*
214 * This function returns the Frequency Pre-Multiplier clock.
215 */
216static u32 get_fpm(void)
217{
218 u32 mult;
219 u32 ccr = readl(&mxc_ccm->ccr);
220
221 if (ccr & MXC_CCM_CCR_FPM_MULT)
222 mult = 1024;
223 else
224 mult = 512;
225
226 return MXC_CLK32 * mult;
227}
228#endif
229
Stefano Babica521a772010-01-20 18:19:32 +0100230/*
Benoît Thébaudeau96d9df32012-09-27 10:22:51 +0000231 * This function returns the low power audio clock.
232 */
233static u32 get_lp_apm(void)
234{
235 u32 ret_val = 0;
236 u32 ccsr = readl(&mxc_ccm->ccsr);
237
238 if (ccsr & MXC_CCM_CCSR_LP_APM)
239#if defined(CONFIG_MX51)
240 ret_val = get_fpm();
241#elif defined(CONFIG_MX53)
242 ret_val = decode_pll(mxc_plls[PLL4_CLOCK], MXC_HCLK);
243#endif
244 else
245 ret_val = MXC_HCLK;
246
247 return ret_val;
248}
249
250/*
Stefano Babica521a772010-01-20 18:19:32 +0100251 * Get mcu main rate
252 */
253u32 get_mcu_main_clk(void)
254{
255 u32 reg, freq;
256
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000257 reg = MXC_CCM_CACRR_ARM_PODF_RD(readl(&mxc_ccm->cacrr));
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000258 freq = decode_pll(mxc_plls[PLL1_CLOCK], MXC_HCLK);
Stefano Babica521a772010-01-20 18:19:32 +0100259 return freq / (reg + 1);
260}
261
262/*
263 * Get the rate of peripheral's root clock.
264 */
Fabio Estevam6479f512012-04-29 08:11:13 +0000265u32 get_periph_clk(void)
Stefano Babica521a772010-01-20 18:19:32 +0100266{
267 u32 reg;
268
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000269 reg = readl(&mxc_ccm->cbcdr);
Stefano Babica521a772010-01-20 18:19:32 +0100270 if (!(reg & MXC_CCM_CBCDR_PERIPH_CLK_SEL))
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000271 return decode_pll(mxc_plls[PLL2_CLOCK], MXC_HCLK);
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000272 reg = readl(&mxc_ccm->cbcmr);
273 switch (MXC_CCM_CBCMR_PERIPH_CLK_SEL_RD(reg)) {
Stefano Babica521a772010-01-20 18:19:32 +0100274 case 0:
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000275 return decode_pll(mxc_plls[PLL1_CLOCK], MXC_HCLK);
Stefano Babica521a772010-01-20 18:19:32 +0100276 case 1:
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000277 return decode_pll(mxc_plls[PLL3_CLOCK], MXC_HCLK);
Benoît Thébaudeau96d9df32012-09-27 10:22:51 +0000278 case 2:
279 return get_lp_apm();
Stefano Babica521a772010-01-20 18:19:32 +0100280 default:
281 return 0;
282 }
283 /* NOTREACHED */
284}
285
286/*
287 * Get the rate of ipg clock.
288 */
289static u32 get_ipg_clk(void)
290{
Marek Vasut6674bf52011-09-22 09:20:37 +0000291 uint32_t freq, reg, div;
Stefano Babica521a772010-01-20 18:19:32 +0100292
Marek Vasut6674bf52011-09-22 09:20:37 +0000293 freq = get_ahb_clk();
294
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000295 reg = readl(&mxc_ccm->cbcdr);
296 div = MXC_CCM_CBCDR_IPG_PODF_RD(reg) + 1;
Marek Vasut6674bf52011-09-22 09:20:37 +0000297
298 return freq / div;
Stefano Babica521a772010-01-20 18:19:32 +0100299}
300
301/*
302 * Get the rate of ipg_per clock.
303 */
304static u32 get_ipg_per_clk(void)
305{
Benoît Thébaudeau0cef3ae2012-09-27 10:23:08 +0000306 u32 freq, pred1, pred2, podf;
Stefano Babica521a772010-01-20 18:19:32 +0100307
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000308 if (readl(&mxc_ccm->cbcmr) & MXC_CCM_CBCMR_PERCLK_IPG_CLK_SEL)
Stefano Babica521a772010-01-20 18:19:32 +0100309 return get_ipg_clk();
Benoît Thébaudeau0cef3ae2012-09-27 10:23:08 +0000310
311 if (readl(&mxc_ccm->cbcmr) & MXC_CCM_CBCMR_PERCLK_LP_APM_CLK_SEL)
312 freq = get_lp_apm();
313 else
314 freq = get_periph_clk();
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000315 podf = readl(&mxc_ccm->cbcdr);
316 pred1 = MXC_CCM_CBCDR_PERCLK_PRED1_RD(podf);
317 pred2 = MXC_CCM_CBCDR_PERCLK_PRED2_RD(podf);
318 podf = MXC_CCM_CBCDR_PERCLK_PODF_RD(podf);
Benoît Thébaudeau0cef3ae2012-09-27 10:23:08 +0000319 return freq / ((pred1 + 1) * (pred2 + 1) * (podf + 1));
Stefano Babica521a772010-01-20 18:19:32 +0100320}
321
Benoît Thébaudeau9aa99c42012-09-27 10:23:23 +0000322/* Get the output clock rate of a standard PLL MUX for peripherals. */
323static u32 get_standard_pll_sel_clk(u32 clk_sel)
Stefano Babica521a772010-01-20 18:19:32 +0100324{
Stefano Babicfd375f32012-10-24 10:06:28 +0200325 u32 freq = 0;
Stefano Babica521a772010-01-20 18:19:32 +0100326
Benoît Thébaudeau9aa99c42012-09-27 10:23:23 +0000327 switch (clk_sel & 0x3) {
328 case 0:
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000329 freq = decode_pll(mxc_plls[PLL1_CLOCK], MXC_HCLK);
Stefano Babica521a772010-01-20 18:19:32 +0100330 break;
Benoît Thébaudeau9aa99c42012-09-27 10:23:23 +0000331 case 1:
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000332 freq = decode_pll(mxc_plls[PLL2_CLOCK], MXC_HCLK);
Stefano Babica521a772010-01-20 18:19:32 +0100333 break;
Benoît Thébaudeau9aa99c42012-09-27 10:23:23 +0000334 case 2:
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000335 freq = decode_pll(mxc_plls[PLL3_CLOCK], MXC_HCLK);
Stefano Babica521a772010-01-20 18:19:32 +0100336 break;
Benoît Thébaudeau9aa99c42012-09-27 10:23:23 +0000337 case 3:
338 freq = get_lp_apm();
339 break;
Stefano Babica521a772010-01-20 18:19:32 +0100340 }
341
Benoît Thébaudeau9aa99c42012-09-27 10:23:23 +0000342 return freq;
343}
344
345/*
346 * Get the rate of uart clk.
347 */
348static u32 get_uart_clk(void)
349{
350 unsigned int clk_sel, freq, reg, pred, podf;
351
352 reg = readl(&mxc_ccm->cscmr1);
353 clk_sel = MXC_CCM_CSCMR1_UART_CLK_SEL_RD(reg);
354 freq = get_standard_pll_sel_clk(clk_sel);
355
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000356 reg = readl(&mxc_ccm->cscdr1);
357 pred = MXC_CCM_CSCDR1_UART_CLK_PRED_RD(reg);
358 podf = MXC_CCM_CSCDR1_UART_CLK_PODF_RD(reg);
Stefano Babica521a772010-01-20 18:19:32 +0100359 freq /= (pred + 1) * (podf + 1);
360
361 return freq;
362}
363
364/*
Stefano Babica521a772010-01-20 18:19:32 +0100365 * get cspi clock rate.
366 */
Fabio Estevamb4121012012-04-30 08:12:02 +0000367static u32 imx_get_cspiclk(void)
Stefano Babica521a772010-01-20 18:19:32 +0100368{
Benoît Thébaudeau81fb2742012-09-27 10:23:42 +0000369 u32 ret_val = 0, pdf, pre_pdf, clk_sel, freq;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000370 u32 cscmr1 = readl(&mxc_ccm->cscmr1);
371 u32 cscdr2 = readl(&mxc_ccm->cscdr2);
Stefano Babica521a772010-01-20 18:19:32 +0100372
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000373 pre_pdf = MXC_CCM_CSCDR2_CSPI_CLK_PRED_RD(cscdr2);
374 pdf = MXC_CCM_CSCDR2_CSPI_CLK_PODF_RD(cscdr2);
375 clk_sel = MXC_CCM_CSCMR1_CSPI_CLK_SEL_RD(cscmr1);
Benoît Thébaudeau81fb2742012-09-27 10:23:42 +0000376 freq = get_standard_pll_sel_clk(clk_sel);
377 ret_val = freq / ((pre_pdf + 1) * (pdf + 1));
Stefano Babica521a772010-01-20 18:19:32 +0100378 return ret_val;
379}
380
Benoît Thébaudeaueb9c2552012-09-27 10:24:37 +0000381/*
382 * get esdhc clock rate.
383 */
384static u32 get_esdhc_clk(u32 port)
385{
386 u32 clk_sel = 0, pred = 0, podf = 0, freq = 0;
387 u32 cscmr1 = readl(&mxc_ccm->cscmr1);
388 u32 cscdr1 = readl(&mxc_ccm->cscdr1);
389
390 switch (port) {
391 case 0:
392 clk_sel = MXC_CCM_CSCMR1_ESDHC1_MSHC1_CLK_SEL_RD(cscmr1);
393 pred = MXC_CCM_CSCDR1_ESDHC1_MSHC1_CLK_PRED_RD(cscdr1);
394 podf = MXC_CCM_CSCDR1_ESDHC1_MSHC1_CLK_PODF_RD(cscdr1);
395 break;
396 case 1:
397 clk_sel = MXC_CCM_CSCMR1_ESDHC2_MSHC2_CLK_SEL_RD(cscmr1);
398 pred = MXC_CCM_CSCDR1_ESDHC2_MSHC2_CLK_PRED_RD(cscdr1);
399 podf = MXC_CCM_CSCDR1_ESDHC2_MSHC2_CLK_PODF_RD(cscdr1);
400 break;
401 case 2:
402 if (cscmr1 & MXC_CCM_CSCMR1_ESDHC3_CLK_SEL)
403 return get_esdhc_clk(1);
404 else
405 return get_esdhc_clk(0);
406 case 3:
407 if (cscmr1 & MXC_CCM_CSCMR1_ESDHC4_CLK_SEL)
408 return get_esdhc_clk(1);
409 else
410 return get_esdhc_clk(0);
411 default:
412 break;
413 }
414
415 freq = get_standard_pll_sel_clk(clk_sel) / ((pred + 1) * (podf + 1));
416 return freq;
417}
418
Fabio Estevamb4121012012-04-30 08:12:02 +0000419static u32 get_axi_a_clk(void)
420{
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000421 u32 cbcdr = readl(&mxc_ccm->cbcdr);
422 u32 pdf = MXC_CCM_CBCDR_AXI_A_PODF_RD(cbcdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000423
424 return get_periph_clk() / (pdf + 1);
425}
426
427static u32 get_axi_b_clk(void)
428{
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000429 u32 cbcdr = readl(&mxc_ccm->cbcdr);
430 u32 pdf = MXC_CCM_CBCDR_AXI_B_PODF_RD(cbcdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000431
432 return get_periph_clk() / (pdf + 1);
433}
434
435static u32 get_emi_slow_clk(void)
436{
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000437 u32 cbcdr = readl(&mxc_ccm->cbcdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000438 u32 emi_clk_sel = cbcdr & MXC_CCM_CBCDR_EMI_CLK_SEL;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000439 u32 pdf = MXC_CCM_CBCDR_EMI_PODF_RD(cbcdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000440
441 if (emi_clk_sel)
442 return get_ahb_clk() / (pdf + 1);
443
444 return get_periph_clk() / (pdf + 1);
445}
446
447static u32 get_ddr_clk(void)
448{
449 u32 ret_val = 0;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000450 u32 cbcmr = readl(&mxc_ccm->cbcmr);
451 u32 ddr_clk_sel = MXC_CCM_CBCMR_DDR_CLK_SEL_RD(cbcmr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000452#ifdef CONFIG_MX51
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000453 u32 cbcdr = readl(&mxc_ccm->cbcdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000454 if (cbcdr & MXC_CCM_CBCDR_DDR_HIFREQ_SEL) {
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000455 u32 ddr_clk_podf = MXC_CCM_CBCDR_DDR_PODF_RD(cbcdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000456
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000457 ret_val = decode_pll(mxc_plls[PLL1_CLOCK], MXC_HCLK);
Fabio Estevamb4121012012-04-30 08:12:02 +0000458 ret_val /= ddr_clk_podf + 1;
459
460 return ret_val;
461 }
462#endif
463 switch (ddr_clk_sel) {
464 case 0:
465 ret_val = get_axi_a_clk();
466 break;
467 case 1:
468 ret_val = get_axi_b_clk();
469 break;
470 case 2:
471 ret_val = get_emi_slow_clk();
472 break;
473 case 3:
474 ret_val = get_ahb_clk();
475 break;
476 default:
477 break;
478 }
479
480 return ret_val;
481}
482
Stefano Babica521a772010-01-20 18:19:32 +0100483/*
Fabio Estevamb4121012012-04-30 08:12:02 +0000484 * The API of get mxc clocks.
Stefano Babica521a772010-01-20 18:19:32 +0100485 */
486unsigned int mxc_get_clock(enum mxc_clock clk)
487{
488 switch (clk) {
489 case MXC_ARM_CLK:
490 return get_mcu_main_clk();
491 case MXC_AHB_CLK:
Marek Vasut6674bf52011-09-22 09:20:37 +0000492 return get_ahb_clk();
Stefano Babica521a772010-01-20 18:19:32 +0100493 case MXC_IPG_CLK:
494 return get_ipg_clk();
495 case MXC_IPG_PERCLK:
Matthias Weisser99ba3422012-09-24 02:46:53 +0000496 case MXC_I2C_CLK:
Stefano Babica521a772010-01-20 18:19:32 +0100497 return get_ipg_per_clk();
498 case MXC_UART_CLK:
499 return get_uart_clk();
500 case MXC_CSPI_CLK:
501 return imx_get_cspiclk();
Benoît Thébaudeaueb9c2552012-09-27 10:24:37 +0000502 case MXC_ESDHC_CLK:
503 return get_esdhc_clk(0);
504 case MXC_ESDHC2_CLK:
505 return get_esdhc_clk(1);
506 case MXC_ESDHC3_CLK:
507 return get_esdhc_clk(2);
508 case MXC_ESDHC4_CLK:
509 return get_esdhc_clk(3);
Stefano Babica521a772010-01-20 18:19:32 +0100510 case MXC_FEC_CLK:
Benoît Thébaudeau743656e2012-09-27 10:23:58 +0000511 return get_ipg_clk();
Stefano Babicd38db762012-02-22 00:24:36 +0000512 case MXC_SATA_CLK:
513 return get_ahb_clk();
Fabio Estevamb4121012012-04-30 08:12:02 +0000514 case MXC_DDR_CLK:
515 return get_ddr_clk();
Stefano Babica521a772010-01-20 18:19:32 +0100516 default:
517 break;
518 }
Fabio Estevamb4121012012-04-30 08:12:02 +0000519 return -EINVAL;
Stefano Babica521a772010-01-20 18:19:32 +0100520}
521
522u32 imx_get_uartclk(void)
523{
524 return get_uart_clk();
525}
526
Stefano Babica521a772010-01-20 18:19:32 +0100527u32 imx_get_fecclk(void)
528{
Benoît Thébaudeau743656e2012-09-27 10:23:58 +0000529 return get_ipg_clk();
Stefano Babica521a772010-01-20 18:19:32 +0100530}
531
Fabio Estevamb4121012012-04-30 08:12:02 +0000532static int gcd(int m, int n)
533{
534 int t;
535 while (m > 0) {
536 if (n > m) {
537 t = m;
538 m = n;
539 n = t;
540 } /* swap */
541 m -= n;
542 }
543 return n;
544}
545
546/*
547 * This is to calculate various parameters based on reference clock and
548 * targeted clock based on the equation:
549 * t_clk = 2*ref_freq*(mfi + mfn/(mfd+1))/(pd+1)
550 * This calculation is based on a fixed MFD value for simplicity.
551 */
552static int calc_pll_params(u32 ref, u32 target, struct pll_param *pll)
553{
554 u64 pd, mfi = 1, mfn, mfd, t1;
555 u32 n_target = target;
556 u32 n_ref = ref, i;
557
558 /*
559 * Make sure targeted freq is in the valid range.
560 * Otherwise the following calculation might be wrong!!!
561 */
562 if (n_target < PLL_FREQ_MIN(ref) ||
563 n_target > PLL_FREQ_MAX(ref)) {
564 printf("Targeted peripheral clock should be"
565 "within [%d - %d]\n",
566 PLL_FREQ_MIN(ref) / SZ_DEC_1M,
567 PLL_FREQ_MAX(ref) / SZ_DEC_1M);
568 return -EINVAL;
569 }
570
571 for (i = 0; i < ARRAY_SIZE(fixed_mfd); i++) {
572 if (fixed_mfd[i].ref_clk_hz == ref) {
573 mfd = fixed_mfd[i].mfd;
574 break;
575 }
576 }
577
578 if (i == ARRAY_SIZE(fixed_mfd))
579 return -EINVAL;
580
581 /* Use n_target and n_ref to avoid overflow */
582 for (pd = 1; pd <= PLL_PD_MAX; pd++) {
583 t1 = n_target * pd;
584 do_div(t1, (4 * n_ref));
585 mfi = t1;
586 if (mfi > PLL_MFI_MAX)
587 return -EINVAL;
588 else if (mfi < 5)
589 continue;
590 break;
591 }
592 /*
593 * Now got pd and mfi already
594 *
595 * mfn = (((n_target * pd) / 4 - n_ref * mfi) * mfd) / n_ref;
596 */
597 t1 = n_target * pd;
598 do_div(t1, 4);
599 t1 -= n_ref * mfi;
600 t1 *= mfd;
601 do_div(t1, n_ref);
602 mfn = t1;
603 debug("ref=%d, target=%d, pd=%d," "mfi=%d,mfn=%d, mfd=%d\n",
604 ref, n_target, (u32)pd, (u32)mfi, (u32)mfn, (u32)mfd);
605 i = 1;
606 if (mfn != 0)
607 i = gcd(mfd, mfn);
608 pll->pd = (u32)pd;
609 pll->mfi = (u32)mfi;
610 do_div(mfn, i);
611 pll->mfn = (u32)mfn;
612 do_div(mfd, i);
613 pll->mfd = (u32)mfd;
614
615 return 0;
616}
617
618#define calc_div(tgt_clk, src_clk, limit) ({ \
619 u32 v = 0; \
620 if (((src_clk) % (tgt_clk)) <= 100) \
621 v = (src_clk) / (tgt_clk); \
622 else \
623 v = ((src_clk) / (tgt_clk)) + 1;\
624 if (v > limit) \
625 v = limit; \
626 (v - 1); \
627 })
628
629#define CHANGE_PLL_SETTINGS(pll, pd, fi, fn, fd) \
630 { \
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000631 writel(0x1232, &pll->ctrl); \
632 writel(0x2, &pll->config); \
633 writel((((pd) - 1) << 0) | ((fi) << 4), \
634 &pll->op); \
635 writel(fn, &(pll->mfn)); \
636 writel((fd) - 1, &pll->mfd); \
637 writel((((pd) - 1) << 0) | ((fi) << 4), \
638 &pll->hfs_op); \
639 writel(fn, &pll->hfs_mfn); \
640 writel((fd) - 1, &pll->hfs_mfd); \
641 writel(0x1232, &pll->ctrl); \
642 while (!readl(&pll->ctrl) & 0x1) \
Fabio Estevamb4121012012-04-30 08:12:02 +0000643 ;\
644 }
645
646static int config_pll_clk(enum pll_clocks index, struct pll_param *pll_param)
647{
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000648 u32 ccsr = readl(&mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000649 struct mxc_pll_reg *pll = mxc_plls[index];
650
651 switch (index) {
652 case PLL1_CLOCK:
653 /* Switch ARM to PLL2 clock */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000654 writel(ccsr | MXC_CCM_CCSR_PLL1_SW_CLK_SEL,
655 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000656 CHANGE_PLL_SETTINGS(pll, pll_param->pd,
657 pll_param->mfi, pll_param->mfn,
658 pll_param->mfd);
659 /* Switch back */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000660 writel(ccsr & ~MXC_CCM_CCSR_PLL1_SW_CLK_SEL,
661 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000662 break;
663 case PLL2_CLOCK:
664 /* Switch to pll2 bypass clock */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000665 writel(ccsr | MXC_CCM_CCSR_PLL2_SW_CLK_SEL,
666 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000667 CHANGE_PLL_SETTINGS(pll, pll_param->pd,
668 pll_param->mfi, pll_param->mfn,
669 pll_param->mfd);
670 /* Switch back */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000671 writel(ccsr & ~MXC_CCM_CCSR_PLL2_SW_CLK_SEL,
672 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000673 break;
674 case PLL3_CLOCK:
675 /* Switch to pll3 bypass clock */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000676 writel(ccsr | MXC_CCM_CCSR_PLL3_SW_CLK_SEL,
677 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000678 CHANGE_PLL_SETTINGS(pll, pll_param->pd,
679 pll_param->mfi, pll_param->mfn,
680 pll_param->mfd);
681 /* Switch back */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000682 writel(ccsr & ~MXC_CCM_CCSR_PLL3_SW_CLK_SEL,
683 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000684 break;
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000685#ifdef CONFIG_MX53
Fabio Estevamb4121012012-04-30 08:12:02 +0000686 case PLL4_CLOCK:
687 /* Switch to pll4 bypass clock */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000688 writel(ccsr | MXC_CCM_CCSR_PLL4_SW_CLK_SEL,
689 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000690 CHANGE_PLL_SETTINGS(pll, pll_param->pd,
691 pll_param->mfi, pll_param->mfn,
692 pll_param->mfd);
693 /* Switch back */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000694 writel(ccsr & ~MXC_CCM_CCSR_PLL4_SW_CLK_SEL,
695 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000696 break;
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000697#endif
Fabio Estevamb4121012012-04-30 08:12:02 +0000698 default:
699 return -EINVAL;
700 }
701
702 return 0;
703}
704
705/* Config CPU clock */
706static int config_core_clk(u32 ref, u32 freq)
707{
708 int ret = 0;
709 struct pll_param pll_param;
710
711 memset(&pll_param, 0, sizeof(struct pll_param));
712
713 /* The case that periph uses PLL1 is not considered here */
714 ret = calc_pll_params(ref, freq, &pll_param);
715 if (ret != 0) {
716 printf("Error:Can't find pll parameters: %d\n", ret);
717 return ret;
718 }
719
720 return config_pll_clk(PLL1_CLOCK, &pll_param);
721}
722
723static int config_nfc_clk(u32 nfc_clk)
724{
Fabio Estevamb4121012012-04-30 08:12:02 +0000725 u32 parent_rate = get_emi_slow_clk();
Marek Vasut24775482013-04-21 05:52:26 +0000726 u32 div;
Fabio Estevamb4121012012-04-30 08:12:02 +0000727
Marek Vasut24775482013-04-21 05:52:26 +0000728 if (nfc_clk == 0)
Fabio Estevamb4121012012-04-30 08:12:02 +0000729 return -EINVAL;
Marek Vasut24775482013-04-21 05:52:26 +0000730 div = parent_rate / nfc_clk;
Fabio Estevamb4121012012-04-30 08:12:02 +0000731 if (div == 0)
732 div++;
733 if (parent_rate / div > NFC_CLK_MAX)
734 div++;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000735 clrsetbits_le32(&mxc_ccm->cbcdr,
736 MXC_CCM_CBCDR_NFC_PODF_MASK,
737 MXC_CCM_CBCDR_NFC_PODF(div - 1));
738 while (readl(&mxc_ccm->cdhipr) != 0)
Fabio Estevamb4121012012-04-30 08:12:02 +0000739 ;
740 return 0;
741}
742
Marek Vasut24775482013-04-21 05:52:26 +0000743void enable_nfc_clk(unsigned char enable)
744{
745 unsigned int cg = enable ? MXC_CCM_CCGR_CG_ON : MXC_CCM_CCGR_CG_OFF;
746
747 clrsetbits_le32(&mxc_ccm->CCGR5,
748 MXC_CCM_CCGR5_EMI_ENFC(MXC_CCM_CCGR_CG_MASK),
749 MXC_CCM_CCGR5_EMI_ENFC(cg));
750}
751
Sergey Alyoshina1d1ff62013-12-17 23:24:54 +0400752#ifdef CONFIG_FSL_IIM
753void enable_efuse_prog_supply(bool enable)
754{
755 if (enable)
756 setbits_le32(&mxc_ccm->cgpr,
757 MXC_CCM_CGPR_EFUSE_PROG_SUPPLY_GATE);
758 else
759 clrbits_le32(&mxc_ccm->cgpr,
760 MXC_CCM_CGPR_EFUSE_PROG_SUPPLY_GATE);
761}
762#endif
763
Fabio Estevamb4121012012-04-30 08:12:02 +0000764/* Config main_bus_clock for periphs */
765static int config_periph_clk(u32 ref, u32 freq)
766{
767 int ret = 0;
768 struct pll_param pll_param;
769
770 memset(&pll_param, 0, sizeof(struct pll_param));
771
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000772 if (readl(&mxc_ccm->cbcdr) & MXC_CCM_CBCDR_PERIPH_CLK_SEL) {
Fabio Estevamb4121012012-04-30 08:12:02 +0000773 ret = calc_pll_params(ref, freq, &pll_param);
774 if (ret != 0) {
775 printf("Error:Can't find pll parameters: %d\n",
776 ret);
777 return ret;
778 }
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000779 switch (MXC_CCM_CBCMR_PERIPH_CLK_SEL_RD(
780 readl(&mxc_ccm->cbcmr))) {
Fabio Estevamb4121012012-04-30 08:12:02 +0000781 case 0:
782 return config_pll_clk(PLL1_CLOCK, &pll_param);
783 break;
784 case 1:
785 return config_pll_clk(PLL3_CLOCK, &pll_param);
786 break;
787 default:
788 return -EINVAL;
789 }
790 }
791
792 return 0;
793}
794
795static int config_ddr_clk(u32 emi_clk)
796{
797 u32 clk_src;
798 s32 shift = 0, clk_sel, div = 1;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000799 u32 cbcmr = readl(&mxc_ccm->cbcmr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000800
801 if (emi_clk > MAX_DDR_CLK) {
802 printf("Warning:DDR clock should not exceed %d MHz\n",
803 MAX_DDR_CLK / SZ_DEC_1M);
804 emi_clk = MAX_DDR_CLK;
805 }
806
807 clk_src = get_periph_clk();
808 /* Find DDR clock input */
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000809 clk_sel = MXC_CCM_CBCMR_DDR_CLK_SEL_RD(cbcmr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000810 switch (clk_sel) {
811 case 0:
812 shift = 16;
813 break;
814 case 1:
815 shift = 19;
816 break;
817 case 2:
818 shift = 22;
819 break;
820 case 3:
821 shift = 10;
822 break;
823 default:
824 return -EINVAL;
825 }
826
827 if ((clk_src % emi_clk) < 10000000)
828 div = clk_src / emi_clk;
829 else
830 div = (clk_src / emi_clk) + 1;
831 if (div > 8)
832 div = 8;
833
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000834 clrsetbits_le32(&mxc_ccm->cbcdr, 0x7 << shift, (div - 1) << shift);
835 while (readl(&mxc_ccm->cdhipr) != 0)
Fabio Estevamb4121012012-04-30 08:12:02 +0000836 ;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000837 writel(0x0, &mxc_ccm->ccdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000838
839 return 0;
840}
841
842/*
843 * This function assumes the expected core clock has to be changed by
844 * modifying the PLL. This is NOT true always but for most of the times,
845 * it is. So it assumes the PLL output freq is the same as the expected
846 * core clock (presc=1) unless the core clock is less than PLL_FREQ_MIN.
847 * In the latter case, it will try to increase the presc value until
848 * (presc*core_clk) is greater than PLL_FREQ_MIN. It then makes call to
849 * calc_pll_params() and obtains the values of PD, MFI,MFN, MFD based
850 * on the targeted PLL and reference input clock to the PLL. Lastly,
851 * it sets the register based on these values along with the dividers.
852 * Note 1) There is no value checking for the passed-in divider values
853 * so the caller has to make sure those values are sensible.
854 * 2) Also adjust the NFC divider such that the NFC clock doesn't
855 * exceed NFC_CLK_MAX.
856 * 3) IPU HSP clock is independent of AHB clock. Even it can go up to
857 * 177MHz for higher voltage, this function fixes the max to 133MHz.
858 * 4) This function should not have allowed diag_printf() calls since
859 * the serial driver has been stoped. But leave then here to allow
860 * easy debugging by NOT calling the cyg_hal_plf_serial_stop().
861 */
862int mxc_set_clock(u32 ref, u32 freq, enum mxc_clock clk)
863{
864 freq *= SZ_DEC_1M;
865
866 switch (clk) {
867 case MXC_ARM_CLK:
868 if (config_core_clk(ref, freq))
869 return -EINVAL;
870 break;
871 case MXC_PERIPH_CLK:
872 if (config_periph_clk(ref, freq))
873 return -EINVAL;
874 break;
875 case MXC_DDR_CLK:
876 if (config_ddr_clk(freq))
877 return -EINVAL;
878 break;
879 case MXC_NFC_CLK:
880 if (config_nfc_clk(freq))
881 return -EINVAL;
882 break;
883 default:
884 printf("Warning:Unsupported or invalid clock type\n");
885 }
886
887 return 0;
888}
889
Stefano Babicc378abf2012-02-22 00:24:38 +0000890#ifdef CONFIG_MX53
891/*
892 * The clock for the external interface can be set to use internal clock
893 * if fuse bank 4, row 3, bit 2 is set.
894 * This is an undocumented feature and it was confirmed by Freescale's support:
895 * Fuses (but not pins) may be used to configure SATA clocks.
896 * Particularly the i.MX53 Fuse_Map contains the next information
897 * about configuring SATA clocks : SATA_ALT_REF_CLK[1:0] (offset 0x180C)
898 * '00' - 100MHz (External)
899 * '01' - 50MHz (External)
900 * '10' - 120MHz, internal (USB PHY)
901 * '11' - Reserved
902*/
903void mxc_set_sata_internal_clock(void)
904{
905 u32 *tmp_base =
906 (u32 *)(IIM_BASE_ADDR + 0x180c);
907
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000908 set_usb_phy_clk();
Stefano Babicc378abf2012-02-22 00:24:38 +0000909
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000910 clrsetbits_le32(tmp_base, 0x6, 0x4);
Stefano Babicc378abf2012-02-22 00:24:38 +0000911}
912#endif
913
Stefano Babica521a772010-01-20 18:19:32 +0100914/*
915 * Dump some core clockes.
916 */
Stefano Babic6eb90102010-10-28 11:08:52 +0200917int do_mx5_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefano Babica521a772010-01-20 18:19:32 +0100918{
919 u32 freq;
920
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000921 freq = decode_pll(mxc_plls[PLL1_CLOCK], MXC_HCLK);
Marek Vasut421bf452011-09-14 14:09:04 +0000922 printf("PLL1 %8d MHz\n", freq / 1000000);
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000923 freq = decode_pll(mxc_plls[PLL2_CLOCK], MXC_HCLK);
Marek Vasut421bf452011-09-14 14:09:04 +0000924 printf("PLL2 %8d MHz\n", freq / 1000000);
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000925 freq = decode_pll(mxc_plls[PLL3_CLOCK], MXC_HCLK);
Marek Vasut421bf452011-09-14 14:09:04 +0000926 printf("PLL3 %8d MHz\n", freq / 1000000);
Marek Vasut3c844f32011-09-23 11:43:47 +0200927#ifdef CONFIG_MX53
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000928 freq = decode_pll(mxc_plls[PLL4_CLOCK], MXC_HCLK);
Marek Vasut421bf452011-09-14 14:09:04 +0000929 printf("PLL4 %8d MHz\n", freq / 1000000);
Marek Vasut3c844f32011-09-23 11:43:47 +0200930#endif
Marek Vasut421bf452011-09-14 14:09:04 +0000931
932 printf("\n");
933 printf("AHB %8d kHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000);
934 printf("IPG %8d kHz\n", mxc_get_clock(MXC_IPG_CLK) / 1000);
935 printf("IPG PERCLK %8d kHz\n", mxc_get_clock(MXC_IPG_PERCLK) / 1000);
Fabio Estevamb4121012012-04-30 08:12:02 +0000936 printf("DDR %8d kHz\n", mxc_get_clock(MXC_DDR_CLK) / 1000);
Fabio Estevama82fee02012-11-15 11:23:22 +0000937#ifdef CONFIG_MXC_SPI
938 printf("CSPI %8d kHz\n", mxc_get_clock(MXC_CSPI_CLK) / 1000);
939#endif
Stefano Babica521a772010-01-20 18:19:32 +0100940 return 0;
941}
942
943/***************************************************/
944
945U_BOOT_CMD(
Stefano Babicc8a02c32011-08-17 17:52:40 +0200946 clocks, CONFIG_SYS_MAXARGS, 1, do_mx5_showclocks,
947 "display clocks",
Stefano Babica521a772010-01-20 18:19:32 +0100948 ""
949);