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