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