public inbox for chrome-platform@lists.linux.dev
 help / color / mirror / Atom feed
From: Gwendal Grignou <gwendal@chromium.org>
To: tzungbi@kernel.org
Cc: chrome-platform@lists.linux.dev, Gwendal Grignou <gwendal@google.com>
Subject: [PATCH] platform/chrome: lightbar: Add on/off switch
Date: Tue,  3 Feb 2026 19:59:06 -0800	[thread overview]
Message-ID: <20260204035906.703625-1-gwendal@google.com> (raw)

Add write-only sysfs entries 'on' and 'off' to switch
the lightbar on or off. Survive reboots, return to `on` on EC resets.

Triggered by:
echo 1 > /sys/class/chromeos/cros_ec/lightbar/off
echo 1 > /sys/class/chromeos/cros_ec/lightbar/on

Signed-off-by: Gwendal Grignou <gwendal@google.com>
---
 drivers/platform/chrome/cros_ec_lightbar.c | 67 ++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platform/chrome/cros_ec_lightbar.c
index 2d1aa6edda1a..d17e2c463fde 100644
--- a/drivers/platform/chrome/cros_ec_lightbar.c
+++ b/drivers/platform/chrome/cros_ec_lightbar.c
@@ -262,6 +262,69 @@ static ssize_t brightness_store(struct device *dev,
 	return ret;
 }
 
+static ssize_t single_command(struct device *dev,
+			      enum lightbar_command cmd)
+{
+	struct cros_ec_dev *ec = to_cros_ec_dev(dev);
+	struct ec_params_lightbar *param;
+	struct cros_ec_command *msg;
+	int ret;
+
+	msg = alloc_lightbar_cmd_msg(ec);
+	if (!msg)
+		return -ENOMEM;
+
+	param = (struct ec_params_lightbar *)msg->data;
+	param->cmd = cmd;
+	ret = lb_throttle();
+	if (ret)
+		goto exit;
+
+	msg->outsize = sizeof(param->cmd);
+	msg->insize = 0;
+	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+exit:
+	kfree(msg);
+	return ret;
+}
+
+static ssize_t on_store(struct device *dev,
+			struct device_attribute *attr,
+			const char *buf, size_t count)
+{
+	bool val;
+	int ret;
+
+	ret = kstrtobool(buf, &val);
+	if (ret < 0)
+		return ret;
+	if (!val)
+		return -EINVAL;
+
+	ret = single_command(dev, LIGHTBAR_CMD_ON);
+	if (ret < 0)
+		return ret;
+	return count;
+}
+
+static ssize_t off_store(struct device *dev,
+			 struct device_attribute *attr,
+			 const char *buf, size_t count)
+{
+	bool val;
+	int ret;
+
+	ret = kstrtobool(buf, &val);
+	if (ret < 0)
+		return ret;
+	if (!val)
+		return -EINVAL;
+
+	ret = single_command(dev, LIGHTBAR_CMD_OFF);
+	if (ret < 0)
+		return ret;
+	return count;
+}
 
 /*
  * We expect numbers, and we'll keep reading until we find them, skipping over
@@ -591,6 +654,8 @@ static DEVICE_ATTR_RO(num_segments);
 static DEVICE_ATTR_RO(version);
 static DEVICE_ATTR_WO(brightness);
 static DEVICE_ATTR_WO(led_rgb);
+static DEVICE_ATTR_WO(on);
+static DEVICE_ATTR_WO(off);
 static DEVICE_ATTR_RW(sequence);
 static DEVICE_ATTR_WO(program);
 static DEVICE_ATTR_RW(userspace_control);
@@ -601,6 +666,8 @@ static struct attribute *__lb_cmds_attrs[] = {
 	&dev_attr_version.attr,
 	&dev_attr_brightness.attr,
 	&dev_attr_led_rgb.attr,
+	&dev_attr_on.attr,
+	&dev_attr_off.attr,
 	&dev_attr_sequence.attr,
 	&dev_attr_program.attr,
 	&dev_attr_userspace_control.attr,
-- 
2.53.0.rc2.204.g2597b5adb4-goog


             reply	other threads:[~2026-02-04  3:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-04  3:59 Gwendal Grignou [this message]
2026-02-23  7:52 ` [PATCH] platform/chrome: lightbar: Add on/off switch Tzung-Bi Shih

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260204035906.703625-1-gwendal@google.com \
    --to=gwendal@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=gwendal@google.com \
    --cc=tzungbi@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox