Angel Pons | 2e8a4b0 | 2020-04-05 13:22:54 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | 926a8d1 | 2014-04-27 22:17:22 +0300 | [diff] [blame] | 3 | #include <bootmode.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 4 | #include <types.h> |
| 5 | #include <console/console.h> |
| 6 | #include <ec/quanta/it8518/ec.h> |
| 7 | #include <device/device.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 8 | #include <southbridge/intel/bd82x6x/pch.h> |
Patrick Rudolph | e67f626 | 2018-06-28 14:09:56 +0200 | [diff] [blame] | 9 | #include <southbridge/intel/common/pmbase.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 10 | #include "ec.h" |
| 11 | |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 12 | void 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 Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame] | 21 | get_recovery_mode_switch(); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 22 | |
| 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 Roth | 0cd338e | 2016-07-29 14:07:30 -0600 | [diff] [blame] | 30 | * 1/0 USB on, all USB port didn't support wake up |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 31 | * 0/1 USB on, yellow port support wake up charge, but may not support |
| 32 | * charge smart phone. |
Martin Roth | 0cd338e | 2016-07-29 14:07:30 -0600 | [diff] [blame] | 33 | * 1/1 USB on, yellow port in AUTO mode and didn't support wake up system. |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 34 | */ |
| 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 Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 41 | void stout_ec_finalize_smm(void) |
| 42 | { |
| 43 | u8 ec_reg, critical_shutdown = 0; |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 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; |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 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; |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 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; |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | if ((ec_reg & 0x8F) == 0x8F) { |
| 72 | printk(BIOS_ERR, " EC Read Battery Error\n"); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 75 | if (critical_shutdown) { |
| 76 | printk(BIOS_ERR, "EC critical_shutdown"); |
| 77 | |
| 78 | /* Go to S5 */ |
Patrick Rudolph | e67f626 | 2018-06-28 14:09:56 +0200 | [diff] [blame] | 79 | write_pmbase32(PM1_CNT, read_pmbase32(PM1_CNT) | (0xf << 10)); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 80 | } |
| 81 | } |