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