blob: bd8ce63377230afde4a3437347c34c3e4ca16db9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass9d5d1cc2015-08-30 16:55:42 -06002/*
3 * (C) Copyright 2015 Google, Inc
Simon Glass9d5d1cc2015-08-30 16:55:42 -06004 */
5
Kever Yang71195ce2019-07-22 20:02:12 +08006#include <clk.h>
Kever Yang71195ce2019-07-22 20:02:12 +08007#include <dm.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Kever Yang92471042019-07-22 20:02:11 +080010#include <asm/arch-rockchip/clock.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Kever Yang71195ce2019-07-22 20:02:12 +080012#include <dt-bindings/clock/rk3288-cru.h>
Simon Glassdbd79542020-05-10 11:40:11 -060013#include <linux/delay.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070014#include <linux/err.h>
Kever Yang71195ce2019-07-22 20:02:12 +080015#include <power/regulator.h>
Simon Glass57538b32016-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 */
Kever Yang71195ce2019-07-22 20:02:12 +080022#ifndef CONFIG_SPL_BUILD
23#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 Glassd77656e2024-06-27 09:29:45 +010031 if (ret)
32 return log_msg_ret("vdd", ret);
Kever Yang71195ce2019-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 Glassd77656e2024-06-27 09:29:45 +010037 return log_msg_ret("s12", ret);
Kever Yang71195ce2019-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 Glassd77656e2024-06-27 09:29:45 +010041 return log_msg_ret("s14", ret);
Kever Yang71195ce2019-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 Glassd77656e2024-06-27 09:29:45 +010046 return log_msg_ret("clk", ret);
Kever Yang71195ce2019-07-22 20:02:12 +080047 clk.id = PLL_APLL;
48 ret = clk_set_rate(&clk, 1800000000);
49 if (IS_ERR_VALUE(ret))
Simon Glassd77656e2024-06-27 09:29:45 +010050 return log_msg_ret("s18", ret);
Kever Yang71195ce2019-07-22 20:02:12 +080051
52 ret = regulator_get_by_platname("vcc33_sd", &dev);
Simon Glassd77656e2024-06-27 09:29:45 +010053 if (ret)
54 return log_msg_ret("vcc", ret);
Kever Yang71195ce2019-07-22 20:02:12 +080055
56 ret = regulator_set_value(dev, 3300000);
57 if (ret)
Simon Glassd77656e2024-06-27 09:29:45 +010058 return log_msg_ret("s33", ret);
Kever Yang71195ce2019-07-22 20:02:12 +080059
60 ret = regulators_enable_boot_on(false);
Simon Glassd77656e2024-06-27 09:29:45 +010061 if (ret)
62 return log_msg_ret("boo", ret);
Kever Yang71195ce2019-07-22 20:02:12 +080063
64 return 0;
65}
66#endif
Kever Yang92471042019-07-22 20:02:11 +080067
Urja Rannikkoe8c4c962020-05-13 19:15:21 +000068int board_early_init_r(void)
Kever Yang92471042019-07-22 20:02:11 +080069{
70 struct udevice *dev;
71 int ret;
72
Kever Yang71195ce2019-07-22 20:02:12 +080073#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 Glassd77656e2024-06-27 09:29:45 +010077 return log_msg_ret("vey", ret);
Kever Yang71195ce2019-07-22 20:02:12 +080078 }
79#endif
Kever Yang92471042019-07-22 20:02:11 +080080 /*
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 Yang71195ce2019-07-22 20:02:12 +080093#endif