lkml.org 
[lkml]   [2019]   [Apr]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] platform/chrome: cros_ec_proto: Also return invalid command in cros_ec_cmd_xfer_status
Date
The commit 9798ac6d32c1 ("mfd: cros_ec: Add cros_ec_cmd_xfer_status()
helper") was introduced to remove duplicated code in several users of
the cros_ec_cmd_xfer function. The idea behind that commit is mask all
the EC errors as protocol error when the EC command fails, what is
really useful because as a user you probably don't care of the exact
error reported by the EC, you only want to know if the command succeeded
or not.

That works for most of the errors returned by the EC, but we might be
also interested on report the EC_RES_INVALID_COMMAND, which happens when
the command is not supported by the EC. An use case for this is when you
need to show/hide a sysfs attribute for a specific command and you don't
have a EC feature flag that tells you that the command is supported or
not.

While here, also document properly the cros_ec_cmd_xfer_status
function.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---

drivers/platform/chrome/cros_ec_proto.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index 97a068dff192..a4e0d3a6d891 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -478,6 +478,16 @@ int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
}
EXPORT_SYMBOL(cros_ec_cmd_xfer);

+/**
+ * cros_ec_cmd_xfer_status() - Send EC command.
+ * @ec_dev: EC device.
+ * @msg: EC message data for request and response.
+ *
+ * Return:
+ * 0 - OK
+ * -EINVAL - Invalid command.
+ * -EPROTO - Protocol error.
+ */
int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg)
{
@@ -486,6 +496,11 @@ int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
ret = cros_ec_cmd_xfer(ec_dev, msg);
if (ret < 0) {
dev_err(ec_dev->dev, "Command xfer error (err:%d)\n", ret);
+ } else if (msg->result == EC_RES_INVALID_COMMAND) {
+ dev_dbg(ec_dev->dev,
+ "Command %d not supported for this device\n",
+ msg->command);
+ return -EINVAL;
} else if (msg->result != EC_RES_SUCCESS) {
dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result);
return -EPROTO;
--
2.20.1
\
 
 \ /
  Last update: 2019-04-03 15:52    [W:0.161 / U:0.140 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site