2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-03-05 04:13:53 +00:00
|
|
|
/*
|
2017-04-25 18:44:33 +00:00
|
|
|
* Copyright (C) 2013-2017 Altera Corporation <www.altera.com>
|
2014-03-05 04:13:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2017-04-25 18:44:33 +00:00
|
|
|
#include <wait_bit.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2014-03-05 04:13:53 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/clock_manager.h>
|
|
|
|
|
2014-09-08 12:08:45 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2017-04-25 18:44:33 +00:00
|
|
|
void cm_wait_for_lock(u32 mask)
|
2014-03-05 04:13:53 +00:00
|
|
|
{
|
2017-04-25 18:44:33 +00:00
|
|
|
u32 inter_val;
|
|
|
|
u32 retry = 0;
|
2014-03-05 04:13:53 +00:00
|
|
|
do {
|
2017-04-25 18:44:39 +00:00
|
|
|
#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
|
2019-11-08 02:38:21 +00:00
|
|
|
inter_val = readl(socfpga_get_clkmgr_addr() +
|
|
|
|
CLKMGR_INTER) & mask;
|
2018-05-18 14:05:22 +00:00
|
|
|
#else
|
2019-11-08 02:38:21 +00:00
|
|
|
inter_val = readl(socfpga_get_clkmgr_addr() +
|
|
|
|
CLKMGR_STAT) & mask;
|
2017-04-25 18:44:39 +00:00
|
|
|
#endif
|
|
|
|
/* Wait for stable lock */
|
2014-09-16 17:54:32 +00:00
|
|
|
if (inter_val == mask)
|
|
|
|
retry++;
|
|
|
|
else
|
|
|
|
retry = 0;
|
|
|
|
if (retry >= 10)
|
|
|
|
break;
|
|
|
|
} while (1);
|
2014-03-05 04:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* function to poll in the fsm busy bit */
|
2017-04-25 18:44:33 +00:00
|
|
|
int cm_wait_for_fsm(void)
|
2014-03-05 04:13:53 +00:00
|
|
|
{
|
2019-11-08 02:38:21 +00:00
|
|
|
return wait_for_bit_le32((const void *)(socfpga_get_clkmgr_addr() +
|
|
|
|
CLKMGR_STAT), CLKMGR_STAT_BUSY, false, 20000,
|
|
|
|
false);
|
2014-09-08 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int set_cpu_clk_info(void)
|
|
|
|
{
|
2018-08-06 19:47:50 +00:00
|
|
|
#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
|
2014-09-08 12:08:45 +00:00
|
|
|
/* Calculate the clock frequencies required for drivers */
|
|
|
|
cm_get_l4_sp_clk_hz();
|
|
|
|
cm_get_mmc_controller_clk_hz();
|
2018-08-06 19:47:50 +00:00
|
|
|
#endif
|
2014-09-08 12:08:45 +00:00
|
|
|
|
|
|
|
gd->bd->bi_arm_freq = cm_get_mpu_clk_hz() / 1000000;
|
|
|
|
gd->bd->bi_dsp_freq = 0;
|
2017-04-25 18:44:39 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
|
2014-09-08 12:08:45 +00:00
|
|
|
gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000;
|
2018-05-18 14:05:22 +00:00
|
|
|
#else
|
2017-04-25 18:44:39 +00:00
|
|
|
gd->bd->bi_ddr_freq = 0;
|
|
|
|
#endif
|
2014-09-08 12:08:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-22 17:19:22 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_showclocks(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2014-09-08 12:08:45 +00:00
|
|
|
{
|
|
|
|
cm_print_clock_quick_summary();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
clocks, CONFIG_SYS_MAXARGS, 1, do_showclocks,
|
|
|
|
"display clocks",
|
|
|
|
""
|
|
|
|
);
|
2017-12-22 17:19:22 +00:00
|
|
|
#endif
|