1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright 2004 Freescale Semiconductor. 4 * Jeff Brown 5 * Srikanth Srinivasan (srikanth.srinivasan (at) freescale.com) 6 * 7 * (C) Copyright 2000-2002 8 * Wolfgang Denk, DENX Software Engineering, wd (at) denx.de. 9 */ 10 11 #include <common.h> 12 #include <mpc86xx.h> 13 #include <asm/processor.h> 14 #include <asm/io.h> 15 16 DECLARE_GLOBAL_DATA_PTR; 17 18 /* used in some defintiions of CONFIG_SYS_CLK_FREQ */ 19 extern unsigned long get_board_sys_clk(unsigned long dummy); 20 21 void get_sys_info(sys_info_t *sys_info) 22 { 23 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; 24 volatile ccsr_gur_t *gur = &immap->im_gur; 25 uint plat_ratio, e600_ratio; 26 27 plat_ratio = (gur->porpllsr) & 0x0000003e; 28 plat_ratio >>= 1; 29 30 switch (plat_ratio) { 31 case 0x0: 32 sys_info->freq_systembus = 16 * CONFIG_SYS_CLK_FREQ; 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: 43 case 0x10: 44 sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ; 45 break; 46 default: 47 sys_info->freq_systembus = 0; 48 break; 49 } 50 51 e600_ratio = (gur->porpllsr) & 0x003f0000; 52 e600_ratio >>= 16; 53 54 switch (e600_ratio) { 55 case 0x10: 56 sys_info->freq_processor = 2 * sys_info->freq_systembus; 57 break; 58 case 0x19: 59 sys_info->freq_processor = 5 * sys_info->freq_systembus / 2; 60 break; 61 case 0x20: 62 sys_info->freq_processor = 3 * sys_info->freq_systembus; 63 break; 64 case 0x39: 65 sys_info->freq_processor = 7 * sys_info->freq_systembus / 2; 66 break; 67 case 0x28: 68 sys_info->freq_processor = 4 * sys_info->freq_systembus; 69 break; 70 case 0x1d: 71 sys_info->freq_processor = 9 * sys_info->freq_systembus / 2; 72 break; 73 default: 74 sys_info->freq_processor = e600_ratio + 75 sys_info->freq_systembus; 76 break; 77 } 78 79 sys_info->freq_localbus = sys_info->freq_systembus; 80 } 81 82 83 /* 84 * Measure CPU clock speed (core clock GCLK1, GCLK2) 85 * (Approx. GCLK frequency in Hz) 86 */ 87 88 int get_clocks(void) 89 { 90 sys_info_t sys_info; 91 92 get_sys_info(&sys_info); 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; 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 */ 104 #ifdef CONFIG_ARCH_MPC8610 105 gd->arch.i2c1_clk = sys_info.freq_systembus; 106 #else 107 gd->arch.i2c1_clk = sys_info.freq_systembus / 2; 108 #endif 109 gd->arch.i2c2_clk = gd->arch.i2c1_clk; 110 111 if (gd->cpu_clk != 0) 112 return 0; 113 else 114 return 1; 115 } 116 117 118 /* 119 * get_bus_freq 120 * Return system bus freq in Hz 121 */ 122 123 ulong get_bus_freq(ulong dummy) 124 { 125 ulong val; 126 sys_info_t sys_info; 127 128 get_sys_info(&sys_info); 129 val = sys_info.freq_systembus; 130 131 return val; 132 } 133