Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 Freescale Semiconductor. |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 3 | * Jeff Brown |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 4 | * Srikanth Srinivasan (srikanth.srinivasan@freescale.com) |
| 5 | * |
| 6 | * (C) Copyright 2000-2002 |
| 7 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 8 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 25 | * MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <common.h> |
| 29 | #include <mpc86xx.h> |
| 30 | #include <asm/processor.h> |
Trent Piepho | ada591d | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 31 | #include <asm/io.h> |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 32 | |
Wolfgang Denk | 1218abf | 2007-09-15 20:48:41 +0200 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 34 | |
Wolfgang Denk | 409ecdc | 2007-11-18 16:36:27 +0100 | [diff] [blame] | 35 | /* used in some defintiions of CONFIG_SYS_CLK_FREQ */ |
| 36 | extern unsigned long get_board_sys_clk(unsigned long dummy); |
| 37 | |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 38 | void get_sys_info(sys_info_t *sysInfo) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 39 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 40 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 41 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 42 | uint plat_ratio, e600_ratio; |
Trent Piepho | ada591d | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 43 | uint lcrr_div; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 44 | |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 45 | plat_ratio = (gur->porpllsr) & 0x0000003e; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 46 | plat_ratio >>= 1; |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 47 | |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 48 | switch (plat_ratio) { |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 49 | case 0x0: |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 50 | sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ; |
| 51 | break; |
| 52 | case 0x02: |
| 53 | case 0x03: |
| 54 | case 0x04: |
| 55 | case 0x05: |
| 56 | case 0x06: |
| 57 | case 0x08: |
| 58 | case 0x09: |
| 59 | case 0x0a: |
| 60 | case 0x0c: |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 61 | case 0x10: |
| 62 | sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ; |
| 63 | break; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 64 | default: |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 65 | sysInfo->freqSystemBus = 0; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 66 | break; |
| 67 | } |
| 68 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 69 | e600_ratio = (gur->porpllsr) & 0x003f0000; |
| 70 | e600_ratio >>= 16; |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 71 | |
| 72 | switch (e600_ratio) { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 73 | case 0x10: |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 74 | sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 75 | break; |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 76 | case 0x19: |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 77 | sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus / 2; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 78 | break; |
| 79 | case 0x20: |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 80 | sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 81 | break; |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 82 | case 0x39: |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 83 | sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus / 2; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 84 | break; |
| 85 | case 0x28: |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 86 | sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 87 | break; |
| 88 | case 0x1d: |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 89 | sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus / 2; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 90 | break; |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 91 | default: |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 92 | sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 93 | break; |
| 94 | } |
Trent Piepho | ada591d | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 95 | |
| 96 | #if defined(CONFIG_SYS_LBC_LCRR) |
| 97 | /* We will program LCRR to this value later */ |
| 98 | lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV; |
| 99 | #else |
Becky Bruce | f51cdaf | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 100 | lcrr_div = in_be32(&immap->im_lbc.lcrr) & LCRR_CLKDIV; |
Trent Piepho | ada591d | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 101 | #endif |
| 102 | if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) { |
| 103 | sysInfo->freqLocalBus = sysInfo->freqSystemBus / (lcrr_div * 2); |
| 104 | } else { |
| 105 | /* In case anyone cares what the unknown value is */ |
| 106 | sysInfo->freqLocalBus = lcrr_div; |
| 107 | } |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 111 | /* |
| 112 | * Measure CPU clock speed (core clock GCLK1, GCLK2) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 113 | * (Approx. GCLK frequency in Hz) |
| 114 | */ |
| 115 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 116 | int get_clocks(void) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 117 | { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 118 | sys_info_t sys_info; |
| 119 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 120 | get_sys_info(&sys_info); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 121 | gd->cpu_clk = sys_info.freqProcessor; |
| 122 | gd->bus_clk = sys_info.freqSystemBus; |
Trent Piepho | ada591d | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 123 | gd->lbc_clk = sys_info.freqLocalBus; |
Timur Tabi | 1b9ed25 | 2008-04-04 11:16:11 -0500 | [diff] [blame] | 124 | |
| 125 | /* |
| 126 | * The base clock for I2C depends on the actual SOC. Unfortunately, |
| 127 | * there is no pattern that can be used to determine the frequency, so |
| 128 | * the only choice is to look up the actual SOC number and use the value |
| 129 | * for that SOC. This information is taken from application note |
| 130 | * AN2919. |
| 131 | */ |
| 132 | #ifdef CONFIG_MPC8610 |
Timur Tabi | 943afa2 | 2008-01-09 14:35:26 -0600 | [diff] [blame] | 133 | gd->i2c1_clk = sys_info.freqSystemBus; |
Timur Tabi | 1b9ed25 | 2008-04-04 11:16:11 -0500 | [diff] [blame] | 134 | #else |
| 135 | gd->i2c1_clk = sys_info.freqSystemBus / 2; |
| 136 | #endif |
| 137 | gd->i2c2_clk = gd->i2c1_clk; |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 138 | |
| 139 | if (gd->cpu_clk != 0) |
| 140 | return 0; |
| 141 | else |
| 142 | return 1; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 143 | } |
| 144 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 145 | |
| 146 | /* |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 147 | * get_bus_freq |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 148 | * Return system bus freq in Hz |
| 149 | */ |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 150 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 151 | ulong get_bus_freq(ulong dummy) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 152 | { |
| 153 | ulong val; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 154 | sys_info_t sys_info; |
| 155 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 156 | get_sys_info(&sys_info); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 157 | val = sys_info.freqSystemBus; |
| 158 | |
| 159 | return val; |
| 160 | } |