blob: c5961d45ecade055f6a6c41ed390883f7306cd57 [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 *
Alison Wang95bed1f2012-03-26 21:49:04 +00005 * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiew34674692007-08-16 13:20:50 -05006 * Hayden Fraser (Hayden.Fraser@freescale.com)
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenkabf7a7c2003-12-08 01:34:36 +00009 */
10
11#include <common.h>
12#include <asm/processor.h>
TsiChungLiew34674692007-08-16 13:20:50 -050013#include <asm/immap.h>
Alison Wang95bed1f2012-03-26 21:49:04 +000014#include <asm/io.h>
wdenkabf7a7c2003-12-08 01:34:36 +000015
Wolfgang Denk6405a152006-03-31 18:32:53 +020016DECLARE_GLOBAL_DATA_PTR;
17
TsiChung Liewb354aef2009-06-12 11:29:00 +000018/* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
wdenke65527f2004-02-12 00:47:09 +000019int get_clocks (void)
wdenkabf7a7c2003-12-08 01:34:36 +000020{
TsiChung Liewb354aef2009-06-12 11:29:00 +000021#if defined(CONFIG_M5208)
Alison Wang95bed1f2012-03-26 21:49:04 +000022 pll_t *pll = (pll_t *) MMAP_PLL;
TsiChung Liewb354aef2009-06-12 11:29:00 +000023
Alison Wang95bed1f2012-03-26 21:49:04 +000024 out_8(&pll->odr, CONFIG_SYS_PLL_ODR);
25 out_8(&pll->fdr, CONFIG_SYS_PLL_FDR);
TsiChung Liewb354aef2009-06-12 11:29:00 +000026#endif
27
TsiChungLiew34674692007-08-16 13:20:50 -050028#if defined(CONFIG_M5249) || defined(CONFIG_M5253)
29 volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
30 unsigned long pllcr;
31
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020032#ifndef CONFIG_SYS_PLL_BYPASS
TsiChungLiew34674692007-08-16 13:20:50 -050033
stroese53395a22004-12-16 18:09:49 +000034#ifdef CONFIG_M5249
TsiChungLiew34674692007-08-16 13:20:50 -050035 /* Setup the PLL to run at the specified speed */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020036#ifdef CONFIG_SYS_FAST_CLK
TsiChungLiew34674692007-08-16 13:20:50 -050037 pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
38#else
39 pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
40#endif
41#endif /* CONFIG_M5249 */
42
43#ifdef CONFIG_M5253
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020044 pllcr = CONFIG_SYS_PLLCR;
TsiChungLiew34674692007-08-16 13:20:50 -050045#endif /* CONFIG_M5253 */
46
47 cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
48 mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
49 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
50 pllcr ^= 0x00000001; /* Set pll bypass to 1 */
51 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
52 udelay(0x20); /* Wait for a lock ... */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020053#endif /* #ifndef CONFIG_SYS_PLL_BYPASS */
TsiChungLiew34674692007-08-16 13:20:50 -050054
55#endif /* CONFIG_M5249 || CONFIG_M5253 */
56
Matthew Fettke761e2e92008-02-04 15:38:20 -060057#if defined(CONFIG_M5275)
Alison Wang95bed1f2012-03-26 21:49:04 +000058 pll_t *pll = (pll_t *)(MMAP_PLL);
Matthew Fettke761e2e92008-02-04 15:38:20 -060059
Wolfgang Denk35f734f2008-04-13 09:59:26 -070060 /* Setup PLL */
Alison Wang95bed1f2012-03-26 21:49:04 +000061 out_be32(&pll->syncr, 0x01080000);
62 while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
Wolfgang Denk35f734f2008-04-13 09:59:26 -070063 ;
Alison Wang95bed1f2012-03-26 21:49:04 +000064 out_be32(&pll->syncr, 0x01000000);
65 while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
Wolfgang Denk35f734f2008-04-13 09:59:26 -070066 ;
Matthew Fettke761e2e92008-02-04 15:38:20 -060067#endif
68
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020069 gd->cpu_clk = CONFIG_SYS_CLK;
TsiChung Liewb354aef2009-06-12 11:29:00 +000070#if defined(CONFIG_M5208) || defined(CONFIG_M5249) || defined(CONFIG_M5253) || \
Richard Retanubun87317642009-01-23 09:27:00 -050071 defined(CONFIG_M5271) || defined(CONFIG_M5275)
stroese53395a22004-12-16 18:09:49 +000072 gd->bus_clk = gd->cpu_clk / 2;
73#else
wdenke65527f2004-02-12 00:47:09 +000074 gd->bus_clk = gd->cpu_clk;
stroese53395a22004-12-16 18:09:49 +000075#endif
TsiChung Liew0c1e3252008-08-19 03:01:19 +060076
Heiko Schocherf2850742012-10-24 13:48:22 +020077#ifdef CONFIG_SYS_I2C_FSL
Simon Glassc2baaec2012-12-13 20:48:49 +000078 gd->arch.i2c1_clk = gd->bus_clk;
Heiko Schocherf2850742012-10-24 13:48:22 +020079#ifdef CONFIG_SYS_I2C2_FSL_OFFSET
Simon Glassc2baaec2012-12-13 20:48:49 +000080 gd->arch.i2c2_clk = gd->bus_clk;
TsiChung Liew0c1e3252008-08-19 03:01:19 +060081#endif
82#endif
83
wdenke65527f2004-02-12 00:47:09 +000084 return (0);
wdenkabf7a7c2003-12-08 01:34:36 +000085}