blob: a4a97b6a0fcf48cfb11a51d196c89e1fa408201c [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>
Simon Glassed38aef2020-05-10 11:40:03 -06007#include <command.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Ley Foon Tanec6f8822017-04-26 02:44:33 +08009#include <wait_bit.h>
Chin Liang Seecb350602014-03-04 22:13:53 -060010#include <asm/io.h>
11#include <asm/arch/clock_manager.h>
12
Pavel Machek7c8d5a62014-09-08 14:08:45 +020013DECLARE_GLOBAL_DATA_PTR;
14
Ley Foon Tanec6f8822017-04-26 02:44:33 +080015void cm_wait_for_lock(u32 mask)
Chin Liang Seecb350602014-03-04 22:13:53 -060016{
Ley Foon Tanec6f8822017-04-26 02:44:33 +080017 u32 inter_val;
18 u32 retry = 0;
Chin Liang Seecb350602014-03-04 22:13:53 -060019 do {
Ley Foon Tanca40f292017-04-26 02:44:39 +080020#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Ley Foon Tan26695912019-11-08 10:38:21 +080021 inter_val = readl(socfpga_get_clkmgr_addr() +
22 CLKMGR_INTER) & mask;
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080023#else
Ley Foon Tan26695912019-11-08 10:38:21 +080024 inter_val = readl(socfpga_get_clkmgr_addr() +
25 CLKMGR_STAT) & mask;
Ley Foon Tanca40f292017-04-26 02:44:39 +080026#endif
27 /* Wait for stable lock */
Marek Vasut43e9c402014-09-16 19:54:32 +020028 if (inter_val == mask)
29 retry++;
30 else
31 retry = 0;
32 if (retry >= 10)
33 break;
34 } while (1);
Chin Liang Seecb350602014-03-04 22:13:53 -060035}
36
37/* function to poll in the fsm busy bit */
Ley Foon Tanec6f8822017-04-26 02:44:33 +080038int cm_wait_for_fsm(void)
Pavel Machek7c8d5a62014-09-08 14:08:45 +020039{
Ley Foon Tan26695912019-11-08 10:38:21 +080040 return wait_for_bit_le32((const void *)(socfpga_get_clkmgr_addr() +
41 CLKMGR_STAT), CLKMGR_STAT_BUSY, false, 20000,
42 false);
Pavel Machek7c8d5a62014-09-08 14:08:45 +020043}
44
45int set_cpu_clk_info(void)
46{
Marek Vasutd430d9a2018-08-06 21:47:50 +020047#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Pavel Machek7c8d5a62014-09-08 14:08:45 +020048 /* Calculate the clock frequencies required for drivers */
49 cm_get_l4_sp_clk_hz();
50 cm_get_mmc_controller_clk_hz();
Marek Vasutd430d9a2018-08-06 21:47:50 +020051#endif
Pavel Machek7c8d5a62014-09-08 14:08:45 +020052
53 gd->bd->bi_arm_freq = cm_get_mpu_clk_hz() / 1000000;
54 gd->bd->bi_dsp_freq = 0;
Ley Foon Tanca40f292017-04-26 02:44:39 +080055
56#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Pavel Machek7c8d5a62014-09-08 14:08:45 +020057 gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000;
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080058#else
Ley Foon Tanca40f292017-04-26 02:44:39 +080059 gd->bd->bi_ddr_freq = 0;
60#endif
Pavel Machek7c8d5a62014-09-08 14:08:45 +020061
62 return 0;
63}
64
Tom Rinidf09a192017-12-22 12:19:22 -050065#ifndef CONFIG_SPL_BUILD
Simon Glassed38aef2020-05-10 11:40:03 -060066static int do_showclocks(struct cmd_tbl *cmdtp, int flag, int argc,
67 char *const argv[])
Pavel Machek7c8d5a62014-09-08 14:08:45 +020068{
69 cm_print_clock_quick_summary();
70 return 0;
71}
72
73U_BOOT_CMD(
74 clocks, CONFIG_SYS_MAXARGS, 1, do_showclocks,
75 "display clocks",
76 ""
77);
Tom Rinidf09a192017-12-22 12:19:22 -050078#endif