blob: 4cc0aa82219bb13c8441a4266a86af4a7ba13598 [file] [log] [blame]
Marc Jones07cf24c2015-06-09 14:42:55 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
Marc Jonesd8621212015-06-09 21:18:38 -06005 * Copyright 2014 Google Inc.
Marc Jones07cf24c2015-06-09 14:42:55 -06006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Marc Jones07cf24c2015-06-09 14:42:55 -060015 */
16
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050017#include <arch/acpi.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060018#include <arch/io.h>
19#include <console/console.h>
20#include <cpu/x86/smm.h>
Marc Jonesd8621212015-06-09 21:18:38 -060021#include <soc/pm.h>
22#include <soc/smm.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060023#include <elog.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060024#include <ec/google/chromeec/ec.h>
Marc Jonesd8621212015-06-09 21:18:38 -060025#include <soc/gpio.h>
26#include <soc/iomap.h>
27#include <soc/nvs.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060028#include "ec.h"
Matt DeVillier45e11aa2016-12-18 11:59:58 -060029#include <variant/onboard.h>
Marc Jonesd8621212015-06-09 21:18:38 -060030
Marc Jones07cf24c2015-06-09 14:42:55 -060031static u8 mainboard_smi_ec(void)
32{
33 u8 cmd = google_chromeec_get_event();
34 u32 pm1_cnt;
35
Marc Jones07cf24c2015-06-09 14:42:55 -060036 /* Log this event */
37 if (cmd)
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +020038 elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
Marc Jones07cf24c2015-06-09 14:42:55 -060039
40 switch (cmd) {
41 case EC_HOST_EVENT_LID_CLOSED:
42 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
43
44 /* Go to S5 */
Marc Jonesd8621212015-06-09 21:18:38 -060045 pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT);
Marc Jones07cf24c2015-06-09 14:42:55 -060046 pm1_cnt |= (0xf << 10);
Marc Jonesd8621212015-06-09 21:18:38 -060047 outl(pm1_cnt, ACPI_BASE_ADDRESS + PM1_CNT);
Marc Jones07cf24c2015-06-09 14:42:55 -060048 break;
49 }
50
51 return cmd;
52}
53
54/* gpi_sts is GPIO 47:32 */
55void mainboard_smi_gpi(u32 gpi_sts)
56{
57 if (gpi_sts & (1 << (EC_SMI_GPI - 32))) {
58 /* Process all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -060059 while (mainboard_smi_ec() != 0)
60 ;
Marc Jones07cf24c2015-06-09 14:42:55 -060061 }
62}
63
Matt DeVillier45e11aa2016-12-18 11:59:58 -060064static void mainboard_disable_gpios(void)
65{
Julius Wernercd49cce2019-03-05 16:53:33 -080066#if CONFIG(BOARD_GOOGLE_SAMUS)
Matt DeVillier45e11aa2016-12-18 11:59:58 -060067 /* Put SSD in reset to prevent leak */
68 set_gpio(BOARD_SSD_RESET_GPIO, 0);
69 /* Disable LTE */
70 set_gpio(BOARD_LTE_DISABLE_GPIO, 0);
71#else
72 set_gpio(BOARD_PP3300_CODEC_GPIO, 0);
73#endif
74 /* Prevent leak from standby rail to WLAN rail */
75 set_gpio(BOARD_WLAN_DISABLE_GPIO, 0);
76}
77
Marc Jones07cf24c2015-06-09 14:42:55 -060078void mainboard_smi_sleep(u8 slp_typ)
79{
80 /* Disable USB charging if required */
81 switch (slp_typ) {
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050082 case ACPI_S3:
Marc Jonesd8621212015-06-09 21:18:38 -060083 if (smm_get_gnvs()->s3u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060084 google_chromeec_set_usb_charge_mode(
85 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060086 google_chromeec_set_usb_charge_mode(
87 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -060088 }
Marc Jones07cf24c2015-06-09 14:42:55 -060089
Matt DeVillier45e11aa2016-12-18 11:59:58 -060090 mainboard_disable_gpios();
Marc Jones07cf24c2015-06-09 14:42:55 -060091
92 /* Enable wake events */
93 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
94 break;
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050095 case ACPI_S5:
Marc Jonesd8621212015-06-09 21:18:38 -060096 if (smm_get_gnvs()->s5u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060097 google_chromeec_set_usb_charge_mode(
98 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060099 google_chromeec_set_usb_charge_mode(
100 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -0600101 }
Marc Jones07cf24c2015-06-09 14:42:55 -0600102
Matt DeVillier45e11aa2016-12-18 11:59:58 -0600103 mainboard_disable_gpios();
Marc Jones07cf24c2015-06-09 14:42:55 -0600104
105 /* Enable wake events */
106 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
107 break;
108 }
109
110 /* Disable SCI and SMI events */
111 google_chromeec_set_smi_mask(0);
112 google_chromeec_set_sci_mask(0);
113
114 /* Clear pending events that may trigger immediate wake */
Marc Jonesd8621212015-06-09 21:18:38 -0600115 while (google_chromeec_get_event() != 0)
116 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600117}
118
Marc Jones07cf24c2015-06-09 14:42:55 -0600119int mainboard_smi_apmc(u8 apmc)
120{
121 switch (apmc) {
Marc Jones07cf24c2015-06-09 14:42:55 -0600122 case APM_CNT_ACPI_ENABLE:
123 google_chromeec_set_smi_mask(0);
124 /* Clear all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -0600125 while (google_chromeec_get_event() != 0)
126 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600127 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS);
128 break;
129 case APM_CNT_ACPI_DISABLE:
130 google_chromeec_set_sci_mask(0);
131 /* Clear all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -0600132 while (google_chromeec_get_event() != 0)
133 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600134 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS);
135 break;
136 }
137 return 0;
138}