Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2016-2018 Intel Corporation <www.intel.com> |
| 4 | * |
| 5 | */ |
| 6 | |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 7 | #include <asm/arch/clock_manager.h> |
| 8 | #include <asm/io.h> |
Siew Chin Lim | 954d599 | 2021-03-24 13:11:34 +0800 | [diff] [blame] | 9 | #include <asm/arch/handoff_soc64.h> |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 10 | #include <asm/arch/system_manager.h> |
| 11 | |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 12 | const struct cm_config * const cm_get_default_config(void) |
| 13 | { |
Chee Hong Ang | 3896901 | 2020-12-24 18:21:10 +0800 | [diff] [blame] | 14 | #ifdef CONFIG_SPL_BUILD |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 15 | struct cm_config *cm_handoff_cfg = (struct cm_config *) |
Siew Chin Lim | 954d599 | 2021-03-24 13:11:34 +0800 | [diff] [blame] | 16 | (SOC64_HANDOFF_CLOCK + SOC64_HANDOFF_OFFSET_DATA); |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 17 | u32 *conversion = (u32 *)cm_handoff_cfg; |
| 18 | u32 i; |
Siew Chin Lim | 954d599 | 2021-03-24 13:11:34 +0800 | [diff] [blame] | 19 | u32 handoff_clk = readl(SOC64_HANDOFF_CLOCK); |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 20 | |
Siew Chin Lim | 954d599 | 2021-03-24 13:11:34 +0800 | [diff] [blame] | 21 | if (swab32(handoff_clk) == SOC64_HANDOFF_MAGIC_CLOCK) { |
| 22 | writel(swab32(handoff_clk), SOC64_HANDOFF_CLOCK); |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 23 | for (i = 0; i < (sizeof(*cm_handoff_cfg) / sizeof(u32)); i++) |
| 24 | conversion[i] = swab32(conversion[i]); |
| 25 | return cm_handoff_cfg; |
Siew Chin Lim | 954d599 | 2021-03-24 13:11:34 +0800 | [diff] [blame] | 26 | } else if (handoff_clk == SOC64_HANDOFF_MAGIC_CLOCK) { |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 27 | return cm_handoff_cfg; |
| 28 | } |
Chee Hong Ang | 3896901 | 2020-12-24 18:21:10 +0800 | [diff] [blame] | 29 | #endif |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 30 | return NULL; |
| 31 | } |
| 32 | |
| 33 | const unsigned int cm_get_osc_clk_hz(void) |
| 34 | { |
| 35 | #ifdef CONFIG_SPL_BUILD |
Ley Foon Tan | 0767f8d | 2019-11-27 15:55:25 +0800 | [diff] [blame] | 36 | |
Siew Chin Lim | 954d599 | 2021-03-24 13:11:34 +0800 | [diff] [blame] | 37 | u32 clock = readl(SOC64_HANDOFF_CLOCK_OSC); |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 38 | |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 39 | writel(clock, |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 40 | socfpga_get_sysmgr_addr() + SYSMGR_SOC64_BOOT_SCRATCH_COLD1); |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 41 | #endif |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 42 | return readl(socfpga_get_sysmgr_addr() + |
| 43 | SYSMGR_SOC64_BOOT_SCRATCH_COLD1); |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | const unsigned int cm_get_intosc_clk_hz(void) |
| 47 | { |
| 48 | return CLKMGR_INTOSC_HZ; |
| 49 | } |
| 50 | |
| 51 | const unsigned int cm_get_fpga_clk_hz(void) |
| 52 | { |
| 53 | #ifdef CONFIG_SPL_BUILD |
Siew Chin Lim | 954d599 | 2021-03-24 13:11:34 +0800 | [diff] [blame] | 54 | u32 clock = readl(SOC64_HANDOFF_CLOCK_FPGA); |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 55 | |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 56 | writel(clock, |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 57 | socfpga_get_sysmgr_addr() + SYSMGR_SOC64_BOOT_SCRATCH_COLD2); |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 58 | #endif |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 59 | return readl(socfpga_get_sysmgr_addr() + |
| 60 | SYSMGR_SOC64_BOOT_SCRATCH_COLD2); |
Ley Foon Tan | 6751e7d | 2018-05-18 22:05:22 +0800 | [diff] [blame] | 61 | } |