blob: c1b018cf22e92c000e712d6c720b53ab3fa8e991 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -08002/*
3 * Copyright (C) 2013 Soren Brinkmann <soren.brinkmann@xilinx.com>
4 * Copyright (C) 2013 Xilinx, Inc. All rights reserved.
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -08005 */
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +01006#include <clk.h>
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +01007#include <dm.h>
Simon Glass691d7192020-05-10 11:40:02 -06008#include <init.h>
Simon Glass336d4612020-02-03 07:36:16 -07009#include <malloc.h>
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080010#include <asm/arch/clk.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080012
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080013DECLARE_GLOBAL_DATA_PTR;
14
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080015/**
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010016 * set_cpu_clk_info() - Setup clock information
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080017 *
18 * This function is called from common code after relocation and sets up the
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010019 * clock information.
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080020 */
21int set_cpu_clk_info(void)
22{
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010023 struct clk clk;
24 struct udevice *dev;
25 ulong rate;
26 int i, ret;
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080027
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010028 ret = uclass_get_device_by_driver(UCLASS_CLK,
Simon Glass65e25be2020-12-28 20:34:56 -070029 DM_DRIVER_GET(zynq_clk), &dev);
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010030 if (ret)
31 return ret;
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080032
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010033 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;
38
39 rate = clk_get_rate(&clk) / 1000000;
Stefan Herbrechtsmeierb7e07502022-08-05 08:16:28 +020040 if (i) {
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010041 gd->bd->bi_ddr_freq = rate;
Stefan Herbrechtsmeierb7e07502022-08-05 08:16:28 +020042 } else {
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010043 gd->bd->bi_arm_freq = rate;
Stefan Herbrechtsmeierb7e07502022-08-05 08:16:28 +020044 gd->cpu_clk = clk_get_rate(&clk);
45 }
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010046 }
Michal Simek96a5d4d2014-01-20 11:05:37 +010047 gd->bd->bi_dsp_freq = 0;
48
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080049 return 0;
50}