summaryrefslogtreecommitdiff
path: root/common
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-12 19:40:10 +0000
commit36e6bbfe34443a3100e07db8479195cd9baa6d39 (patch)
tree9d738b71d07c037ab0ff2fda144f6e0756111087 /common
parentddfb436d7199bd186c2f806da5e83b1bf439672f (diff)
downloadchrome-ec-36e6bbfe34443a3100e07db8479195cd9baa6d39.tar.gz
RGBKBD: Separate init and enable
Currently, enable is included in init. This patch separates them so that an RGB unit can be enabled or disabled separately. BUG=b:228525798,b:226215987 BRANCH=None TEST=Taniks Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I6f4d3b64f35f0cd30b6b58944d377932bbf5ef2e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3582324 Reviewed-by: Parth Malkan <parthmalkan@google.com>
Diffstat (limited to 'common')
-rw-r--r--common/rgb_keyboard.c79
1 files changed, 72 insertions, 7 deletions
diff --git a/common/rgb_keyboard.c b/common/rgb_keyboard.c
index 29f5563463..f581d5ae1a 100644
--- a/common/rgb_keyboard.c
+++ b/common/rgb_keyboard.c
@@ -235,6 +235,75 @@ void rgbkbd_init_lookup_table(void)
__overridable void board_enable_rgb_keyboard(bool enable) {}
+static int rgbkbd_init(void)
+{
+ int rv = EC_SUCCESS;
+ int e, i;
+ bool updated = false;
+
+ for (i = 0; i < rgbkbd_count; i++) {
+ struct rgbkbd *ctx = &rgbkbds[i];
+
+ if (ctx->state >= RGBKBD_STATE_INITIALIZED)
+ continue;
+
+ e = ctx->cfg->drv->init(ctx);
+ if (e) {
+ CPRINTS("Failed to init GRID%d (%d)", i, e);
+ rv = e;
+ continue;
+ }
+
+ ctx->state = RGBKBD_STATE_INITIALIZED;
+ updated = true;
+
+ e = ctx->cfg->drv->set_scale(ctx, 0, 0x80, get_grid_size(ctx));
+ if (e) {
+ CPRINTS("Failed to set scale of GRID%d (%d)", i, e);
+ rv = e;
+ }
+ }
+
+ if (updated)
+ CPRINTS("Initialized (%d)", rv);
+
+ /* Return EC_SUCCESS or the last error. */
+ return rv;
+}
+
+static int rgbkbd_enable(int enable)
+{
+ int rv = EC_SUCCESS;
+ int e, i;
+ bool updated = false;
+
+ for (i = 0; i < rgbkbd_count; i++) {
+ struct rgbkbd *ctx = &rgbkbds[i];
+
+ if (ctx->state >= RGBKBD_STATE_ENABLED && enable)
+ continue;
+
+ e = ctx->cfg->drv->enable(ctx, enable);
+ if (e) {
+ CPRINTS("Failed to %s GRID%d (%d)",
+ enable ? "enable" : "disable", i, e);
+ rv = e;
+ continue;
+ }
+
+ ctx->state = enable ?
+ RGBKBD_STATE_ENABLED : RGBKBD_STATE_DISABLED;
+ updated = true;
+ }
+
+ if (updated)
+ CPRINTS("%s (%d)", enable ? "Enabled" : "Disabled", rv);
+
+ /* Return EC_SUCCESS or the last error. */
+ return rv;
+}
+
+
void rgbkbd_task(void *u)
{
uint32_t event;
@@ -243,17 +312,13 @@ void rgbkbd_task(void *u)
board_enable_rgb_keyboard(true);
rgbkbd_init_lookup_table();
-
+ rgbkbd_init();
+ rgbkbd_enable(1);
for (i = 0; i < rgbkbd_count; i++) {
struct rgbkbd *ctx = &rgbkbds[i];
- rv = ctx->cfg->drv->init(ctx);
- if (rv)
- CPRINTS("Failed to init GRID%d (%d)", i, rv);
rv = ctx->cfg->drv->set_gcc(ctx, 0x80);
- rv |= ctx->cfg->drv->set_scale(ctx, 0, 0x80,
- get_grid_size(ctx));
if (rv)
- CPRINTS("Failed to set GCC or scale (%d)", rv);
+ CPRINTS("Failed to set GCC (%d)", rv);
}
while (1) {