blob: a38f7125648eda1954d51acc4e4c6d173afdd379 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glasse2e947f2015-08-30 16:55:42 -06002/*
3 * (C) Copyright 2015 Google, Inc
Simon Glasse2e947f2015-08-30 16:55:42 -06004 */
5
Kever Yangb678f272019-07-22 20:02:12 +08006#include <clk.h>
Kever Yangb678f272019-07-22 20:02:12 +08007#include <dm.h>
Simon Glass691d7192020-05-10 11:40:02 -06008#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Kever Yang02219102019-07-22 20:02:11 +080010#include <asm/arch-rockchip/clock.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Kever Yangb678f272019-07-22 20:02:12 +080012#include <dt-bindings/clock/rk3288-cru.h>
Simon Glassc05ed002020-05-10 11:40:11 -060013#include <linux/delay.h>
Simon Glass61b29b82020-02-03 07:36:15 -070014#include <linux/err.h>
Kever Yangb678f272019-07-22 20:02:12 +080015#include <power/regulator.h>
Simon Glass38ffcb62016-11-13 14:22:11 -070016
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 */
Simon Glassdac3ce92024-09-29 19:49:47 -060022#ifndef CONFIG_XPL_BUILD
Kever Yangb678f272019-07-22 20:02:12 +080023#if !CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
24static 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 Glassbbc46242024-06-27 09:29:45 +010031 if (ret)
32 return log_msg_ret("vdd", ret);
Kever Yangb678f272019-07-22 20:02:12 +080033
34 /* Slowly raise to max CPU voltage to prevent overshoot */
35 ret = regulator_set_value(dev, 1200000);
36 if (ret)
Simon Glassbbc46242024-06-27 09:29:45 +010037 return log_msg_ret("s12", ret);
Kever Yangb678f272019-07-22 20:02:12 +080038 udelay(175); /* Must wait for voltage to stabilize, 2mV/us */
39 ret = regulator_set_value(dev, 1400000);
40 if (ret)
Simon Glassbbc46242024-06-27 09:29:45 +010041 return log_msg_ret("s14", ret);
Kever Yangb678f272019-07-22 20:02:12 +080042 udelay(100); /* Must wait for voltage to stabilize, 2mV/us */
43
44 ret = rockchip_get_clk(&clk.dev);
45 if (ret)
Simon Glassbbc46242024-06-27 09:29:45 +010046 return log_msg_ret("clk", ret);
Kever Yangb678f272019-07-22 20:02:12 +080047 clk.id = PLL_APLL;
48 ret = clk_set_rate(&clk, 1800000000);
49 if (IS_ERR_VALUE(ret))
Simon Glassbbc46242024-06-27 09:29:45 +010050 return log_msg_ret("s18", ret);
Kever Yangb678f272019-07-22 20:02:12 +080051
52 ret = regulator_get_by_platname("vcc33_sd", &dev);
Simon Glassbbc46242024-06-27 09:29:45 +010053 if (ret)
54 return log_msg_ret("vcc", ret);
Kever Yangb678f272019-07-22 20:02:12 +080055
56 ret = regulator_set_value(dev, 3300000);
57 if (ret)
Simon Glassbbc46242024-06-27 09:29:45 +010058 return log_msg_ret("s33", ret);
Kever Yangb678f272019-07-22 20:02:12 +080059
Kever Yangb678f272019-07-22 20:02:12 +080060 return 0;
61}
62#endif
Kever Yang02219102019-07-22 20:02:11 +080063
Urja Rannikkofffdf722020-05-13 19:15:21 +000064int board_early_init_r(void)
Kever Yang02219102019-07-22 20:02:11 +080065{
66 struct udevice *dev;
67 int ret;
68
Kever Yangb678f272019-07-22 20:02:12 +080069#if !CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
70 if (!fdt_node_check_compatible(gd->fdt_blob, 0, "google,veyron")) {
71 ret = veyron_init();
72 if (ret)
Simon Glassbbc46242024-06-27 09:29:45 +010073 return log_msg_ret("vey", ret);
Kever Yangb678f272019-07-22 20:02:12 +080074 }
75#endif
Kever Yang02219102019-07-22 20:02:11 +080076 /*
77 * This init is done in SPL, but when chain-loading U-Boot SPL will
78 * have been skipped. Allow the clock driver to check if it needs
79 * setting up.
80 */
81 ret = rockchip_get_clk(&dev);
82 if (ret) {
83 debug("CLK init failed: %d\n", ret);
84 return ret;
85 }
86
87 return 0;
88}
Kever Yangb678f272019-07-22 20:02:12 +080089#endif