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