diff options
author | Hyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com> | 2021-01-19 23:17:30 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-26 19:48:44 +0000 |
commit | 8ba2a0dd442aff3dd8cdd486d5c86b15108c1b90 (patch) | |
tree | 4438f9939fe8d369c15e682200b6b240a212fbaf /zephyr | |
parent | 1e14f4669113703fb496406e6a58602bc17a4001 (diff) | |
download | chrome-ec-8ba2a0dd442aff3dd8cdd486d5c86b15108c1b90.tar.gz |
zephyr: add MKBP support
Add MKBP support to zephyr.
BUG=b:173507858
BRANCH=none
TEST=make buildall -j8
build volteer on zephyr
Signed-off-by: Hyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com>
Change-Id: I9b7d979241b0df5dc0fa5d9741f05dc9875189ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2639854
Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/CMakeLists.txt | 2 | ||||
-rw-r--r-- | zephyr/Kconfig | 55 | ||||
-rw-r--r-- | zephyr/shim/include/config_chip.h | 18 | ||||
-rw-r--r-- | zephyr/shim/include/zephyr_mkbp_event.h | 48 | ||||
-rw-r--r-- | zephyr/shim/src/CMakeLists.txt | 17 | ||||
-rw-r--r-- | zephyr/shim/src/mkbp_event.c | 31 |
6 files changed, 163 insertions, 8 deletions
diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index e94af76986..3842220085 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -134,6 +134,8 @@ zephyr_sources_ifdef(CONFIG_PLATFORM_EC_LID_SWITCH "${PLATFORM_EC}/common/lid_switch.c") zephyr_sources_ifdef(CONFIG_PLATFORM_EC_MOTIONSENSE "${PLATFORM_EC}/common/motion_sense.c") +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_MKBP_EVENT + "${PLATFORM_EC}/common/mkbp_event.c") zephyr_sources_ifdef(CONFIG_PLATFORM_EC_PORT80 "${PLATFORM_EC}/common/port80.c") zephyr_sources_ifdef(CONFIG_PLATFORM_EC_POWER_BUTTON "${PLATFORM_EC}/common/power_button.c") diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 55f3b74c12..4be595f343 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -306,6 +306,61 @@ config PLATFORM_EC_LID_SWITCH This requires a GPIO named GPIO_LID_OPEN to be defined in gpio_map.h. +config PLATFORM_EC_MKBP_EVENT + bool "MKBP event" + help + Enable this to support MKBP event. MKBP event is used not only + for matrix keyboard but also for other many events like button, + switch, fingerprint, and etc. + + This requires a MKBP event delivery method(GPIO, HOST_EVENT, and etc) + +if PLATFORM_EC_MKBP_EVENT + +choice + prompt "MKBP delivery method" + default PLATFORM_EC_MKBP_USE_GPIO + help + Select MKBP delivery method + +config PLATFORM_EC_MKBP_USE_GPIO + bool "Use GPIO" + help + Select to send MKBP events via GPIO. You should define GPIO_EC_INT_L + in gpio_map.h as output from the EC. The GPIO is used to indicate an + event is ready for serving by the AP. + +config PLATFORM_EC_MKBP_USE_HOST_EVENT + bool "Use host event" + help + Select to send MKBP events via host event. + +config PLATFORM_EC_MKBP_USE_GPIO_AND_HOST_EVENT + bool "Use GPIO and host event" + help + MKBP events are notified by using both a GPIO and a host event. + + You should use this if you are using a GPIO to notify the AP of an MKBP + event, and you need an MKBP event to wake the AP in suspend and the + AP cannot wake from the GPIO. Since you are using both a GPIO and + a hostevent for the notification, make sure that the S0 hostevent mask + does NOT include MKBP events. Otherwise, you will have multiple + consumers for a single event. However, make sure to configure the + host event *sleep* mask in coreboot to include MKBP events. In order to + prevent all MKBP events from waking the AP, use + CONFIG_MKBP_EVENT_WAKEUP_MASK to filter the events. + +config PLATFORM_EC_MKBP_USE_CUSTOM + bool "Use custom method" + help + Select to send MKBP events using custom method. You need to define + mkbp_set_host_active_via_custom() which is called when there's a MKBP event + to be sent. for more about the function, refer to mkbp_event.h. + +endchoice + +endif # PLATFORM_EC_MKBP_EVENT + config PLATFORM_EC_PORT80 bool "Port 80 support" default y if AP_X86 && PLATFORM_EC_POWERSEQ diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h index 5b36508627..73a41547e2 100644 --- a/zephyr/shim/include/config_chip.h +++ b/zephyr/shim/include/config_chip.h @@ -552,6 +552,24 @@ enum battery_type { #define CONFIG_HAS_TASK_PD_INT #endif +#undef CONFIG_MKBP_EVENT +#undef CONFIG_MKBP_USE_GPIO +#undef CONFIG_MKBP_USE_HOST_EVENT +#undef CONFIG_MKBP_USE_GPIO_AND_HOST_EVENT +#undef CONFIG_MKBP_USE_CUSTOM +#ifdef CONFIG_PLATFORM_EC_MKBP_EVENT +#define CONFIG_MKBP_EVENT +#ifdef CONFIG_PLATFORM_EC_MKBP_USE_GPIO +#define CONFIG_MKBP_USE_GPIO +#elif PLATFORM_EC_MKBP_USE_HOST_EVENT +#define CONFIG_MKBP_USE_HOST_EVENT +#elif PLATFORM_EC_MKBP_USE_GPIO_AND_HOST_EVENT +#define CONFIG_MKBP_USE_GPIO_AND_HOST_EVENT +#elif PLATFORM_EC_MKBP_USE_CUSTOM +#define CONFIG_MKBP_USE_CUSTOM +#endif +#endif /* CONFIG_PLATFORM_EC_MKBP_EVENT */ + #undef CONFIG_USB_PD_TCPC_LOW_POWER #undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE #ifdef CONFIG_PLATFORM_EC_USB_PD_TCPC_LOW_POWER diff --git a/zephyr/shim/include/zephyr_mkbp_event.h b/zephyr/shim/include/zephyr_mkbp_event.h new file mode 100644 index 0000000000..b37ce0d5d3 --- /dev/null +++ b/zephyr/shim/include/zephyr_mkbp_event.h @@ -0,0 +1,48 @@ +/* Copyright 2021 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. + */ + +#if !defined(__CROS_EC_MKBP_EVENT_H) || \ + defined(__CROS_EC_ZEPHYR_MKBP_EVENT_H) +#error "This file must only be included from mkbp_event.h. " \ + "Include mkbp_event.h directly" +#endif +#define __CROS_EC_ZEPHYR_MKBP_EVENT_H + +/** Node in a list of mkbp event handlers */ +struct zshim_mkbp_event_node { + struct mkbp_event_source evtsrc; + struct zshim_mkbp_event_node *next; +}; + +/** + * Runtime helper for DECLARE_EVENT_SOURCE setup data. + * + * @param event_type event type (EC_MKBP_EVENT_...) + * @param get_data event handler for the event type + * @param entry pointer to statically allocated zshim_mkbp_event_node + item + */ +void zshim_setup_mkbp_event(uint8_t event_type, int (*get_data)(uint8_t *data), + struct zshim_mkbp_event_node *entry); + +const struct mkbp_event_source *zephyr_find_mkbp_event_source( + uint8_t event_type); + +/** + * See include/mkbp_event.h for documentation. + */ +#define DECLARE_EVENT_SOURCE(type, func) \ + _DECLARE_EVENT_SOURCE_1(type, func, __LINE__) +#define _DECLARE_EVENT_SOURCE_1(type, func, line) \ + _DECLARE_EVENT_SOURCE_2(type, func, line) +#define _DECLARE_EVENT_SOURCE_2(type, func, line) \ + static int _setup_mkbp_event_##line(const struct device *unused) \ + { \ + ARG_UNUSED(unused); \ + static struct zshim_mkbp_event_node mkbp_event; \ + zshim_setup_mkbp_event(type, func, &mkbp_event); \ + return 0; \ + } \ + SYS_INIT(_setup_mkbp_event_##line, APPLICATION, 1) diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt index be283829cc..03ff31eb8c 100644 --- a/zephyr/shim/src/CMakeLists.txt +++ b/zephyr/shim/src/CMakeLists.txt @@ -9,11 +9,12 @@ zephyr_sources(crc.c) zephyr_sources_ifdef(no_libgcc libgcc_${ARCH}.S) -zephyr_sources_ifdef(CONFIG_PLATFORM_EC_ESPI espi.c) -zephyr_sources_ifdef(CONFIG_PLATFORM_EC_FLASH flash.c) -zephyr_sources_ifdef(CONFIG_PLATFORM_EC_HOOKS hooks.c) -zephyr_sources_ifdef(CONFIG_PLATFORM_EC_HOSTCMD host_command.c) -zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TIMER hwtimer.c) -zephyr_sources_ifdef(CONFIG_PLATFORM_EC_I2C i2c.c) -zephyr_sources_ifdef(CONFIG_CROS_EC system.c) -zephyr_sources_ifdef(CONFIG_SHIMMED_TASKS tasks.c) +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_ESPI espi.c) +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_FLASH flash.c) +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_HOOKS hooks.c) +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_HOSTCMD host_command.c) +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_MKBP_EVENT mkbp_event.c) +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TIMER hwtimer.c) +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_I2C i2c.c) +zephyr_sources_ifdef(CONFIG_CROS_EC system.c) +zephyr_sources_ifdef(CONFIG_SHIMMED_TASKS tasks.c) diff --git a/zephyr/shim/src/mkbp_event.c b/zephyr/shim/src/mkbp_event.c new file mode 100644 index 0000000000..fec6ef3ab3 --- /dev/null +++ b/zephyr/shim/src/mkbp_event.c @@ -0,0 +1,31 @@ +/* Copyright 2021 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. + */ + +#include "mkbp_event.h" + +static struct zshim_mkbp_event_node *mkbp_event_head; + +void zshim_setup_mkbp_event(uint8_t event_type, int (*get_data)(uint8_t *data), + struct zshim_mkbp_event_node *entry) +{ + + entry->evtsrc.event_type = event_type; + entry->evtsrc.get_data = get_data; + entry->next = mkbp_event_head; + + mkbp_event_head = entry; +} + +const struct mkbp_event_source *zephyr_find_mkbp_event_source(uint8_t type) +{ + struct zshim_mkbp_event_node *p; + + for (p = mkbp_event_head; p != NULL; p = p->next) { + if (p->evtsrc.event_type == type) + return &p->evtsrc; + } + + return NULL; +} |