blob: 538e4c623d42557332614602b665287d01e480af [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
Simon Glass85d65312019-12-28 10:44:58 -070010#include <clock_legacy.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.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
Tom Rini6a5dccc2022-11-16 13:10:41 -050025 out_8(&pll->odr, CFG_SYS_PLL_ODR);
26 out_8(&pll->fdr, CFG_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
Tom Rini6a5dccc2022-11-16 13:10:41 -050033#ifndef CFG_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 */
Tom Rini6a5dccc2022-11-16 13:10:41 -050037#ifdef CFG_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
Tom Rini6a5dccc2022-11-16 13:10:41 -050045 pllcr = CFG_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 ... */
Tom Rini6a5dccc2022-11-16 13:10:41 -050054#endif /* #ifndef CFG_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
Tom Rini6a5dccc2022-11-16 13:10:41 -050070 gd->cpu_clk = CFG_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}