Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 14 | */ |
| 15 | |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 16 | #include <arch/acpi.h> |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 17 | #include <arch/io.h> |
| 18 | #include <console/console.h> |
| 19 | #include <cpu/x86/smm.h> |
Aaron Durbin | 84da959 | 2013-11-07 11:19:34 -0600 | [diff] [blame] | 20 | #include <elog.h> |
| 21 | |
| 22 | #include <ec/google/chromeec/ec.h> |
| 23 | #include "ec.h" |
| 24 | |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 25 | #include <soc/nvs.h> |
| 26 | #include <soc/pmc.h> |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 27 | |
Aaron Durbin | 3fbf671 | 2013-11-11 14:55:47 -0600 | [diff] [blame] | 28 | /* The wake gpio is SUS_GPIO[0]. */ |
| 29 | #define WAKE_GPIO_EN SUS_GPIO_EN0 |
| 30 | |
Aaron Durbin | 84da959 | 2013-11-07 11:19:34 -0600 | [diff] [blame] | 31 | static uint8_t mainboard_smi_ec(void) |
| 32 | { |
| 33 | uint8_t cmd = google_chromeec_get_event(); |
| 34 | uint16_t pmbase = get_pmbase(); |
| 35 | uint32_t pm1_cnt; |
| 36 | |
Martin Roth | 356b519 | 2017-06-24 21:53:37 -0600 | [diff] [blame] | 37 | #if IS_ENABLED(CONFIG_ELOG_GSMI) |
Aaron Durbin | 84da959 | 2013-11-07 11:19:34 -0600 | [diff] [blame] | 38 | /* Log this event */ |
| 39 | if (cmd) |
| 40 | elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd); |
| 41 | #endif |
| 42 | |
| 43 | switch (cmd) { |
| 44 | case EC_HOST_EVENT_LID_CLOSED: |
| 45 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 46 | |
| 47 | /* Go to S5 */ |
| 48 | pm1_cnt = inl(pmbase + PM1_CNT); |
Aaron Durbin | 3fbf671 | 2013-11-11 14:55:47 -0600 | [diff] [blame] | 49 | pm1_cnt |= SLP_EN | (SLP_TYP_S5 << SLP_TYP_SHIFT); |
Aaron Durbin | 84da959 | 2013-11-07 11:19:34 -0600 | [diff] [blame] | 50 | outl(pm1_cnt, pmbase + PM1_CNT); |
| 51 | break; |
| 52 | } |
| 53 | |
| 54 | return cmd; |
| 55 | } |
| 56 | |
Aaron Durbin | 3fbf671 | 2013-11-11 14:55:47 -0600 | [diff] [blame] | 57 | /* The entire 32-bit ALT_GPIO_SMI register is passed as a parameter. Note, that |
| 58 | * this includes the enable bits in the lower 16 bits. */ |
| 59 | void mainboard_smi_gpi(uint32_t alt_gpio_smi) |
Aaron Durbin | 84da959 | 2013-11-07 11:19:34 -0600 | [diff] [blame] | 60 | { |
Aaron Durbin | 3fbf671 | 2013-11-11 14:55:47 -0600 | [diff] [blame] | 61 | if (alt_gpio_smi & (1 << EC_SMI_GPI)) { |
Aaron Durbin | 84da959 | 2013-11-07 11:19:34 -0600 | [diff] [blame] | 62 | /* Process all pending events */ |
| 63 | while (mainboard_smi_ec() != 0); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | void mainboard_smi_sleep(uint8_t slp_typ) |
| 68 | { |
| 69 | /* Disable USB charging if required */ |
| 70 | switch (slp_typ) { |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 71 | case ACPI_S3: |
Aaron Durbin | 84da959 | 2013-11-07 11:19:34 -0600 | [diff] [blame] | 72 | if (smm_get_gnvs()->s3u0 == 0) |
| 73 | google_chromeec_set_usb_charge_mode( |
| 74 | 0, USB_CHARGE_MODE_DISABLED); |
| 75 | if (smm_get_gnvs()->s3u1 == 0) |
| 76 | google_chromeec_set_usb_charge_mode( |
| 77 | 1, USB_CHARGE_MODE_DISABLED); |
| 78 | |
| 79 | /* Enable wake events */ |
| 80 | google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS); |
Aaron Durbin | 3fbf671 | 2013-11-11 14:55:47 -0600 | [diff] [blame] | 81 | /* Enable wake pin in GPE block. */ |
| 82 | enable_gpe(WAKE_GPIO_EN); |
Aaron Durbin | 84da959 | 2013-11-07 11:19:34 -0600 | [diff] [blame] | 83 | break; |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 84 | case ACPI_S5: |
Aaron Durbin | 84da959 | 2013-11-07 11:19:34 -0600 | [diff] [blame] | 85 | if (smm_get_gnvs()->s5u0 == 0) |
| 86 | google_chromeec_set_usb_charge_mode( |
| 87 | 0, USB_CHARGE_MODE_DISABLED); |
| 88 | if (smm_get_gnvs()->s5u1 == 0) |
| 89 | google_chromeec_set_usb_charge_mode( |
| 90 | 1, USB_CHARGE_MODE_DISABLED); |
| 91 | |
| 92 | /* Enable wake events */ |
| 93 | google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS); |
| 94 | break; |
| 95 | } |
| 96 | |
| 97 | /* Disable SCI and SMI events */ |
| 98 | google_chromeec_set_smi_mask(0); |
| 99 | google_chromeec_set_sci_mask(0); |
| 100 | |
| 101 | /* Clear pending events that may trigger immediate wake */ |
| 102 | while (google_chromeec_get_event() != 0); |
| 103 | } |
| 104 | |
Aaron Durbin | 84da959 | 2013-11-07 11:19:34 -0600 | [diff] [blame] | 105 | int mainboard_smi_apmc(uint8_t apmc) |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 106 | { |
| 107 | switch (apmc) { |
Aaron Durbin | 84da959 | 2013-11-07 11:19:34 -0600 | [diff] [blame] | 108 | case APM_CNT_ACPI_ENABLE: |
| 109 | google_chromeec_set_smi_mask(0); |
| 110 | /* Clear all pending events */ |
| 111 | while (google_chromeec_get_event() != 0); |
| 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 */ |
| 117 | while (google_chromeec_get_event() != 0); |
Edward O'Callaghan | 48b6b97 | 2014-11-09 12:06:19 +1100 | [diff] [blame] | 118 | google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS); |
Aaron Durbin | 84da959 | 2013-11-07 11:19:34 -0600 | [diff] [blame] | 119 | break; |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 120 | } |
| 121 | return 0; |
| 122 | } |