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