blob: 0f274adf451a01f7e297b9b742fb7561642be3a5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkabf7a7c2003-12-08 01:34:36 +00002/*
wdenke65527f2004-02-12 00:47:09 +00003 * (C) Copyright 2003
4 * Josef Baumgartner <josef.baumgartner@telex.de>
wdenkabf7a7c2003-12-08 01:34:36 +00005 *
Alison Wang95bed1f2012-03-26 21:49:04 +00006 * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiew34674692007-08-16 13:20:50 -05007 * Hayden Fraser (Hayden.Fraser@freescale.com)
wdenkabf7a7c2003-12-08 01:34:36 +00008 */
9
10#include <common.h>
11#include <asm/processor.h>
TsiChungLiew34674692007-08-16 13:20:50 -050012#include <asm/immap.h>
Alison Wang95bed1f2012-03-26 21:49:04 +000013#include <asm/io.h>
wdenkabf7a7c2003-12-08 01:34:36 +000014
Wolfgang Denk6405a152006-03-31 18:32:53 +020015DECLARE_GLOBAL_DATA_PTR;
16
TsiChung Liewb354aef2009-06-12 11:29:00 +000017/* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
wdenke65527f2004-02-12 00:47:09 +000018int get_clocks (void)
wdenkabf7a7c2003-12-08 01:34:36 +000019{
TsiChung Liewb354aef2009-06-12 11:29:00 +000020#if defined(CONFIG_M5208)
Alison Wang95bed1f2012-03-26 21:49:04 +000021 pll_t *pll = (pll_t *) MMAP_PLL;
TsiChung Liewb354aef2009-06-12 11:29:00 +000022
Alison Wang95bed1f2012-03-26 21:49:04 +000023 out_8(&pll->odr, CONFIG_SYS_PLL_ODR);
24 out_8(&pll->fdr, CONFIG_SYS_PLL_FDR);
TsiChung Liewb354aef2009-06-12 11:29:00 +000025#endif
26
TsiChungLiew34674692007-08-16 13:20:50 -050027#if defined(CONFIG_M5249) || defined(CONFIG_M5253)
28 volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
29 unsigned long pllcr;
30
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020031#ifndef CONFIG_SYS_PLL_BYPASS
TsiChungLiew34674692007-08-16 13:20:50 -050032
stroese53395a22004-12-16 18:09:49 +000033#ifdef CONFIG_M5249
TsiChungLiew34674692007-08-16 13:20:50 -050034 /* Setup the PLL to run at the specified speed */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020035#ifdef CONFIG_SYS_FAST_CLK
TsiChungLiew34674692007-08-16 13:20:50 -050036 pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
37#else
38 pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
39#endif
40#endif /* CONFIG_M5249 */
41
42#ifdef CONFIG_M5253
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020043 pllcr = CONFIG_SYS_PLLCR;
TsiChungLiew34674692007-08-16 13:20:50 -050044#endif /* CONFIG_M5253 */
45
46 cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
47 mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
48 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
49 pllcr ^= 0x00000001; /* Set pll bypass to 1 */
50 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
51 udelay(0x20); /* Wait for a lock ... */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020052#endif /* #ifndef CONFIG_SYS_PLL_BYPASS */
TsiChungLiew34674692007-08-16 13:20:50 -050053
54#endif /* CONFIG_M5249 || CONFIG_M5253 */
55
Matthew Fettke761e2e92008-02-04 15:38:20 -060056#if defined(CONFIG_M5275)
Alison Wang95bed1f2012-03-26 21:49:04 +000057 pll_t *pll = (pll_t *)(MMAP_PLL);
Matthew Fettke761e2e92008-02-04 15:38:20 -060058
Wolfgang Denk35f734f2008-04-13 09:59:26 -070059 /* Setup PLL */
Alison Wang95bed1f2012-03-26 21:49:04 +000060 out_be32(&pll->syncr, 0x01080000);
61 while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
Wolfgang Denk35f734f2008-04-13 09:59:26 -070062 ;
Alison Wang95bed1f2012-03-26 21:49:04 +000063 out_be32(&pll->syncr, 0x01000000);
64 while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
Wolfgang Denk35f734f2008-04-13 09:59:26 -070065 ;
Matthew Fettke761e2e92008-02-04 15:38:20 -060066#endif
67
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020068 gd->cpu_clk = CONFIG_SYS_CLK;
TsiChung Liewb354aef2009-06-12 11:29:00 +000069#if defined(CONFIG_M5208) || defined(CONFIG_M5249) || defined(CONFIG_M5253) || \
Richard Retanubun87317642009-01-23 09:27:00 -050070 defined(CONFIG_M5271) || defined(CONFIG_M5275)
stroese53395a22004-12-16 18:09:49 +000071 gd->bus_clk = gd->cpu_clk / 2;
72#else
wdenke65527f2004-02-12 00:47:09 +000073 gd->bus_clk = gd->cpu_clk;
stroese53395a22004-12-16 18:09:49 +000074#endif
TsiChung Liew0c1e3252008-08-19 03:01:19 +060075
Heiko Schocherf2850742012-10-24 13:48:22 +020076#ifdef CONFIG_SYS_I2C_FSL
Simon Glassc2baaec2012-12-13 20:48:49 +000077 gd->arch.i2c1_clk = gd->bus_clk;
Heiko Schocherf2850742012-10-24 13:48:22 +020078#ifdef CONFIG_SYS_I2C2_FSL_OFFSET
Simon Glassc2baaec2012-12-13 20:48:49 +000079 gd->arch.i2c2_clk = gd->bus_clk;
TsiChung Liew0c1e3252008-08-19 03:01:19 +060080#endif
81#endif
82
wdenke65527f2004-02-12 00:47:09 +000083 return (0);
wdenkabf7a7c2003-12-08 01:34:36 +000084}