diff options
author | Scott Worley <scott.worley@microchip.corp-partner.google.com> | 2017-12-20 12:23:59 -0500 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-01-02 15:48:20 -0800 |
commit | d813935b827b55f4650365a5e9e8096e47122f07 (patch) | |
tree | 32d0ef28e42c9b540770a5e4572e163e80f62b52 | |
parent | b74f6a576a822f43872f07aebb6909a457a84afa (diff) | |
download | chrome-ec-d813935b827b55f4650365a5e9e8096e47122f07.tar.gz |
espi: Add API to test if signal is eSPI virtual wire
Add espi_signal_is_vw in new file common/espi.c for
testing if a signal is an eSPI virtual wire. API used
in power common and intel_x86.
Fix CONFIG_BRINGUP support for eSPI (off by default).
Add espi_vw_get_wire_name returning a pointer to
constant string. Chip modules do not need to maintain
names of eSPI signals.
BRANCH=none
BUG=
TEST=Build poppy and other eSPI enabled boards. Test
power state machine.
Change-Id: I13319e79d208c69092a02ec3ac655477d3043d61
Signed-off-by: Scott Worley <scott.worley@microchip.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/836818
Commit-Ready: Randall Spangler <rspangler@chromium.org>
Tested-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | common/build.mk | 1 | ||||
-rw-r--r-- | common/espi.c | 67 | ||||
-rw-r--r-- | include/espi.h | 18 | ||||
-rw-r--r-- | power/common.c | 30 | ||||
-rw-r--r-- | power/intel_x86.c | 2 |
5 files changed, 106 insertions, 12 deletions
diff --git a/common/build.mk b/common/build.mk index 2af1a0e3f7..c51d95be8c 100644 --- a/common/build.mk +++ b/common/build.mk @@ -47,6 +47,7 @@ common-$(CONFIG_DEVICE_EVENT)+=device_event.o common-$(CONFIG_DEVICE_STATE)+=device_state.o common-$(CONFIG_DPTF)+=dptf.o common-$(CONFIG_EC_EC_COMM_SLAVE)+=ec_ec_comm_slave.o +common-$(CONFIG_ESPI)+=espi.o common-$(CONFIG_EXTENSION_COMMAND)+=extension.o common-$(CONFIG_EXTPOWER_GPIO)+=extpower_gpio.o common-$(CONFIG_FANS)+=fan.o pwm.o diff --git a/common/espi.c b/common/espi.c new file mode 100644 index 0000000000..4c6a0ed1c2 --- /dev/null +++ b/common/espi.c @@ -0,0 +1,67 @@ +/* Copyright (c) 2017 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* eSPI common functionality for Chrome EC */ + +#include "common.h" +#include "gpio.h" +#include "registers.h" +#include "espi.h" +#include "timer.h" +#include "util.h" + + +const char *espi_vw_names[] = { + "VW_SLP_S3_L", + "VW_SLP_S4_L", + "VW_SLP_S5_L", + "VW_SUS_STAT_L", + "VW_PLTRST_L", + "VW_OOB_RST_WARN", + "VW_OOB_RST_ACK", + "VW_WAKE_L", + "VW_PME_L", + "VW_ERROR_FATAL", + "VW_ERROR_NON_FATAL", + /* Merge bit 3/0 into one signal. Need to set them simultaneously */ + "VW_SLAVE_BTLD_STATUS_DONE", + "VW_SCI_L", + "VW_SMI_L", + "VW_RCIN_L", + "VW_HOST_RST_ACK", + "VW_HOST_RST_WARN", + "VW_SUS_ACK", + "VW_SUS_WARN_L", + "VW_SUS_PWRDN_ACK_L", + "VW_SLP_A_L", + "VW_SLP_LAN", + "VW_SLP_WLAN", +}; +BUILD_ASSERT(ARRAY_SIZE(espi_vw_names) == VW_SIGNAL_COUNT); + + +const char *espi_vw_get_wire_name(enum espi_vw_signal signal) +{ + int idx; + + if ((uint32_t)signal > VW_SIGNAL_BASE) { + idx = (uint32_t)signal - (VW_SIGNAL_BASE + 1); + if (idx < ARRAY_SIZE(espi_vw_names)) + return espi_vw_names[idx]; + } + + return NULL; +} + + +int espi_signal_is_vw(int signal) +{ + enum espi_vw_signal sig = (enum espi_vw_signal)signal; + + if ((sig > VW_SIGNAL_BASE) && (sig < VW_SIGNAL_BASE_END)) + return 1; + + return 0; +} diff --git a/include/espi.h b/include/espi.h index d96f79c9c8..2795f9aacb 100644 --- a/include/espi.h +++ b/include/espi.h @@ -40,6 +40,8 @@ enum espi_vw_signal { VW_SIGNAL_BASE_END, }; +#define VW_SIGNAL_COUNT (VW_SIGNAL_BASE_END - VW_SIGNAL_BASE - 1) + /** * Set eSPI Virtual-Wire signal to Host * @@ -73,4 +75,20 @@ int espi_vw_enable_wire_int(enum espi_vw_signal signal); */ int espi_vw_disable_wire_int(enum espi_vw_signal signal); +/** + * Return pointer to constant eSPI virtual wire signal name + * + * @param signal virtual wire enum + * @return pointer to string or NULL if signal out of range + */ +const char *espi_vw_get_wire_name(enum espi_vw_signal signal); + +/** + * Check if signal is an eSPI virtual wire + * @param signal is gpio_signal or espi_vw_signal enum casted to int + * @return 1 if signal is virtual wire else returns 0. + */ +int espi_signal_is_vw(int signal); + + #endif /* __CROS_EC_ESPI_H */ diff --git a/power/common.c b/power/common.c index ed1ffcc0e5..ddde0427f6 100644 --- a/power/common.c +++ b/power/common.c @@ -77,7 +77,7 @@ static int power_signal_get_level(enum gpio_signal signal) { #ifdef CONFIG_ESPI_VW_SIGNALS /* Check signal is from GPIOs or VWs */ - if ((int)signal > VW_SIGNAL_BASE) + if (espi_signal_is_vw(signal)) return espi_vw_get_wire(signal); #endif return gpio_get_level(signal); @@ -87,7 +87,7 @@ int power_signal_disable_interrupt(enum gpio_signal signal) { #ifdef CONFIG_ESPI_VW_SIGNALS /* Check signal is from GPIOs or VWs */ - if ((int)signal > VW_SIGNAL_BASE) + if (espi_signal_is_vw(signal)) return espi_vw_disable_wire_int(signal); #endif return gpio_disable_interrupt(signal); @@ -97,7 +97,7 @@ int power_signal_enable_interrupt(enum gpio_signal signal) { #ifdef CONFIG_ESPI_VW_SIGNALS /* Check signal is from GPIOs or VWs */ - if ((int)signal > VW_SIGNAL_BASE) + if (espi_signal_is_vw(signal)) return espi_vw_enable_wire_int(signal); #endif return gpio_enable_interrupt(signal); @@ -109,6 +109,18 @@ int power_signal_is_asserted(const struct power_signal_info *s) !!(s->flags & POWER_SIGNAL_ACTIVE_STATE); } +#ifdef CONFIG_BRINGUP +static const char *power_signal_get_name(enum gpio_signal signal) +{ +#ifdef CONFIG_ESPI_VW_SIGNALS + /* Check signal is from GPIOs or VWs */ + if (espi_signal_is_vw(signal)) + return espi_vw_get_wire_name(signal); +#endif + return gpio_get_name(signal); +} +#endif + /** * Update input signals mask */ @@ -515,10 +527,6 @@ DECLARE_HOOK(HOOK_AC_CHANGE, power_ac_change, HOOK_PRIO_DEFAULT); /*****************************************************************************/ /* Interrupts */ -#if defined(CONFIG_BRINGUP) && defined(CONFIG_ESPI_VW_SIGNALS) -#error "Not support CONFIG_BRINGUP since gpio_get_name func" -#endif - #ifdef CONFIG_BRINGUP #define MAX_SIGLOG_ENTRIES 24 @@ -538,7 +546,7 @@ static void siglog_deferred(void) /* Disable interrupts for input signals while we print stuff.*/ for (i = 0; i < POWER_SIGNAL_COUNT; i++) - gpio_disable_interrupt(power_signal_list[i].gpio); + power_signal_disable_interrupt(power_signal_list[i].gpio); CPRINTF("%d signal changes:\n", siglog_entries); for (i = 0; i < siglog_entries; i++) { @@ -546,7 +554,7 @@ static void siglog_deferred(void) tdiff.val = siglog[i].time.val - siglog[i-1].time.val; CPRINTF(" %.6ld +%.6ld %s => %d\n", siglog[i].time.val, tdiff.val, - gpio_get_name(siglog[i].signal), + power_signal_get_name(siglog[i].signal), siglog[i].level); } if (siglog_truncated) @@ -555,7 +563,7 @@ static void siglog_deferred(void) /* Okay, turn 'em on again. */ for (i = 0; i < POWER_SIGNAL_COUNT; i++) - gpio_enable_interrupt(power_signal_list[i].gpio); + power_signal_disable_interrupt(power_signal_list[i].gpio); } DECLARE_DEFERRED(siglog_deferred); @@ -568,7 +576,7 @@ static void siglog_add(enum gpio_signal signal) siglog[siglog_entries].time = get_time(); siglog[siglog_entries].signal = signal; - siglog[siglog_entries].level = gpio_get_level(signal); + siglog[siglog_entries].level = power_signal_get_level(signal); siglog_entries++; hook_call_deferred(&siglog_deferred_data, SECOND); diff --git a/power/intel_x86.c b/power/intel_x86.c index 8233261661..2ef05191ba 100644 --- a/power/intel_x86.c +++ b/power/intel_x86.c @@ -98,7 +98,7 @@ DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, power_up_inhibited_cb, HOOK_PRIO_DEFAULT); static inline int chipset_get_sleep_signal(enum sys_sleep_state state) { #ifdef CONFIG_ESPI_VW_SIGNALS - if (sleep_sig[state] > VW_SIGNAL_BASE) + if (espi_signal_is_vw(sleep_sig[state])) return espi_vw_get_wire(sleep_sig[state]); else #endif |