blob: f2b55002f88756e0d5003a87b8fedbef6f416dfb [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 <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 Rudolphbaea5992018-06-28 14:10:27 +020022#include <southbridge/intel/common/pmbase.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080023#include <northbridge/intel/sandybridge/sandybridge.h>
24#include <cpu/intel/model_206ax/model_206ax.h>
25#include <elog.h>
26
Stefan Reinauer49428d82013-02-21 15:48:37 -080027/* Include EC functions */
28#include <ec/google/chromeec/ec.h>
29#include "ec.h"
30
Stefan Reinauer49428d82013-02-21 15:48:37 -080031static u8 mainboard_smi_ec(void)
32{
33 u8 cmd = google_chromeec_get_event();
Stefan Reinauer49428d82013-02-21 15:48:37 -080034
Martin Roth356b5192017-06-24 21:53:37 -060035#if IS_ENABLED(CONFIG_ELOG_GSMI)
Stefan Reinauer49428d82013-02-21 15:48:37 -080036 /* 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 Rudolphbaea5992018-06-28 14:10:27 +020046 write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10));
Stefan Reinauer49428d82013-02-21 15:48:37 -080047 break;
48 }
49
50 return cmd;
51}
52
Duncan Laurie0edc2242013-04-29 15:04:30 -070053void mainboard_smi_gpi(u32 gpi_sts)
Stefan Reinauer49428d82013-02-21 15:48:37 -080054{
55 if (gpi_sts & (1 << EC_SMI_GPI)) {
56 /* Process all pending events */
57 while (mainboard_smi_ec() != 0);
58 }
59}
60
61void mainboard_smi_sleep(u8 slp_typ)
62{
63 /* Disable USB charging if required */
64 switch (slp_typ) {
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050065 case ACPI_S3:
Stefan Reinauer49428d82013-02-21 15:48:37 -080066 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 Durbin30b0c7a2016-07-13 13:01:13 -050073 case ACPI_S5:
Stefan Reinauer49428d82013-02-21 15:48:37 -080074 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 Reinauer49428d82013-02-21 15:48:37 -080094#define APMC_ACPI_EN 0xe1
95#define APMC_ACPI_DIS 0x1e
96
Stefan Reinauer49428d82013-02-21 15:48:37 -080097int mainboard_smi_apmc(u8 apmc)
98{
99 switch (apmc) {
Stefan Reinauer49428d82013-02-21 15:48:37 -0800100 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 Volleringd26da9c2013-12-22 21:38:18 +0000110 google_chromeec_set_smi_mask(LINK_EC_SMI_EVENTS);
Stefan Reinauer49428d82013-02-21 15:48:37 -0800111 break;
112 }
113 return 0;
114}