blob: 12c1b97e870f82ba7a531d9b1b7a62113d8aa3de [file] [log] [blame]
Angel Ponsfeedf232020-04-05 13:22:01 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Stefan Reinauer49428d82013-02-21 15:48:37 -08003
Furquan Shaikh76cedd22020-05-02 10:24:23 -07004#include <acpi/acpi.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:
Stefan Reinauer49428d82013-02-21 15:48:37 -080052 if (smm_get_gnvs()->s3u0 == 0)
53 google_chromeec_set_usb_charge_mode(
54 0, USB_CHARGE_MODE_DISABLED);
55 if (smm_get_gnvs()->s3u1 == 0)
56 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:
Stefan Reinauer49428d82013-02-21 15:48:37 -080060 if (smm_get_gnvs()->s5u0 == 0)
61 google_chromeec_set_usb_charge_mode(
62 0, USB_CHARGE_MODE_DISABLED);
63 if (smm_get_gnvs()->s5u1 == 0)
64 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 -080080#define APMC_ACPI_EN 0xe1
81#define APMC_ACPI_DIS 0x1e
82
Stefan Reinauer49428d82013-02-21 15:48:37 -080083int mainboard_smi_apmc(u8 apmc)
84{
85 switch (apmc) {
Stefan Reinauer49428d82013-02-21 15:48:37 -080086 case APMC_ACPI_EN:
87 google_chromeec_set_smi_mask(0);
88 /* Clear all pending events */
89 while (google_chromeec_get_event() != 0);
90 google_chromeec_set_sci_mask(LINK_EC_SCI_EVENTS);
91 break;
92 case APMC_ACPI_DIS:
93 google_chromeec_set_sci_mask(0);
94 /* Clear all pending events */
95 while (google_chromeec_get_event() != 0);
Idwer Volleringd26da9c2013-12-22 21:38:18 +000096 google_chromeec_set_smi_mask(LINK_EC_SMI_EVENTS);
Stefan Reinauer49428d82013-02-21 15:48:37 -080097 break;
98 }
99 return 0;
100}