iio: common: cros_ec_sensors: Add protocol v3 support
Subsystems (2)
v3 cover iio: common: cros_ec_sensors: Add protocol v3 support
This patch is part of a split of the following patch:
https://lkml.org/lkml/2019/6/18/268
To fix Enric comments from https://lkml.org/lkml/2019/6/25/949
I extract it from the other serie to speed up acceptance because other patches need it to be upstreamed.
Changes since v2:
- Use patch 1 from v1 after discussion on ML
Changes since v1:
- Drop second patch
- return ENODEV if version is 0
Fabien Lahoudere (1):
iio: common: cros_ec_sensors: determine protocol version
.../cros_ec_sensors/cros_ec_sensors_core.c | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)
Signature · 1 line
2.19.2
PATCH v3 1/1 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.
--- .../cros_ec_sensors/cros_ec_sensors_core.c | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +35 -1
@@ -25,6 +25,31 @@ static char *cros_ec_loc[] = { [MOTIONSENSE_LOC_MAX] = "unknown", }; +static int cros_ec_get_host_cmd_version_mask (struct cros_ec_device *ec_dev, +u16 cmd_offset,u16 cmd,u32 *mask) +{ +int ret; +struct { +struct cros_ec_command msg; +union { +struct ec_params_get_cmd_versions params; +struct ec_response_get_cmd_versions resp; + }; + } __packed buf = { + .msg = { + .command =EC_CMD_GET_CMD_VERSIONS + cmd_offset, + .insize =sizeof (struct ec_response_get_cmd_versions ), + .outsize =sizeof (struct ec_params_get_cmd_versions ) + }, + .params = {.cmd = cmd} + }; + + ret =cros_ec_cmd_xfer_status (ec_dev, &buf.msg); +if (ret >=0 ) + *mask = buf.resp.version_mask; +return ret; +} +int cros_ec_sensors_core_init (struct platform_device *pdev,struct iio_dev *indio_dev,bool physical_device)
@@ -33,6 +58,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,struct cros_ec_sensors_core_state *state =iio_priv (indio_dev);struct cros_ec_dev *ec =dev_get_drvdata (pdev->dev.parent);struct cros_ec_sensor_platform *sensor_platform =dev_get_platdata (dev); +u32 ver_mask; +int ret;platform_set_drvdata (pdev, indio_dev);
@@ -47,8 +74,15 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,mutex_init (&state->cmd_lock); + ret =cros_ec_get_host_cmd_version_mask (state->ec, + ec->cmd_offset, +EC_CMD_MOTION_SENSE_CMD , + &ver_mask); +if (ret <0 ) +return ret; +/* Set up the host command structure. */ - state->msg->version =2 ; + state->msg->version =fls (ver_mask) -1 ;; state->msg->command =EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset; state->msg->outsize =sizeof (struct ec_params_motion_sense );
Signature · 1 line
2.19.2
Re: [PATCH v3 1/1] iio: common: cros_ec_sensors: determine protocol version
Quoted 7 lines · Fabien Lahoudere
This patch adds a function to determine which version of the protocol is used to communicate with EC.
Signed-off-by Fabien Lahoudere <[email protected]>Signed-off-by Nick Vaccaro <[email protected]>Reviewed-by Gwendal Grignou <[email protected]>Tested-by Gwendal Grignou <[email protected]>
For my own reference and for if the patch ends going through the platform-chrome tree:
Just need the ack and the ok from Jonathan.
Thanks,
~ Enric
Quoted 67 lines
--- .../cros_ec_sensors/cros_ec_sensors_core.c | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +35
-1@@ -25,6 +25,31 @@ static char *cros_ec_loc[] = { [MOTIONSENSE_LOC_MAX] = "unknown", }; +static int cros_ec_get_host_cmd_version_mask (struct cros_ec_device *ec_dev, +u16 cmd_offset,u16 cmd,u32 *mask) +{ +int ret; +struct { +struct cros_ec_command msg; +union { +struct ec_params_get_cmd_versions params; +struct ec_response_get_cmd_versions resp; + }; + } __packed buf = { + .msg = { + .command =EC_CMD_GET_CMD_VERSIONS + cmd_offset, + .insize =sizeof (struct ec_response_get_cmd_versions ), + .outsize =sizeof (struct ec_params_get_cmd_versions ) + }, + .params = {.cmd = cmd} + }; + + ret =cros_ec_cmd_xfer_status (ec_dev, &buf.msg); +if (ret >=0 ) + *mask = buf.resp.version_mask; +return ret; +} +int cros_ec_sensors_core_init (struct platform_device *pdev,struct iio_dev *indio_dev,bool physical_device)@@ -33,6 +58,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,struct cros_ec_sensors_core_state *state =iio_priv (indio_dev);struct cros_ec_dev *ec =dev_get_drvdata (pdev->dev.parent);struct cros_ec_sensor_platform *sensor_platform =dev_get_platdata (dev); +u32 ver_mask; +int ret;platform_set_drvdata (pdev, indio_dev);@@ -47,8 +74,15 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,mutex_init (&state->cmd_lock); + ret =cros_ec_get_host_cmd_version_mask (state->ec, + ec->cmd_offset, +EC_CMD_MOTION_SENSE_CMD , + &ver_mask); +if (ret <0 ) +return ret; +/* Set up the host command structure. */ - state->msg->version =2 ; + state->msg->version =fls (ver_mask) -1 ;; state->msg->command =EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset; state->msg->outsize =sizeof (struct ec_params_motion_sense );
Re: [PATCH v3 1/1] iio: common: cros_ec_sensors: determine protocol version
In reply to Fabien LahoudereHi,
There is a double semi colon in that patch.
Let me send a v4 without it.
Quoted 72 lines · Fabien Lahoudere
This patch adds a function to determine which version of the protocol is used to communicate with EC.
Signed-off-by Fabien Lahoudere <[email protected]>Signed-off-by Nick Vaccaro <[email protected]>Reviewed-by Gwendal Grignou <[email protected]>Tested-by Gwendal Grignou <[email protected]>--- .../cros_ec_sensors/cros_ec_sensors_core.c | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)diff --git
a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.cb/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.cindex130362ca421b..2e0f97448e64100644drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +14
-0@@ -25,6 +25,31 @@ static char *cros_ec_loc[] = { [MOTIONSENSE_LOC_MAX] = "unknown", }; +static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev, + u16 cmd_offset, u16 cmd, u32 *mask) +{ + int ret; + struct { + struct cros_ec_command msg; + union { + struct ec_params_get_cmd_versions params; + struct ec_response_get_cmd_versions resp; + }; + } __packed buf = { + .msg = { + .command = EC_CMD_GET_CMD_VERSIONS + cmd_offset, + .insize = sizeof(struct
ec_response_get_cmd_versions),drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +1
-0+ .outsize = sizeof(struct
ec_params_get_cmd_versions)drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +12
-0+ }, + .params = {.cmd = cmd} + }; + + ret =cros_ec_cmd_xfer_status (ec_dev, &buf.msg); +if (ret >=0 ) + *mask = buf.resp.version_mask; +return ret; +} +int cros_ec_sensors_core_init (struct platform_device *pdev,struct iio_dev *indio_dev,bool physical_device)@@ -33,6 +58,8 @@ int cros_ec_sensors_core_init(structplatform_device *pdev, struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);struct cros_ec_dev *ec =dev_get_drvdata (pdev->dev.parent);struct cros_ec_sensor_platform *sensor_platform =dev_get_platdata (dev); +u32 ver_mask; +int ret;drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +1
-0platform_set_drvdata (pdev, indio_dev);@@ -47,8 +74,15 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,mutex_init (&state->cmd_lock); + ret = cros_ec_get_host_cmd_version_mask(state->ec,
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c int cros_ec_sensors_core_init(struct · line 87
Quoted 10 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +7
-1+ ec->cmd_offset, +EC_CMD_MOTION_SENSE_CMD , + &ver_mask); +if (ret <0 ) +return ret; +/* Set up the host command structure. */ - state->msg->version =2 ; + state->msg->version =fls (ver_mask) -1 ;;
Unneeded semi colon.
Quoted 3 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +0
-0state->msg->command =EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
state->msg->outsize=sizeof(struct ec_params_motion_sense);