Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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