• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpi_gnvs.h>
4 #include <device/pci_ops.h>
5 #include <console/console.h>
6 #include <cpu/x86/smm.h>
7 #include <halt.h>
8 #include <soc/nvs.h>
9 #include <southbridge/intel/bd82x6x/pch.h>
10 #include <southbridge/intel/bd82x6x/me.h>
11 #include <northbridge/intel/sandybridge/sandybridge.h>
12 
13 /* Include EC functions */
14 #include <ec/quanta/it8518/ec.h>
15 #include "ec.h"
16 
mainboard_smi_ec(void)17 static u8 mainboard_smi_ec(void)
18 {
19 	u8 cmd = ec_it8518_get_event();
20 
21 	switch (cmd) {
22 	case EC_SMI_LID_CLOSED:
23 		printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
24 		/* Go to S5 */
25 		poweroff();
26 		break;
27 	}
28 
29 	return cmd;
30 }
31 
mainboard_smi_gpi(u32 gpi_sts)32 void mainboard_smi_gpi(u32 gpi_sts)
33 {
34 	if (gpi_sts & (1 << EC_SMI_GPI)) {
35 		/* Process all pending events */
36 		while (mainboard_smi_ec() != 0);
37 	}
38 }
39 
mainboard_smi_sleep(u8 slp_typ)40 void mainboard_smi_sleep(u8 slp_typ)
41 {
42 	bool usb0_disable = 0, usb1_disable = 0;
43 
44 	/*
45 	 * Tell the EC to Enable USB power for S3 if requested.
46 	 * Bit0 of 0x0D/Bit0 of 0x26
47 	 * 0/0 All USB port off
48 	 * 1/0 USB on, all USB port didn't support wake up
49 	 * 0/1 USB on, yellow port support wake up charge, but may not support
50 	 *             charge smart phone.
51 	 * 1/1 USB on, yellow port in AUTO mode and didn't support wake up system.
52 	 */
53 	usb_charge_mode_from_gnvs(3, &usb0_disable, &usb1_disable);
54 
55 	if (!usb0_disable || !usb1_disable) {
56 		ec_write(EC_PERIPH_CNTL_3, ec_read(EC_PERIPH_CNTL_3) | 0x00);
57 		ec_write(EC_USB_S3_EN, ec_read(EC_USB_S3_EN) | 0x01);
58 		printk(BIOS_DEBUG, "USB wake from S3 enabled.\n");
59 	} else {
60 		/*
61 		 * If USB charging in suspend is disabled then also disable
62 		 * the XHCI PME to prevent wake when the port power is cut
63 		 * after the transition into suspend.
64 		 */
65 		if (gnvs->xhci) {
66 			pci_update_config32(PCH_XHCI_DEV, 0x74, ~(1 << 8), 1 << 15);
67 		}
68 	}
69 
70 	ec_kbc_write_cmd(EC_KBD_CMD_MUTE);
71 	ec_it8518_enable_wake_events();
72 }
73 
mainboard_smi_apmc(u8 apmc)74 int mainboard_smi_apmc(u8 apmc)
75 {
76 	switch (apmc) {
77 	case APM_CNT_FINALIZE:
78 		stout_ec_finalize_smm();
79 		break;
80 	case APM_CNT_ACPI_ENABLE:
81 		/*
82 		 * TODO(kimarie) Clear all pending events and enable SCI.
83 		 */
84 		ec_write_cmd(EC_CMD_NOTIFY_ACPI_ENTER);
85 		break;
86 	case APM_CNT_ACPI_DISABLE:
87 		/*
88 		 * TODO(kimarie) Clear all pending events and enable SMI.
89 		 */
90 		ec_write_cmd(EC_CMD_NOTIFY_ACPI_EXIT);
91 		break;
92 	}
93 	return 0;
94 }
95