blob: 9987d5bcee6fab4f4ce102c8e748dbcfbb032278 [file] [log] [blame]
Ley Foon Tanb7d95b72019-11-27 15:55:23 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2019 Intel Corporation <www.intel.com>
4 *
5 */
6
7#include <clk.h>
Ley Foon Tanb7d95b72019-11-27 15:55:23 +08008#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070010#include <malloc.h>
Ley Foon Tanb7d95b72019-11-27 15:55:23 +080011#include <asm/arch/clock_manager.h>
12#include <asm/arch/system_manager.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Ley Foon Tanb7d95b72019-11-27 15:55:23 +080014#include <asm/io.h>
15#include <dt-bindings/clock/agilex-clock.h>
16
17DECLARE_GLOBAL_DATA_PTR;
18
19static ulong cm_get_rate_dm(u32 id)
20{
21 struct udevice *dev;
22 struct clk clk;
23 ulong rate;
24 int ret;
25
26 ret = uclass_get_device_by_driver(UCLASS_CLK,
Simon Glass65130cd2020-12-28 20:34:56 -070027 DM_DRIVER_GET(socfpga_agilex_clk),
Ley Foon Tanb7d95b72019-11-27 15:55:23 +080028 &dev);
29 if (ret)
30 return 0;
31
32 clk.id = id;
33 ret = clk_request(dev, &clk);
34 if (ret < 0)
35 return 0;
36
37 rate = clk_get_rate(&clk);
38
Ley Foon Tanb7d95b72019-11-27 15:55:23 +080039 if ((rate == (unsigned long)-ENOSYS) ||
40 (rate == (unsigned long)-ENXIO) ||
41 (rate == (unsigned long)-EIO)) {
42 debug("%s id %u: clk_get_rate err: %ld\n",
43 __func__, id, rate);
44 return 0;
45 }
46
47 return rate;
48}
49
50static u32 cm_get_rate_dm_khz(u32 id)
51{
52 return cm_get_rate_dm(id) / 1000;
53}
54
55unsigned long cm_get_mpu_clk_hz(void)
56{
57 return cm_get_rate_dm(AGILEX_MPU_CLK);
58}
59
60unsigned int cm_get_l4_sys_free_clk_hz(void)
61{
62 return cm_get_rate_dm(AGILEX_L4_SYS_FREE_CLK);
63}
64
Ley Foon Tanb7d95b72019-11-27 15:55:23 +080065void cm_print_clock_quick_summary(void)
66{
67 printf("MPU %10d kHz\n",
68 cm_get_rate_dm_khz(AGILEX_MPU_CLK));
69 printf("L4 Main %8d kHz\n",
70 cm_get_rate_dm_khz(AGILEX_L4_MAIN_CLK));
71 printf("L4 sys free %8d kHz\n",
72 cm_get_rate_dm_khz(AGILEX_L4_SYS_FREE_CLK));
73 printf("L4 MP %8d kHz\n",
74 cm_get_rate_dm_khz(AGILEX_L4_MP_CLK));
75 printf("L4 SP %8d kHz\n",
76 cm_get_rate_dm_khz(AGILEX_L4_SP_CLK));
77 printf("SDMMC %8d kHz\n",
78 cm_get_rate_dm_khz(AGILEX_SDMMC_CLK));
79}