blob: 9cb9d528b9d9f64517cc280162a42292845bd1cb [file] [log] [blame]
Karthikeyan Ramasubramanian24295572021-03-25 18:07:12 -06001/* 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
8#define PM_RTC_SHADOW_REG 0x5b
9/* Init bit to be set by BIOS while configuring the PWR_FAIL_* shadow bits. */
10#define PWR_FAIL_INIT BIT(2)
11#define PWR_FAIL_MASK (BIT(0) | BIT(1) | BIT(2) | BIT(3))
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
16void pm_set_power_failure_state(void)
17{
18 uint8_t val, pwr_fail = PWR_FAIL_INIT;
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
40 val = pm_io_read8(PM_RTC_SHADOW_REG) & ~PWR_FAIL_MASK;
41 val |= pwr_fail;
42 pm_io_write8(PM_RTC_SHADOW_REG, val);
43}