From a834638b29823e7eeeb98a7a85675d7253f938b4 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Thu, 23 Jul 2015 11:11:25 -0700 Subject: [PATCH] lid_switch: allow to specify several lid GPIOs Add a X-macro CONFIG_LID_SWITCH_GPIO_LIST to be able to optionally specify more than one GPIO to check to find out whether the lid is open. By default, use GPIO_LID_OPEN as before. Signed-off-by: Vincent Palatin BRANCH=smaug BUG=chrome-os-partner:42110 TEST=on Smaug EVT2, define CONFIG_LID_SWITCH_GPIO_LIST as LID_GPIO(GPIO_LID_OPEN) LID_GPIO(GPIO_BASE_PRES_L) and play with magnets and the genuine lid, check we get the right "lid open" / "lid close" messages on the console. Change-Id: I9e7c67bb39f36f254d31d5861d535d69db754faa Reviewed-on: https://chromium-review.googlesource.com/287852 Trybot-Ready: Vincent Palatin Tested-by: Vincent Palatin Reviewed-by: Alec Berg Commit-Queue: Vincent Palatin --- common/lid_switch.c | 13 +++++++++++-- include/config.h | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/common/lid_switch.c b/common/lid_switch.c index 8671368631..eefd2bdfa1 100644 --- a/common/lid_switch.c +++ b/common/lid_switch.c @@ -20,6 +20,11 @@ #define LID_DEBOUNCE_US (30 * MSEC) /* Debounce time for lid switch */ +/* if no X-macro is defined for LID switch GPIO, use GPIO_LID_OPEN as default */ +#ifndef CONFIG_LID_SWITCH_GPIO_LIST +#define CONFIG_LID_SWITCH_GPIO_LIST LID_GPIO(GPIO_LID_OPEN) +#endif + static int debounced_lid_open; /* Debounced lid state */ static int forced_lid_open; /* Forced lid open */ @@ -30,7 +35,9 @@ static int forced_lid_open; /* Forced lid open */ */ static int raw_lid_open(void) { - return (forced_lid_open || gpio_get_level(GPIO_LID_OPEN)) ? 1 : 0; +#define LID_GPIO(gpio) || gpio_get_level(gpio) + return (forced_lid_open CONFIG_LID_SWITCH_GPIO_LIST) ? 1 : 0; +#undef LID_GPIO } /** @@ -79,7 +86,9 @@ static void lid_init(void) debounced_lid_open = 1; /* Enable interrupts, now that we've initialized */ - gpio_enable_interrupt(GPIO_LID_OPEN); +#define LID_GPIO(gpio) gpio_enable_interrupt(gpio); + CONFIG_LID_SWITCH_GPIO_LIST +#undef LID_GPIO } DECLARE_HOOK(HOOK_INIT, lid_init, HOOK_PRIO_INIT_LID); diff --git a/include/config.h b/include/config.h index 32f1a983f7..8cd6e5a19b 100644 --- a/include/config.h +++ b/include/config.h @@ -1077,6 +1077,15 @@ */ #define CONFIG_LID_SWITCH +/* + * GPIOs to use to detect that the lid is opened. + * + * This is a X-macro composed of a list of LID_OPEN(GPIO_xxx) elements defining + * all the GPIOs to check to find whether the lid is currently opened. + * If not defined, it is using GPIO_LID_OPEN. + */ +#undef CONFIG_LID_SWITCH_GPIO_LIST + /* * Support for turning the lightbar power rails on briefly when the AP is off. * Enabling this requires implementing the board-specific lb_power() function