blob: be426a5cfb8fa51ae296c3cec45e55ee7a65fef9 [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>
Siew Chin Limfa2cc492021-03-24 17:16:49 +08007#include <asm/arch/clock_manager.h>
8#include <asm/arch/system_manager.h>
9#include <asm/global_data.h>
10#include <asm/io.h>
Simon Glassed38aef2020-05-10 11:40:03 -060011#include <command.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Ley Foon Tanec6f8822017-04-26 02:44:33 +080013#include <wait_bit.h>
Chin Liang Seecb350602014-03-04 22:13:53 -060014
Pavel Machek7c8d5a62014-09-08 14:08:45 +020015DECLARE_GLOBAL_DATA_PTR;
16
Ley Foon Tanec6f8822017-04-26 02:44:33 +080017void cm_wait_for_lock(u32 mask)
Chin Liang Seecb350602014-03-04 22:13:53 -060018{
Ley Foon Tanec6f8822017-04-26 02:44:33 +080019 u32 inter_val;
20 u32 retry = 0;
Chin Liang Seecb350602014-03-04 22:13:53 -060021 do {
Ley Foon Tanca40f292017-04-26 02:44:39 +080022#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Ley Foon Tan26695912019-11-08 10:38:21 +080023 inter_val = readl(socfpga_get_clkmgr_addr() +
24 CLKMGR_INTER) & mask;
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080025#else
Ley Foon Tan26695912019-11-08 10:38:21 +080026 inter_val = readl(socfpga_get_clkmgr_addr() +
27 CLKMGR_STAT) & mask;
Ley Foon Tanca40f292017-04-26 02:44:39 +080028#endif
29 /* Wait for stable lock */
Marek Vasut43e9c402014-09-16 19:54:32 +020030 if (inter_val == mask)
31 retry++;
32 else
33 retry = 0;
34 if (retry >= 10)
35 break;
36 } while (1);
Chin Liang Seecb350602014-03-04 22:13:53 -060037}
38
39/* function to poll in the fsm busy bit */
Ley Foon Tanec6f8822017-04-26 02:44:33 +080040int cm_wait_for_fsm(void)
Pavel Machek7c8d5a62014-09-08 14:08:45 +020041{
Ley Foon Tan26695912019-11-08 10:38:21 +080042 return wait_for_bit_le32((const void *)(socfpga_get_clkmgr_addr() +
43 CLKMGR_STAT), CLKMGR_STAT_BUSY, false, 20000,
44 false);
Pavel Machek7c8d5a62014-09-08 14:08:45 +020045}
46
47int set_cpu_clk_info(void)
48{
Marek Vasutd430d9a2018-08-06 21:47:50 +020049#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Pavel Machek7c8d5a62014-09-08 14:08:45 +020050 /* Calculate the clock frequencies required for drivers */
51 cm_get_l4_sp_clk_hz();
52 cm_get_mmc_controller_clk_hz();
Marek Vasutd430d9a2018-08-06 21:47:50 +020053#endif
Pavel Machek7c8d5a62014-09-08 14:08:45 +020054
55 gd->bd->bi_arm_freq = cm_get_mpu_clk_hz() / 1000000;
56 gd->bd->bi_dsp_freq = 0;
Ley Foon Tanca40f292017-04-26 02:44:39 +080057
58#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Pavel Machek7c8d5a62014-09-08 14:08:45 +020059 gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000;
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080060#else
Ley Foon Tanca40f292017-04-26 02:44:39 +080061 gd->bd->bi_ddr_freq = 0;
62#endif
Pavel Machek7c8d5a62014-09-08 14:08:45 +020063
64 return 0;
65}
66
Siew Chin Limfa2cc492021-03-24 17:16:49 +080067#if IS_ENABLED(CONFIG_TARGET_SOCFPGA_SOC64)
68unsigned int cm_get_qspi_controller_clk_hz(void)
69{
70 return readl(socfpga_get_sysmgr_addr() +
71 SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
72}
73#endif
74
Tom Rinidf09a192017-12-22 12:19:22 -050075#ifndef CONFIG_SPL_BUILD
Simon Glassed38aef2020-05-10 11:40:03 -060076static int do_showclocks(struct cmd_tbl *cmdtp, int flag, int argc,
77 char *const argv[])
Pavel Machek7c8d5a62014-09-08 14:08:45 +020078{
79 cm_print_clock_quick_summary();
80 return 0;
81}
82
83U_BOOT_CMD(
84 clocks, CONFIG_SYS_MAXARGS, 1, do_showclocks,
85 "display clocks",
86 ""
87);
Tom Rinidf09a192017-12-22 12:19:22 -050088#endif