diff options
| author | Nick Crews <ncrews@chromium.org> | 2019-02-08 19:37:17 -0500 |
|---|---|---|
| committer | Enric Balletbo i Serra <enric.balletbo@collabora.com> | 2019-02-21 15:35:59 -0500 |
| commit | 7b3d4f44abf0e7a1ba762c8a9c99a8b39ee0c8b1 (patch) | |
| tree | 59ed497376f624fad1530a06870f43d86cabce33 /include/linux/platform_data | |
| parent | 6b7cb2227d4d833aaccb3e98214015f2162d5bb0 (diff) | |
platform/chrome: Add new driver for Wilco EC
This EC is an incompatible variant of the typical Chrome OS embedded
controller. It uses the same low-level communication and a similar
protocol with some significant differences. The EC firmware does
not support the same mailbox commands so it is not registered as a
cros_ec device type. This commit exports the wilco_ec_mailbox()
function so that other modules can use it to communicate with the EC.
Signed-off-by: Duncan Laurie <dlaurie@google.com>
Signed-off-by: Nick Crews <ncrews@chromium.org>
[Fix the sparse warning: symbol 'wilco_ec_transfer' was not declared]
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
[Fix Kconfig dependencies for wilco_ec]
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Diffstat (limited to 'include/linux/platform_data')
| -rw-r--r-- | include/linux/platform_data/wilco-ec.h | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/include/linux/platform_data/wilco-ec.h b/include/linux/platform_data/wilco-ec.h new file mode 100644 index 000000000000..0feb4b520a54 --- /dev/null +++ b/include/linux/platform_data/wilco-ec.h | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * ChromeOS Wilco Embedded Controller | ||
| 4 | * | ||
| 5 | * Copyright 2018 Google LLC | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef WILCO_EC_H | ||
| 9 | #define WILCO_EC_H | ||
| 10 | |||
| 11 | #include <linux/device.h> | ||
| 12 | #include <linux/kernel.h> | ||
| 13 | |||
| 14 | /* Message flags for using the mailbox() interface */ | ||
| 15 | #define WILCO_EC_FLAG_NO_RESPONSE BIT(0) /* EC does not respond */ | ||
| 16 | #define WILCO_EC_FLAG_EXTENDED_DATA BIT(1) /* EC returns 256 data bytes */ | ||
| 17 | #define WILCO_EC_FLAG_RAW_REQUEST BIT(2) /* Do not trim request data */ | ||
| 18 | #define WILCO_EC_FLAG_RAW_RESPONSE BIT(3) /* Do not trim response data */ | ||
| 19 | #define WILCO_EC_FLAG_RAW (WILCO_EC_FLAG_RAW_REQUEST | \ | ||
| 20 | WILCO_EC_FLAG_RAW_RESPONSE) | ||
| 21 | |||
| 22 | /* Normal commands have a maximum 32 bytes of data */ | ||
| 23 | #define EC_MAILBOX_DATA_SIZE 32 | ||
| 24 | /* Extended commands have 256 bytes of response data */ | ||
| 25 | #define EC_MAILBOX_DATA_SIZE_EXTENDED 256 | ||
| 26 | |||
| 27 | /** | ||
| 28 | * struct wilco_ec_device - Wilco Embedded Controller handle. | ||
| 29 | * @dev: Device handle. | ||
| 30 | * @mailbox_lock: Mutex to ensure one mailbox command at a time. | ||
| 31 | * @io_command: I/O port for mailbox command. Provided by ACPI. | ||
| 32 | * @io_data: I/O port for mailbox data. Provided by ACPI. | ||
| 33 | * @io_packet: I/O port for mailbox packet data. Provided by ACPI. | ||
| 34 | * @data_buffer: Buffer used for EC communication. The same buffer | ||
| 35 | * is used to hold the request and the response. | ||
| 36 | * @data_size: Size of the data buffer used for EC communication. | ||
| 37 | */ | ||
| 38 | struct wilco_ec_device { | ||
| 39 | struct device *dev; | ||
| 40 | struct mutex mailbox_lock; | ||
| 41 | struct resource *io_command; | ||
| 42 | struct resource *io_data; | ||
| 43 | struct resource *io_packet; | ||
| 44 | void *data_buffer; | ||
| 45 | size_t data_size; | ||
| 46 | }; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * struct wilco_ec_request - Mailbox request message format. | ||
| 50 | * @struct_version: Should be %EC_MAILBOX_PROTO_VERSION | ||
| 51 | * @checksum: Sum of all bytes must be 0. | ||
| 52 | * @mailbox_id: Mailbox identifier, specifies the command set. | ||
| 53 | * @mailbox_version: Mailbox interface version %EC_MAILBOX_VERSION | ||
| 54 | * @reserved: Set to zero. | ||
| 55 | * @data_size: Length of request, data + last 2 bytes of the header. | ||
| 56 | * @command: Mailbox command code, unique for each mailbox_id set. | ||
| 57 | * @reserved_raw: Set to zero for most commands, but is used by | ||
| 58 | * some command types and for raw commands. | ||
| 59 | */ | ||
| 60 | struct wilco_ec_request { | ||
| 61 | u8 struct_version; | ||
| 62 | u8 checksum; | ||
| 63 | u16 mailbox_id; | ||
| 64 | u8 mailbox_version; | ||
| 65 | u8 reserved; | ||
| 66 | u16 data_size; | ||
| 67 | u8 command; | ||
| 68 | u8 reserved_raw; | ||
| 69 | } __packed; | ||
| 70 | |||
| 71 | /** | ||
| 72 | * struct wilco_ec_response - Mailbox response message format. | ||
| 73 | * @struct_version: Should be %EC_MAILBOX_PROTO_VERSION | ||
| 74 | * @checksum: Sum of all bytes must be 0. | ||
| 75 | * @result: Result code from the EC. Non-zero indicates an error. | ||
| 76 | * @data_size: Length of the response data buffer. | ||
| 77 | * @reserved: Set to zero. | ||
| 78 | * @mbox0: EC returned data at offset 0 is unused (always 0) so this byte | ||
| 79 | * is treated as part of the header instead of the data. | ||
| 80 | * @data: Response data buffer. Max size is %EC_MAILBOX_DATA_SIZE_EXTENDED. | ||
| 81 | */ | ||
| 82 | struct wilco_ec_response { | ||
| 83 | u8 struct_version; | ||
| 84 | u8 checksum; | ||
| 85 | u16 result; | ||
| 86 | u16 data_size; | ||
| 87 | u8 reserved[2]; | ||
| 88 | u8 mbox0; | ||
| 89 | u8 data[0]; | ||
| 90 | } __packed; | ||
| 91 | |||
| 92 | /** | ||
| 93 | * enum wilco_ec_msg_type - Message type to select a set of command codes. | ||
| 94 | * @WILCO_EC_MSG_LEGACY: Legacy EC messages for standard EC behavior. | ||
| 95 | * @WILCO_EC_MSG_PROPERTY: Get/Set/Sync EC controlled NVRAM property. | ||
| 96 | * @WILCO_EC_MSG_TELEMETRY_SHORT: 32 bytes of telemetry data provided by the EC. | ||
| 97 | * @WILCO_EC_MSG_TELEMETRY_LONG: 256 bytes of telemetry data provided by the EC. | ||
| 98 | */ | ||
| 99 | enum wilco_ec_msg_type { | ||
| 100 | WILCO_EC_MSG_LEGACY = 0x00f0, | ||
| 101 | WILCO_EC_MSG_PROPERTY = 0x00f2, | ||
| 102 | WILCO_EC_MSG_TELEMETRY_SHORT = 0x00f5, | ||
| 103 | WILCO_EC_MSG_TELEMETRY_LONG = 0x00f6, | ||
| 104 | }; | ||
| 105 | |||
| 106 | /** | ||
| 107 | * struct wilco_ec_message - Request and response message. | ||
| 108 | * @type: Mailbox message type. | ||
| 109 | * @flags: Message flags, e.g. %WILCO_EC_FLAG_NO_RESPONSE. | ||
| 110 | * @command: Mailbox command code. | ||
| 111 | * @result: Result code from the EC. Non-zero indicates an error. | ||
| 112 | * @request_size: Number of bytes to send to the EC. | ||
| 113 | * @request_data: Buffer containing the request data. | ||
| 114 | * @response_size: Number of bytes expected from the EC. | ||
| 115 | * This is 32 by default and 256 if the flag | ||
| 116 | * is set for %WILCO_EC_FLAG_EXTENDED_DATA | ||
| 117 | * @response_data: Buffer containing the response data, should be | ||
| 118 | * response_size bytes and allocated by caller. | ||
| 119 | */ | ||
| 120 | struct wilco_ec_message { | ||
| 121 | enum wilco_ec_msg_type type; | ||
| 122 | u8 flags; | ||
| 123 | u8 command; | ||
| 124 | u8 result; | ||
| 125 | size_t request_size; | ||
| 126 | void *request_data; | ||
| 127 | size_t response_size; | ||
| 128 | void *response_data; | ||
| 129 | }; | ||
| 130 | |||
| 131 | /** | ||
| 132 | * wilco_ec_mailbox() - Send request to the EC and receive the response. | ||
| 133 | * @ec: Wilco EC device. | ||
| 134 | * @msg: Wilco EC message. | ||
| 135 | * | ||
| 136 | * Return: Number of bytes received or negative error code on failure. | ||
| 137 | */ | ||
| 138 | int wilco_ec_mailbox(struct wilco_ec_device *ec, struct wilco_ec_message *msg); | ||
| 139 | |||
| 140 | #endif /* WILCO_EC_H */ | ||
