blob: 2584166cf29ce3f1211cbf332533e66c3ffa447e [file] [log] [blame]
Angel Pons2e8a4b02020-04-05 13:22:54 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07002
Kyösti Mälkki926a8d12014-04-27 22:17:22 +03003#include <bootmode.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07004#include <types.h>
5#include <console/console.h>
6#include <ec/quanta/it8518/ec.h>
7#include <device/device.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07008#include <southbridge/intel/bd82x6x/pch.h>
Patrick Rudolphe67f6262018-06-28 14:09:56 +02009#include <southbridge/intel/common/pmbase.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070010#include "ec.h"
11
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070012void stout_ec_init(void)
13{
14
15 printk(BIOS_DEBUG,"%s: EC FW version %x%x\n", __func__,
16 ec_read(EC_FW_VER), ec_read(EC_FW_VER + 1));
17
18 /*
19 * Important: get_recovery_mode_switch() must be called in EC init.
20 */
Furquan Shaikh0325dc62016-07-25 13:02:36 -070021 get_recovery_mode_switch();
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070022
23 /* Unmute */
24 ec_kbc_write_cmd(EC_KBD_CMD_UNMUTE);
25
26 /*
27 * Set USB Power off in S3 (enabled in S3 path if requested in gnvs)
28 * Bit0 of 0x0D/Bit0 of 0x26
29 * 0/0 All USB port off
Martin Roth0cd338e2016-07-29 14:07:30 -060030 * 1/0 USB on, all USB port didn't support wake up
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070031 * 0/1 USB on, yellow port support wake up charge, but may not support
32 * charge smart phone.
Martin Roth0cd338e2016-07-29 14:07:30 -060033 * 1/1 USB on, yellow port in AUTO mode and didn't support wake up system.
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070034 */
35 ec_write(EC_PERIPH_CNTL_3, ec_read(EC_PERIPH_CNTL_3) & 0xE);
36 ec_write(EC_USB_S3_EN, ec_read(EC_USB_S3_EN) & 0xE);
37
38 // TODO: Power Limit Setting
39}
40
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070041void stout_ec_finalize_smm(void)
42{
43 u8 ec_reg, critical_shutdown = 0;
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070044
45 /*
46 * Check EC for error conditions.
47 */
48
49 /* Fan Error : Peripheral Status 3 (0x35) bit 4 */
50 ec_reg = ec_read(EC_PERIPH_STAT_3);
51
52 if (ec_reg & 0x8) {
53 printk(BIOS_ERR, " EC Fan Error\n");
54 critical_shutdown = 1;
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070055 }
56
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070057 /* Thermal Device Error : Peripheral Status 3 (0x35) bit 8 */
58 if (ec_reg & 0x80) {
59 printk(BIOS_ERR, " EC Thermal Device Error\n");
60 critical_shutdown = 1;
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070061 }
62
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070063 /* Critical Battery Error */
64 ec_reg = ec_read(EC_MBAT_STATUS);
65
66 if ((ec_reg & 0xCF) == 0xC0) {
67 printk(BIOS_ERR, " EC Critical Battery Error\n");
68 critical_shutdown = 1;
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070069 }
70
71 if ((ec_reg & 0x8F) == 0x8F) {
72 printk(BIOS_ERR, " EC Read Battery Error\n");
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070073 }
74
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070075 if (critical_shutdown) {
76 printk(BIOS_ERR, "EC critical_shutdown");
77
78 /* Go to S5 */
Patrick Rudolphe67f6262018-06-28 14:09:56 +020079 write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10));
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070080 }
81}