blob: c4c071330fc34857396b91aa1bd4d29895be1047 [file] [log] [blame]
Siew Chin Lim4d7b6dc2021-08-10 11:26:34 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
4 *
5 */
6
Siew Chin Lim4d7b6dc2021-08-10 11:26:34 +08007#include <asm/arch/clock_manager.h>
8#include <asm/arch/system_manager.h>
9#include <asm/global_data.h>
10#include <asm/io.h>
11#include <clk.h>
12#include <dm.h>
13#include <dt-bindings/clock/n5x-clock.h>
14#include <malloc.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18static ulong cm_get_rate_dm(u32 id)
19{
20 struct udevice *dev;
21 struct clk clk;
22 ulong rate;
23 int ret;
24
25 ret = uclass_get_device_by_driver(UCLASS_CLK,
26 DM_DRIVER_GET(socfpga_n5x_clk),
27 &dev);
28 if (ret)
29 return 0;
30
31 clk.id = id;
32 ret = clk_request(dev, &clk);
33 if (ret < 0)
34 return 0;
35
36 rate = clk_get_rate(&clk);
37
Siew Chin Lim4d7b6dc2021-08-10 11:26:34 +080038 if ((rate == (unsigned long)-ENXIO) ||
39 (rate == (unsigned long)-EIO)) {
40 debug("%s id %u: clk_get_rate err: %ld\n",
41 __func__, id, rate);
42 return 0;
43 }
44
45 return rate;
46}
47
48static u32 cm_get_rate_dm_khz(u32 id)
49{
50 return cm_get_rate_dm(id) / 1000;
51}
52
53unsigned long cm_get_mpu_clk_hz(void)
54{
55 return cm_get_rate_dm(N5X_MPU_CLK);
56}
57
58unsigned int cm_get_l4_sys_free_clk_hz(void)
59{
60 return cm_get_rate_dm(N5X_L4_SYS_FREE_CLK);
61}
62
63void cm_print_clock_quick_summary(void)
64{
65 printf("MPU %10d kHz\n",
66 cm_get_rate_dm_khz(N5X_MPU_CLK));
67 printf("L4 Main %8d kHz\n",
68 cm_get_rate_dm_khz(N5X_L4_MAIN_CLK));
69 printf("L4 sys free %8d kHz\n",
70 cm_get_rate_dm_khz(N5X_L4_SYS_FREE_CLK));
71 printf("L4 MP %8d kHz\n",
72 cm_get_rate_dm_khz(N5X_L4_MP_CLK));
73 printf("L4 SP %8d kHz\n",
74 cm_get_rate_dm_khz(N5X_L4_SP_CLK));
75 printf("SDMMC %8d kHz\n",
76 cm_get_rate_dm_khz(N5X_SDMMC_CLK));
77}