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 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame^] | 36 | #if CONFIG(ELOG_GSMI) |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 37 | /* Log this event */ |
| 38 | if (cmd) |
| 39 | elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd); |
| 40 | #endif |
| 41 | |
| 42 | switch (cmd) { |
| 43 | case EC_HOST_EVENT_LID_CLOSED: |
| 44 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 45 | |
| 46 | /* Go to S5 */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 47 | pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 48 | pm1_cnt |= (0xf << 10); |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 49 | outl(pm1_cnt, ACPI_BASE_ADDRESS + PM1_CNT); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 50 | break; |
| 51 | } |
| 52 | |
| 53 | return cmd; |
| 54 | } |
| 55 | |
| 56 | /* gpi_sts is GPIO 47:32 */ |
| 57 | void mainboard_smi_gpi(u32 gpi_sts) |
| 58 | { |
| 59 | if (gpi_sts & (1 << (EC_SMI_GPI - 32))) { |
| 60 | /* Process all pending events */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 61 | while (mainboard_smi_ec() != 0) |
| 62 | ; |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
Matt DeVillier | 45e11aa | 2016-12-18 11:59:58 -0600 | [diff] [blame] | 66 | static void mainboard_disable_gpios(void) |
| 67 | { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame^] | 68 | #if CONFIG(BOARD_GOOGLE_SAMUS) |
Matt DeVillier | 45e11aa | 2016-12-18 11:59:58 -0600 | [diff] [blame] | 69 | /* Put SSD in reset to prevent leak */ |
| 70 | set_gpio(BOARD_SSD_RESET_GPIO, 0); |
| 71 | /* Disable LTE */ |
| 72 | set_gpio(BOARD_LTE_DISABLE_GPIO, 0); |
| 73 | #else |
| 74 | set_gpio(BOARD_PP3300_CODEC_GPIO, 0); |
| 75 | #endif |
| 76 | /* Prevent leak from standby rail to WLAN rail */ |
| 77 | set_gpio(BOARD_WLAN_DISABLE_GPIO, 0); |
| 78 | } |
| 79 | |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 80 | void mainboard_smi_sleep(u8 slp_typ) |
| 81 | { |
| 82 | /* Disable USB charging if required */ |
| 83 | switch (slp_typ) { |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 84 | case ACPI_S3: |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 85 | if (smm_get_gnvs()->s3u0 == 0) { |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 86 | google_chromeec_set_usb_charge_mode( |
| 87 | 0, USB_CHARGE_MODE_DISABLED); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 88 | google_chromeec_set_usb_charge_mode( |
| 89 | 1, USB_CHARGE_MODE_DISABLED); |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 90 | } |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 91 | |
Matt DeVillier | 45e11aa | 2016-12-18 11:59:58 -0600 | [diff] [blame] | 92 | mainboard_disable_gpios(); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 93 | |
| 94 | /* Enable wake events */ |
| 95 | google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS); |
| 96 | break; |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 97 | case ACPI_S5: |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 98 | if (smm_get_gnvs()->s5u0 == 0) { |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 99 | google_chromeec_set_usb_charge_mode( |
| 100 | 0, USB_CHARGE_MODE_DISABLED); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 101 | google_chromeec_set_usb_charge_mode( |
| 102 | 1, USB_CHARGE_MODE_DISABLED); |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 103 | } |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 104 | |
Matt DeVillier | 45e11aa | 2016-12-18 11:59:58 -0600 | [diff] [blame] | 105 | mainboard_disable_gpios(); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 106 | |
| 107 | /* Enable wake events */ |
| 108 | google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS); |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | /* Disable SCI and SMI events */ |
| 113 | google_chromeec_set_smi_mask(0); |
| 114 | google_chromeec_set_sci_mask(0); |
| 115 | |
| 116 | /* Clear pending events that may trigger immediate wake */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 117 | while (google_chromeec_get_event() != 0) |
| 118 | ; |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 119 | } |
| 120 | |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 121 | int mainboard_smi_apmc(u8 apmc) |
| 122 | { |
| 123 | switch (apmc) { |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 124 | case APM_CNT_ACPI_ENABLE: |
| 125 | google_chromeec_set_smi_mask(0); |
| 126 | /* Clear all pending events */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 127 | while (google_chromeec_get_event() != 0) |
| 128 | ; |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 129 | google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS); |
| 130 | break; |
| 131 | case APM_CNT_ACPI_DISABLE: |
| 132 | google_chromeec_set_sci_mask(0); |
| 133 | /* Clear all pending events */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 134 | while (google_chromeec_get_event() != 0) |
| 135 | ; |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 136 | google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS); |
| 137 | break; |
| 138 | } |
| 139 | return 0; |
| 140 | } |