blob: 324227e704347340ed7a714bfd445e3da1becf0d [file] [log] [blame]
Marc Jones07cf24c2015-06-09 14:42:55 -06001/*
2 * This file is part of the coreboot project.
3 *
Marc Jones07cf24c2015-06-09 14:42:55 -06004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Marc Jones07cf24c2015-06-09 14:42:55 -060013 */
14
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050015#include <arch/acpi.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060016#include <arch/io.h>
17#include <console/console.h>
18#include <cpu/x86/smm.h>
Marc Jonesd8621212015-06-09 21:18:38 -060019#include <soc/pm.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060020#include <elog.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060021#include <ec/google/chromeec/ec.h>
Marc Jonesd8621212015-06-09 21:18:38 -060022#include <soc/gpio.h>
23#include <soc/iomap.h>
24#include <soc/nvs.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060025#include "ec.h"
Matt DeVillier45e11aa2016-12-18 11:59:58 -060026#include <variant/onboard.h>
Marc Jonesd8621212015-06-09 21:18:38 -060027
Marc Jones07cf24c2015-06-09 14:42:55 -060028static u8 mainboard_smi_ec(void)
29{
30 u8 cmd = google_chromeec_get_event();
31 u32 pm1_cnt;
32
Marc Jones07cf24c2015-06-09 14:42:55 -060033 /* Log this event */
34 if (cmd)
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +020035 elog_gsmi_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
Marc Jones07cf24c2015-06-09 14:42:55 -060036
37 switch (cmd) {
38 case EC_HOST_EVENT_LID_CLOSED:
39 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
40
41 /* Go to S5 */
Marc Jonesd8621212015-06-09 21:18:38 -060042 pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT);
Marc Jones07cf24c2015-06-09 14:42:55 -060043 pm1_cnt |= (0xf << 10);
Marc Jonesd8621212015-06-09 21:18:38 -060044 outl(pm1_cnt, ACPI_BASE_ADDRESS + PM1_CNT);
Marc Jones07cf24c2015-06-09 14:42:55 -060045 break;
46 }
47
48 return cmd;
49}
50
51/* gpi_sts is GPIO 47:32 */
52void mainboard_smi_gpi(u32 gpi_sts)
53{
54 if (gpi_sts & (1 << (EC_SMI_GPI - 32))) {
55 /* Process all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -060056 while (mainboard_smi_ec() != 0)
57 ;
Marc Jones07cf24c2015-06-09 14:42:55 -060058 }
59}
60
Matt DeVillier45e11aa2016-12-18 11:59:58 -060061static void mainboard_disable_gpios(void)
62{
Julius Wernercd49cce2019-03-05 16:53:33 -080063#if CONFIG(BOARD_GOOGLE_SAMUS)
Matt DeVillier45e11aa2016-12-18 11:59:58 -060064 /* Put SSD in reset to prevent leak */
65 set_gpio(BOARD_SSD_RESET_GPIO, 0);
66 /* Disable LTE */
67 set_gpio(BOARD_LTE_DISABLE_GPIO, 0);
68#else
69 set_gpio(BOARD_PP3300_CODEC_GPIO, 0);
70#endif
71 /* Prevent leak from standby rail to WLAN rail */
72 set_gpio(BOARD_WLAN_DISABLE_GPIO, 0);
73}
74
Marc Jones07cf24c2015-06-09 14:42:55 -060075void mainboard_smi_sleep(u8 slp_typ)
76{
77 /* Disable USB charging if required */
78 switch (slp_typ) {
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050079 case ACPI_S3:
Marc Jonesd8621212015-06-09 21:18:38 -060080 if (smm_get_gnvs()->s3u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060081 google_chromeec_set_usb_charge_mode(
82 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060083 google_chromeec_set_usb_charge_mode(
84 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -060085 }
Marc Jones07cf24c2015-06-09 14:42:55 -060086
Matt DeVillier45e11aa2016-12-18 11:59:58 -060087 mainboard_disable_gpios();
Marc Jones07cf24c2015-06-09 14:42:55 -060088
89 /* Enable wake events */
90 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
91 break;
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050092 case ACPI_S5:
Marc Jonesd8621212015-06-09 21:18:38 -060093 if (smm_get_gnvs()->s5u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060094 google_chromeec_set_usb_charge_mode(
95 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060096 google_chromeec_set_usb_charge_mode(
97 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -060098 }
Marc Jones07cf24c2015-06-09 14:42:55 -060099
Matt DeVillier45e11aa2016-12-18 11:59:58 -0600100 mainboard_disable_gpios();
Marc Jones07cf24c2015-06-09 14:42:55 -0600101
102 /* Enable wake events */
103 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
104 break;
105 }
106
107 /* Disable SCI and SMI events */
108 google_chromeec_set_smi_mask(0);
109 google_chromeec_set_sci_mask(0);
110
111 /* Clear pending events that may trigger immediate wake */
Marc Jonesd8621212015-06-09 21:18:38 -0600112 while (google_chromeec_get_event() != 0)
113 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600114}
115
Marc Jones07cf24c2015-06-09 14:42:55 -0600116int mainboard_smi_apmc(u8 apmc)
117{
118 switch (apmc) {
Marc Jones07cf24c2015-06-09 14:42:55 -0600119 case APM_CNT_ACPI_ENABLE:
120 google_chromeec_set_smi_mask(0);
121 /* Clear all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -0600122 while (google_chromeec_get_event() != 0)
123 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600124 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS);
125 break;
126 case APM_CNT_ACPI_DISABLE:
127 google_chromeec_set_sci_mask(0);
128 /* Clear all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -0600129 while (google_chromeec_get_event() != 0)
130 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600131 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS);
132 break;
133 }
134 return 0;
135}