Skip to content

Commit be653d2

Browse files
committed
Merge tag 'chrome-platform-v7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux
Pull chrome platform updates from Tzung-Bi Shih: "New cros_ec_lightbar features: - Report the number of exposed LED segments via sysfs - Support large sequence of program to be transmitted Fixes: - Don't touch fwnode_handle::dev which is a private field - Fix wrong assignment for response size in cros_ec_lightbar Cleanups: - Use acpi_get_local_u64_address() helper" * tag 'chrome-platform-v7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux: platform/chrome: lightbar: Use flexible array member platform/chrome: lightbar: Fix lightbar_program_ex alignment platform/chrome: lightbar: Add support for large sequence platform/chrome: lightbar: Report number of segments platform/chrome: cros_ec_lightbar: Fix response size initialization platform/chrome: cros_typec_switch: Use acpi_get_local_u64_address() platform/chrome: cros_typec_switch: Don't touch struct fwnode_handle::dev
2 parents 192c015 + 520e345 commit be653d2

3 files changed

Lines changed: 134 additions & 42 deletions

File tree

drivers/platform/chrome/cros_ec_lightbar.c

Lines changed: 105 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ static bool userspace_control;
3737
*/
3838
static bool has_manual_suspend;
3939

40+
/*
41+
* Lightbar version
42+
*/
43+
static int lb_version;
44+
4045
static ssize_t interval_msec_show(struct device *dev,
4146
struct device_attribute *attr, char *buf)
4247
{
@@ -93,18 +98,20 @@ static int lb_throttle(void)
9398

9499
static struct cros_ec_command *alloc_lightbar_cmd_msg(struct cros_ec_dev *ec)
95100
{
101+
int len = max(ec->ec_dev->max_response, ec->ec_dev->max_request);
96102
struct cros_ec_command *msg;
97-
int len;
98-
99-
len = max(sizeof(struct ec_params_lightbar),
100-
sizeof(struct ec_response_lightbar));
101103

102104
msg = kmalloc(sizeof(*msg) + len, GFP_KERNEL);
103105
if (!msg)
104106
return NULL;
105107

106108
msg->version = 0;
107109
msg->command = EC_CMD_LIGHTBAR_CMD + ec->cmd_offset;
110+
/*
111+
* Default sizes for regular commands.
112+
* Can be set smaller to optimize transfer,
113+
* larger when sending large light sequences.
114+
*/
108115
msg->outsize = sizeof(struct ec_params_lightbar);
109116
msg->insize = sizeof(struct ec_response_lightbar);
110117

@@ -126,7 +133,7 @@ static int get_lightbar_version(struct cros_ec_dev *ec,
126133
param = (struct ec_params_lightbar *)msg->data;
127134
param->cmd = LIGHTBAR_CMD_VERSION;
128135
msg->outsize = sizeof(param->cmd);
129-
msg->result = sizeof(resp->version);
136+
msg->insize = sizeof(resp->version);
130137
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
131138
if (ret < 0 && ret != -EINVAL) {
132139
ret = 0;
@@ -180,6 +187,47 @@ static ssize_t version_show(struct device *dev,
180187
return sysfs_emit(buf, "%d %d\n", version, flags);
181188
}
182189

190+
static ssize_t num_segments_show(struct device *dev,
191+
struct device_attribute *attr, char *buf)
192+
{
193+
struct ec_params_lightbar *param;
194+
struct ec_response_lightbar *resp;
195+
struct cros_ec_command *msg;
196+
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
197+
uint32_t num = 0;
198+
int ret;
199+
200+
ret = lb_throttle();
201+
if (ret)
202+
return ret;
203+
204+
msg = alloc_lightbar_cmd_msg(ec);
205+
if (!msg)
206+
return -ENOMEM;
207+
208+
param = (struct ec_params_lightbar *)msg->data;
209+
param->cmd = LIGHTBAR_CMD_GET_PARAMS_V3;
210+
msg->outsize = sizeof(param->cmd);
211+
msg->insize = sizeof(resp->get_params_v3);
212+
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
213+
if (ret < 0 && ret != -EINVAL)
214+
goto exit;
215+
216+
if (msg->result == EC_RES_SUCCESS) {
217+
resp = (struct ec_response_lightbar *)msg->data;
218+
num = resp->get_params_v3.reported_led_num;
219+
}
220+
221+
/*
222+
* Anything else (ie, EC_RES_INVALID_COMMAND) - no direct control over
223+
* LEDs, return that no leds are supported.
224+
*/
225+
ret = sysfs_emit(buf, "%u\n", num);
226+
exit:
227+
kfree(msg);
228+
return ret;
229+
}
230+
183231
static ssize_t brightness_store(struct device *dev,
184232
struct device_attribute *attr,
185233
const char *buf, size_t count)
@@ -430,25 +478,34 @@ static ssize_t sequence_store(struct device *dev, struct device_attribute *attr,
430478
static ssize_t program_store(struct device *dev, struct device_attribute *attr,
431479
const char *buf, size_t count)
432480
{
433-
int extra_bytes, max_size, ret;
481+
size_t extra_bytes, max_size;
434482
struct ec_params_lightbar *param;
435483
struct cros_ec_command *msg;
436484
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
485+
int ret;
437486

438487
/*
439488
* We might need to reject the program for size reasons. The EC
440489
* enforces a maximum program size, but we also don't want to try
441490
* and send a program that is too big for the protocol. In order
442491
* to ensure the latter, we also need to ensure we have extra bytes
443492
* to represent the rest of the packet.
493+
* With V3, larger program can be sent, limited only by the EC.
494+
* Only the protocol limit the payload size.
444495
*/
445-
extra_bytes = sizeof(*param) - sizeof(param->set_program.data);
446-
max_size = min(EC_LB_PROG_LEN, ec->ec_dev->max_request - extra_bytes);
447-
if (count > max_size) {
448-
dev_err(dev, "Program is %u bytes, too long to send (max: %u)",
449-
(unsigned int)count, max_size);
450-
451-
return -EINVAL;
496+
if (lb_version < 3) {
497+
extra_bytes = sizeof(*param) - sizeof(param->set_program.data);
498+
max_size = min(EC_LB_PROG_LEN, ec->ec_dev->max_request - extra_bytes);
499+
if (count > max_size) {
500+
dev_err(dev, "Program is %zu bytes, too long to send (max: %zu)",
501+
count, max_size);
502+
503+
return -EINVAL;
504+
}
505+
} else {
506+
extra_bytes = offsetof(typeof(*param), set_program_ex) +
507+
sizeof(param->set_program_ex);
508+
max_size = ec->ec_dev->max_request - extra_bytes;
452509
}
453510

454511
msg = alloc_lightbar_cmd_msg(ec);
@@ -458,26 +515,44 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr,
458515
ret = lb_throttle();
459516
if (ret)
460517
goto exit;
518+
param = (struct ec_params_lightbar *)msg->data;
461519

462-
dev_info(dev, "Copying %zu byte program to EC", count);
520+
if (lb_version < 3) {
521+
dev_info(dev, "Copying %zu byte program to EC", count);
463522

464-
param = (struct ec_params_lightbar *)msg->data;
465-
param->cmd = LIGHTBAR_CMD_SET_PROGRAM;
523+
param->cmd = LIGHTBAR_CMD_SET_PROGRAM;
466524

467-
param->set_program.size = count;
468-
memcpy(param->set_program.data, buf, count);
525+
param->set_program.size = count;
526+
memcpy(param->set_program.data, buf, count);
469527

470-
/*
471-
* We need to set the message size manually or else it will use
472-
* EC_LB_PROG_LEN. This might be too long, and the program
473-
* is unlikely to use all of the space.
474-
*/
475-
msg->outsize = count + extra_bytes;
528+
/*
529+
* We need to set the message size manually or else it will use
530+
* EC_LB_PROG_LEN. This might be too long, and the program
531+
* is unlikely to use all of the space.
532+
*/
533+
msg->outsize = count + extra_bytes;
476534

477-
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
478-
if (ret < 0)
479-
goto exit;
535+
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
536+
if (ret < 0)
537+
goto exit;
538+
} else {
539+
size_t offset = 0;
540+
size_t payload = 0;
541+
542+
param->cmd = LIGHTBAR_CMD_SET_PROGRAM_EX;
543+
while (offset < count) {
544+
payload = min(max_size, count - offset);
545+
param->set_program_ex.offset = offset;
546+
param->set_program_ex.size = payload;
547+
memcpy(param->set_program_ex.data, &buf[offset], payload);
548+
msg->outsize = payload + extra_bytes;
480549

550+
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
551+
if (ret < 0)
552+
goto exit;
553+
offset += payload;
554+
}
555+
}
481556
ret = count;
482557
exit:
483558
kfree(msg);
@@ -512,6 +587,7 @@ static ssize_t userspace_control_store(struct device *dev,
512587
/* Module initialization */
513588

514589
static DEVICE_ATTR_RW(interval_msec);
590+
static DEVICE_ATTR_RO(num_segments);
515591
static DEVICE_ATTR_RO(version);
516592
static DEVICE_ATTR_WO(brightness);
517593
static DEVICE_ATTR_WO(led_rgb);
@@ -521,6 +597,7 @@ static DEVICE_ATTR_RW(userspace_control);
521597

522598
static struct attribute *__lb_cmds_attrs[] = {
523599
&dev_attr_interval_msec.attr,
600+
&dev_attr_num_segments.attr,
524601
&dev_attr_version.attr,
525602
&dev_attr_brightness.attr,
526603
&dev_attr_led_rgb.attr,
@@ -553,7 +630,7 @@ static int cros_ec_lightbar_probe(struct platform_device *pd)
553630
* Ask then for the lightbar version, if it's 0 then the 'cros_ec'
554631
* doesn't have a lightbar.
555632
*/
556-
if (!get_lightbar_version(ec_dev, NULL, NULL))
633+
if (!get_lightbar_version(ec_dev, &lb_version, NULL))
557634
return -ENODEV;
558635

559636
/* Take control of the lightbar from the EC. */

drivers/platform/chrome/cros_typec_switch.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,8 @@ static int cros_typec_register_switches(struct cros_typec_switch_data *sdata)
211211
struct cros_typec_port *port;
212212
struct device *dev = sdata->dev;
213213
struct fwnode_handle *fwnode;
214-
struct acpi_device *adev;
215-
unsigned long long index;
216214
int nports, ret;
215+
u64 index;
217216

218217
nports = device_get_child_node_count(dev);
219218
if (nports == 0) {
@@ -228,22 +227,14 @@ static int cros_typec_register_switches(struct cros_typec_switch_data *sdata)
228227
goto err_switch;
229228
}
230229

231-
adev = to_acpi_device_node(fwnode);
232-
if (!adev) {
233-
dev_err(fwnode->dev, "Couldn't get ACPI device handle\n");
234-
ret = -ENODEV;
235-
goto err_switch;
236-
}
237-
238-
ret = acpi_evaluate_integer(adev->handle, "_ADR", NULL, &index);
239-
if (ACPI_FAILURE(ret)) {
240-
dev_err(fwnode->dev, "_ADR wasn't evaluated\n");
241-
ret = -ENODATA;
230+
ret = acpi_get_local_u64_address(ACPI_HANDLE_FWNODE(fwnode), &index);
231+
if (ret) {
232+
dev_err(dev, "_ADR wasn't evaluated for %pfwP\n", fwnode);
242233
goto err_switch;
243234
}
244235

245236
if (index >= EC_USB_PD_MAX_PORTS) {
246-
dev_err(fwnode->dev, "Invalid port index number: %llu\n", index);
237+
dev_err(dev, "%pfwP: Invalid port index number: %llu\n", fwnode, index);
247238
ret = -EINVAL;
248239
goto err_switch;
249240
}

include/linux/platform_data/cros_ec_commands.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,13 +2005,32 @@ struct lightbar_params_v2_colors {
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 {
20112019
uint8_t size;
20122020
uint8_t data[EC_LB_PROG_LEN];
20132021
} __ec_todo_unpacked;
20142022

2023+
/*
2024+
* Lightbar program for large sequences. Sequences are sent in pieces, with
2025+
* increasing offset. The sequences are still limited by the amount reserved in
2026+
* EC RAM.
2027+
*/
2028+
struct lightbar_program_ex {
2029+
uint8_t size;
2030+
uint16_t offset;
2031+
uint8_t data[];
2032+
} __ec_todo_packed;
2033+
20152034
struct ec_params_lightbar {
20162035
uint8_t cmd; /* Command (see enum lightbar_command) */
20172036
union {
@@ -2058,6 +2077,7 @@ struct ec_params_lightbar {
20582077
struct lightbar_params_v2_colors set_v2par_colors;
20592078

20602079
struct lightbar_program set_program;
2080+
struct lightbar_program_ex set_program_ex;
20612081
};
20622082
} __ec_todo_packed;
20632083

@@ -2086,6 +2106,8 @@ struct ec_response_lightbar {
20862106
struct lightbar_params_v2_thresholds get_params_v2_thlds;
20872107
struct lightbar_params_v2_colors get_params_v2_colors;
20882108

2109+
struct lightbar_params_v3 get_params_v3;
2110+
20892111
struct __ec_todo_unpacked {
20902112
uint32_t num;
20912113
uint32_t flags;
@@ -2143,6 +2165,8 @@ enum lightbar_command {
21432165
LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
21442166
LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
21452167
LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
2168+
LIGHTBAR_CMD_GET_PARAMS_V3 = 34,
2169+
LIGHTBAR_CMD_SET_PROGRAM_EX = 35,
21462170
LIGHTBAR_NUM_CMDS
21472171
};
21482172

0 commit comments

Comments
 (0)