Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 2 | /* |
3 | * Copyright 2004 Freescale Semiconductor. | ||||
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 4 | * Jeff Brown |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 5 | * Srikanth Srinivasan (srikanth.srinivasan@freescale.com) |
6 | * | ||||
7 | * (C) Copyright 2000-2002 | ||||
8 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | ||||
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 9 | */ |
10 | |||||
11 | #include <common.h> | ||||
12 | #include <mpc86xx.h> | ||||
13 | #include <asm/processor.h> | ||||
Trent Piepho | 0b691fc | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 14 | #include <asm/io.h> |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 15 | |
Wolfgang Denk | d112a2c | 2007-09-15 20:48:41 +0200 | [diff] [blame] | 16 | DECLARE_GLOBAL_DATA_PTR; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 17 | |
Wolfgang Denk | 9225411 | 2007-11-18 16:36:27 +0100 | [diff] [blame] | 18 | /* used in some defintiions of CONFIG_SYS_CLK_FREQ */ |
19 | extern unsigned long get_board_sys_clk(unsigned long dummy); | ||||
20 | |||||
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 21 | void get_sys_info(sys_info_t *sys_info) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 22 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 24 | volatile ccsr_gur_t *gur = &immap->im_gur; |
25 | uint plat_ratio, e600_ratio; | ||||
26 | |||||
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 27 | plat_ratio = (gur->porpllsr) & 0x0000003e; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 28 | plat_ratio >>= 1; |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 29 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 30 | switch (plat_ratio) { |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 31 | case 0x0: |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 32 | sys_info->freq_systembus = 16 * CONFIG_SYS_CLK_FREQ; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 33 | break; |
34 | case 0x02: | ||||
35 | case 0x03: | ||||
36 | case 0x04: | ||||
37 | case 0x05: | ||||
38 | case 0x06: | ||||
39 | case 0x08: | ||||
40 | case 0x09: | ||||
41 | case 0x0a: | ||||
42 | case 0x0c: | ||||
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 43 | case 0x10: |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 44 | sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ; |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 45 | break; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 46 | default: |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 47 | sys_info->freq_systembus = 0; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 48 | break; |
49 | } | ||||
50 | |||||
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 51 | e600_ratio = (gur->porpllsr) & 0x003f0000; |
52 | e600_ratio >>= 16; | ||||
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 53 | |
54 | switch (e600_ratio) { | ||||
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 55 | case 0x10: |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 56 | sys_info->freq_processor = 2 * sys_info->freq_systembus; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 57 | break; |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 58 | case 0x19: |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 59 | sys_info->freq_processor = 5 * sys_info->freq_systembus / 2; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 60 | break; |
61 | case 0x20: | ||||
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 62 | sys_info->freq_processor = 3 * sys_info->freq_systembus; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 63 | break; |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 64 | case 0x39: |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 65 | sys_info->freq_processor = 7 * sys_info->freq_systembus / 2; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 66 | break; |
67 | case 0x28: | ||||
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 68 | sys_info->freq_processor = 4 * sys_info->freq_systembus; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 69 | break; |
70 | case 0x1d: | ||||
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 71 | sys_info->freq_processor = 9 * sys_info->freq_systembus / 2; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 72 | break; |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 73 | default: |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 74 | sys_info->freq_processor = e600_ratio + |
75 | sys_info->freq_systembus; | ||||
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 76 | break; |
77 | } | ||||
Trent Piepho | 0b691fc | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 78 | |
Prabhakar Kushwaha | bedc562 | 2017-02-02 15:02:00 +0530 | [diff] [blame] | 79 | sys_info->freq_localbus = sys_info->freq_systembus; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 80 | } |
81 | |||||
82 | |||||
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 83 | /* |
84 | * Measure CPU clock speed (core clock GCLK1, GCLK2) | ||||
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 85 | * (Approx. GCLK frequency in Hz) |
86 | */ | ||||
87 | |||||
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 88 | int get_clocks(void) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 89 | { |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 90 | sys_info_t sys_info; |
91 | |||||
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 92 | get_sys_info(&sys_info); |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 93 | gd->cpu_clk = sys_info.freq_processor; |
94 | gd->bus_clk = sys_info.freq_systembus; | ||||
95 | gd->arch.lbc_clk = sys_info.freq_localbus; | ||||
Timur Tabi | d93136b | 2008-04-04 11:16:11 -0500 | [diff] [blame] | 96 | |
97 | /* | ||||
98 | * The base clock for I2C depends on the actual SOC. Unfortunately, | ||||
99 | * there is no pattern that can be used to determine the frequency, so | ||||
100 | * the only choice is to look up the actual SOC number and use the value | ||||
101 | * for that SOC. This information is taken from application note | ||||
102 | * AN2919. | ||||
103 | */ | ||||
York Sun | f48436a | 2016-11-23 14:06:21 -0800 | [diff] [blame] | 104 | #ifdef CONFIG_ARCH_MPC8610 |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 105 | gd->arch.i2c1_clk = sys_info.freq_systembus; |
Timur Tabi | d93136b | 2008-04-04 11:16:11 -0500 | [diff] [blame] | 106 | #else |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 107 | gd->arch.i2c1_clk = sys_info.freq_systembus / 2; |
Timur Tabi | d93136b | 2008-04-04 11:16:11 -0500 | [diff] [blame] | 108 | #endif |
Simon Glass | c2baaec | 2012-12-13 20:48:49 +0000 | [diff] [blame] | 109 | gd->arch.i2c2_clk = gd->arch.i2c1_clk; |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 110 | |
111 | if (gd->cpu_clk != 0) | ||||
112 | return 0; | ||||
113 | else | ||||
114 | return 1; | ||||
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 115 | } |
116 | |||||
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 117 | |
118 | /* | ||||
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 119 | * get_bus_freq |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 120 | * Return system bus freq in Hz |
121 | */ | ||||
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 122 | |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 123 | ulong get_bus_freq(ulong dummy) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 124 | { |
125 | ulong val; | ||||
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 126 | sys_info_t sys_info; |
127 | |||||
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 128 | get_sys_info(&sys_info); |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 129 | val = sys_info.freq_systembus; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 130 | |
131 | return val; | ||||
132 | } |