Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 13 | */ |
| 14 | |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 15 | #include <arch/acpi.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 16 | #include <console/console.h> |
| 17 | #include <cpu/x86/smm.h> |
| 18 | #include <southbridge/intel/bd82x6x/nvs.h> |
| 19 | #include <southbridge/intel/bd82x6x/pch.h> |
| 20 | #include <southbridge/intel/bd82x6x/me.h> |
Patrick Rudolph | baea599 | 2018-06-28 14:10:27 +0200 | [diff] [blame] | 21 | #include <southbridge/intel/common/pmbase.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 22 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 23 | #include <cpu/intel/model_206ax/model_206ax.h> |
| 24 | #include <elog.h> |
| 25 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 26 | /* Include EC functions */ |
| 27 | #include <ec/google/chromeec/ec.h> |
| 28 | #include "ec.h" |
| 29 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 30 | static u8 mainboard_smi_ec(void) |
| 31 | { |
| 32 | u8 cmd = google_chromeec_get_event(); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 33 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 34 | /* Log this event */ |
| 35 | if (cmd) |
Kyösti Mälkki | 9dd1a12 | 2019-11-06 11:04:27 +0200 | [diff] [blame] | 36 | elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT, cmd); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 37 | |
| 38 | switch (cmd) { |
| 39 | case EC_HOST_EVENT_LID_CLOSED: |
| 40 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 41 | |
| 42 | /* Go to S5 */ |
Patrick Rudolph | baea599 | 2018-06-28 14:10:27 +0200 | [diff] [blame] | 43 | write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10)); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 44 | break; |
| 45 | } |
| 46 | |
| 47 | return cmd; |
| 48 | } |
| 49 | |
Duncan Laurie | 0edc224 | 2013-04-29 15:04:30 -0700 | [diff] [blame] | 50 | void mainboard_smi_gpi(u32 gpi_sts) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 51 | { |
| 52 | if (gpi_sts & (1 << EC_SMI_GPI)) { |
| 53 | /* Process all pending events */ |
| 54 | while (mainboard_smi_ec() != 0); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void mainboard_smi_sleep(u8 slp_typ) |
| 59 | { |
| 60 | /* Disable USB charging if required */ |
| 61 | switch (slp_typ) { |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 62 | case ACPI_S3: |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 63 | if (smm_get_gnvs()->s3u0 == 0) |
| 64 | google_chromeec_set_usb_charge_mode( |
| 65 | 0, USB_CHARGE_MODE_DISABLED); |
| 66 | if (smm_get_gnvs()->s3u1 == 0) |
| 67 | google_chromeec_set_usb_charge_mode( |
| 68 | 1, USB_CHARGE_MODE_DISABLED); |
| 69 | break; |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 70 | case ACPI_S5: |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 71 | if (smm_get_gnvs()->s5u0 == 0) |
| 72 | google_chromeec_set_usb_charge_mode( |
| 73 | 0, USB_CHARGE_MODE_DISABLED); |
| 74 | if (smm_get_gnvs()->s5u1 == 0) |
| 75 | google_chromeec_set_usb_charge_mode( |
| 76 | 1, USB_CHARGE_MODE_DISABLED); |
| 77 | break; |
| 78 | } |
| 79 | |
| 80 | /* Disable SCI and SMI events */ |
| 81 | google_chromeec_set_smi_mask(0); |
| 82 | google_chromeec_set_sci_mask(0); |
| 83 | |
| 84 | /* Clear pending events that may trigger immediate wake */ |
| 85 | while (google_chromeec_get_event() != 0); |
| 86 | |
| 87 | /* Enable wake events */ |
| 88 | google_chromeec_set_wake_mask(LINK_EC_S3_WAKE_EVENTS); |
| 89 | } |
| 90 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 91 | #define APMC_ACPI_EN 0xe1 |
| 92 | #define APMC_ACPI_DIS 0x1e |
| 93 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 94 | int mainboard_smi_apmc(u8 apmc) |
| 95 | { |
| 96 | switch (apmc) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 97 | case APMC_ACPI_EN: |
| 98 | google_chromeec_set_smi_mask(0); |
| 99 | /* Clear all pending events */ |
| 100 | while (google_chromeec_get_event() != 0); |
| 101 | google_chromeec_set_sci_mask(LINK_EC_SCI_EVENTS); |
| 102 | break; |
| 103 | case APMC_ACPI_DIS: |
| 104 | google_chromeec_set_sci_mask(0); |
| 105 | /* Clear all pending events */ |
| 106 | while (google_chromeec_get_event() != 0); |
Idwer Vollering | d26da9c | 2013-12-22 21:38:18 +0000 | [diff] [blame] | 107 | google_chromeec_set_smi_mask(LINK_EC_SMI_EVENTS); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 108 | break; |
| 109 | } |
| 110 | return 0; |
| 111 | } |