blob: c93a5180eb5702f3e84928dc7ad07a6d60eca056 [file] [log] [blame]
wdenk4e5ca3e2003-12-08 01:34:36 +00001/*
wdenkbf9e3b32004-02-12 00:47:09 +00002 * (C) Copyright 2003
3 * Josef Baumgartner <josef.baumgartner@telex.de>
wdenk4e5ca3e2003-12-08 01:34:36 +00004 *
TsiChungLiewa1436a82007-08-16 13:20:50 -05005 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
6 * Hayden Fraser (Hayden.Fraser@freescale.com)
7 *
wdenk4e5ca3e2003-12-08 01:34:36 +00008 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27#include <common.h>
28#include <asm/processor.h>
TsiChungLiewa1436a82007-08-16 13:20:50 -050029#include <asm/immap.h>
wdenk4e5ca3e2003-12-08 01:34:36 +000030
Wolfgang Denkd87080b2006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
32
wdenkbf9e3b32004-02-12 00:47:09 +000033/*
34 * get_clocks() fills in gd->cpu_clock and gd->bus_clk
35 */
36int get_clocks (void)
wdenk4e5ca3e2003-12-08 01:34:36 +000037{
TsiChungLiewa1436a82007-08-16 13:20:50 -050038#if defined(CONFIG_M5249) || defined(CONFIG_M5253)
39 volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
40 unsigned long pllcr;
41
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020042#ifndef CONFIG_SYS_PLL_BYPASS
TsiChungLiewa1436a82007-08-16 13:20:50 -050043
stroese8c725b92004-12-16 18:09:49 +000044#ifdef CONFIG_M5249
TsiChungLiewa1436a82007-08-16 13:20:50 -050045 /* Setup the PLL to run at the specified speed */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020046#ifdef CONFIG_SYS_FAST_CLK
TsiChungLiewa1436a82007-08-16 13:20:50 -050047 pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
48#else
49 pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
50#endif
51#endif /* CONFIG_M5249 */
52
53#ifdef CONFIG_M5253
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020054 pllcr = CONFIG_SYS_PLLCR;
TsiChungLiewa1436a82007-08-16 13:20:50 -050055#endif /* CONFIG_M5253 */
56
57 cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
58 mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
59 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
60 pllcr ^= 0x00000001; /* Set pll bypass to 1 */
61 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
62 udelay(0x20); /* Wait for a lock ... */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020063#endif /* #ifndef CONFIG_SYS_PLL_BYPASS */
TsiChungLiewa1436a82007-08-16 13:20:50 -050064
65#endif /* CONFIG_M5249 || CONFIG_M5253 */
66
Matthew Fettkef71d9d92008-02-04 15:38:20 -060067#if defined(CONFIG_M5275)
68 volatile pll_t *pll = (volatile pll_t *)(MMAP_PLL);
69
Wolfgang Denk1aeed8d2008-04-13 09:59:26 -070070 /* Setup PLL */
71 pll->syncr = 0x01080000;
TsiChung Liewdd08e972008-06-18 19:19:07 -050072 while (!(pll->synsr & FMPLL_SYNSR_LOCK))
Wolfgang Denk1aeed8d2008-04-13 09:59:26 -070073 ;
74 pll->syncr = 0x01000000;
75 while (!(pll->synsr & FMPLL_SYNSR_LOCK))
76 ;
Matthew Fettkef71d9d92008-02-04 15:38:20 -060077#endif
78
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020079 gd->cpu_clk = CONFIG_SYS_CLK;
Richard Retanubun4ffc3902009-01-23 09:27:00 -050080#if defined(CONFIG_M5249) || defined(CONFIG_M5253) || \
81 defined(CONFIG_M5271) || defined(CONFIG_M5275)
stroese8c725b92004-12-16 18:09:49 +000082 gd->bus_clk = gd->cpu_clk / 2;
83#else
wdenkbf9e3b32004-02-12 00:47:09 +000084 gd->bus_clk = gd->cpu_clk;
stroese8c725b92004-12-16 18:09:49 +000085#endif
TsiChung Lieweec567a2008-08-19 03:01:19 +060086
87#ifdef CONFIG_FSL_I2C
88 gd->i2c1_clk = gd->bus_clk;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020089#ifdef CONFIG_SYS_I2C2_OFFSET
TsiChung Lieweec567a2008-08-19 03:01:19 +060090 gd->i2c2_clk = gd->bus_clk;
91#endif
92#endif
93
wdenkbf9e3b32004-02-12 00:47:09 +000094 return (0);
wdenk4e5ca3e2003-12-08 01:34:36 +000095}