Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Soren Brinkmann <soren.brinkmann@xilinx.com> |
| 4 | * Copyright (C) 2013 Xilinx, Inc. All rights reserved. |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 5 | */ |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 6 | #include <clk.h> |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 7 | #include <common.h> |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 10 | #include <malloc.h> |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 11 | #include <asm/arch/clk.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 13 | |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 16 | /** |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 17 | * set_cpu_clk_info() - Setup clock information |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 18 | * |
| 19 | * This function is called from common code after relocation and sets up the |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 20 | * clock information. |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 21 | */ |
| 22 | int set_cpu_clk_info(void) |
| 23 | { |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 24 | struct clk clk; |
| 25 | struct udevice *dev; |
| 26 | ulong rate; |
| 27 | int i, ret; |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 28 | |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 29 | ret = uclass_get_device_by_driver(UCLASS_CLK, |
Simon Glass | 65e25be | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 30 | DM_DRIVER_GET(zynq_clk), &dev); |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 31 | if (ret) |
| 32 | return ret; |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 33 | |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 34 | for (i = 0; i < 2; i++) { |
| 35 | clk.id = i ? ddr3x_clk : cpu_6or4x_clk; |
| 36 | ret = clk_request(dev, &clk); |
| 37 | if (ret < 0) |
| 38 | return ret; |
| 39 | |
| 40 | rate = clk_get_rate(&clk) / 1000000; |
Stefan Herbrechtsmeier | b7e0750 | 2022-08-05 08:16:28 +0200 | [diff] [blame] | 41 | if (i) { |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 42 | gd->bd->bi_ddr_freq = rate; |
Stefan Herbrechtsmeier | b7e0750 | 2022-08-05 08:16:28 +0200 | [diff] [blame] | 43 | } else { |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 44 | gd->bd->bi_arm_freq = rate; |
Stefan Herbrechtsmeier | b7e0750 | 2022-08-05 08:16:28 +0200 | [diff] [blame] | 45 | gd->cpu_clk = clk_get_rate(&clk); |
| 46 | } |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 47 | } |
Michal Simek | 96a5d4d | 2014-01-20 11:05:37 +0100 | [diff] [blame] | 48 | gd->bd->bi_dsp_freq = 0; |
| 49 | |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 50 | return 0; |
| 51 | } |