blob: 76c2c529a88fb72e7a5f96e9497725b48e1f6646 [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 *
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 Babicac41d4d2010-03-05 17:54:37 +010031#include <asm/arch/clock.h>
Marek Vasut3c844f32011-09-23 11:43:47 +020032#include <div64.h>
Fabio Estevam6479f512012-04-29 08:11:13 +000033#include <asm/arch/sys_proto.h>
Stefano Babica521a772010-01-20 18:19:32 +010034
35enum pll_clocks {
36 PLL1_CLOCK = 0,
37 PLL2_CLOCK,
38 PLL3_CLOCK,
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +000039#ifdef CONFIG_MX53
Marek Vasut3c844f32011-09-23 11:43:47 +020040 PLL4_CLOCK,
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +000041#endif
Stefano Babica521a772010-01-20 18:19:32 +010042 PLL_CLOCKS,
43};
44
45struct mxc_pll_reg *mxc_plls[PLL_CLOCKS] = {
46 [PLL1_CLOCK] = (struct mxc_pll_reg *)PLL1_BASE_ADDR,
47 [PLL2_CLOCK] = (struct mxc_pll_reg *)PLL2_BASE_ADDR,
48 [PLL3_CLOCK] = (struct mxc_pll_reg *)PLL3_BASE_ADDR,
Marek Vasut3c844f32011-09-23 11:43:47 +020049#ifdef CONFIG_MX53
50 [PLL4_CLOCK] = (struct mxc_pll_reg *)PLL4_BASE_ADDR,
51#endif
Stefano Babica521a772010-01-20 18:19:32 +010052};
53
Fabio Estevamb4121012012-04-30 08:12:02 +000054#define AHB_CLK_ROOT 133333333
55#define SZ_DEC_1M 1000000
56#define PLL_PD_MAX 16 /* Actual pd+1 */
57#define PLL_MFI_MAX 15
58#define PLL_MFI_MIN 5
59#define ARM_DIV_MAX 8
60#define IPG_DIV_MAX 4
61#define AHB_DIV_MAX 8
62#define EMI_DIV_MAX 8
63#define NFC_DIV_MAX 8
64
65#define MX5_CBCMR 0x00015154
66#define MX5_CBCDR 0x02888945
67
68struct fixed_pll_mfd {
69 u32 ref_clk_hz;
70 u32 mfd;
71};
72
73const struct fixed_pll_mfd fixed_mfd[] = {
Benoît Thébaudeauafac1652012-09-27 10:19:58 +000074 {MXC_HCLK, 24 * 16},
Fabio Estevamb4121012012-04-30 08:12:02 +000075};
76
77struct pll_param {
78 u32 pd;
79 u32 mfi;
80 u32 mfn;
81 u32 mfd;
82};
83
84#define PLL_FREQ_MAX(ref_clk) (4 * (ref_clk) * PLL_MFI_MAX)
85#define PLL_FREQ_MIN(ref_clk) \
86 ((2 * (ref_clk) * (PLL_MFI_MIN - 1)) / PLL_PD_MAX)
87#define MAX_DDR_CLK 420000000
88#define NFC_CLK_MAX 34000000
89
Stefano Babicac41d4d2010-03-05 17:54:37 +010090struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
Stefano Babica521a772010-01-20 18:19:32 +010091
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +010092void set_usboh3_clk(void)
93{
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +000094 clrsetbits_le32(&mxc_ccm->cscmr1,
95 MXC_CCM_CSCMR1_USBOH3_CLK_SEL_MASK,
96 MXC_CCM_CSCMR1_USBOH3_CLK_SEL(1));
97 clrsetbits_le32(&mxc_ccm->cscdr1,
98 MXC_CCM_CSCDR1_USBOH3_CLK_PODF_MASK |
99 MXC_CCM_CSCDR1_USBOH3_CLK_PRED_MASK,
100 MXC_CCM_CSCDR1_USBOH3_CLK_PRED(4) |
101 MXC_CCM_CSCDR1_USBOH3_CLK_PODF(1));
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100102}
103
104void enable_usboh3_clk(unsigned char enable)
105{
Benoît Thébaudeau6dfc6302012-09-27 10:21:22 +0000106 unsigned int cg = enable ? MXC_CCM_CCGR_CG_ON : MXC_CCM_CCGR_CG_OFF;
107
108 clrsetbits_le32(&mxc_ccm->CCGR2,
109 MXC_CCM_CCGR2_USBOH3_60M(MXC_CCM_CCGR_CG_MASK),
110 MXC_CCM_CCGR2_USBOH3_60M(cg));
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100111}
112
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000113#ifdef CONFIG_I2C_MXC
Benoît Thébaudeaua23408c2012-09-27 10:24:13 +0000114/* i2c_num can be from 0, to 1 for i.MX51 and 2 for i.MX53 */
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000115int enable_i2c_clk(unsigned char enable, unsigned i2c_num)
116{
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000117 u32 mask;
118
Benoît Thébaudeaua23408c2012-09-27 10:24:13 +0000119#if defined(CONFIG_MX51)
120 if (i2c_num > 1)
121#elif defined(CONFIG_MX53)
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000122 if (i2c_num > 2)
Benoît Thébaudeaua23408c2012-09-27 10:24:13 +0000123#endif
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000124 return -EINVAL;
Benoît Thébaudeau461a00a2012-09-27 10:21:00 +0000125 mask = MXC_CCM_CCGR_CG_MASK <<
126 (MXC_CCM_CCGR1_I2C1_OFFSET + (i2c_num << 1));
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000127 if (enable)
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000128 setbits_le32(&mxc_ccm->CCGR1, mask);
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000129 else
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000130 clrbits_le32(&mxc_ccm->CCGR1, mask);
Troy Kiskyd4fdc992012-07-19 08:18:25 +0000131 return 0;
132}
133#endif
134
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000135void set_usb_phy_clk(void)
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100136{
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000137 clrbits_le32(&mxc_ccm->cscmr1, MXC_CCM_CSCMR1_USB_PHY_CLK_SEL);
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100138}
139
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000140#if defined(CONFIG_MX51)
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100141void enable_usb_phy1_clk(unsigned char enable)
142{
Benoît Thébaudeau6dfc6302012-09-27 10:21:22 +0000143 unsigned int cg = enable ? MXC_CCM_CCGR_CG_ON : MXC_CCM_CCGR_CG_OFF;
144
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000145 clrsetbits_le32(&mxc_ccm->CCGR2,
146 MXC_CCM_CCGR2_USB_PHY(MXC_CCM_CCGR_CG_MASK),
147 MXC_CCM_CCGR2_USB_PHY(cg));
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100148}
149
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000150void enable_usb_phy2_clk(unsigned char enable)
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100151{
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000152 /* i.MX51 has a single USB PHY clock, so do nothing here. */
153}
154#elif defined(CONFIG_MX53)
155void enable_usb_phy1_clk(unsigned char enable)
156{
157 unsigned int cg = enable ? MXC_CCM_CCGR_CG_ON : MXC_CCM_CCGR_CG_OFF;
158
159 clrsetbits_le32(&mxc_ccm->CCGR4,
160 MXC_CCM_CCGR4_USB_PHY1(MXC_CCM_CCGR_CG_MASK),
161 MXC_CCM_CCGR4_USB_PHY1(cg));
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100162}
163
164void enable_usb_phy2_clk(unsigned char enable)
165{
Benoît Thébaudeau6dfc6302012-09-27 10:21:22 +0000166 unsigned int cg = enable ? MXC_CCM_CCGR_CG_ON : MXC_CCM_CCGR_CG_OFF;
167
168 clrsetbits_le32(&mxc_ccm->CCGR4,
169 MXC_CCM_CCGR4_USB_PHY2(MXC_CCM_CCGR_CG_MASK),
170 MXC_CCM_CCGR4_USB_PHY2(cg));
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100171}
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000172#endif
Wolfgang Grandegger8c1e4d32011-11-11 14:03:34 +0100173
Stefano Babica521a772010-01-20 18:19:32 +0100174/*
Marek Vasut3c844f32011-09-23 11:43:47 +0200175 * Calculate the frequency of PLLn.
Stefano Babica521a772010-01-20 18:19:32 +0100176 */
Marek Vasut3c844f32011-09-23 11:43:47 +0200177static uint32_t decode_pll(struct mxc_pll_reg *pll, uint32_t infreq)
Stefano Babica521a772010-01-20 18:19:32 +0100178{
Marek Vasut3c844f32011-09-23 11:43:47 +0200179 uint32_t ctrl, op, mfd, mfn, mfi, pdf, ret;
180 uint64_t refclk, temp;
181 int32_t mfn_abs;
Stefano Babica521a772010-01-20 18:19:32 +0100182
Marek Vasut3c844f32011-09-23 11:43:47 +0200183 ctrl = readl(&pll->ctrl);
Stefano Babica521a772010-01-20 18:19:32 +0100184
Marek Vasut3c844f32011-09-23 11:43:47 +0200185 if (ctrl & MXC_DPLLC_CTL_HFSM) {
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000186 mfn = readl(&pll->hfs_mfn);
187 mfd = readl(&pll->hfs_mfd);
188 op = readl(&pll->hfs_op);
Marek Vasut3c844f32011-09-23 11:43:47 +0200189 } else {
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000190 mfn = readl(&pll->mfn);
191 mfd = readl(&pll->mfd);
192 op = readl(&pll->op);
Marek Vasut3c844f32011-09-23 11:43:47 +0200193 }
194
195 mfd &= MXC_DPLLC_MFD_MFD_MASK;
196 mfn &= MXC_DPLLC_MFN_MFN_MASK;
197 pdf = op & MXC_DPLLC_OP_PDF_MASK;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000198 mfi = MXC_DPLLC_OP_MFI_RD(op);
Marek Vasut3c844f32011-09-23 11:43:47 +0200199
200 /* 21.2.3 */
201 if (mfi < 5)
202 mfi = 5;
203
204 /* Sign extend */
205 if (mfn >= 0x04000000) {
206 mfn |= 0xfc000000;
207 mfn_abs = -mfn;
208 } else
209 mfn_abs = mfn;
210
211 refclk = infreq * 2;
212 if (ctrl & MXC_DPLLC_CTL_DPDCK0_2_EN)
213 refclk *= 2;
214
Simon Glass3d557882011-11-05 04:25:22 +0000215 do_div(refclk, pdf + 1);
Marek Vasut3c844f32011-09-23 11:43:47 +0200216 temp = refclk * mfn_abs;
217 do_div(temp, mfd + 1);
218 ret = refclk * mfi;
219
220 if ((int)mfn < 0)
221 ret -= temp;
222 else
223 ret += temp;
224
225 return ret;
Stefano Babica521a772010-01-20 18:19:32 +0100226}
227
Benoît Thébaudeau9c05cc72012-09-27 10:22:37 +0000228#ifdef CONFIG_MX51
229/*
230 * This function returns the Frequency Pre-Multiplier clock.
231 */
232static u32 get_fpm(void)
233{
234 u32 mult;
235 u32 ccr = readl(&mxc_ccm->ccr);
236
237 if (ccr & MXC_CCM_CCR_FPM_MULT)
238 mult = 1024;
239 else
240 mult = 512;
241
242 return MXC_CLK32 * mult;
243}
244#endif
245
Stefano Babica521a772010-01-20 18:19:32 +0100246/*
Benoît Thébaudeau96d9df32012-09-27 10:22:51 +0000247 * This function returns the low power audio clock.
248 */
249static u32 get_lp_apm(void)
250{
251 u32 ret_val = 0;
252 u32 ccsr = readl(&mxc_ccm->ccsr);
253
254 if (ccsr & MXC_CCM_CCSR_LP_APM)
255#if defined(CONFIG_MX51)
256 ret_val = get_fpm();
257#elif defined(CONFIG_MX53)
258 ret_val = decode_pll(mxc_plls[PLL4_CLOCK], MXC_HCLK);
259#endif
260 else
261 ret_val = MXC_HCLK;
262
263 return ret_val;
264}
265
266/*
Stefano Babica521a772010-01-20 18:19:32 +0100267 * Get mcu main rate
268 */
269u32 get_mcu_main_clk(void)
270{
271 u32 reg, freq;
272
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000273 reg = MXC_CCM_CACRR_ARM_PODF_RD(readl(&mxc_ccm->cacrr));
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000274 freq = decode_pll(mxc_plls[PLL1_CLOCK], MXC_HCLK);
Stefano Babica521a772010-01-20 18:19:32 +0100275 return freq / (reg + 1);
276}
277
278/*
279 * Get the rate of peripheral's root clock.
280 */
Fabio Estevam6479f512012-04-29 08:11:13 +0000281u32 get_periph_clk(void)
Stefano Babica521a772010-01-20 18:19:32 +0100282{
283 u32 reg;
284
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000285 reg = readl(&mxc_ccm->cbcdr);
Stefano Babica521a772010-01-20 18:19:32 +0100286 if (!(reg & MXC_CCM_CBCDR_PERIPH_CLK_SEL))
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000287 return decode_pll(mxc_plls[PLL2_CLOCK], MXC_HCLK);
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000288 reg = readl(&mxc_ccm->cbcmr);
289 switch (MXC_CCM_CBCMR_PERIPH_CLK_SEL_RD(reg)) {
Stefano Babica521a772010-01-20 18:19:32 +0100290 case 0:
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000291 return decode_pll(mxc_plls[PLL1_CLOCK], MXC_HCLK);
Stefano Babica521a772010-01-20 18:19:32 +0100292 case 1:
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000293 return decode_pll(mxc_plls[PLL3_CLOCK], MXC_HCLK);
Benoît Thébaudeau96d9df32012-09-27 10:22:51 +0000294 case 2:
295 return get_lp_apm();
Stefano Babica521a772010-01-20 18:19:32 +0100296 default:
297 return 0;
298 }
299 /* NOTREACHED */
300}
301
302/*
303 * Get the rate of ipg clock.
304 */
305static u32 get_ipg_clk(void)
306{
Marek Vasut6674bf52011-09-22 09:20:37 +0000307 uint32_t freq, reg, div;
Stefano Babica521a772010-01-20 18:19:32 +0100308
Marek Vasut6674bf52011-09-22 09:20:37 +0000309 freq = get_ahb_clk();
310
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000311 reg = readl(&mxc_ccm->cbcdr);
312 div = MXC_CCM_CBCDR_IPG_PODF_RD(reg) + 1;
Marek Vasut6674bf52011-09-22 09:20:37 +0000313
314 return freq / div;
Stefano Babica521a772010-01-20 18:19:32 +0100315}
316
317/*
318 * Get the rate of ipg_per clock.
319 */
320static u32 get_ipg_per_clk(void)
321{
Benoît Thébaudeau0cef3ae2012-09-27 10:23:08 +0000322 u32 freq, pred1, pred2, podf;
Stefano Babica521a772010-01-20 18:19:32 +0100323
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000324 if (readl(&mxc_ccm->cbcmr) & MXC_CCM_CBCMR_PERCLK_IPG_CLK_SEL)
Stefano Babica521a772010-01-20 18:19:32 +0100325 return get_ipg_clk();
Benoît Thébaudeau0cef3ae2012-09-27 10:23:08 +0000326
327 if (readl(&mxc_ccm->cbcmr) & MXC_CCM_CBCMR_PERCLK_LP_APM_CLK_SEL)
328 freq = get_lp_apm();
329 else
330 freq = get_periph_clk();
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000331 podf = readl(&mxc_ccm->cbcdr);
332 pred1 = MXC_CCM_CBCDR_PERCLK_PRED1_RD(podf);
333 pred2 = MXC_CCM_CBCDR_PERCLK_PRED2_RD(podf);
334 podf = MXC_CCM_CBCDR_PERCLK_PODF_RD(podf);
Benoît Thébaudeau0cef3ae2012-09-27 10:23:08 +0000335 return freq / ((pred1 + 1) * (pred2 + 1) * (podf + 1));
Stefano Babica521a772010-01-20 18:19:32 +0100336}
337
Benoît Thébaudeau9aa99c42012-09-27 10:23:23 +0000338/* Get the output clock rate of a standard PLL MUX for peripherals. */
339static u32 get_standard_pll_sel_clk(u32 clk_sel)
Stefano Babica521a772010-01-20 18:19:32 +0100340{
Stefano Babicfd375f32012-10-24 10:06:28 +0200341 u32 freq = 0;
Stefano Babica521a772010-01-20 18:19:32 +0100342
Benoît Thébaudeau9aa99c42012-09-27 10:23:23 +0000343 switch (clk_sel & 0x3) {
344 case 0:
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000345 freq = decode_pll(mxc_plls[PLL1_CLOCK], MXC_HCLK);
Stefano Babica521a772010-01-20 18:19:32 +0100346 break;
Benoît Thébaudeau9aa99c42012-09-27 10:23:23 +0000347 case 1:
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000348 freq = decode_pll(mxc_plls[PLL2_CLOCK], MXC_HCLK);
Stefano Babica521a772010-01-20 18:19:32 +0100349 break;
Benoît Thébaudeau9aa99c42012-09-27 10:23:23 +0000350 case 2:
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000351 freq = decode_pll(mxc_plls[PLL3_CLOCK], MXC_HCLK);
Stefano Babica521a772010-01-20 18:19:32 +0100352 break;
Benoît Thébaudeau9aa99c42012-09-27 10:23:23 +0000353 case 3:
354 freq = get_lp_apm();
355 break;
Stefano Babica521a772010-01-20 18:19:32 +0100356 }
357
Benoît Thébaudeau9aa99c42012-09-27 10:23:23 +0000358 return freq;
359}
360
361/*
362 * Get the rate of uart clk.
363 */
364static u32 get_uart_clk(void)
365{
366 unsigned int clk_sel, freq, reg, pred, podf;
367
368 reg = readl(&mxc_ccm->cscmr1);
369 clk_sel = MXC_CCM_CSCMR1_UART_CLK_SEL_RD(reg);
370 freq = get_standard_pll_sel_clk(clk_sel);
371
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000372 reg = readl(&mxc_ccm->cscdr1);
373 pred = MXC_CCM_CSCDR1_UART_CLK_PRED_RD(reg);
374 podf = MXC_CCM_CSCDR1_UART_CLK_PODF_RD(reg);
Stefano Babica521a772010-01-20 18:19:32 +0100375 freq /= (pred + 1) * (podf + 1);
376
377 return freq;
378}
379
380/*
Stefano Babica521a772010-01-20 18:19:32 +0100381 * get cspi clock rate.
382 */
Fabio Estevamb4121012012-04-30 08:12:02 +0000383static u32 imx_get_cspiclk(void)
Stefano Babica521a772010-01-20 18:19:32 +0100384{
Benoît Thébaudeau81fb2742012-09-27 10:23:42 +0000385 u32 ret_val = 0, pdf, pre_pdf, clk_sel, freq;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000386 u32 cscmr1 = readl(&mxc_ccm->cscmr1);
387 u32 cscdr2 = readl(&mxc_ccm->cscdr2);
Stefano Babica521a772010-01-20 18:19:32 +0100388
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000389 pre_pdf = MXC_CCM_CSCDR2_CSPI_CLK_PRED_RD(cscdr2);
390 pdf = MXC_CCM_CSCDR2_CSPI_CLK_PODF_RD(cscdr2);
391 clk_sel = MXC_CCM_CSCMR1_CSPI_CLK_SEL_RD(cscmr1);
Benoît Thébaudeau81fb2742012-09-27 10:23:42 +0000392 freq = get_standard_pll_sel_clk(clk_sel);
393 ret_val = freq / ((pre_pdf + 1) * (pdf + 1));
Stefano Babica521a772010-01-20 18:19:32 +0100394 return ret_val;
395}
396
Benoît Thébaudeaueb9c2552012-09-27 10:24:37 +0000397/*
398 * get esdhc clock rate.
399 */
400static u32 get_esdhc_clk(u32 port)
401{
402 u32 clk_sel = 0, pred = 0, podf = 0, freq = 0;
403 u32 cscmr1 = readl(&mxc_ccm->cscmr1);
404 u32 cscdr1 = readl(&mxc_ccm->cscdr1);
405
406 switch (port) {
407 case 0:
408 clk_sel = MXC_CCM_CSCMR1_ESDHC1_MSHC1_CLK_SEL_RD(cscmr1);
409 pred = MXC_CCM_CSCDR1_ESDHC1_MSHC1_CLK_PRED_RD(cscdr1);
410 podf = MXC_CCM_CSCDR1_ESDHC1_MSHC1_CLK_PODF_RD(cscdr1);
411 break;
412 case 1:
413 clk_sel = MXC_CCM_CSCMR1_ESDHC2_MSHC2_CLK_SEL_RD(cscmr1);
414 pred = MXC_CCM_CSCDR1_ESDHC2_MSHC2_CLK_PRED_RD(cscdr1);
415 podf = MXC_CCM_CSCDR1_ESDHC2_MSHC2_CLK_PODF_RD(cscdr1);
416 break;
417 case 2:
418 if (cscmr1 & MXC_CCM_CSCMR1_ESDHC3_CLK_SEL)
419 return get_esdhc_clk(1);
420 else
421 return get_esdhc_clk(0);
422 case 3:
423 if (cscmr1 & MXC_CCM_CSCMR1_ESDHC4_CLK_SEL)
424 return get_esdhc_clk(1);
425 else
426 return get_esdhc_clk(0);
427 default:
428 break;
429 }
430
431 freq = get_standard_pll_sel_clk(clk_sel) / ((pred + 1) * (podf + 1));
432 return freq;
433}
434
Fabio Estevamb4121012012-04-30 08:12:02 +0000435static u32 get_axi_a_clk(void)
436{
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000437 u32 cbcdr = readl(&mxc_ccm->cbcdr);
438 u32 pdf = MXC_CCM_CBCDR_AXI_A_PODF_RD(cbcdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000439
440 return get_periph_clk() / (pdf + 1);
441}
442
443static u32 get_axi_b_clk(void)
444{
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000445 u32 cbcdr = readl(&mxc_ccm->cbcdr);
446 u32 pdf = MXC_CCM_CBCDR_AXI_B_PODF_RD(cbcdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000447
448 return get_periph_clk() / (pdf + 1);
449}
450
451static u32 get_emi_slow_clk(void)
452{
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000453 u32 cbcdr = readl(&mxc_ccm->cbcdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000454 u32 emi_clk_sel = cbcdr & MXC_CCM_CBCDR_EMI_CLK_SEL;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000455 u32 pdf = MXC_CCM_CBCDR_EMI_PODF_RD(cbcdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000456
457 if (emi_clk_sel)
458 return get_ahb_clk() / (pdf + 1);
459
460 return get_periph_clk() / (pdf + 1);
461}
462
463static u32 get_ddr_clk(void)
464{
465 u32 ret_val = 0;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000466 u32 cbcmr = readl(&mxc_ccm->cbcmr);
467 u32 ddr_clk_sel = MXC_CCM_CBCMR_DDR_CLK_SEL_RD(cbcmr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000468#ifdef CONFIG_MX51
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000469 u32 cbcdr = readl(&mxc_ccm->cbcdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000470 if (cbcdr & MXC_CCM_CBCDR_DDR_HIFREQ_SEL) {
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000471 u32 ddr_clk_podf = MXC_CCM_CBCDR_DDR_PODF_RD(cbcdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000472
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000473 ret_val = decode_pll(mxc_plls[PLL1_CLOCK], MXC_HCLK);
Fabio Estevamb4121012012-04-30 08:12:02 +0000474 ret_val /= ddr_clk_podf + 1;
475
476 return ret_val;
477 }
478#endif
479 switch (ddr_clk_sel) {
480 case 0:
481 ret_val = get_axi_a_clk();
482 break;
483 case 1:
484 ret_val = get_axi_b_clk();
485 break;
486 case 2:
487 ret_val = get_emi_slow_clk();
488 break;
489 case 3:
490 ret_val = get_ahb_clk();
491 break;
492 default:
493 break;
494 }
495
496 return ret_val;
497}
498
Stefano Babica521a772010-01-20 18:19:32 +0100499/*
Fabio Estevamb4121012012-04-30 08:12:02 +0000500 * The API of get mxc clocks.
Stefano Babica521a772010-01-20 18:19:32 +0100501 */
502unsigned int mxc_get_clock(enum mxc_clock clk)
503{
504 switch (clk) {
505 case MXC_ARM_CLK:
506 return get_mcu_main_clk();
507 case MXC_AHB_CLK:
Marek Vasut6674bf52011-09-22 09:20:37 +0000508 return get_ahb_clk();
Stefano Babica521a772010-01-20 18:19:32 +0100509 case MXC_IPG_CLK:
510 return get_ipg_clk();
511 case MXC_IPG_PERCLK:
Matthias Weisser99ba3422012-09-24 02:46:53 +0000512 case MXC_I2C_CLK:
Stefano Babica521a772010-01-20 18:19:32 +0100513 return get_ipg_per_clk();
514 case MXC_UART_CLK:
515 return get_uart_clk();
516 case MXC_CSPI_CLK:
517 return imx_get_cspiclk();
Benoît Thébaudeaueb9c2552012-09-27 10:24:37 +0000518 case MXC_ESDHC_CLK:
519 return get_esdhc_clk(0);
520 case MXC_ESDHC2_CLK:
521 return get_esdhc_clk(1);
522 case MXC_ESDHC3_CLK:
523 return get_esdhc_clk(2);
524 case MXC_ESDHC4_CLK:
525 return get_esdhc_clk(3);
Stefano Babica521a772010-01-20 18:19:32 +0100526 case MXC_FEC_CLK:
Benoît Thébaudeau743656e2012-09-27 10:23:58 +0000527 return get_ipg_clk();
Stefano Babicd38db762012-02-22 00:24:36 +0000528 case MXC_SATA_CLK:
529 return get_ahb_clk();
Fabio Estevamb4121012012-04-30 08:12:02 +0000530 case MXC_DDR_CLK:
531 return get_ddr_clk();
Stefano Babica521a772010-01-20 18:19:32 +0100532 default:
533 break;
534 }
Fabio Estevamb4121012012-04-30 08:12:02 +0000535 return -EINVAL;
Stefano Babica521a772010-01-20 18:19:32 +0100536}
537
538u32 imx_get_uartclk(void)
539{
540 return get_uart_clk();
541}
542
Stefano Babica521a772010-01-20 18:19:32 +0100543u32 imx_get_fecclk(void)
544{
Benoît Thébaudeau743656e2012-09-27 10:23:58 +0000545 return get_ipg_clk();
Stefano Babica521a772010-01-20 18:19:32 +0100546}
547
Fabio Estevamb4121012012-04-30 08:12:02 +0000548static int gcd(int m, int n)
549{
550 int t;
551 while (m > 0) {
552 if (n > m) {
553 t = m;
554 m = n;
555 n = t;
556 } /* swap */
557 m -= n;
558 }
559 return n;
560}
561
562/*
563 * This is to calculate various parameters based on reference clock and
564 * targeted clock based on the equation:
565 * t_clk = 2*ref_freq*(mfi + mfn/(mfd+1))/(pd+1)
566 * This calculation is based on a fixed MFD value for simplicity.
567 */
568static int calc_pll_params(u32 ref, u32 target, struct pll_param *pll)
569{
570 u64 pd, mfi = 1, mfn, mfd, t1;
571 u32 n_target = target;
572 u32 n_ref = ref, i;
573
574 /*
575 * Make sure targeted freq is in the valid range.
576 * Otherwise the following calculation might be wrong!!!
577 */
578 if (n_target < PLL_FREQ_MIN(ref) ||
579 n_target > PLL_FREQ_MAX(ref)) {
580 printf("Targeted peripheral clock should be"
581 "within [%d - %d]\n",
582 PLL_FREQ_MIN(ref) / SZ_DEC_1M,
583 PLL_FREQ_MAX(ref) / SZ_DEC_1M);
584 return -EINVAL;
585 }
586
587 for (i = 0; i < ARRAY_SIZE(fixed_mfd); i++) {
588 if (fixed_mfd[i].ref_clk_hz == ref) {
589 mfd = fixed_mfd[i].mfd;
590 break;
591 }
592 }
593
594 if (i == ARRAY_SIZE(fixed_mfd))
595 return -EINVAL;
596
597 /* Use n_target and n_ref to avoid overflow */
598 for (pd = 1; pd <= PLL_PD_MAX; pd++) {
599 t1 = n_target * pd;
600 do_div(t1, (4 * n_ref));
601 mfi = t1;
602 if (mfi > PLL_MFI_MAX)
603 return -EINVAL;
604 else if (mfi < 5)
605 continue;
606 break;
607 }
608 /*
609 * Now got pd and mfi already
610 *
611 * mfn = (((n_target * pd) / 4 - n_ref * mfi) * mfd) / n_ref;
612 */
613 t1 = n_target * pd;
614 do_div(t1, 4);
615 t1 -= n_ref * mfi;
616 t1 *= mfd;
617 do_div(t1, n_ref);
618 mfn = t1;
619 debug("ref=%d, target=%d, pd=%d," "mfi=%d,mfn=%d, mfd=%d\n",
620 ref, n_target, (u32)pd, (u32)mfi, (u32)mfn, (u32)mfd);
621 i = 1;
622 if (mfn != 0)
623 i = gcd(mfd, mfn);
624 pll->pd = (u32)pd;
625 pll->mfi = (u32)mfi;
626 do_div(mfn, i);
627 pll->mfn = (u32)mfn;
628 do_div(mfd, i);
629 pll->mfd = (u32)mfd;
630
631 return 0;
632}
633
634#define calc_div(tgt_clk, src_clk, limit) ({ \
635 u32 v = 0; \
636 if (((src_clk) % (tgt_clk)) <= 100) \
637 v = (src_clk) / (tgt_clk); \
638 else \
639 v = ((src_clk) / (tgt_clk)) + 1;\
640 if (v > limit) \
641 v = limit; \
642 (v - 1); \
643 })
644
645#define CHANGE_PLL_SETTINGS(pll, pd, fi, fn, fd) \
646 { \
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000647 writel(0x1232, &pll->ctrl); \
648 writel(0x2, &pll->config); \
649 writel((((pd) - 1) << 0) | ((fi) << 4), \
650 &pll->op); \
651 writel(fn, &(pll->mfn)); \
652 writel((fd) - 1, &pll->mfd); \
653 writel((((pd) - 1) << 0) | ((fi) << 4), \
654 &pll->hfs_op); \
655 writel(fn, &pll->hfs_mfn); \
656 writel((fd) - 1, &pll->hfs_mfd); \
657 writel(0x1232, &pll->ctrl); \
658 while (!readl(&pll->ctrl) & 0x1) \
Fabio Estevamb4121012012-04-30 08:12:02 +0000659 ;\
660 }
661
662static int config_pll_clk(enum pll_clocks index, struct pll_param *pll_param)
663{
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000664 u32 ccsr = readl(&mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000665 struct mxc_pll_reg *pll = mxc_plls[index];
666
667 switch (index) {
668 case PLL1_CLOCK:
669 /* Switch ARM to PLL2 clock */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000670 writel(ccsr | MXC_CCM_CCSR_PLL1_SW_CLK_SEL,
671 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000672 CHANGE_PLL_SETTINGS(pll, pll_param->pd,
673 pll_param->mfi, pll_param->mfn,
674 pll_param->mfd);
675 /* Switch back */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000676 writel(ccsr & ~MXC_CCM_CCSR_PLL1_SW_CLK_SEL,
677 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000678 break;
679 case PLL2_CLOCK:
680 /* Switch to pll2 bypass clock */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000681 writel(ccsr | MXC_CCM_CCSR_PLL2_SW_CLK_SEL,
682 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000683 CHANGE_PLL_SETTINGS(pll, pll_param->pd,
684 pll_param->mfi, pll_param->mfn,
685 pll_param->mfd);
686 /* Switch back */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000687 writel(ccsr & ~MXC_CCM_CCSR_PLL2_SW_CLK_SEL,
688 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000689 break;
690 case PLL3_CLOCK:
691 /* Switch to pll3 bypass clock */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000692 writel(ccsr | MXC_CCM_CCSR_PLL3_SW_CLK_SEL,
693 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000694 CHANGE_PLL_SETTINGS(pll, pll_param->pd,
695 pll_param->mfi, pll_param->mfn,
696 pll_param->mfd);
697 /* Switch back */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000698 writel(ccsr & ~MXC_CCM_CCSR_PLL3_SW_CLK_SEL,
699 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000700 break;
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000701#ifdef CONFIG_MX53
Fabio Estevamb4121012012-04-30 08:12:02 +0000702 case PLL4_CLOCK:
703 /* Switch to pll4 bypass clock */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000704 writel(ccsr | MXC_CCM_CCSR_PLL4_SW_CLK_SEL,
705 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000706 CHANGE_PLL_SETTINGS(pll, pll_param->pd,
707 pll_param->mfi, pll_param->mfn,
708 pll_param->mfd);
709 /* Switch back */
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000710 writel(ccsr & ~MXC_CCM_CCSR_PLL4_SW_CLK_SEL,
711 &mxc_ccm->ccsr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000712 break;
Benoît Thébaudeau3c98eb52012-09-27 10:22:22 +0000713#endif
Fabio Estevamb4121012012-04-30 08:12:02 +0000714 default:
715 return -EINVAL;
716 }
717
718 return 0;
719}
720
721/* Config CPU clock */
722static int config_core_clk(u32 ref, u32 freq)
723{
724 int ret = 0;
725 struct pll_param pll_param;
726
727 memset(&pll_param, 0, sizeof(struct pll_param));
728
729 /* The case that periph uses PLL1 is not considered here */
730 ret = calc_pll_params(ref, freq, &pll_param);
731 if (ret != 0) {
732 printf("Error:Can't find pll parameters: %d\n", ret);
733 return ret;
734 }
735
736 return config_pll_clk(PLL1_CLOCK, &pll_param);
737}
738
739static int config_nfc_clk(u32 nfc_clk)
740{
Fabio Estevamb4121012012-04-30 08:12:02 +0000741 u32 parent_rate = get_emi_slow_clk();
742 u32 div = parent_rate / nfc_clk;
743
744 if (nfc_clk <= 0)
745 return -EINVAL;
746 if (div == 0)
747 div++;
748 if (parent_rate / div > NFC_CLK_MAX)
749 div++;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000750 clrsetbits_le32(&mxc_ccm->cbcdr,
751 MXC_CCM_CBCDR_NFC_PODF_MASK,
752 MXC_CCM_CBCDR_NFC_PODF(div - 1));
753 while (readl(&mxc_ccm->cdhipr) != 0)
Fabio Estevamb4121012012-04-30 08:12:02 +0000754 ;
755 return 0;
756}
757
758/* Config main_bus_clock for periphs */
759static int config_periph_clk(u32 ref, u32 freq)
760{
761 int ret = 0;
762 struct pll_param pll_param;
763
764 memset(&pll_param, 0, sizeof(struct pll_param));
765
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000766 if (readl(&mxc_ccm->cbcdr) & MXC_CCM_CBCDR_PERIPH_CLK_SEL) {
Fabio Estevamb4121012012-04-30 08:12:02 +0000767 ret = calc_pll_params(ref, freq, &pll_param);
768 if (ret != 0) {
769 printf("Error:Can't find pll parameters: %d\n",
770 ret);
771 return ret;
772 }
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000773 switch (MXC_CCM_CBCMR_PERIPH_CLK_SEL_RD(
774 readl(&mxc_ccm->cbcmr))) {
Fabio Estevamb4121012012-04-30 08:12:02 +0000775 case 0:
776 return config_pll_clk(PLL1_CLOCK, &pll_param);
777 break;
778 case 1:
779 return config_pll_clk(PLL3_CLOCK, &pll_param);
780 break;
781 default:
782 return -EINVAL;
783 }
784 }
785
786 return 0;
787}
788
789static int config_ddr_clk(u32 emi_clk)
790{
791 u32 clk_src;
792 s32 shift = 0, clk_sel, div = 1;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000793 u32 cbcmr = readl(&mxc_ccm->cbcmr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000794
795 if (emi_clk > MAX_DDR_CLK) {
796 printf("Warning:DDR clock should not exceed %d MHz\n",
797 MAX_DDR_CLK / SZ_DEC_1M);
798 emi_clk = MAX_DDR_CLK;
799 }
800
801 clk_src = get_periph_clk();
802 /* Find DDR clock input */
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000803 clk_sel = MXC_CCM_CBCMR_DDR_CLK_SEL_RD(cbcmr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000804 switch (clk_sel) {
805 case 0:
806 shift = 16;
807 break;
808 case 1:
809 shift = 19;
810 break;
811 case 2:
812 shift = 22;
813 break;
814 case 3:
815 shift = 10;
816 break;
817 default:
818 return -EINVAL;
819 }
820
821 if ((clk_src % emi_clk) < 10000000)
822 div = clk_src / emi_clk;
823 else
824 div = (clk_src / emi_clk) + 1;
825 if (div > 8)
826 div = 8;
827
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000828 clrsetbits_le32(&mxc_ccm->cbcdr, 0x7 << shift, (div - 1) << shift);
829 while (readl(&mxc_ccm->cdhipr) != 0)
Fabio Estevamb4121012012-04-30 08:12:02 +0000830 ;
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000831 writel(0x0, &mxc_ccm->ccdr);
Fabio Estevamb4121012012-04-30 08:12:02 +0000832
833 return 0;
834}
835
836/*
837 * This function assumes the expected core clock has to be changed by
838 * modifying the PLL. This is NOT true always but for most of the times,
839 * it is. So it assumes the PLL output freq is the same as the expected
840 * core clock (presc=1) unless the core clock is less than PLL_FREQ_MIN.
841 * In the latter case, it will try to increase the presc value until
842 * (presc*core_clk) is greater than PLL_FREQ_MIN. It then makes call to
843 * calc_pll_params() and obtains the values of PD, MFI,MFN, MFD based
844 * on the targeted PLL and reference input clock to the PLL. Lastly,
845 * it sets the register based on these values along with the dividers.
846 * Note 1) There is no value checking for the passed-in divider values
847 * so the caller has to make sure those values are sensible.
848 * 2) Also adjust the NFC divider such that the NFC clock doesn't
849 * exceed NFC_CLK_MAX.
850 * 3) IPU HSP clock is independent of AHB clock. Even it can go up to
851 * 177MHz for higher voltage, this function fixes the max to 133MHz.
852 * 4) This function should not have allowed diag_printf() calls since
853 * the serial driver has been stoped. But leave then here to allow
854 * easy debugging by NOT calling the cyg_hal_plf_serial_stop().
855 */
856int mxc_set_clock(u32 ref, u32 freq, enum mxc_clock clk)
857{
858 freq *= SZ_DEC_1M;
859
860 switch (clk) {
861 case MXC_ARM_CLK:
862 if (config_core_clk(ref, freq))
863 return -EINVAL;
864 break;
865 case MXC_PERIPH_CLK:
866 if (config_periph_clk(ref, freq))
867 return -EINVAL;
868 break;
869 case MXC_DDR_CLK:
870 if (config_ddr_clk(freq))
871 return -EINVAL;
872 break;
873 case MXC_NFC_CLK:
874 if (config_nfc_clk(freq))
875 return -EINVAL;
876 break;
877 default:
878 printf("Warning:Unsupported or invalid clock type\n");
879 }
880
881 return 0;
882}
883
Stefano Babicc378abf2012-02-22 00:24:38 +0000884#ifdef CONFIG_MX53
885/*
886 * The clock for the external interface can be set to use internal clock
887 * if fuse bank 4, row 3, bit 2 is set.
888 * This is an undocumented feature and it was confirmed by Freescale's support:
889 * Fuses (but not pins) may be used to configure SATA clocks.
890 * Particularly the i.MX53 Fuse_Map contains the next information
891 * about configuring SATA clocks : SATA_ALT_REF_CLK[1:0] (offset 0x180C)
892 * '00' - 100MHz (External)
893 * '01' - 50MHz (External)
894 * '10' - 120MHz, internal (USB PHY)
895 * '11' - Reserved
896*/
897void mxc_set_sata_internal_clock(void)
898{
899 u32 *tmp_base =
900 (u32 *)(IIM_BASE_ADDR + 0x180c);
901
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000902 set_usb_phy_clk();
Stefano Babicc378abf2012-02-22 00:24:38 +0000903
Benoît Thébaudeaue5a10172012-09-27 10:20:33 +0000904 clrsetbits_le32(tmp_base, 0x6, 0x4);
Stefano Babicc378abf2012-02-22 00:24:38 +0000905}
906#endif
907
Stefano Babica521a772010-01-20 18:19:32 +0100908/*
909 * Dump some core clockes.
910 */
Stefano Babic6eb90102010-10-28 11:08:52 +0200911int do_mx5_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefano Babica521a772010-01-20 18:19:32 +0100912{
913 u32 freq;
914
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000915 freq = decode_pll(mxc_plls[PLL1_CLOCK], MXC_HCLK);
Marek Vasut421bf452011-09-14 14:09:04 +0000916 printf("PLL1 %8d MHz\n", freq / 1000000);
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000917 freq = decode_pll(mxc_plls[PLL2_CLOCK], MXC_HCLK);
Marek Vasut421bf452011-09-14 14:09:04 +0000918 printf("PLL2 %8d MHz\n", freq / 1000000);
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000919 freq = decode_pll(mxc_plls[PLL3_CLOCK], MXC_HCLK);
Marek Vasut421bf452011-09-14 14:09:04 +0000920 printf("PLL3 %8d MHz\n", freq / 1000000);
Marek Vasut3c844f32011-09-23 11:43:47 +0200921#ifdef CONFIG_MX53
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000922 freq = decode_pll(mxc_plls[PLL4_CLOCK], MXC_HCLK);
Marek Vasut421bf452011-09-14 14:09:04 +0000923 printf("PLL4 %8d MHz\n", freq / 1000000);
Marek Vasut3c844f32011-09-23 11:43:47 +0200924#endif
Marek Vasut421bf452011-09-14 14:09:04 +0000925
926 printf("\n");
927 printf("AHB %8d kHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000);
928 printf("IPG %8d kHz\n", mxc_get_clock(MXC_IPG_CLK) / 1000);
929 printf("IPG PERCLK %8d kHz\n", mxc_get_clock(MXC_IPG_PERCLK) / 1000);
Fabio Estevamb4121012012-04-30 08:12:02 +0000930 printf("DDR %8d kHz\n", mxc_get_clock(MXC_DDR_CLK) / 1000);
Fabio Estevama82fee02012-11-15 11:23:22 +0000931#ifdef CONFIG_MXC_SPI
932 printf("CSPI %8d kHz\n", mxc_get_clock(MXC_CSPI_CLK) / 1000);
933#endif
Stefano Babica521a772010-01-20 18:19:32 +0100934 return 0;
935}
936
937/***************************************************/
938
939U_BOOT_CMD(
Stefano Babicc8a02c32011-08-17 17:52:40 +0200940 clocks, CONFIG_SYS_MAXARGS, 1, do_mx5_showclocks,
941 "display clocks",
Stefano Babica521a772010-01-20 18:19:32 +0100942 ""
943);