blob: 09cbd4a15f816d63b5fb11f65da673cdb04ae057 [file] [log] [blame]
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +02001/*
2 * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
3 * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301, USA.
18 */
19
20#include <linux/module.h>
21#include <linux/spinlock.h>
22#include <linux/delay.h>
23#include <linux/clk.h>
24#include <linux/err.h>
25#include <linux/io.h>
Sascha Hauer9eb2eb82009-02-18 11:55:33 +010026
27#include <asm/clkdev.h>
28#include <asm/div64.h>
29
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/clock.h>
Sascha Hauera2449092008-12-18 11:51:57 +010031#include <mach/hardware.h>
Sascha Hauer30c730f2009-02-16 14:36:49 +010032#include <mach/common.h>
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +020033
34#include "crm_regs.h"
35
36#define PRE_DIV_MIN_FREQ 10000000 /* Minimum Frequency after Predivider */
37
38static void __calc_pre_post_dividers(u32 div, u32 *pre, u32 *post)
39{
40 u32 min_pre, temp_pre, old_err, err;
41
42 if (div >= 512) {
43 *pre = 8;
44 *post = 64;
45 } else if (div >= 64) {
46 min_pre = (div - 1) / 64 + 1;
47 old_err = 8;
48 for (temp_pre = 8; temp_pre >= min_pre; temp_pre--) {
49 err = div % temp_pre;
50 if (err == 0) {
51 *pre = temp_pre;
52 break;
53 }
54 err = temp_pre - err;
55 if (err < old_err) {
56 old_err = err;
57 *pre = temp_pre;
58 }
59 }
60 *post = (div + *pre - 1) / *pre;
61 } else if (div <= 8) {
62 *pre = div;
63 *post = 1;
64 } else {
65 *pre = 1;
66 *post = div;
67 }
68}
69
70static struct clk mcu_pll_clk;
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +020071static struct clk serial_pll_clk;
72static struct clk ipg_clk;
73static struct clk ckih_clk;
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +020074
Sascha Hauer9eb2eb82009-02-18 11:55:33 +010075static int cgr_enable(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +020076{
77 u32 reg;
78
Sascha Hauer9eb2eb82009-02-18 11:55:33 +010079 if (!clk->enable_reg)
80 return 0;
81
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +020082 reg = __raw_readl(clk->enable_reg);
83 reg |= 3 << clk->enable_shift;
84 __raw_writel(reg, clk->enable_reg);
85
86 return 0;
87}
88
Sascha Hauer9eb2eb82009-02-18 11:55:33 +010089static void cgr_disable(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +020090{
91 u32 reg;
92
Sascha Hauer9eb2eb82009-02-18 11:55:33 +010093 if (!clk->enable_reg)
94 return;
95
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +020096 reg = __raw_readl(clk->enable_reg);
97 reg &= ~(3 << clk->enable_shift);
Sascha Hauer9eb2eb82009-02-18 11:55:33 +010098
99 /* special case for EMI clock */
100 if (clk->enable_reg == MXC_CCM_CGR2 && clk->enable_shift == 8)
101 reg |= (1 << clk->enable_shift);
102
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200103 __raw_writel(reg, clk->enable_reg);
104}
105
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100106static unsigned long pll_ref_get_rate(void)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200107{
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100108 unsigned long ccmr;
109 unsigned int prcs;
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200110
111 ccmr = __raw_readl(MXC_CCM_CCMR);
112 prcs = (ccmr & MXC_CCM_CCMR_PRCS_MASK) >> MXC_CCM_CCMR_PRCS_OFFSET;
113 if (prcs == 0x1)
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100114 return CKIL_CLK_FREQ * 1024;
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200115 else
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100116 return clk_get_rate(&ckih_clk);
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200117}
118
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100119static unsigned long usb_pll_get_rate(struct clk *clk)
120{
121 unsigned long reg;
122
123 reg = __raw_readl(MXC_CCM_UPCTL);
124
125 return mxc_decode_pll(reg, pll_ref_get_rate());
126}
127
128static unsigned long serial_pll_get_rate(struct clk *clk)
129{
130 unsigned long reg;
131
132 reg = __raw_readl(MXC_CCM_SRPCTL);
133
134 return mxc_decode_pll(reg, pll_ref_get_rate());
135}
136
137static unsigned long mcu_pll_get_rate(struct clk *clk)
138{
139 unsigned long reg, ccmr;
140
141 ccmr = __raw_readl(MXC_CCM_CCMR);
142
143 if (!(ccmr & MXC_CCM_CCMR_MPE) || (ccmr & MXC_CCM_CCMR_MDS))
144 return clk_get_rate(&ckih_clk);
145
146 reg = __raw_readl(MXC_CCM_MPCTL);
147
148 return mxc_decode_pll(reg, pll_ref_get_rate());
149}
150
151static int usb_pll_enable(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200152{
153 u32 reg;
154
155 reg = __raw_readl(MXC_CCM_CCMR);
156 reg |= MXC_CCM_CCMR_UPE;
157 __raw_writel(reg, MXC_CCM_CCMR);
158
159 /* No lock bit on MX31, so using max time from spec */
160 udelay(80);
161
162 return 0;
163}
164
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100165static void usb_pll_disable(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200166{
167 u32 reg;
168
169 reg = __raw_readl(MXC_CCM_CCMR);
170 reg &= ~MXC_CCM_CCMR_UPE;
171 __raw_writel(reg, MXC_CCM_CCMR);
172}
173
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100174static int serial_pll_enable(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200175{
176 u32 reg;
177
178 reg = __raw_readl(MXC_CCM_CCMR);
179 reg |= MXC_CCM_CCMR_SPE;
180 __raw_writel(reg, MXC_CCM_CCMR);
181
182 /* No lock bit on MX31, so using max time from spec */
183 udelay(80);
184
185 return 0;
186}
187
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100188static void serial_pll_disable(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200189{
190 u32 reg;
191
192 reg = __raw_readl(MXC_CCM_CCMR);
193 reg &= ~MXC_CCM_CCMR_SPE;
194 __raw_writel(reg, MXC_CCM_CCMR);
195}
196
197#define PDR0(mask, off) ((__raw_readl(MXC_CCM_PDR0) & mask) >> off)
198#define PDR1(mask, off) ((__raw_readl(MXC_CCM_PDR1) & mask) >> off)
199#define PDR2(mask, off) ((__raw_readl(MXC_CCM_PDR2) & mask) >> off)
200
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100201static unsigned long mcu_main_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200202{
203 u32 pmcr0 = __raw_readl(MXC_CCM_PMCR0);
204
205 if ((pmcr0 & MXC_CCM_PMCR0_DFSUP1) == MXC_CCM_PMCR0_DFSUP1_SPLL)
206 return clk_get_rate(&serial_pll_clk);
207 else
208 return clk_get_rate(&mcu_pll_clk);
209}
210
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100211static unsigned long ahb_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200212{
213 unsigned long max_pdf;
214
215 max_pdf = PDR0(MXC_CCM_PDR0_MAX_PODF_MASK,
216 MXC_CCM_PDR0_MAX_PODF_OFFSET);
217 return clk_get_rate(clk->parent) / (max_pdf + 1);
218}
219
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100220static unsigned long ipg_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200221{
222 unsigned long ipg_pdf;
223
224 ipg_pdf = PDR0(MXC_CCM_PDR0_IPG_PODF_MASK,
225 MXC_CCM_PDR0_IPG_PODF_OFFSET);
226 return clk_get_rate(clk->parent) / (ipg_pdf + 1);
227}
228
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100229static unsigned long nfc_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200230{
231 unsigned long nfc_pdf;
232
233 nfc_pdf = PDR0(MXC_CCM_PDR0_NFC_PODF_MASK,
234 MXC_CCM_PDR0_NFC_PODF_OFFSET);
235 return clk_get_rate(clk->parent) / (nfc_pdf + 1);
236}
237
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100238static unsigned long hsp_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200239{
240 unsigned long hsp_pdf;
241
242 hsp_pdf = PDR0(MXC_CCM_PDR0_HSP_PODF_MASK,
243 MXC_CCM_PDR0_HSP_PODF_OFFSET);
244 return clk_get_rate(clk->parent) / (hsp_pdf + 1);
245}
246
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100247static unsigned long usb_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200248{
249 unsigned long usb_pdf, usb_prepdf;
250
251 usb_pdf = PDR1(MXC_CCM_PDR1_USB_PODF_MASK,
252 MXC_CCM_PDR1_USB_PODF_OFFSET);
253 usb_prepdf = PDR1(MXC_CCM_PDR1_USB_PRDF_MASK,
254 MXC_CCM_PDR1_USB_PRDF_OFFSET);
255 return clk_get_rate(clk->parent) / (usb_prepdf + 1) / (usb_pdf + 1);
256}
257
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100258static unsigned long csi_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200259{
260 u32 reg, pre, post;
261
262 reg = __raw_readl(MXC_CCM_PDR0);
263 pre = (reg & MXC_CCM_PDR0_CSI_PRDF_MASK) >>
264 MXC_CCM_PDR0_CSI_PRDF_OFFSET;
265 pre++;
266 post = (reg & MXC_CCM_PDR0_CSI_PODF_MASK) >>
267 MXC_CCM_PDR0_CSI_PODF_OFFSET;
268 post++;
269 return clk_get_rate(clk->parent) / (pre * post);
270}
271
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100272static unsigned long csi_round_rate(struct clk *clk, unsigned long rate)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200273{
274 u32 pre, post, parent = clk_get_rate(clk->parent);
275 u32 div = parent / rate;
276
277 if (parent % rate)
278 div++;
279
280 __calc_pre_post_dividers(div, &pre, &post);
281
282 return parent / (pre * post);
283}
284
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100285static int csi_set_rate(struct clk *clk, unsigned long rate)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200286{
287 u32 reg, div, pre, post, parent = clk_get_rate(clk->parent);
288
289 div = parent / rate;
290
291 if ((parent / div) != rate)
292 return -EINVAL;
293
294 __calc_pre_post_dividers(div, &pre, &post);
295
296 /* Set CSI clock divider */
297 reg = __raw_readl(MXC_CCM_PDR0) &
298 ~(MXC_CCM_PDR0_CSI_PODF_MASK | MXC_CCM_PDR0_CSI_PRDF_MASK);
299 reg |= (post - 1) << MXC_CCM_PDR0_CSI_PODF_OFFSET;
300 reg |= (pre - 1) << MXC_CCM_PDR0_CSI_PRDF_OFFSET;
301 __raw_writel(reg, MXC_CCM_PDR0);
302
303 return 0;
304}
305
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100306static unsigned long ssi1_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200307{
308 unsigned long ssi1_pdf, ssi1_prepdf;
309
310 ssi1_pdf = PDR1(MXC_CCM_PDR1_SSI1_PODF_MASK,
311 MXC_CCM_PDR1_SSI1_PODF_OFFSET);
312 ssi1_prepdf = PDR1(MXC_CCM_PDR1_SSI1_PRE_PODF_MASK,
313 MXC_CCM_PDR1_SSI1_PRE_PODF_OFFSET);
314 return clk_get_rate(clk->parent) / (ssi1_prepdf + 1) / (ssi1_pdf + 1);
315}
316
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100317static unsigned long ssi2_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200318{
319 unsigned long ssi2_pdf, ssi2_prepdf;
320
321 ssi2_pdf = PDR1(MXC_CCM_PDR1_SSI2_PODF_MASK,
322 MXC_CCM_PDR1_SSI2_PODF_OFFSET);
323 ssi2_prepdf = PDR1(MXC_CCM_PDR1_SSI2_PRE_PODF_MASK,
324 MXC_CCM_PDR1_SSI2_PRE_PODF_OFFSET);
325 return clk_get_rate(clk->parent) / (ssi2_prepdf + 1) / (ssi2_pdf + 1);
326}
327
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100328static unsigned long firi_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200329{
330 unsigned long firi_pdf, firi_prepdf;
331
332 firi_pdf = PDR1(MXC_CCM_PDR1_FIRI_PODF_MASK,
333 MXC_CCM_PDR1_FIRI_PODF_OFFSET);
334 firi_prepdf = PDR1(MXC_CCM_PDR1_FIRI_PRE_PODF_MASK,
335 MXC_CCM_PDR1_FIRI_PRE_PODF_OFFSET);
336 return clk_get_rate(clk->parent) / (firi_prepdf + 1) / (firi_pdf + 1);
337}
338
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100339static unsigned long firi_round_rate(struct clk *clk, unsigned long rate)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200340{
341 u32 pre, post;
342 u32 parent = clk_get_rate(clk->parent);
343 u32 div = parent / rate;
344
345 if (parent % rate)
346 div++;
347
348 __calc_pre_post_dividers(div, &pre, &post);
349
350 return parent / (pre * post);
351
352}
353
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100354static int firi_set_rate(struct clk *clk, unsigned long rate)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200355{
356 u32 reg, div, pre, post, parent = clk_get_rate(clk->parent);
357
358 div = parent / rate;
359
360 if ((parent / div) != rate)
361 return -EINVAL;
362
363 __calc_pre_post_dividers(div, &pre, &post);
364
365 /* Set FIRI clock divider */
366 reg = __raw_readl(MXC_CCM_PDR1) &
367 ~(MXC_CCM_PDR1_FIRI_PODF_MASK | MXC_CCM_PDR1_FIRI_PRE_PODF_MASK);
368 reg |= (pre - 1) << MXC_CCM_PDR1_FIRI_PRE_PODF_OFFSET;
369 reg |= (post - 1) << MXC_CCM_PDR1_FIRI_PODF_OFFSET;
370 __raw_writel(reg, MXC_CCM_PDR1);
371
372 return 0;
373}
374
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100375static unsigned long mbx_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200376{
377 return clk_get_rate(clk->parent) / 2;
378}
379
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100380static unsigned long mstick1_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200381{
382 unsigned long msti_pdf;
383
384 msti_pdf = PDR2(MXC_CCM_PDR2_MST1_PDF_MASK,
385 MXC_CCM_PDR2_MST1_PDF_OFFSET);
386 return clk_get_rate(clk->parent) / (msti_pdf + 1);
387}
388
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100389static unsigned long mstick2_get_rate(struct clk *clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200390{
391 unsigned long msti_pdf;
392
393 msti_pdf = PDR2(MXC_CCM_PDR2_MST2_PDF_MASK,
394 MXC_CCM_PDR2_MST2_PDF_OFFSET);
395 return clk_get_rate(clk->parent) / (msti_pdf + 1);
396}
397
398static unsigned long ckih_rate;
399
400static unsigned long clk_ckih_get_rate(struct clk *clk)
401{
402 return ckih_rate;
403}
404
405static struct clk ckih_clk = {
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200406 .get_rate = clk_ckih_get_rate,
407};
408
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200409static struct clk mcu_pll_clk = {
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200410 .parent = &ckih_clk,
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100411 .get_rate = mcu_pll_get_rate,
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200412};
413
414static struct clk mcu_main_clk = {
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200415 .parent = &mcu_pll_clk,
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100416 .get_rate = mcu_main_get_rate,
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200417};
418
419static struct clk serial_pll_clk = {
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200420 .parent = &ckih_clk,
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100421 .get_rate = serial_pll_get_rate,
422 .enable = serial_pll_enable,
423 .disable = serial_pll_disable,
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200424};
425
426static struct clk usb_pll_clk = {
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200427 .parent = &ckih_clk,
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100428 .get_rate = usb_pll_get_rate,
429 .enable = usb_pll_enable,
430 .disable = usb_pll_disable,
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200431};
432
433static struct clk ahb_clk = {
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200434 .parent = &mcu_main_clk,
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100435 .get_rate = ahb_get_rate,
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200436};
437
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100438#define DEFINE_CLOCK(name, i, er, es, gr, s, p) \
439 static struct clk name = { \
440 .id = i, \
441 .enable_reg = er, \
442 .enable_shift = es, \
443 .get_rate = gr, \
444 .enable = cgr_enable, \
445 .disable = cgr_disable, \
446 .secondary = s, \
447 .parent = p, \
448 }
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200449
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100450#define DEFINE_CLOCK1(name, i, er, es, getsetround, s, p) \
451 static struct clk name = { \
452 .id = i, \
453 .enable_reg = er, \
454 .enable_shift = es, \
455 .get_rate = getsetround##_get_rate, \
456 .set_rate = getsetround##_set_rate, \
457 .round_rate = getsetround##_round_rate, \
458 .enable = cgr_enable, \
459 .disable = cgr_disable, \
460 .secondary = s, \
461 .parent = p, \
462 }
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200463
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100464DEFINE_CLOCK(perclk_clk, 0, NULL, 0, NULL, NULL, &ipg_clk);
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200465
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100466DEFINE_CLOCK(sdhc1_clk, 0, MXC_CCM_CGR0, 0, NULL, NULL, &perclk_clk);
467DEFINE_CLOCK(sdhc2_clk, 1, MXC_CCM_CGR0, 2, NULL, NULL, &perclk_clk);
468DEFINE_CLOCK(gpt_clk, 0, MXC_CCM_CGR0, 4, NULL, NULL, &perclk_clk);
469DEFINE_CLOCK(epit1_clk, 0, MXC_CCM_CGR0, 6, NULL, NULL, &perclk_clk);
470DEFINE_CLOCK(epit2_clk, 1, MXC_CCM_CGR0, 8, NULL, NULL, &perclk_clk);
471DEFINE_CLOCK(iim_clk, 0, MXC_CCM_CGR0, 10, NULL, NULL, &ipg_clk);
472DEFINE_CLOCK(ata_clk, 0, MXC_CCM_CGR0, 12, NULL, NULL, &ipg_clk);
473DEFINE_CLOCK(sdma_clk1, 0, MXC_CCM_CGR0, 14, NULL, &sdma_clk1, &ahb_clk);
474DEFINE_CLOCK(cspi3_clk, 2, MXC_CCM_CGR0, 16, NULL, NULL, &ipg_clk);
475DEFINE_CLOCK(rng_clk, 0, MXC_CCM_CGR0, 18, NULL, NULL, &ipg_clk);
476DEFINE_CLOCK(uart1_clk, 0, MXC_CCM_CGR0, 20, NULL, NULL, &perclk_clk);
477DEFINE_CLOCK(uart2_clk, 1, MXC_CCM_CGR0, 22, NULL, NULL, &perclk_clk);
478DEFINE_CLOCK(ssi1_clk, 0, MXC_CCM_CGR0, 24, ssi1_get_rate, NULL, &serial_pll_clk);
479DEFINE_CLOCK(i2c1_clk, 0, MXC_CCM_CGR0, 26, NULL, NULL, &perclk_clk);
480DEFINE_CLOCK(i2c2_clk, 1, MXC_CCM_CGR0, 28, NULL, NULL, &perclk_clk);
481DEFINE_CLOCK(i2c3_clk, 2, MXC_CCM_CGR0, 30, NULL, NULL, &perclk_clk);
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200482
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100483DEFINE_CLOCK(mpeg4_clk, 0, MXC_CCM_CGR1, 0, NULL, NULL, &ahb_clk);
484DEFINE_CLOCK(mstick1_clk, 0, MXC_CCM_CGR1, 2, mstick1_get_rate, NULL, &usb_pll_clk);
485DEFINE_CLOCK(mstick2_clk, 1, MXC_CCM_CGR1, 4, mstick2_get_rate, NULL, &usb_pll_clk);
486DEFINE_CLOCK1(csi_clk, 0, MXC_CCM_CGR1, 6, csi, NULL, &ahb_clk);
487DEFINE_CLOCK(rtc_clk, 0, MXC_CCM_CGR1, 8, NULL, NULL, &ipg_clk);
488DEFINE_CLOCK(wdog_clk, 0, MXC_CCM_CGR1, 10, NULL, NULL, &ipg_clk);
489DEFINE_CLOCK(pwm_clk, 0, MXC_CCM_CGR1, 12, NULL, NULL, &perclk_clk);
490DEFINE_CLOCK(usb_clk2, 0, MXC_CCM_CGR1, 18, usb_get_rate, NULL, &ahb_clk);
491DEFINE_CLOCK(kpp_clk, 0, MXC_CCM_CGR1, 20, NULL, NULL, &ipg_clk);
492DEFINE_CLOCK(ipu_clk, 0, MXC_CCM_CGR1, 22, hsp_get_rate, NULL, &mcu_main_clk);
493DEFINE_CLOCK(uart3_clk, 2, MXC_CCM_CGR1, 24, NULL, NULL, &perclk_clk);
494DEFINE_CLOCK(uart4_clk, 3, MXC_CCM_CGR1, 26, NULL, NULL, &perclk_clk);
495DEFINE_CLOCK(uart5_clk, 4, MXC_CCM_CGR1, 28, NULL, NULL, &perclk_clk);
496DEFINE_CLOCK(owire_clk, 0, MXC_CCM_CGR1, 30, NULL, NULL, &perclk_clk);
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200497
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100498DEFINE_CLOCK(ssi2_clk, 1, MXC_CCM_CGR2, 0, ssi2_get_rate, NULL, &serial_pll_clk);
499DEFINE_CLOCK(cspi1_clk, 0, MXC_CCM_CGR2, 2, NULL, NULL, &ipg_clk);
500DEFINE_CLOCK(cspi2_clk, 1, MXC_CCM_CGR2, 4, NULL, NULL, &ipg_clk);
501DEFINE_CLOCK(mbx_clk, 0, MXC_CCM_CGR2, 6, mbx_get_rate, NULL, &ahb_clk);
502DEFINE_CLOCK(emi_clk, 0, MXC_CCM_CGR2, 8, NULL, NULL, &ahb_clk);
503DEFINE_CLOCK(rtic_clk, 0, MXC_CCM_CGR2, 10, NULL, NULL, &ahb_clk);
504DEFINE_CLOCK1(firi_clk, 0, MXC_CCM_CGR2, 12, firi, NULL, &usb_pll_clk);
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200505
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100506DEFINE_CLOCK(sdma_clk2, 0, NULL, 0, NULL, NULL, &ipg_clk);
507DEFINE_CLOCK(usb_clk1, 0, NULL, 0, usb_get_rate, NULL, &usb_pll_clk);
508DEFINE_CLOCK(nfc_clk, 0, NULL, 0, nfc_get_rate, NULL, &ahb_clk);
509DEFINE_CLOCK(scc_clk, 0, NULL, 0, NULL, NULL, &ipg_clk);
510DEFINE_CLOCK(ipg_clk, 0, NULL, 0, ipg_get_rate, NULL, &ahb_clk);
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200511
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100512#define _REGISTER_CLOCK(d, n, c) \
513 { \
514 .dev_id = d, \
515 .con_id = n, \
516 .clk = &c, \
517 },
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200518
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100519static struct clk_lookup lookups[] __initdata = {
520 _REGISTER_CLOCK(NULL, "emi", emi_clk)
521 _REGISTER_CLOCK(NULL, "cspi", cspi1_clk)
522 _REGISTER_CLOCK(NULL, "cspi", cspi2_clk)
523 _REGISTER_CLOCK(NULL, "cspi", cspi3_clk)
524 _REGISTER_CLOCK(NULL, "gpt", gpt_clk)
525 _REGISTER_CLOCK(NULL, "pwm", pwm_clk)
526 _REGISTER_CLOCK(NULL, "wdog", wdog_clk)
527 _REGISTER_CLOCK(NULL, "rtc", rtc_clk)
528 _REGISTER_CLOCK(NULL, "epit", epit1_clk)
529 _REGISTER_CLOCK(NULL, "epit", epit2_clk)
530 _REGISTER_CLOCK("mxc_nand.0", NULL, nfc_clk)
531 _REGISTER_CLOCK("ipu-core", NULL, ipu_clk)
532 _REGISTER_CLOCK("mx3_sdc_fb", NULL, ipu_clk)
533 _REGISTER_CLOCK(NULL, "kpp", kpp_clk)
534 _REGISTER_CLOCK("fsl-usb2-udc", "usb", usb_clk1)
535 _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", usb_clk2)
Guennadi Liakhovetskib71df972009-04-03 10:34:02 -0300536 _REGISTER_CLOCK("mx3-camera.0", NULL, csi_clk)
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100537 _REGISTER_CLOCK("imx-uart.0", NULL, uart1_clk)
538 _REGISTER_CLOCK("imx-uart.1", NULL, uart2_clk)
539 _REGISTER_CLOCK("imx-uart.2", NULL, uart3_clk)
540 _REGISTER_CLOCK("imx-uart.3", NULL, uart4_clk)
541 _REGISTER_CLOCK("imx-uart.4", NULL, uart5_clk)
542 _REGISTER_CLOCK("imx-i2c.0", NULL, i2c1_clk)
543 _REGISTER_CLOCK("imx-i2c.1", NULL, i2c2_clk)
544 _REGISTER_CLOCK("imx-i2c.2", NULL, i2c3_clk)
545 _REGISTER_CLOCK("mxc_w1.0", NULL, owire_clk)
546 _REGISTER_CLOCK("mxc-mmc.0", NULL, sdhc1_clk)
547 _REGISTER_CLOCK("mxc-mmc.1", NULL, sdhc2_clk)
548 _REGISTER_CLOCK(NULL, "ssi", ssi1_clk)
549 _REGISTER_CLOCK(NULL, "ssi", ssi2_clk)
550 _REGISTER_CLOCK(NULL, "firi", firi_clk)
551 _REGISTER_CLOCK(NULL, "ata", ata_clk)
552 _REGISTER_CLOCK(NULL, "rtic", rtic_clk)
553 _REGISTER_CLOCK(NULL, "rng", rng_clk)
554 _REGISTER_CLOCK(NULL, "sdma_ahb", sdma_clk1)
555 _REGISTER_CLOCK(NULL, "sdma_ipg", sdma_clk2)
556 _REGISTER_CLOCK(NULL, "mstick", mstick1_clk)
557 _REGISTER_CLOCK(NULL, "mstick", mstick2_clk)
558 _REGISTER_CLOCK(NULL, "scc", scc_clk)
559 _REGISTER_CLOCK(NULL, "iim", iim_clk)
560 _REGISTER_CLOCK(NULL, "mpeg4", mpeg4_clk)
561 _REGISTER_CLOCK(NULL, "mbx", mbx_clk)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200562};
563
Sascha Hauer30c730f2009-02-16 14:36:49 +0100564int __init mx31_clocks_init(unsigned long fref)
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200565{
566 u32 reg;
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100567 int i;
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200568
569 ckih_rate = fref;
570
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100571 for (i = 0; i < ARRAY_SIZE(lookups); i++)
572 clkdev_add(&lookups[i]);
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200573
574 /* Turn off all possible clocks */
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100575 __raw_writel((3 << 4), MXC_CCM_CGR0);
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200576 __raw_writel(0, MXC_CCM_CGR1);
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100577 __raw_writel((3 << 8) | (3 << 14) | (3 << 16)|
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200578 1 << 27 | 1 << 28, /* Bit 27 and 28 are not defined for
579 MX32, but still required to be set */
580 MXC_CCM_CGR2);
581
Sascha Hauer9eb2eb82009-02-18 11:55:33 +0100582 usb_pll_disable(&usb_pll_clk);
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200583
584 pr_info("Clock input source is %ld\n", clk_get_rate(&ckih_clk));
585
586 clk_enable(&gpt_clk);
587 clk_enable(&emi_clk);
588 clk_enable(&iim_clk);
589
590 clk_enable(&serial_pll_clk);
591
592 if (mx31_revision() >= CHIP_REV_2_0) {
593 reg = __raw_readl(MXC_CCM_PMCR1);
594 /* No PLL restart on DVFS switch; enable auto EMI handshake */
595 reg |= MXC_CCM_PMCR1_PLLRDIS | MXC_CCM_PMCR1_EMIRQ_EN;
596 __raw_writel(reg, MXC_CCM_PMCR1);
597 }
598
Sascha Hauer30c730f2009-02-16 14:36:49 +0100599 mxc_timer_init(&ipg_clk);
600
Sascha Hauerdf1bf4b2008-07-05 10:02:48 +0200601 return 0;
602}
603