Jit Loon Lim | 977071e | 2024-03-12 22:01:03 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2024 Intel Corporation <www.intel.com> |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #include <clk.h> |
| 8 | #include <config.h> |
| 9 | #include <dm.h> |
| 10 | #include <errno.h> |
| 11 | #include <log.h> |
| 12 | #include <malloc.h> |
| 13 | #include <stdarg.h> |
| 14 | #include <stdio.h> |
| 15 | #include <time.h> |
| 16 | #include <vsprintf.h> |
| 17 | #include <asm/global_data.h> |
| 18 | #include <asm/io.h> |
Jit Loon Lim | 977071e | 2024-03-12 22:01:03 +0800 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/string.h> |
| 21 | #include <linux/types.h> |
| 22 | #include <asm/arch/clock_manager.h> |
| 23 | #include <asm/arch/system_manager.h> |
| 24 | #include <dt-bindings/clock/agilex5-clock.h> |
| 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
| 28 | static ulong cm_get_rate_dm(u32 id) |
| 29 | { |
| 30 | struct udevice *dev; |
| 31 | struct clk clk; |
| 32 | ulong rate; |
| 33 | int ret; |
| 34 | |
| 35 | ret = uclass_get_device_by_driver(UCLASS_CLK, |
| 36 | DM_DRIVER_GET(socfpga_agilex5_clk), |
| 37 | &dev); |
| 38 | if (ret) |
| 39 | return 0; |
| 40 | |
| 41 | clk.id = id; |
| 42 | ret = clk_request(dev, &clk); |
| 43 | if (ret < 0) |
| 44 | return 0; |
| 45 | |
| 46 | rate = clk_get_rate(&clk); |
| 47 | |
| 48 | if ((rate == (unsigned long)-ENOSYS) || |
| 49 | (rate == (unsigned long)-ENXIO) || |
| 50 | (rate == (unsigned long)-EIO)) { |
| 51 | debug("%s id %u: clk_get_rate err: %ld\n", |
| 52 | __func__, id, rate); |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | return rate; |
| 57 | } |
| 58 | |
| 59 | static u32 cm_get_rate_dm_khz(u32 id) |
| 60 | { |
| 61 | return cm_get_rate_dm(id) / 1000; |
| 62 | } |
| 63 | |
| 64 | unsigned long cm_get_mpu_clk_hz(void) |
| 65 | { |
| 66 | return cm_get_rate_dm(AGILEX5_MPU_CLK); |
| 67 | } |
| 68 | |
| 69 | unsigned int cm_get_l4_sys_free_clk_hz(void) |
| 70 | { |
| 71 | return cm_get_rate_dm(AGILEX5_L4_SYS_FREE_CLK); |
| 72 | } |
| 73 | |
| 74 | void cm_print_clock_quick_summary(void) |
| 75 | { |
| 76 | printf("MPU %10d kHz\n", |
| 77 | cm_get_rate_dm_khz(AGILEX5_MPU_CLK)); |
| 78 | printf("L4 Main %8d kHz\n", |
| 79 | cm_get_rate_dm_khz(AGILEX5_L4_MAIN_CLK)); |
| 80 | printf("L4 sys free %8d kHz\n", |
| 81 | cm_get_rate_dm_khz(AGILEX5_L4_SYS_FREE_CLK)); |
| 82 | printf("L4 MP %8d kHz\n", |
| 83 | cm_get_rate_dm_khz(AGILEX5_L4_MP_CLK)); |
| 84 | printf("L4 SP %8d kHz\n", |
| 85 | cm_get_rate_dm_khz(AGILEX5_L4_SP_CLK)); |
| 86 | printf("SDMMC %8d kHz\n", |
| 87 | cm_get_rate_dm_khz(AGILEX5_SDMMC_CLK)); |
| 88 | } |