2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-11-21 21:38:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Soren Brinkmann <soren.brinkmann@xilinx.com>
|
|
|
|
* Copyright (C) 2013 Xilinx, Inc. All rights reserved.
|
|
|
|
*/
|
2017-01-17 15:27:30 +00:00
|
|
|
#include <clk.h>
|
2013-11-21 21:38:54 +00:00
|
|
|
#include <common.h>
|
2017-01-17 15:27:30 +00:00
|
|
|
#include <dm.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2013-11-21 21:38:54 +00:00
|
|
|
#include <asm/arch/clk.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2017-01-17 15:27:27 +00:00
|
|
|
static const char * const clk_names[clk_max] = {
|
|
|
|
"armpll", "ddrpll", "iopll",
|
|
|
|
"cpu_6or4x", "cpu_3or2x", "cpu_2x", "cpu_1x",
|
|
|
|
"ddr2x", "ddr3x", "dci",
|
|
|
|
"lqspi", "smc", "pcap", "gem0", "gem1",
|
|
|
|
"fclk0", "fclk1", "fclk2", "fclk3", "can0", "can1",
|
|
|
|
"sdio0", "sdio1", "uart0", "uart1", "spi0", "spi1", "dma",
|
|
|
|
"usb0_aper", "usb1_aper", "gem0_aper", "gem1_aper",
|
|
|
|
"sdio0_aper", "sdio1_aper", "spi0_aper", "spi1_aper",
|
|
|
|
"can0_aper", "can1_aper", "i2c0_aper", "i2c1_aper",
|
|
|
|
"uart0_aper", "uart1_aper", "gpio_aper", "lqspi_aper",
|
|
|
|
"smc_aper", "swdt", "dbg_trc", "dbg_apb"
|
|
|
|
};
|
|
|
|
|
2013-11-21 21:38:54 +00:00
|
|
|
/**
|
2017-01-17 15:27:30 +00:00
|
|
|
* set_cpu_clk_info() - Setup clock information
|
2013-11-21 21:38:54 +00:00
|
|
|
*
|
|
|
|
* This function is called from common code after relocation and sets up the
|
2017-01-17 15:27:30 +00:00
|
|
|
* clock information.
|
2013-11-21 21:38:54 +00:00
|
|
|
*/
|
|
|
|
int set_cpu_clk_info(void)
|
|
|
|
{
|
2017-01-17 15:27:30 +00:00
|
|
|
struct clk clk;
|
|
|
|
struct udevice *dev;
|
|
|
|
ulong rate;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_CLK,
|
2020-12-29 03:34:56 +00:00
|
|
|
DM_DRIVER_GET(zynq_clk), &dev);
|
2017-01-17 15:27:30 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
clk.id = i ? ddr3x_clk : cpu_6or4x_clk;
|
|
|
|
ret = clk_request(dev, &clk);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
rate = clk_get_rate(&clk) / 1000000;
|
|
|
|
if (i)
|
|
|
|
gd->bd->bi_ddr_freq = rate;
|
|
|
|
else
|
|
|
|
gd->bd->bi_arm_freq = rate;
|
|
|
|
|
|
|
|
clk_free(&clk);
|
|
|
|
}
|
2014-01-20 10:05:37 +00:00
|
|
|
gd->bd->bi_dsp_freq = 0;
|
|
|
|
|
2013-11-21 21:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-21 21:39:03 +00:00
|
|
|
/**
|
|
|
|
* soc_clk_dump() - Print clock frequencies
|
|
|
|
* Returns zero on success
|
|
|
|
*
|
|
|
|
* Implementation for the clk dump command.
|
|
|
|
*/
|
|
|
|
int soc_clk_dump(void)
|
|
|
|
{
|
2017-01-17 15:27:30 +00:00
|
|
|
struct udevice *dev;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_CLK,
|
2020-12-29 03:34:56 +00:00
|
|
|
DM_DRIVER_GET(zynq_clk), &dev);
|
2017-01-17 15:27:30 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2013-11-21 21:39:03 +00:00
|
|
|
|
|
|
|
printf("clk\t\tfrequency\n");
|
|
|
|
for (i = 0; i < clk_max; i++) {
|
2017-01-17 15:27:28 +00:00
|
|
|
const char *name = clk_names[i];
|
2017-01-17 15:27:30 +00:00
|
|
|
if (name) {
|
|
|
|
struct clk clk;
|
|
|
|
unsigned long rate;
|
|
|
|
|
|
|
|
clk.id = i;
|
|
|
|
ret = clk_request(dev, &clk);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
rate = clk_get_rate(&clk);
|
|
|
|
|
|
|
|
clk_free(&clk);
|
|
|
|
|
2018-02-23 12:39:37 +00:00
|
|
|
if ((rate == (unsigned long)-ENOSYS) ||
|
|
|
|
(rate == (unsigned long)-ENXIO))
|
2017-01-17 15:27:30 +00:00
|
|
|
printf("%10s%20s\n", name, "unknown");
|
|
|
|
else
|
|
|
|
printf("%10s%20lu\n", name, rate);
|
|
|
|
}
|
2013-11-21 21:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|