Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -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. |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <arch/io.h> |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 17 | #include <console/console.h> |
| 18 | #include <cpu/x86/smm.h> |
| 19 | #include <southbridge/intel/bd82x6x/nvs.h> |
| 20 | #include <southbridge/intel/bd82x6x/pch.h> |
| 21 | #include <southbridge/intel/bd82x6x/me.h> |
| 22 | #include <northbridge/intel/sandybridge/sandybridge.h> |
| 23 | #include <cpu/intel/model_206ax/model_206ax.h> |
| 24 | #include <elog.h> |
| 25 | #include <ec/compal/ene932/ec.h> |
| 26 | #include "ec.h" |
| 27 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 28 | static u8 mainboard_smi_ec(void) |
| 29 | { |
| 30 | u8 src; |
| 31 | u32 pm1_cnt; |
Paul Menzel | 5679e5a | 2013-10-21 20:23:35 +0200 | [diff] [blame] | 32 | #if CONFIG_ELOG_GSMI |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 33 | static int battery_critical_logged; |
Paul Menzel | 5679e5a | 2013-10-21 20:23:35 +0200 | [diff] [blame] | 34 | #endif |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 35 | |
| 36 | ec_kbc_write_cmd(0x56); |
| 37 | src = ec_kbc_read_ob(); |
| 38 | printk(BIOS_DEBUG, "mainboard_smi_ec src: %x\n", src); |
| 39 | |
| 40 | switch (src) { |
| 41 | case EC_BATTERY_CRITICAL: |
| 42 | #if CONFIG_ELOG_GSMI |
| 43 | if (!battery_critical_logged) |
| 44 | elog_add_event_byte(ELOG_TYPE_EC_EVENT, |
| 45 | EC_EVENT_BATTERY_CRITICAL); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 46 | battery_critical_logged = 1; |
Paul Menzel | 5679e5a | 2013-10-21 20:23:35 +0200 | [diff] [blame] | 47 | #endif |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 48 | break; |
| 49 | case EC_LID_CLOSE: |
| 50 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 51 | |
| 52 | #if CONFIG_ELOG_GSMI |
| 53 | elog_add_event_byte(ELOG_TYPE_EC_EVENT, EC_EVENT_LID_CLOSED); |
| 54 | #endif |
| 55 | /* Go to S5 */ |
| 56 | pm1_cnt = inl(smm_get_pmbase() + PM1_CNT); |
| 57 | pm1_cnt |= (0xf << 10); |
| 58 | outl(pm1_cnt, smm_get_pmbase() + PM1_CNT); |
| 59 | break; |
| 60 | } |
| 61 | |
| 62 | return src; |
| 63 | } |
| 64 | |
Duncan Laurie | 0edc224 | 2013-04-29 15:04:30 -0700 | [diff] [blame] | 65 | void mainboard_smi_gpi(u32 gpi_sts) |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 66 | { |
| 67 | u32 pm1_cnt; |
| 68 | |
| 69 | printk(BIOS_DEBUG, "mainboard_smi_gpi: %x\n", gpi_sts); |
| 70 | if (gpi_sts & (1 << EC_SMI_GPI)) { |
| 71 | /* Process all pending events from EC */ |
| 72 | while (mainboard_smi_ec() != EC_NO_EVENT); |
| 73 | } |
| 74 | else if (gpi_sts & (1 << EC_LID_GPI)) { |
| 75 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 76 | |
| 77 | #if CONFIG_ELOG_GSMI |
| 78 | elog_add_event_byte(ELOG_TYPE_EC_EVENT, EC_EVENT_LID_CLOSED); |
| 79 | #endif |
| 80 | /* Go to S5 */ |
| 81 | pm1_cnt = inl(smm_get_pmbase() + PM1_CNT); |
| 82 | pm1_cnt |= (0xf << 10); |
| 83 | outl(pm1_cnt, smm_get_pmbase() + PM1_CNT); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | void mainboard_smi_sleep(u8 slp_typ) |
| 88 | { |
| 89 | printk(BIOS_DEBUG, "mainboard_smi_sleep: %x\n", slp_typ); |
| 90 | /* Disable SCI and SMI events */ |
| 91 | |
| 92 | |
| 93 | /* Clear pending events that may trigger immediate wake */ |
| 94 | |
| 95 | |
| 96 | /* Enable wake events */ |
| 97 | |
| 98 | |
| 99 | /* Tell the EC to Disable USB power */ |
| 100 | if (smm_get_gnvs()->s3u0 == 0 && smm_get_gnvs()->s3u1 == 0) { |
| 101 | ec_kbc_write_cmd(0x45); |
| 102 | ec_kbc_write_ib(0xF2); |
| 103 | } |
| 104 | } |
| 105 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 106 | #define APMC_ACPI_EN 0xe1 |
| 107 | #define APMC_ACPI_DIS 0x1e |
| 108 | |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 109 | int mainboard_smi_apmc(u8 apmc) |
| 110 | { |
| 111 | printk(BIOS_DEBUG, "mainboard_smi_apmc: %x\n", apmc); |
| 112 | switch (apmc) { |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 113 | case APMC_ACPI_EN: |
| 114 | printk(BIOS_DEBUG, "APMC: ACPI_EN\n"); |
| 115 | /* Clear all pending events */ |
| 116 | /* EC cmd:59 data:E8 */ |
| 117 | ec_kbc_write_cmd(0x59); |
| 118 | ec_kbc_write_ib(0xE8); |
| 119 | |
| 120 | /* Set LID GPI to generate SCIs */ |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 121 | gpi_route_interrupt(EC_LID_GPI, GPI_IS_SCI); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 122 | break; |
| 123 | case APMC_ACPI_DIS: |
| 124 | printk(BIOS_DEBUG, "APMC: ACPI_DIS\n"); |
| 125 | /* Clear all pending events */ |
| 126 | /* EC cmd:59 data:e9 */ |
| 127 | ec_kbc_write_cmd(0x59); |
| 128 | ec_kbc_write_ib(0xE9); |
| 129 | |
| 130 | /* Set LID GPI to generate SMIs */ |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 131 | gpi_route_interrupt(EC_LID_GPI, GPI_IS_SMI); |
Stefan Reinauer | a7198b3 | 2012-12-11 16:00:47 -0800 | [diff] [blame] | 132 | break; |
| 133 | } |
| 134 | return 0; |
| 135 | } |