blob: 47cb0ebce60994df82a51a68d69dd6f3aa65f654 [file] [log] [blame]
Angel Pons2e8a4b02020-04-05 13:22:54 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07002
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02003#include <device/pci_ops.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07004#include <console/console.h>
5#include <cpu/x86/smm.h>
Kyösti Mälkki661ad462020-12-29 06:26:21 +02006#include <soc/nvs.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07007#include <southbridge/intel/bd82x6x/pch.h>
8#include <southbridge/intel/bd82x6x/me.h>
Patrick Rudolphe67f6262018-06-28 14:09:56 +02009#include <southbridge/intel/common/pmbase.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070010#include <northbridge/intel/sandybridge/sandybridge.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070011
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070012/* Include EC functions */
13#include <ec/quanta/it8518/ec.h>
14#include "ec.h"
15
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070016static u8 mainboard_smi_ec(void)
17{
18 u8 cmd = ec_it8518_get_event();
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070019
20 switch (cmd) {
21 case EC_SMI_LID_CLOSED:
22 printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
23 /* Go to S5 */
Patrick Rudolphe67f6262018-06-28 14:09:56 +020024 write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10));
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070025 break;
26 }
27
28 return cmd;
29}
30
Duncan Laurie0edc2242013-04-29 15:04:30 -070031void mainboard_smi_gpi(u32 gpi_sts)
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070032{
33 if (gpi_sts & (1 << EC_SMI_GPI)) {
34 /* Process all pending events */
35 while (mainboard_smi_ec() != 0);
36 }
37}
38
39void mainboard_smi_sleep(u8 slp_typ)
40{
41 /*
42 * Tell the EC to Enable USB power for S3 if requested.
43 * Bit0 of 0x0D/Bit0 of 0x26
44 * 0/0 All USB port off
Martin Roth0cd338e2016-07-29 14:07:30 -060045 * 1/0 USB on, all USB port didn't support wake up
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070046 * 0/1 USB on, yellow port support wake up charge, but may not support
47 * charge smart phone.
Martin Roth0cd338e2016-07-29 14:07:30 -060048 * 1/1 USB on, yellow port in AUTO mode and didn't support wake up system.
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070049 */
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030050 if (gnvs->s3u0 != 0 || gnvs->s3u1 != 0) {
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070051 ec_write(EC_PERIPH_CNTL_3, ec_read(EC_PERIPH_CNTL_3) | 0x00);
52 ec_write(EC_USB_S3_EN, ec_read(EC_USB_S3_EN) | 0x01);
53 printk(BIOS_DEBUG, "USB wake from S3 enabled.\n");
54 } else {
55 /*
56 * If USB charging in suspend is disabled then also disable
57 * the XHCI PME to prevent wake when the port power is cut
58 * after the transition into suspend.
59 */
Kyösti Mälkki239abaf2020-06-28 12:12:01 +030060 if (gnvs->xhci) {
Kyösti Mälkkifd98c652013-07-26 08:50:53 +030061 u32 reg32 = pci_read_config32(PCH_XHCI_DEV, 0x74);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070062 reg32 &= ~(1 << 8); /* disable PME */
63 reg32 |= (1 << 15); /* clear PME status */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +030064 pci_write_config32(PCH_XHCI_DEV, 0x74, reg32);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070065 }
66 }
67
68 ec_kbc_write_cmd(EC_KBD_CMD_MUTE);
69 ec_it8518_enable_wake_events();
70}
71
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070072int mainboard_smi_apmc(u8 apmc)
73{
74 switch (apmc) {
Vladimir Serbinenko3026e472015-05-16 13:33:49 +020075 case APM_CNT_FINALIZE:
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070076 stout_ec_finalize_smm();
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070077 break;
Kyösti Mälkkid4174b52020-06-27 14:25:20 +030078 case APM_CNT_ACPI_ENABLE:
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070079 /*
80 * TODO(kimarie) Clear all pending events and enable SCI.
81 */
82 ec_write_cmd(EC_CMD_NOTIFY_ACPI_ENTER);
83 break;
Kyösti Mälkkid4174b52020-06-27 14:25:20 +030084 case APM_CNT_ACPI_DISABLE:
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070085 /*
86 * TODO(kimarie) Clear all pending events and enable SMI.
87 */
88 ec_write_cmd(EC_CMD_NOTIFY_ACPI_EXIT);
89 break;
90 }
91 return 0;
92}