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 | * | ||||
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 10 | */ |
11 | |||||
12 | #include <common.h> | ||||
13 | #include <mpc86xx.h> | ||||
14 | #include <asm/processor.h> | ||||
Trent Piepho | ada591d | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 15 | #include <asm/io.h> |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 16 | |
Wolfgang Denk | 1218abf | 2007-09-15 20:48:41 +0200 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 18 | |
Wolfgang Denk | 409ecdc | 2007-11-18 16:36:27 +0100 | [diff] [blame] | 19 | /* used in some defintiions of CONFIG_SYS_CLK_FREQ */ |
20 | extern unsigned long get_board_sys_clk(unsigned long dummy); | ||||
21 | |||||
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 22 | void get_sys_info(sys_info_t *sys_info) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 23 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 24 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 25 | volatile ccsr_gur_t *gur = &immap->im_gur; |
26 | uint plat_ratio, e600_ratio; | ||||
Trent Piepho | ada591d | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 27 | uint lcrr_div; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 28 | |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 29 | plat_ratio = (gur->porpllsr) & 0x0000003e; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 30 | plat_ratio >>= 1; |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 31 | |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 32 | switch (plat_ratio) { |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 33 | case 0x0: |
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 34 | sys_info->freq_systembus = 16 * CONFIG_SYS_CLK_FREQ; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 35 | break; |
36 | case 0x02: | ||||
37 | case 0x03: | ||||
38 | case 0x04: | ||||
39 | case 0x05: | ||||
40 | case 0x06: | ||||
41 | case 0x08: | ||||
42 | case 0x09: | ||||
43 | case 0x0a: | ||||
44 | case 0x0c: | ||||
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 45 | case 0x10: |
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 46 | sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ; |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 47 | break; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 48 | default: |
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 49 | sys_info->freq_systembus = 0; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 50 | break; |
51 | } | ||||
52 | |||||
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 53 | e600_ratio = (gur->porpllsr) & 0x003f0000; |
54 | e600_ratio >>= 16; | ||||
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 55 | |
56 | switch (e600_ratio) { | ||||
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 57 | case 0x10: |
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 58 | sys_info->freq_processor = 2 * sys_info->freq_systembus; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 59 | break; |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 60 | case 0x19: |
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 61 | sys_info->freq_processor = 5 * sys_info->freq_systembus / 2; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 62 | break; |
63 | case 0x20: | ||||
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 64 | sys_info->freq_processor = 3 * sys_info->freq_systembus; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 65 | break; |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 66 | case 0x39: |
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 67 | sys_info->freq_processor = 7 * sys_info->freq_systembus / 2; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 68 | break; |
69 | case 0x28: | ||||
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 70 | sys_info->freq_processor = 4 * sys_info->freq_systembus; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 71 | break; |
72 | case 0x1d: | ||||
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 73 | sys_info->freq_processor = 9 * sys_info->freq_systembus / 2; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 74 | break; |
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 75 | default: |
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 76 | sys_info->freq_processor = e600_ratio + |
77 | sys_info->freq_systembus; | ||||
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 78 | break; |
79 | } | ||||
Trent Piepho | ada591d | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 80 | |
81 | #if defined(CONFIG_SYS_LBC_LCRR) | ||||
82 | /* We will program LCRR to this value later */ | ||||
83 | lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV; | ||||
84 | #else | ||||
Becky Bruce | f51cdaf | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 85 | lcrr_div = in_be32(&immap->im_lbc.lcrr) & LCRR_CLKDIV; |
Trent Piepho | ada591d | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 86 | #endif |
87 | if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) { | ||||
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 88 | sys_info->freq_localbus = sys_info->freq_systembus |
89 | / (lcrr_div * 2); | ||||
Trent Piepho | ada591d | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 90 | } else { |
91 | /* In case anyone cares what the unknown value is */ | ||||
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 92 | sys_info->freq_localbus = lcrr_div; |
Trent Piepho | ada591d | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 93 | } |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 94 | } |
95 | |||||
96 | |||||
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 97 | /* |
98 | * Measure CPU clock speed (core clock GCLK1, GCLK2) | ||||
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 99 | * (Approx. GCLK frequency in Hz) |
100 | */ | ||||
101 | |||||
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 102 | int get_clocks(void) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 103 | { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 104 | sys_info_t sys_info; |
105 | |||||
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 106 | get_sys_info(&sys_info); |
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 107 | gd->cpu_clk = sys_info.freq_processor; |
108 | gd->bus_clk = sys_info.freq_systembus; | ||||
109 | gd->arch.lbc_clk = sys_info.freq_localbus; | ||||
Timur Tabi | 1b9ed25 | 2008-04-04 11:16:11 -0500 | [diff] [blame] | 110 | |
111 | /* | ||||
112 | * The base clock for I2C depends on the actual SOC. Unfortunately, | ||||
113 | * there is no pattern that can be used to determine the frequency, so | ||||
114 | * the only choice is to look up the actual SOC number and use the value | ||||
115 | * for that SOC. This information is taken from application note | ||||
116 | * AN2919. | ||||
117 | */ | ||||
118 | #ifdef CONFIG_MPC8610 | ||||
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 119 | gd->arch.i2c1_clk = sys_info.freq_systembus; |
Timur Tabi | 1b9ed25 | 2008-04-04 11:16:11 -0500 | [diff] [blame] | 120 | #else |
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 121 | gd->arch.i2c1_clk = sys_info.freq_systembus / 2; |
Timur Tabi | 1b9ed25 | 2008-04-04 11:16:11 -0500 | [diff] [blame] | 122 | #endif |
Simon Glass | 609e6ec | 2012-12-13 20:48:49 +0000 | [diff] [blame] | 123 | gd->arch.i2c2_clk = gd->arch.i2c1_clk; |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 124 | |
125 | if (gd->cpu_clk != 0) | ||||
126 | return 0; | ||||
127 | else | ||||
128 | return 1; | ||||
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 129 | } |
130 | |||||
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 131 | |
132 | /* | ||||
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 133 | * get_bus_freq |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 134 | * Return system bus freq in Hz |
135 | */ | ||||
Jon Loeliger | c934f65 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 136 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 137 | ulong get_bus_freq(ulong dummy) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 138 | { |
139 | ulong val; | ||||
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 140 | sys_info_t sys_info; |
141 | |||||
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 142 | get_sys_info(&sys_info); |
Prabhakar Kushwaha | 997399f | 2013-08-16 14:52:26 +0530 | [diff] [blame^] | 143 | val = sys_info.freq_systembus; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 144 | |
145 | return val; | ||||
146 | } |