Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

platform/chrome: lightbar: Report number of segments

Add attribue `num_segments` to return the number of exposed LED segments
in the lightbar. It can be smaller than the number of physical leds in
the lightbar.

Test: Check the attribute is present and returns a value when read.

Signed-off-by: Gwendal Grignou <gwendal@google.com>
Link: https://lore.kernel.org/r/20260130081351.487517-1-gwendal@google.com
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

authored by

Gwendal Grignou and committed by
Tzung-Bi Shih
2d8251d9 ec0dd36d

+54
+43
drivers/platform/chrome/cros_ec_lightbar.c
··· 180 180 return sysfs_emit(buf, "%d %d\n", version, flags); 181 181 } 182 182 183 + static ssize_t num_segments_show(struct device *dev, 184 + struct device_attribute *attr, char *buf) 185 + { 186 + struct ec_params_lightbar *param; 187 + struct ec_response_lightbar *resp; 188 + struct cros_ec_command *msg; 189 + struct cros_ec_dev *ec = to_cros_ec_dev(dev); 190 + uint32_t num = 0; 191 + int ret; 192 + 193 + ret = lb_throttle(); 194 + if (ret) 195 + return ret; 196 + 197 + msg = alloc_lightbar_cmd_msg(ec); 198 + if (!msg) 199 + return -ENOMEM; 200 + 201 + param = (struct ec_params_lightbar *)msg->data; 202 + param->cmd = LIGHTBAR_CMD_GET_PARAMS_V3; 203 + msg->outsize = sizeof(param->cmd); 204 + msg->insize = sizeof(resp->get_params_v3); 205 + ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg); 206 + if (ret < 0 && ret != -EINVAL) 207 + goto exit; 208 + 209 + if (msg->result == EC_RES_SUCCESS) { 210 + resp = (struct ec_response_lightbar *)msg->data; 211 + num = resp->get_params_v3.reported_led_num; 212 + } 213 + 214 + /* 215 + * Anything else (ie, EC_RES_INVALID_COMMAND) - no direct control over 216 + * LEDs, return that no leds are supported. 217 + */ 218 + ret = sysfs_emit(buf, "%u\n", num); 219 + exit: 220 + kfree(msg); 221 + return ret; 222 + } 223 + 183 224 static ssize_t brightness_store(struct device *dev, 184 225 struct device_attribute *attr, 185 226 const char *buf, size_t count) ··· 553 512 /* Module initialization */ 554 513 555 514 static DEVICE_ATTR_RW(interval_msec); 515 + static DEVICE_ATTR_RO(num_segments); 556 516 static DEVICE_ATTR_RO(version); 557 517 static DEVICE_ATTR_WO(brightness); 558 518 static DEVICE_ATTR_WO(led_rgb); ··· 563 521 564 522 static struct attribute *__lb_cmds_attrs[] = { 565 523 &dev_attr_interval_msec.attr, 524 + &dev_attr_num_segments.attr, 566 525 &dev_attr_version.attr, 567 526 &dev_attr_brightness.attr, 568 527 &dev_attr_led_rgb.attr,
+11
include/linux/platform_data/cros_ec_commands.h
··· 2005 2005 struct rgb_s color[8]; /* 0-3 are Google colors */ 2006 2006 } __ec_todo_packed; 2007 2007 2008 + struct lightbar_params_v3 { 2009 + /* 2010 + * Number of LEDs reported by the EC. 2011 + * May be less than the actual number of LEDs in the lightbar. 2012 + */ 2013 + uint8_t reported_led_num; 2014 + } __ec_todo_packed; 2015 + 2008 2016 /* Lightbar program. */ 2009 2017 #define EC_LB_PROG_LEN 192 2010 2018 struct lightbar_program { ··· 2094 2086 struct lightbar_params_v2_thresholds get_params_v2_thlds; 2095 2087 struct lightbar_params_v2_colors get_params_v2_colors; 2096 2088 2089 + struct lightbar_params_v3 get_params_v3; 2090 + 2097 2091 struct __ec_todo_unpacked { 2098 2092 uint32_t num; 2099 2093 uint32_t flags; ··· 2153 2143 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, 2154 2144 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, 2155 2145 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, 2146 + LIGHTBAR_CMD_GET_PARAMS_V3 = 34, 2156 2147 LIGHTBAR_NUM_CMDS 2157 2148 }; 2158 2149