Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 2 | /* |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 3 | * (C) Copyright 2003 |
| 4 | * Josef Baumgartner <josef.baumgartner@telex.de> |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 5 | * |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 6 | * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc. |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 7 | * Hayden Fraser (Hayden.Fraser@freescale.com) |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 85d6531 | 2019-12-28 10:44:58 -0700 | [diff] [blame] | 11 | #include <clock_legacy.h> |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 12 | #include <asm/processor.h> |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 13 | #include <asm/immap.h> |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 14 | #include <asm/io.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 15 | #include <linux/delay.h> |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 16 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
TsiChung Liew | b354aef | 2009-06-12 11:29:00 +0000 | [diff] [blame] | 19 | /* get_clocks() fills in gd->cpu_clock and gd->bus_clk */ |
Simon Glass | 85d6531 | 2019-12-28 10:44:58 -0700 | [diff] [blame] | 20 | int get_clocks(void) |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 21 | { |
TsiChung Liew | b354aef | 2009-06-12 11:29:00 +0000 | [diff] [blame] | 22 | #if defined(CONFIG_M5208) |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 23 | pll_t *pll = (pll_t *) MMAP_PLL; |
TsiChung Liew | b354aef | 2009-06-12 11:29:00 +0000 | [diff] [blame] | 24 | |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 25 | out_8(&pll->odr, CONFIG_SYS_PLL_ODR); |
| 26 | out_8(&pll->fdr, CONFIG_SYS_PLL_FDR); |
TsiChung Liew | b354aef | 2009-06-12 11:29:00 +0000 | [diff] [blame] | 27 | #endif |
| 28 | |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 29 | #if defined(CONFIG_M5249) || defined(CONFIG_M5253) |
| 30 | volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR); |
| 31 | unsigned long pllcr; |
| 32 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 33 | #ifndef CONFIG_SYS_PLL_BYPASS |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 34 | |
stroese | 53395a2 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 35 | #ifdef CONFIG_M5249 |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 36 | /* Setup the PLL to run at the specified speed */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 37 | #ifdef CONFIG_SYS_FAST_CLK |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 38 | 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-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 45 | pllcr = CONFIG_SYS_PLLCR; |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 46 | #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-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 54 | #endif /* #ifndef CONFIG_SYS_PLL_BYPASS */ |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 55 | |
| 56 | #endif /* CONFIG_M5249 || CONFIG_M5253 */ |
| 57 | |
Matthew Fettke | 761e2e9 | 2008-02-04 15:38:20 -0600 | [diff] [blame] | 58 | #if defined(CONFIG_M5275) |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 59 | pll_t *pll = (pll_t *)(MMAP_PLL); |
Matthew Fettke | 761e2e9 | 2008-02-04 15:38:20 -0600 | [diff] [blame] | 60 | |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 61 | /* Setup PLL */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 62 | out_be32(&pll->syncr, 0x01080000); |
| 63 | while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK)) |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 64 | ; |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 65 | out_be32(&pll->syncr, 0x01000000); |
| 66 | while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK)) |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 67 | ; |
Matthew Fettke | 761e2e9 | 2008-02-04 15:38:20 -0600 | [diff] [blame] | 68 | #endif |
| 69 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 70 | gd->cpu_clk = CONFIG_SYS_CLK; |
TsiChung Liew | b354aef | 2009-06-12 11:29:00 +0000 | [diff] [blame] | 71 | #if defined(CONFIG_M5208) || defined(CONFIG_M5249) || defined(CONFIG_M5253) || \ |
Richard Retanubun | 8731764 | 2009-01-23 09:27:00 -0500 | [diff] [blame] | 72 | defined(CONFIG_M5271) || defined(CONFIG_M5275) |
stroese | 53395a2 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 73 | gd->bus_clk = gd->cpu_clk / 2; |
| 74 | #else |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 75 | gd->bus_clk = gd->cpu_clk; |
stroese | 53395a2 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 76 | #endif |
TsiChung Liew | 0c1e325 | 2008-08-19 03:01:19 +0600 | [diff] [blame] | 77 | |
Heiko Schocher | f285074 | 2012-10-24 13:48:22 +0200 | [diff] [blame] | 78 | #ifdef CONFIG_SYS_I2C_FSL |
Simon Glass | c2baaec | 2012-12-13 20:48:49 +0000 | [diff] [blame] | 79 | gd->arch.i2c1_clk = gd->bus_clk; |
Heiko Schocher | f285074 | 2012-10-24 13:48:22 +0200 | [diff] [blame] | 80 | #ifdef CONFIG_SYS_I2C2_FSL_OFFSET |
Simon Glass | c2baaec | 2012-12-13 20:48:49 +0000 | [diff] [blame] | 81 | gd->arch.i2c2_clk = gd->bus_clk; |
TsiChung Liew | 0c1e325 | 2008-08-19 03:01:19 +0600 | [diff] [blame] | 82 | #endif |
| 83 | #endif |
| 84 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 85 | return (0); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 86 | } |