Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 2 | /* |
Ley Foon Tan | ec6f882 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 3 | * Copyright (C) 2013-2017 Altera Corporation <www.altera.com> |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Siew Chin Lim | fa2cc49 | 2021-03-24 17:16:49 +0800 | [diff] [blame^] | 7 | #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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 11 | #include <command.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Ley Foon Tan | ec6f882 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 13 | #include <wait_bit.h> |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 14 | |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Ley Foon Tan | ec6f882 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 17 | void cm_wait_for_lock(u32 mask) |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 18 | { |
Ley Foon Tan | ec6f882 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 19 | u32 inter_val; |
| 20 | u32 retry = 0; |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 21 | do { |
Ley Foon Tan | ca40f29 | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 22 | #if defined(CONFIG_TARGET_SOCFPGA_GEN5) |
Ley Foon Tan | 2669591 | 2019-11-08 10:38:21 +0800 | [diff] [blame] | 23 | inter_val = readl(socfpga_get_clkmgr_addr() + |
| 24 | CLKMGR_INTER) & mask; |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 25 | #else |
Ley Foon Tan | 2669591 | 2019-11-08 10:38:21 +0800 | [diff] [blame] | 26 | inter_val = readl(socfpga_get_clkmgr_addr() + |
| 27 | CLKMGR_STAT) & mask; |
Ley Foon Tan | ca40f29 | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 28 | #endif |
| 29 | /* Wait for stable lock */ |
Marek Vasut | 43e9c40 | 2014-09-16 19:54:32 +0200 | [diff] [blame] | 30 | if (inter_val == mask) |
| 31 | retry++; |
| 32 | else |
| 33 | retry = 0; |
| 34 | if (retry >= 10) |
| 35 | break; |
| 36 | } while (1); |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /* function to poll in the fsm busy bit */ |
Ley Foon Tan | ec6f882 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 40 | int cm_wait_for_fsm(void) |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 41 | { |
Ley Foon Tan | 2669591 | 2019-11-08 10:38:21 +0800 | [diff] [blame] | 42 | return wait_for_bit_le32((const void *)(socfpga_get_clkmgr_addr() + |
| 43 | CLKMGR_STAT), CLKMGR_STAT_BUSY, false, 20000, |
| 44 | false); |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | int set_cpu_clk_info(void) |
| 48 | { |
Marek Vasut | d430d9a | 2018-08-06 21:47:50 +0200 | [diff] [blame] | 49 | #if defined(CONFIG_TARGET_SOCFPGA_GEN5) |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 50 | /* Calculate the clock frequencies required for drivers */ |
| 51 | cm_get_l4_sp_clk_hz(); |
| 52 | cm_get_mmc_controller_clk_hz(); |
Marek Vasut | d430d9a | 2018-08-06 21:47:50 +0200 | [diff] [blame] | 53 | #endif |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 54 | |
| 55 | gd->bd->bi_arm_freq = cm_get_mpu_clk_hz() / 1000000; |
| 56 | gd->bd->bi_dsp_freq = 0; |
Ley Foon Tan | ca40f29 | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 57 | |
| 58 | #if defined(CONFIG_TARGET_SOCFPGA_GEN5) |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 59 | gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000; |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 60 | #else |
Ley Foon Tan | ca40f29 | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 61 | gd->bd->bi_ddr_freq = 0; |
| 62 | #endif |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
Siew Chin Lim | fa2cc49 | 2021-03-24 17:16:49 +0800 | [diff] [blame^] | 67 | #if IS_ENABLED(CONFIG_TARGET_SOCFPGA_SOC64) |
| 68 | unsigned 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 Rini | df09a19 | 2017-12-22 12:19:22 -0500 | [diff] [blame] | 75 | #ifndef CONFIG_SPL_BUILD |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 76 | static int do_showclocks(struct cmd_tbl *cmdtp, int flag, int argc, |
| 77 | char *const argv[]) |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 78 | { |
| 79 | cm_print_clock_quick_summary(); |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | U_BOOT_CMD( |
| 84 | clocks, CONFIG_SYS_MAXARGS, 1, do_showclocks, |
| 85 | "display clocks", |
| 86 | "" |
| 87 | ); |
Tom Rini | df09a19 | 2017-12-22 12:19:22 -0500 | [diff] [blame] | 88 | #endif |