Suniel Mahesh | f1cd07b | 2020-02-03 19:20:04 +0530 | [diff] [blame] | 1 | // 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 Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 8 | #include <env.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 10 | #include <spl_gpio.h> |
| 11 | #include <asm/io.h> |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 12 | #include <power/regulator.h> |
| 13 | |
| 14 | #include <asm/arch-rockchip/cru.h> |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 15 | #include <asm/arch-rockchip/gpio.h> |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 16 | #include <asm/arch-rockchip/grf_rk3399.h> |
Suniel Mahesh | f1cd07b | 2020-02-03 19:20:04 +0530 | [diff] [blame] | 17 | |
| 18 | #ifndef CONFIG_SPL_BUILD |
| 19 | int board_early_init_f(void) |
| 20 | { |
| 21 | struct udevice *regulator; |
| 22 | int ret; |
| 23 | |
| 24 | ret = regulator_get_by_platname("vcc5v0_host", ®ulator); |
| 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); |
| 33 | out: |
| 34 | return 0; |
| 35 | } |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 36 | |
Jagan Teki | 6df1826 | 2020-07-21 20:36:01 +0530 | [diff] [blame] | 37 | #else |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 38 | |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 39 | #define PMUGRF_BASE 0xff320000 |
Jagan Teki | 6df1826 | 2020-07-21 20:36:01 +0530 | [diff] [blame] | 40 | #define GPIO0_BASE 0xff720000 |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 41 | |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 42 | /** |
| 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 Teki | 6df1826 | 2020-07-21 20:36:01 +0530 | [diff] [blame] | 51 | void led_setup(void) |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 52 | { |
| 53 | struct rockchip_gpio_regs * const gpio0 = (void *)GPIO0_BASE; |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 54 | 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 Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 63 | |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 64 | 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 Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 75 | spl_gpio_output(gpio0, GPIO(BANK_B, 5), 1); |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 76 | } |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 77 | |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 78 | #endif |