blob: 0f274adf451a01f7e297b9b742fb7561642be3a5 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk4e5ca3e2003-12-08 01:34:36 +00002/*
wdenkbf9e3b32004-02-12 00:47:09 +00003 * (C) Copyright 2003
4 * Josef Baumgartner <josef.baumgartner@telex.de>
wdenk4e5ca3e2003-12-08 01:34:36 +00005 *
Alison Wang32dbaaf2012-03-26 21:49:04 +00006 * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiewa1436a82007-08-16 13:20:50 -05007 * Hayden Fraser (Hayden.Fraser@freescale.com)
wdenk4e5ca3e2003-12-08 01:34:36 +00008 */
9
10#include <common.h>
11#include <asm/processor.h>
TsiChungLiewa1436a82007-08-16 13:20:50 -050012#include <asm/immap.h>
Alison Wang32dbaaf2012-03-26 21:49:04 +000013#include <asm/io.h>
wdenk4e5ca3e2003-12-08 01:34:36 +000014
Wolfgang Denkd87080b2006-03-31 18:32:53 +020015DECLARE_GLOBAL_DATA_PTR;
16
TsiChung Liewbf9a5212009-06-12 11:29:00 +000017/* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
wdenkbf9e3b32004-02-12 00:47:09 +000018int get_clocks (void)
wdenk4e5ca3e2003-12-08 01:34:36 +000019{
TsiChung Liewbf9a5212009-06-12 11:29:00 +000020#if defined(CONFIG_M5208)
Alison Wang32dbaaf2012-03-26 21:49:04 +000021 pll_t *pll = (pll_t *) MMAP_PLL;
TsiChung Liewbf9a5212009-06-12 11:29:00 +000022
Alison Wang32dbaaf2012-03-26 21:49:04 +000023 out_8(&pll->odr, CONFIG_SYS_PLL_ODR);
24 out_8(&pll->fdr, CONFIG_SYS_PLL_FDR);
TsiChung Liewbf9a5212009-06-12 11:29:00 +000025#endif
26
TsiChungLiewa1436a82007-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-VILLARD6d0f6bc2008-10-16 15:01:15 +020031#ifndef CONFIG_SYS_PLL_BYPASS
TsiChungLiewa1436a82007-08-16 13:20:50 -050032
stroese8c725b92004-12-16 18:09:49 +000033#ifdef CONFIG_M5249
TsiChungLiewa1436a82007-08-16 13:20:50 -050034 /* Setup the PLL to run at the specified speed */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020035#ifdef CONFIG_SYS_FAST_CLK
TsiChungLiewa1436a82007-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-VILLARD6d0f6bc2008-10-16 15:01:15 +020043 pllcr = CONFIG_SYS_PLLCR;
TsiChungLiewa1436a82007-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-VILLARD6d0f6bc2008-10-16 15:01:15 +020052#endif /* #ifndef CONFIG_SYS_PLL_BYPASS */
TsiChungLiewa1436a82007-08-16 13:20:50 -050053
54#endif /* CONFIG_M5249 || CONFIG_M5253 */
55
Matthew Fettkef71d9d92008-02-04 15:38:20 -060056#if defined(CONFIG_M5275)
Alison Wang32dbaaf2012-03-26 21:49:04 +000057 pll_t *pll = (pll_t *)(MMAP_PLL);
Matthew Fettkef71d9d92008-02-04 15:38:20 -060058
Wolfgang Denk1aeed8d2008-04-13 09:59:26 -070059 /* Setup PLL */
Alison Wang32dbaaf2012-03-26 21:49:04 +000060 out_be32(&pll->syncr, 0x01080000);
61 while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
Wolfgang Denk1aeed8d2008-04-13 09:59:26 -070062 ;
Alison Wang32dbaaf2012-03-26 21:49:04 +000063 out_be32(&pll->syncr, 0x01000000);
64 while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
Wolfgang Denk1aeed8d2008-04-13 09:59:26 -070065 ;
Matthew Fettkef71d9d92008-02-04 15:38:20 -060066#endif
67
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020068 gd->cpu_clk = CONFIG_SYS_CLK;
TsiChung Liewbf9a5212009-06-12 11:29:00 +000069#if defined(CONFIG_M5208) || defined(CONFIG_M5249) || defined(CONFIG_M5253) || \
Richard Retanubun4ffc3902009-01-23 09:27:00 -050070 defined(CONFIG_M5271) || defined(CONFIG_M5275)
stroese8c725b92004-12-16 18:09:49 +000071 gd->bus_clk = gd->cpu_clk / 2;
72#else
wdenkbf9e3b32004-02-12 00:47:09 +000073 gd->bus_clk = gd->cpu_clk;
stroese8c725b92004-12-16 18:09:49 +000074#endif
TsiChung Lieweec567a2008-08-19 03:01:19 +060075
Heiko Schocher00f792e2012-10-24 13:48:22 +020076#ifdef CONFIG_SYS_I2C_FSL
Simon Glass609e6ec2012-12-13 20:48:49 +000077 gd->arch.i2c1_clk = gd->bus_clk;
Heiko Schocher00f792e2012-10-24 13:48:22 +020078#ifdef CONFIG_SYS_I2C2_FSL_OFFSET
Simon Glass609e6ec2012-12-13 20:48:49 +000079 gd->arch.i2c2_clk = gd->bus_clk;
TsiChung Lieweec567a2008-08-19 03:01:19 +060080#endif
81#endif
82
wdenkbf9e3b32004-02-12 00:47:09 +000083 return (0);
wdenk4e5ca3e2003-12-08 01:34:36 +000084}