Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 9d5d1cc | 2015-08-30 16:55:42 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Google, Inc |
Simon Glass | 9d5d1cc | 2015-08-30 16:55:42 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 6 | #include <clk.h> |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Kever Yang | 9247104 | 2019-07-22 20:02:11 +0800 | [diff] [blame] | 10 | #include <asm/arch-rockchip/clock.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 12 | #include <dt-bindings/clock/rk3288-cru.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 14 | #include <linux/err.h> |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 15 | #include <power/regulator.h> |
Simon Glass | 57538b3 | 2016-11-13 14:22:11 -0700 | [diff] [blame] | 16 | |
| 17 | /* |
| 18 | * We should increase the DDR voltage to 1.2V using the PWM regulator. |
| 19 | * There is a U-Boot driver for this but it may need to add support for the |
| 20 | * 'voltage-table' property. |
| 21 | */ |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 22 | #ifndef CONFIG_SPL_BUILD |
| 23 | #if !CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) |
| 24 | static int veyron_init(void) |
| 25 | { |
| 26 | struct udevice *dev; |
| 27 | struct clk clk; |
| 28 | int ret; |
| 29 | |
| 30 | ret = regulator_get_by_platname("vdd_arm", &dev); |
Simon Glass | d77656e | 2024-06-27 09:29:45 +0100 | [diff] [blame] | 31 | if (ret) |
| 32 | return log_msg_ret("vdd", ret); |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 33 | |
| 34 | /* Slowly raise to max CPU voltage to prevent overshoot */ |
| 35 | ret = regulator_set_value(dev, 1200000); |
| 36 | if (ret) |
Simon Glass | d77656e | 2024-06-27 09:29:45 +0100 | [diff] [blame] | 37 | return log_msg_ret("s12", ret); |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 38 | udelay(175); /* Must wait for voltage to stabilize, 2mV/us */ |
| 39 | ret = regulator_set_value(dev, 1400000); |
| 40 | if (ret) |
Simon Glass | d77656e | 2024-06-27 09:29:45 +0100 | [diff] [blame] | 41 | return log_msg_ret("s14", ret); |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 42 | udelay(100); /* Must wait for voltage to stabilize, 2mV/us */ |
| 43 | |
| 44 | ret = rockchip_get_clk(&clk.dev); |
| 45 | if (ret) |
Simon Glass | d77656e | 2024-06-27 09:29:45 +0100 | [diff] [blame] | 46 | return log_msg_ret("clk", ret); |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 47 | clk.id = PLL_APLL; |
| 48 | ret = clk_set_rate(&clk, 1800000000); |
| 49 | if (IS_ERR_VALUE(ret)) |
Simon Glass | d77656e | 2024-06-27 09:29:45 +0100 | [diff] [blame] | 50 | return log_msg_ret("s18", ret); |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 51 | |
| 52 | ret = regulator_get_by_platname("vcc33_sd", &dev); |
Simon Glass | d77656e | 2024-06-27 09:29:45 +0100 | [diff] [blame] | 53 | if (ret) |
| 54 | return log_msg_ret("vcc", ret); |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 55 | |
| 56 | ret = regulator_set_value(dev, 3300000); |
| 57 | if (ret) |
Simon Glass | d77656e | 2024-06-27 09:29:45 +0100 | [diff] [blame] | 58 | return log_msg_ret("s33", ret); |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 59 | |
| 60 | ret = regulators_enable_boot_on(false); |
Simon Glass | d77656e | 2024-06-27 09:29:45 +0100 | [diff] [blame] | 61 | if (ret) |
| 62 | return log_msg_ret("boo", ret); |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | #endif |
Kever Yang | 9247104 | 2019-07-22 20:02:11 +0800 | [diff] [blame] | 67 | |
Urja Rannikko | e8c4c96 | 2020-05-13 19:15:21 +0000 | [diff] [blame] | 68 | int board_early_init_r(void) |
Kever Yang | 9247104 | 2019-07-22 20:02:11 +0800 | [diff] [blame] | 69 | { |
| 70 | struct udevice *dev; |
| 71 | int ret; |
| 72 | |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 73 | #if !CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) |
| 74 | if (!fdt_node_check_compatible(gd->fdt_blob, 0, "google,veyron")) { |
| 75 | ret = veyron_init(); |
| 76 | if (ret) |
Simon Glass | d77656e | 2024-06-27 09:29:45 +0100 | [diff] [blame] | 77 | return log_msg_ret("vey", ret); |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 78 | } |
| 79 | #endif |
Kever Yang | 9247104 | 2019-07-22 20:02:11 +0800 | [diff] [blame] | 80 | /* |
| 81 | * This init is done in SPL, but when chain-loading U-Boot SPL will |
| 82 | * have been skipped. Allow the clock driver to check if it needs |
| 83 | * setting up. |
| 84 | */ |
| 85 | ret = rockchip_get_clk(&dev); |
| 86 | if (ret) { |
| 87 | debug("CLK init failed: %d\n", ret); |
| 88 | return ret; |
| 89 | } |
| 90 | |
| 91 | return 0; |
| 92 | } |
Kever Yang | 71195ce | 2019-07-22 20:02:12 +0800 | [diff] [blame] | 93 | #endif |