backlight: Adding support for active low GPIO signal

BUG=b:72007261
BRANCH=none
TEST=Verified with grunt board (with is active low)

Change-Id: I9a58148b8d92065bec982071ed1d97a466197e9a
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/872233
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Edward Hill <ecgh@chromium.org>
This commit is contained in:
Jett Rink
2018-01-17 16:53:59 -08:00
committed by chrome-bot
parent 289347ad6a
commit d52ba1a4d4
3 changed files with 31 additions and 4 deletions

View File

@@ -11,6 +11,19 @@
#include "host_command.h"
#include "lid_switch.h"
/**
* Activate/Deactivate the backlight GPIO pin considering active high or low.
*/
void enable_backlight(int enabled)
{
#ifdef CONFIG_BACKLIGHT_LID_ACTIVE_LOW
gpio_set_level(GPIO_ENABLE_BACKLIGHT_L, !enabled);
#else
gpio_set_level(GPIO_ENABLE_BACKLIGHT, enabled);
#endif
}
/**
* Update backlight state.
*/
@@ -18,14 +31,14 @@ static void update_backlight(void)
{
#ifdef CONFIG_BACKLIGHT_REQ_GPIO
/* Enable the backlight if lid is open AND requested by AP */
gpio_set_level(GPIO_ENABLE_BACKLIGHT, lid_is_open() &&
gpio_get_level(CONFIG_BACKLIGHT_REQ_GPIO));
enable_backlight(lid_is_open() &&
gpio_get_level(CONFIG_BACKLIGHT_REQ_GPIO));
#else
/*
* Enable backlight if lid is open; this is AND'd with the request from
* the AP in hardware.
*/
gpio_set_level(GPIO_ENABLE_BACKLIGHT, lid_is_open());
enable_backlight(lid_is_open());
#endif
}
DECLARE_HOOK(HOOK_LID_CHANGE, update_backlight, HOOK_PRIO_DEFAULT);
@@ -60,7 +73,7 @@ static int switch_command_enable_backlight(struct host_cmd_handler_args *args)
{
const struct ec_params_switch_enable_backlight *p = args->params;
gpio_set_level(GPIO_ENABLE_BACKLIGHT, p->enabled);
enable_backlight(p->enabled);
return EC_RES_SUCCESS;
}

View File

@@ -22,4 +22,9 @@ void backlight_interrupt(enum gpio_signal signal);
static inline void backlight_interrupt(enum gpio_signal signal) { }
#endif /* !CONFIG_BACKLIGHT_REQ_GPIO */
/**
* Activate/Deactivate the backlight GPIO pin considering active high or low.
*/
void enable_backlight(int enabled);
#endif /* __CROS_EC_BACKLIGHT_H */

View File

@@ -189,12 +189,21 @@
/* Allow proprietary communication protocols' extensions. */
#undef CONFIG_EXTENSION_COMMAND
/*
* Support controlling the display backlight based on the state of the lid
* switch. The EC will disable the backlight when the lid is closed.
*
* The GPIO should be named GPIO_BACKLIGHT_ENABLED if active high, or
* GPIO_BACKLIGHT_ENABLED_L if active low. See CONFIG_BACKLIGHT_LID_ACTIVE_LOW.
*/
#undef CONFIG_BACKLIGHT_LID
/*
* The backlight GPIO pin is active low and named GPIO_BACKLIGHT_ENABLED_L
*/
#undef CONFIG_BACKLIGHT_LID_ACTIVE_LOW
/*
* If defined, EC will enable the backlight signal only if this GPIO is
* asserted AND the lid is open. This supports passing the backlight-enable