coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
ec.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <bootmode.h>
4 #include <types.h>
5 #include <console/console.h>
6 #include <ec/quanta/it8518/ec.h>
7 #include <device/device.h>
10 #include "ec.h"
11 
12 void stout_ec_init(void)
13 {
14 
15  printk(BIOS_DEBUG,"%s: EC FW version %x%x\n", __func__,
17 
18  /*
19  * Important: get_recovery_mode_switch() must be called in EC init.
20  */
22 
23  /* 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
30  * 1/0 USB on, all USB port didn't support wake up
31  * 0/1 USB on, yellow port support wake up charge, but may not support
32  * charge smart phone.
33  * 1/1 USB on, yellow port in AUTO mode and didn't support wake up system.
34  */
37 
38  // TODO: Power Limit Setting
39 }
40 
42 {
43  u8 ec_reg, critical_shutdown = 0;
44 
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;
55  }
56 
57  /* 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;
61  }
62 
63  /* 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;
69  }
70 
71  if ((ec_reg & 0x8F) == 0x8F) {
72  printk(BIOS_ERR, " EC Read Battery Error\n");
73  }
74 
75  if (critical_shutdown) {
76  printk(BIOS_ERR, "EC critical_shutdown");
77 
78  /* Go to S5 */
80  }
81 }
#define PM1_CNT
Definition: pm.h:27
#define printk(level,...)
Definition: stdlib.h:16
u8 ec_read(u8 addr)
Definition: ec.c:107
int ec_write(u8 addr, u8 data)
Definition: ec.c:115
void ec_kbc_write_cmd(u8 cmd)
Definition: ec.c:77
#define EC_PERIPH_STAT_3
Definition: ec.h:52
#define EC_USB_S3_EN
Definition: ec.h:51
#define EC_FW_VER
Definition: ec.h:55
#define EC_MBAT_STATUS
Definition: ec.h:59
#define EC_PERIPH_CNTL_3
Definition: ec.h:50
#define EC_KBD_CMD_UNMUTE
Definition: ec.h:26
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
void stout_ec_init(void)
Definition: ec.c:12
void stout_ec_finalize_smm(void)
Definition: ec.c:41
u32 read_pmbase32(const u8 addr)
Definition: pmbase.c:57
void write_pmbase32(const u8 addr, const u32 val)
Definition: pmbase.c:36
uint8_t u8
Definition: stdint.h:45
int get_recovery_mode_switch(void)
Definition: switches.c:17