blob: f13581033e6bf28a0cdd4c9fc7d5e163d0e3475c [file] [log] [blame]
Ley Foon Tan6751e7d2018-05-18 22:05:22 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
4 *
5 */
6
Ley Foon Tan6751e7d2018-05-18 22:05:22 +08007#include <asm/arch/clock_manager.h>
8#include <asm/io.h>
Siew Chin Lim954d5992021-03-24 13:11:34 +08009#include <asm/arch/handoff_soc64.h>
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080010#include <asm/arch/system_manager.h>
11
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080012const struct cm_config * const cm_get_default_config(void)
13{
Chee Hong Ang38969012020-12-24 18:21:10 +080014#ifdef CONFIG_SPL_BUILD
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080015 struct cm_config *cm_handoff_cfg = (struct cm_config *)
Siew Chin Lim954d5992021-03-24 13:11:34 +080016 (SOC64_HANDOFF_CLOCK + SOC64_HANDOFF_OFFSET_DATA);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080017 u32 *conversion = (u32 *)cm_handoff_cfg;
18 u32 i;
Siew Chin Lim954d5992021-03-24 13:11:34 +080019 u32 handoff_clk = readl(SOC64_HANDOFF_CLOCK);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080020
Siew Chin Lim954d5992021-03-24 13:11:34 +080021 if (swab32(handoff_clk) == SOC64_HANDOFF_MAGIC_CLOCK) {
22 writel(swab32(handoff_clk), SOC64_HANDOFF_CLOCK);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080023 for (i = 0; i < (sizeof(*cm_handoff_cfg) / sizeof(u32)); i++)
24 conversion[i] = swab32(conversion[i]);
25 return cm_handoff_cfg;
Siew Chin Lim954d5992021-03-24 13:11:34 +080026 } else if (handoff_clk == SOC64_HANDOFF_MAGIC_CLOCK) {
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080027 return cm_handoff_cfg;
28 }
Chee Hong Ang38969012020-12-24 18:21:10 +080029#endif
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080030 return NULL;
31}
32
33const unsigned int cm_get_osc_clk_hz(void)
34{
35#ifdef CONFIG_SPL_BUILD
Ley Foon Tan0767f8d2019-11-27 15:55:25 +080036
Siew Chin Lim954d5992021-03-24 13:11:34 +080037 u32 clock = readl(SOC64_HANDOFF_CLOCK_OSC);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080038
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080039 writel(clock,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080040 socfpga_get_sysmgr_addr() + SYSMGR_SOC64_BOOT_SCRATCH_COLD1);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080041#endif
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080042 return readl(socfpga_get_sysmgr_addr() +
43 SYSMGR_SOC64_BOOT_SCRATCH_COLD1);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080044}
45
46const unsigned int cm_get_intosc_clk_hz(void)
47{
48 return CLKMGR_INTOSC_HZ;
49}
50
51const unsigned int cm_get_fpga_clk_hz(void)
52{
53#ifdef CONFIG_SPL_BUILD
Siew Chin Lim954d5992021-03-24 13:11:34 +080054 u32 clock = readl(SOC64_HANDOFF_CLOCK_FPGA);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080055
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080056 writel(clock,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080057 socfpga_get_sysmgr_addr() + SYSMGR_SOC64_BOOT_SCRATCH_COLD2);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080058#endif
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080059 return readl(socfpga_get_sysmgr_addr() +
60 SYSMGR_SOC64_BOOT_SCRATCH_COLD2);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080061}