History

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.

Gwendal Grignou committed 9 months ago

Commit 2d8251d1 parent ec0dd362 files · +54 −0Browse files

Unified · Split

2 files
  1. drivers/platform/chrome/cros_ec_lightbar.c +43 −0
  2. include/linux/platform_data/cros_ec_commands.h +11 −0
drivers/platform/chrome/cros_ec_lightbar.c+43−0
@@ -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
183static 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);
219exit:
220 kfree(msg);
221 return ret;
222}
223
183static ssize_t brightness_store(struct device *dev,224static 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
514static DEVICE_ATTR_RW(interval_msec);555static DEVICE_ATTR_RW(interval_msec);
556static DEVICE_ATTR_RO(num_segments);
515static DEVICE_ATTR_RO(version);557static DEVICE_ATTR_RO(version);
516static DEVICE_ATTR_WO(brightness);558static DEVICE_ATTR_WO(brightness);
517static DEVICE_ATTR_WO(led_rgb);559static DEVICE_ATTR_WO(led_rgb);
@@ -521,6 +563,7 @@ static DEVICE_ATTR_RW(userspace_control); · 3 unmodified lines
521 563
522static struct attribute *__lb_cmds_attrs[] = {564static 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,
include/linux/platform_data/cros_ec_commands.h+11−0
@@ -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
2008struct 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 1922017#define EC_LB_PROG_LEN 192
2010struct lightbar_program {2018struct 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_CMDS2157 LIGHTBAR_NUM_CMDS
2147};2158};
2148 2159

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t