Angel Pons | d28443e | 2020-04-05 13:22:44 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Matt DeVillier | c12e5ae | 2016-11-27 02:19:02 -0600 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Matt DeVillier | c12e5ae | 2016-11-27 02:19:02 -0600 | [diff] [blame] | 4 | #include <arch/io.h> |
| 5 | #include <console/console.h> |
| 6 | #include <cpu/x86/smm.h> |
Kyösti Mälkki | 661ad46 | 2020-12-29 06:26:21 +0200 | [diff] [blame^] | 7 | #include <soc/nvs.h> |
Matt DeVillier | c12e5ae | 2016-11-27 02:19:02 -0600 | [diff] [blame] | 8 | #include <southbridge/intel/lynxpoint/pch.h> |
| 9 | #include <southbridge/intel/common/gpio.h> |
| 10 | #include <southbridge/intel/lynxpoint/me.h> |
| 11 | #include <northbridge/intel/haswell/haswell.h> |
| 12 | #include <cpu/intel/haswell/haswell.h> |
| 13 | #include <elog.h> |
| 14 | |
| 15 | /* Include EC functions */ |
| 16 | #include <ec/google/chromeec/ec.h> |
| 17 | #include "ec.h" |
| 18 | |
| 19 | /* Codec enable: GPIO45 */ |
| 20 | #define GPIO_PP3300_CODEC_EN 45 |
| 21 | /* GPIO46 controls the WLAN_DISABLE_L signal. */ |
| 22 | #define GPIO_WLAN_DISABLE_L 46 |
| 23 | #define GPIO_LTE_DISABLE_L 59 |
| 24 | |
| 25 | static u8 mainboard_smi_ec(void) |
| 26 | { |
| 27 | u8 cmd = google_chromeec_get_event(); |
| 28 | u32 pm1_cnt; |
| 29 | |
Matt DeVillier | c12e5ae | 2016-11-27 02:19:02 -0600 | [diff] [blame] | 30 | /* Log this event */ |
| 31 | if (cmd) |
Kyösti Mälkki | 9dd1a12 | 2019-11-06 11:04:27 +0200 | [diff] [blame] | 32 | elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT, cmd); |
Matt DeVillier | c12e5ae | 2016-11-27 02:19:02 -0600 | [diff] [blame] | 33 | |
| 34 | switch (cmd) { |
| 35 | case EC_HOST_EVENT_LID_CLOSED: |
| 36 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 37 | |
| 38 | /* Go to S5 */ |
| 39 | pm1_cnt = inl(get_pmbase() + PM1_CNT); |
| 40 | pm1_cnt |= (0xf << 10); |
| 41 | outl(pm1_cnt, get_pmbase() + PM1_CNT); |
| 42 | break; |
| 43 | } |
| 44 | |
| 45 | return cmd; |
| 46 | } |
| 47 | |
| 48 | /* gpi_sts is GPIO 47:32 */ |
| 49 | void mainboard_smi_gpi(u32 gpi_sts) |
| 50 | { |
| 51 | if (gpi_sts & (1 << (EC_SMI_GPI - 32))) { |
| 52 | /* Process all pending events */ |
| 53 | while (mainboard_smi_ec() != 0); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | void mainboard_smi_sleep(u8 slp_typ) |
| 58 | { |
| 59 | /* Disable USB charging if required */ |
| 60 | switch (slp_typ) { |
| 61 | case ACPI_S3: |
Kyösti Mälkki | 239abaf | 2020-06-28 12:12:01 +0300 | [diff] [blame] | 62 | if (gnvs->s3u0 == 0) |
Matt DeVillier | c12e5ae | 2016-11-27 02:19:02 -0600 | [diff] [blame] | 63 | google_chromeec_set_usb_charge_mode( |
| 64 | 0, USB_CHARGE_MODE_DISABLED); |
Kyösti Mälkki | 239abaf | 2020-06-28 12:12:01 +0300 | [diff] [blame] | 65 | if (gnvs->s3u1 == 0) |
Matt DeVillier | c12e5ae | 2016-11-27 02:19:02 -0600 | [diff] [blame] | 66 | google_chromeec_set_usb_charge_mode( |
| 67 | 1, USB_CHARGE_MODE_DISABLED); |
| 68 | |
| 69 | /* Prevent leak from standby rail to WLAN rail in S3. */ |
| 70 | set_gpio(GPIO_WLAN_DISABLE_L, 0); |
| 71 | set_gpio(GPIO_PP3300_CODEC_EN, 0); |
| 72 | /* Disable LTE */ |
| 73 | set_gpio(GPIO_LTE_DISABLE_L, 0); |
| 74 | |
| 75 | /* Enable wake events */ |
| 76 | google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS); |
| 77 | break; |
| 78 | case ACPI_S4: |
| 79 | case ACPI_S5: |
Kyösti Mälkki | 239abaf | 2020-06-28 12:12:01 +0300 | [diff] [blame] | 80 | if (gnvs->s5u0 == 0) |
Matt DeVillier | c12e5ae | 2016-11-27 02:19:02 -0600 | [diff] [blame] | 81 | google_chromeec_set_usb_charge_mode( |
| 82 | 0, USB_CHARGE_MODE_DISABLED); |
Kyösti Mälkki | 239abaf | 2020-06-28 12:12:01 +0300 | [diff] [blame] | 83 | if (gnvs->s5u1 == 0) |
Matt DeVillier | c12e5ae | 2016-11-27 02:19:02 -0600 | [diff] [blame] | 84 | google_chromeec_set_usb_charge_mode( |
| 85 | 1, USB_CHARGE_MODE_DISABLED); |
| 86 | |
| 87 | /* Prevent leak from standby rail to WLAN rail in S5. */ |
| 88 | set_gpio(GPIO_WLAN_DISABLE_L, 0); |
| 89 | set_gpio(GPIO_PP3300_CODEC_EN, 0); |
| 90 | /* Disable LTE */ |
| 91 | set_gpio(GPIO_LTE_DISABLE_L, 0); |
| 92 | |
| 93 | /* Enable wake events */ |
| 94 | google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS); |
| 95 | break; |
| 96 | } |
| 97 | |
| 98 | /* Disable SCI and SMI events */ |
| 99 | google_chromeec_set_smi_mask(0); |
| 100 | google_chromeec_set_sci_mask(0); |
| 101 | |
| 102 | /* Clear pending events that may trigger immediate wake */ |
| 103 | while (google_chromeec_get_event() != 0); |
| 104 | } |
| 105 | |
Matt DeVillier | c12e5ae | 2016-11-27 02:19:02 -0600 | [diff] [blame] | 106 | int mainboard_smi_apmc(u8 apmc) |
| 107 | { |
| 108 | switch (apmc) { |
Matt DeVillier | c12e5ae | 2016-11-27 02:19:02 -0600 | [diff] [blame] | 109 | case APM_CNT_ACPI_ENABLE: |
| 110 | google_chromeec_set_smi_mask(0); |
| 111 | /* Clear all pending events */ |
| 112 | while (google_chromeec_get_event() != 0); |
| 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 */ |
| 118 | while (google_chromeec_get_event() != 0); |
| 119 | google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS); |
| 120 | break; |
| 121 | } |
| 122 | return 0; |
| 123 | } |