blob: c740c9f648d2165a0f96a02f4e577dac10ed41ca [file] [log] [blame]
Chin Liang Seeddfeb0a2014-03-04 22:13:53 -06001/*
Ley Foon Tande778112017-04-26 02:44:33 +08002 * Copyright (C) 2013-2017 Altera Corporation <www.altera.com>
Chin Liang Seeddfeb0a2014-03-04 22:13:53 -06003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Ley Foon Tande778112017-04-26 02:44:33 +08008#include <wait_bit.h>
Chin Liang Seeddfeb0a2014-03-04 22:13:53 -06009#include <asm/io.h>
10#include <asm/arch/clock_manager.h>
11
Pavel Macheka832ddb2014-09-08 14:08:45 +020012DECLARE_GLOBAL_DATA_PTR;
13
Chin Liang Seeddfeb0a2014-03-04 22:13:53 -060014static const struct socfpga_clock_manager *clock_manager_base =
Pavel Macheka832ddb2014-09-08 14:08:45 +020015 (struct socfpga_clock_manager *)SOCFPGA_CLKMGR_ADDRESS;
Chin Liang Seeddfeb0a2014-03-04 22:13:53 -060016
Ley Foon Tande778112017-04-26 02:44:33 +080017void cm_wait_for_lock(u32 mask)
Chin Liang Seeddfeb0a2014-03-04 22:13:53 -060018{
Ley Foon Tande778112017-04-26 02:44:33 +080019 u32 inter_val;
20 u32 retry = 0;
Chin Liang Seeddfeb0a2014-03-04 22:13:53 -060021 do {
Ley Foon Tan177ba1f2017-04-26 02:44:39 +080022#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Chin Liang Seeddfeb0a2014-03-04 22:13:53 -060023 inter_val = readl(&clock_manager_base->inter) & mask;
Ley Foon Tan177ba1f2017-04-26 02:44:39 +080024#elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10)
25 inter_val = readl(&clock_manager_base->stat) & mask;
26#endif
27 /* Wait for stable lock */
Marek Vasut036ba542014-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 Seeddfeb0a2014-03-04 22:13:53 -060035}
36
37/* function to poll in the fsm busy bit */
Ley Foon Tande778112017-04-26 02:44:33 +080038int cm_wait_for_fsm(void)
Chin Liang Seeddfeb0a2014-03-04 22:13:53 -060039{
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +010040 return wait_for_bit_le32(&clock_manager_base->stat,
41 CLKMGR_STAT_BUSY, false, 20000, false);
Pavel Macheka832ddb2014-09-08 14:08:45 +020042}
43
44int set_cpu_clk_info(void)
45{
46 /* Calculate the clock frequencies required for drivers */
47 cm_get_l4_sp_clk_hz();
48 cm_get_mmc_controller_clk_hz();
49
50 gd->bd->bi_arm_freq = cm_get_mpu_clk_hz() / 1000000;
51 gd->bd->bi_dsp_freq = 0;
Ley Foon Tan177ba1f2017-04-26 02:44:39 +080052
53#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Pavel Macheka832ddb2014-09-08 14:08:45 +020054 gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000;
Ley Foon Tan177ba1f2017-04-26 02:44:39 +080055#elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10)
56 gd->bd->bi_ddr_freq = 0;
57#endif
Pavel Macheka832ddb2014-09-08 14:08:45 +020058
59 return 0;
60}
61
62int do_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
63{
64 cm_print_clock_quick_summary();
65 return 0;
66}
67
68U_BOOT_CMD(
69 clocks, CONFIG_SYS_MAXARGS, 1, do_showclocks,
70 "display clocks",
71 ""
72);