Angel Pons | feedf23 | 2020-04-05 13:22:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 3 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame^] | 4 | #include <acpi/acpi.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <cpu/x86/smm.h> |
| 7 | #include <southbridge/intel/bd82x6x/nvs.h> |
| 8 | #include <southbridge/intel/bd82x6x/pch.h> |
| 9 | #include <southbridge/intel/bd82x6x/me.h> |
Patrick Rudolph | baea599 | 2018-06-28 14:10:27 +0200 | [diff] [blame] | 10 | #include <southbridge/intel/common/pmbase.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 11 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 12 | #include <cpu/intel/model_206ax/model_206ax.h> |
| 13 | #include <elog.h> |
| 14 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 15 | /* Include EC functions */ |
| 16 | #include <ec/google/chromeec/ec.h> |
| 17 | #include "ec.h" |
| 18 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 19 | static u8 mainboard_smi_ec(void) |
| 20 | { |
| 21 | u8 cmd = google_chromeec_get_event(); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 22 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 23 | /* Log this event */ |
| 24 | if (cmd) |
Kyösti Mälkki | 9dd1a12 | 2019-11-06 11:04:27 +0200 | [diff] [blame] | 25 | elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT, cmd); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 26 | |
| 27 | switch (cmd) { |
| 28 | case EC_HOST_EVENT_LID_CLOSED: |
| 29 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 30 | |
| 31 | /* Go to S5 */ |
Patrick Rudolph | baea599 | 2018-06-28 14:10:27 +0200 | [diff] [blame] | 32 | write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10)); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 33 | break; |
| 34 | } |
| 35 | |
| 36 | return cmd; |
| 37 | } |
| 38 | |
Duncan Laurie | 0edc224 | 2013-04-29 15:04:30 -0700 | [diff] [blame] | 39 | void mainboard_smi_gpi(u32 gpi_sts) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 40 | { |
| 41 | if (gpi_sts & (1 << EC_SMI_GPI)) { |
| 42 | /* Process all pending events */ |
| 43 | while (mainboard_smi_ec() != 0); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void mainboard_smi_sleep(u8 slp_typ) |
| 48 | { |
| 49 | /* Disable USB charging if required */ |
| 50 | switch (slp_typ) { |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 51 | case ACPI_S3: |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 52 | if (smm_get_gnvs()->s3u0 == 0) |
| 53 | google_chromeec_set_usb_charge_mode( |
| 54 | 0, USB_CHARGE_MODE_DISABLED); |
| 55 | if (smm_get_gnvs()->s3u1 == 0) |
| 56 | google_chromeec_set_usb_charge_mode( |
| 57 | 1, USB_CHARGE_MODE_DISABLED); |
| 58 | break; |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 59 | case ACPI_S5: |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 60 | if (smm_get_gnvs()->s5u0 == 0) |
| 61 | google_chromeec_set_usb_charge_mode( |
| 62 | 0, USB_CHARGE_MODE_DISABLED); |
| 63 | if (smm_get_gnvs()->s5u1 == 0) |
| 64 | google_chromeec_set_usb_charge_mode( |
| 65 | 1, USB_CHARGE_MODE_DISABLED); |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | /* Disable SCI and SMI events */ |
| 70 | google_chromeec_set_smi_mask(0); |
| 71 | google_chromeec_set_sci_mask(0); |
| 72 | |
| 73 | /* Clear pending events that may trigger immediate wake */ |
| 74 | while (google_chromeec_get_event() != 0); |
| 75 | |
| 76 | /* Enable wake events */ |
| 77 | google_chromeec_set_wake_mask(LINK_EC_S3_WAKE_EVENTS); |
| 78 | } |
| 79 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 80 | #define APMC_ACPI_EN 0xe1 |
| 81 | #define APMC_ACPI_DIS 0x1e |
| 82 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 83 | int mainboard_smi_apmc(u8 apmc) |
| 84 | { |
| 85 | switch (apmc) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 86 | case APMC_ACPI_EN: |
| 87 | google_chromeec_set_smi_mask(0); |
| 88 | /* Clear all pending events */ |
| 89 | while (google_chromeec_get_event() != 0); |
| 90 | google_chromeec_set_sci_mask(LINK_EC_SCI_EVENTS); |
| 91 | break; |
| 92 | case APMC_ACPI_DIS: |
| 93 | google_chromeec_set_sci_mask(0); |
| 94 | /* Clear all pending events */ |
| 95 | while (google_chromeec_get_event() != 0); |
Idwer Vollering | d26da9c | 2013-12-22 21:38:18 +0000 | [diff] [blame] | 96 | google_chromeec_set_smi_mask(LINK_EC_SMI_EVENTS); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 97 | break; |
| 98 | } |
| 99 | return 0; |
| 100 | } |