Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * ChromeOS EC multi-function device |
| 3 | * |
| 4 | * Copyright (C) 2012 Google, Inc |
| 5 | * |
| 6 | * This software is licensed under the terms of the GNU General Public |
| 7 | * License version 2, as published by the Free Software Foundation, and |
| 8 | * may be copied, distributed, and modified under those terms. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #ifndef __LINUX_MFD_CROS_EC_H |
| 17 | #define __LINUX_MFD_CROS_EC_H |
| 18 | |
Javier Martinez Canillas | 05c11ac | 2015-02-02 12:26:23 +0100 | [diff] [blame] | 19 | #include <linux/cdev.h> |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 20 | #include <linux/device.h> |
Bill Richardson | 7e6cb5b | 2014-06-18 11:14:00 -0700 | [diff] [blame] | 21 | #include <linux/notifier.h> |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 22 | #include <linux/mfd/cros_ec_commands.h> |
Bill Richardson | 7e6cb5b | 2014-06-18 11:14:00 -0700 | [diff] [blame] | 23 | #include <linux/mutex.h> |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 24 | |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 25 | #define CROS_EC_DEV_NAME "cros_ec" |
Enric Balletbo i Serra | 90486af | 2019-05-08 11:19:55 +0200 | [diff] [blame^] | 26 | #define CROS_EC_DEV_FP_NAME "cros_fp" |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 27 | #define CROS_EC_DEV_PD_NAME "cros_pd" |
Rushikesh S Kadam | d4cee95 | 2019-03-01 13:50:54 +0530 | [diff] [blame] | 28 | #define CROS_EC_DEV_ISH_NAME "cros_ish" |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 29 | |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 30 | /* |
Stephen Barber | d365407 | 2015-06-09 13:04:46 +0200 | [diff] [blame] | 31 | * The EC is unresponsive for a time after a reboot command. Add a |
| 32 | * simple delay to make sure that the bus stays locked. |
| 33 | */ |
| 34 | #define EC_REBOOT_DELAY_MS 50 |
| 35 | |
| 36 | /* |
Stephen Barber | 2c7589a | 2015-06-09 13:04:45 +0200 | [diff] [blame] | 37 | * Max bus-specific overhead incurred by request/responses. |
| 38 | * I2C requires 1 additional byte for requests. |
| 39 | * I2C requires 2 additional bytes for responses. |
Vic Yang | b237640 | 2017-03-24 18:44:01 +0100 | [diff] [blame] | 40 | * SPI requires up to 32 additional bytes for responses. |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 41 | */ |
Stephen Barber | 2c7589a | 2015-06-09 13:04:45 +0200 | [diff] [blame] | 42 | #define EC_PROTO_VERSION_UNKNOWN 0 |
| 43 | #define EC_MAX_REQUEST_OVERHEAD 1 |
Vic Yang | b237640 | 2017-03-24 18:44:01 +0100 | [diff] [blame] | 44 | #define EC_MAX_RESPONSE_OVERHEAD 32 |
Stephen Barber | 2c7589a | 2015-06-09 13:04:45 +0200 | [diff] [blame] | 45 | |
| 46 | /* |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 47 | * Command interface between EC and AP, for LPC, I2C and SPI interfaces. |
| 48 | */ |
| 49 | enum { |
| 50 | EC_MSG_TX_HEADER_BYTES = 3, |
| 51 | EC_MSG_TX_TRAILER_BYTES = 1, |
| 52 | EC_MSG_TX_PROTO_BYTES = EC_MSG_TX_HEADER_BYTES + |
| 53 | EC_MSG_TX_TRAILER_BYTES, |
| 54 | EC_MSG_RX_PROTO_BYTES = 3, |
| 55 | |
Gwendal Grignou | 5d749d0 | 2016-03-08 09:13:52 -0800 | [diff] [blame] | 56 | /* Max length of messages for proto 2*/ |
| 57 | EC_PROTO2_MSG_BYTES = EC_PROTO2_MAX_PARAM_SIZE + |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 58 | EC_MSG_TX_PROTO_BYTES, |
Gwendal Grignou | 5d749d0 | 2016-03-08 09:13:52 -0800 | [diff] [blame] | 59 | |
| 60 | EC_MAX_MSG_BYTES = 64 * 1024, |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 63 | /** |
| 64 | * struct cros_ec_command - Information about a ChromeOS EC command. |
| 65 | * @version: Command version number (often 0). |
| 66 | * @command: Command to send (EC_CMD_...). |
| 67 | * @outsize: Outgoing length in bytes. |
| 68 | * @insize: Max number of bytes to accept from the EC. |
| 69 | * @result: EC's response to the command (separate from communication failure). |
| 70 | * @data: Where to put the incoming data from EC and outgoing data to EC. |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 71 | */ |
Bill Richardson | 5d4773e | 2014-06-18 11:14:02 -0700 | [diff] [blame] | 72 | struct cros_ec_command { |
| 73 | uint32_t version; |
| 74 | uint32_t command; |
Bill Richardson | 5d4773e | 2014-06-18 11:14:02 -0700 | [diff] [blame] | 75 | uint32_t outsize; |
Bill Richardson | 5d4773e | 2014-06-18 11:14:02 -0700 | [diff] [blame] | 76 | uint32_t insize; |
| 77 | uint32_t result; |
Javier Martinez Canillas | a841178 | 2015-06-09 13:04:42 +0200 | [diff] [blame] | 78 | uint8_t data[0]; |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | /** |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 82 | * struct cros_ec_device - Information about a ChromeOS EC device. |
| 83 | * @phys_name: Name of physical comms layer (e.g. 'i2c-4'). |
Javier Martinez Canillas | 05c11ac | 2015-02-02 12:26:23 +0100 | [diff] [blame] | 84 | * @dev: Device pointer for physical comms device |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 85 | * @was_wake_device: True if this device was set to wake the system from |
| 86 | * sleep at the last suspend. |
| 87 | * @cros_class: The class structure for this device. |
| 88 | * @cmd_readmem: Direct read of the EC memory-mapped region, if supported. |
| 89 | * @offset: Is within EC_LPC_ADDR_MEMMAP region. |
| 90 | * @bytes: Number of bytes to read. zero means "read a string" (including |
| 91 | * the trailing '\0'). At most only EC_MEMMAP_SIZE bytes can be |
| 92 | * read. Caller must ensure that the buffer is large enough for the |
| 93 | * result when reading a string. |
| 94 | * @max_request: Max size of message requested. |
| 95 | * @max_response: Max size of message response. |
| 96 | * @max_passthru: Max sice of passthru message. |
| 97 | * @proto_version: The protocol version used for this device. |
| 98 | * @priv: Private data. |
| 99 | * @irq: Interrupt to use. |
| 100 | * @id: Device id. |
| 101 | * @din: Input buffer (for data from EC). This buffer will always be |
| 102 | * dword-aligned and include enough space for up to 7 word-alignment |
| 103 | * bytes also, so we can ensure that the body of the message is always |
| 104 | * dword-aligned (64-bit). We use this alignment to keep ARM and x86 |
| 105 | * happy. Probably word alignment would be OK, there might be a small |
| 106 | * performance advantage to using dword. |
| 107 | * @dout: Output buffer (for data to EC). This buffer will always be |
| 108 | * dword-aligned and include enough space for up to 7 word-alignment |
| 109 | * bytes also, so we can ensure that the body of the message is always |
| 110 | * dword-aligned (64-bit). We use this alignment to keep ARM and x86 |
| 111 | * happy. Probably word alignment would be OK, there might be a small |
| 112 | * performance advantage to using dword. |
| 113 | * @din_size: Size of din buffer to allocate (zero to use static din). |
| 114 | * @dout_size: Size of dout buffer to allocate (zero to use static dout). |
| 115 | * @wake_enabled: True if this device can wake the system from sleep. |
| 116 | * @suspended: True if this device had been suspended. |
| 117 | * @cmd_xfer: Send command to EC and get response. |
| 118 | * Returns the number of bytes received if the communication |
| 119 | * succeeded, but that doesn't mean the EC was happy with the |
| 120 | * command. The caller should check msg.result for the EC's result |
| 121 | * code. |
| 122 | * @pkt_xfer: Send packet to EC and get response. |
| 123 | * @lock: One transaction at a time. |
| 124 | * @mkbp_event_supported: True if this EC supports the MKBP event protocol. |
Evan Green | 7235560 | 2019-04-03 14:34:28 -0700 | [diff] [blame] | 125 | * @host_sleep_v1: True if this EC supports the sleep v1 command. |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 126 | * @event_notifier: Interrupt event notifier for transport devices. |
| 127 | * @event_data: Raw payload transferred with the MKBP event. |
| 128 | * @event_size: Size in bytes of the event data. |
| 129 | * @host_event_wake_mask: Mask of host events that cause wake from suspend. |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 130 | */ |
| 131 | struct cros_ec_device { |
Bill Richardson | 7e6cb5b | 2014-06-18 11:14:00 -0700 | [diff] [blame] | 132 | /* These are used by other drivers that want to talk to the EC */ |
Bill Richardson | 7e6cb5b | 2014-06-18 11:14:00 -0700 | [diff] [blame] | 133 | const char *phys_name; |
| 134 | struct device *dev; |
| 135 | bool was_wake_device; |
| 136 | struct class *cros_class; |
Javier Martinez Canillas | 05c11ac | 2015-02-02 12:26:23 +0100 | [diff] [blame] | 137 | int (*cmd_readmem)(struct cros_ec_device *ec, unsigned int offset, |
| 138 | unsigned int bytes, void *dest); |
Bill Richardson | 7e6cb5b | 2014-06-18 11:14:00 -0700 | [diff] [blame] | 139 | |
| 140 | /* These are used to implement the platform-specific interface */ |
Stephen Barber | 2c7589a | 2015-06-09 13:04:45 +0200 | [diff] [blame] | 141 | u16 max_request; |
| 142 | u16 max_response; |
| 143 | u16 max_passthru; |
| 144 | u16 proto_version; |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 145 | void *priv; |
| 146 | int irq; |
Stephen Barber | 2c7589a | 2015-06-09 13:04:45 +0200 | [diff] [blame] | 147 | u8 *din; |
| 148 | u8 *dout; |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 149 | int din_size; |
| 150 | int dout_size; |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 151 | bool wake_enabled; |
Joseph Lo | a9eb186 | 2016-12-16 18:57:36 +0100 | [diff] [blame] | 152 | bool suspended; |
Andrew Bresticker | a6551a7 | 2014-09-18 17:18:56 +0200 | [diff] [blame] | 153 | int (*cmd_xfer)(struct cros_ec_device *ec, |
| 154 | struct cros_ec_command *msg); |
Stephen Barber | 2c7589a | 2015-06-09 13:04:45 +0200 | [diff] [blame] | 155 | int (*pkt_xfer)(struct cros_ec_device *ec, |
| 156 | struct cros_ec_command *msg); |
Bill Richardson | 7e6cb5b | 2014-06-18 11:14:00 -0700 | [diff] [blame] | 157 | struct mutex lock; |
Vic Yang | 6f1d912 | 2016-08-10 19:05:24 +0200 | [diff] [blame] | 158 | bool mkbp_event_supported; |
Evan Green | 7235560 | 2019-04-03 14:34:28 -0700 | [diff] [blame] | 159 | bool host_sleep_v1; |
Vic Yang | 6f1d912 | 2016-08-10 19:05:24 +0200 | [diff] [blame] | 160 | struct blocking_notifier_head event_notifier; |
| 161 | |
Neil Armstrong | 57e94c8 | 2018-07-04 17:08:18 +0200 | [diff] [blame] | 162 | struct ec_response_get_next_event_v1 event_data; |
Vic Yang | 6f1d912 | 2016-08-10 19:05:24 +0200 | [diff] [blame] | 163 | int event_size; |
Shawn Nematbakhsh | 29d99b9 | 2017-02-14 20:58:02 +0100 | [diff] [blame] | 164 | u32 host_event_wake_mask; |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 165 | }; |
| 166 | |
Enric Balletbo i Serra | 974e6f0 | 2016-08-01 11:54:35 +0200 | [diff] [blame] | 167 | /** |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 168 | * struct cros_ec_sensor_platform - ChromeOS EC sensor platform information. |
Enric Balletbo i Serra | 974e6f0 | 2016-08-01 11:54:35 +0200 | [diff] [blame] | 169 | * @sensor_num: Id of the sensor, as reported by the EC. |
| 170 | */ |
| 171 | struct cros_ec_sensor_platform { |
| 172 | u8 sensor_num; |
| 173 | }; |
| 174 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 175 | /** |
| 176 | * struct cros_ec_platform - ChromeOS EC platform information. |
| 177 | * @ec_name: Name of EC device (e.g. 'cros-ec', 'cros-pd', ...) |
| 178 | * used in /dev/ and sysfs. |
| 179 | * @cmd_offset: Offset to apply for each command. Set when |
| 180 | * registering a device behind another one. |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 181 | */ |
| 182 | struct cros_ec_platform { |
| 183 | const char *ec_name; |
| 184 | u16 cmd_offset; |
| 185 | }; |
| 186 | |
Eric Caruso | e862645 | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 187 | struct cros_ec_debugfs; |
| 188 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 189 | /** |
| 190 | * struct cros_ec_dev - ChromeOS EC device entry point. |
| 191 | * @class_dev: Device structure used in sysfs. |
| 192 | * @cdev: Character device structure in /dev. |
| 193 | * @ec_dev: cros_ec_device structure to talk to the physical device. |
| 194 | * @dev: Pointer to the platform device. |
| 195 | * @debug_info: cros_ec_debugfs structure for debugging information. |
| 196 | * @has_kb_wake_angle: True if at least 2 accelerometer are connected to the EC. |
| 197 | * @cmd_offset: Offset to apply for each command. |
| 198 | * @features: Features supported by the EC. |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 199 | */ |
| 200 | struct cros_ec_dev { |
| 201 | struct device class_dev; |
| 202 | struct cdev cdev; |
| 203 | struct cros_ec_device *ec_dev; |
| 204 | struct device *dev; |
Eric Caruso | e862645 | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 205 | struct cros_ec_debugfs *debug_info; |
Gwendal Grignou | c1d1e91a | 2018-03-23 18:42:47 +0100 | [diff] [blame] | 206 | bool has_kb_wake_angle; |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 207 | u16 cmd_offset; |
Vincent Palatin | e4244eb | 2016-08-01 11:54:37 +0200 | [diff] [blame] | 208 | u32 features[2]; |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 209 | }; |
| 210 | |
Gwendal Grignou | 79a3d60 | 2018-05-30 09:04:13 -0700 | [diff] [blame] | 211 | #define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev) |
| 212 | |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 213 | /** |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 214 | * cros_ec_suspend() - Handle a suspend operation for the ChromeOS EC device. |
| 215 | * @ec_dev: Device to suspend. |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 216 | * |
| 217 | * This can be called by drivers to handle a suspend event. |
| 218 | * |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 219 | * Return: 0 on success or negative error code. |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 220 | */ |
| 221 | int cros_ec_suspend(struct cros_ec_device *ec_dev); |
| 222 | |
| 223 | /** |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 224 | * cros_ec_resume() - Handle a resume operation for the ChromeOS EC device. |
| 225 | * @ec_dev: Device to resume. |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 226 | * |
| 227 | * This can be called by drivers to handle a resume event. |
| 228 | * |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 229 | * Return: 0 on success or negative error code. |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 230 | */ |
| 231 | int cros_ec_resume(struct cros_ec_device *ec_dev); |
| 232 | |
| 233 | /** |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 234 | * cros_ec_prepare_tx() - Prepare an outgoing message in the output buffer. |
| 235 | * @ec_dev: Device to register. |
| 236 | * @msg: Message to write. |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 237 | * |
| 238 | * This is intended to be used by all ChromeOS EC drivers, but at present |
| 239 | * only SPI uses it. Once LPC uses the same protocol it can start using it. |
| 240 | * I2C could use it now, with a refactor of the existing code. |
| 241 | * |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 242 | * Return: 0 on success or negative error code. |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 243 | */ |
| 244 | int cros_ec_prepare_tx(struct cros_ec_device *ec_dev, |
Bill Richardson | 5d4773e | 2014-06-18 11:14:02 -0700 | [diff] [blame] | 245 | struct cros_ec_command *msg); |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 246 | |
| 247 | /** |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 248 | * cros_ec_check_result() - Check ec_msg->result. |
| 249 | * @ec_dev: EC device. |
| 250 | * @msg: Message to check. |
Bill Richardson | 6db07b6 | 2014-06-18 11:14:05 -0700 | [diff] [blame] | 251 | * |
| 252 | * This is used by ChromeOS EC drivers to check the ec_msg->result for |
| 253 | * errors and to warn about them. |
| 254 | * |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 255 | * Return: 0 on success or negative error code. |
Bill Richardson | 6db07b6 | 2014-06-18 11:14:05 -0700 | [diff] [blame] | 256 | */ |
| 257 | int cros_ec_check_result(struct cros_ec_device *ec_dev, |
| 258 | struct cros_ec_command *msg); |
| 259 | |
| 260 | /** |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 261 | * cros_ec_cmd_xfer() - Send a command to the ChromeOS EC. |
| 262 | * @ec_dev: EC device. |
| 263 | * @msg: Message to write. |
Andrew Bresticker | a6551a7 | 2014-09-18 17:18:56 +0200 | [diff] [blame] | 264 | * |
| 265 | * Call this to send a command to the ChromeOS EC. This should be used |
| 266 | * instead of calling the EC's cmd_xfer() callback directly. |
| 267 | * |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 268 | * Return: 0 on success or negative error code. |
Andrew Bresticker | a6551a7 | 2014-09-18 17:18:56 +0200 | [diff] [blame] | 269 | */ |
| 270 | int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, |
| 271 | struct cros_ec_command *msg); |
| 272 | |
| 273 | /** |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 274 | * cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC. |
| 275 | * @ec_dev: EC device. |
| 276 | * @msg: Message to write. |
Tomeu Vizoso | 9798ac6 | 2016-07-15 16:28:41 -0700 | [diff] [blame] | 277 | * |
| 278 | * This function is identical to cros_ec_cmd_xfer, except it returns success |
| 279 | * status only if both the command was transmitted successfully and the EC |
| 280 | * replied with success status. It's not necessary to check msg->result when |
| 281 | * using this function. |
| 282 | * |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 283 | * Return: The number of bytes transferred on success or negative error code. |
Tomeu Vizoso | 9798ac6 | 2016-07-15 16:28:41 -0700 | [diff] [blame] | 284 | */ |
| 285 | int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, |
| 286 | struct cros_ec_command *msg); |
| 287 | |
| 288 | /** |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 289 | * cros_ec_register() - Register a new ChromeOS EC, using the provided info. |
| 290 | * @ec_dev: Device to register. |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 291 | * |
| 292 | * Before calling this, allocate a pointer to a new device and then fill |
| 293 | * in all the fields up to the --private-- marker. |
| 294 | * |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 295 | * Return: 0 on success or negative error code. |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 296 | */ |
| 297 | int cros_ec_register(struct cros_ec_device *ec_dev); |
| 298 | |
Stephen Barber | 2c7589a | 2015-06-09 13:04:45 +0200 | [diff] [blame] | 299 | /** |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 300 | * cros_ec_query_all() - Query the protocol version supported by the |
| 301 | * ChromeOS EC. |
| 302 | * @ec_dev: Device to register. |
Stephen Barber | 2c7589a | 2015-06-09 13:04:45 +0200 | [diff] [blame] | 303 | * |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 304 | * Return: 0 on success or negative error code. |
Stephen Barber | 2c7589a | 2015-06-09 13:04:45 +0200 | [diff] [blame] | 305 | */ |
| 306 | int cros_ec_query_all(struct cros_ec_device *ec_dev); |
| 307 | |
Vic Yang | 6f1d912 | 2016-08-10 19:05:24 +0200 | [diff] [blame] | 308 | /** |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 309 | * cros_ec_get_next_event() - Fetch next event from the ChromeOS EC. |
| 310 | * @ec_dev: Device to fetch event from. |
Shawn Nematbakhsh | 29d99b9 | 2017-02-14 20:58:02 +0100 | [diff] [blame] | 311 | * @wake_event: Pointer to a bool set to true upon return if the event might be |
| 312 | * treated as a wake event. Ignored if null. |
Vic Yang | 6f1d912 | 2016-08-10 19:05:24 +0200 | [diff] [blame] | 313 | * |
Brian Norris | 475b087 | 2018-11-07 18:49:38 -0800 | [diff] [blame] | 314 | * Return: negative error code on errors; 0 for no data; or else number of |
| 315 | * bytes received (i.e., an event was retrieved successfully). Event types are |
| 316 | * written out to @ec_dev->event_data.event_type on success. |
Vic Yang | 6f1d912 | 2016-08-10 19:05:24 +0200 | [diff] [blame] | 317 | */ |
Shawn Nematbakhsh | 29d99b9 | 2017-02-14 20:58:02 +0100 | [diff] [blame] | 318 | int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event); |
Vic Yang | 6f1d912 | 2016-08-10 19:05:24 +0200 | [diff] [blame] | 319 | |
Gwendal Grignou | 68c35ea | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 320 | /** |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 321 | * cros_ec_get_host_event() - Return a mask of event set by the ChromeOS EC. |
| 322 | * @ec_dev: Device to fetch event from. |
Gwendal Grignou | 68c35ea | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 323 | * |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 324 | * When MKBP is supported, when the EC raises an interrupt, we collect the |
| 325 | * events raised and call the functions in the ec notifier. This function |
| 326 | * is a helper to know which events are raised. |
Gwendal Grignou | 68c35ea | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 327 | * |
Brian Norris | 475b087 | 2018-11-07 18:49:38 -0800 | [diff] [blame] | 328 | * Return: 0 on error or non-zero bitmask of one or more EC_HOST_EVENT_*. |
Gwendal Grignou | 68c35ea | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 329 | */ |
| 330 | u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); |
| 331 | |
Simon Glass | 4ab6174 | 2013-02-25 14:08:37 -0800 | [diff] [blame] | 332 | #endif /* __LINUX_MFD_CROS_EC_H */ |