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 | |
| 13 | #include <asm/arch-rockchip/cru.h> |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 14 | #include <asm/arch-rockchip/gpio.h> |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 15 | #include <asm/arch-rockchip/grf_rk3399.h> |
Suniel Mahesh | f1cd07b | 2020-02-03 19:20:04 +0530 | [diff] [blame] | 16 | |
Jonas Karlman | d95e08b | 2024-03-12 23:36:13 +0000 | [diff] [blame^] | 17 | #ifdef CONFIG_SPL_BUILD |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 18 | |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 19 | #define PMUGRF_BASE 0xff320000 |
Jagan Teki | 6df1826 | 2020-07-21 20:36:01 +0530 | [diff] [blame] | 20 | #define GPIO0_BASE 0xff720000 |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 21 | |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 22 | /** |
| 23 | * LED setup for roc-rk3399-pc |
| 24 | * |
| 25 | * 1. Set the low power leds (only during POR, pwr_key env is 'y') |
| 26 | * glow yellow LED, termed as low power |
| 27 | * poll for on board power key press |
| 28 | * once powe key pressed, turn off yellow |
| 29 | * 2. Turn on red LED, indicating full power mode |
| 30 | */ |
Jagan Teki | 6df1826 | 2020-07-21 20:36:01 +0530 | [diff] [blame] | 31 | void led_setup(void) |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 32 | { |
| 33 | struct rockchip_gpio_regs * const gpio0 = (void *)GPIO0_BASE; |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 34 | struct rk3399_pmugrf_regs * const pmugrf = (void *)PMUGRF_BASE; |
| 35 | bool press_pwr_key = false; |
| 36 | |
| 37 | if (IS_ENABLED(CONFIG_SPL_ENV_SUPPORT)) { |
| 38 | env_init(); |
| 39 | env_load(); |
| 40 | if (env_get_yesno("pwr_key") == 1) |
| 41 | press_pwr_key = true; |
| 42 | } |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 43 | |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 44 | if (press_pwr_key && !strcmp(get_reset_cause(), "POR")) { |
| 45 | spl_gpio_output(gpio0, GPIO(BANK_A, 2), 1); |
| 46 | |
| 47 | spl_gpio_set_pull(&pmugrf->gpio0_p, GPIO(BANK_A, 5), |
| 48 | GPIO_PULL_NORMAL); |
| 49 | while (readl(&gpio0->ext_port) & 0x20) |
| 50 | ; |
| 51 | |
| 52 | spl_gpio_output(gpio0, GPIO(BANK_A, 2), 0); |
| 53 | } |
| 54 | |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 55 | spl_gpio_output(gpio0, GPIO(BANK_B, 5), 1); |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 56 | } |
Jagan Teki | 5969196 | 2020-07-21 20:36:04 +0530 | [diff] [blame] | 57 | |
Suniel Mahesh | fe65e71 | 2020-02-03 19:20:05 +0530 | [diff] [blame] | 58 | #endif |