|
5 | 5 |
|
6 | 6 | #include <linux/delay.h>
|
7 | 7 | #include <linux/device.h>
|
| 8 | +#include <linux/limits.h> |
8 | 9 | #include <linux/module.h>
|
9 | 10 | #include <linux/platform_data/cros_ec_commands.h>
|
10 | 11 | #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
|
1069 | 1070 | ¶ms, sizeof(params), dest, size);
|
1070 | 1071 | }
|
1071 | 1072 | 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); |
0 commit comments