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.
Unified · Split
| @@ -180,6 +180,47 @@ static ssize_t version_show(struct device *dev, · 179 unmodified lines | |||
| 180 | return sysfs_emit(buf, "%d %d\n", version, flags); | 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 | static ssize_t brightness_store(struct device *dev, | 224 | static ssize_t brightness_store(struct device *dev, |
| 184 | struct device_attribute *attr, | 225 | struct device_attribute *attr, |
| 185 | const char *buf, size_t count) | 226 | const char *buf, size_t count) |
| @@ -512,6 +553,7 @@ static ssize_t userspace_control_store(struct device *dev, · 326 unmodified lines | |||
| 512 | /* Module initialization */ | 553 | /* Module initialization */ |
| 513 | 554 | ||
| 514 | static DEVICE_ATTR_RW(interval_msec); | 555 | static DEVICE_ATTR_RW(interval_msec); |
| 556 | static DEVICE_ATTR_RO(num_segments); | ||
| 515 | static DEVICE_ATTR_RO(version); | 557 | static DEVICE_ATTR_RO(version); |
| 516 | static DEVICE_ATTR_WO(brightness); | 558 | static DEVICE_ATTR_WO(brightness); |
| 517 | static DEVICE_ATTR_WO(led_rgb); | 559 | static DEVICE_ATTR_WO(led_rgb); |
| @@ -521,6 +563,7 @@ static DEVICE_ATTR_RW(userspace_control); · 3 unmodified lines | |||
| 521 | 563 | ||
| 522 | static struct attribute *__lb_cmds_attrs[] = { | 564 | static struct attribute *__lb_cmds_attrs[] = { |
| 523 | &dev_attr_interval_msec.attr, | 565 | &dev_attr_interval_msec.attr, |
| 566 | &dev_attr_num_segments.attr, | ||
| 524 | &dev_attr_version.attr, | 567 | &dev_attr_version.attr, |
| 525 | &dev_attr_brightness.attr, | 568 | &dev_attr_brightness.attr, |
| 526 | &dev_attr_led_rgb.attr, | 569 | &dev_attr_led_rgb.attr, |
| @@ -2005,6 +2005,14 @@ struct lightbar_params_v2_colors { · 2004 unmodified lines | |||
| 2005 | struct rgb_s color[8]; /* 0-3 are Google colors */ | 2005 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
| 2006 | } __ec_todo_packed; | 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 | /* Lightbar program. */ | 2016 | /* Lightbar program. */ |
| 2009 | #define EC_LB_PROG_LEN 192 | 2017 | #define EC_LB_PROG_LEN 192 |
| 2010 | struct lightbar_program { | 2018 | struct lightbar_program { |
| @@ -2086,6 +2094,8 @@ struct ec_response_lightbar { · 75 unmodified lines | |||
| 2086 | struct lightbar_params_v2_thresholds get_params_v2_thlds; | 2094 | struct lightbar_params_v2_thresholds get_params_v2_thlds; |
| 2087 | struct lightbar_params_v2_colors get_params_v2_colors; | 2095 | struct lightbar_params_v2_colors get_params_v2_colors; |
| 2088 | 2096 | ||
| 2097 | struct lightbar_params_v3 get_params_v3; | ||
| 2098 | |||
| 2089 | struct __ec_todo_unpacked { | 2099 | struct __ec_todo_unpacked { |
| 2090 | uint32_t num; | 2100 | uint32_t num; |
| 2091 | uint32_t flags; | 2101 | uint32_t flags; |
| @@ -2143,6 +2153,7 @@ enum lightbar_command { · 51 unmodified lines | |||
| 2143 | LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, | 2153 | LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, |
| 2144 | LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, | 2154 | LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, |
| 2145 | LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, | 2155 | LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, |
| 2156 | LIGHTBAR_CMD_GET_PARAMS_V3 = 34, | ||
| 2146 | LIGHTBAR_NUM_CMDS | 2157 | LIGHTBAR_NUM_CMDS |
| 2147 | }; | 2158 | }; |
| 2148 | 2159 | ||