blob: c1b018cf22e92c000e712d6c720b53ab3fa8e991 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Soren Brinkmann102ad002013-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 Brinkmann102ad002013-11-21 13:38:54 -08005 */
Stefan Herbrechtsmeiere67c6c42017-01-17 16:27:30 +01006#include <clk.h>
Stefan Herbrechtsmeiere67c6c42017-01-17 16:27:30 +01007#include <dm.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass9bc15642020-02-03 07:36:16 -07009#include <malloc.h>
Soren Brinkmann102ad002013-11-21 13:38:54 -080010#include <asm/arch/clk.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Soren Brinkmann102ad002013-11-21 13:38:54 -080012
Soren Brinkmann102ad002013-11-21 13:38:54 -080013DECLARE_GLOBAL_DATA_PTR;
14
Soren Brinkmann102ad002013-11-21 13:38:54 -080015/**
Stefan Herbrechtsmeiere67c6c42017-01-17 16:27:30 +010016 * set_cpu_clk_info() - Setup clock information
Soren Brinkmann102ad002013-11-21 13:38:54 -080017 *
Stefan Herbrechtsmeiere67c6c42017-01-17 16:27:30 +010018 * This function is called from common code after relocation and sets up the
19 * clock information.
Soren Brinkmann102ad002013-11-21 13:38:54 -080020 */
Stefan Herbrechtsmeiere67c6c42017-01-17 16:27:30 +010021int set_cpu_clk_info(void)
Soren Brinkmann102ad002013-11-21 13:38:54 -080022{
Stefan Herbrechtsmeiere67c6c42017-01-17 16:27:30 +010023 struct clk clk;
24 struct udevice *dev;
25 ulong rate;
26 int i, ret;
Soren Brinkmann102ad002013-11-21 13:38:54 -080027
Stefan Herbrechtsmeiere67c6c42017-01-17 16:27:30 +010028 ret = uclass_get_device_by_driver(UCLASS_CLK,
Simon Glass65130cd2020-12-28 20:34:56 -070029 DM_DRIVER_GET(zynq_clk), &dev);
Stefan Herbrechtsmeiere67c6c42017-01-17 16:27:30 +010030 if (ret)
31 return ret;
Soren Brinkmann102ad002013-11-21 13:38:54 -080032
Stefan Herbrechtsmeiere67c6c42017-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;
Soren Brinkmann102ad002013-11-21 13:38:54 -080038
Stefan Herbrechtsmeiere67c6c42017-01-17 16:27:30 +010039 rate = clk_get_rate(&clk) / 1000000;
Stefan Herbrechtsmeier10ff2882022-08-05 08:16:28 +020040 if (i) {
Stefan Herbrechtsmeiere67c6c42017-01-17 16:27:30 +010041 gd->bd->bi_ddr_freq = rate;
Stefan Herbrechtsmeier10ff2882022-08-05 08:16:28 +020042 } else {
Stefan Herbrechtsmeiere67c6c42017-01-17 16:27:30 +010043 gd->bd->bi_arm_freq = rate;
Stefan Herbrechtsmeier10ff2882022-08-05 08:16:28 +020044 gd->cpu_clk = clk_get_rate(&clk);
45 }
Soren Brinkmann102ad002013-11-21 13:38:54 -080046 }
Michal Simek0ec9d232014-01-20 11:05:37 +010047 gd->bd->bi_dsp_freq = 0;
48
Soren Brinkmann102ad002013-11-21 13:38:54 -080049 return 0;
50}