summaryrefslogtreecommitdiff
path: root/include/linux/platform_data/wilco-ec.h
diff options
context:
space:
mode:
authorNick Crews <ncrews@chromium.org>2019-04-04 16:54:15 -0600
committerEnric Balletbo i Serra <enric.balletbo@collabora.com>2019-04-15 16:07:42 +0200
commit14e14aaf61321ba30d0bbdf4c4668f260ca1141c (patch)
treee410541fbd7aa0434df158a51a5d9f21baf4f112 /include/linux/platform_data/wilco-ec.h
parent94d4e7af14a1170e34cf082d92e4c02de9e9fb88 (diff)
platform/chrome: wilco_ec: Standardize mailbox interface
The current API for the wilco EC mailbox interface is bad. It assumes that most messages sent to the EC follow a similar structure, with a command byte in MBOX[0], followed by a junk byte, followed by actual data. This doesn't happen in several cases, such as setting the RTC time, using the raw debugfs interface, and reading or writing properties such as the Peak Shift policy (this last to be submitted soon). Similarly for the response message from the EC, the current interface assumes that the first byte of data is always 0, and the second byte is unused. However, in both setting and getting the RTC time, in the debugfs interface, and for reading and writing properties, this isn't true. The current way to resolve this is to use WILCO_EC_FLAG_RAW* flags to specify when and when not to skip these initial bytes in the sent and received message. They are confusing and used so much that they are normal, and not exceptions. In addition, the first byte of response in the debugfs interface is still always skipped, which is weird, since this raw interface should be giving the entire result. Additionally, sent messages assume the first byte is a command, and so struct wilco_ec_message contains the "command" field. In setting or getting properties however, the first byte is not a command, and so this field has to be filled with a byte that isn't actually a command. This is again inconsistent. wilco_ec_message contains a result field as well, copied from wilco_ec_response->result. The message result field should be removed: if the message fails, the cause is already logged, and the callers are alerted. They will never care about the actual state of the result flag. These flags and different cases make the wilco_ec_transfer() function, used in wilco_ec_mailbox(), really gross, dealing with a bunch of different cases. It's difficult to figure out what it is doing. Finally, making these assumptions about the structure of a message make it so that the messages do not correspond well with the specification for the EC's mailbox interface. For instance, this interface specification may say that MBOX[9] in the received message contains some information, but the calling code needs to remember that the first byte of response is always skipped, and because it didn't set the RESPONSE_RAW flag, the next byte is also skipped, so this information is actually contained within wilco_ec_message->response_data[7]. This makes it difficult to maintain this code in the future. To fix these problems this patch standardizes the mailbox interface by: - Removing the WILCO_EC_FLAG_RAW* flags - Removing the command and reserved_raw bytes from wilco_ec_request - Removing the mbox0 byte from wilco_ec_response - Simplifying wilco_ec_transfer() because of these changes - Gives the callers of wilco_ec_mailbox() the responsibility of exactly and consistently defining the structure of the mailbox request and response - Removing command and result from wilco_ec_message. This results in the reduction of total code, and makes it much more maintainable and understandable. Signed-off-by: Nick Crews <ncrews@chromium.org> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Diffstat (limited to 'include/linux/platform_data/wilco-ec.h')
-rw-r--r--include/linux/platform_data/wilco-ec.h22
1 files changed, 2 insertions, 20 deletions
diff --git a/include/linux/platform_data/wilco-ec.h b/include/linux/platform_data/wilco-ec.h
index 446473a46b88..1ff224793c99 100644
--- a/include/linux/platform_data/wilco-ec.h
+++ b/include/linux/platform_data/wilco-ec.h
@@ -14,10 +14,6 @@
/* Message flags for using the mailbox() interface */
#define WILCO_EC_FLAG_NO_RESPONSE BIT(0) /* EC does not respond */
#define WILCO_EC_FLAG_EXTENDED_DATA BIT(1) /* EC returns 256 data bytes */
-#define WILCO_EC_FLAG_RAW_REQUEST BIT(2) /* Do not trim request data */
-#define WILCO_EC_FLAG_RAW_RESPONSE BIT(3) /* Do not trim response data */
-#define WILCO_EC_FLAG_RAW (WILCO_EC_FLAG_RAW_REQUEST | \
- WILCO_EC_FLAG_RAW_RESPONSE)
/* Normal commands have a maximum 32 bytes of data */
#define EC_MAILBOX_DATA_SIZE 32
@@ -56,10 +52,7 @@ struct wilco_ec_device {
* @mailbox_id: Mailbox identifier, specifies the command set.
* @mailbox_version: Mailbox interface version %EC_MAILBOX_VERSION
* @reserved: Set to zero.
- * @data_size: Length of request, data + last 2 bytes of the header.
- * @command: Mailbox command code, unique for each mailbox_id set.
- * @reserved_raw: Set to zero for most commands, but is used by
- * some command types and for raw commands.
+ * @data_size: Length of following data.
*/
struct wilco_ec_request {
u8 struct_version;
@@ -68,8 +61,6 @@ struct wilco_ec_request {
u8 mailbox_version;
u8 reserved;
u16 data_size;
- u8 command;
- u8 reserved_raw;
} __packed;
/**
@@ -79,8 +70,6 @@ struct wilco_ec_request {
* @result: Result code from the EC. Non-zero indicates an error.
* @data_size: Length of the response data buffer.
* @reserved: Set to zero.
- * @mbox0: EC returned data at offset 0 is unused (always 0) so this byte
- * is treated as part of the header instead of the data.
* @data: Response data buffer. Max size is %EC_MAILBOX_DATA_SIZE_EXTENDED.
*/
struct wilco_ec_response {
@@ -89,7 +78,6 @@ struct wilco_ec_response {
u16 result;
u16 data_size;
u8 reserved[2];
- u8 mbox0;
u8 data[0];
} __packed;
@@ -111,21 +99,15 @@ enum wilco_ec_msg_type {
* struct wilco_ec_message - Request and response message.
* @type: Mailbox message type.
* @flags: Message flags, e.g. %WILCO_EC_FLAG_NO_RESPONSE.
- * @command: Mailbox command code.
- * @result: Result code from the EC. Non-zero indicates an error.
* @request_size: Number of bytes to send to the EC.
* @request_data: Buffer containing the request data.
- * @response_size: Number of bytes expected from the EC.
- * This is 32 by default and 256 if the flag
- * is set for %WILCO_EC_FLAG_EXTENDED_DATA
+ * @response_size: Number of bytes to read from EC.
* @response_data: Buffer containing the response data, should be
* response_size bytes and allocated by caller.
*/
struct wilco_ec_message {
enum wilco_ec_msg_type type;
u8 flags;
- u8 command;
- u8 result;
size_t request_size;
void *request_data;
size_t response_size;