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> |
Ley Foon Tan | ec6f882 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 7 | #include <wait_bit.h> |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/clock_manager.h> |
| 10 | |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 11 | DECLARE_GLOBAL_DATA_PTR; |
| 12 | |
Ley Foon Tan | ec6f882 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 13 | void cm_wait_for_lock(u32 mask) |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 14 | { |
Ley Foon Tan | ec6f882 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 15 | u32 inter_val; |
| 16 | u32 retry = 0; |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 17 | do { |
Ley Foon Tan | ca40f29 | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 18 | #if defined(CONFIG_TARGET_SOCFPGA_GEN5) |
Ley Foon Tan | 2669591 | 2019-11-08 10:38:21 +0800 | [diff] [blame^] | 19 | inter_val = readl(socfpga_get_clkmgr_addr() + |
| 20 | CLKMGR_INTER) & mask; |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 21 | #else |
Ley Foon Tan | 2669591 | 2019-11-08 10:38:21 +0800 | [diff] [blame^] | 22 | inter_val = readl(socfpga_get_clkmgr_addr() + |
| 23 | CLKMGR_STAT) & mask; |
Ley Foon Tan | ca40f29 | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 24 | #endif |
| 25 | /* Wait for stable lock */ |
Marek Vasut | 43e9c40 | 2014-09-16 19:54:32 +0200 | [diff] [blame] | 26 | if (inter_val == mask) |
| 27 | retry++; |
| 28 | else |
| 29 | retry = 0; |
| 30 | if (retry >= 10) |
| 31 | break; |
| 32 | } while (1); |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | /* function to poll in the fsm busy bit */ |
Ley Foon Tan | ec6f882 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 36 | int cm_wait_for_fsm(void) |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 37 | { |
Ley Foon Tan | 2669591 | 2019-11-08 10:38:21 +0800 | [diff] [blame^] | 38 | return wait_for_bit_le32((const void *)(socfpga_get_clkmgr_addr() + |
| 39 | CLKMGR_STAT), CLKMGR_STAT_BUSY, false, 20000, |
| 40 | false); |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | int set_cpu_clk_info(void) |
| 44 | { |
Marek Vasut | d430d9a | 2018-08-06 21:47:50 +0200 | [diff] [blame] | 45 | #if defined(CONFIG_TARGET_SOCFPGA_GEN5) |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 46 | /* Calculate the clock frequencies required for drivers */ |
| 47 | cm_get_l4_sp_clk_hz(); |
| 48 | cm_get_mmc_controller_clk_hz(); |
Marek Vasut | d430d9a | 2018-08-06 21:47:50 +0200 | [diff] [blame] | 49 | #endif |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 50 | |
| 51 | gd->bd->bi_arm_freq = cm_get_mpu_clk_hz() / 1000000; |
| 52 | gd->bd->bi_dsp_freq = 0; |
Ley Foon Tan | ca40f29 | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 53 | |
| 54 | #if defined(CONFIG_TARGET_SOCFPGA_GEN5) |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 55 | gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000; |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 56 | #else |
Ley Foon Tan | ca40f29 | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 57 | gd->bd->bi_ddr_freq = 0; |
| 58 | #endif |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
Tom Rini | df09a19 | 2017-12-22 12:19:22 -0500 | [diff] [blame] | 63 | #ifndef CONFIG_SPL_BUILD |
| 64 | static int do_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 65 | { |
| 66 | cm_print_clock_quick_summary(); |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | U_BOOT_CMD( |
| 71 | clocks, CONFIG_SYS_MAXARGS, 1, do_showclocks, |
| 72 | "display clocks", |
| 73 | "" |
| 74 | ); |
Tom Rini | df09a19 | 2017-12-22 12:19:22 -0500 | [diff] [blame] | 75 | #endif |