blob: 6c7628252b5945046f292b9df67eb2d07ba568d7 [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
wdenkabf7a7c2003-12-08 01:34:36 +000013#include <asm/processor.h>
TsiChungLiew34674692007-08-16 13:20:50 -050014#include <asm/immap.h>
Alison Wang95bed1f2012-03-26 21:49:04 +000015#include <asm/io.h>
Simon Glassdbd79542020-05-10 11:40:11 -060016#include <linux/delay.h>
wdenkabf7a7c2003-12-08 01:34:36 +000017
Wolfgang Denk6405a152006-03-31 18:32:53 +020018DECLARE_GLOBAL_DATA_PTR;
19
TsiChung Liewb354aef2009-06-12 11:29:00 +000020/* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
Simon Glass85d65312019-12-28 10:44:58 -070021int get_clocks(void)
wdenkabf7a7c2003-12-08 01:34:36 +000022{
TsiChung Liewb354aef2009-06-12 11:29:00 +000023#if defined(CONFIG_M5208)
Alison Wang95bed1f2012-03-26 21:49:04 +000024 pll_t *pll = (pll_t *) MMAP_PLL;
TsiChung Liewb354aef2009-06-12 11:29:00 +000025
Tom Rini6a5dccc2022-11-16 13:10:41 -050026 out_8(&pll->odr, CFG_SYS_PLL_ODR);
27 out_8(&pll->fdr, CFG_SYS_PLL_FDR);
TsiChung Liewb354aef2009-06-12 11:29:00 +000028#endif
29
TsiChungLiew34674692007-08-16 13:20:50 -050030#if defined(CONFIG_M5249) || defined(CONFIG_M5253)
31 volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
32 unsigned long pllcr;
33
Tom Rini6a5dccc2022-11-16 13:10:41 -050034#ifndef CFG_SYS_PLL_BYPASS
TsiChungLiew34674692007-08-16 13:20:50 -050035
stroese53395a22004-12-16 18:09:49 +000036#ifdef CONFIG_M5249
TsiChungLiew34674692007-08-16 13:20:50 -050037 /* Setup the PLL to run at the specified speed */
Tom Rini6a5dccc2022-11-16 13:10:41 -050038#ifdef CFG_SYS_FAST_CLK
TsiChungLiew34674692007-08-16 13:20:50 -050039 pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
40#else
41 pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
42#endif
43#endif /* CONFIG_M5249 */
44
45#ifdef CONFIG_M5253
Tom Rini6a5dccc2022-11-16 13:10:41 -050046 pllcr = CFG_SYS_PLLCR;
TsiChungLiew34674692007-08-16 13:20:50 -050047#endif /* CONFIG_M5253 */
48
49 cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
50 mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
51 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
52 pllcr ^= 0x00000001; /* Set pll bypass to 1 */
53 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
54 udelay(0x20); /* Wait for a lock ... */
Tom Rini6a5dccc2022-11-16 13:10:41 -050055#endif /* #ifndef CFG_SYS_PLL_BYPASS */
TsiChungLiew34674692007-08-16 13:20:50 -050056
57#endif /* CONFIG_M5249 || CONFIG_M5253 */
58
Matthew Fettke761e2e92008-02-04 15:38:20 -060059#if defined(CONFIG_M5275)
Alison Wang95bed1f2012-03-26 21:49:04 +000060 pll_t *pll = (pll_t *)(MMAP_PLL);
Matthew Fettke761e2e92008-02-04 15:38:20 -060061
Wolfgang Denk35f734f2008-04-13 09:59:26 -070062 /* Setup PLL */
Alison Wang95bed1f2012-03-26 21:49:04 +000063 out_be32(&pll->syncr, 0x01080000);
64 while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
Wolfgang Denk35f734f2008-04-13 09:59:26 -070065 ;
Alison Wang95bed1f2012-03-26 21:49:04 +000066 out_be32(&pll->syncr, 0x01000000);
67 while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
Wolfgang Denk35f734f2008-04-13 09:59:26 -070068 ;
Matthew Fettke761e2e92008-02-04 15:38:20 -060069#endif
70
Tom Rini6a5dccc2022-11-16 13:10:41 -050071 gd->cpu_clk = CFG_SYS_CLK;
TsiChung Liewb354aef2009-06-12 11:29:00 +000072#if defined(CONFIG_M5208) || defined(CONFIG_M5249) || defined(CONFIG_M5253) || \
Richard Retanubun87317642009-01-23 09:27:00 -050073 defined(CONFIG_M5271) || defined(CONFIG_M5275)
stroese53395a22004-12-16 18:09:49 +000074 gd->bus_clk = gd->cpu_clk / 2;
75#else
wdenke65527f2004-02-12 00:47:09 +000076 gd->bus_clk = gd->cpu_clk;
stroese53395a22004-12-16 18:09:49 +000077#endif
TsiChung Liew0c1e3252008-08-19 03:01:19 +060078
Heiko Schocherf2850742012-10-24 13:48:22 +020079#ifdef CONFIG_SYS_I2C_FSL
Simon Glassc2baaec2012-12-13 20:48:49 +000080 gd->arch.i2c1_clk = gd->bus_clk;
Heiko Schocherf2850742012-10-24 13:48:22 +020081#ifdef CONFIG_SYS_I2C2_FSL_OFFSET
Simon Glassc2baaec2012-12-13 20:48:49 +000082 gd->arch.i2c2_clk = gd->bus_clk;
TsiChung Liew0c1e3252008-08-19 03:01:19 +060083#endif
84#endif
85
wdenke65527f2004-02-12 00:47:09 +000086 return (0);
wdenkabf7a7c2003-12-08 01:34:36 +000087}