IB between mfd, iio, input and chrome platform for cros-ec-sensorhub
Showing the changes to include/linux (2 of 17 files). Show all
Unified · Split
| @@ -12,6 +12,7 @@ · 11 unmodified lines | ||
| 12 | 12 | #include <linux/mutex.h> |
| 13 | 13 | #include <linux/notifier.h> |
| 14 | 14 | |
| 15 | +#include <linux/mfd/cros_ec.h> | |
| 15 | 16 | #include <linux/platform_data/cros_ec_commands.h> |
| 16 | 17 | |
| 17 | 18 | #define CROS_EC_DEV_NAME "cros_ec" |
| @@ -115,12 +116,16 @@ struct cros_ec_command { · 97 unmodified lines | ||
| 115 | 116 | * code. |
| 116 | 117 | * @pkt_xfer: Send packet to EC and get response. |
| 117 | 118 | * @lock: One transaction at a time. |
| 118 | − * @mkbp_event_supported: True if this EC supports the MKBP event protocol. | |
| 119 | + * @mkbp_event_supported: 0 if MKBP not supported. Otherwise its value is | |
| 120 | + * the maximum supported version of the MKBP host event | |
| 121 | + * command + 1. | |
| 119 | 122 | * @host_sleep_v1: True if this EC supports the sleep v1 command. |
| 120 | 123 | * @event_notifier: Interrupt event notifier for transport devices. |
| 121 | 124 | * @event_data: Raw payload transferred with the MKBP event. |
| 122 | 125 | * @event_size: Size in bytes of the event data. |
| 123 | 126 | * @host_event_wake_mask: Mask of host events that cause wake from suspend. |
| 127 | + * @last_event_time: exact time from the hard irq when we got notified of | |
| 128 | + * a new event. | |
| 124 | 129 | * @ec: The platform_device used by the mfd driver to interface with the |
| 125 | 130 | * main EC. |
| 126 | 131 | * @pd: The platform_device used by the mfd driver to interface with the |
| @@ -153,7 +158,7 @@ struct cros_ec_device { · 26 unmodified lines | ||
| 153 | 158 | int (*pkt_xfer)(struct cros_ec_device *ec, |
| 154 | 159 | struct cros_ec_command *msg); |
| 155 | 160 | struct mutex lock; |
| 156 | − bool mkbp_event_supported; | |
| 161 | + u8 mkbp_event_supported; | |
| 157 | 162 | bool host_sleep_v1; |
| 158 | 163 | struct blocking_notifier_head event_notifier; |
| 159 | 164 | |
| @@ -161,20 +166,13 @@ struct cros_ec_device { · 1 unmodified line | ||
| 161 | 166 | int event_size; |
| 162 | 167 | u32 host_event_wake_mask; |
| 163 | 168 | u32 last_resume_result; |
| 169 | + ktime_t last_event_time; | |
| 164 | 170 | |
| 165 | 171 | /* The platform devices used by the mfd driver */ |
| 166 | 172 | struct platform_device *ec; |
| 167 | 173 | struct platform_device *pd; |
| 168 | 174 | }; |
| 169 | 175 | |
| 170 | −/** | |
| 171 | − * struct cros_ec_sensor_platform - ChromeOS EC sensor platform information. | |
| 172 | − * @sensor_num: Id of the sensor, as reported by the EC. | |
| 173 | − */ | |
| 174 | −struct cros_ec_sensor_platform { | |
| 175 | − u8 sensor_num; | |
| 176 | −}; | |
| 177 | − | |
| 178 | 176 | /** |
| 179 | 177 | * struct cros_ec_platform - ChromeOS EC platform information. |
| 180 | 178 | * @ec_name: Name of EC device (e.g. 'cros-ec', 'cros-pd', ...) |
| @@ -187,133 +185,51 @@ struct cros_ec_platform { · 6 unmodified lines | ||
| 187 | 185 | u16 cmd_offset; |
| 188 | 186 | }; |
| 189 | 187 | |
| 190 | −/** | |
| 191 | − * cros_ec_suspend() - Handle a suspend operation for the ChromeOS EC device. | |
| 192 | − * @ec_dev: Device to suspend. | |
| 193 | − * | |
| 194 | − * This can be called by drivers to handle a suspend event. | |
| 195 | − * | |
| 196 | − * Return: 0 on success or negative error code. | |
| 197 | − */ | |
| 198 | 188 | int cros_ec_suspend(struct cros_ec_device *ec_dev); |
| 199 | 189 | |
| 200 | −/** | |
| 201 | − * cros_ec_resume() - Handle a resume operation for the ChromeOS EC device. | |
| 202 | − * @ec_dev: Device to resume. | |
| 203 | − * | |
| 204 | − * This can be called by drivers to handle a resume event. | |
| 205 | − * | |
| 206 | − * Return: 0 on success or negative error code. | |
| 207 | − */ | |
| 208 | 190 | int cros_ec_resume(struct cros_ec_device *ec_dev); |
| 209 | 191 | |
| 210 | −/** | |
| 211 | − * cros_ec_prepare_tx() - Prepare an outgoing message in the output buffer. | |
| 212 | − * @ec_dev: Device to register. | |
| 213 | − * @msg: Message to write. | |
| 214 | − * | |
| 215 | − * This is intended to be used by all ChromeOS EC drivers, but at present | |
| 216 | − * only SPI uses it. Once LPC uses the same protocol it can start using it. | |
| 217 | − * I2C could use it now, with a refactor of the existing code. | |
| 218 | − * | |
| 219 | − * Return: 0 on success or negative error code. | |
| 220 | − */ | |
| 221 | 192 | int cros_ec_prepare_tx(struct cros_ec_device *ec_dev, |
| 222 | 193 | struct cros_ec_command *msg); |
| 223 | 194 | |
| 224 | −/** | |
| 225 | − * cros_ec_check_result() - Check ec_msg->result. | |
| 226 | − * @ec_dev: EC device. | |
| 227 | − * @msg: Message to check. | |
| 228 | − * | |
| 229 | − * This is used by ChromeOS EC drivers to check the ec_msg->result for | |
| 230 | − * errors and to warn about them. | |
| 231 | − * | |
| 232 | − * Return: 0 on success or negative error code. | |
| 233 | − */ | |
| 234 | 195 | int cros_ec_check_result(struct cros_ec_device *ec_dev, |
| 235 | 196 | struct cros_ec_command *msg); |
| 236 | 197 | |
| 237 | −/** | |
| 238 | − * cros_ec_cmd_xfer() - Send a command to the ChromeOS EC. | |
| 239 | − * @ec_dev: EC device. | |
| 240 | − * @msg: Message to write. | |
| 241 | − * | |
| 242 | − * Call this to send a command to the ChromeOS EC. This should be used | |
| 243 | − * instead of calling the EC's cmd_xfer() callback directly. | |
| 244 | − * | |
| 245 | − * Return: 0 on success or negative error code. | |
| 246 | − */ | |
| 247 | 198 | int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, |
| 248 | 199 | struct cros_ec_command *msg); |
| 249 | 200 | |
| 250 | −/** | |
| 251 | − * cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC. | |
| 252 | − * @ec_dev: EC device. | |
| 253 | − * @msg: Message to write. | |
| 254 | − * | |
| 255 | − * This function is identical to cros_ec_cmd_xfer, except it returns success | |
| 256 | − * status only if both the command was transmitted successfully and the EC | |
| 257 | − * replied with success status. It's not necessary to check msg->result when | |
| 258 | − * using this function. | |
| 259 | − * | |
| 260 | − * Return: The number of bytes transferred on success or negative error code. | |
| 261 | − */ | |
| 262 | 201 | int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, |
| 263 | 202 | struct cros_ec_command *msg); |
| 264 | 203 | |
| 265 | −/** | |
| 266 | − * cros_ec_register() - Register a new ChromeOS EC, using the provided info. | |
| 267 | − * @ec_dev: Device to register. | |
| 268 | − * | |
| 269 | − * Before calling this, allocate a pointer to a new device and then fill | |
| 270 | − * in all the fields up to the --private-- marker. | |
| 271 | − * | |
| 272 | − * Return: 0 on success or negative error code. | |
| 273 | − */ | |
| 274 | 204 | int cros_ec_register(struct cros_ec_device *ec_dev); |
| 275 | 205 | |
| 276 | −/** | |
| 277 | − * cros_ec_unregister() - Remove a ChromeOS EC. | |
| 278 | − * @ec_dev: Device to unregister. | |
| 279 | − * | |
| 280 | − * Call this to deregister a ChromeOS EC, then clean up any private data. | |
| 281 | − * | |
| 282 | − * Return: 0 on success or negative error code. | |
| 283 | − */ | |
| 284 | 206 | int cros_ec_unregister(struct cros_ec_device *ec_dev); |
| 285 | 207 | |
| 286 | −/** | |
| 287 | − * cros_ec_query_all() - Query the protocol version supported by the | |
| 288 | − * ChromeOS EC. | |
| 289 | − * @ec_dev: Device to register. | |
| 290 | − * | |
| 291 | − * Return: 0 on success or negative error code. | |
| 292 | − */ | |
| 293 | 208 | int cros_ec_query_all(struct cros_ec_device *ec_dev); |
| 294 | 209 | |
| 295 | −/** | |
| 296 | − * cros_ec_get_next_event() - Fetch next event from the ChromeOS EC. | |
| 297 | − * @ec_dev: Device to fetch event from. | |
| 298 | − * @wake_event: Pointer to a bool set to true upon return if the event might be | |
| 299 | − * treated as a wake event. Ignored if null. | |
| 300 | − * | |
| 301 | − * Return: negative error code on errors; 0 for no data; or else number of | |
| 302 | − * bytes received (i.e., an event was retrieved successfully). Event types are | |
| 303 | − * written out to @ec_dev->event_data.event_type on success. | |
| 304 | − */ | |
| 305 | −int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event); | |
| 210 | +int cros_ec_get_next_event(struct cros_ec_device *ec_dev, | |
| 211 | + bool *wake_event, | |
| 212 | + bool *has_more_events); | |
| 213 | + | |
| 214 | +u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); | |
| 215 | + | |
| 216 | +int cros_ec_check_features(struct cros_ec_dev *ec, int feature); | |
| 217 | + | |
| 218 | +int cros_ec_get_sensor_count(struct cros_ec_dev *ec); | |
| 219 | + | |
| 220 | +bool cros_ec_handle_event(struct cros_ec_device *ec_dev); | |
| 306 | 221 | |
| 307 | 222 | /** |
| 308 | − * cros_ec_get_host_event() - Return a mask of event set by the ChromeOS EC. | |
| 309 | − * @ec_dev: Device to fetch event from. | |
| 223 | + * cros_ec_get_time_ns() - Return time in ns. | |
| 310 | 224 | * |
| 311 | − * When MKBP is supported, when the EC raises an interrupt, we collect the | |
| 312 | − * events raised and call the functions in the ec notifier. This function | |
| 313 | − * is a helper to know which events are raised. | |
| 225 | + * This is the function used to record the time for last_event_time in struct | |
| 226 | + * cros_ec_device during the hard irq. | |
| 314 | 227 | * |
| 315 | − * Return: 0 on error or non-zero bitmask of one or more EC_HOST_EVENT_*. | |
| 228 | + * Return: ktime_t format since boot. | |
| 316 | 229 | */ |
| 317 | −u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); | |
| 230 | +static inline ktime_t cros_ec_get_time_ns(void) | |
| 231 | +{ | |
| 232 | + return ktime_get_boottime_ns(); | |
| 233 | +} | |
| 318 | 234 | |
| 319 | 235 | #endif /* __LINUX_CROS_EC_PROTO_H */ |
| @@ -0,0 +1,30 @@ | ||
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
| 2 | +/* | |
| 3 | + * Chrome OS EC MEMS Sensor Hub driver. | |
| 4 | + * | |
| 5 | + * Copyright 2019 Google LLC | |
| 6 | + */ | |
| 7 | + | |
| 8 | +#ifndef __LINUX_PLATFORM_DATA_CROS_EC_SENSORHUB_H | |
| 9 | +#define __LINUX_PLATFORM_DATA_CROS_EC_SENSORHUB_H | |
| 10 | + | |
| 11 | +#include <linux/platform_data/cros_ec_commands.h> | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * struct cros_ec_sensor_platform - ChromeOS EC sensor platform information. | |
| 15 | + * @sensor_num: Id of the sensor, as reported by the EC. | |
| 16 | + */ | |
| 17 | +struct cros_ec_sensor_platform { | |
| 18 | + u8 sensor_num; | |
| 19 | +}; | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * struct cros_ec_sensorhub - Sensor Hub device data. | |
| 23 | + * | |
| 24 | + * @ec: Embedded Controller where the hub is located. | |
| 25 | + */ | |
| 26 | +struct cros_ec_sensorhub { | |
| 27 | + struct cros_ec_dev *ec; | |
| 28 | +}; | |
| 29 | + | |
| 30 | +#endif /* __LINUX_PLATFORM_DATA_CROS_EC_SENSORHUB_H */ | |