Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 2 | /* |
Ley Foon Tan | de77811 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 3 | * Copyright (C) 2013-2017 Altera Corporation <www.altera.com> |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Ley Foon Tan | de77811 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 7 | #include <wait_bit.h> |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/clock_manager.h> |
| 10 | |
Pavel Machek | a832ddb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 11 | DECLARE_GLOBAL_DATA_PTR; |
| 12 | |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 13 | static const struct socfpga_clock_manager *clock_manager_base = |
Pavel Machek | a832ddb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 14 | (struct socfpga_clock_manager *)SOCFPGA_CLKMGR_ADDRESS; |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 15 | |
Ley Foon Tan | de77811 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 16 | void cm_wait_for_lock(u32 mask) |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 17 | { |
Ley Foon Tan | de77811 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 18 | u32 inter_val; |
| 19 | u32 retry = 0; |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 20 | do { |
Ley Foon Tan | 177ba1f | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 21 | #if defined(CONFIG_TARGET_SOCFPGA_GEN5) |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 22 | inter_val = readl(&clock_manager_base->inter) & mask; |
Ley Foon Tan | 508791a | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 23 | #else |
Ley Foon Tan | 177ba1f | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 24 | inter_val = readl(&clock_manager_base->stat) & mask; |
| 25 | #endif |
| 26 | /* Wait for stable lock */ |
Marek Vasut | 036ba54 | 2014-09-16 19:54:32 +0200 | [diff] [blame] | 27 | if (inter_val == mask) |
| 28 | retry++; |
| 29 | else |
| 30 | retry = 0; |
| 31 | if (retry >= 10) |
| 32 | break; |
| 33 | } while (1); |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /* function to poll in the fsm busy bit */ |
Ley Foon Tan | de77811 | 2017-04-26 02:44:33 +0800 | [diff] [blame] | 37 | int cm_wait_for_fsm(void) |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 38 | { |
Álvaro Fernández Rojas | 4826350 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 39 | return wait_for_bit_le32(&clock_manager_base->stat, |
| 40 | CLKMGR_STAT_BUSY, false, 20000, false); |
Pavel Machek | a832ddb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | int set_cpu_clk_info(void) |
| 44 | { |
Marek Vasut | 49e508e | 2018-08-06 21:47:50 +0200 | [diff] [blame] | 45 | #if defined(CONFIG_TARGET_SOCFPGA_GEN5) |
Pavel Machek | a832ddb | 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 | 49e508e | 2018-08-06 21:47:50 +0200 | [diff] [blame] | 49 | #endif |
Pavel Machek | a832ddb | 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 | 177ba1f | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 53 | |
| 54 | #if defined(CONFIG_TARGET_SOCFPGA_GEN5) |
Pavel Machek | a832ddb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 55 | gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000; |
Ley Foon Tan | 508791a | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 56 | #else |
Ley Foon Tan | 177ba1f | 2017-04-26 02:44:39 +0800 | [diff] [blame] | 57 | gd->bd->bi_ddr_freq = 0; |
| 58 | #endif |
Pavel Machek | a832ddb | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
Tom Rini | b4b9814 | 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 | a832ddb | 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 | b4b9814 | 2017-12-22 12:19:22 -0500 | [diff] [blame] | 75 | #endif |