blob: ba7dbaa1cfc34a1cd4bb3dad218d1deec893e6e2 [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 *
Alison Wang32dbaaf2012-03-26 21:49:04 +00005 * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiewa1436a82007-08-16 13:20:50 -05006 * 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>
Alison Wang32dbaaf2012-03-26 21:49:04 +000030#include <asm/io.h>
wdenk4e5ca3e2003-12-08 01:34:36 +000031
Wolfgang Denkd87080b2006-03-31 18:32:53 +020032DECLARE_GLOBAL_DATA_PTR;
33
TsiChung Liewbf9a5212009-06-12 11:29:00 +000034/* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
wdenkbf9e3b32004-02-12 00:47:09 +000035int get_clocks (void)
wdenk4e5ca3e2003-12-08 01:34:36 +000036{
TsiChung Liewbf9a5212009-06-12 11:29:00 +000037#if defined(CONFIG_M5208)
Alison Wang32dbaaf2012-03-26 21:49:04 +000038 pll_t *pll = (pll_t *) MMAP_PLL;
TsiChung Liewbf9a5212009-06-12 11:29:00 +000039
Alison Wang32dbaaf2012-03-26 21:49:04 +000040 out_8(&pll->odr, CONFIG_SYS_PLL_ODR);
41 out_8(&pll->fdr, CONFIG_SYS_PLL_FDR);
TsiChung Liewbf9a5212009-06-12 11:29:00 +000042#endif
43
TsiChungLiewa1436a82007-08-16 13:20:50 -050044#if defined(CONFIG_M5249) || defined(CONFIG_M5253)
45 volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
46 unsigned long pllcr;
47
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020048#ifndef CONFIG_SYS_PLL_BYPASS
TsiChungLiewa1436a82007-08-16 13:20:50 -050049
stroese8c725b92004-12-16 18:09:49 +000050#ifdef CONFIG_M5249
TsiChungLiewa1436a82007-08-16 13:20:50 -050051 /* Setup the PLL to run at the specified speed */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020052#ifdef CONFIG_SYS_FAST_CLK
TsiChungLiewa1436a82007-08-16 13:20:50 -050053 pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
54#else
55 pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
56#endif
57#endif /* CONFIG_M5249 */
58
59#ifdef CONFIG_M5253
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020060 pllcr = CONFIG_SYS_PLLCR;
TsiChungLiewa1436a82007-08-16 13:20:50 -050061#endif /* CONFIG_M5253 */
62
63 cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
64 mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
65 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
66 pllcr ^= 0x00000001; /* Set pll bypass to 1 */
67 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
68 udelay(0x20); /* Wait for a lock ... */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020069#endif /* #ifndef CONFIG_SYS_PLL_BYPASS */
TsiChungLiewa1436a82007-08-16 13:20:50 -050070
71#endif /* CONFIG_M5249 || CONFIG_M5253 */
72
Matthew Fettkef71d9d92008-02-04 15:38:20 -060073#if defined(CONFIG_M5275)
Alison Wang32dbaaf2012-03-26 21:49:04 +000074 pll_t *pll = (pll_t *)(MMAP_PLL);
Matthew Fettkef71d9d92008-02-04 15:38:20 -060075
Wolfgang Denk1aeed8d2008-04-13 09:59:26 -070076 /* Setup PLL */
Alison Wang32dbaaf2012-03-26 21:49:04 +000077 out_be32(&pll->syncr, 0x01080000);
78 while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
Wolfgang Denk1aeed8d2008-04-13 09:59:26 -070079 ;
Alison Wang32dbaaf2012-03-26 21:49:04 +000080 out_be32(&pll->syncr, 0x01000000);
81 while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
Wolfgang Denk1aeed8d2008-04-13 09:59:26 -070082 ;
Matthew Fettkef71d9d92008-02-04 15:38:20 -060083#endif
84
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020085 gd->cpu_clk = CONFIG_SYS_CLK;
TsiChung Liewbf9a5212009-06-12 11:29:00 +000086#if defined(CONFIG_M5208) || defined(CONFIG_M5249) || defined(CONFIG_M5253) || \
Richard Retanubun4ffc3902009-01-23 09:27:00 -050087 defined(CONFIG_M5271) || defined(CONFIG_M5275)
stroese8c725b92004-12-16 18:09:49 +000088 gd->bus_clk = gd->cpu_clk / 2;
89#else
wdenkbf9e3b32004-02-12 00:47:09 +000090 gd->bus_clk = gd->cpu_clk;
stroese8c725b92004-12-16 18:09:49 +000091#endif
TsiChung Lieweec567a2008-08-19 03:01:19 +060092
93#ifdef CONFIG_FSL_I2C
Simon Glass609e6ec2012-12-13 20:48:49 +000094 gd->arch.i2c1_clk = gd->bus_clk;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020095#ifdef CONFIG_SYS_I2C2_OFFSET
Simon Glass609e6ec2012-12-13 20:48:49 +000096 gd->arch.i2c2_clk = gd->bus_clk;
TsiChung Lieweec567a2008-08-19 03:01:19 +060097#endif
98#endif
99
wdenkbf9e3b32004-02-12 00:47:09 +0000100 return (0);
wdenk4e5ca3e2003-12-08 01:34:36 +0000101}