blob: 790eeff77cb5a5f6adab94162e8bc18c95c30c99 [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
Julius Wernercd49cce2019-03-05 16:53:33 -080036#if CONFIG(ELOG_GSMI)
Marc Jones07cf24c2015-06-09 14:42:55 -060037 /* 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 */
Marc Jonesd8621212015-06-09 21:18:38 -060047 pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT);
Marc Jones07cf24c2015-06-09 14:42:55 -060048 pm1_cnt |= (0xf << 10);
Marc Jonesd8621212015-06-09 21:18:38 -060049 outl(pm1_cnt, ACPI_BASE_ADDRESS + PM1_CNT);
Marc Jones07cf24c2015-06-09 14:42:55 -060050 break;
51 }
52
53 return cmd;
54}
55
56/* gpi_sts is GPIO 47:32 */
57void mainboard_smi_gpi(u32 gpi_sts)
58{
59 if (gpi_sts & (1 << (EC_SMI_GPI - 32))) {
60 /* Process all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -060061 while (mainboard_smi_ec() != 0)
62 ;
Marc Jones07cf24c2015-06-09 14:42:55 -060063 }
64}
65
Matt DeVillier45e11aa2016-12-18 11:59:58 -060066static void mainboard_disable_gpios(void)
67{
Julius Wernercd49cce2019-03-05 16:53:33 -080068#if CONFIG(BOARD_GOOGLE_SAMUS)
Matt DeVillier45e11aa2016-12-18 11:59:58 -060069 /* Put SSD in reset to prevent leak */
70 set_gpio(BOARD_SSD_RESET_GPIO, 0);
71 /* Disable LTE */
72 set_gpio(BOARD_LTE_DISABLE_GPIO, 0);
73#else
74 set_gpio(BOARD_PP3300_CODEC_GPIO, 0);
75#endif
76 /* Prevent leak from standby rail to WLAN rail */
77 set_gpio(BOARD_WLAN_DISABLE_GPIO, 0);
78}
79
Marc Jones07cf24c2015-06-09 14:42:55 -060080void mainboard_smi_sleep(u8 slp_typ)
81{
82 /* Disable USB charging if required */
83 switch (slp_typ) {
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050084 case ACPI_S3:
Marc Jonesd8621212015-06-09 21:18:38 -060085 if (smm_get_gnvs()->s3u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060086 google_chromeec_set_usb_charge_mode(
87 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060088 google_chromeec_set_usb_charge_mode(
89 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -060090 }
Marc Jones07cf24c2015-06-09 14:42:55 -060091
Matt DeVillier45e11aa2016-12-18 11:59:58 -060092 mainboard_disable_gpios();
Marc Jones07cf24c2015-06-09 14:42:55 -060093
94 /* Enable wake events */
95 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
96 break;
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050097 case ACPI_S5:
Marc Jonesd8621212015-06-09 21:18:38 -060098 if (smm_get_gnvs()->s5u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060099 google_chromeec_set_usb_charge_mode(
100 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -0600101 google_chromeec_set_usb_charge_mode(
102 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -0600103 }
Marc Jones07cf24c2015-06-09 14:42:55 -0600104
Matt DeVillier45e11aa2016-12-18 11:59:58 -0600105 mainboard_disable_gpios();
Marc Jones07cf24c2015-06-09 14:42:55 -0600106
107 /* Enable wake events */
108 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
109 break;
110 }
111
112 /* Disable SCI and SMI events */
113 google_chromeec_set_smi_mask(0);
114 google_chromeec_set_sci_mask(0);
115
116 /* Clear pending events that may trigger immediate wake */
Marc Jonesd8621212015-06-09 21:18:38 -0600117 while (google_chromeec_get_event() != 0)
118 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600119}
120
Marc Jones07cf24c2015-06-09 14:42:55 -0600121int mainboard_smi_apmc(u8 apmc)
122{
123 switch (apmc) {
Marc Jones07cf24c2015-06-09 14:42:55 -0600124 case APM_CNT_ACPI_ENABLE:
125 google_chromeec_set_smi_mask(0);
126 /* Clear all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -0600127 while (google_chromeec_get_event() != 0)
128 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600129 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS);
130 break;
131 case APM_CNT_ACPI_DISABLE:
132 google_chromeec_set_sci_mask(0);
133 /* Clear all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -0600134 while (google_chromeec_get_event() != 0)
135 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600136 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS);
137 break;
138 }
139 return 0;
140}