blob: 019f046b4cec75a7d3004cbd8b4784a01da77041 [file] [log] [blame]
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 The Chromium OS Authors. All rights reserved.
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 Reinauerb7ecf6d2013-03-13 17:13:32 -070014 */
15
16#include <arch/acpi.h>
17#include <arch/io.h>
Kyösti Mälkki926a8d12014-04-27 22:17:22 +030018#include <bootmode.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070019#include <types.h>
20#include <console/console.h>
21#include <ec/quanta/it8518/ec.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <southbridge/intel/bd82x6x/pch.h>
25#include <elog.h>
26#include "ec.h"
27
28#ifdef __SMM__
29#include <cpu/x86/smm.h>
30#endif
31
32#ifndef __SMM__
33void stout_ec_init(void)
34{
35
36 printk(BIOS_DEBUG,"%s: EC FW version %x%x\n", __func__,
37 ec_read(EC_FW_VER), ec_read(EC_FW_VER + 1));
38
39 /*
40 * Important: get_recovery_mode_switch() must be called in EC init.
41 */
Kyösti Mälkki926a8d12014-04-27 22:17:22 +030042 if (IS_ENABLED(CONFIG_BOOTMODE_STRAPS))
43 get_recovery_mode_switch();
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070044
45 /* Unmute */
46 ec_kbc_write_cmd(EC_KBD_CMD_UNMUTE);
47
48 /*
49 * Set USB Power off in S3 (enabled in S3 path if requested in gnvs)
50 * Bit0 of 0x0D/Bit0 of 0x26
51 * 0/0 All USB port off
52 * 1/0 USB on, all USB port didn’t support wake up
53 * 0/1 USB on, yellow port support wake up charge, but may not support
54 * charge smart phone.
55 * 1/1 USB on, yellow port in AUTO mode and didn’t support wake up system.
56 */
57 ec_write(EC_PERIPH_CNTL_3, ec_read(EC_PERIPH_CNTL_3) & 0xE);
58 ec_write(EC_USB_S3_EN, ec_read(EC_USB_S3_EN) & 0xE);
59
60 // TODO: Power Limit Setting
61}
62
63#else // SMM
64
65void stout_ec_finalize_smm(void)
66{
67 u8 ec_reg, critical_shutdown = 0;
68 u32 pm1_cnt;
69
70 /*
71 * Check EC for error conditions.
72 */
73
74 /* Fan Error : Peripheral Status 3 (0x35) bit 4 */
75 ec_reg = ec_read(EC_PERIPH_STAT_3);
76
77 if (ec_reg & 0x8) {
78 printk(BIOS_ERR, " EC Fan Error\n");
79 critical_shutdown = 1;
Patrick Georgi7605a5a2015-07-31 17:18:16 +020080#if CONFIG_ELOG_GSMI
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070081 elog_add_event_word(EC_EVENT_BATTERY_CRITICAL, EC_EVENT_FAN_ERROR);
82#endif
83 }
84
85
86 /* Thermal Device Error : Peripheral Status 3 (0x35) bit 8 */
87 if (ec_reg & 0x80) {
88 printk(BIOS_ERR, " EC Thermal Device Error\n");
89 critical_shutdown = 1;
Patrick Georgi7605a5a2015-07-31 17:18:16 +020090#if CONFIG_ELOG_GSMI
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070091 elog_add_event_word(EC_EVENT_BATTERY_CRITICAL, EC_EVENT_THERMAL);
92#endif
93 }
94
95
96 /* Critical Battery Error */
97 ec_reg = ec_read(EC_MBAT_STATUS);
98
99 if ((ec_reg & 0xCF) == 0xC0) {
100 printk(BIOS_ERR, " EC Critical Battery Error\n");
101 critical_shutdown = 1;
Patrick Georgi7605a5a2015-07-31 17:18:16 +0200102#if CONFIG_ELOG_GSMI
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700103 elog_add_event_word(ELOG_TYPE_EC_EVENT, EC_EVENT_BATTERY_CRITICAL);
104#endif
105 }
106
107 if ((ec_reg & 0x8F) == 0x8F) {
108 printk(BIOS_ERR, " EC Read Battery Error\n");
Patrick Georgi7605a5a2015-07-31 17:18:16 +0200109#if CONFIG_ELOG_GSMI
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -0700110 elog_add_event_word(ELOG_TYPE_EC_EVENT, EC_EVENT_BATTERY);
111#endif
112 }
113
114
115 if (critical_shutdown) {
116 printk(BIOS_ERR, "EC critical_shutdown");
117
118 /* Go to S5 */
119 pm1_cnt = inl(smm_get_pmbase() + PM1_CNT);
120 pm1_cnt |= (0xf << 10);
121 outl(pm1_cnt, smm_get_pmbase() + PM1_CNT);
122 }
123}
124#endif //__SMM__