TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 1 | /* |
| 2 | * |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 3 | * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc. |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 4 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <common.h> |
| 26 | #include <asm/processor.h> |
| 27 | |
| 28 | #include <asm/immap.h> |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 29 | #include <asm/io.h> |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 30 | |
| 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
| 33 | /* |
| 34 | * Low Power Divider specifications |
| 35 | */ |
| 36 | #define CLOCK_LPD_MIN (1 << 0) /* Divider (decoded) */ |
| 37 | #define CLOCK_LPD_MAX (1 << 15) /* Divider (decoded) */ |
| 38 | |
| 39 | #define CLOCK_PLL_FVCO_MAX 540000000 |
| 40 | #define CLOCK_PLL_FVCO_MIN 300000000 |
| 41 | |
| 42 | #define CLOCK_PLL_FSYS_MAX 266666666 |
| 43 | #define CLOCK_PLL_FSYS_MIN 100000000 |
| 44 | #define MHZ 1000000 |
| 45 | |
| 46 | void clock_enter_limp(int lpdiv) |
| 47 | { |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 48 | ccm_t *ccm = (ccm_t *)MMAP_CCM; |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 49 | int i, j; |
| 50 | |
| 51 | /* Check bounds of divider */ |
| 52 | if (lpdiv < CLOCK_LPD_MIN) |
| 53 | lpdiv = CLOCK_LPD_MIN; |
| 54 | if (lpdiv > CLOCK_LPD_MAX) |
| 55 | lpdiv = CLOCK_LPD_MAX; |
| 56 | |
| 57 | /* Round divider down to nearest power of two */ |
| 58 | for (i = 0, j = lpdiv; j != 1; j >>= 1, i++) ; |
| 59 | |
| 60 | /* Apply the divider to the system clock */ |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 61 | clrsetbits_be16(&ccm->cdr, 0x0f00, CCM_CDR_LPDIV(i)); |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 62 | |
| 63 | /* Enable Limp Mode */ |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 64 | setbits_be16(&ccm->misccr, CCM_MISCCR_LIMP); |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /* |
| 68 | * brief Exit Limp mode |
| 69 | * warning The PLL should be set and locked prior to exiting Limp mode |
| 70 | */ |
| 71 | void clock_exit_limp(void) |
| 72 | { |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 73 | ccm_t *ccm = (ccm_t *)MMAP_CCM; |
| 74 | pll_t *pll = (pll_t *)MMAP_PLL; |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 75 | |
| 76 | /* Exit Limp mode */ |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 77 | clrbits_be16(&ccm->misccr, CCM_MISCCR_LIMP); |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 78 | |
| 79 | /* Wait for the PLL to lock */ |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 80 | while (!(in_be32(&pll->psr) & PLL_PSR_LOCK)) |
| 81 | ; |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /* |
| 85 | * get_clocks() fills in gd->cpu_clock and gd->bus_clk |
| 86 | */ |
| 87 | int get_clocks(void) |
| 88 | { |
| 89 | |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 90 | ccm_t *ccm = (ccm_t *)MMAP_CCM; |
| 91 | pll_t *pll = (pll_t *)MMAP_PLL; |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 92 | int vco, temp, pcrvalue, pfdr; |
| 93 | u8 bootmode; |
| 94 | |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 95 | pcrvalue = in_be32(&pll->pcr) & 0xFF0F0FFF; |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 96 | pfdr = pcrvalue >> 24; |
| 97 | |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 98 | if (pfdr == 0x1E) |
| 99 | bootmode = 0; /* Normal Mode */ |
| 100 | |
| 101 | #ifdef CONFIG_CF_SBF |
| 102 | bootmode = 3; /* Serial Mode */ |
| 103 | #endif |
| 104 | |
| 105 | if (bootmode == 0) { |
| 106 | /* Normal mode */ |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 107 | vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC; |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 108 | if ((vco < CLOCK_PLL_FVCO_MIN) || (vco > CLOCK_PLL_FVCO_MAX)) { |
| 109 | /* Default value */ |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 110 | pcrvalue = (in_be32(&pll->pcr) & 0x00FFFFFF); |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 111 | pcrvalue |= 0x1E << 24; |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 112 | out_be32(&pll->pcr, pcrvalue); |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 113 | vco = |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 114 | ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 115 | CONFIG_SYS_INPUT_CLKSRC; |
| 116 | } |
Simon Glass | 568a7b6 | 2012-12-13 20:49:07 +0000 | [diff] [blame^] | 117 | gd->arch.vco_clk = vco; /* Vco clock */ |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 118 | } else if (bootmode == 3) { |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 119 | /* serial mode */ |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 120 | vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC; |
Simon Glass | 568a7b6 | 2012-12-13 20:49:07 +0000 | [diff] [blame^] | 121 | gd->arch.vco_clk = vco; /* Vco clock */ |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 122 | } |
| 123 | |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 124 | if ((in_be16(&ccm->ccr) & CCM_MISCCR_LIMP) == CCM_MISCCR_LIMP) { |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 125 | /* Limp mode */ |
| 126 | } else { |
Simon Glass | 568a7b6 | 2012-12-13 20:49:07 +0000 | [diff] [blame^] | 127 | gd->arch.inp_clk = CONFIG_SYS_INPUT_CLKSRC; /* Input clock */ |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 128 | |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 129 | temp = (in_be32(&pll->pcr) & PLL_PCR_OUTDIV1_MASK) + 1; |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 130 | gd->cpu_clk = vco / temp; /* cpu clock */ |
| 131 | |
Alison Wang | 8bce3ec | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 132 | temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV2_MASK) >> 4) + 1; |
Simon Glass | 568a7b6 | 2012-12-13 20:49:07 +0000 | [diff] [blame^] | 133 | gd->arch.flb_clk = vco / temp; /* flexbus clock */ |
| 134 | gd->bus_clk = gd->arch.flb_clk; |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 135 | } |
| 136 | |
TsiChung Liew | 0c1e325 | 2008-08-19 03:01:19 +0600 | [diff] [blame] | 137 | #ifdef CONFIG_FSL_I2C |
Simon Glass | c2baaec | 2012-12-13 20:48:49 +0000 | [diff] [blame] | 138 | gd->arch.i2c1_clk = gd->bus_clk; |
TsiChung Liew | 0c1e325 | 2008-08-19 03:01:19 +0600 | [diff] [blame] | 139 | #endif |
| 140 | |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 141 | return (0); |
| 142 | } |