blob: b266a5817b019e3402a2dbb68de9cbbd5f73fe41 [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>
10#include <asm/arch/handoff_s10.h>
11#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{
15 struct cm_config *cm_handoff_cfg = (struct cm_config *)
16 (S10_HANDOFF_CLOCK + S10_HANDOFF_OFFSET_DATA);
17 u32 *conversion = (u32 *)cm_handoff_cfg;
18 u32 i;
19 u32 handoff_clk = readl(S10_HANDOFF_CLOCK);
20
21 if (swab32(handoff_clk) == S10_HANDOFF_MAGIC_CLOCK) {
22 writel(swab32(handoff_clk), S10_HANDOFF_CLOCK);
23 for (i = 0; i < (sizeof(*cm_handoff_cfg) / sizeof(u32)); i++)
24 conversion[i] = swab32(conversion[i]);
25 return cm_handoff_cfg;
26 } else if (handoff_clk == S10_HANDOFF_MAGIC_CLOCK) {
27 return cm_handoff_cfg;
28 }
29
30 return NULL;
31}
32
33const unsigned int cm_get_osc_clk_hz(void)
34{
35#ifdef CONFIG_SPL_BUILD
36 u32 clock = readl(S10_HANDOFF_CLOCK_OSC);
37
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080038 writel(clock,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080039 socfpga_get_sysmgr_addr() + SYSMGR_SOC64_BOOT_SCRATCH_COLD1);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080040#endif
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080041 return readl(socfpga_get_sysmgr_addr() +
42 SYSMGR_SOC64_BOOT_SCRATCH_COLD1);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080043}
44
45const unsigned int cm_get_intosc_clk_hz(void)
46{
47 return CLKMGR_INTOSC_HZ;
48}
49
50const unsigned int cm_get_fpga_clk_hz(void)
51{
52#ifdef CONFIG_SPL_BUILD
53 u32 clock = readl(S10_HANDOFF_CLOCK_FPGA);
54
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080055 writel(clock,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080056 socfpga_get_sysmgr_addr() + SYSMGR_SOC64_BOOT_SCRATCH_COLD2);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080057#endif
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080058 return readl(socfpga_get_sysmgr_addr() +
59 SYSMGR_SOC64_BOOT_SCRATCH_COLD2);
Ley Foon Tan6751e7d2018-05-18 22:05:22 +080060}