Kyösti Mälkki | 4a3f67a | 2020-06-18 13:44:29 +0300 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi.h> |
Kyösti Mälkki | 2787237 | 2021-01-21 16:05:26 +0200 | [diff] [blame] | 4 | #include <acpi/acpi_pm.h> |
| 5 | #include <cbmem.h> |
| 6 | #include <console/console.h> |
Kyösti Mälkki | e0d3868 | 2020-06-07 12:01:58 +0300 | [diff] [blame] | 7 | #include <smbios.h> |
Kyösti Mälkki | 4a3f67a | 2020-06-18 13:44:29 +0300 | [diff] [blame] | 8 | |
Kyösti Mälkki | 4a3f67a | 2020-06-18 13:44:29 +0300 | [diff] [blame] | 9 | void __weak mainboard_suspend_resume(void) |
| 10 | { |
| 11 | } |
Kyösti Mälkki | e0d3868 | 2020-06-07 12:01:58 +0300 | [diff] [blame] | 12 | |
| 13 | /* Default mapping to ACPI FADT preferred_pm_profile field. */ |
| 14 | uint8_t acpi_get_preferred_pm_profile(void) |
| 15 | { |
| 16 | switch (smbios_mainboard_enclosure_type()) { |
| 17 | case SMBIOS_ENCLOSURE_LAPTOP: |
| 18 | case SMBIOS_ENCLOSURE_CONVERTIBLE: |
| 19 | return PM_MOBILE; |
| 20 | case SMBIOS_ENCLOSURE_DETACHABLE: |
| 21 | case SMBIOS_ENCLOSURE_TABLET: |
| 22 | return PM_TABLET; |
| 23 | case SMBIOS_ENCLOSURE_DESKTOP: |
| 24 | return PM_DESKTOP; |
| 25 | case SMBIOS_ENCLOSURE_UNKNOWN: |
| 26 | default: |
| 27 | return PM_UNSPECIFIED; |
| 28 | } |
| 29 | } |
Kyösti Mälkki | 2787237 | 2021-01-21 16:05:26 +0200 | [diff] [blame] | 30 | |
| 31 | struct chipset_power_state *acpi_get_pm_state(void) |
| 32 | { |
| 33 | static struct chipset_power_state *acpi_pm_state; |
| 34 | if (acpi_pm_state) |
| 35 | return acpi_pm_state; |
| 36 | |
| 37 | acpi_pm_state = cbmem_find(CBMEM_ID_POWER_STATE); |
| 38 | return acpi_pm_state; |
| 39 | } |
| 40 | |
| 41 | int acpi_pm_state_for_elog(const struct chipset_power_state **ps) |
| 42 | { |
| 43 | *ps = acpi_get_pm_state(); |
| 44 | if (!*ps) { |
| 45 | printk(BIOS_ERR, "No CBMEM_ID_POWER_STATE entry, no event recorded in ELOG.\n"); |
| 46 | return -1; |
| 47 | } |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | int acpi_pm_state_for_rtc(const struct chipset_power_state **ps) |
| 52 | { |
| 53 | *ps = acpi_get_pm_state(); |
| 54 | if (!*ps) { |
| 55 | printk(BIOS_ERR, "No CBMEM_ID_POWER_STATE entry, RTC init aborted.\n"); |
| 56 | return -1; |
| 57 | } |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | int acpi_pm_state_for_wake(const struct chipset_power_state **ps) |
| 62 | { |
| 63 | *ps = acpi_get_pm_state(); |
| 64 | if (!*ps) { |
| 65 | printk(BIOS_ERR, "No CBMEM_ID_POWER_STATE entry, wake source unknown.\n"); |
| 66 | return -1; |
| 67 | } |
| 68 | return 0; |
| 69 | } |