Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Soren Brinkmann | 102ad00 | 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 | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 5 | */ |
Stefan Herbrechtsmeier | e67c6c4 | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 6 | #include <clk.h> |
Stefan Herbrechtsmeier | e67c6c4 | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 9 | #include <malloc.h> |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 10 | #include <asm/arch/clk.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 12 | |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 15 | /** |
Stefan Herbrechtsmeier | e67c6c4 | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 16 | * set_cpu_clk_info() - Setup clock information |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 17 | * |
Stefan Herbrechtsmeier | e67c6c4 | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 18 | * This function is called from common code after relocation and sets up the |
| 19 | * clock information. |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 20 | */ |
Stefan Herbrechtsmeier | e67c6c4 | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 21 | int set_cpu_clk_info(void) |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 22 | { |
Stefan Herbrechtsmeier | e67c6c4 | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 23 | struct clk clk; |
| 24 | struct udevice *dev; |
| 25 | ulong rate; |
| 26 | int i, ret; |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 27 | |
Stefan Herbrechtsmeier | e67c6c4 | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 28 | ret = uclass_get_device_by_driver(UCLASS_CLK, |
Simon Glass | 65130cd | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 29 | DM_DRIVER_GET(zynq_clk), &dev); |
Stefan Herbrechtsmeier | e67c6c4 | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 30 | if (ret) |
| 31 | return ret; |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 32 | |
Stefan Herbrechtsmeier | e67c6c4 | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 33 | for (i = 0; i < 2; i++) { |
| 34 | clk.id = i ? ddr3x_clk : cpu_6or4x_clk; |
| 35 | ret = clk_request(dev, &clk); |
| 36 | if (ret < 0) |
| 37 | return ret; |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 38 | |
Stefan Herbrechtsmeier | e67c6c4 | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 39 | rate = clk_get_rate(&clk) / 1000000; |
Stefan Herbrechtsmeier | 10ff288 | 2022-08-05 08:16:28 +0200 | [diff] [blame] | 40 | if (i) { |
Stefan Herbrechtsmeier | e67c6c4 | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 41 | gd->bd->bi_ddr_freq = rate; |
Stefan Herbrechtsmeier | 10ff288 | 2022-08-05 08:16:28 +0200 | [diff] [blame] | 42 | } else { |
Stefan Herbrechtsmeier | e67c6c4 | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 43 | gd->bd->bi_arm_freq = rate; |
Stefan Herbrechtsmeier | 10ff288 | 2022-08-05 08:16:28 +0200 | [diff] [blame] | 44 | gd->cpu_clk = clk_get_rate(&clk); |
| 45 | } |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 46 | } |
Michal Simek | 0ec9d23 | 2014-01-20 11:05:37 +0100 | [diff] [blame] | 47 | gd->bd->bi_dsp_freq = 0; |
| 48 | |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 49 | return 0; |
| 50 | } |