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