platform/chrome: lightbar: Add on/off switch
Subsystems (2)
PATCH 1/1 platform/chrome: lightbar: Add on/off switch
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 <[email protected]>
--- drivers/platform/chrome/cros_ec_lightbar.c | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+)
drivers/platform/chrome/cros_ec_lightbar.c +67 -0
@@ -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,
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
Tzung-Bi Shih
maintainerQuoted 7 lines · Gwendal Grignou
drivers/platform/chrome/cros_ec_lightbar.c +7
-0+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;
drivers/platform/chrome/cros_ec_lightbar.c static ssize_t brightness_store(struct device *dev, · line 281
Quoted 10 lines
drivers/platform/chrome/cros_ec_lightbar.c +10
-0+ + 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;
Move lb_throttle() before param = ... to save cycles if it needs to exit earlier.
Quoted 27 lines
drivers/platform/chrome/cros_ec_lightbar.c +27
-0+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);
drivers/platform/chrome/cros_ec_lightbar.c static ssize_t brightness_store(struct device *dev, · line 327
Quoted 10 lines
drivers/platform/chrome/cros_ec_lightbar.c +10
-0+if (ret <0 ) +return ret; +if (!val) +return -EINVAL ; + + ret =single_command (dev,LIGHTBAR_CMD_OFF ); +if (ret <0 ) +return ret; +return count; +}
on_store and off_store are similar. Can they use a common helper function? Maybe combine with single_command() as there is no other users of the function.