Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Soren Brinkmann <soren.brinkmann@xilinx.com> |
| 4 | * Copyright (C) 2013 Xilinx, Inc. All rights reserved. |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 5 | */ |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 6 | #include <clk.h> |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 7 | #include <common.h> |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 8 | #include <dm.h> |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 9 | #include <asm/arch/clk.h> |
| 10 | |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 11 | DECLARE_GLOBAL_DATA_PTR; |
| 12 | |
Stefan Herbrechtsmeier | e18c0f6 | 2017-01-17 16:27:27 +0100 | [diff] [blame] | 13 | static const char * const clk_names[clk_max] = { |
| 14 | "armpll", "ddrpll", "iopll", |
| 15 | "cpu_6or4x", "cpu_3or2x", "cpu_2x", "cpu_1x", |
| 16 | "ddr2x", "ddr3x", "dci", |
| 17 | "lqspi", "smc", "pcap", "gem0", "gem1", |
| 18 | "fclk0", "fclk1", "fclk2", "fclk3", "can0", "can1", |
| 19 | "sdio0", "sdio1", "uart0", "uart1", "spi0", "spi1", "dma", |
| 20 | "usb0_aper", "usb1_aper", "gem0_aper", "gem1_aper", |
| 21 | "sdio0_aper", "sdio1_aper", "spi0_aper", "spi1_aper", |
| 22 | "can0_aper", "can1_aper", "i2c0_aper", "i2c1_aper", |
| 23 | "uart0_aper", "uart1_aper", "gpio_aper", "lqspi_aper", |
| 24 | "smc_aper", "swdt", "dbg_trc", "dbg_apb" |
| 25 | }; |
| 26 | |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 27 | /** |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 28 | * set_cpu_clk_info() - Setup clock information |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 29 | * |
| 30 | * This function is called from common code after relocation and sets up the |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 31 | * clock information. |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 32 | */ |
| 33 | int set_cpu_clk_info(void) |
| 34 | { |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 35 | struct clk clk; |
| 36 | struct udevice *dev; |
| 37 | ulong rate; |
| 38 | int i, ret; |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 39 | |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 40 | ret = uclass_get_device_by_driver(UCLASS_CLK, |
| 41 | DM_GET_DRIVER(zynq_clk), &dev); |
| 42 | if (ret) |
| 43 | return ret; |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 44 | |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 45 | for (i = 0; i < 2; i++) { |
| 46 | clk.id = i ? ddr3x_clk : cpu_6or4x_clk; |
| 47 | ret = clk_request(dev, &clk); |
| 48 | if (ret < 0) |
| 49 | return ret; |
| 50 | |
| 51 | rate = clk_get_rate(&clk) / 1000000; |
| 52 | if (i) |
| 53 | gd->bd->bi_ddr_freq = rate; |
| 54 | else |
| 55 | gd->bd->bi_arm_freq = rate; |
| 56 | |
| 57 | clk_free(&clk); |
| 58 | } |
Michal Simek | 96a5d4d | 2014-01-20 11:05:37 +0100 | [diff] [blame] | 59 | gd->bd->bi_dsp_freq = 0; |
| 60 | |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | /** |
Soren Brinkmann | d6c9bba | 2013-11-21 13:39:03 -0800 | [diff] [blame] | 65 | * soc_clk_dump() - Print clock frequencies |
| 66 | * Returns zero on success |
| 67 | * |
| 68 | * Implementation for the clk dump command. |
| 69 | */ |
| 70 | int soc_clk_dump(void) |
| 71 | { |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 72 | struct udevice *dev; |
| 73 | int i, ret; |
| 74 | |
| 75 | ret = uclass_get_device_by_driver(UCLASS_CLK, |
| 76 | DM_GET_DRIVER(zynq_clk), &dev); |
| 77 | if (ret) |
| 78 | return ret; |
Soren Brinkmann | d6c9bba | 2013-11-21 13:39:03 -0800 | [diff] [blame] | 79 | |
| 80 | printf("clk\t\tfrequency\n"); |
| 81 | for (i = 0; i < clk_max; i++) { |
Stefan Herbrechtsmeier | f96fccb | 2017-01-17 16:27:28 +0100 | [diff] [blame] | 82 | const char *name = clk_names[i]; |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 83 | if (name) { |
| 84 | struct clk clk; |
| 85 | unsigned long rate; |
| 86 | |
| 87 | clk.id = i; |
| 88 | ret = clk_request(dev, &clk); |
| 89 | if (ret < 0) |
| 90 | return ret; |
| 91 | |
| 92 | rate = clk_get_rate(&clk); |
| 93 | |
| 94 | clk_free(&clk); |
| 95 | |
Michal Simek | 7ad6d9a | 2018-02-23 13:39:37 +0100 | [diff] [blame] | 96 | if ((rate == (unsigned long)-ENOSYS) || |
| 97 | (rate == (unsigned long)-ENXIO)) |
Stefan Herbrechtsmeier | 781745b | 2017-01-17 16:27:30 +0100 | [diff] [blame] | 98 | printf("%10s%20s\n", name, "unknown"); |
| 99 | else |
| 100 | printf("%10s%20lu\n", name, rate); |
| 101 | } |
Soren Brinkmann | d6c9bba | 2013-11-21 13:39:03 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | return 0; |
| 105 | } |