Skip to content

Commit 090a7d0

Browse files
committed
Merge tag 'tag-chrome-platform-for-v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux
Pull chrome platform updates from Benson Leung: "cros-ec: - Error code cleanup across cros-ec by Guenter - Remove cros_ec_cmd_xfer in favor of cros_ec_cmd_xfer_status cros_ec_typec: - Landed initial USB4 support in typec connector class driver for cros_ec - Role switch bugfix on disconnect, and reordering configuration steps cros_ec_lightbar: - Fix buffer outsize and result for get_lightbar_version misc: - Remove config MFD_CROS_EC, now that transition from MFD is complete - Enable KEY_LEFTMETA in new location on arm based cros-ec-keyboard keymap" * tag 'tag-chrome-platform-for-v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux: ARM: dts: cros-ec-keyboard: Add alternate keymap for KEY_LEFTMETA platform/chrome: Use kobj_to_dev() instead of container_of() platform/chrome: cros_ec_proto: Drop cros_ec_cmd_xfer() platform/chrome: cros_ec_proto: Update cros_ec_cmd_xfer() call-sites platform/chrome: Kconfig: Remove the transitional MFD_CROS_EC config platform/chrome: cros_ec_lightbar: Reduce ligthbar get version command platform/chrome: cros_ec_trace: Add fields to command traces platform/chrome: cros_ec_typec: Re-order connector configuration steps platform/chrome: cros_ec_typec: Avoid setting usb role twice during disconnect platform/chrome: cros_ec_typec: Send enum values to usb_role_switch_set_role() platform/chrome: cros_ec_typec: USB4 support pwm: cros-ec: Simplify EC error handling platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes platform/input: cros_ec: Replace -ENOTSUPP with -ENOPROTOOPT pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status platform/chrome: cros_ec_sysfs: Report range of error codes from EC cros_ec_lightbar: Accept more error codes from cros_ec_cmd_xfer_status iio: cros_ec: Accept -EOPNOTSUPP as 'not supported' error code
2 parents 4a22709 + 3e98fd6 commit 090a7d0

11 files changed

Lines changed: 154 additions & 115 deletions

File tree

arch/arm/boot/dts/cros-ec-keyboard.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
MATRIX_KEY(0x02, 0x09, KEY_F8)
4747
MATRIX_KEY(0x02, 0x0a, KEY_YEN)
4848

49+
MATRIX_KEY(0x03, 0x00, KEY_LEFTMETA)
4950
MATRIX_KEY(0x03, 0x01, KEY_GRAVE)
5051
MATRIX_KEY(0x03, 0x02, KEY_F2)
5152
MATRIX_KEY(0x03, 0x03, KEY_5)

drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int cros_ec_sensors_read(struct iio_dev *indio_dev,
7373
st->core.param.sensor_offset.flags = 0;
7474

7575
ret = cros_ec_motion_send_host_cmd(&st->core, 0);
76-
if (ret == -EPROTO) {
76+
if (ret == -EPROTO || ret == -EOPNOTSUPP) {
7777
/* Reading calibscale is not supported on older EC. */
7878
*val = 1;
7979
*val2 = 0;

drivers/input/keyboard/cros_ec_keyb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static int cros_ec_keyb_info(struct cros_ec_device *ec_dev,
348348
params->event_type = event_type;
349349

350350
ret = cros_ec_cmd_xfer_status(ec_dev, msg);
351-
if (ret == -ENOTSUPP) {
351+
if (ret == -ENOPROTOOPT) {
352352
/* With older ECs we just return 0 for everything */
353353
memset(result, 0, result_size);
354354
ret = 0;

drivers/platform/chrome/Kconfig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@
33
# Platform support for Chrome OS hardware (Chromebooks and Chromeboxes)
44
#
55

6-
config MFD_CROS_EC
7-
tristate "Platform support for Chrome hardware (transitional)"
8-
select CHROME_PLATFORMS
9-
select CROS_EC
10-
select MFD_CROS_EC_DEV
11-
depends on X86 || ARM || ARM64 || COMPILE_TEST
12-
help
13-
This is a transitional Kconfig option and will be removed after
14-
everyone enables the parts individually.
15-
166
menuconfig CHROME_PLATFORMS
177
bool "Platform support for Chrome hardware"
188
depends on X86 || ARM || ARM64 || COMPILE_TEST

drivers/platform/chrome/cros_ec_lightbar.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ static int get_lightbar_version(struct cros_ec_dev *ec,
116116

117117
param = (struct ec_params_lightbar *)msg->data;
118118
param->cmd = LIGHTBAR_CMD_VERSION;
119+
msg->outsize = sizeof(param->cmd);
120+
msg->result = sizeof(resp->version);
119121
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
120-
if (ret < 0) {
122+
if (ret < 0 && ret != -EINVAL) {
121123
ret = 0;
122124
goto exit;
123125
}
@@ -298,11 +300,9 @@ static ssize_t sequence_show(struct device *dev,
298300
goto exit;
299301

300302
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
301-
if (ret == -EPROTO) {
302-
ret = scnprintf(buf, PAGE_SIZE,
303-
"ERROR: EC returned %d\n", msg->result);
304-
goto exit;
305-
} else if (ret < 0) {
303+
if (ret < 0) {
304+
ret = scnprintf(buf, PAGE_SIZE, "XFER / EC ERROR %d / %d\n",
305+
ret, msg->result);
306306
goto exit;
307307
}
308308

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,43 @@
1515

1616
#define EC_COMMAND_RETRIES 50
1717

18+
static const int cros_ec_error_map[] = {
19+
[EC_RES_INVALID_COMMAND] = -EOPNOTSUPP,
20+
[EC_RES_ERROR] = -EIO,
21+
[EC_RES_INVALID_PARAM] = -EINVAL,
22+
[EC_RES_ACCESS_DENIED] = -EACCES,
23+
[EC_RES_INVALID_RESPONSE] = -EPROTO,
24+
[EC_RES_INVALID_VERSION] = -ENOPROTOOPT,
25+
[EC_RES_INVALID_CHECKSUM] = -EBADMSG,
26+
[EC_RES_IN_PROGRESS] = -EINPROGRESS,
27+
[EC_RES_UNAVAILABLE] = -ENODATA,
28+
[EC_RES_TIMEOUT] = -ETIMEDOUT,
29+
[EC_RES_OVERFLOW] = -EOVERFLOW,
30+
[EC_RES_INVALID_HEADER] = -EBADR,
31+
[EC_RES_REQUEST_TRUNCATED] = -EBADR,
32+
[EC_RES_RESPONSE_TOO_BIG] = -EFBIG,
33+
[EC_RES_BUS_ERROR] = -EFAULT,
34+
[EC_RES_BUSY] = -EBUSY,
35+
[EC_RES_INVALID_HEADER_VERSION] = -EBADMSG,
36+
[EC_RES_INVALID_HEADER_CRC] = -EBADMSG,
37+
[EC_RES_INVALID_DATA_CRC] = -EBADMSG,
38+
[EC_RES_DUP_UNAVAILABLE] = -ENODATA,
39+
};
40+
41+
static int cros_ec_map_error(uint32_t result)
42+
{
43+
int ret = 0;
44+
45+
if (result != EC_RES_SUCCESS) {
46+
if (result < ARRAY_SIZE(cros_ec_error_map) && cros_ec_error_map[result])
47+
ret = cros_ec_error_map[result];
48+
else
49+
ret = -EPROTO;
50+
}
51+
52+
return ret;
53+
}
54+
1855
static int prepare_packet(struct cros_ec_device *ec_dev,
1956
struct cros_ec_command *msg)
2057
{
@@ -512,19 +549,22 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)
512549
EXPORT_SYMBOL(cros_ec_query_all);
513550

514551
/**
515-
* cros_ec_cmd_xfer() - Send a command to the ChromeOS EC.
552+
* cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC.
516553
* @ec_dev: EC device.
517554
* @msg: Message to write.
518555
*
519-
* Call this to send a command to the ChromeOS EC. This should be used
520-
* instead of calling the EC's cmd_xfer() callback directly.
556+
* Call this to send a command to the ChromeOS EC. This should be used instead of calling the EC's
557+
* cmd_xfer() callback directly. It returns success status only if both the command was transmitted
558+
* successfully and the EC replied with success status.
521559
*
522-
* Return: 0 on success or negative error code.
560+
* Return:
561+
* >=0 - The number of bytes transferred
562+
* <0 - Linux error code
523563
*/
524-
static int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
564+
int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
525565
struct cros_ec_command *msg)
526566
{
527-
int ret;
567+
int ret, mapped;
528568

529569
mutex_lock(&ec_dev->lock);
530570
if (ec_dev->proto_version == EC_PROTO_VERSION_UNKNOWN) {
@@ -561,42 +601,15 @@ static int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
561601
return -EMSGSIZE;
562602
}
563603
}
604+
564605
ret = send_command(ec_dev, msg);
565606
mutex_unlock(&ec_dev->lock);
566607

567-
return ret;
568-
}
569-
570-
/**
571-
* cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC.
572-
* @ec_dev: EC device.
573-
* @msg: Message to write.
574-
*
575-
* This function is identical to cros_ec_cmd_xfer, except it returns success
576-
* status only if both the command was transmitted successfully and the EC
577-
* replied with success status. It's not necessary to check msg->result when
578-
* using this function.
579-
*
580-
* Return:
581-
* >=0 - The number of bytes transferred
582-
* -ENOTSUPP - Operation not supported
583-
* -EPROTO - Protocol error
584-
*/
585-
int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
586-
struct cros_ec_command *msg)
587-
{
588-
int ret;
589-
590-
ret = cros_ec_cmd_xfer(ec_dev, msg);
591-
if (ret < 0) {
592-
dev_err(ec_dev->dev, "Command xfer error (err:%d)\n", ret);
593-
} else if (msg->result == EC_RES_INVALID_VERSION) {
594-
dev_dbg(ec_dev->dev, "Command invalid version (err:%d)\n",
595-
msg->result);
596-
return -ENOTSUPP;
597-
} else if (msg->result != EC_RES_SUCCESS) {
598-
dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result);
599-
return -EPROTO;
608+
mapped = cros_ec_map_error(msg->result);
609+
if (mapped) {
610+
dev_dbg(ec_dev->dev, "Command result (err: %d [%d])\n",
611+
msg->result, mapped);
612+
ret = mapped;
600613
}
601614

602615
return ret;
@@ -615,7 +628,7 @@ static int get_next_event_xfer(struct cros_ec_device *ec_dev,
615628
msg->insize = size;
616629
msg->outsize = 0;
617630

618-
ret = cros_ec_cmd_xfer(ec_dev, msg);
631+
ret = cros_ec_cmd_xfer_status(ec_dev, msg);
619632
if (ret > 0) {
620633
ec_dev->event_size = ret - 1;
621634
ec_dev->event_data = *event;
@@ -659,7 +672,7 @@ static int get_keyboard_state_event(struct cros_ec_device *ec_dev)
659672
msg->insize = sizeof(ec_dev->event_data.data);
660673
msg->outsize = 0;
661674

662-
ec_dev->event_size = cros_ec_cmd_xfer(ec_dev, msg);
675+
ec_dev->event_size = cros_ec_cmd_xfer_status(ec_dev, msg);
663676
ec_dev->event_data.event_type = EC_MKBP_EVENT_KEY_MATRIX;
664677
memcpy(&ec_dev->event_data.data, msg->data,
665678
sizeof(ec_dev->event_data.data));
@@ -848,11 +861,9 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)
848861
params = (struct ec_params_motion_sense *)msg->data;
849862
params->cmd = MOTIONSENSE_CMD_DUMP;
850863

851-
ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
864+
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
852865
if (ret < 0) {
853866
sensor_count = ret;
854-
} else if (msg->result != EC_RES_SUCCESS) {
855-
sensor_count = -EPROTO;
856867
} else {
857868
resp = (struct ec_response_motion_sense *)msg->data;
858869
sensor_count = resp->dump.sensor_count;
@@ -863,9 +874,7 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)
863874
* Check legacy mode: Let's find out if sensors are accessible
864875
* via LPC interface.
865876
*/
866-
if (sensor_count == -EPROTO &&
867-
ec->cmd_offset == 0 &&
868-
ec_dev->cmd_readmem) {
877+
if (sensor_count < 0 && ec->cmd_offset == 0 && ec_dev->cmd_readmem) {
869878
ret = ec_dev->cmd_readmem(ec_dev, EC_MEMMAP_ACC_STATUS,
870879
1, &status);
871880
if (ret >= 0 &&
@@ -880,9 +889,6 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)
880889
*/
881890
sensor_count = 0;
882891
}
883-
} else if (sensor_count == -EPROTO) {
884-
/* EC responded, but does not understand DUMP command. */
885-
sensor_count = 0;
886892
}
887893
return sensor_count;
888894
}

drivers/platform/chrome/cros_ec_sysfs.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,10 @@ static ssize_t version_show(struct device *dev,
150150
msg->command = EC_CMD_GET_BUILD_INFO + ec->cmd_offset;
151151
msg->insize = EC_HOST_PARAM_SIZE;
152152
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
153-
if (ret == -EPROTO) {
154-
count += scnprintf(buf + count, PAGE_SIZE - count,
155-
"Build info: EC error %d\n", msg->result);
156-
} else if (ret < 0) {
153+
if (ret < 0) {
157154
count += scnprintf(buf + count, PAGE_SIZE - count,
158-
"Build info: XFER ERROR %d\n", ret);
155+
"Build info: XFER / EC ERROR %d / %d\n",
156+
ret, msg->result);
159157
} else {
160158
msg->data[EC_HOST_PARAM_SIZE - 1] = '\0';
161159
count += scnprintf(buf + count, PAGE_SIZE - count,
@@ -166,12 +164,10 @@ static ssize_t version_show(struct device *dev,
166164
msg->command = EC_CMD_GET_CHIP_INFO + ec->cmd_offset;
167165
msg->insize = sizeof(*r_chip);
168166
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
169-
if (ret == -EPROTO) {
170-
count += scnprintf(buf + count, PAGE_SIZE - count,
171-
"Chip info: EC error %d\n", msg->result);
172-
} else if (ret < 0) {
167+
if (ret < 0) {
173168
count += scnprintf(buf + count, PAGE_SIZE - count,
174-
"Chip info: XFER ERROR %d\n", ret);
169+
"Chip info: XFER / EC ERROR %d / %d\n",
170+
ret, msg->result);
175171
} else {
176172
r_chip = (struct ec_response_get_chip_info *)msg->data;
177173

@@ -190,12 +186,10 @@ static ssize_t version_show(struct device *dev,
190186
msg->command = EC_CMD_GET_BOARD_VERSION + ec->cmd_offset;
191187
msg->insize = sizeof(*r_board);
192188
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
193-
if (ret == -EPROTO) {
194-
count += scnprintf(buf + count, PAGE_SIZE - count,
195-
"Board version: EC error %d\n", msg->result);
196-
} else if (ret < 0) {
189+
if (ret < 0) {
197190
count += scnprintf(buf + count, PAGE_SIZE - count,
198-
"Board version: XFER ERROR %d\n", ret);
191+
"Board version: XFER / EC ERROR %d / %d\n",
192+
ret, msg->result);
199193
} else {
200194
r_board = (struct ec_response_board_version *)msg->data;
201195

@@ -326,7 +320,7 @@ static struct attribute *__ec_attrs[] = {
326320
static umode_t cros_ec_ctrl_visible(struct kobject *kobj,
327321
struct attribute *a, int n)
328322
{
329-
struct device *dev = container_of(kobj, struct device, kobj);
323+
struct device *dev = kobj_to_dev(kobj);
330324
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
331325

332326
if (a == &dev_attr_kb_wake_angle.attr && !ec->has_kb_wake_angle)

drivers/platform/chrome/cros_ec_trace.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,49 @@ TRACE_EVENT(cros_ec_request_start,
2323
TP_ARGS(cmd),
2424
TP_STRUCT__entry(
2525
__field(uint32_t, version)
26+
__field(uint32_t, offset)
2627
__field(uint32_t, command)
28+
__field(uint32_t, outsize)
29+
__field(uint32_t, insize)
2730
),
2831
TP_fast_assign(
2932
__entry->version = cmd->version;
30-
__entry->command = cmd->command;
33+
__entry->offset = cmd->command / EC_CMD_PASSTHRU_OFFSET(1);
34+
__entry->command = cmd->command % EC_CMD_PASSTHRU_OFFSET(1);
35+
__entry->outsize = cmd->outsize;
36+
__entry->insize = cmd->insize;
3137
),
32-
TP_printk("version: %u, command: %s", __entry->version,
33-
__print_symbolic(__entry->command, EC_CMDS))
38+
TP_printk("version: %u, offset: %d, command: %s, outsize: %u, insize: %u",
39+
__entry->version, __entry->offset,
40+
__print_symbolic(__entry->command, EC_CMDS),
41+
__entry->outsize, __entry->insize)
3442
);
3543

3644
TRACE_EVENT(cros_ec_request_done,
3745
TP_PROTO(struct cros_ec_command *cmd, int retval),
3846
TP_ARGS(cmd, retval),
3947
TP_STRUCT__entry(
4048
__field(uint32_t, version)
49+
__field(uint32_t, offset)
4150
__field(uint32_t, command)
51+
__field(uint32_t, outsize)
52+
__field(uint32_t, insize)
4253
__field(uint32_t, result)
4354
__field(int, retval)
4455
),
4556
TP_fast_assign(
4657
__entry->version = cmd->version;
47-
__entry->command = cmd->command;
58+
__entry->offset = cmd->command / EC_CMD_PASSTHRU_OFFSET(1);
59+
__entry->command = cmd->command % EC_CMD_PASSTHRU_OFFSET(1);
60+
__entry->outsize = cmd->outsize;
61+
__entry->insize = cmd->insize;
4862
__entry->result = cmd->result;
4963
__entry->retval = retval;
5064
),
51-
TP_printk("version: %u, command: %s, ec result: %s, retval: %d",
52-
__entry->version,
65+
TP_printk("version: %u, offset: %d, command: %s, outsize: %u, insize: %u, ec result: %s, retval: %u",
66+
__entry->version, __entry->offset,
5367
__print_symbolic(__entry->command, EC_CMDS),
68+
__entry->outsize, __entry->insize,
5469
__print_symbolic(__entry->result, EC_RESULT),
5570
__entry->retval)
5671
);

0 commit comments

Comments
 (0)