Skip to content

Commit 69a1374

Browse files
t-8chTzung-Bi Shih
authored andcommitted
platform/chrome: cros_ec_proto: Introduce cros_ec_get_cmd_versions()
Retrieving the supported versions of a command is a fairly common operation. Provide a helper for it. If the command is not supported at all the EC returns -EINVAL/EC_RES_INVALID_PARAMS. This error is translated into an empty version mask as that is easier to handle for callers and they don't need to know about the error details. Signed-off-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Tzung-Bi Shih <[email protected]>
1 parent c05cb5b commit 69a1374

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <linux/delay.h>
77
#include <linux/device.h>
8+
#include <linux/limits.h>
89
#include <linux/module.h>
910
#include <linux/platform_data/cros_ec_commands.h>
1011
#include <linux/platform_data/cros_ec_proto.h>
@@ -1069,3 +1070,37 @@ int cros_ec_cmd_readmem(struct cros_ec_device *ec_dev, u8 offset, u8 size, void
10691070
&params, sizeof(params), dest, size);
10701071
}
10711072
EXPORT_SYMBOL_GPL(cros_ec_cmd_readmem);
1073+
1074+
/**
1075+
* cros_ec_get_cmd_versions - Get supported version mask.
1076+
*
1077+
* @ec_dev: EC device
1078+
* @cmd: Command to test
1079+
*
1080+
* Return: version mask on success, negative error number on failure.
1081+
*/
1082+
int cros_ec_get_cmd_versions(struct cros_ec_device *ec_dev, u16 cmd)
1083+
{
1084+
struct ec_params_get_cmd_versions req_v0;
1085+
struct ec_params_get_cmd_versions_v1 req_v1;
1086+
struct ec_response_get_cmd_versions resp;
1087+
int ret;
1088+
1089+
if (cmd <= U8_MAX) {
1090+
req_v0.cmd = cmd;
1091+
ret = cros_ec_cmd(ec_dev, 0, EC_CMD_GET_CMD_VERSIONS,
1092+
&req_v0, sizeof(req_v0), &resp, sizeof(resp));
1093+
} else {
1094+
req_v1.cmd = cmd;
1095+
ret = cros_ec_cmd(ec_dev, 1, EC_CMD_GET_CMD_VERSIONS,
1096+
&req_v1, sizeof(req_v1), &resp, sizeof(resp));
1097+
}
1098+
1099+
if (ret == -EINVAL)
1100+
return 0; /* Command not implemented */
1101+
else if (ret < 0)
1102+
return ret;
1103+
else
1104+
return resp.version_mask;
1105+
}
1106+
EXPORT_SYMBOL_GPL(cros_ec_get_cmd_versions);

include/linux/platform_data/cros_ec_proto.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ int cros_ec_cmd(struct cros_ec_device *ec_dev, unsigned int version, int command
263263

264264
int cros_ec_cmd_readmem(struct cros_ec_device *ec_dev, u8 offset, u8 size, void *dest);
265265

266+
int cros_ec_get_cmd_versions(struct cros_ec_device *ec_dev, u16 cmd);
267+
266268
/**
267269
* cros_ec_get_time_ns() - Return time in ns.
268270
*

0 commit comments

Comments
 (0)