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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc. |
| 19 | */ |
| 20 | |
| 21 | #include <arch/io.h> |
| 22 | #include <console/console.h> |
| 23 | #include <cpu/x86/smm.h> |
| 24 | #include <elog.h> |
| 25 | #include <ec/google/chromeec/ec.h> |
| 26 | #include <soc/iomap.h> |
| 27 | #include <soc/nvs.h> |
| 28 | #include <soc/pm.h> |
| 29 | #include <soc/smm.h> |
| 30 | #include "ec.h" |
Duncan Laurie | 5626085 | 2015-08-17 09:53:22 -0700 | [diff] [blame^] | 31 | #include "gpio.h" |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 32 | |
| 33 | int mainboard_io_trap_handler(int smif) |
| 34 | { |
| 35 | switch (smif) { |
| 36 | case 0x99: |
| 37 | printk(BIOS_DEBUG, "Sample\n"); |
| 38 | smm_get_gnvs()->smif = 0; |
| 39 | break; |
| 40 | default: |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | /* On success, the IO Trap Handler returns 0 |
| 45 | * On failure, the IO Trap Handler returns a value != 0 |
| 46 | * |
| 47 | * For now, we force the return value to 0 and log all traps to |
| 48 | * see what's going on. |
| 49 | */ |
| 50 | return 1; |
| 51 | } |
| 52 | |
| 53 | static u8 mainboard_smi_ec(void) |
| 54 | { |
| 55 | u8 cmd = 0; |
| 56 | #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC) |
| 57 | u32 pm1_cnt; |
| 58 | cmd = google_chromeec_get_event(); |
| 59 | |
| 60 | /* Log this event */ |
| 61 | if (IS_ENABLED(CONFIG_ELOG_GSMI) && cmd) |
| 62 | elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd); |
| 63 | |
| 64 | switch (cmd) { |
| 65 | case EC_HOST_EVENT_LID_CLOSED: |
| 66 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 67 | |
| 68 | /* Go to S5 */ |
| 69 | pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT); |
| 70 | pm1_cnt |= (0xf << 10); |
| 71 | outl(pm1_cnt, ACPI_BASE_ADDRESS + PM1_CNT); |
| 72 | break; |
| 73 | } |
| 74 | #endif |
| 75 | return cmd; |
| 76 | } |
| 77 | |
Aaron Durbin | 50ed38f | 2015-08-08 01:25:21 -0500 | [diff] [blame] | 78 | void mainboard_smi_gpi_handler(const struct gpi_status *sts) |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 79 | { |
Aaron Durbin | 50ed38f | 2015-08-08 01:25:21 -0500 | [diff] [blame] | 80 | if (gpi_status_get(sts, EC_SMI_GPI)) { |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 81 | /* Process all pending events */ |
| 82 | while (mainboard_smi_ec() != 0) |
| 83 | ; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | void mainboard_smi_sleep(u8 slp_typ) |
| 88 | { |
| 89 | #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC) |
| 90 | /* Disable USB charging if required */ |
| 91 | switch (slp_typ) { |
| 92 | case 3: |
| 93 | if (smm_get_gnvs()->s3u0 == 0) { |
| 94 | google_chromeec_set_usb_charge_mode( |
| 95 | 0, USB_CHARGE_MODE_DISABLED); |
| 96 | google_chromeec_set_usb_charge_mode( |
| 97 | 1, USB_CHARGE_MODE_DISABLED); |
| 98 | } |
| 99 | |
| 100 | /* Enable wake events */ |
| 101 | google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS); |
| 102 | break; |
| 103 | case 5: |
| 104 | if (smm_get_gnvs()->s5u0 == 0) { |
| 105 | google_chromeec_set_usb_charge_mode( |
| 106 | 0, USB_CHARGE_MODE_DISABLED); |
| 107 | google_chromeec_set_usb_charge_mode( |
| 108 | 1, USB_CHARGE_MODE_DISABLED); |
| 109 | } |
| 110 | |
| 111 | /* Enable wake events */ |
| 112 | google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS); |
| 113 | break; |
| 114 | } |
| 115 | |
| 116 | /* Disable SCI and SMI events */ |
| 117 | google_chromeec_set_smi_mask(0); |
| 118 | google_chromeec_set_sci_mask(0); |
| 119 | |
| 120 | /* Clear pending events that may trigger immediate wake */ |
| 121 | while (google_chromeec_get_event() != 0) |
| 122 | ; |
| 123 | #endif |
| 124 | } |
| 125 | |
| 126 | int mainboard_smi_apmc(u8 apmc) |
| 127 | { |
| 128 | #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC) |
| 129 | switch (apmc) { |
| 130 | case APM_CNT_ACPI_ENABLE: |
| 131 | google_chromeec_set_smi_mask(0); |
| 132 | /* Clear all pending events */ |
| 133 | while (google_chromeec_get_event() != 0) |
| 134 | ; |
| 135 | google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS); |
| 136 | break; |
| 137 | case APM_CNT_ACPI_DISABLE: |
| 138 | google_chromeec_set_sci_mask(0); |
| 139 | /* Clear all pending events */ |
| 140 | while (google_chromeec_get_event() != 0) |
| 141 | ; |
| 142 | google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS); |
| 143 | break; |
| 144 | } |
| 145 | #endif |
| 146 | return 0; |
| 147 | } |