blob: 827ec17de8207c0538402dfc52c233619abce7c8 [file] [log] [blame]
Angel Ponsfeedf232020-04-05 13:22:01 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer49428d82013-02-21 15:48:37 -08002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +03004#include <acpi/acpi_gnvs.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -08005#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 Rudolphbaea5992018-06-28 14:10:27 +020010#include <southbridge/intel/common/pmbase.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080011#include <northbridge/intel/sandybridge/sandybridge.h>
12#include <cpu/intel/model_206ax/model_206ax.h>
13#include <elog.h>
14
Stefan Reinauer49428d82013-02-21 15:48:37 -080015/* Include EC functions */
16#include <ec/google/chromeec/ec.h>
17#include "ec.h"
18
Stefan Reinauer49428d82013-02-21 15:48:37 -080019static u8 mainboard_smi_ec(void)
20{
21 u8 cmd = google_chromeec_get_event();
Stefan Reinauer49428d82013-02-21 15:48:37 -080022
Stefan Reinauer49428d82013-02-21 15:48:37 -080023 /* Log this event */
24 if (cmd)
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +020025 elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
Stefan Reinauer49428d82013-02-21 15:48:37 -080026
27 switch (cmd) {
28 case EC_HOST_EVENT_LID_CLOSED:
29 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
30
31 /* Go to S5 */
Patrick Rudolphbaea5992018-06-28 14:10:27 +020032 write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10));
Stefan Reinauer49428d82013-02-21 15:48:37 -080033 break;
34 }
35
36 return cmd;
37}
38
Duncan Laurie0edc2242013-04-29 15:04:30 -070039void mainboard_smi_gpi(u32 gpi_sts)
Stefan Reinauer49428d82013-02-21 15:48:37 -080040{
41 if (gpi_sts & (1 << EC_SMI_GPI)) {
42 /* Process all pending events */
43 while (mainboard_smi_ec() != 0);
44 }
45}
46
47void mainboard_smi_sleep(u8 slp_typ)
48{
49 /* Disable USB charging if required */
50 switch (slp_typ) {
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050051 case ACPI_S3:
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030052 if (gnvs->s3u0 == 0)
Stefan Reinauer49428d82013-02-21 15:48:37 -080053 google_chromeec_set_usb_charge_mode(
54 0, USB_CHARGE_MODE_DISABLED);
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030055 if (gnvs->s3u1 == 0)
Stefan Reinauer49428d82013-02-21 15:48:37 -080056 google_chromeec_set_usb_charge_mode(
57 1, USB_CHARGE_MODE_DISABLED);
58 break;
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050059 case ACPI_S5:
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030060 if (gnvs->s5u0 == 0)
Stefan Reinauer49428d82013-02-21 15:48:37 -080061 google_chromeec_set_usb_charge_mode(
62 0, USB_CHARGE_MODE_DISABLED);
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030063 if (gnvs->s5u1 == 0)
Stefan Reinauer49428d82013-02-21 15:48:37 -080064 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 Reinauer49428d82013-02-21 15:48:37 -080080int mainboard_smi_apmc(u8 apmc)
81{
82 switch (apmc) {
Kyösti Mälkkid4174b52020-06-27 14:25:20 +030083 case APM_CNT_ACPI_ENABLE:
Stefan Reinauer49428d82013-02-21 15:48:37 -080084 google_chromeec_set_smi_mask(0);
85 /* Clear all pending events */
86 while (google_chromeec_get_event() != 0);
87 google_chromeec_set_sci_mask(LINK_EC_SCI_EVENTS);
88 break;
Kyösti Mälkkid4174b52020-06-27 14:25:20 +030089 case APM_CNT_ACPI_DISABLE:
Stefan Reinauer49428d82013-02-21 15:48:37 -080090 google_chromeec_set_sci_mask(0);
91 /* Clear all pending events */
92 while (google_chromeec_get_event() != 0);
Idwer Volleringd26da9c2013-12-22 21:38:18 +000093 google_chromeec_set_smi_mask(LINK_EC_SMI_EVENTS);
Stefan Reinauer49428d82013-02-21 15:48:37 -080094 break;
95 }
96 return 0;
97}