blob: 751c83a4fc0873342378410b4f64590e39564f8b [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>
Simon Glass85d65312019-12-28 10:44:58 -070011#include <clock_legacy.h>
wdenkabf7a7c2003-12-08 01:34:36 +000012#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>
Simon Glassdbd79542020-05-10 11:40:11 -060015#include <linux/delay.h>
wdenkabf7a7c2003-12-08 01:34:36 +000016
Wolfgang Denk6405a152006-03-31 18:32:53 +020017DECLARE_GLOBAL_DATA_PTR;
18
TsiChung Liewb354aef2009-06-12 11:29:00 +000019/* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
Simon Glass85d65312019-12-28 10:44:58 -070020int get_clocks(void)
wdenkabf7a7c2003-12-08 01:34:36 +000021{
TsiChung Liewb354aef2009-06-12 11:29:00 +000022#if defined(CONFIG_M5208)
Alison Wang95bed1f2012-03-26 21:49:04 +000023 pll_t *pll = (pll_t *) MMAP_PLL;
TsiChung Liewb354aef2009-06-12 11:29:00 +000024
Alison Wang95bed1f2012-03-26 21:49:04 +000025 out_8(&pll->odr, CONFIG_SYS_PLL_ODR);
26 out_8(&pll->fdr, CONFIG_SYS_PLL_FDR);
TsiChung Liewb354aef2009-06-12 11:29:00 +000027#endif
28
TsiChungLiew34674692007-08-16 13:20:50 -050029#if defined(CONFIG_M5249) || defined(CONFIG_M5253)
30 volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
31 unsigned long pllcr;
32
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020033#ifndef CONFIG_SYS_PLL_BYPASS
TsiChungLiew34674692007-08-16 13:20:50 -050034
stroese53395a22004-12-16 18:09:49 +000035#ifdef CONFIG_M5249
TsiChungLiew34674692007-08-16 13:20:50 -050036 /* Setup the PLL to run at the specified speed */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020037#ifdef CONFIG_SYS_FAST_CLK
TsiChungLiew34674692007-08-16 13:20:50 -050038 pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
39#else
40 pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
41#endif
42#endif /* CONFIG_M5249 */
43
44#ifdef CONFIG_M5253
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020045 pllcr = CONFIG_SYS_PLLCR;
TsiChungLiew34674692007-08-16 13:20:50 -050046#endif /* CONFIG_M5253 */
47
48 cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
49 mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
50 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
51 pllcr ^= 0x00000001; /* Set pll bypass to 1 */
52 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
53 udelay(0x20); /* Wait for a lock ... */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020054#endif /* #ifndef CONFIG_SYS_PLL_BYPASS */
TsiChungLiew34674692007-08-16 13:20:50 -050055
56#endif /* CONFIG_M5249 || CONFIG_M5253 */
57
Matthew Fettke761e2e92008-02-04 15:38:20 -060058#if defined(CONFIG_M5275)
Alison Wang95bed1f2012-03-26 21:49:04 +000059 pll_t *pll = (pll_t *)(MMAP_PLL);
Matthew Fettke761e2e92008-02-04 15:38:20 -060060
Wolfgang Denk35f734f2008-04-13 09:59:26 -070061 /* Setup PLL */
Alison Wang95bed1f2012-03-26 21:49:04 +000062 out_be32(&pll->syncr, 0x01080000);
63 while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
Wolfgang Denk35f734f2008-04-13 09:59:26 -070064 ;
Alison Wang95bed1f2012-03-26 21:49:04 +000065 out_be32(&pll->syncr, 0x01000000);
66 while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
Wolfgang Denk35f734f2008-04-13 09:59:26 -070067 ;
Matthew Fettke761e2e92008-02-04 15:38:20 -060068#endif
69
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020070 gd->cpu_clk = CONFIG_SYS_CLK;
TsiChung Liewb354aef2009-06-12 11:29:00 +000071#if defined(CONFIG_M5208) || defined(CONFIG_M5249) || defined(CONFIG_M5253) || \
Richard Retanubun87317642009-01-23 09:27:00 -050072 defined(CONFIG_M5271) || defined(CONFIG_M5275)
stroese53395a22004-12-16 18:09:49 +000073 gd->bus_clk = gd->cpu_clk / 2;
74#else
wdenke65527f2004-02-12 00:47:09 +000075 gd->bus_clk = gd->cpu_clk;
stroese53395a22004-12-16 18:09:49 +000076#endif
TsiChung Liew0c1e3252008-08-19 03:01:19 +060077
Heiko Schocherf2850742012-10-24 13:48:22 +020078#ifdef CONFIG_SYS_I2C_FSL
Simon Glassc2baaec2012-12-13 20:48:49 +000079 gd->arch.i2c1_clk = gd->bus_clk;
Heiko Schocherf2850742012-10-24 13:48:22 +020080#ifdef CONFIG_SYS_I2C2_FSL_OFFSET
Simon Glassc2baaec2012-12-13 20:48:49 +000081 gd->arch.i2c2_clk = gd->bus_clk;
TsiChung Liew0c1e3252008-08-19 03:01:19 +060082#endif
83#endif
84
wdenke65527f2004-02-12 00:47:09 +000085 return (0);
wdenkabf7a7c2003-12-08 01:34:36 +000086}