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