linux/include/linux/platform_data/cros_ec_sensorhub.h

/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Chrome OS EC MEMS Sensor Hub driver.
 *
 * Copyright 2019 Google LLC
 */

#ifndef __LINUX_PLATFORM_DATA_CROS_EC_SENSORHUB_H
#define __LINUX_PLATFORM_DATA_CROS_EC_SENSORHUB_H

#include <linux/ktime.h>
#include <linux/mutex.h>
#include <linux/notifier.h>
#include <linux/platform_data/cros_ec_commands.h>

struct iio_dev;

/**
 * struct cros_ec_sensor_platform - ChromeOS EC sensor platform information.
 * @sensor_num: Id of the sensor, as reported by the EC.
 */
struct cros_ec_sensor_platform {};

/**
 * typedef cros_ec_sensorhub_push_data_cb_t - Callback function to send datum
 *					      to specific sensors.
 *
 * @indio_dev: The IIO device that will process the sample.
 * @data: Vector array of the ring sample.
 * @timestamp: Timestamp in host timespace when the sample was acquired by
 *             the EC.
 */
cros_ec_sensorhub_push_data_cb_t;

struct cros_ec_sensorhub_sensor_push_data {};

enum {};

struct cros_ec_sensors_ring_sample {} __packed;

/* State used for cros_ec_ring_fix_overflow */
struct cros_ec_sensors_ec_overflow_state {};

/* Length of the filter, how long to remember entries for */
#define CROS_EC_SENSORHUB_TS_HISTORY_SIZE

/**
 * struct cros_ec_sensors_ts_filter_state - Timestamp filetr state.
 *
 * @x_offset: x is EC interrupt time. x_offset its last value.
 * @y_offset: y is the difference between AP and EC time, y_offset its last
 *            value.
 * @x_history: The past history of x, relative to x_offset.
 * @y_history: The past history of y, relative to y_offset.
 * @m_history: rate between y and x.
 * @history_len: Amount of valid historic data in the arrays.
 * @temp_buf: Temporary buffer used when updating the filter.
 * @median_m: median value of m_history
 * @median_error: final error to apply to AP interrupt timestamp to get the
 *                "true timestamp" the event occurred.
 */
struct cros_ec_sensors_ts_filter_state {};

/* struct cros_ec_sensors_ts_batch_state - State of batch of a single sensor.
 *
 * Use to store information to batch data using median fileter information.
 *
 * @penul_ts: last but one batch timestamp (penultimate timestamp).
 *	      Used for timestamp spreading calculations
 *	      when a batch shows up.
 * @penul_len: last but one batch length.
 * @last_ts: Last batch timestam.
 * @last_len: Last batch length.
 * @newest_sensor_event: Last sensor timestamp.
 */
struct cros_ec_sensors_ts_batch_state {};

/*
 * struct cros_ec_sensorhub - Sensor Hub device data.
 *
 * @dev: Device object, mostly used for logging.
 * @ec: Embedded Controller where the hub is located.
 * @sensor_num: Number of MEMS sensors present in the EC.
 * @msg: Structure to send FIFO requests.
 * @params: Pointer to parameters in msg.
 * @resp: Pointer to responses in msg.
 * @cmd_lock : Lock for sending msg.
 * @notifier: Notifier to kick the FIFO interrupt.
 * @ring: Preprocessed ring to store events.
 * @fifo_timestamp: Array for event timestamp and spreading.
 * @fifo_info: Copy of FIFO information coming from the EC.
 * @fifo_size: Size of the ring.
 * @batch_state: Per sensor information of the last batches received.
 * @overflow_a: For handling timestamp overflow for a time (sensor events)
 * @overflow_b: For handling timestamp overflow for b time (ec interrupts)
 * @filter: Medium fileter structure.
 * @tight_timestamps: Set to truen when EC support tight timestamping:
 *		      The timestamps reported from the EC have low jitter.
 *		      Timestamps also come before every sample. Set either
 *		      by feature bits coming from the EC or userspace.
 * @future_timestamp_count: Statistics used to compute shaved time.
 *			    This occurs when timestamp interpolation from EC
 *			    time to AP time accidentally puts timestamps in
 *			    the future. These timestamps are clamped to
 *			    `now` and these count/total_ns maintain the
 *			    statistics for how much time was removed in a
 *			    given period.
 * @future_timestamp_total_ns: Total amount of time shaved.
 * @push_data: Array of callback to send datums to iio sensor object.
 */
struct cros_ec_sensorhub {};

int cros_ec_sensorhub_register_push_data(struct cros_ec_sensorhub *sensorhub,
					 u8 sensor_num,
					 struct iio_dev *indio_dev,
					 cros_ec_sensorhub_push_data_cb_t cb);

void cros_ec_sensorhub_unregister_push_data(struct cros_ec_sensorhub *sensorhub,
					    u8 sensor_num);

int cros_ec_sensorhub_ring_allocate(struct cros_ec_sensorhub *sensorhub);
int cros_ec_sensorhub_ring_add(struct cros_ec_sensorhub *sensorhub);
void cros_ec_sensorhub_ring_remove(void *arg);
int cros_ec_sensorhub_ring_fifo_enable(struct cros_ec_sensorhub *sensorhub,
				       bool on);

#endif   /* __LINUX_PLATFORM_DATA_CROS_EC_SENSORHUB_H */