blob: efd6efe5d062c31d8026467db1bbaa74929550e7 [file] [log] [blame]
Angel Pons2de6bdf2020-04-05 13:21:00 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy89b5fbd2015-05-11 17:24:31 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <device/mmio.h>
Lee Leahy89b5fbd2015-05-11 17:24:31 -07005#include <console/console.h>
6#include <cpu/x86/smm.h>
7#include "ec.h"
8#include <ec/google/chromeec/ec.h>
Kyösti Mälkki923b8ec2022-11-29 07:36:44 +02009#include <ec/google/chromeec/smm.h>
Lee Leahy89b5fbd2015-05-11 17:24:31 -070010#include <soc/pm.h>
11#include <soc/gpio.h>
12
Matt DeVilliere69a9c72017-08-20 14:48:57 -050013#include <variant/onboard.h>
Lee Leahy89b5fbd2015-05-11 17:24:31 -070014
15/* The wake gpio is SUS_GPIO[0]. */
16#define WAKE_GPIO_EN SUS_GPIO_EN0
Hannah Williams73600e32015-07-27 19:46:34 -070017#define GPIO_SUS7_WAKE_MASK (1 << 12)
18#define GPIO_SUS1_WAKE_MASK (1 << 13)
Lee Leahy89b5fbd2015-05-11 17:24:31 -070019
Lee Leahy89b5fbd2015-05-11 17:24:31 -070020/*
21 * The entire 32-bit ALT_GPIO_SMI register is passed as a parameter. Note, that
22 * this includes the enable bits in the lower 16 bits.
23 */
24void mainboard_smi_gpi(uint32_t alt_gpio_smi)
25{
Kyösti Mälkki83faa5d2023-01-05 15:39:16 +020026 if (alt_gpio_smi & (1 << EC_SMI_GPI))
27 chromeec_smi_process_events();
Lee Leahy89b5fbd2015-05-11 17:24:31 -070028}
29
30void mainboard_smi_sleep(uint8_t slp_typ)
31{
Hannah Williams73600e32015-07-27 19:46:34 -070032 void *addr;
33 uint32_t mask;
34
Lee Leahy89b5fbd2015-05-11 17:24:31 -070035 /* Disable USB charging if required */
Kyösti Mälkki027f86e2022-12-02 15:30:10 +020036 chromeec_set_usb_charge_mode(slp_typ);
37
Lee Leahy89b5fbd2015-05-11 17:24:31 -070038 switch (slp_typ) {
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050039 case ACPI_S3:
Lee Leahy89b5fbd2015-05-11 17:24:31 -070040 /* Enable wake events */
41 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
Lee Leahy89b5fbd2015-05-11 17:24:31 -070042 /* Enable wake pin in GPE block. */
43 enable_gpe(WAKE_GPIO_EN);
44 break;
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050045 case ACPI_S5:
Lee Leahy89b5fbd2015-05-11 17:24:31 -070046 /* Enable wake events */
47 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
Hannah Williams73600e32015-07-27 19:46:34 -070048
49 /* Disabling wake from SUS_GPIO1 (TOUCH INT) and
50 * SUS_GPIO7 (TRACKPAD INT) in North bank as they are not
51 * valid S5 wake sources
52 */
53 addr = (void *)(IO_BASE_ADDRESS + COMMUNITY_OFFSET_GPNORTH +
54 GPIO_WAKE_MASK_REG0);
55 mask = ~(GPIO_SUS1_WAKE_MASK | GPIO_SUS7_WAKE_MASK);
56 write32(addr, read32(addr) & mask);
57
Lee Leahy89b5fbd2015-05-11 17:24:31 -070058 break;
59 }
60
Lee Leahy89b5fbd2015-05-11 17:24:31 -070061 /* Disable SCI and SMI events */
62 google_chromeec_set_smi_mask(0);
63 google_chromeec_set_sci_mask(0);
64
65 /* Clear pending events that may trigger immediate wake */
Rob Barnesf1ade482021-06-14 10:22:21 -060066 while (google_chromeec_get_event() != EC_HOST_EVENT_NONE)
Lee Leahy89b5fbd2015-05-11 17:24:31 -070067 ;
Matt DeVillier4f20a4a2017-08-20 17:56:48 -050068
69 /* Set LPC lines to low power in S3/S5. */
70 if ((slp_typ == ACPI_S3) || (slp_typ == ACPI_S5)) {
71 lpc_set_low_power();
72 }
Lee Leahy89b5fbd2015-05-11 17:24:31 -070073}
74
75int mainboard_smi_apmc(uint8_t apmc)
76{
Kyösti Mälkki923b8ec2022-11-29 07:36:44 +020077 chromeec_smi_apmc(apmc, MAINBOARD_EC_SCI_EVENTS, MAINBOARD_EC_SMI_EVENTS);
Lee Leahy89b5fbd2015-05-11 17:24:31 -070078 return 0;
79}