Browse Source
Get CPU frequency and update the timer init div with it. The timer is vary based on the CPU frequency instead of hardcoded. Signed-off-by: Jit Loon Lim <jit.loon.lim@intel.com> Signed-off-by: Sieu Mun Tang <sieu.mun.tang@intel.com> Change-Id: Ibfaa47fb7a25176eebf06f4828bf9729d56f12edpull/1994/merge
Sieu Mun Tang
2 years ago
9 changed files with 188 additions and 10 deletions
@ -0,0 +1,57 @@ |
|||
/*
|
|||
* Copyright (c) 2019-2023, Intel Corporation. All rights reserved. |
|||
* |
|||
* SPDX-License-Identifier: BSD-3-Clause |
|||
*/ |
|||
|
|||
#ifndef CLOCKMANAGER_H |
|||
#define CLOCKMANAGER_H |
|||
|
|||
#include "socfpga_handoff.h" |
|||
|
|||
/* MACRO DEFINITION */ |
|||
#define SOCFPGA_GLOBAL_TIMER 0xffd01000 |
|||
#define SOCFPGA_GLOBAL_TIMER_EN 0x3 |
|||
|
|||
#define CLKMGR_PLLGLOB_VCO_PSRC_MASK GENMASK(17, 16) |
|||
#define CLKMGR_PLLGLOB_VCO_PSRC_OFFSET 16 |
|||
#define CLKMGR_PLLDIV_FDIV_MASK GENMASK(16, 8) |
|||
#define CLKMGR_PLLDIV_FDIV_OFFSET 8 |
|||
#define CLKMGR_PLLDIV_REFCLKDIV_MASK GENMASK(5, 0) |
|||
#define CLKMGR_PLLDIV_REFCLKDIV_OFFSET 0 |
|||
#define CLKMGR_PLLDIV_OUTDIV_QDIV_MASK GENMASK(26, 24) |
|||
#define CLKMGR_PLLDIV_OUTDIV_QDIV_OFFSET 24 |
|||
|
|||
#define CLKMGR_PLLOUTDIV_C1CNT_MASK GENMASK(12, 8) |
|||
#define CLKMGR_PLLOUTDIV_C1CNT_OFFSET 8 |
|||
#define CLKMGR_PLLDIV_OUTDIV_QDIV_MASK GENMASK(26, 24) |
|||
#define CLKMGR_PLLDIV_OUTDIV_QDIV_OFFSET 24 |
|||
#define CLKMGR_CLKSRC_MASK GENMASK(18, 16) |
|||
#define CLKMGR_CLKSRC_OFFSET 16 |
|||
#define CLKMGR_NOCDIV_DIVIDER_MASK GENMASK(1, 0) |
|||
#define CLKMGR_NOCDIV_L4MAIN_OFFSET 0 |
|||
|
|||
#define CLKMGR_INTOSC_HZ 400000000 |
|||
#define CLKMGR_VCO_PSRC_EOSC1 0 |
|||
#define CLKMGR_VCO_PSRC_INTOSC 1 |
|||
#define CLKMGR_VCO_PSRC_F2S 2 |
|||
#define CLKMGR_CLKSRC_MAIN 0 |
|||
#define CLKMGR_CLKSRC_PER 1 |
|||
|
|||
#define CLKMGR_N5X_BASE 0xffd10000 |
|||
#define CLKMGR_MAINPLL_NOCCLK 0x40 |
|||
#define CLKMGR_MAINPLL_NOCDIV 0x44 |
|||
#define CLKMGR_MAINPLL_PLLGLOB 0x48 |
|||
#define CLKMGR_MAINPLL_PLLOUTDIV 0x54 |
|||
#define CLKMGR_MAINPLL_PLLDIV 0x50 |
|||
#define CLKMGR_PERPLL_PLLGLOB 0x9c |
|||
#define CLKMGR_PERPLL_PLLDIV 0xa4 |
|||
#define CLKMGR_PERPLL_PLLOUTDIV 0xa8 |
|||
|
|||
/* FUNCTION DEFINITION */ |
|||
uint64_t clk_get_pll_output_hz(void); |
|||
uint64_t get_l4_clk(void); |
|||
uint32_t get_clk_freq(uint32_t psrc_reg); |
|||
uint32_t get_cpu_clk(void); |
|||
|
|||
#endif |
@ -0,0 +1,116 @@ |
|||
/*
|
|||
* Copyright (c) 2019-2023, Intel Corporation. All rights reserved. |
|||
* |
|||
* SPDX-License-Identifier: BSD-3-Clause |
|||
*/ |
|||
|
|||
#include <assert.h> |
|||
#include <errno.h> |
|||
#include <common/debug.h> |
|||
#include <drivers/delay_timer.h> |
|||
#include <lib/mmio.h> |
|||
|
|||
#include "n5x_clock_manager.h" |
|||
#include "socfpga_system_manager.h" |
|||
|
|||
|
|||
uint64_t clk_get_pll_output_hz(void) |
|||
{ |
|||
uint32_t clksrc; |
|||
uint32_t scr_reg; |
|||
uint32_t divf; |
|||
uint32_t divr; |
|||
uint32_t divq; |
|||
uint32_t power = 1; |
|||
uint64_t clock = 0; |
|||
|
|||
clksrc = ((get_clk_freq(CLKMGR_PERPLL_PLLGLOB)) & |
|||
CLKMGR_PLLGLOB_VCO_PSRC_MASK) >> CLKMGR_PLLGLOB_VCO_PSRC_OFFSET; |
|||
|
|||
switch (clksrc) { |
|||
case CLKMGR_VCO_PSRC_EOSC1: |
|||
scr_reg = SOCFPGA_SYSMGR(BOOT_SCRATCH_COLD_1); |
|||
clock = mmio_read_32(scr_reg); |
|||
break; |
|||
|
|||
case CLKMGR_VCO_PSRC_INTOSC: |
|||
clock = CLKMGR_INTOSC_HZ; |
|||
break; |
|||
|
|||
case CLKMGR_VCO_PSRC_F2S: |
|||
scr_reg = SOCFPGA_SYSMGR(BOOT_SCRATCH_COLD_2); |
|||
clock = mmio_read_32(scr_reg); |
|||
break; |
|||
} |
|||
|
|||
divf = ((get_clk_freq(CLKMGR_PERPLL_PLLDIV)) & |
|||
CLKMGR_PLLDIV_FDIV_MASK) >> CLKMGR_PLLDIV_FDIV_OFFSET; |
|||
divr = ((get_clk_freq(CLKMGR_PERPLL_PLLDIV)) & |
|||
CLKMGR_PLLDIV_REFCLKDIV_MASK) >> CLKMGR_PLLDIV_REFCLKDIV_OFFSET; |
|||
divq = ((get_clk_freq(CLKMGR_PERPLL_PLLDIV)) & |
|||
CLKMGR_PLLDIV_OUTDIV_QDIV_MASK) >> CLKMGR_PLLDIV_OUTDIV_QDIV_OFFSET; |
|||
|
|||
while (divq) { |
|||
power *= 2; |
|||
divq--; |
|||
} |
|||
|
|||
return ((clock * 2 * (divf + 1)) / ((divr + 1) * power)); |
|||
} |
|||
|
|||
uint64_t get_l4_clk(void) |
|||
{ |
|||
uint32_t clock = 0; |
|||
uint32_t mainpll_c1cnt; |
|||
uint32_t perpll_c1cnt; |
|||
uint32_t clksrc; |
|||
|
|||
mainpll_c1cnt = ((get_clk_freq(CLKMGR_MAINPLL_PLLOUTDIV)) & |
|||
CLKMGR_PLLOUTDIV_C1CNT_MASK) >> CLKMGR_PLLOUTDIV_C1CNT_OFFSET; |
|||
|
|||
perpll_c1cnt = ((get_clk_freq(CLKMGR_PERPLL_PLLOUTDIV)) & |
|||
CLKMGR_PLLOUTDIV_C1CNT_MASK) >> CLKMGR_PLLOUTDIV_C1CNT_OFFSET; |
|||
|
|||
clksrc = ((get_clk_freq(CLKMGR_MAINPLL_NOCCLK)) & CLKMGR_CLKSRC_MASK) >> |
|||
CLKMGR_CLKSRC_OFFSET; |
|||
|
|||
switch (clksrc) { |
|||
case CLKMGR_CLKSRC_MAIN: |
|||
clock = clk_get_pll_output_hz(); |
|||
clock /= 1 + mainpll_c1cnt; |
|||
break; |
|||
|
|||
case CLKMGR_CLKSRC_PER: |
|||
clock = clk_get_pll_output_hz(); |
|||
clock /= 1 + perpll_c1cnt; |
|||
break; |
|||
|
|||
default: |
|||
return 0; |
|||
} |
|||
|
|||
clock /= BIT(((get_clk_freq(CLKMGR_MAINPLL_NOCDIV)) >> |
|||
CLKMGR_NOCDIV_L4MAIN_OFFSET) & CLKMGR_NOCDIV_DIVIDER_MASK); |
|||
|
|||
return clock; |
|||
} |
|||
|
|||
/* Calculate clock frequency based on parameter */ |
|||
uint32_t get_clk_freq(uint32_t psrc_reg) |
|||
{ |
|||
uint32_t clk_psrc; |
|||
|
|||
clk_psrc = mmio_read_32(CLKMGR_N5X_BASE + psrc_reg); |
|||
|
|||
return clk_psrc; |
|||
} |
|||
|
|||
/* Get cpu freq clock */ |
|||
uint32_t get_cpu_clk(void) |
|||
{ |
|||
uint32_t cpu_clk = 0; |
|||
|
|||
cpu_clk = get_l4_clk()/PLAT_SYS_COUNTER_CONVERT_TO_MHZ; |
|||
|
|||
return cpu_clk; |
|||
} |
Loading…
Reference in new issue