blob: dbb10ecb681cec7795a88d15a32f9f9f35488e3c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Chin Liang Seecb350602014-03-04 22:13:53 -06002/*
Ley Foon Tanec6f8822017-04-26 02:44:33 +08003 * Copyright (C) 2013-2017 Altera Corporation <www.altera.com>
Chin Liang Seecb350602014-03-04 22:13:53 -06004 */
5
6#include <common.h>
Ley Foon Tanec6f8822017-04-26 02:44:33 +08007#include <wait_bit.h>
Chin Liang Seecb350602014-03-04 22:13:53 -06008#include <asm/io.h>
9#include <asm/arch/clock_manager.h>
10
Pavel Machek7c8d5a62014-09-08 14:08:45 +020011DECLARE_GLOBAL_DATA_PTR;
12
Ley Foon Tanec6f8822017-04-26 02:44:33 +080013void cm_wait_for_lock(u32 mask)
Chin Liang Seecb350602014-03-04 22:13:53 -060014{
Ley Foon Tanec6f8822017-04-26 02:44:33 +080015 u32 inter_val;
16 u32 retry = 0;
Chin Liang Seecb350602014-03-04 22:13:53 -060017 do {
Ley Foon Tanca40f292017-04-26 02:44:39 +080018#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Ley Foon Tan26695912019-11-08 10:38:21 +080019 inter_val = readl(socfpga_get_clkmgr_addr() +
20 CLKMGR_INTER) & mask;
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080021#else
Ley Foon Tan26695912019-11-08 10:38:21 +080022 inter_val = readl(socfpga_get_clkmgr_addr() +
23 CLKMGR_STAT) & mask;
Ley Foon Tanca40f292017-04-26 02:44:39 +080024#endif
25 /* Wait for stable lock */
Marek Vasut43e9c402014-09-16 19:54:32 +020026 if (inter_val == mask)
27 retry++;
28 else
29 retry = 0;
30 if (retry >= 10)
31 break;
32 } while (1);
Chin Liang Seecb350602014-03-04 22:13:53 -060033}
34
35/* function to poll in the fsm busy bit */
Ley Foon Tanec6f8822017-04-26 02:44:33 +080036int cm_wait_for_fsm(void)
Pavel Machek7c8d5a62014-09-08 14:08:45 +020037{
Ley Foon Tan26695912019-11-08 10:38:21 +080038 return wait_for_bit_le32((const void *)(socfpga_get_clkmgr_addr() +
39 CLKMGR_STAT), CLKMGR_STAT_BUSY, false, 20000,
40 false);
Pavel Machek7c8d5a62014-09-08 14:08:45 +020041}
42
43int set_cpu_clk_info(void)
44{
Marek Vasutd430d9a2018-08-06 21:47:50 +020045#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Pavel Machek7c8d5a62014-09-08 14:08:45 +020046 /* Calculate the clock frequencies required for drivers */
47 cm_get_l4_sp_clk_hz();
48 cm_get_mmc_controller_clk_hz();
Marek Vasutd430d9a2018-08-06 21:47:50 +020049#endif
Pavel Machek7c8d5a62014-09-08 14:08:45 +020050
51 gd->bd->bi_arm_freq = cm_get_mpu_clk_hz() / 1000000;
52 gd->bd->bi_dsp_freq = 0;
Ley Foon Tanca40f292017-04-26 02:44:39 +080053
54#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Pavel Machek7c8d5a62014-09-08 14:08:45 +020055 gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000;
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080056#else
Ley Foon Tanca40f292017-04-26 02:44:39 +080057 gd->bd->bi_ddr_freq = 0;
58#endif
Pavel Machek7c8d5a62014-09-08 14:08:45 +020059
60 return 0;
61}
62
Tom Rinidf09a192017-12-22 12:19:22 -050063#ifndef CONFIG_SPL_BUILD
64static int do_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Pavel Machek7c8d5a62014-09-08 14:08:45 +020065{
66 cm_print_clock_quick_summary();
67 return 0;
68}
69
70U_BOOT_CMD(
71 clocks, CONFIG_SYS_MAXARGS, 1, do_showclocks,
72 "display clocks",
73 ""
74);
Tom Rinidf09a192017-12-22 12:19:22 -050075#endif