Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [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. |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 16 | #include <arch/acpi.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 17 | #include <console/console.h> |
| 18 | #include <cpu/x86/smm.h> |
| 19 | #include <southbridge/intel/bd82x6x/nvs.h> |
| 20 | #include <southbridge/intel/bd82x6x/pch.h> |
| 21 | #include <southbridge/intel/bd82x6x/me.h> |
Patrick Rudolph | baea599 | 2018-06-28 14:10:27 +0200 | [diff] [blame] | 22 | #include <southbridge/intel/common/pmbase.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 23 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 24 | #include <cpu/intel/model_206ax/model_206ax.h> |
| 25 | #include <elog.h> |
| 26 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 27 | /* Include EC functions */ |
| 28 | #include <ec/google/chromeec/ec.h> |
| 29 | #include "ec.h" |
| 30 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 31 | static u8 mainboard_smi_ec(void) |
| 32 | { |
| 33 | u8 cmd = google_chromeec_get_event(); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 34 | |
Martin Roth | 356b519 | 2017-06-24 21:53:37 -0600 | [diff] [blame] | 35 | #if IS_ENABLED(CONFIG_ELOG_GSMI) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 36 | /* Log this event */ |
| 37 | if (cmd) |
| 38 | elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd); |
| 39 | #endif |
| 40 | |
| 41 | switch (cmd) { |
| 42 | case EC_HOST_EVENT_LID_CLOSED: |
| 43 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 44 | |
| 45 | /* Go to S5 */ |
Patrick Rudolph | baea599 | 2018-06-28 14:10:27 +0200 | [diff] [blame] | 46 | write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10)); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 47 | break; |
| 48 | } |
| 49 | |
| 50 | return cmd; |
| 51 | } |
| 52 | |
Duncan Laurie | 0edc224 | 2013-04-29 15:04:30 -0700 | [diff] [blame] | 53 | void mainboard_smi_gpi(u32 gpi_sts) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 54 | { |
| 55 | if (gpi_sts & (1 << EC_SMI_GPI)) { |
| 56 | /* Process all pending events */ |
| 57 | while (mainboard_smi_ec() != 0); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | void mainboard_smi_sleep(u8 slp_typ) |
| 62 | { |
| 63 | /* Disable USB charging if required */ |
| 64 | switch (slp_typ) { |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 65 | case ACPI_S3: |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 66 | if (smm_get_gnvs()->s3u0 == 0) |
| 67 | google_chromeec_set_usb_charge_mode( |
| 68 | 0, USB_CHARGE_MODE_DISABLED); |
| 69 | if (smm_get_gnvs()->s3u1 == 0) |
| 70 | google_chromeec_set_usb_charge_mode( |
| 71 | 1, USB_CHARGE_MODE_DISABLED); |
| 72 | break; |
Aaron Durbin | 30b0c7a | 2016-07-13 13:01:13 -0500 | [diff] [blame] | 73 | case ACPI_S5: |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 74 | if (smm_get_gnvs()->s5u0 == 0) |
| 75 | google_chromeec_set_usb_charge_mode( |
| 76 | 0, USB_CHARGE_MODE_DISABLED); |
| 77 | if (smm_get_gnvs()->s5u1 == 0) |
| 78 | google_chromeec_set_usb_charge_mode( |
| 79 | 1, USB_CHARGE_MODE_DISABLED); |
| 80 | break; |
| 81 | } |
| 82 | |
| 83 | /* Disable SCI and SMI events */ |
| 84 | google_chromeec_set_smi_mask(0); |
| 85 | google_chromeec_set_sci_mask(0); |
| 86 | |
| 87 | /* Clear pending events that may trigger immediate wake */ |
| 88 | while (google_chromeec_get_event() != 0); |
| 89 | |
| 90 | /* Enable wake events */ |
| 91 | google_chromeec_set_wake_mask(LINK_EC_S3_WAKE_EVENTS); |
| 92 | } |
| 93 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 94 | #define APMC_ACPI_EN 0xe1 |
| 95 | #define APMC_ACPI_DIS 0x1e |
| 96 | |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 97 | int mainboard_smi_apmc(u8 apmc) |
| 98 | { |
| 99 | switch (apmc) { |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 100 | case APMC_ACPI_EN: |
| 101 | google_chromeec_set_smi_mask(0); |
| 102 | /* Clear all pending events */ |
| 103 | while (google_chromeec_get_event() != 0); |
| 104 | google_chromeec_set_sci_mask(LINK_EC_SCI_EVENTS); |
| 105 | break; |
| 106 | case APMC_ACPI_DIS: |
| 107 | google_chromeec_set_sci_mask(0); |
| 108 | /* Clear all pending events */ |
| 109 | while (google_chromeec_get_event() != 0); |
Idwer Vollering | d26da9c | 2013-12-22 21:38:18 +0000 | [diff] [blame] | 110 | google_chromeec_set_smi_mask(LINK_EC_SMI_EVENTS); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 111 | break; |
| 112 | } |
| 113 | return 0; |
| 114 | } |