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 <vpalatin@chromium.org>

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 <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Vincent Palatin
2015-07-23 11:11:25 -07:00
committed by ChromeOS Commit Bot
parent bcb8e11c63
commit a834638b29
2 changed files with 20 additions and 2 deletions

View File

@@ -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);

View File

@@ -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