wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 1 | /* |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 2 | * (C) Copyright 2000-2004 |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <mpc8xx.h> |
| 26 | #include <asm/processor.h> |
| 27 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame^] | 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Wolfgang Denk | bb17209 | 2005-08-12 22:32:29 +0200 | [diff] [blame] | 30 | #if !defined(CONFIG_8xx_CPUCLK_DEFAULT) || defined(CFG_MEASURE_CPUCLK) || defined(DEBUG) |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 31 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 32 | #define PITC_SHIFT 16 |
| 33 | #define PITR_SHIFT 16 |
| 34 | /* pitc values to time for 58/8192 seconds (about 70.8 milliseconds) */ |
| 35 | #define SPEED_PIT_COUNTS 58 |
| 36 | #define SPEED_PITC ((SPEED_PIT_COUNTS - 1) << PITC_SHIFT) |
| 37 | #define SPEED_PITC_INIT ((SPEED_PIT_COUNTS + 1) << PITC_SHIFT) |
| 38 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 39 | /* Access functions for the Machine State Register */ |
| 40 | static __inline__ unsigned long get_msr(void) |
| 41 | { |
| 42 | unsigned long msr; |
| 43 | |
| 44 | asm volatile("mfmsr %0" : "=r" (msr) :); |
| 45 | return msr; |
| 46 | } |
| 47 | |
| 48 | static __inline__ void set_msr(unsigned long msr) |
| 49 | { |
| 50 | asm volatile("mtmsr %0" : : "r" (msr)); |
| 51 | } |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 52 | |
| 53 | /* ------------------------------------------------------------------------- */ |
| 54 | |
| 55 | /* |
| 56 | * Measure CPU clock speed (core clock GCLK1, GCLK2), |
| 57 | * also determine bus clock speed (checking bus divider factor) |
| 58 | * |
| 59 | * (Approx. GCLK frequency in Hz) |
| 60 | * |
| 61 | * Initializes timer 2 and PIT, but disables them before return. |
| 62 | * [Use timer 2, because MPC823 CPUs mask 0.x do not have timers 3 and 4] |
| 63 | * |
| 64 | * When measuring the CPU clock against the PIT, we count cpu clocks |
| 65 | * for 58/8192 seconds with a prescale divide by 177 for the cpu clock. |
| 66 | * These strange values for the timing interval and prescaling are used |
| 67 | * because the formula for the CPU clock is: |
| 68 | * |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 69 | * CPU clock = count * (177 * (8192 / 58)) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 70 | * |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 71 | * = count * 24999.7241 |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 72 | * |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 73 | * which is very close to |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 74 | * |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 75 | * = count * 25000 |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 76 | * |
| 77 | * Since the count gives the CPU clock divided by 25000, we can get |
| 78 | * the CPU clock rounded to the nearest 0.1 MHz by |
| 79 | * |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 80 | * CPU clock = ((count + 2) / 4) * 100000; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 81 | * |
| 82 | * The rounding is important since the measurement is sometimes going |
| 83 | * to be high or low by 0.025 MHz, depending on exactly how the clocks |
| 84 | * and counters interact. By rounding we get the exact answer for any |
| 85 | * CPU clock that is an even multiple of 0.1 MHz. |
| 86 | */ |
| 87 | |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 88 | unsigned long measure_gclk(void) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 89 | { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 90 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 91 | volatile cpmtimer8xx_t *timerp = &immr->im_cpmtimer; |
| 92 | ulong timer2_val; |
| 93 | ulong msr_val; |
| 94 | |
wdenk | a7556b2 | 2004-06-06 21:35:06 +0000 | [diff] [blame] | 95 | #ifdef CFG_8XX_XIN |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 96 | /* dont use OSCM, only use EXTCLK/512 */ |
| 97 | immr->im_clkrst.car_sccr |= SCCR_RTSEL | SCCR_RTDIV; |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 98 | #else |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 99 | immr->im_clkrst.car_sccr &= ~(SCCR_RTSEL | SCCR_RTDIV); |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 100 | #endif |
| 101 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 102 | /* Reset + Stop Timer 2, no cascading |
| 103 | */ |
| 104 | timerp->cpmt_tgcr &= ~(TGCR_CAS2 | TGCR_RST2); |
| 105 | |
| 106 | /* Keep stopped, halt in debug mode |
| 107 | */ |
| 108 | timerp->cpmt_tgcr |= (TGCR_FRZ2 | TGCR_STP2); |
| 109 | |
| 110 | /* Timer 2 setup: |
| 111 | * Output ref. interrupt disable, int. clock |
| 112 | * Prescale by 177. Note that prescaler divides by value + 1 |
| 113 | * so we must subtract 1 here. |
| 114 | */ |
| 115 | timerp->cpmt_tmr2 = ((177 - 1) << TMR_PS_SHIFT) | TMR_ICLK_IN_GEN; |
| 116 | |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 117 | timerp->cpmt_tcn2 = 0; /* reset state */ |
| 118 | timerp->cpmt_tgcr |= TGCR_RST2; /* enable timer 2 */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * PIT setup: |
| 122 | * |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 123 | * We want to time for SPEED_PITC_COUNTS counts (of 8192 Hz), |
| 124 | * so the count value would be SPEED_PITC_COUNTS - 1. |
| 125 | * But there would be an uncertainty in the start time of 1/4 |
| 126 | * count since when we enable the PIT the count is not |
| 127 | * synchronized to the 32768 Hz oscillator. The trick here is |
| 128 | * to start the count higher and wait until the PIT count |
| 129 | * changes to the required value before starting timer 2. |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 130 | * |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 131 | * One count high should be enough, but occasionally the start |
| 132 | * is off by 1 or 2 counts of 32768 Hz. With the start value |
| 133 | * set two counts high it seems very reliable. |
| 134 | */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 135 | |
| 136 | immr->im_sitk.sitk_pitck = KAPWR_KEY; /* PIT initialization */ |
| 137 | immr->im_sit.sit_pitc = SPEED_PITC_INIT; |
| 138 | |
| 139 | immr->im_sitk.sitk_piscrk = KAPWR_KEY; |
| 140 | immr->im_sit.sit_piscr = CFG_PISCR; |
| 141 | |
| 142 | /* |
| 143 | * Start measurement - disable interrupts, just in case |
| 144 | */ |
| 145 | msr_val = get_msr (); |
| 146 | set_msr (msr_val & ~MSR_EE); |
| 147 | |
| 148 | immr->im_sit.sit_piscr |= PISCR_PTE; |
| 149 | |
| 150 | /* spin until get exact count when we want to start */ |
| 151 | while (immr->im_sit.sit_pitr > SPEED_PITC); |
| 152 | |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 153 | timerp->cpmt_tgcr &= ~TGCR_STP2; /* Start Timer 2 */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 154 | while ((immr->im_sit.sit_piscr & PISCR_PS) == 0); |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 155 | timerp->cpmt_tgcr |= TGCR_STP2; /* Stop Timer 2 */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 156 | |
| 157 | /* re-enable external interrupts if they were on */ |
| 158 | set_msr (msr_val); |
| 159 | |
| 160 | /* Disable timer and PIT |
| 161 | */ |
| 162 | timer2_val = timerp->cpmt_tcn2; /* save before reset timer */ |
| 163 | |
| 164 | timerp->cpmt_tgcr &= ~(TGCR_RST2 | TGCR_FRZ2 | TGCR_STP2); |
| 165 | immr->im_sit.sit_piscr &= ~PISCR_PTE; |
| 166 | |
wdenk | a7556b2 | 2004-06-06 21:35:06 +0000 | [diff] [blame] | 167 | #if defined(CFG_8XX_XIN) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 168 | /* not using OSCM, using XIN, so scale appropriately */ |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 169 | return (((timer2_val + 2) / 4) * (CFG_8XX_XIN/512))/8192 * 100000L; |
| 170 | #else |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 171 | return ((timer2_val + 2) / 4) * 100000L; /* convert to Hz */ |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 172 | #endif |
| 173 | } |
| 174 | |
wdenk | fde3704 | 2004-01-31 20:06:54 +0000 | [diff] [blame] | 175 | #endif |
| 176 | |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 177 | #if !defined(CONFIG_8xx_CPUCLK_DEFAULT) |
wdenk | fde3704 | 2004-01-31 20:06:54 +0000 | [diff] [blame] | 178 | |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 179 | /* |
| 180 | * get_clocks() fills in gd->cpu_clock depending on CONFIG_8xx_GCLK_FREQ |
| 181 | * or (if it is not defined) measure_gclk() (which uses the ref clock) |
| 182 | * from above. |
| 183 | */ |
| 184 | int get_clocks (void) |
| 185 | { |
wdenk | a7556b2 | 2004-06-06 21:35:06 +0000 | [diff] [blame] | 186 | uint immr = get_immr (0); /* Return full IMMR contents */ |
| 187 | volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000); |
| 188 | uint sccr = immap->im_clkrst.car_sccr; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 189 | /* |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 190 | * If for some reason measuring the gclk frequency won't |
| 191 | * work, we return the hardwired value. |
| 192 | * (For example, the cogent CMA286-60 CPU module has no |
| 193 | * separate oscillator for PITRTCLK) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 194 | */ |
wdenk | a7556b2 | 2004-06-06 21:35:06 +0000 | [diff] [blame] | 195 | #if defined(CONFIG_8xx_GCLK_FREQ) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 196 | gd->cpu_clk = CONFIG_8xx_GCLK_FREQ; |
wdenk | a7556b2 | 2004-06-06 21:35:06 +0000 | [diff] [blame] | 197 | #elif defined(CONFIG_8xx_OSCLK) |
| 198 | #define PLPRCR_val(a) ((pll & PLPRCR_ ## a ## _MSK) >> PLPRCR_ ## a ## _SHIFT) |
| 199 | uint pll = immap->im_clkrst.car_plprcr; |
| 200 | uint clk; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 201 | |
wdenk | a7556b2 | 2004-06-06 21:35:06 +0000 | [diff] [blame] | 202 | if ((immr & 0x0FFF) >= MPC8xx_NEW_CLK) { /* MPC866/87x/88x series */ |
| 203 | clk = ((CONFIG_8xx_OSCLK / (PLPRCR_val(PDF)+1)) * |
| 204 | (PLPRCR_val(MFI) + PLPRCR_val(MFN) / (PLPRCR_val(MFD)+1))) / |
| 205 | (1<<PLPRCR_val(S)); |
| 206 | } else { |
| 207 | clk = CONFIG_8xx_OSCLK * (PLPRCR_val(MF)+1); |
| 208 | } |
| 209 | if (pll & PLPRCR_CSRC) { /* Low frequency division factor is used */ |
| 210 | gd->cpu_clk = clk / (2 << ((sccr >> 8) & 7)); |
| 211 | } else { /* High frequency division factor is used */ |
| 212 | gd->cpu_clk = clk / (1 << ((sccr >> 5) & 7)); |
| 213 | } |
| 214 | #else |
| 215 | gd->cpu_clk = measure_gclk(); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 216 | #endif /* CONFIG_8xx_GCLK_FREQ */ |
| 217 | |
wdenk | a7556b2 | 2004-06-06 21:35:06 +0000 | [diff] [blame] | 218 | if ((sccr & SCCR_EBDF11) == 0) { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 219 | /* No Bus Divider active */ |
| 220 | gd->bus_clk = gd->cpu_clk; |
| 221 | } else { |
| 222 | /* The MPC8xx has only one BDF: half clock speed */ |
| 223 | gd->bus_clk = gd->cpu_clk / 2; |
| 224 | } |
| 225 | |
| 226 | return (0); |
| 227 | } |
| 228 | |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 229 | #else /* CONFIG_8xx_CPUCLK_DEFAULT defined, use dynamic clock setting */ |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 230 | |
| 231 | static long init_pll_866 (long clk); |
| 232 | |
| 233 | /* This function sets up PLL (init_pll_866() is called) and |
| 234 | * fills gd->cpu_clk and gd->bus_clk according to the environment |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 235 | * variable 'cpuclk' or to CONFIG_8xx_CPUCLK_DEFAULT (if 'cpuclk' |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 236 | * contains invalid value). |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 237 | * This functions requires an MPC866 or newer series CPU. |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 238 | */ |
| 239 | int get_clocks_866 (void) |
| 240 | { |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 241 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 242 | char tmp[64]; |
| 243 | long cpuclk = 0; |
| 244 | long sccr_reg; |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 245 | |
| 246 | if (getenv_r ("cpuclk", tmp, sizeof (tmp)) > 0) |
| 247 | cpuclk = simple_strtoul (tmp, NULL, 10) * 1000000; |
| 248 | |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 249 | if ((CFG_8xx_CPUCLK_MIN > cpuclk) || (CFG_8xx_CPUCLK_MAX < cpuclk)) |
| 250 | cpuclk = CONFIG_8xx_CPUCLK_DEFAULT; |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 251 | |
| 252 | gd->cpu_clk = init_pll_866 (cpuclk); |
wdenk | fde3704 | 2004-01-31 20:06:54 +0000 | [diff] [blame] | 253 | #if defined(CFG_MEASURE_CPUCLK) |
| 254 | gd->cpu_clk = measure_gclk (); |
| 255 | #endif |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 256 | |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 257 | /* if cpu clock <= 66 MHz then set bus division factor to 1, |
| 258 | * otherwise set it to 2 |
| 259 | */ |
| 260 | sccr_reg = immr->im_clkrst.car_sccr; |
| 261 | sccr_reg &= ~SCCR_EBDF11; |
| 262 | if (gd->cpu_clk <= 66000000) { |
| 263 | sccr_reg |= SCCR_EBDF00; /* bus division factor = 1 */ |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 264 | gd->bus_clk = gd->cpu_clk; |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 265 | } else { |
| 266 | sccr_reg |= SCCR_EBDF01; /* bus division factor = 2 */ |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 267 | gd->bus_clk = gd->cpu_clk / 2; |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 268 | } |
| 269 | immr->im_clkrst.car_sccr = sccr_reg; |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 270 | |
| 271 | return (0); |
| 272 | } |
| 273 | |
| 274 | /* Adjust sdram refresh rate to actual CPU clock. |
| 275 | */ |
| 276 | int sdram_adjust_866 (void) |
| 277 | { |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 278 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 279 | long mamr; |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 280 | |
| 281 | mamr = immr->im_memctl.memc_mamr; |
| 282 | mamr &= ~MAMR_PTA_MSK; |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 283 | mamr |= ((gd->cpu_clk / CFG_PTA_PER_CLK) << MAMR_PTA_SHIFT); |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 284 | immr->im_memctl.memc_mamr = mamr; |
| 285 | |
| 286 | return (0); |
| 287 | } |
| 288 | |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 289 | /* Configure PLL for MPC866/859/885 CPU series |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 290 | * PLL multiplication factor is set to the value nearest to the desired clk, |
| 291 | * assuming a oscclk of 10 MHz. |
| 292 | */ |
| 293 | static long init_pll_866 (long clk) |
| 294 | { |
| 295 | extern void plprcr_write_866 (long); |
| 296 | |
| 297 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
wdenk | 88d73b5 | 2004-02-11 21:35:18 +0000 | [diff] [blame] | 298 | long n, plprcr; |
| 299 | char mfi, mfn, mfd, s, pdf; |
| 300 | long step_mfi, step_mfn; |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 301 | |
wdenk | fde3704 | 2004-01-31 20:06:54 +0000 | [diff] [blame] | 302 | if (clk < 20000000) { |
| 303 | clk *= 2; |
| 304 | pdf = 1; |
| 305 | } else { |
| 306 | pdf = 0; |
| 307 | } |
| 308 | |
| 309 | if (clk < 40000000) { |
| 310 | s = 2; |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 311 | step_mfi = CONFIG_8xx_OSCLK / 4; |
wdenk | fde3704 | 2004-01-31 20:06:54 +0000 | [diff] [blame] | 312 | mfd = 7; |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 313 | step_mfn = CONFIG_8xx_OSCLK / 30; |
wdenk | fde3704 | 2004-01-31 20:06:54 +0000 | [diff] [blame] | 314 | } else if (clk < 80000000) { |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 315 | s = 1; |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 316 | step_mfi = CONFIG_8xx_OSCLK / 2; |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 317 | mfd = 14; |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 318 | step_mfn = CONFIG_8xx_OSCLK / 30; |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 319 | } else { |
| 320 | s = 0; |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 321 | step_mfi = CONFIG_8xx_OSCLK; |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 322 | mfd = 29; |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 323 | step_mfn = CONFIG_8xx_OSCLK / 30; |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /* Calculate integer part of multiplication factor |
| 327 | */ |
| 328 | n = clk / step_mfi; |
| 329 | mfi = (char)n; |
| 330 | |
| 331 | /* Calculate numerator of fractional part of multiplication factor |
| 332 | */ |
| 333 | n = clk - (n * step_mfi); |
| 334 | mfn = (char)(n / step_mfn); |
| 335 | |
| 336 | /* Calculate effective clk |
| 337 | */ |
wdenk | fde3704 | 2004-01-31 20:06:54 +0000 | [diff] [blame] | 338 | n = ((mfi * step_mfi) + (mfn * step_mfn)) / (pdf + 1); |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 339 | |
| 340 | immr->im_clkrstk.cark_plprcrk = KAPWR_KEY; |
| 341 | |
| 342 | plprcr = (immr->im_clkrst.car_plprcr & ~(PLPRCR_MFN_MSK |
| 343 | | PLPRCR_MFD_MSK | PLPRCR_S_MSK |
wdenk | fde3704 | 2004-01-31 20:06:54 +0000 | [diff] [blame] | 344 | | PLPRCR_MFI_MSK | PLPRCR_DBRMO |
| 345 | | PLPRCR_PDF_MSK)) |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 346 | | (mfn << PLPRCR_MFN_SHIFT) |
| 347 | | (mfd << PLPRCR_MFD_SHIFT) |
| 348 | | (s << PLPRCR_S_SHIFT) |
| 349 | | (mfi << PLPRCR_MFI_SHIFT) |
| 350 | | (pdf << PLPRCR_PDF_SHIFT); |
| 351 | |
| 352 | if( (mfn > 0) && ((mfd / mfn) > 10) ) |
| 353 | plprcr |= PLPRCR_DBRMO; |
| 354 | |
| 355 | plprcr_write_866 (plprcr); /* set value using SIU4/9 workaround */ |
| 356 | immr->im_clkrstk.cark_plprcrk = 0x00000000; |
| 357 | |
| 358 | return (n); |
| 359 | } |
| 360 | |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 361 | #endif /* CONFIG_8xx_CPUCLK_DEFAULT */ |
wdenk | b50cde5 | 2004-01-24 20:25:54 +0000 | [diff] [blame] | 362 | |
wdenk | c78bf13 | 2004-04-24 23:23:30 +0000 | [diff] [blame] | 363 | #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) |
| 364 | /* |
| 365 | * Adjust sdram refresh rate to actual CPU clock |
| 366 | * and set timebase source according to actual CPU clock |
| 367 | */ |
| 368 | int adjust_sdram_tbs_8xx (void) |
| 369 | { |
wdenk | c78bf13 | 2004-04-24 23:23:30 +0000 | [diff] [blame] | 370 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 371 | long mamr; |
| 372 | long sccr; |
| 373 | |
| 374 | mamr = immr->im_memctl.memc_mamr; |
| 375 | mamr &= ~MAMR_PTA_MSK; |
| 376 | mamr |= ((gd->cpu_clk / CFG_PTA_PER_CLK) << MAMR_PTA_SHIFT); |
| 377 | immr->im_memctl.memc_mamr = mamr; |
| 378 | |
| 379 | if (gd->cpu_clk < 67000000) { |
| 380 | sccr = immr->im_clkrst.car_sccr; |
| 381 | sccr |= SCCR_TBS; |
| 382 | immr->im_clkrst.car_sccr = sccr; |
| 383 | } |
| 384 | |
| 385 | return (0); |
| 386 | } |
| 387 | #endif /* CONFIG_TQM8xxL/M, !TQM866M */ |
| 388 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 389 | /* ------------------------------------------------------------------------- */ |