| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <cpu/x86/smm.h> |
| 5 |
#include <ec/acpi/ec.h> |
| 6 |
#include <ec/compal/ene932/ec.h> |
| 7 |
#include <southbridge/intel/bd82x6x/pch.h> |
| 8 |
#include <southbridge/intel/common/pmutil.h> |
| 9 |
|
| 10 |
#include "ec.h" |
| 11 |
|
| 12 |
#define GPE_PALMDET1 2 |
| 13 |
#define GPE_PALMDET2 4 |
| 14 |
#define GPE_EC_SCI 7 |
| 15 |
#define GPE_EC_SMI 8 |
| 16 |
|
| 17 |
#define GPE_EC_WAKE 13 |
| 18 |
|
| 19 |
enum sleep_states { |
| 20 |
S0 = 0, |
| 21 |
S1 = 1, |
| 22 |
S3 = 3, |
| 23 |
S4 = 4, |
| 24 |
S5 = 5, |
| 25 |
}; |
| 26 |
|
| 27 |
enum ec_smi_event { |
| 28 |
EC_SMI_EVENT_IDLE = 0x80, |
| 29 |
EC_SMI_BATTERY_LOW = 0xb3, |
| 30 |
}; |
| 31 |
|
| 32 |
|
| 33 |
static void ec_enter_apm_mode(void) |
| 34 |
{ |
| 35 |
ec_kbc_write_cmd(0x59); |
| 36 |
ec_kbc_write_ib(0xE9); |
| 37 |
} |
| 38 |
|
| 39 |
static void ec_enter_acpi_mode(void) |
| 40 |
{ |
| 41 |
ec_kbc_write_cmd(0x59); |
| 42 |
ec_kbc_write_ib(0xE8); |
| 43 |
} |
| 44 |
|
| 45 |
static uint8_t ec_get_smi_event(void) |
| 46 |
{ |
| 47 |
ec_kbc_write_cmd(0x56); |
| 48 |
return ec_kbc_read_ob(); |
| 49 |
} |
| 50 |
|
| 51 |
static void ec_process_smi(uint8_t src) |
| 52 |
{ |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
printk(BIOS_DEBUG, "Unhandled EC_SMI event 0x%x\n", src); |
| 59 |
} |
| 60 |
|
| 61 |
static void handle_ec_smi(void) |
| 62 |
{ |
| 63 |
uint8_t src; |
| 64 |
|
| 65 |
while ((src = ec_get_smi_event()) != EC_SMI_EVENT_IDLE) |
| 66 |
ec_process_smi(src); |
| 67 |
} |
| 68 |
|
| 69 |
void mainboard_smi_gpi(u32 gpi_sts) |
| 70 |
{ |
| 71 |
if (gpi_sts & (1 << GPE_EC_SMI)) |
| 72 |
handle_ec_smi(); |
| 73 |
} |
| 74 |
|
| 75 |
int mainboard_smi_apmc(u8 data) |
| 76 |
{ |
| 77 |
switch (data) { |
| 78 |
case APM_CNT_ACPI_ENABLE: |
| 79 |
ec_enter_acpi_mode(); |
| 80 |
gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI); |
| 81 |
gpi_route_interrupt(GPE_PALMDET1, GPI_IS_SCI); |
| 82 |
gpi_route_interrupt(GPE_PALMDET2, GPI_IS_SCI); |
| 83 |
break; |
| 84 |
case APM_CNT_ACPI_DISABLE: |
| 85 |
ec_enter_apm_mode(); |
| 86 |
gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI); |
| 87 |
break; |
| 88 |
default: |
| 89 |
printk(BIOS_DEBUG, "Unhandled ACPI command: 0x%x\n", data); |
| 90 |
} |
| 91 |
return 0; |
| 92 |
} |
| 93 |
|
| 94 |
void mainboard_smi_sleep(u8 slp_typ) |
| 95 |
{ |
| 96 |
if (slp_typ == S3) { |
| 97 |
u8 ec_wake = ec_read(0x32); |
| 98 |
|
| 99 |
if (ec_wake & 0x14) |
| 100 |
gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI); |
| 101 |
} |
| 102 |
} |