diff options
-rw-r--r-- | drivers/mfd/cros_ec.c | 18 | ||||
-rw-r--r-- | drivers/mfd/cros_ec_i2c.c | 8 | ||||
-rw-r--r-- | drivers/mfd/cros_ec_spi.c | 19 | ||||
-rw-r--r-- | include/linux/mfd/cros_ec.h | 12 |
4 files changed, 39 insertions, 18 deletions
diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c index 4851ed2fbe31..83e30c663578 100644 --- a/drivers/mfd/cros_ec.c +++ b/drivers/mfd/cros_ec.c | |||
@@ -44,6 +44,24 @@ int cros_ec_prepare_tx(struct cros_ec_device *ec_dev, | |||
44 | } | 44 | } |
45 | EXPORT_SYMBOL(cros_ec_prepare_tx); | 45 | EXPORT_SYMBOL(cros_ec_prepare_tx); |
46 | 46 | ||
47 | int cros_ec_check_result(struct cros_ec_device *ec_dev, | ||
48 | struct cros_ec_command *msg) | ||
49 | { | ||
50 | switch (msg->result) { | ||
51 | case EC_RES_SUCCESS: | ||
52 | return 0; | ||
53 | case EC_RES_IN_PROGRESS: | ||
54 | dev_dbg(ec_dev->dev, "command 0x%02x in progress\n", | ||
55 | msg->command); | ||
56 | return -EAGAIN; | ||
57 | default: | ||
58 | dev_dbg(ec_dev->dev, "command 0x%02x returned %d\n", | ||
59 | msg->command, msg->result); | ||
60 | return 0; | ||
61 | } | ||
62 | } | ||
63 | EXPORT_SYMBOL(cros_ec_check_result); | ||
64 | |||
47 | static irqreturn_t ec_irq_thread(int irq, void *data) | 65 | static irqreturn_t ec_irq_thread(int irq, void *data) |
48 | { | 66 | { |
49 | struct cros_ec_device *ec_dev = data; | 67 | struct cros_ec_device *ec_dev = data; |
diff --git a/drivers/mfd/cros_ec_i2c.c b/drivers/mfd/cros_ec_i2c.c index 5bb32f5550b3..189e7d1d7742 100644 --- a/drivers/mfd/cros_ec_i2c.c +++ b/drivers/mfd/cros_ec_i2c.c | |||
@@ -92,12 +92,10 @@ static int cros_ec_cmd_xfer_i2c(struct cros_ec_device *ec_dev, | |||
92 | } | 92 | } |
93 | 93 | ||
94 | /* check response error code */ | 94 | /* check response error code */ |
95 | if (i2c_msg[1].buf[0]) { | 95 | msg->result = i2c_msg[1].buf[0]; |
96 | dev_warn(ec_dev->dev, "command 0x%02x returned an error %d\n", | 96 | ret = cros_ec_check_result(ec_dev, msg); |
97 | msg->command, i2c_msg[1].buf[0]); | 97 | if (ret) |
98 | ret = -EINVAL; | ||
99 | goto done; | 98 | goto done; |
100 | } | ||
101 | 99 | ||
102 | /* copy response packet payload and compute checksum */ | 100 | /* copy response packet payload and compute checksum */ |
103 | sum = in_buf[0] + in_buf[1]; | 101 | sum = in_buf[0] + in_buf[1]; |
diff --git a/drivers/mfd/cros_ec_spi.c b/drivers/mfd/cros_ec_spi.c index 6e929b5f3bd3..da1da05cd546 100644 --- a/drivers/mfd/cros_ec_spi.c +++ b/drivers/mfd/cros_ec_spi.c | |||
@@ -285,21 +285,14 @@ static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev, | |||
285 | goto exit; | 285 | goto exit; |
286 | } | 286 | } |
287 | 287 | ||
288 | /* check response error code */ | ||
289 | ptr = ec_dev->din; | 288 | ptr = ec_dev->din; |
290 | if (ptr[0]) { | 289 | |
291 | if (ptr[0] == EC_RES_IN_PROGRESS) { | 290 | /* check response error code */ |
292 | dev_dbg(ec_dev->dev, "command 0x%02x in progress\n", | 291 | ec_msg->result = ptr[0]; |
293 | ec_msg->command); | 292 | ret = cros_ec_check_result(ec_dev, ec_msg); |
294 | ret = -EAGAIN; | 293 | if (ret) |
295 | goto exit; | ||
296 | } | ||
297 | dev_warn(ec_dev->dev, "command 0x%02x returned an error %d\n", | ||
298 | ec_msg->command, ptr[0]); | ||
299 | debug_packet(ec_dev->dev, "in_err", ptr, len); | ||
300 | ret = -EINVAL; | ||
301 | goto exit; | 294 | goto exit; |
302 | } | 295 | |
303 | len = ptr[1]; | 296 | len = ptr[1]; |
304 | sum = ptr[0] + ptr[1]; | 297 | sum = ptr[0] + ptr[1]; |
305 | if (len > ec_msg->insize) { | 298 | if (len > ec_msg->insize) { |
diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h index 60c088055f3a..1f79f162abe4 100644 --- a/include/linux/mfd/cros_ec.h +++ b/include/linux/mfd/cros_ec.h | |||
@@ -143,6 +143,18 @@ int cros_ec_prepare_tx(struct cros_ec_device *ec_dev, | |||
143 | struct cros_ec_command *msg); | 143 | struct cros_ec_command *msg); |
144 | 144 | ||
145 | /** | 145 | /** |
146 | * cros_ec_check_result - Check ec_msg->result | ||
147 | * | ||
148 | * This is used by ChromeOS EC drivers to check the ec_msg->result for | ||
149 | * errors and to warn about them. | ||
150 | * | ||
151 | * @ec_dev: EC device | ||
152 | * @msg: Message to check | ||
153 | */ | ||
154 | int cros_ec_check_result(struct cros_ec_device *ec_dev, | ||
155 | struct cros_ec_command *msg); | ||
156 | |||
157 | /** | ||
146 | * cros_ec_remove - Remove a ChromeOS EC | 158 | * cros_ec_remove - Remove a ChromeOS EC |
147 | * | 159 | * |
148 | * Call this to deregister a ChromeOS EC, then clean up any private data. | 160 | * Call this to deregister a ChromeOS EC, then clean up any private data. |