blob: b485e1cccc129516c50acb3080bd1ec006f04762 [file] [log] [blame]
wdenkabf7a7c2003-12-08 01:34:36 +00001/*
wdenke65527f2004-02-12 00:47:09 +00002 * (C) Copyright 2003
3 * Josef Baumgartner <josef.baumgartner@telex.de>
wdenkabf7a7c2003-12-08 01:34:36 +00004 *
TsiChungLiew34674692007-08-16 13:20:50 -05005 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
6 * Hayden Fraser (Hayden.Fraser@freescale.com)
7 *
wdenkabf7a7c2003-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>
TsiChungLiew34674692007-08-16 13:20:50 -050029#include <asm/immap.h>
wdenkabf7a7c2003-12-08 01:34:36 +000030
Wolfgang Denk6405a152006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
32
TsiChung Liewb354aef2009-06-12 11:29:00 +000033/* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
wdenke65527f2004-02-12 00:47:09 +000034int get_clocks (void)
wdenkabf7a7c2003-12-08 01:34:36 +000035{
TsiChung Liewb354aef2009-06-12 11:29:00 +000036#if defined(CONFIG_M5208)
37 volatile pll_t *pll = (pll_t *) MMAP_PLL;
38
39 pll->odr = CONFIG_SYS_PLL_ODR;
40 pll->fdr = CONFIG_SYS_PLL_FDR;
41#endif
42
TsiChungLiew34674692007-08-16 13:20:50 -050043#if defined(CONFIG_M5249) || defined(CONFIG_M5253)
44 volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
45 unsigned long pllcr;
46
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020047#ifndef CONFIG_SYS_PLL_BYPASS
TsiChungLiew34674692007-08-16 13:20:50 -050048
stroese53395a22004-12-16 18:09:49 +000049#ifdef CONFIG_M5249
TsiChungLiew34674692007-08-16 13:20:50 -050050 /* Setup the PLL to run at the specified speed */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020051#ifdef CONFIG_SYS_FAST_CLK
TsiChungLiew34674692007-08-16 13:20:50 -050052 pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
53#else
54 pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
55#endif
56#endif /* CONFIG_M5249 */
57
58#ifdef CONFIG_M5253
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020059 pllcr = CONFIG_SYS_PLLCR;
TsiChungLiew34674692007-08-16 13:20:50 -050060#endif /* CONFIG_M5253 */
61
62 cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
63 mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
64 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
65 pllcr ^= 0x00000001; /* Set pll bypass to 1 */
66 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
67 udelay(0x20); /* Wait for a lock ... */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020068#endif /* #ifndef CONFIG_SYS_PLL_BYPASS */
TsiChungLiew34674692007-08-16 13:20:50 -050069
70#endif /* CONFIG_M5249 || CONFIG_M5253 */
71
Matthew Fettke761e2e92008-02-04 15:38:20 -060072#if defined(CONFIG_M5275)
73 volatile pll_t *pll = (volatile pll_t *)(MMAP_PLL);
74
Wolfgang Denk35f734f2008-04-13 09:59:26 -070075 /* Setup PLL */
76 pll->syncr = 0x01080000;
TsiChung Liew7d129382008-06-18 19:19:07 -050077 while (!(pll->synsr & FMPLL_SYNSR_LOCK))
Wolfgang Denk35f734f2008-04-13 09:59:26 -070078 ;
79 pll->syncr = 0x01000000;
80 while (!(pll->synsr & FMPLL_SYNSR_LOCK))
81 ;
Matthew Fettke761e2e92008-02-04 15:38:20 -060082#endif
83
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020084 gd->cpu_clk = CONFIG_SYS_CLK;
TsiChung Liewb354aef2009-06-12 11:29:00 +000085#if defined(CONFIG_M5208) || defined(CONFIG_M5249) || defined(CONFIG_M5253) || \
Richard Retanubun87317642009-01-23 09:27:00 -050086 defined(CONFIG_M5271) || defined(CONFIG_M5275)
stroese53395a22004-12-16 18:09:49 +000087 gd->bus_clk = gd->cpu_clk / 2;
88#else
wdenke65527f2004-02-12 00:47:09 +000089 gd->bus_clk = gd->cpu_clk;
stroese53395a22004-12-16 18:09:49 +000090#endif
TsiChung Liew0c1e3252008-08-19 03:01:19 +060091
92#ifdef CONFIG_FSL_I2C
93 gd->i2c1_clk = gd->bus_clk;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020094#ifdef CONFIG_SYS_I2C2_OFFSET
TsiChung Liew0c1e3252008-08-19 03:01:19 +060095 gd->i2c2_clk = gd->bus_clk;
96#endif
97#endif
98
wdenke65527f2004-02-12 00:47:09 +000099 return (0);
wdenkabf7a7c2003-12-08 01:34:36 +0000100}