summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip/it83xx/espi.c7
-rw-r--r--chip/mchp/espi.c10
-rw-r--r--common/espi.c16
-rw-r--r--common/ioexpander.c46
-rw-r--r--include/espi.h11
-rw-r--r--include/gpio_signal.h27
-rw-r--r--include/ioexpander.h10
7 files changed, 83 insertions, 44 deletions
diff --git a/chip/it83xx/espi.c b/chip/it83xx/espi.c
index 972ac6c146..c731a7ad7e 100644
--- a/chip/it83xx/espi.c
+++ b/chip/it83xx/espi.c
@@ -59,7 +59,7 @@ static const struct vw_channel_t vw_host_startup_setting[] = {
};
#define VW_CHAN(name, idx, level, valid) \
- [(name - VW_SIGNAL_BASE)] = {idx, level, valid}
+ [(name - VW_SIGNAL_START)] = {idx, level, valid}
/* VW signals used in eSPI (NOTE: must match order of enum espi_vw_signal). */
static const struct vw_channel_t vw_channel_list[] = {
@@ -165,13 +165,12 @@ static const struct vw_channel_t vw_channel_list[] = {
VW_LEVEL_FIELD(VW_IDX_42_SLP_WLAN),
VW_VALID_FIELD(VW_IDX_42_SLP_WLAN)),
};
-BUILD_ASSERT(ARRAY_SIZE(vw_channel_list) ==
- (VW_SIGNAL_BASE_END - VW_SIGNAL_BASE));
+BUILD_ASSERT(ARRAY_SIZE(vw_channel_list) == VW_SIGNAL_COUNT);
/* Get vw index & value information by signal */
static int espi_vw_get_signal_index(enum espi_vw_signal event)
{
- uint32_t i = event - VW_SIGNAL_BASE;
+ uint32_t i = event - VW_SIGNAL_START;
return (i < ARRAY_SIZE(vw_channel_list)) ? i : -1;
}
diff --git a/chip/mchp/espi.c b/chip/mchp/espi.c
index e7459ae25c..95cd05c10a 100644
--- a/chip/mchp/espi.c
+++ b/chip/mchp/espi.c
@@ -578,7 +578,7 @@ static void espi_pc_flush(void)
void espi_vw_power_signal_interrupt(enum espi_vw_signal signal)
{
CPRINTS("eSPI power signal interrupt for VW %d", signal);
- trace1(0, ESPI, 0, "eSPI pwr intr VW %d", (signal - VW_SIGNAL_BASE));
+ trace1(0, ESPI, 0, "eSPI pwr intr VW %d", (signal - VW_SIGNAL_START));
power_signal_interrupt((enum gpio_signal) signal);
}
@@ -625,7 +625,7 @@ int espi_vw_set_wire(enum espi_vw_signal signal, uint8_t level)
CPRINTS("eSPI VW Set Wire %s = %d",
espi_vw_get_wire_name(signal), level);
trace2(0, ESPI, 0, "VW SetWire[%d] = %d",
- ((uint32_t)signal - VW_SIGNAL_BASE), level);
+ ((uint32_t)signal - VW_SIGNAL_START), level);
#endif
return EC_SUCCESS;
@@ -735,7 +735,7 @@ int espi_vw_get_wire(enum espi_vw_signal signal)
CPRINTS("VW GetWire %s = %d",
espi_vw_get_wire_name(signal), vw);
trace2(0, ESPI, 0, "VW GetWire[%d] = %d",
- ((uint32_t)signal - VW_SIGNAL_BASE), vw);
+ ((uint32_t)signal - VW_SIGNAL_START), vw);
#endif
}
@@ -765,7 +765,7 @@ int espi_vw_enable_wire_int(enum espi_vw_signal signal)
CPRINTS("VW IntrEn for VW[%s]",
espi_vw_get_wire_name(signal));
trace1(0, ESPI, 0, "VW IntrEn for VW[%d]",
- ((uint32_t)signal - VW_SIGNAL_BASE));
+ ((uint32_t)signal - VW_SIGNAL_START));
#endif
ridx = vw_info_tbl[tidx].reg_idx;
@@ -816,7 +816,7 @@ int espi_vw_disable_wire_int(enum espi_vw_signal signal)
CPRINTS("VW IntrDis for VW[%s]",
espi_vw_get_wire_name(signal));
trace1(0, ESPI, 0, "VW IntrDis for VW[%d]",
- (signal - VW_SIGNAL_BASE));
+ (signal - VW_SIGNAL_START));
#endif
ridx = vw_info_tbl[tidx].reg_idx;
diff --git a/common/espi.c b/common/espi.c
index b496ca3cb6..0904f102d7 100644
--- a/common/espi.c
+++ b/common/espi.c
@@ -44,13 +44,8 @@ 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];
- }
+ if (espi_signal_is_vw(signal))
+ return espi_vw_names[signal - VW_SIGNAL_START];
return NULL;
}
@@ -58,10 +53,5 @@ const char *espi_vw_get_wire_name(enum espi_vw_signal signal)
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;
+ return ((signal >= VW_SIGNAL_START) && (signal < VW_SIGNAL_END));
}
diff --git a/common/ioexpander.c b/common/ioexpander.c
index 796673a668..6b54fd635e 100644
--- a/common/ioexpander.c
+++ b/common/ioexpander.c
@@ -29,10 +29,22 @@ static int last_val_changed(int i, int v)
}
}
+int signal_is_ioex(int signal)
+{
+ return ((signal >= IOEX_SIGNAL_START) && (signal < IOEX_SIGNAL_END));
+}
+
+static const struct ioex_info *ioex_get_signal_info(enum ioex_signal signal)
+{
+ ASSERT(signal_is_ioex(signal));
+
+ return ioex_list + signal - IOEX_SIGNAL_START;
+}
+
static int ioex_is_valid_interrupt_signal(enum ioex_signal signal)
{
const struct ioexpander_drv *drv;
- const struct ioex_info *g = ioex_list + signal;
+ const struct ioex_info *g = ioex_get_signal_info(signal);
/* Fail if no interrupt handler */
if (signal >= ioex_ih_count)
@@ -53,7 +65,7 @@ static int ioex_is_valid_interrupt_signal(enum ioex_signal signal)
int ioex_enable_interrupt(enum ioex_signal signal)
{
int rv;
- const struct ioex_info *g = ioex_list + signal;
+ const struct ioex_info *g = ioex_get_signal_info(signal);
const struct ioexpander_drv *drv;
rv = ioex_is_valid_interrupt_signal(signal);
@@ -68,7 +80,7 @@ int ioex_disable_interrupt(enum ioex_signal signal)
{
int rv;
const struct ioexpander_drv *drv;
- const struct ioex_info *g = ioex_list + signal;
+ const struct ioex_info *g = ioex_get_signal_info(signal);
rv = ioex_is_valid_interrupt_signal(signal);
if (rv != EC_SUCCESS)
@@ -92,7 +104,7 @@ int ioex_set_flags_by_mask(int ioex, int port, int mask, int flags)
int ioex_get_flags(enum ioex_signal signal, int *flags)
{
- const struct ioex_info *g = ioex_list + signal;
+ const struct ioex_info *g = ioex_get_signal_info(signal);
return ioex_config[g->ioex].drv->get_flags_by_mask(g->ioex,
g->port, g->mask, flags);
@@ -100,7 +112,7 @@ int ioex_get_flags(enum ioex_signal signal, int *flags)
int ioex_set_flags(enum ioex_signal signal, int flags)
{
- const struct ioex_info *g = ioex_list + signal;
+ const struct ioex_info *g = ioex_get_signal_info(signal);
return ioex_config[g->ioex].drv->set_flags_by_mask(g->ioex,
g->port, g->mask, flags);
@@ -108,7 +120,7 @@ int ioex_set_flags(enum ioex_signal signal, int flags)
int ioex_get_level(enum ioex_signal signal, int *val)
{
- const struct ioex_info *g = ioex_list + signal;
+ const struct ioex_info *g = ioex_get_signal_info(signal);
return ioex_config[g->ioex].drv->get_level(g->ioex, g->port,
g->mask, val);
@@ -116,7 +128,7 @@ int ioex_get_level(enum ioex_signal signal, int *val)
int ioex_set_level(enum ioex_signal signal, int value)
{
- const struct ioex_info *g = ioex_list + signal;
+ const struct ioex_info *g = ioex_get_signal_info(signal);
return ioex_config[g->ioex].drv->set_level(g->ioex, g->port,
g->mask, value);
@@ -155,7 +167,9 @@ DECLARE_HOOK(HOOK_INIT, ioex_init_default, HOOK_PRIO_INIT_I2C + 1);
const char *ioex_get_name(enum ioex_signal signal)
{
- return ioex_list[signal].name;
+ const struct ioex_info *g = ioex_get_signal_info(signal);
+
+ return g->name;
}
static void print_ioex_info(int io)
@@ -191,7 +205,9 @@ static void print_ioex_info(int io)
int ioex_get_default_flags(enum ioex_signal signal)
{
- return ioex_list[signal].flags;
+ const struct ioex_info *g = ioex_get_signal_info(signal);
+
+ return g->flags;
}
/* IO expander commands */
@@ -200,21 +216,21 @@ static enum ioex_signal find_ioex_by_name(const char *name)
int i;
if (!name)
- return IOEX_COUNT;
+ return -1;
- for (i = 0; i < IOEX_COUNT; i++) {
+ for (i = IOEX_SIGNAL_START; i < IOEX_SIGNAL_END; i++) {
if (!strcasecmp(name, ioex_get_name(i)))
return i;
}
- return IOEX_COUNT;
+ return -1;
}
static enum ec_error_list ioex_set(const char *name, int value)
{
enum ioex_signal signal = find_ioex_by_name(name);
- if (signal == IOEX_COUNT)
+ if (signal == -1)
return EC_ERROR_INVAL;
if (!(ioex_get_default_flags(signal) & GPIO_OUTPUT))
@@ -251,7 +267,7 @@ static int command_ioex_get(int argc, char **argv)
/* If a signal is specified, print only that one */
if (argc == 2) {
i = find_ioex_by_name(argv[1]);
- if (i == IOEX_COUNT)
+ if (i == -1)
return EC_ERROR_PARAM1;
print_ioex_info(i);
@@ -259,7 +275,7 @@ static int command_ioex_get(int argc, char **argv)
}
/* Otherwise print them all */
- for (i = 0; i < IOEX_COUNT; i++)
+ for (i = IOEX_SIGNAL_START; i < IOEX_SIGNAL_END; i++)
print_ioex_info(i);
return EC_SUCCESS;
diff --git a/include/espi.h b/include/espi.h
index 2795f9aacb..6d4de73330 100644
--- a/include/espi.h
+++ b/include/espi.h
@@ -12,8 +12,9 @@
/* Signal through VW */
enum espi_vw_signal {
- VW_SIGNAL_BASE = GPIO_COUNT,
- VW_SLP_S3_L, /* index 02h (In) */
+ /* The first valid VW signal is 0x2000 */
+ VW_SIGNAL_START = IOEX_LIMIT + 1,
+ VW_SLP_S3_L = VW_SIGNAL_START, /* index 02h (In) */
VW_SLP_S4_L,
VW_SLP_S5_L,
VW_SUS_STAT_L, /* index 03h (In) */
@@ -37,10 +38,12 @@ enum espi_vw_signal {
VW_SLP_A_L,
VW_SLP_LAN, /* index 42h (In) */
VW_SLP_WLAN,
- VW_SIGNAL_BASE_END,
+ VW_SIGNAL_END,
+ VW_LIMIT = 0x2FFF
};
+BUILD_ASSERT(VW_SIGNAL_END < VW_LIMIT);
-#define VW_SIGNAL_COUNT (VW_SIGNAL_BASE_END - VW_SIGNAL_BASE - 1)
+#define VW_SIGNAL_COUNT (VW_SIGNAL_END - VW_SIGNAL_START)
/**
* Set eSPI Virtual-Wire signal to Host
diff --git a/include/gpio_signal.h b/include/gpio_signal.h
index e863b7c415..478e83dca5 100644
--- a/include/gpio_signal.h
+++ b/include/gpio_signal.h
@@ -6,21 +6,44 @@
#ifndef __CROS_EC_GPIO_SIGNAL_H
#define __CROS_EC_GPIO_SIGNAL_H
+#include "compile_time_macros.h"
+
+/*
+ * There are 3 different IO signal types used by the EC.
+ * Ensure they each use a unique range of values so we can tell them apart.
+ * 1) Local GPIO => 0 to 0x0FFF
+ * 2) IO expander GPIO => 0x1000 to 0x1FFF
+ * 3) eSPI virtual wire signals (defined in include/espi.h) => 0x2000 to 0x2FFF
+ */
+
#define GPIO(name, pin, flags) GPIO_##name,
#define UNIMPLEMENTED(name) GPIO_##name,
#define GPIO_INT(name, pin, flags, signal) GPIO_##name,
+#define GPIO_SIGNAL_START 0 /* The first valid GPIO signal is 0 */
+
enum gpio_signal {
#include "gpio.wrap"
- GPIO_COUNT
+ GPIO_COUNT,
+ /* Ensure that sizeof gpio_signal is large enough for ioex_signal */
+ GPIO_LIMIT = 0x0FFF
};
+BUILD_ASSERT(GPIO_COUNT < GPIO_LIMIT);
#define IOEX(name, expin, flags) IOEX_##name,
#define IOEX_INT(name, expin, flags, signal) IOEX_##name,
enum ioex_signal {
+ /* The first valid IOEX signal is 0x1000 */
+ IOEX_SIGNAL_START = GPIO_LIMIT + 1,
+ /* Used to ensure that the first IOEX signal is same as start */
+ __IOEX_PLACEHOLDER = GPIO_LIMIT,
#include "gpio.wrap"
- IOEX_COUNT
+ IOEX_SIGNAL_END,
+ IOEX_LIMIT = 0x1FFF
};
+BUILD_ASSERT(IOEX_SIGNAL_END < IOEX_LIMIT);
+
+#define IOEX_COUNT (IOEX_SIGNAL_END - IOEX_SIGNAL_START)
#endif /* __CROS_EC_GPIO_SIGNAL_H */
diff --git a/include/ioexpander.h b/include/ioexpander.h
index 150db65750..206b0a390c 100644
--- a/include/ioexpander.h
+++ b/include/ioexpander.h
@@ -148,5 +148,13 @@ int ioex_init(int ioex);
* @returns name of the given IOEX signal
*/
const char *ioex_get_name(enum ioex_signal signal);
-#endif /* __CROS_EC_IOEXPANDER_H */
+/*
+ * Check if signal is an IO expander signal or GPIO signal.
+ *
+ * @param signal GPIO or IOEX signal
+ * @return 1 if signal is IOEX else return 0
+ */
+int signal_is_ioex(int signal);
+
+#endif /* __CROS_EC_IOEXPANDER_H */