Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <arch/io.h> |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 21 | #include <console/console.h> |
| 22 | #include <cpu/x86/smm.h> |
| 23 | #include <southbridge/intel/bd82x6x/nvs.h> |
| 24 | #include <southbridge/intel/bd82x6x/pch.h> |
| 25 | #include <southbridge/intel/bd82x6x/me.h> |
| 26 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 27 | #include <cpu/intel/model_206ax/model_206ax.h> |
| 28 | #include <elog.h> |
| 29 | |
| 30 | /* Include romstage serial for SIO helper functions */ |
| 31 | #include <superio/ite/it8772f/early_serial.c> |
| 32 | |
| 33 | /* Include EC functions */ |
| 34 | #include <ec/google/chromeec/ec.h> |
| 35 | #include "ec.h" |
| 36 | |
| 37 | int mainboard_io_trap_handler(int smif) |
| 38 | { |
| 39 | switch (smif) { |
| 40 | case 0x99: |
| 41 | printk(BIOS_DEBUG, "Sample\n"); |
| 42 | smm_get_gnvs()->smif = 0; |
| 43 | break; |
| 44 | default: |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | /* On success, the IO Trap Handler returns 0 |
| 49 | * On failure, the IO Trap Handler returns a value != 0 |
| 50 | * |
| 51 | * For now, we force the return value to 0 and log all traps to |
| 52 | * see what's going on. |
| 53 | */ |
| 54 | //gnvs->smif = 0; |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | static u8 mainboard_smi_ec(void) |
| 59 | { |
| 60 | u8 cmd = google_chromeec_get_event(); |
| 61 | u32 pm1_cnt; |
| 62 | |
| 63 | #if CONFIG_ELOG_GSMI |
| 64 | /* Log this event */ |
| 65 | if (cmd) |
| 66 | elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd); |
| 67 | #endif |
| 68 | |
| 69 | switch (cmd) { |
| 70 | case EC_HOST_EVENT_LID_CLOSED: |
| 71 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 72 | |
| 73 | /* Go to S5 */ |
| 74 | pm1_cnt = inl(smm_get_pmbase() + PM1_CNT); |
| 75 | pm1_cnt |= (0xf << 10); |
| 76 | outl(pm1_cnt, smm_get_pmbase() + PM1_CNT); |
| 77 | break; |
| 78 | } |
| 79 | |
| 80 | return cmd; |
| 81 | } |
| 82 | |
Duncan Laurie | 0edc224 | 2013-04-29 15:04:30 -0700 | [diff] [blame] | 83 | void mainboard_smi_gpi(u32 gpi_sts) |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 84 | { |
| 85 | if (gpi_sts & (1 << EC_SMI_GPI)) { |
| 86 | /* Process all pending events */ |
| 87 | while (mainboard_smi_ec() != 0); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | void mainboard_smi_sleep(u8 slp_typ) |
| 92 | { |
| 93 | /* Disable USB charging if required */ |
| 94 | switch (slp_typ) { |
| 95 | case 3: |
| 96 | if (smm_get_gnvs()->s3u0 == 0) |
| 97 | google_chromeec_set_usb_charge_mode( |
| 98 | 0, USB_CHARGE_MODE_DISABLED); |
| 99 | if (smm_get_gnvs()->s3u1 == 0) |
| 100 | google_chromeec_set_usb_charge_mode( |
| 101 | 1, USB_CHARGE_MODE_DISABLED); |
| 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 | if (smm_get_gnvs()->s5u1 == 0) |
| 108 | google_chromeec_set_usb_charge_mode( |
| 109 | 1, USB_CHARGE_MODE_DISABLED); |
| 110 | break; |
| 111 | } |
| 112 | |
| 113 | /* Disable SCI and SMI events */ |
| 114 | google_chromeec_set_smi_mask(0); |
| 115 | google_chromeec_set_sci_mask(0); |
| 116 | |
| 117 | /* Clear pending events that may trigger immediate wake */ |
| 118 | while (google_chromeec_get_event() != 0); |
| 119 | |
| 120 | /* Enable wake events */ |
| 121 | google_chromeec_set_wake_mask(LINK_EC_S3_WAKE_EVENTS); |
| 122 | } |
| 123 | |
| 124 | #define APMC_FINALIZE 0xcb |
| 125 | #define APMC_ACPI_EN 0xe1 |
| 126 | #define APMC_ACPI_DIS 0x1e |
| 127 | |
| 128 | static int mainboard_finalized = 0; |
| 129 | |
| 130 | int mainboard_smi_apmc(u8 apmc) |
| 131 | { |
| 132 | switch (apmc) { |
| 133 | case APMC_FINALIZE: |
| 134 | if (mainboard_finalized) { |
| 135 | printk(BIOS_DEBUG, "SMI#: Already finalized\n"); |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | intel_me_finalize_smm(); |
| 140 | intel_pch_finalize_smm(); |
| 141 | intel_sandybridge_finalize_smm(); |
| 142 | intel_model_206ax_finalize_smm(); |
| 143 | |
| 144 | mainboard_finalized = 1; |
| 145 | break; |
| 146 | case APMC_ACPI_EN: |
| 147 | google_chromeec_set_smi_mask(0); |
| 148 | /* Clear all pending events */ |
| 149 | while (google_chromeec_get_event() != 0); |
| 150 | google_chromeec_set_sci_mask(LINK_EC_SCI_EVENTS); |
| 151 | break; |
| 152 | case APMC_ACPI_DIS: |
| 153 | google_chromeec_set_sci_mask(0); |
| 154 | /* Clear all pending events */ |
| 155 | while (google_chromeec_get_event() != 0); |
Idwer Vollering | d26da9c | 2013-12-22 21:38:18 +0000 | [diff] [blame^] | 156 | google_chromeec_set_smi_mask(LINK_EC_SMI_EVENTS); |
Stefan Reinauer | 49428d8 | 2013-02-21 15:48:37 -0800 | [diff] [blame] | 157 | break; |
| 158 | } |
| 159 | return 0; |
| 160 | } |