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