blob: 08b5d2f9099f3b27df511a766085fe0fae2390e6 [file] [log] [blame]
Angel Pons89ab2502020-04-03 01:22:28 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Nicolas Reineckeb165c4a2015-07-04 23:37:06 +02002
3#include <arch/io.h>
4#include <console/console.h>
5#include <cpu/x86/smm.h>
6#include <southbridge/intel/ibexpeak/nvs.h>
7#include <southbridge/intel/common/pmutil.h>
Angel Pons95de2312020-02-17 13:08:53 +01008#include <northbridge/intel/ironlake/ironlake.h>
Nicolas Reineckeb165c4a2015-07-04 23:37:06 +02009#include <ec/acpi/ec.h>
10#include <ec/lenovo/h8/h8.h>
11#include <delay.h>
12#include "dock.h"
13
14#define GPE_EC_SCI 1
15#define GPE_EC_WAKE 13
16
17static void mainboard_smi_handle_ec_sci(void)
18{
19 u8 status = inb(EC_SC);
20 u8 event;
21
22 if (!(status & EC_SCI_EVT))
23 return;
24
25 event = ec_query();
Paul Menzel56642932020-07-19 09:42:53 +020026 printk(BIOS_DEBUG, "EC event %#02x\n", event);
Nicolas Reineckeb165c4a2015-07-04 23:37:06 +020027
28 switch (event) {
29 case 0x18:
30 /* Fn-F9 key */
31 case 0x27:
32 /* Power loss */
33 case 0x50:
34 /* Undock Key */
35 ec_clr_bit(0x03, 2);
36 dock_disconnect();
37 break;
38 case 0x37:
39 case 0x58:
40 /* Dock Event */
41 ec_clr_bit(0x03, 2);
42 mdelay(250);
43 dock_connect();
44 ec_set_bit(0x03, 2);
45 /* set dock LED to indicate status */
46 ec_write(0x0c, 0x09);
47 ec_write(0x0c, 0x88);
48 break;
49 default:
50 break;
51 }
52}
53
54void mainboard_smi_gpi(u32 gpi_sts)
55{
56 if (gpi_sts & (1 << GPE_EC_SCI))
57 mainboard_smi_handle_ec_sci();
58}
59
60int mainboard_smi_apmc(u8 data)
61{
62 switch (data) {
63 case APM_CNT_ACPI_ENABLE:
64 /* use 0x1600/0x1604 to prevent races with userspace */
65 ec_set_ports(0x1604, 0x1600);
66 /* route H8SCI to SCI */
67 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
68 /* discard all events, and enable attention */
69 ec_write(0x80, 0x01);
70 break;
71 case APM_CNT_ACPI_DISABLE:
72 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
73 provide a EC query function */
74 ec_set_ports(0x66, 0x62);
75 /* route H8SCI# to SMI */
76 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
77 /* discard all events, and enable attention */
78 ec_write(0x80, 0x01);
79 break;
80 default:
81 break;
82 }
83 return 0;
84}
85
86void mainboard_smi_sleep(u8 slp_typ)
87{
88 if (slp_typ == 3) {
89 u8 ec_wake = ec_read(0x32);
90 /* If EC wake events are enabled, enable wake on EC WAKE GPE. */
91 if (ec_wake & 0x14) {
92 /* Redirect EC WAKE GPE to SCI. */
93 gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI);
94 }
95 }
96}