blob: 5e1ba8d43ed1920bd2740fb080e0cd803edc9b69 [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>
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -08007#include <common.h>
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +01008#include <dm.h>
Simon Glass691d7192020-05-10 11:40:02 -06009#include <init.h>
Simon Glass336d4612020-02-03 07:36:16 -070010#include <malloc.h>
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080011#include <asm/arch/clk.h>
Simon Glass401d1c42020-10-30 21:38:53 -060012#include <asm/global_data.h>
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080013
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080014DECLARE_GLOBAL_DATA_PTR;
15
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080016/**
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010017 * set_cpu_clk_info() - Setup clock information
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080018 *
19 * This function is called from common code after relocation and sets up the
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010020 * clock information.
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080021 */
22int set_cpu_clk_info(void)
23{
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010024 struct clk clk;
25 struct udevice *dev;
26 ulong rate;
27 int i, ret;
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080028
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010029 ret = uclass_get_device_by_driver(UCLASS_CLK,
Simon Glass65e25be2020-12-28 20:34:56 -070030 DM_DRIVER_GET(zynq_clk), &dev);
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010031 if (ret)
32 return ret;
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080033
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010034 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 Herbrechtsmeierb7e07502022-08-05 08:16:28 +020041 if (i) {
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010042 gd->bd->bi_ddr_freq = rate;
Stefan Herbrechtsmeierb7e07502022-08-05 08:16:28 +020043 } else {
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010044 gd->bd->bi_arm_freq = rate;
Stefan Herbrechtsmeierb7e07502022-08-05 08:16:28 +020045 gd->cpu_clk = clk_get_rate(&clk);
46 }
Stefan Herbrechtsmeier781745b2017-01-17 16:27:30 +010047 }
Michal Simek96a5d4d2014-01-20 11:05:37 +010048 gd->bd->bi_dsp_freq = 0;
49
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -080050 return 0;
51}