blob: 6a0d6b5ead72991ef9119c666040fcb9c33c059d [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
7#include <common.h>
8#include <asm/arch/clock_manager.h>
9#include <asm/io.h>
Siew Chin Lim954d5992021-03-24 13:11:34 +080010#include <asm/arch/handoff_soc64.h>
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080011#include <asm/arch/system_manager.h>
12
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080013const struct cm_config * const cm_get_default_config(void)
14{
Chee Hong Ang38969012020-12-24 18:21:10 +080015#ifdef CONFIG_SPL_BUILD
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080016 struct cm_config *cm_handoff_cfg = (struct cm_config *)
Siew Chin Lim954d5992021-03-24 13:11:34 +080017 (SOC64_HANDOFF_CLOCK + SOC64_HANDOFF_OFFSET_DATA);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080018 u32 *conversion = (u32 *)cm_handoff_cfg;
19 u32 i;
Siew Chin Lim954d5992021-03-24 13:11:34 +080020 u32 handoff_clk = readl(SOC64_HANDOFF_CLOCK);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080021
Siew Chin Lim954d5992021-03-24 13:11:34 +080022 if (swab32(handoff_clk) == SOC64_HANDOFF_MAGIC_CLOCK) {
23 writel(swab32(handoff_clk), SOC64_HANDOFF_CLOCK);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080024 for (i = 0; i < (sizeof(*cm_handoff_cfg) / sizeof(u32)); i++)
25 conversion[i] = swab32(conversion[i]);
26 return cm_handoff_cfg;
Siew Chin Lim954d5992021-03-24 13:11:34 +080027 } else if (handoff_clk == SOC64_HANDOFF_MAGIC_CLOCK) {
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080028 return cm_handoff_cfg;
29 }
Chee Hong Ang38969012020-12-24 18:21:10 +080030#endif
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080031 return NULL;
32}
33
34const unsigned int cm_get_osc_clk_hz(void)
35{
36#ifdef CONFIG_SPL_BUILD
Ley Foon Tan0767f8d2019-11-27 15:55:25 +080037
Siew Chin Lim954d5992021-03-24 13:11:34 +080038 u32 clock = readl(SOC64_HANDOFF_CLOCK_OSC);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080039
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080040 writel(clock,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080041 socfpga_get_sysmgr_addr() + SYSMGR_SOC64_BOOT_SCRATCH_COLD1);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080042#endif
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080043 return readl(socfpga_get_sysmgr_addr() +
44 SYSMGR_SOC64_BOOT_SCRATCH_COLD1);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080045}
46
47const unsigned int cm_get_intosc_clk_hz(void)
48{
49 return CLKMGR_INTOSC_HZ;
50}
51
52const unsigned int cm_get_fpga_clk_hz(void)
53{
54#ifdef CONFIG_SPL_BUILD
Siew Chin Lim954d5992021-03-24 13:11:34 +080055 u32 clock = readl(SOC64_HANDOFF_CLOCK_FPGA);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080056
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080057 writel(clock,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080058 socfpga_get_sysmgr_addr() + SYSMGR_SOC64_BOOT_SCRATCH_COLD2);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080059#endif
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080060 return readl(socfpga_get_sysmgr_addr() +
61 SYSMGR_SOC64_BOOT_SCRATCH_COLD2);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080062}