blob: fac07b14d253df0e37b2193267110a1e60555991 [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
17#include <arch/io.h>
18#include <console/console.h>
19#include <cpu/x86/smm.h>
Marc Jonesd8621212015-06-09 21:18:38 -060020#include <soc/pm.h>
21#include <soc/smm.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060022#include <elog.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060023#include <ec/google/chromeec/ec.h>
Marc Jonesd8621212015-06-09 21:18:38 -060024#include <soc/gpio.h>
25#include <soc/iomap.h>
26#include <soc/nvs.h>
27#include <soc/pm.h>
28#include <soc/smm.h>
Marc Jones07cf24c2015-06-09 14:42:55 -060029#include "ec.h"
30
31/* Codec enable: GPIO45 */
32#define GPIO_PP3300_CODEC_EN 45
33/* WLAN / BT enable: GPIO46 */
34#define GPIO_WLAN_DISABLE_L 46
35
Marc Jonesd8621212015-06-09 21:18:38 -060036
Marc Jones07cf24c2015-06-09 14:42:55 -060037static u8 mainboard_smi_ec(void)
38{
39 u8 cmd = google_chromeec_get_event();
40 u32 pm1_cnt;
41
42#if CONFIG_ELOG_GSMI
43 /* Log this event */
44 if (cmd)
45 elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd);
46#endif
47
48 switch (cmd) {
49 case EC_HOST_EVENT_LID_CLOSED:
50 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
51
52 /* Go to S5 */
Marc Jonesd8621212015-06-09 21:18:38 -060053 pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT);
Marc Jones07cf24c2015-06-09 14:42:55 -060054 pm1_cnt |= (0xf << 10);
Marc Jonesd8621212015-06-09 21:18:38 -060055 outl(pm1_cnt, ACPI_BASE_ADDRESS + PM1_CNT);
Marc Jones07cf24c2015-06-09 14:42:55 -060056 break;
57 }
58
59 return cmd;
60}
61
62/* gpi_sts is GPIO 47:32 */
63void mainboard_smi_gpi(u32 gpi_sts)
64{
65 if (gpi_sts & (1 << (EC_SMI_GPI - 32))) {
66 /* Process all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -060067 while (mainboard_smi_ec() != 0)
68 ;
Marc Jones07cf24c2015-06-09 14:42:55 -060069 }
70}
71
72void mainboard_smi_sleep(u8 slp_typ)
73{
74 /* Disable USB charging if required */
75 switch (slp_typ) {
76 case 3:
Marc Jonesd8621212015-06-09 21:18:38 -060077 if (smm_get_gnvs()->s3u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060078 google_chromeec_set_usb_charge_mode(
79 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060080 google_chromeec_set_usb_charge_mode(
81 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -060082 }
Marc Jones07cf24c2015-06-09 14:42:55 -060083
84 set_gpio(GPIO_PP3300_CODEC_EN, 0);
85 set_gpio(GPIO_WLAN_DISABLE_L, 0);
86
87 /* Enable wake events */
88 google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
89 break;
90 case 5:
Marc Jonesd8621212015-06-09 21:18:38 -060091 if (smm_get_gnvs()->s5u0 == 0) {
Marc Jones07cf24c2015-06-09 14:42:55 -060092 google_chromeec_set_usb_charge_mode(
93 0, USB_CHARGE_MODE_DISABLED);
Marc Jones07cf24c2015-06-09 14:42:55 -060094 google_chromeec_set_usb_charge_mode(
95 1, USB_CHARGE_MODE_DISABLED);
Marc Jonesd8621212015-06-09 21:18:38 -060096 }
Marc Jones07cf24c2015-06-09 14:42:55 -060097
98 set_gpio(GPIO_PP3300_CODEC_EN, 0);
99 set_gpio(GPIO_WLAN_DISABLE_L, 0);
100
101 /* Enable wake events */
102 google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
103 break;
104 }
105
106 /* Disable SCI and SMI events */
107 google_chromeec_set_smi_mask(0);
108 google_chromeec_set_sci_mask(0);
109
110 /* Clear pending events that may trigger immediate wake */
Marc Jonesd8621212015-06-09 21:18:38 -0600111 while (google_chromeec_get_event() != 0)
112 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600113}
114
Marc Jones07cf24c2015-06-09 14:42:55 -0600115int mainboard_smi_apmc(u8 apmc)
116{
117 switch (apmc) {
Marc Jones07cf24c2015-06-09 14:42:55 -0600118 case APM_CNT_ACPI_ENABLE:
119 google_chromeec_set_smi_mask(0);
120 /* Clear all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -0600121 while (google_chromeec_get_event() != 0)
122 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600123 google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS);
124 break;
125 case APM_CNT_ACPI_DISABLE:
126 google_chromeec_set_sci_mask(0);
127 /* Clear all pending events */
Marc Jonesd8621212015-06-09 21:18:38 -0600128 while (google_chromeec_get_event() != 0)
129 ;
Marc Jones07cf24c2015-06-09 14:42:55 -0600130 google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS);
131 break;
132 }
133 return 0;
134}