Angel Pons | 58c0d32 | 2020-04-05 13:20:46 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 3 | |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 4 | #include <arch/acpi.h> |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 5 | #include <arch/io.h> |
| 6 | #include <console/console.h> |
| 7 | #include <cpu/x86/smm.h> |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 8 | #include <soc/pm.h> |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 9 | #include <elog.h> |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 10 | #include <ec/google/chromeec/ec.h> |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 11 | #include <soc/gpio.h> |
| 12 | #include <soc/iomap.h> |
| 13 | #include <soc/nvs.h> |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 14 | #include "ec.h" |
Matt DeVillier | 45e11aa | 2016-12-18 11:59:58 -0600 | [diff] [blame] | 15 | #include <variant/onboard.h> |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 16 | |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 17 | static u8 mainboard_smi_ec(void) |
| 18 | { |
| 19 | u8 cmd = google_chromeec_get_event(); |
| 20 | u32 pm1_cnt; |
| 21 | |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 22 | /* Log this event */ |
| 23 | if (cmd) |
Kyösti Mälkki | 9dd1a12 | 2019-11-06 11:04:27 +0200 | [diff] [blame] | 24 | elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT, cmd); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 25 | |
| 26 | switch (cmd) { |
| 27 | case EC_HOST_EVENT_LID_CLOSED: |
| 28 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 29 | |
| 30 | /* Go to S5 */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 31 | pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 32 | pm1_cnt |= (0xf << 10); |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 33 | outl(pm1_cnt, ACPI_BASE_ADDRESS + PM1_CNT); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 34 | break; |
| 35 | } |
| 36 | |
| 37 | return cmd; |
| 38 | } |
| 39 | |
| 40 | /* gpi_sts is GPIO 47:32 */ |
| 41 | void mainboard_smi_gpi(u32 gpi_sts) |
| 42 | { |
| 43 | if (gpi_sts & (1 << (EC_SMI_GPI - 32))) { |
| 44 | /* Process all pending events */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 45 | while (mainboard_smi_ec() != 0) |
| 46 | ; |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
Matt DeVillier | 45e11aa | 2016-12-18 11:59:58 -0600 | [diff] [blame] | 50 | static void mainboard_disable_gpios(void) |
| 51 | { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 52 | #if CONFIG(BOARD_GOOGLE_SAMUS) |
Matt DeVillier | 45e11aa | 2016-12-18 11:59:58 -0600 | [diff] [blame] | 53 | /* Put SSD in reset to prevent leak */ |
| 54 | set_gpio(BOARD_SSD_RESET_GPIO, 0); |
| 55 | /* Disable LTE */ |
| 56 | set_gpio(BOARD_LTE_DISABLE_GPIO, 0); |
| 57 | #else |
| 58 | set_gpio(BOARD_PP3300_CODEC_GPIO, 0); |
| 59 | #endif |
| 60 | /* Prevent leak from standby rail to WLAN rail */ |
| 61 | set_gpio(BOARD_WLAN_DISABLE_GPIO, 0); |
| 62 | } |
| 63 | |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 64 | void mainboard_smi_sleep(u8 slp_typ) |
| 65 | { |
| 66 | /* Disable USB charging if required */ |
| 67 | switch (slp_typ) { |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 68 | case ACPI_S3: |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 69 | if (smm_get_gnvs()->s3u0 == 0) { |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 70 | google_chromeec_set_usb_charge_mode( |
| 71 | 0, USB_CHARGE_MODE_DISABLED); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 72 | google_chromeec_set_usb_charge_mode( |
| 73 | 1, USB_CHARGE_MODE_DISABLED); |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 74 | } |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 75 | |
Matt DeVillier | 45e11aa | 2016-12-18 11:59:58 -0600 | [diff] [blame] | 76 | mainboard_disable_gpios(); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 77 | |
| 78 | /* Enable wake events */ |
| 79 | google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS); |
| 80 | break; |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 81 | case ACPI_S5: |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 82 | if (smm_get_gnvs()->s5u0 == 0) { |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 83 | google_chromeec_set_usb_charge_mode( |
| 84 | 0, USB_CHARGE_MODE_DISABLED); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 85 | google_chromeec_set_usb_charge_mode( |
| 86 | 1, USB_CHARGE_MODE_DISABLED); |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 87 | } |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 88 | |
Matt DeVillier | 45e11aa | 2016-12-18 11:59:58 -0600 | [diff] [blame] | 89 | mainboard_disable_gpios(); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 90 | |
| 91 | /* Enable wake events */ |
| 92 | google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS); |
| 93 | break; |
| 94 | } |
| 95 | |
| 96 | /* Disable SCI and SMI events */ |
| 97 | google_chromeec_set_smi_mask(0); |
| 98 | google_chromeec_set_sci_mask(0); |
| 99 | |
| 100 | /* Clear pending events that may trigger immediate wake */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 101 | while (google_chromeec_get_event() != 0) |
| 102 | ; |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 103 | } |
| 104 | |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 105 | int mainboard_smi_apmc(u8 apmc) |
| 106 | { |
| 107 | switch (apmc) { |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 108 | case APM_CNT_ACPI_ENABLE: |
| 109 | google_chromeec_set_smi_mask(0); |
| 110 | /* Clear all pending events */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 111 | while (google_chromeec_get_event() != 0) |
| 112 | ; |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 113 | google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS); |
| 114 | break; |
| 115 | case APM_CNT_ACPI_DISABLE: |
| 116 | google_chromeec_set_sci_mask(0); |
| 117 | /* Clear all pending events */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 118 | while (google_chromeec_get_event() != 0) |
| 119 | ; |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 120 | google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS); |
| 121 | break; |
| 122 | } |
| 123 | return 0; |
| 124 | } |