3 * Martin Winistoerfer, martinwinistoerfer@gmx.ch.
5 * SPDX-License-Identifier: GPL-2.0+
11 * Discription: Provides cpu speed calculation
17 #include <asm/processor.h>
19 DECLARE_GLOBAL_DATA_PTR;
22 * Get cpu and bus clock
26 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
28 #ifndef CONFIG_5xx_GCLK_FREQ
29 uint divf = (immr->im_clkrst.car_plprcr & PLPRCR_DIVF_MSK);
30 uint mf = ((immr->im_clkrst.car_plprcr & PLPRCR_MF_MSK) >> PLPRCR_MF_SHIFT);
33 vcoout = (CONFIG_SYS_OSC_CLK / (divf + 1)) * (mf + 1) * 2;
34 if(immr->im_clkrst.car_plprcr & PLPRCR_CSRC_MSK) {
35 gd->cpu_clk = vcoout / (2^(((immr->im_clkrst.car_sccr & SCCR_DFNL_MSK) >> SCCR_DFNL_SHIFT) + 1));
37 gd->cpu_clk = vcoout / (2^(immr->im_clkrst.car_sccr & SCCR_DFNH_MSK));
40 #else /* CONFIG_5xx_GCLK_FREQ */
41 gd->bus_clk = CONFIG_5xx_GCLK_FREQ;
42 #endif /* CONFIG_5xx_GCLK_FREQ */
44 if ((immr->im_clkrst.car_sccr & SCCR_EBDF11) == 0) {
45 /* No Bus Divider active */
46 gd->bus_clk = gd->cpu_clk;
48 /* CLKOUT is GCLK / 2 */
49 gd->bus_clk = gd->cpu_clk / 2;