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