summaryrefslogtreecommitdiff
path: root/common/rgb_keyboard.c
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2022-04-07 23:06:11 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-04-13 18:45:14 +0000
commitf4134044af7328f25b56aec0e2e12018d37b4bb7 (patch)
treedd45377376a05ba521ed7a6d66b707739423471e /common/rgb_keyboard.c
parent985fe9a5e746db7fc2f2ad11e13ce3a77e138a4b (diff)
downloadchrome-ec-f4134044af7328f25b56aec0e2e12018d37b4bb7.tar.gz
RGBKBD: Support backlight control via ACPI
This patch allows x86 boards to control the keyboard backlight via ACPI. BUG=b:228525798,b:226215987 BRANCH=None TEST=Taniks. Run 'rgbk all 0xff 0xff 0xff' on EC then press Alt+F6/F7. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Ic4b5599ac754c5c50e5f89b4dcb48c73677c57e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3582325 Reviewed-by: Parth Malkan <parthmalkan@google.com>
Diffstat (limited to 'common/rgb_keyboard.c')
-rw-r--r--common/rgb_keyboard.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/common/rgb_keyboard.c b/common/rgb_keyboard.c
index 0f66e6c242..c9987c5e5b 100644
--- a/common/rgb_keyboard.c
+++ b/common/rgb_keyboard.c
@@ -11,6 +11,7 @@
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
+#include "keyboard_backlight.h"
#include "registers.h"
#include "rgb_keyboard.h"
#include "task.h"
@@ -335,6 +336,40 @@ static int rgbkbd_enable(int enable)
return rv;
}
+static int rgbkbd_kblight_set(int percent)
+{
+ uint8_t gcc = DIV_ROUND_NEAREST(percent * RGBKBD_MAX_GCC_LEVEL, 100);
+ return rgbkbd_set_global_brightness(gcc);
+}
+
+static int rgbkbd_kblight_get(void)
+{
+ uint8_t gcc;
+
+ if (rgbkbd_get_global_brightness(&gcc))
+ return 0;
+
+ return DIV_ROUND_NEAREST(gcc * 100, RGBKBD_MAX_GCC_LEVEL);
+}
+
+static int rgbkbd_get_enabled(void)
+{
+ return rgbkbds[0].state >= RGBKBD_STATE_ENABLED;
+}
+
+const struct kblight_drv kblight_rgbkbd = {
+ .init = rgbkbd_init,
+ .set = rgbkbd_kblight_set,
+ .get = rgbkbd_kblight_get,
+ /*
+ * We need to let RGBKBD manage enable/disable the backlight to keep
+ * the LEDs under the control of RGBKBD. Registering NULL also avoids
+ * ASSERT(!in_interrupt_context()) failure in task.c called from
+ * rgbkbd_enable API.
+ */
+ .enable = NULL,
+ .get_enabled = rgbkbd_get_enabled,
+};
void rgbkbd_task(void *u)
{