Skip to content

Commit 3cf9df0

Browse files
Fabien Lahouderejic23
authored andcommitted
iio: common: cros_ec_sensors: determine protocol version
This patch adds a function to determine which version of the protocol is used to communicate with EC. Signed-off-by: Nick Vaccaro <[email protected]> Signed-off-by: Fabien Lahoudere <[email protected]> Reviewed-by: Gwendal Grignou <[email protected]> Tested-by: Gwendal Grignou <[email protected]> [rebased on top of iio/testing and solved conflicts] Signed-off-by: Enric Balletbo i Serra <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 3e4daba commit 3cf9df0

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ static char *cros_ec_loc[] = {
2525
[MOTIONSENSE_LOC_MAX] = "unknown",
2626
};
2727

28+
static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev,
29+
u16 cmd_offset, u16 cmd, u32 *mask)
30+
{
31+
int ret;
32+
struct {
33+
struct cros_ec_command msg;
34+
union {
35+
struct ec_params_get_cmd_versions params;
36+
struct ec_response_get_cmd_versions resp;
37+
};
38+
} __packed buf = {
39+
.msg = {
40+
.command = EC_CMD_GET_CMD_VERSIONS + cmd_offset,
41+
.insize = sizeof(struct ec_response_get_cmd_versions),
42+
.outsize = sizeof(struct ec_params_get_cmd_versions)
43+
},
44+
.params = {.cmd = cmd}
45+
};
46+
47+
ret = cros_ec_cmd_xfer_status(ec_dev, &buf.msg);
48+
if (ret >= 0)
49+
*mask = buf.resp.version_mask;
50+
return ret;
51+
}
52+
2853
int cros_ec_sensors_core_init(struct platform_device *pdev,
2954
struct iio_dev *indio_dev,
3055
bool physical_device)
@@ -33,6 +58,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
3358
struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
3459
struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent);
3560
struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
61+
u32 ver_mask;
3662
int ret;
3763

3864
platform_set_drvdata(pdev, indio_dev);
@@ -48,8 +74,15 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
4874

4975
mutex_init(&state->cmd_lock);
5076

77+
ret = cros_ec_get_host_cmd_version_mask(state->ec,
78+
ec->cmd_offset,
79+
EC_CMD_MOTION_SENSE_CMD,
80+
&ver_mask);
81+
if (ret < 0)
82+
return ret;
83+
5184
/* Set up the host command structure. */
52-
state->msg->version = 2;
85+
state->msg->version = fls(ver_mask) - 1;
5386
state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
5487
state->msg->outsize = sizeof(struct ec_params_motion_sense);
5588

0 commit comments

Comments
 (0)