blob: 93e7d776fb2fcfa3093d35d36d3612cfaa84373a [file] [log] [blame]
Suniel Maheshf1cd07b2020-02-03 19:20:04 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
4 */
5
6#include <common.h>
7#include <dm.h>
Jagan Teki59691962020-07-21 20:36:04 +05308#include <env.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Suniel Maheshfe65e712020-02-03 19:20:05 +053010#include <spl_gpio.h>
11#include <asm/io.h>
Jagan Teki59691962020-07-21 20:36:04 +053012#include <power/regulator.h>
13
14#include <asm/arch-rockchip/cru.h>
Suniel Maheshfe65e712020-02-03 19:20:05 +053015#include <asm/arch-rockchip/gpio.h>
Jagan Teki59691962020-07-21 20:36:04 +053016#include <asm/arch-rockchip/grf_rk3399.h>
Suniel Maheshf1cd07b2020-02-03 19:20:04 +053017
18#ifndef CONFIG_SPL_BUILD
19int board_early_init_f(void)
20{
21 struct udevice *regulator;
22 int ret;
23
24 ret = regulator_get_by_platname("vcc5v0_host", &regulator);
25 if (ret) {
26 debug("%s vcc5v0_host init fail! ret %d\n", __func__, ret);
27 goto out;
28 }
29
30 ret = regulator_set_enable(regulator, true);
31 if (ret)
32 debug("%s vcc5v0-host-en set fail! ret %d\n", __func__, ret);
33out:
34 return 0;
35}
Suniel Maheshfe65e712020-02-03 19:20:05 +053036
Jagan Teki6df18262020-07-21 20:36:01 +053037#else
Suniel Maheshfe65e712020-02-03 19:20:05 +053038
Jagan Teki59691962020-07-21 20:36:04 +053039#define PMUGRF_BASE 0xff320000
Jagan Teki6df18262020-07-21 20:36:01 +053040#define GPIO0_BASE 0xff720000
Suniel Maheshfe65e712020-02-03 19:20:05 +053041
Jagan Teki59691962020-07-21 20:36:04 +053042/**
43 * LED setup for roc-rk3399-pc
44 *
45 * 1. Set the low power leds (only during POR, pwr_key env is 'y')
46 * glow yellow LED, termed as low power
47 * poll for on board power key press
48 * once powe key pressed, turn off yellow
49 * 2. Turn on red LED, indicating full power mode
50 */
Jagan Teki6df18262020-07-21 20:36:01 +053051void led_setup(void)
Suniel Maheshfe65e712020-02-03 19:20:05 +053052{
53 struct rockchip_gpio_regs * const gpio0 = (void *)GPIO0_BASE;
Jagan Teki59691962020-07-21 20:36:04 +053054 struct rk3399_pmugrf_regs * const pmugrf = (void *)PMUGRF_BASE;
55 bool press_pwr_key = false;
56
57 if (IS_ENABLED(CONFIG_SPL_ENV_SUPPORT)) {
58 env_init();
59 env_load();
60 if (env_get_yesno("pwr_key") == 1)
61 press_pwr_key = true;
62 }
Suniel Maheshfe65e712020-02-03 19:20:05 +053063
Jagan Teki59691962020-07-21 20:36:04 +053064 if (press_pwr_key && !strcmp(get_reset_cause(), "POR")) {
65 spl_gpio_output(gpio0, GPIO(BANK_A, 2), 1);
66
67 spl_gpio_set_pull(&pmugrf->gpio0_p, GPIO(BANK_A, 5),
68 GPIO_PULL_NORMAL);
69 while (readl(&gpio0->ext_port) & 0x20)
70 ;
71
72 spl_gpio_output(gpio0, GPIO(BANK_A, 2), 0);
73 }
74
Suniel Maheshfe65e712020-02-03 19:20:05 +053075 spl_gpio_output(gpio0, GPIO(BANK_B, 5), 1);
Suniel Maheshfe65e712020-02-03 19:20:05 +053076}
Jagan Teki59691962020-07-21 20:36:04 +053077
Suniel Maheshfe65e712020-02-03 19:20:05 +053078#endif