summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/bolt/board.h3
-rw-r--r--board/link/board.h3
-rw-r--r--board/peppy/board.h3
-rw-r--r--board/rambi/board.h2
-rw-r--r--board/slippy/board.h3
-rw-r--r--common/backlight_lid.c (renamed from common/backlight_x86.c)29
-rw-r--r--common/build.mk2
-rw-r--r--include/backlight.h2
-rw-r--r--include/config.h15
-rw-r--r--test/bklight_lid.c106
-rw-r--r--test/bklight_lid.tasklist (renamed from test/bklight_x86.tasklist)0
-rw-r--r--test/bklight_passthru.c (renamed from test/bklight_x86.c)0
-rw-r--r--test/bklight_passthru.tasklist17
-rw-r--r--test/build.mk5
-rw-r--r--test/test_config.h9
15 files changed, 177 insertions, 22 deletions
diff --git a/board/bolt/board.h b/board/bolt/board.h
index b74424d474..3f6f8b4891 100644
--- a/board/bolt/board.h
+++ b/board/bolt/board.h
@@ -29,7 +29,8 @@
#define CONFIG_BATTERY_LINK
#define CONFIG_BATTERY_SMART
-#define CONFIG_BACKLIGHT_X86
+#define CONFIG_BACKLIGHT_LID
+#define CONFIG_BACKLIGHT_REQ_GPIO GPIO_PCH_BKLTEN
#define CONFIG_CHARGER
#define CONFIG_CHARGER_BQ24715
/* 10mOhm sense resitors. */
diff --git a/board/link/board.h b/board/link/board.h
index f011003c22..3ff1749c41 100644
--- a/board/link/board.h
+++ b/board/link/board.h
@@ -9,7 +9,8 @@
#define __BOARD_H
/* Optional features */
-#define CONFIG_BACKLIGHT_X86
+#define CONFIG_BACKLIGHT_LID
+#define CONFIG_BACKLIGHT_REQ_GPIO GPIO_PCH_BKLTEN
#define CONFIG_BATTERY_LINK
#define CONFIG_BATTERY_SMART
#define CONFIG_BATTERY_VENDOR_PARAMS
diff --git a/board/peppy/board.h b/board/peppy/board.h
index f98eab08ac..46d110d642 100644
--- a/board/peppy/board.h
+++ b/board/peppy/board.h
@@ -9,7 +9,8 @@
#define __BOARD_H
/* Optional features */
-#define CONFIG_BACKLIGHT_X86
+#define CONFIG_BACKLIGHT_LID
+#define CONFIG_BACKLIGHT_REQ_GPIO GPIO_PCH_BKLTEN
#define CONFIG_BATTERY_CHECK_CONNECTED
#define CONFIG_BATTERY_SMART
#define CONFIG_BOARD_VERSION
diff --git a/board/rambi/board.h b/board/rambi/board.h
index 8c8ca0e684..9792d31e51 100644
--- a/board/rambi/board.h
+++ b/board/rambi/board.h
@@ -9,6 +9,7 @@
#define __BOARD_H
/* Optional features */
+#define CONFIG_BACKLIGHT_LID
#define CONFIG_BOARD_VERSION
#define CONFIG_CMD_GSV
#define CONFIG_EXTPOWER_GPIO
@@ -23,7 +24,6 @@
/* TODO(rspangler): port these to Rambi, or remove if not needed */
#if 0
-#define CONFIG_BACKLIGHT_X86
#define CONFIG_BATTERY_CHECK_CONNECTED
#define CONFIG_BATTERY_SMART
#define CONFIG_CHARGER
diff --git a/board/slippy/board.h b/board/slippy/board.h
index 648f09a960..e56702adfe 100644
--- a/board/slippy/board.h
+++ b/board/slippy/board.h
@@ -9,7 +9,8 @@
#define __BOARD_H
/* Optional features */
-#define CONFIG_BACKLIGHT_X86
+#define CONFIG_BACKLIGHT_LID
+#define CONFIG_BACKLIGHT_REQ_GPIO GPIO_PCH_BKLTEN
#define CONFIG_BATTERY_CHECK_CONNECTED
#define CONFIG_BATTERY_SMART
#define CONFIG_BOARD_VERSION
diff --git a/common/backlight_x86.c b/common/backlight_lid.c
index 9c3b4d0ae3..30b8b75eb7 100644
--- a/common/backlight_x86.c
+++ b/common/backlight_lid.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* Backlight passthru for x86 platforms */
+/* Backlight control based on lid and optional request signal from AP */
#include "common.h"
#include "gpio.h"
@@ -16,11 +16,17 @@
*/
static void update_backlight(void)
{
- /* Only enable the backlight if the lid is open */
- if (gpio_get_level(GPIO_PCH_BKLTEN) && lid_is_open())
- gpio_set_level(GPIO_ENABLE_BACKLIGHT, 1);
- else
- gpio_set_level(GPIO_ENABLE_BACKLIGHT, 0);
+#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));
+#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());
+#endif
}
DECLARE_HOOK(HOOK_LID_CHANGE, update_backlight, HOOK_PRIO_DEFAULT);
@@ -31,22 +37,31 @@ static void backlight_init(void)
{
update_backlight();
- gpio_enable_interrupt(GPIO_PCH_BKLTEN);
+#ifdef CONFIG_BACKLIGHT_REQ_GPIO
+ gpio_enable_interrupt(CONFIG_BACKLIGHT_REQ_GPIO);
+#endif
}
DECLARE_HOOK(HOOK_INIT, backlight_init, HOOK_PRIO_DEFAULT);
+#ifdef CONFIG_BACKLIGHT_REQ_GPIO
void backlight_interrupt(enum gpio_signal signal)
{
update_backlight();
}
+#endif
/**
* Host command to toggle backlight.
+ *
+ * The requested state will persist until the next lid-switch or request-gpio
+ * transition.
*/
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);
+
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_SWITCH_ENABLE_BKLIGHT,
diff --git a/common/build.mk b/common/build.mk
index 39c38d00c9..0ab2658c07 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -18,7 +18,7 @@ common-$(BOARD_peppy)+=led_common.o led_peppy.o
common-$(BOARD_slippy)+=led_slippy.o
common-$(BOARD_snow)+=extpower_snow.o
-common-$(CONFIG_BACKLIGHT_X86)+=backlight_x86.o
+common-$(CONFIG_BACKLIGHT_LID)+=backlight_lid.o
common-$(CONFIG_BATTERY_BQ20Z453)+=battery_bq20z453.o
common-$(CONFIG_BATTERY_BQ27541)+=battery.o battery_bq27541.o
common-$(CONFIG_BATTERY_LINK)+=battery_link.o
diff --git a/include/backlight.h b/include/backlight.h
index 7fbdcfb34a..be905d0f47 100644
--- a/include/backlight.h
+++ b/include/backlight.h
@@ -15,7 +15,7 @@
*
* @param signal Signal which triggered the interrupt.
*/
-#ifdef CONFIG_BACKLIGHT_X86
+#ifdef CONFIG_BACKLIGHT_REQ_GPIO
void backlight_interrupt(enum gpio_signal signal);
#else
#define backlight_interrupt NULL
diff --git a/include/config.h b/include/config.h
index a3f67c06c7..1e1568ca6b 100644
--- a/include/config.h
+++ b/include/config.h
@@ -46,11 +46,18 @@
#undef CONFIG_ADC_CLOCK
/*
- * Compile support for passing backlight-enable signal from x86 chipset through
- * EC. This allows the EC to gate the backlight-enable signal with the lid
- * switch.
+ * Compile support for controlling the display backlight based on the state of
+ * the lid switch. The EC will disable the backlight when the lid is
+ * closed.
*/
-#undef CONFIG_BACKLIGHT_X86
+#undef CONFIG_BACKLIGHT_LID
+
+/*
+ * 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
+ * signal from the AP through EC.
+ */
+#undef CONFIG_BACKLIGHT_REQ_GPIO
/*****************************************************************************/
/* Battery config */
diff --git a/test/bklight_lid.c b/test/bklight_lid.c
new file mode 100644
index 0000000000..9cdd3741a2
--- /dev/null
+++ b/test/bklight_lid.c
@@ -0,0 +1,106 @@
+/* Copyright (c) 2013 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.
+ *
+ * Test backlight control based on lid
+ */
+
+#include "backlight.h"
+#include "common.h"
+#include "console.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "lid_switch.h"
+#include "test_util.h"
+#include "timer.h"
+#include "util.h"
+
+static int mock_lid = 1;
+static int backlight_en;
+
+int gpio_get_level(enum gpio_signal signal)
+{
+ if (signal == GPIO_LID_OPEN)
+ return mock_lid;
+ return 0;
+}
+
+void gpio_set_level(enum gpio_signal signal, int level)
+{
+ if (signal == GPIO_ENABLE_BACKLIGHT)
+ backlight_en = level;
+}
+
+void set_lid_state(int is_open)
+{
+ mock_lid = is_open;
+ lid_interrupt(GPIO_LID_OPEN);
+ msleep(40);
+}
+
+static int send_bklight_hostcmd(int enabled)
+{
+ struct ec_params_switch_enable_backlight p;
+ p.enabled = enabled;
+
+ return test_send_host_command(EC_CMD_SWITCH_ENABLE_BKLIGHT, 0, &p,
+ sizeof(p), NULL, 0);
+}
+
+static int test_passthrough(void)
+{
+ /* Initial state */
+ TEST_ASSERT(mock_lid == 1);
+ TEST_ASSERT(backlight_en);
+
+ /* Close lid. Backlight should turn off */
+ set_lid_state(0);
+ TEST_ASSERT(!backlight_en);
+
+ /* Open lid. Backlight turns on */
+ set_lid_state(1);
+ TEST_ASSERT(backlight_en);
+
+ return EC_SUCCESS;
+}
+
+static int test_hostcommand(void)
+{
+ /* Open lid */
+ set_lid_state(1);
+ TEST_ASSERT(backlight_en);
+
+ /* Disable by host command */
+ send_bklight_hostcmd(0);
+ TEST_ASSERT(!backlight_en);
+
+ /* Close and open lid. Backlight should come up */
+ set_lid_state(0);
+ set_lid_state(1);
+ TEST_ASSERT(backlight_en);
+
+ /* Close lid */
+ set_lid_state(0);
+ TEST_ASSERT(!backlight_en);
+
+ /* Enable by host command */
+ send_bklight_hostcmd(1);
+ TEST_ASSERT(backlight_en);
+
+ /* Disable backlight by lid */
+ set_lid_state(1);
+ set_lid_state(0);
+ TEST_ASSERT(!backlight_en);
+
+ return EC_SUCCESS;
+}
+
+void run_test(void)
+{
+ test_reset();
+
+ RUN_TEST(test_passthrough);
+ RUN_TEST(test_hostcommand);
+
+ test_print_result();
+}
diff --git a/test/bklight_x86.tasklist b/test/bklight_lid.tasklist
index 26cfc53453..26cfc53453 100644
--- a/test/bklight_x86.tasklist
+++ b/test/bklight_lid.tasklist
diff --git a/test/bklight_x86.c b/test/bklight_passthru.c
index cf533912ae..cf533912ae 100644
--- a/test/bklight_x86.c
+++ b/test/bklight_passthru.c
diff --git a/test/bklight_passthru.tasklist b/test/bklight_passthru.tasklist
new file mode 100644
index 0000000000..26cfc53453
--- /dev/null
+++ b/test/bklight_passthru.tasklist
@@ -0,0 +1,17 @@
+/* Copyright (c) 2013 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.
+ */
+
+/**
+ * List of enabled tasks in the priority order
+ *
+ * The first one has the lowest priority.
+ *
+ * For each task, use the macro TASK_TEST(n, r, d, s) where :
+ * 'n' in the name of the task
+ * 'r' in the main routine of the task
+ * 'd' in an opaque parameter passed to the routine at startup
+ * 's' is the stack size in bytes; must be a multiple of 8
+ */
+#define CONFIG_TEST_TASK_LIST /* No test task */
diff --git a/test/build.mk b/test/build.mk
index af3807a84a..1271511129 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -30,10 +30,11 @@ test-list-$(BOARD_bolt)=
test-list-host=mutex pingpong utils kb_scan kb_mkbp lid_sw power_button hooks
test-list-host+=thermal flash queue kb_8042 extpwr_gpio console_edit system
test-list-host+=sbs_charging adapter host_command thermal_falco led_lp5562
-test-list-host+=bklight_x86
+test-list-host+=bklight_lid bklight_passthru
adapter-y=adapter.o
-bklight_x86-y=bklight_x86.o
+bklight_lid-y=bklight_lid.o
+bklight_passthru-y=bklight_passthru.o
console_edit-y=console_edit.o
extpwr_gpio-y=extpwr_gpio.o
flash-y=flash.o
diff --git a/test/test_config.h b/test/test_config.h
index bf47205d9b..3c8f35b75d 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -13,8 +13,13 @@
#define CONFIG_EXTPOWER_FALCO
#endif
-#ifdef TEST_bklight_x86
-#define CONFIG_BACKLIGHT_X86
+#ifdef TEST_bklight_lid
+#define CONFIG_BACKLIGHT_LID
+#endif
+
+#ifdef TEST_bklight_passthru
+#define CONFIG_BACKLIGHT_LID
+#define CONFIG_BACKLIGHT_REQ_GPIO GPIO_PCH_BKLTEN
#endif
#ifdef TEST_kb_8042