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
180180 return sysfs_emit(buf, "%d %d\n", version, flags);
181181 }
182182
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+
183224 static ssize_t brightness_store(struct device *dev,
184225 struct device_attribute *attr,
185226 const char *buf, size_t count)
@@ -512,6 +553,7 @@ static ssize_t userspace_control_store(struct device *dev, · 326 unmodified lines
512553 /* Module initialization */
513554
514555 static DEVICE_ATTR_RW(interval_msec);
556+static DEVICE_ATTR_RO(num_segments);
515557 static DEVICE_ATTR_RO(version);
516558 static DEVICE_ATTR_WO(brightness);
517559 static DEVICE_ATTR_WO(led_rgb);
@@ -521,6 +563,7 @@ static DEVICE_ATTR_RW(userspace_control); · 3 unmodified lines
521563
522564 static struct attribute *__lb_cmds_attrs[] = {
523565 &dev_attr_interval_msec.attr,
566+ &dev_attr_num_segments.attr,
524567 &dev_attr_version.attr,
525568 &dev_attr_brightness.attr,
526569 &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
20052005 struct rgb_s color[8]; /* 0-3 are Google colors */
20062006 } __ec_todo_packed;
20072007
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+
20082016 /* Lightbar program. */
20092017 #define EC_LB_PROG_LEN 192
20102018 struct lightbar_program {
@@ -2086,6 +2094,8 @@ struct ec_response_lightbar { · 75 unmodified lines
20862094 struct lightbar_params_v2_thresholds get_params_v2_thlds;
20872095 struct lightbar_params_v2_colors get_params_v2_colors;
20882096
2097+ struct lightbar_params_v3 get_params_v3;
2098+
20892099 struct __ec_todo_unpacked {
20902100 uint32_t num;
20912101 uint32_t flags;
@@ -2143,6 +2153,7 @@ enum lightbar_command { · 51 unmodified lines
21432153 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
21442154 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
21452155 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
2156+ LIGHTBAR_CMD_GET_PARAMS_V3 = 34,
21462157 LIGHTBAR_NUM_CMDS
21472158 };
21482159

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