Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 1 | /* |
Ley Foon Tan | ec6f882 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 2 | * Copyright (C) 2013-2017 Altera Corporation <www.altera.com> |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Ley Foon Tan | ec6f882 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 8 | #include <wait_bit.h> |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/clock_manager.h> |
| 11 | |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 14 | static const struct socfpga_clock_manager *clock_manager_base = |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 15 | (struct socfpga_clock_manager *)SOCFPGA_CLKMGR_ADDRESS; |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 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) |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 23 | inter_val = readl(&clock_manager_base->inter) & mask; |
Ley Foon Tan | ca40f29 | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 24 | #elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10) |
| 25 | inter_val = readl(&clock_manager_base->stat) & mask; |
| 26 | #endif |
| 27 | /* Wait for stable lock */ |
Marek Vasut | 43e9c40 | 2014-09-16 19:54:32 +0200 | [diff] [blame] | 28 | if (inter_val == mask) |
| 29 | retry++; |
| 30 | else |
| 31 | retry = 0; |
| 32 | if (retry >= 10) |
| 33 | break; |
| 34 | } while (1); |
Chin Liang See | cb35060 | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /* function to poll in the fsm busy bit */ |
Ley Foon Tan | ec6f882 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 38 | int cm_wait_for_fsm(void) |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 39 | { |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 40 | return wait_for_bit_le32(&clock_manager_base->stat, |
| 41 | CLKMGR_STAT_BUSY, false, 20000, false); |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | int 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 Tan | ca40f29 | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 52 | |
| 53 | #if defined(CONFIG_TARGET_SOCFPGA_GEN5) |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 54 | gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000; |
Ley Foon Tan | ca40f29 | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 55 | #elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10) |
| 56 | gd->bd->bi_ddr_freq = 0; |
| 57 | #endif |
Pavel Machek | 7c8d5a6 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
Tom Rini | df09a19 | 2017-12-22 12:19:22 -0500 | [diff] [blame] | 62 | #ifndef CONFIG_SPL_BUILD |
| 63 | 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] | 64 | { |
| 65 | cm_print_clock_quick_summary(); |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | U_BOOT_CMD( |
| 70 | clocks, CONFIG_SYS_MAXARGS, 1, do_showclocks, |
| 71 | "display clocks", |
| 72 | "" |
| 73 | ); |
Tom Rini | df09a19 | 2017-12-22 12:19:22 -0500 | [diff] [blame] | 74 | #endif |