blob: 0bd164e959ae1a3bccb2f3f1132bd05e52bea410 [file] [log] [blame]
Stefan Reinauer49428d82013-02-21 15:48:37 -08001/*
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 Reinauer49428d82013-02-21 15:48:37 -080014 */
15
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050016#include <arch/acpi.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080017#include <arch/io.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080018#include <console/console.h>
19#include <cpu/x86/smm.h>
20#include <southbridge/intel/bd82x6x/nvs.h>
21#include <southbridge/intel/bd82x6x/pch.h>
22#include <southbridge/intel/bd82x6x/me.h>
Patrick Rudolphbaea5992018-06-28 14:10:27 +020023#include <southbridge/intel/common/pmbase.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080024#include <northbridge/intel/sandybridge/sandybridge.h>
25#include <cpu/intel/model_206ax/model_206ax.h>
26#include <elog.h>
27
Stefan Reinauer49428d82013-02-21 15:48:37 -080028/* Include EC functions */
29#include <ec/google/chromeec/ec.h>
30#include "ec.h"
31
Stefan Reinauer49428d82013-02-21 15:48:37 -080032static u8 mainboard_smi_ec(void)
33{
34 u8 cmd = google_chromeec_get_event();
Stefan Reinauer49428d82013-02-21 15:48:37 -080035
Martin Roth356b5192017-06-24 21:53:37 -060036#if IS_ENABLED(CONFIG_ELOG_GSMI)
Stefan Reinauer49428d82013-02-21 15:48:37 -080037 /* Log this event */
38 if (cmd)
39 elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
40#endif
41
42 switch (cmd) {
43 case EC_HOST_EVENT_LID_CLOSED:
44 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
45
46 /* Go to S5 */
Patrick Rudolphbaea5992018-06-28 14:10:27 +020047 write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10));
Stefan Reinauer49428d82013-02-21 15:48:37 -080048 break;
49 }
50
51 return cmd;
52}
53
Duncan Laurie0edc2242013-04-29 15:04:30 -070054void mainboard_smi_gpi(u32 gpi_sts)
Stefan Reinauer49428d82013-02-21 15:48:37 -080055{
56 if (gpi_sts & (1 << EC_SMI_GPI)) {
57 /* Process all pending events */
58 while (mainboard_smi_ec() != 0);
59 }
60}
61
62void mainboard_smi_sleep(u8 slp_typ)
63{
64 /* Disable USB charging if required */
65 switch (slp_typ) {
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050066 case ACPI_S3:
Stefan Reinauer49428d82013-02-21 15:48:37 -080067 if (smm_get_gnvs()->s3u0 == 0)
68 google_chromeec_set_usb_charge_mode(
69 0, USB_CHARGE_MODE_DISABLED);
70 if (smm_get_gnvs()->s3u1 == 0)
71 google_chromeec_set_usb_charge_mode(
72 1, USB_CHARGE_MODE_DISABLED);
73 break;
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050074 case ACPI_S5:
Stefan Reinauer49428d82013-02-21 15:48:37 -080075 if (smm_get_gnvs()->s5u0 == 0)
76 google_chromeec_set_usb_charge_mode(
77 0, USB_CHARGE_MODE_DISABLED);
78 if (smm_get_gnvs()->s5u1 == 0)
79 google_chromeec_set_usb_charge_mode(
80 1, USB_CHARGE_MODE_DISABLED);
81 break;
82 }
83
84 /* Disable SCI and SMI events */
85 google_chromeec_set_smi_mask(0);
86 google_chromeec_set_sci_mask(0);
87
88 /* Clear pending events that may trigger immediate wake */
89 while (google_chromeec_get_event() != 0);
90
91 /* Enable wake events */
92 google_chromeec_set_wake_mask(LINK_EC_S3_WAKE_EVENTS);
93}
94
Stefan Reinauer49428d82013-02-21 15:48:37 -080095#define APMC_ACPI_EN 0xe1
96#define APMC_ACPI_DIS 0x1e
97
Stefan Reinauer49428d82013-02-21 15:48:37 -080098int mainboard_smi_apmc(u8 apmc)
99{
100 switch (apmc) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800101 case APMC_ACPI_EN:
102 google_chromeec_set_smi_mask(0);
103 /* Clear all pending events */
104 while (google_chromeec_get_event() != 0);
105 google_chromeec_set_sci_mask(LINK_EC_SCI_EVENTS);
106 break;
107 case APMC_ACPI_DIS:
108 google_chromeec_set_sci_mask(0);
109 /* Clear all pending events */
110 while (google_chromeec_get_event() != 0);
Idwer Volleringd26da9c2013-12-22 21:38:18 +0000111 google_chromeec_set_smi_mask(LINK_EC_SMI_EVENTS);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800112 break;
113 }
114 return 0;
115}