blob: 113e7ce98709fe6cd6136d365bd2587f078d65a1 [file] [log] [blame]
Aaron Durbinc625d092013-10-04 16:00:07 -05001/*
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.
Aaron Durbinc625d092013-10-04 16:00:07 -050014 */
15
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050016#include <arch/acpi.h>
Aaron Durbinc625d092013-10-04 16:00:07 -050017#include <arch/io.h>
18#include <console/console.h>
19#include <cpu/x86/smm.h>
Aaron Durbin84da9592013-11-07 11:19:34 -060020#include <elog.h>
21
22#include <ec/google/chromeec/ec.h>
23#include "ec.h"
24
Julius Werner18ea2d32014-10-07 16:42:17 -070025#include <soc/nvs.h>
26#include <soc/pmc.h>
Aaron Durbinc625d092013-10-04 16:00:07 -050027
Aaron Durbin3fbf6712013-11-11 14:55:47 -060028/* The wake gpio is SUS_GPIO[0]. */
29#define WAKE_GPIO_EN SUS_GPIO_EN0
30
Aaron Durbin84da9592013-11-07 11:19:34 -060031static uint8_t mainboard_smi_ec(void)
32{
33 uint8_t cmd = google_chromeec_get_event();
34 uint16_t pmbase = get_pmbase();
35 uint32_t pm1_cnt;
36
Martin Roth356b5192017-06-24 21:53:37 -060037#if IS_ENABLED(CONFIG_ELOG_GSMI)
Aaron Durbin84da9592013-11-07 11:19:34 -060038 /* Log this event */
39 if (cmd)
40 elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
41#endif
42
43 switch (cmd) {
44 case EC_HOST_EVENT_LID_CLOSED:
45 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
46
47 /* Go to S5 */
48 pm1_cnt = inl(pmbase + PM1_CNT);
Aaron Durbin3fbf6712013-11-11 14:55:47 -060049 pm1_cnt |= SLP_EN | (SLP_TYP_S5 << SLP_TYP_SHIFT);
Aaron Durbin84da9592013-11-07 11:19:34 -060050 outl(pm1_cnt, pmbase + PM1_CNT);
51 break;
52 }
53
54 return cmd;
55}
56
Aaron Durbin3fbf6712013-11-11 14:55:47 -060057/* The entire 32-bit ALT_GPIO_SMI register is passed as a parameter. Note, that
58 * this includes the enable bits in the lower 16 bits. */
59void mainboard_smi_gpi(uint32_t alt_gpio_smi)
Aaron Durbin84da9592013-11-07 11:19:34 -060060{
Aaron Durbin3fbf6712013-11-11 14:55:47 -060061 if (alt_gpio_smi & (1 << EC_SMI_GPI)) {
Aaron Durbin84da9592013-11-07 11:19:34 -060062 /* Process all pending events */
63 while (mainboard_smi_ec() != 0);
64 }
65}
66
67void mainboard_smi_sleep(uint8_t slp_typ)
68{
69 /* Disable USB charging if required */
70 switch (slp_typ) {
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050071 case ACPI_S3:
Aaron Durbin84da9592013-11-07 11:19:34 -060072 if (smm_get_gnvs()->s3u0 == 0)
73 google_chromeec_set_usb_charge_mode(
74 0, USB_CHARGE_MODE_DISABLED);
75 if (smm_get_gnvs()->s3u1 == 0)
76 google_chromeec_set_usb_charge_mode(
77 1, USB_CHARGE_MODE_DISABLED);
78
79 /* Enable wake events */
80 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
Aaron Durbin3fbf6712013-11-11 14:55:47 -060081 /* Enable wake pin in GPE block. */
82 enable_gpe(WAKE_GPIO_EN);
Aaron Durbin84da9592013-11-07 11:19:34 -060083 break;
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050084 case ACPI_S5:
Aaron Durbin84da9592013-11-07 11:19:34 -060085 if (smm_get_gnvs()->s5u0 == 0)
86 google_chromeec_set_usb_charge_mode(
87 0, USB_CHARGE_MODE_DISABLED);
88 if (smm_get_gnvs()->s5u1 == 0)
89 google_chromeec_set_usb_charge_mode(
90 1, USB_CHARGE_MODE_DISABLED);
91
92 /* Enable wake events */
93 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
94 break;
95 }
96
97 /* Disable SCI and SMI events */
98 google_chromeec_set_smi_mask(0);
99 google_chromeec_set_sci_mask(0);
100
101 /* Clear pending events that may trigger immediate wake */
102 while (google_chromeec_get_event() != 0);
103}
104
Aaron Durbin84da9592013-11-07 11:19:34 -0600105int mainboard_smi_apmc(uint8_t apmc)
Aaron Durbinc625d092013-10-04 16:00:07 -0500106{
107 switch (apmc) {
Aaron Durbin84da9592013-11-07 11:19:34 -0600108 case APM_CNT_ACPI_ENABLE:
109 google_chromeec_set_smi_mask(0);
110 /* Clear all pending events */
111 while (google_chromeec_get_event() != 0);
112 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS);
113 break;
114 case APM_CNT_ACPI_DISABLE:
115 google_chromeec_set_sci_mask(0);
116 /* Clear all pending events */
117 while (google_chromeec_get_event() != 0);
Edward O'Callaghan48b6b972014-11-09 12:06:19 +1100118 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS);
Aaron Durbin84da9592013-11-07 11:19:34 -0600119 break;
Aaron Durbinc625d092013-10-04 16:00:07 -0500120 }
121 return 0;
122}