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