Karthikeyan Ramasubramanian | 2429557 | 2021-03-25 18:07:12 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <amdblocks/acpimmio.h> |
| 4 | #include <amdblocks/pmlib.h> |
| 5 | #include <console/console.h> |
| 6 | #include <types.h> |
| 7 | |
Felix Held | 43cd1c0 | 2021-04-13 20:07:26 +0200 | [diff] [blame] | 8 | /* This register is a bit of an odd one. The configuration gets written into the lower nibble, |
| 9 | but ends up being copied to the upper nibble which gets initialized by this. */ |
Karthikeyan Ramasubramanian | 2429557 | 2021-03-25 18:07:12 -0600 | [diff] [blame] | 10 | #define PM_RTC_SHADOW_REG 0x5b |
Felix Held | 43cd1c0 | 2021-04-13 20:07:26 +0200 | [diff] [blame] | 11 | #define PWR_PWRSTATE BIT(2) /* power state bit; needs to be written as 1 */ |
Karthikeyan Ramasubramanian | 2429557 | 2021-03-25 18:07:12 -0600 | [diff] [blame] | 12 | #define PWR_FAIL_OFF 0x0 /* Always power off after power resumes */ |
| 13 | #define PWR_FAIL_ON 0x1 /* Always power on after power resumes */ |
| 14 | #define PWR_FAIL_PREV 0x3 /* Use previous setting after power resumes */ |
| 15 | |
| 16 | void pm_set_power_failure_state(void) |
| 17 | { |
Felix Held | 43cd1c0 | 2021-04-13 20:07:26 +0200 | [diff] [blame] | 18 | uint8_t pwr_fail = PWR_PWRSTATE; |
Karthikeyan Ramasubramanian | 2429557 | 2021-03-25 18:07:12 -0600 | [diff] [blame] | 19 | |
| 20 | switch (CONFIG_MAINBOARD_POWER_FAILURE_STATE) { |
| 21 | case MAINBOARD_POWER_STATE_OFF: |
| 22 | printk(BIOS_INFO, "Set power off after power failure.\n"); |
| 23 | pwr_fail |= PWR_FAIL_OFF; |
| 24 | break; |
| 25 | case MAINBOARD_POWER_STATE_ON: |
| 26 | printk(BIOS_INFO, "Set power on after power failure.\n"); |
| 27 | pwr_fail |= PWR_FAIL_ON; |
| 28 | break; |
| 29 | case MAINBOARD_POWER_STATE_PREVIOUS: |
| 30 | printk(BIOS_INFO, "Keep power state after power failure.\n"); |
| 31 | pwr_fail |= PWR_FAIL_PREV; |
| 32 | break; |
| 33 | default: |
| 34 | printk(BIOS_WARNING, "WARNING: Unknown power-failure state: %d\n", |
| 35 | CONFIG_MAINBOARD_POWER_FAILURE_STATE); |
| 36 | pwr_fail |= PWR_FAIL_OFF; |
| 37 | break; |
| 38 | } |
| 39 | |
Felix Held | 43cd1c0 | 2021-04-13 20:07:26 +0200 | [diff] [blame] | 40 | pm_io_write8(PM_RTC_SHADOW_REG, pwr_fail); |
Karthikeyan Ramasubramanian | 2429557 | 2021-03-25 18:07:12 -0600 | [diff] [blame] | 41 | } |