blob: 7dce4cbbd276d45304886867d551fac343f3ce8f [file] [log] [blame]
Stefan Reinauer49428d82013-02-21 15:48:37 -08001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer49428d82013-02-21 15:48:37 -08004 *
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 Reinauer49428d82013-02-21 15:48:37 -080013 */
14
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050015#include <arch/acpi.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080016#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 Rudolphbaea5992018-06-28 14:10:27 +020021#include <southbridge/intel/common/pmbase.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080022#include <northbridge/intel/sandybridge/sandybridge.h>
23#include <cpu/intel/model_206ax/model_206ax.h>
24#include <elog.h>
25
Stefan Reinauer49428d82013-02-21 15:48:37 -080026/* Include EC functions */
27#include <ec/google/chromeec/ec.h>
28#include "ec.h"
29
Stefan Reinauer49428d82013-02-21 15:48:37 -080030static u8 mainboard_smi_ec(void)
31{
32 u8 cmd = google_chromeec_get_event();
Stefan Reinauer49428d82013-02-21 15:48:37 -080033
Stefan Reinauer49428d82013-02-21 15:48:37 -080034 /* Log this event */
35 if (cmd)
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +020036 elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
Stefan Reinauer49428d82013-02-21 15:48:37 -080037
38 switch (cmd) {
39 case EC_HOST_EVENT_LID_CLOSED:
40 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
41
42 /* Go to S5 */
Patrick Rudolphbaea5992018-06-28 14:10:27 +020043 write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10));
Stefan Reinauer49428d82013-02-21 15:48:37 -080044 break;
45 }
46
47 return cmd;
48}
49
Duncan Laurie0edc2242013-04-29 15:04:30 -070050void mainboard_smi_gpi(u32 gpi_sts)
Stefan Reinauer49428d82013-02-21 15:48:37 -080051{
52 if (gpi_sts & (1 << EC_SMI_GPI)) {
53 /* Process all pending events */
54 while (mainboard_smi_ec() != 0);
55 }
56}
57
58void mainboard_smi_sleep(u8 slp_typ)
59{
60 /* Disable USB charging if required */
61 switch (slp_typ) {
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050062 case ACPI_S3:
Stefan Reinauer49428d82013-02-21 15:48:37 -080063 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 Durbin30b0c7a2016-07-13 13:01:13 -050070 case ACPI_S5:
Stefan Reinauer49428d82013-02-21 15:48:37 -080071 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 Reinauer49428d82013-02-21 15:48:37 -080091#define APMC_ACPI_EN 0xe1
92#define APMC_ACPI_DIS 0x1e
93
Stefan Reinauer49428d82013-02-21 15:48:37 -080094int mainboard_smi_apmc(u8 apmc)
95{
96 switch (apmc) {
Stefan Reinauer49428d82013-02-21 15:48:37 -080097 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 Volleringd26da9c2013-12-22 21:38:18 +0000107 google_chromeec_set_smi_mask(LINK_EC_SMI_EVENTS);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800108 break;
109 }
110 return 0;
111}