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 | #include <linux/mutex.h> | 12 | #include <linux/mutex.h> |
| 13 | #include <linux/notifier.h> | 13 | #include <linux/notifier.h> |
| 14 | 14 | ||
| 15 | #include <linux/mfd/cros_ec.h> | ||
| 15 | #include <linux/platform_data/cros_ec_commands.h> | 16 | #include <linux/platform_data/cros_ec_commands.h> |
| 16 | 17 | ||
| 17 | #define CROS_EC_DEV_NAME "cros_ec" | 18 | #define CROS_EC_DEV_NAME "cros_ec" |
| @@ -115,12 +116,16 @@ struct cros_ec_command { · 97 unmodified lines | |||
| 115 | * code. | 116 | * code. |
| 116 | * @pkt_xfer: Send packet to EC and get response. | 117 | * @pkt_xfer: Send packet to EC and get response. |
| 117 | * @lock: One transaction at a time. | 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 | * @host_sleep_v1: True if this EC supports the sleep v1 command. | 122 | * @host_sleep_v1: True if this EC supports the sleep v1 command. |
| 120 | * @event_notifier: Interrupt event notifier for transport devices. | 123 | * @event_notifier: Interrupt event notifier for transport devices. |
| 121 | * @event_data: Raw payload transferred with the MKBP event. | 124 | * @event_data: Raw payload transferred with the MKBP event. |
| 122 | * @event_size: Size in bytes of the event data. | 125 | * @event_size: Size in bytes of the event data. |
| 123 | * @host_event_wake_mask: Mask of host events that cause wake from suspend. | 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 | * @ec: The platform_device used by the mfd driver to interface with the | 129 | * @ec: The platform_device used by the mfd driver to interface with the |
| 125 | * main EC. | 130 | * main EC. |
| 126 | * @pd: The platform_device used by the mfd driver to interface with the | 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 | int (*pkt_xfer)(struct cros_ec_device *ec, | 158 | int (*pkt_xfer)(struct cros_ec_device *ec, |
| 154 | struct cros_ec_command *msg); | 159 | struct cros_ec_command *msg); |
| 155 | struct mutex lock; | 160 | struct mutex lock; |
| 156 | bool mkbp_event_supported; | 161 | u8 mkbp_event_supported; |
| 157 | bool host_sleep_v1; | 162 | bool host_sleep_v1; |
| 158 | struct blocking_notifier_head event_notifier; | 163 | struct blocking_notifier_head event_notifier; |
| 159 | 164 | ||
| @@ -161,20 +166,13 @@ struct cros_ec_device { · 1 unmodified line | |||
| 161 | int event_size; | 166 | int event_size; |
| 162 | u32 host_event_wake_mask; | 167 | u32 host_event_wake_mask; |
| 163 | u32 last_resume_result; | 168 | u32 last_resume_result; |
| 169 | ktime_t last_event_time; | ||
| 164 | 170 | ||
| 165 | /* The platform devices used by the mfd driver */ | 171 | /* The platform devices used by the mfd driver */ |
| 166 | struct platform_device *ec; | 172 | struct platform_device *ec; |
| 167 | struct platform_device *pd; | 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 | * struct cros_ec_platform - ChromeOS EC platform information. | 177 | * struct cros_ec_platform - ChromeOS EC platform information. |
| 180 | * @ec_name: Name of EC device (e.g. 'cros-ec', 'cros-pd', ...) | 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 | u16 cmd_offset; | 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 | int cros_ec_suspend(struct cros_ec_device *ec_dev); | 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 | int cros_ec_resume(struct cros_ec_device *ec_dev); | 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 | int cros_ec_prepare_tx(struct cros_ec_device *ec_dev, | 192 | int cros_ec_prepare_tx(struct cros_ec_device *ec_dev, |
| 222 | struct cros_ec_command *msg); | 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 | int cros_ec_check_result(struct cros_ec_device *ec_dev, | 195 | int cros_ec_check_result(struct cros_ec_device *ec_dev, |
| 235 | struct cros_ec_command *msg); | 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 | int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, | 198 | int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, |
| 248 | struct cros_ec_command *msg); | 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 | int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, | 201 | int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, |
| 263 | struct cros_ec_command *msg); | 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 | int cros_ec_register(struct cros_ec_device *ec_dev); | 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 | int cros_ec_unregister(struct cros_ec_device *ec_dev); | 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 | int cros_ec_query_all(struct cros_ec_device *ec_dev); | 208 | int cros_ec_query_all(struct cros_ec_device *ec_dev); |
| 294 | 209 | ||
| 295 | /** | 210 | int cros_ec_get_next_event(struct cros_ec_device *ec_dev, |
| 296 | * cros_ec_get_next_event() - Fetch next event from the ChromeOS EC. | 211 | bool *wake_event, |
| 297 | * @ec_dev: Device to fetch event from. | 212 | bool *has_more_events); |
| 298 | * @wake_event: Pointer to a bool set to true upon return if the event might be | 213 | |
| 299 | * treated as a wake event. Ignored if null. | 214 | u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); |
| 300 | * | 215 | |
| 301 | * Return: negative error code on errors; 0 for no data; or else number of | 216 | int cros_ec_check_features(struct cros_ec_dev *ec, int feature); |
| 302 | * bytes received (i.e., an event was retrieved successfully). Event types are | 217 | |
| 303 | * written out to @ec_dev->event_data.event_type on success. | 218 | int cros_ec_get_sensor_count(struct cros_ec_dev *ec); |
| 304 | */ | 219 | |
| 305 | int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event); | 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. | 223 | * cros_ec_get_time_ns() - Return time in ns. |
| 309 | * @ec_dev: Device to fetch event from. | ||
| 310 | * | 224 | * |
| 311 | * When MKBP is supported, when the EC raises an interrupt, we collect the | 225 | * This is the function used to record the time for last_event_time in struct |
| 312 | * events raised and call the functions in the ec notifier. This function | 226 | * cros_ec_device during the hard irq. |
| 313 | * is a helper to know which events are raised. | ||
| 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 | #endif /* __LINUX_CROS_EC_PROTO_H */ | 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 */ | ||