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