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