platform/chrome: cros_ec_proto: Update cros_ec_cmd_xfer() call-sites
Subsystems (2)
PATCH 1/2 platform/chrome: cros_ec_proto: Update cros_ec_cmd_xfer() call-sites
Since all the other call-sites of cros_ec_cmd_xfer() have been converted to use cros_ec_cmd_xfer_status() instead, update the remaining call-sites to prepare for the merge of cros_ec_cmd_xfer() into cros_ec_cmd_xfer_status().
As part of this update, change the error handling inside cros_ec_get_sensor_count() such that the legacy LPC interface is tried on all error values, not just when msg->result != EC_RESULT_SUCCESS.
--- drivers/platform/chrome/cros_ec_proto.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/platform/chrome/cros_ec_proto.c +4 -11
@@ -650,7 +650,7 @@ static int get_next_event_xfer(struct cros_ec_device *ec_dev, msg->insize = size; msg->outsize =0 ; - ret =cros_ec_cmd_xfer (ec_dev, msg); + ret =cros_ec_cmd_xfer_status (ec_dev, msg);if (ret >0 ) { ec_dev->event_size = ret -1 ; ec_dev->event_data = *event;
@@ -694,7 +694,7 @@ static int get_keyboard_state_event(struct cros_ec_device *ec_dev) msg->insize =sizeof (ec_dev->event_data.data); msg->outsize =0 ; - ec_dev->event_size =cros_ec_cmd_xfer (ec_dev, msg); + ec_dev->event_size =cros_ec_cmd_xfer_status (ec_dev, msg); ec_dev->event_data.event_type =EC_MKBP_EVENT_KEY_MATRIX ;memcpy (&ec_dev->event_data.data, msg->data,sizeof (ec_dev->event_data.data));
@@ -883,11 +883,9 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec) params = (struct ec_params_motion_sense *)msg->data; params->cmd =MOTIONSENSE_CMD_DUMP ; - ret =cros_ec_cmd_xfer (ec->ec_dev, msg); + ret =cros_ec_cmd_xfer_status (ec->ec_dev, msg);if (ret <0 ) { sensor_count = ret; - }else if (msg->result !=EC_RES_SUCCESS ) { - sensor_count = -EPROTO ; }else { resp = (struct ec_response_motion_sense *)msg->data; sensor_count = resp->dump.sensor_count;
@@ -898,9 +896,7 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)* Check legacy mode: Let's find out if sensors are accessible * via LPC interface. */ -if (sensor_count == -EPROTO && - ec->cmd_offset ==0 && - ec_dev->cmd_readmem) { +if (sensor_count <0 && ec->cmd_offset ==0 && ec_dev->cmd_readmem) { ret = ec_dev->cmd_readmem (ec_dev,EC_MEMMAP_ACC_STATUS ,1 , &status); if (ret >= 0 &&
@@ -915,9 +911,6 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)*/ sensor_count =0 ; } - }else if (sensor_count == -EPROTO ) { -/* EC responded, but does not understand DUMP command. */ - sensor_count =0 ; }return sensor_count; }
Signature · 1 line
2.28.0.526.ge36021eeef-goog
PATCH 2/2 platform/chrome: cros_ec_proto: Drop cros_ec_cmd_xfer()
Since cros_ec_cmd_xfer_status() now returns Linux error codes and all other files use that command, remove the now-unused function cros_ec_cmd_xfer().
--- drivers/platform/chrome/cros_ec_proto.c | 44 +++++++------------------ 1 file changed, 11 insertions(+), 33 deletions(-)
drivers/platform/chrome/cros_ec_proto.c +11 -33
@@ -549,19 +549,22 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)EXPORT_SYMBOL (cros_ec_query_all);/** -* cros_ec_cmd_xfer() - Send a command to the ChromeOS EC. +* cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC. * @ec_dev: EC device. * @msg: Message to write. * -* Call this to send a command to the ChromeOS EC. This should be used -* instead of calling the EC's cmd_xfer() callback directly. +* Call this to send a command to the ChromeOS EC. This should be used instead of calling the EC's +* cmd_xfer() callback directly. It returns success status only if both the command was transmitted +* successfully and the EC replied with success status. * -* Return: 0 on success or negative error code. +* Return: +* >=0 - The number of bytes transferred +* <0 - Linux error code */ -static int cros_ec_cmd_xfer (struct cros_ec_device *ec_dev, +int cros_ec_cmd_xfer_status (struct cros_ec_device *ec_dev,struct cros_ec_command *msg) { -int ret; +int ret, mapped;mutex_lock (&ec_dev->lock);if (ec_dev->proto_version ==EC_PROTO_VERSION_UNKNOWN ) {
@@ -598,42 +601,17 @@ static int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,return -EMSGSIZE ; } } + ret =send_command (ec_dev, msg);mutex_unlock (&ec_dev->lock); -return ret; -} - -/** -* cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC. -* @ec_dev: EC device. -* @msg: Message to write. -* -* This function is identical to cros_ec_cmd_xfer, except it returns success -* status only if both the command was transmitted successfully and the EC -* replied with success status. It's not necessary to check msg->result when -* using this function. -* -* Return: -* >=0 - The number of bytes transferred -* <0 - Linux error code -*/ -int cros_ec_cmd_xfer_status (struct cros_ec_device *ec_dev, -struct cros_ec_command *msg) -{ -int ret, mapped; - - ret =cros_ec_cmd_xfer (ec_dev, msg); -if (ret <0 ) { -dev_err (ec_dev->dev,"Command xfer error (err:%d)\n" , ret); -return ret; - } mapped =cros_ec_map_error (msg->result);if (mapped) {dev_dbg (ec_dev->dev,"Command result (err: %d [%d])\n" , msg->result, mapped); ret = mapped; } +return ret; }EXPORT_SYMBOL (cros_ec_cmd_xfer_status);
Signature · 1 line
2.28.0.526.ge36021eeef-goog
Re: [PATCH 2/2] platform/chrome: cros_ec_proto: Drop cros_ec_cmd_xfer()
Hi Prashant,
Quoted 5 lines · Prashant Malani
Since
cros_ec_cmd_xfer_status()now returns Linux error codes and all other files use that command, remove the now-unused functioncros_ec_cmd_xfer().Signed-off-by Prashant Malani <[email protected]>
Applied for 5.10
Thanks,
Enric
Quoted 83 lines
--- drivers/platform/chrome/cros_ec_proto.c | 44 +++++++------------------ 1 file changed, 11 insertions(+), 33 deletions(-)drivers/platform/chrome/cros_ec_proto.c +11
-33@@ -549,19 +549,22 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)EXPORT_SYMBOL (cros_ec_query_all);/** -* cros_ec_cmd_xfer() - Send a command to the ChromeOS EC. +* cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC. * @ec_dev: EC device. * @msg: Message to write. * -* Call this to send a command to the ChromeOS EC. This should be used -* instead of calling the EC's cmd_xfer() callback directly. +* Call this to send a command to the ChromeOS EC. This should be used instead of calling the EC's +* cmd_xfer() callback directly. It returns success status only if both the command was transmitted +* successfully and the EC replied with success status. * -* Return: 0 on success or negative error code. +* Return: +* >=0 - The number of bytes transferred +* <0 - Linux error code */ -static int cros_ec_cmd_xfer (struct cros_ec_device *ec_dev, +int cros_ec_cmd_xfer_status (struct cros_ec_device *ec_dev,struct cros_ec_command *msg) { -int ret; +int ret, mapped;mutex_lock (&ec_dev->lock);if (ec_dev->proto_version ==EC_PROTO_VERSION_UNKNOWN ) {@@ -598,42 +601,17 @@ static int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,return -EMSGSIZE ; } } + ret =send_command (ec_dev, msg);mutex_unlock (&ec_dev->lock); -return ret; -} - -/** -* cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC. -* @ec_dev: EC device. -* @msg: Message to write. -* -* This function is identical to cros_ec_cmd_xfer, except it returns success -* status only if both the command was transmitted successfully and the EC -* replied with success status. It's not necessary to check msg->result when -* using this function. -* -* Return: -* >=0 - The number of bytes transferred -* <0 - Linux error code -*/ -int cros_ec_cmd_xfer_status (struct cros_ec_device *ec_dev, -struct cros_ec_command *msg) -{ -int ret, mapped; - - ret =cros_ec_cmd_xfer (ec_dev, msg); -if (ret <0 ) { -dev_err (ec_dev->dev,"Command xfer error (err:%d)\n" , ret); -return ret; - } mapped =cros_ec_map_error (msg->result);if (mapped) {dev_dbg (ec_dev->dev,"Command result (err: %d [%d])\n" , msg->result, mapped); ret = mapped; } +return ret; }EXPORT_SYMBOL (cros_ec_cmd_xfer_status);
Hi Prashant,
Thank you for your patch.
Quoted 10 lines · Prashant Malani
Since all the other call-sites of
cros_ec_cmd_xfer()have been converted to usecros_ec_cmd_xfer_status()instead, update the remaining call-sites to prepare for the merge ofcros_ec_cmd_xfer()intocros_ec_cmd_xfer_status().As part of this update, change the error handling inside
cros_ec_get_sensor_count()such that the legacy LPC interface is tried on all error values, not just whenmsg->result!=EC_RESULT_SUCCESS.Signed-off-by Prashant Malani <[email protected]>
Gwendal, I'd like to hear from you regarding this patch as you're the one that know most about the corner cases for the sensors in different hardware. Could you take a look and give us your Reviewed tag if all is good?
Thanks,
Enric
Quoted 61 lines
--- drivers/platform/chrome/cros_ec_proto.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)drivers/platform/chrome/cros_ec_proto.c +4
-11@@ -650,7 +650,7 @@ static int get_next_event_xfer(struct cros_ec_device *ec_dev, msg->insize = size; msg->outsize =0 ; - ret =cros_ec_cmd_xfer (ec_dev, msg); + ret =cros_ec_cmd_xfer_status (ec_dev, msg);if (ret >0 ) { ec_dev->event_size = ret -1 ; ec_dev->event_data = *event;@@ -694,7 +694,7 @@ static int get_keyboard_state_event(struct cros_ec_device *ec_dev) msg->insize =sizeof (ec_dev->event_data.data); msg->outsize =0 ; - ec_dev->event_size =cros_ec_cmd_xfer (ec_dev, msg); + ec_dev->event_size =cros_ec_cmd_xfer_status (ec_dev, msg); ec_dev->event_data.event_type =EC_MKBP_EVENT_KEY_MATRIX ;memcpy (&ec_dev->event_data.data, msg->data,sizeof (ec_dev->event_data.data));@@ -883,11 +883,9 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec) params = (struct ec_params_motion_sense *)msg->data; params->cmd =MOTIONSENSE_CMD_DUMP ; - ret =cros_ec_cmd_xfer (ec->ec_dev, msg); + ret =cros_ec_cmd_xfer_status (ec->ec_dev, msg);if (ret <0 ) { sensor_count = ret; - }else if (msg->result !=EC_RES_SUCCESS ) { - sensor_count = -EPROTO ; }else { resp = (struct ec_response_motion_sense *)msg->data; sensor_count = resp->dump.sensor_count;@@ -898,9 +896,7 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)* Check legacy mode: Let's find out if sensors are accessible * via LPC interface. */ -if (sensor_count == -EPROTO && - ec->cmd_offset ==0 && - ec_dev->cmd_readmem) { +if (sensor_count <0 && ec->cmd_offset ==0 && ec_dev->cmd_readmem) { ret = ec_dev->cmd_readmem (ec_dev,EC_MEMMAP_ACC_STATUS ,1 , &status); if (ret >= 0 &&@@ -915,9 +911,6 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)*/ sensor_count =0 ; } - }else if (sensor_count == -EPROTO ) { -/* EC responded, but does not understand DUMP command. */ - sensor_count =0 ; }return sensor_count; }
Thanks Enric,
Quoted 15 lines · Enric Balletbo i Serra
Hi Prashant,
Thank you for your patch.
Quoted 9 lines · Prashant Malani
Since all the other call-sites of
cros_ec_cmd_xfer()have been converted to usecros_ec_cmd_xfer_status()instead, update the remaining call-sites to prepare for the merge ofcros_ec_cmd_xfer()intocros_ec_cmd_xfer_status().As part of this update, change the error handling inside
cros_ec_get_sensor_count()such that the legacy LPC interface is tried on all error values, not just whenmsg->result!=EC_RESULT_SUCCESS.
Quoted 6 lines
Quoted 1 line
Signed-off-by Prashant Malani <[email protected]>Gwendal, I'd like to hear from you regarding this patch as you're the one that know most about the corner cases for the sensors in different hardware. Could you take a look and give us your Reviewed tag if all is good?
Gwendal, could you kindly take a look? Thanks!
Quoted 65 lines
Thanks,
Enric
Quoted 61 lines
--- drivers/platform/chrome/cros_ec_proto.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)drivers/platform/chrome/cros_ec_proto.c +4
-11@@ -650,7 +650,7 @@ static int get_next_event_xfer(struct cros_ec_device *ec_dev, msg->insize = size; msg->outsize =0 ; - ret =cros_ec_cmd_xfer (ec_dev, msg); + ret =cros_ec_cmd_xfer_status (ec_dev, msg);if (ret >0 ) { ec_dev->event_size = ret -1 ; ec_dev->event_data = *event;@@ -694,7 +694,7 @@ static int get_keyboard_state_event(struct cros_ec_device *ec_dev) msg->insize =sizeof (ec_dev->event_data.data); msg->outsize =0 ; - ec_dev->event_size =cros_ec_cmd_xfer (ec_dev, msg); + ec_dev->event_size =cros_ec_cmd_xfer_status (ec_dev, msg); ec_dev->event_data.event_type =EC_MKBP_EVENT_KEY_MATRIX ;memcpy (&ec_dev->event_data.data, msg->data,sizeof (ec_dev->event_data.data));@@ -883,11 +883,9 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec) params = (struct ec_params_motion_sense *)msg->data; params->cmd =MOTIONSENSE_CMD_DUMP ; - ret =cros_ec_cmd_xfer (ec->ec_dev, msg); + ret =cros_ec_cmd_xfer_status (ec->ec_dev, msg);if (ret <0 ) { sensor_count = ret; - }else if (msg->result !=EC_RES_SUCCESS ) { - sensor_count = -EPROTO ; }else { resp = (struct ec_response_motion_sense *)msg->data; sensor_count = resp->dump.sensor_count;@@ -898,9 +896,7 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)* Check legacy mode: Let's find out if sensors are accessible * via LPC interface. */ -if (sensor_count == -EPROTO && - ec->cmd_offset ==0 && - ec_dev->cmd_readmem) { +if (sensor_count <0 && ec->cmd_offset ==0 && ec_dev->cmd_readmem) { ret = ec_dev->cmd_readmem (ec_dev,EC_MEMMAP_ACC_STATUS ,1 , &status); if (ret >= 0 &&@@ -915,9 +911,6 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)*/ sensor_count =0 ; } - }else if (sensor_count == -EPROTO ) { -/* EC responded, but does not understand DUMP command. */ - sensor_count =0 ; }return sensor_count; }
Quoted 21 lines · Prashant Malani
Thanks Enric,
Quoted 16 lines · Enric Balletbo i Serra
Hi Prashant,
Thank you for your patch.
Quoted 10 lines · Prashant Malani
Since all the other call-sites of
cros_ec_cmd_xfer()have been converted to usecros_ec_cmd_xfer_status()instead, update the remaining call-sites to prepare for the merge ofcros_ec_cmd_xfer()intocros_ec_cmd_xfer_status().As part of this update, change the error handling inside
cros_ec_get_sensor_count()such that the legacy LPC interface is tried on all error values, not just whenmsg->result!=EC_RESULT_SUCCESS.Signed-off-by Prashant Malani <[email protected]>
There is a slight change in API in cros_ec_get_sensor_count(): it will return a negative number of sensors when there
are no sensors on arm platform when MOTIONSENSE_CMD_DUMP is not supported (typical for sensorless chromebook) instead of 0. However, this is not a problem when probing the EC as we ignore errors only looking for cros_ec_get_sensor_count() returning a positive number of sensors.
Quoted 72 lines
Quoted 5 lines
Gwendal, I'd like to hear from you regarding this patch as you're the one that know most about the corner cases for the sensors in different hardware. Could you take a look and give us your Reviewed tag if all is good?
Gwendal, could you kindly take a look? Thanks!
Quoted 65 lines
Thanks,
Enric
Quoted 61 lines
--- drivers/platform/chrome/cros_ec_proto.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)drivers/platform/chrome/cros_ec_proto.c +4
-11@@ -650,7 +650,7 @@ static int get_next_event_xfer(struct cros_ec_device *ec_dev, msg->insize = size; msg->outsize =0 ; - ret =cros_ec_cmd_xfer (ec_dev, msg); + ret =cros_ec_cmd_xfer_status (ec_dev, msg);if (ret >0 ) { ec_dev->event_size = ret -1 ; ec_dev->event_data = *event;@@ -694,7 +694,7 @@ static int get_keyboard_state_event(struct cros_ec_device *ec_dev) msg->insize =sizeof (ec_dev->event_data.data); msg->outsize =0 ; - ec_dev->event_size =cros_ec_cmd_xfer (ec_dev, msg); + ec_dev->event_size =cros_ec_cmd_xfer_status (ec_dev, msg); ec_dev->event_data.event_type =EC_MKBP_EVENT_KEY_MATRIX ;memcpy (&ec_dev->event_data.data, msg->data,sizeof (ec_dev->event_data.data));@@ -883,11 +883,9 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec) params = (struct ec_params_motion_sense *)msg->data; params->cmd =MOTIONSENSE_CMD_DUMP ; - ret =cros_ec_cmd_xfer (ec->ec_dev, msg); + ret =cros_ec_cmd_xfer_status (ec->ec_dev, msg);if (ret <0 ) { sensor_count = ret; - }else if (msg->result !=EC_RES_SUCCESS ) { - sensor_count = -EPROTO ; }else { resp = (struct ec_response_motion_sense *)msg->data; sensor_count = resp->dump.sensor_count;@@ -898,9 +896,7 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)* Check legacy mode: Let's find out if sensors are accessible * via LPC interface. */ -if (sensor_count == -EPROTO && - ec->cmd_offset ==0 && - ec_dev->cmd_readmem) { +if (sensor_count <0 && ec->cmd_offset ==0 && ec_dev->cmd_readmem) { ret = ec_dev->cmd_readmem (ec_dev,EC_MEMMAP_ACC_STATUS ,1 , &status); if (ret >= 0 &&@@ -915,9 +911,6 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)*/ sensor_count =0 ; } - }else if (sensor_count == -EPROTO ) { -/* EC responded, but does not understand DUMP command. */ - sensor_count =0 ; }return sensor_count; }
Hi Prashant and Gwendal,
Quoted 25 lines · Gwendal Grignou
Quoted 21 lines · Prashant Malani
Thanks Enric,
Quoted 16 lines · Enric Balletbo i Serra
Hi Prashant,
Thank you for your patch.
Quoted 10 lines · Prashant Malani
Since all the other call-sites of
cros_ec_cmd_xfer()have been converted to usecros_ec_cmd_xfer_status()instead, update the remaining call-sites to prepare for the merge ofcros_ec_cmd_xfer()intocros_ec_cmd_xfer_status().As part of this update, change the error handling inside
cros_ec_get_sensor_count()such that the legacy LPC interface is tried on all error values, not just whenmsg->result!=EC_RESULT_SUCCESS.Signed-off-by Prashant Malani <[email protected]>Reviewed-by Gwendal Grignou <[email protected]>Tested-by Gwendal Grignou <[email protected]>
Quoted 8 lines
There is a slight change in API in
cros_ec_get_sensor_count(): it will return a negative number of sensors when there
are no sensors on arm platform whenMOTIONSENSE_CMD_DUMPis not supported (typical for sensorless chromebook) instead of 0. However, this is not a problem when probing the EC as we ignore errors only looking forcros_ec_get_sensor_count()returning a positive number of sensors.
I added this comment to the commit log and applied the patch for 5.10.
Thanks,
Enric
Quoted 72 lines
Quoted 72 lines
Quoted 5 lines
Gwendal, I'd like to hear from you regarding this patch as you're the one that know most about the corner cases for the sensors in different hardware. Could you take a look and give us your Reviewed tag if all is good?
Gwendal, could you kindly take a look? Thanks!
Quoted 65 lines
Thanks,
Enric
Quoted 61 lines
--- drivers/platform/chrome/cros_ec_proto.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)drivers/platform/chrome/cros_ec_proto.c +4
-11@@ -650,7 +650,7 @@ static int get_next_event_xfer(struct cros_ec_device *ec_dev, msg->insize = size; msg->outsize =0 ; - ret =cros_ec_cmd_xfer (ec_dev, msg); + ret =cros_ec_cmd_xfer_status (ec_dev, msg);if (ret >0 ) { ec_dev->event_size = ret -1 ; ec_dev->event_data = *event;@@ -694,7 +694,7 @@ static int get_keyboard_state_event(struct cros_ec_device *ec_dev) msg->insize =sizeof (ec_dev->event_data.data); msg->outsize =0 ; - ec_dev->event_size =cros_ec_cmd_xfer (ec_dev, msg); + ec_dev->event_size =cros_ec_cmd_xfer_status (ec_dev, msg); ec_dev->event_data.event_type =EC_MKBP_EVENT_KEY_MATRIX ;memcpy (&ec_dev->event_data.data, msg->data,sizeof (ec_dev->event_data.data));@@ -883,11 +883,9 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec) params = (struct ec_params_motion_sense *)msg->data; params->cmd =MOTIONSENSE_CMD_DUMP ; - ret =cros_ec_cmd_xfer (ec->ec_dev, msg); + ret =cros_ec_cmd_xfer_status (ec->ec_dev, msg);if (ret <0 ) { sensor_count = ret; - }else if (msg->result !=EC_RES_SUCCESS ) { - sensor_count = -EPROTO ; }else { resp = (struct ec_response_motion_sense *)msg->data; sensor_count = resp->dump.sensor_count;@@ -898,9 +896,7 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)* Check legacy mode: Let's find out if sensors are accessible * via LPC interface. */ -if (sensor_count == -EPROTO && - ec->cmd_offset ==0 && - ec_dev->cmd_readmem) { +if (sensor_count <0 && ec->cmd_offset ==0 && ec_dev->cmd_readmem) { ret = ec_dev->cmd_readmem (ec_dev,EC_MEMMAP_ACC_STATUS ,1 , &status); if (ret >= 0 &&@@ -915,9 +911,6 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)*/ sensor_count =0 ; } - }else if (sensor_count == -EPROTO ) { -/* EC responded, but does not understand DUMP command. */ - sensor_count =0 ; }return sensor_count; }