Angel Pons | 96d93d1 | 2020-04-05 13:22:23 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 2 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 3 | #include <console/console.h> |
| 4 | #include <cpu/x86/smm.h> |
Kyösti Mälkki | 661ad46 | 2020-12-29 06:26:21 +0200 | [diff] [blame] | 5 | #include <soc/nvs.h> |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 6 | #include <southbridge/intel/bd82x6x/pch.h> |
| 7 | #include <southbridge/intel/bd82x6x/me.h> |
Arthur Heymans | a050817 | 2018-01-25 11:30:22 +0100 | [diff] [blame] | 8 | #include <southbridge/intel/common/pmutil.h> |
Patrick Rudolph | ecb2399 | 2018-07-28 12:47:42 +0200 | [diff] [blame] | 9 | #include <southbridge/intel/common/pmbase.h> |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 10 | #include <northbridge/intel/sandybridge/sandybridge.h> |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 11 | #include <ec/compal/ene932/ec.h> |
| 12 | #include "ec.h" |
| 13 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 14 | static u8 mainboard_smi_ec(void) |
| 15 | { |
| 16 | u8 src; |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 17 | |
| 18 | ec_kbc_write_cmd(0x56); |
| 19 | src = ec_kbc_read_ob(); |
Felix Singer | 81ffd00 | 2021-01-07 02:46:17 +0000 | [diff] [blame] | 20 | printk(BIOS_DEBUG, "%s src: %x\n", __func__, src); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 21 | |
| 22 | switch (src) { |
| 23 | case EC_BATTERY_CRITICAL: |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 24 | break; |
| 25 | case EC_LID_CLOSE: |
| 26 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 27 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 28 | /* Go to S5 */ |
Patrick Rudolph | ecb2399 | 2018-07-28 12:47:42 +0200 | [diff] [blame] | 29 | write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10)); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 30 | break; |
| 31 | } |
| 32 | |
| 33 | return src; |
| 34 | } |
| 35 | |
Duncan Laurie | 0edc224 | 2013-04-29 15:04:30 -0700 | [diff] [blame] | 36 | void mainboard_smi_gpi(u32 gpi_sts) |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 37 | { |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 38 | if (gpi_sts & (1 << EC_SMI_GPI)) { |
| 39 | /* Process all pending events from EC */ |
Felix Singer | fb777b5 | 2021-01-07 02:51:30 +0000 | [diff] [blame] | 40 | do {} while (mainboard_smi_ec() != EC_NO_EVENT); |
Felix Singer | 57ef7c3 | 2021-01-07 02:49:46 +0000 | [diff] [blame] | 41 | } else if (gpi_sts & (1 << EC_LID_GPI)) { |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 42 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 43 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 44 | /* Go to S5 */ |
Patrick Rudolph | ecb2399 | 2018-07-28 12:47:42 +0200 | [diff] [blame] | 45 | write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10)); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
| 49 | void mainboard_smi_sleep(u8 slp_typ) |
| 50 | { |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 51 | /* Disable SCI and SMI events */ |
| 52 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 53 | /* Clear pending events that may trigger immediate wake */ |
| 54 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 55 | /* Enable wake events */ |
| 56 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 57 | /* Tell the EC to Disable USB power */ |
Kyösti Mälkki | 239abaf | 2020-06-28 12:12:01 +0300 | [diff] [blame] | 58 | if (gnvs->s3u0 == 0 && gnvs->s3u1 == 0) { |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 59 | ec_kbc_write_cmd(0x45); |
| 60 | ec_kbc_write_ib(0xF2); |
| 61 | } |
| 62 | } |
| 63 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 64 | int mainboard_smi_apmc(u8 apmc) |
| 65 | { |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 66 | switch (apmc) { |
Kyösti Mälkki | d4174b5 | 2020-06-27 14:25:20 +0300 | [diff] [blame] | 67 | case APM_CNT_ACPI_ENABLE: |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 68 | /* Clear all pending events */ |
| 69 | /* EC cmd:59 data:E8 */ |
| 70 | ec_kbc_write_cmd(0x59); |
| 71 | ec_kbc_write_ib(0xE8); |
| 72 | |
| 73 | /* Set LID GPI to generate SCIs */ |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 74 | gpi_route_interrupt(EC_LID_GPI, GPI_IS_SCI); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 75 | break; |
Kyösti Mälkki | d4174b5 | 2020-06-27 14:25:20 +0300 | [diff] [blame] | 76 | case APM_CNT_ACPI_DISABLE: |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 77 | /* Clear all pending events */ |
| 78 | /* EC cmd:59 data:e9 */ |
| 79 | ec_kbc_write_cmd(0x59); |
| 80 | ec_kbc_write_ib(0xE9); |
| 81 | |
| 82 | /* Set LID GPI to generate SMIs */ |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 83 | gpi_route_interrupt(EC_LID_GPI, GPI_IS_SMI); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 84 | break; |
| 85 | } |
| 86 | return 0; |
| 87 | } |