wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 1 | /* |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 2 | * (C) Copyright 2003 |
| 3 | * Josef Baumgartner <josef.baumgartner@telex.de> |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 4 | * |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame^] | 5 | * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc. |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 6 | * Hayden Fraser (Hayden.Fraser@freescale.com) |
| 7 | * |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <asm/processor.h> |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 29 | #include <asm/immap.h> |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame^] | 30 | #include <asm/io.h> |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 31 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
TsiChung Liew | b354aef | 2009-06-12 11:29:00 +0000 | [diff] [blame] | 34 | /* get_clocks() fills in gd->cpu_clock and gd->bus_clk */ |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 35 | int get_clocks (void) |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 36 | { |
TsiChung Liew | b354aef | 2009-06-12 11:29:00 +0000 | [diff] [blame] | 37 | #if defined(CONFIG_M5208) |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame^] | 38 | pll_t *pll = (pll_t *) MMAP_PLL; |
TsiChung Liew | b354aef | 2009-06-12 11:29:00 +0000 | [diff] [blame] | 39 | |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame^] | 40 | out_8(&pll->odr, CONFIG_SYS_PLL_ODR); |
| 41 | out_8(&pll->fdr, CONFIG_SYS_PLL_FDR); |
TsiChung Liew | b354aef | 2009-06-12 11:29:00 +0000 | [diff] [blame] | 42 | #endif |
| 43 | |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 44 | #if defined(CONFIG_M5249) || defined(CONFIG_M5253) |
| 45 | volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR); |
| 46 | unsigned long pllcr; |
| 47 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 48 | #ifndef CONFIG_SYS_PLL_BYPASS |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 49 | |
stroese | 53395a2 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 50 | #ifdef CONFIG_M5249 |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 51 | /* Setup the PLL to run at the specified speed */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 52 | #ifdef CONFIG_SYS_FAST_CLK |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 53 | pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */ |
| 54 | #else |
| 55 | pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */ |
| 56 | #endif |
| 57 | #endif /* CONFIG_M5249 */ |
| 58 | |
| 59 | #ifdef CONFIG_M5253 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 60 | pllcr = CONFIG_SYS_PLLCR; |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 61 | #endif /* CONFIG_M5253 */ |
| 62 | |
| 63 | cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */ |
| 64 | mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */ |
| 65 | mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */ |
| 66 | pllcr ^= 0x00000001; /* Set pll bypass to 1 */ |
| 67 | mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */ |
| 68 | udelay(0x20); /* Wait for a lock ... */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 69 | #endif /* #ifndef CONFIG_SYS_PLL_BYPASS */ |
TsiChungLiew | 3467469 | 2007-08-16 13:20:50 -0500 | [diff] [blame] | 70 | |
| 71 | #endif /* CONFIG_M5249 || CONFIG_M5253 */ |
| 72 | |
Matthew Fettke | 761e2e9 | 2008-02-04 15:38:20 -0600 | [diff] [blame] | 73 | #if defined(CONFIG_M5275) |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame^] | 74 | pll_t *pll = (pll_t *)(MMAP_PLL); |
Matthew Fettke | 761e2e9 | 2008-02-04 15:38:20 -0600 | [diff] [blame] | 75 | |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 76 | /* Setup PLL */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame^] | 77 | out_be32(&pll->syncr, 0x01080000); |
| 78 | while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK)) |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 79 | ; |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame^] | 80 | out_be32(&pll->syncr, 0x01000000); |
| 81 | while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK)) |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 82 | ; |
Matthew Fettke | 761e2e9 | 2008-02-04 15:38:20 -0600 | [diff] [blame] | 83 | #endif |
| 84 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 85 | gd->cpu_clk = CONFIG_SYS_CLK; |
TsiChung Liew | b354aef | 2009-06-12 11:29:00 +0000 | [diff] [blame] | 86 | #if defined(CONFIG_M5208) || defined(CONFIG_M5249) || defined(CONFIG_M5253) || \ |
Richard Retanubun | 8731764 | 2009-01-23 09:27:00 -0500 | [diff] [blame] | 87 | defined(CONFIG_M5271) || defined(CONFIG_M5275) |
stroese | 53395a2 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 88 | gd->bus_clk = gd->cpu_clk / 2; |
| 89 | #else |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 90 | gd->bus_clk = gd->cpu_clk; |
stroese | 53395a2 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 91 | #endif |
TsiChung Liew | 0c1e325 | 2008-08-19 03:01:19 +0600 | [diff] [blame] | 92 | |
| 93 | #ifdef CONFIG_FSL_I2C |
| 94 | gd->i2c1_clk = gd->bus_clk; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 95 | #ifdef CONFIG_SYS_I2C2_OFFSET |
TsiChung Liew | 0c1e325 | 2008-08-19 03:01:19 +0600 | [diff] [blame] | 96 | gd->i2c2_clk = gd->bus_clk; |
| 97 | #endif |
| 98 | #endif |
| 99 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 100 | return (0); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 101 | } |