Angel Pons | 2e8a4b0 | 2020-04-05 13:22:54 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 3 | #include <device/pci_ops.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 4 | #include <console/console.h> |
| 5 | #include <cpu/x86/smm.h> |
Kyösti Mälkki | 661ad46 | 2020-12-29 06:26:21 +0200 | [diff] [blame] | 6 | #include <soc/nvs.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 7 | #include <southbridge/intel/bd82x6x/pch.h> |
| 8 | #include <southbridge/intel/bd82x6x/me.h> |
Patrick Rudolph | e67f626 | 2018-06-28 14:09:56 +0200 | [diff] [blame] | 9 | #include <southbridge/intel/common/pmbase.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 10 | #include <northbridge/intel/sandybridge/sandybridge.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 11 | |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 12 | /* Include EC functions */ |
| 13 | #include <ec/quanta/it8518/ec.h> |
| 14 | #include "ec.h" |
| 15 | |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 16 | static u8 mainboard_smi_ec(void) |
| 17 | { |
| 18 | u8 cmd = ec_it8518_get_event(); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 19 | |
| 20 | switch (cmd) { |
| 21 | case EC_SMI_LID_CLOSED: |
| 22 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 23 | /* Go to S5 */ |
Patrick Rudolph | e67f626 | 2018-06-28 14:09:56 +0200 | [diff] [blame] | 24 | write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10)); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 25 | break; |
| 26 | } |
| 27 | |
| 28 | return cmd; |
| 29 | } |
| 30 | |
Duncan Laurie | 0edc224 | 2013-04-29 15:04:30 -0700 | [diff] [blame] | 31 | void mainboard_smi_gpi(u32 gpi_sts) |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 32 | { |
| 33 | if (gpi_sts & (1 << EC_SMI_GPI)) { |
| 34 | /* Process all pending events */ |
| 35 | while (mainboard_smi_ec() != 0); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | void 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 Roth | 0cd338e | 2016-07-29 14:07:30 -0600 | [diff] [blame] | 45 | * 1/0 USB on, all USB port didn't support wake up |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 46 | * 0/1 USB on, yellow port support wake up charge, but may not support |
| 47 | * charge smart phone. |
Martin Roth | 0cd338e | 2016-07-29 14:07:30 -0600 | [diff] [blame] | 48 | * 1/1 USB on, yellow port in AUTO mode and didn't support wake up system. |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 49 | */ |
Kyösti Mälkki | 239abaf | 2020-06-28 12:12:01 +0300 | [diff] [blame] | 50 | if (gnvs->s3u0 != 0 || gnvs->s3u1 != 0) { |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 51 | 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älkki | 239abaf | 2020-06-28 12:12:01 +0300 | [diff] [blame] | 60 | if (gnvs->xhci) { |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 61 | u32 reg32 = pci_read_config32(PCH_XHCI_DEV, 0x74); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 62 | reg32 &= ~(1 << 8); /* disable PME */ |
| 63 | reg32 |= (1 << 15); /* clear PME status */ |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 64 | pci_write_config32(PCH_XHCI_DEV, 0x74, reg32); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
| 68 | ec_kbc_write_cmd(EC_KBD_CMD_MUTE); |
| 69 | ec_it8518_enable_wake_events(); |
| 70 | } |
| 71 | |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 72 | int mainboard_smi_apmc(u8 apmc) |
| 73 | { |
| 74 | switch (apmc) { |
Vladimir Serbinenko | 3026e47 | 2015-05-16 13:33:49 +0200 | [diff] [blame] | 75 | case APM_CNT_FINALIZE: |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 76 | stout_ec_finalize_smm(); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 77 | break; |
Kyösti Mälkki | d4174b5 | 2020-06-27 14:25:20 +0300 | [diff] [blame] | 78 | case APM_CNT_ACPI_ENABLE: |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 79 | /* |
| 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älkki | d4174b5 | 2020-06-27 14:25:20 +0300 | [diff] [blame] | 84 | case APM_CNT_ACPI_DISABLE: |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 85 | /* |
| 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 | } |