Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * Copyright (C) 2015 Google Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <arch/io.h> |
| 18 | #include <console/console.h> |
| 19 | #include <cpu/x86/smm.h> |
| 20 | #include <elog.h> |
| 21 | #include <ec/google/chromeec/ec.h> |
| 22 | #include <soc/iomap.h> |
| 23 | #include <soc/nvs.h> |
| 24 | #include <soc/pm.h> |
| 25 | #include <soc/smm.h> |
| 26 | #include "ec.h" |
Duncan Laurie | 5626085 | 2015-08-17 09:53:22 -0700 | [diff] [blame] | 27 | #include "gpio.h" |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 28 | |
| 29 | int mainboard_io_trap_handler(int smif) |
| 30 | { |
| 31 | switch (smif) { |
| 32 | case 0x99: |
| 33 | printk(BIOS_DEBUG, "Sample\n"); |
| 34 | smm_get_gnvs()->smif = 0; |
| 35 | break; |
| 36 | default: |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | /* On success, the IO Trap Handler returns 0 |
| 41 | * On failure, the IO Trap Handler returns a value != 0 |
| 42 | * |
| 43 | * For now, we force the return value to 0 and log all traps to |
| 44 | * see what's going on. |
| 45 | */ |
| 46 | return 1; |
| 47 | } |
| 48 | |
| 49 | static u8 mainboard_smi_ec(void) |
| 50 | { |
| 51 | u8 cmd = 0; |
| 52 | #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC) |
| 53 | u32 pm1_cnt; |
| 54 | cmd = google_chromeec_get_event(); |
| 55 | |
| 56 | /* Log this event */ |
| 57 | if (IS_ENABLED(CONFIG_ELOG_GSMI) && cmd) |
| 58 | elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd); |
| 59 | |
| 60 | switch (cmd) { |
| 61 | case EC_HOST_EVENT_LID_CLOSED: |
| 62 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 63 | |
| 64 | /* Go to S5 */ |
| 65 | pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT); |
| 66 | pm1_cnt |= (0xf << 10); |
| 67 | outl(pm1_cnt, ACPI_BASE_ADDRESS + PM1_CNT); |
| 68 | break; |
| 69 | } |
| 70 | #endif |
| 71 | return cmd; |
| 72 | } |
| 73 | |
Aaron Durbin | 50ed38f | 2015-08-08 01:25:21 -0500 | [diff] [blame] | 74 | void mainboard_smi_gpi_handler(const struct gpi_status *sts) |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 75 | { |
Aaron Durbin | 50ed38f | 2015-08-08 01:25:21 -0500 | [diff] [blame] | 76 | if (gpi_status_get(sts, EC_SMI_GPI)) { |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 77 | /* Process all pending events */ |
| 78 | while (mainboard_smi_ec() != 0) |
| 79 | ; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | void mainboard_smi_sleep(u8 slp_typ) |
| 84 | { |
| 85 | #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC) |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 86 | switch (slp_typ) { |
| 87 | case 3: |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 88 | /* Enable wake events */ |
| 89 | google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS); |
| 90 | break; |
| 91 | case 5: |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 92 | /* Enable wake events */ |
| 93 | google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS); |
| 94 | break; |
| 95 | } |
| 96 | |
| 97 | /* Disable SCI and SMI events */ |
| 98 | google_chromeec_set_smi_mask(0); |
| 99 | google_chromeec_set_sci_mask(0); |
| 100 | |
| 101 | /* Clear pending events that may trigger immediate wake */ |
| 102 | while (google_chromeec_get_event() != 0) |
| 103 | ; |
| 104 | #endif |
| 105 | } |
| 106 | |
| 107 | int mainboard_smi_apmc(u8 apmc) |
| 108 | { |
| 109 | #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC) |
| 110 | switch (apmc) { |
| 111 | case APM_CNT_ACPI_ENABLE: |
| 112 | google_chromeec_set_smi_mask(0); |
| 113 | /* Clear all pending events */ |
| 114 | while (google_chromeec_get_event() != 0) |
| 115 | ; |
| 116 | google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS); |
| 117 | break; |
| 118 | case APM_CNT_ACPI_DISABLE: |
| 119 | google_chromeec_set_sci_mask(0); |
| 120 | /* Clear all pending events */ |
| 121 | while (google_chromeec_get_event() != 0) |
| 122 | ; |
| 123 | google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS); |
| 124 | break; |
| 125 | } |
| 126 | #endif |
| 127 | return 0; |
| 128 | } |