18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/**
38c2ecf20Sopenharmony_ci * Copyright (c) 2011 Jonathan Cameron
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Join together the various functionality of iio_simple_dummy driver
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _IIO_SIMPLE_DUMMY_H_
98c2ecf20Sopenharmony_ci#define _IIO_SIMPLE_DUMMY_H_
108c2ecf20Sopenharmony_ci#include <linux/kernel.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cistruct iio_dummy_accel_calibscale;
138c2ecf20Sopenharmony_cistruct iio_dummy_regs;
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/**
168c2ecf20Sopenharmony_ci * struct iio_dummy_state - device instance specific state.
178c2ecf20Sopenharmony_ci * @dac_val:			cache for dac value
188c2ecf20Sopenharmony_ci * @single_ended_adc_val:	cache for single ended adc value
198c2ecf20Sopenharmony_ci * @differential_adc_val:	cache for differential adc value
208c2ecf20Sopenharmony_ci * @accel_val:			cache for acceleration value
218c2ecf20Sopenharmony_ci * @accel_calibbias:		cache for acceleration calibbias
228c2ecf20Sopenharmony_ci * @accel_calibscale:		cache for acceleration calibscale
238c2ecf20Sopenharmony_ci * @lock:			lock to ensure state is consistent
248c2ecf20Sopenharmony_ci * @event_irq:			irq number for event line (faked)
258c2ecf20Sopenharmony_ci * @event_val:			cache for event threshold value
268c2ecf20Sopenharmony_ci * @event_en:			cache of whether event is enabled
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_cistruct iio_dummy_state {
298c2ecf20Sopenharmony_ci	int dac_val;
308c2ecf20Sopenharmony_ci	int single_ended_adc_val;
318c2ecf20Sopenharmony_ci	int differential_adc_val[2];
328c2ecf20Sopenharmony_ci	int accel_val;
338c2ecf20Sopenharmony_ci	int accel_calibbias;
348c2ecf20Sopenharmony_ci	int activity_running;
358c2ecf20Sopenharmony_ci	int activity_walking;
368c2ecf20Sopenharmony_ci	const struct iio_dummy_accel_calibscale *accel_calibscale;
378c2ecf20Sopenharmony_ci	struct mutex lock;
388c2ecf20Sopenharmony_ci	struct iio_dummy_regs *regs;
398c2ecf20Sopenharmony_ci	int steps_enabled;
408c2ecf20Sopenharmony_ci	int steps;
418c2ecf20Sopenharmony_ci	int height;
428c2ecf20Sopenharmony_ci#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
438c2ecf20Sopenharmony_ci	int event_irq;
448c2ecf20Sopenharmony_ci	int event_val;
458c2ecf20Sopenharmony_ci	bool event_en;
468c2ecf20Sopenharmony_ci	s64 event_timestamp;
478c2ecf20Sopenharmony_ci#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistruct iio_dev;
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ciint iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
558c2ecf20Sopenharmony_ci				       const struct iio_chan_spec *chan,
568c2ecf20Sopenharmony_ci				       enum iio_event_type type,
578c2ecf20Sopenharmony_ci				       enum iio_event_direction dir);
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciint iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
608c2ecf20Sopenharmony_ci					const struct iio_chan_spec *chan,
618c2ecf20Sopenharmony_ci					enum iio_event_type type,
628c2ecf20Sopenharmony_ci					enum iio_event_direction dir,
638c2ecf20Sopenharmony_ci					int state);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciint iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
668c2ecf20Sopenharmony_ci				      const struct iio_chan_spec *chan,
678c2ecf20Sopenharmony_ci				      enum iio_event_type type,
688c2ecf20Sopenharmony_ci				      enum iio_event_direction dir,
698c2ecf20Sopenharmony_ci				      enum iio_event_info info, int *val,
708c2ecf20Sopenharmony_ci				      int *val2);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ciint iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
738c2ecf20Sopenharmony_ci				       const struct iio_chan_spec *chan,
748c2ecf20Sopenharmony_ci				       enum iio_event_type type,
758c2ecf20Sopenharmony_ci				       enum iio_event_direction dir,
768c2ecf20Sopenharmony_ci				       enum iio_event_info info, int val,
778c2ecf20Sopenharmony_ci				       int val2);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ciint iio_simple_dummy_events_register(struct iio_dev *indio_dev);
808c2ecf20Sopenharmony_civoid iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#else /* Stubs for when events are disabled at compile time */
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cistatic inline int
858c2ecf20Sopenharmony_ciiio_simple_dummy_events_register(struct iio_dev *indio_dev)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	return 0;
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistatic inline void
918c2ecf20Sopenharmony_ciiio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
928c2ecf20Sopenharmony_ci{}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/**
978c2ecf20Sopenharmony_ci * enum iio_simple_dummy_scan_elements - scan index enum
988c2ecf20Sopenharmony_ci * @DUMMY_INDEX_VOLTAGE_0:         the single ended voltage channel
998c2ecf20Sopenharmony_ci * @DUMMY_INDEX_DIFFVOLTAGE_1M2:   first differential channel
1008c2ecf20Sopenharmony_ci * @DUMMY_INDEX_DIFFVOLTAGE_3M4:   second differential channel
1018c2ecf20Sopenharmony_ci * @DUMMY_INDEX_ACCELX:            acceleration channel
1028c2ecf20Sopenharmony_ci *
1038c2ecf20Sopenharmony_ci * Enum provides convenient numbering for the scan index.
1048c2ecf20Sopenharmony_ci */
1058c2ecf20Sopenharmony_cienum iio_simple_dummy_scan_elements {
1068c2ecf20Sopenharmony_ci	DUMMY_INDEX_VOLTAGE_0,
1078c2ecf20Sopenharmony_ci	DUMMY_INDEX_DIFFVOLTAGE_1M2,
1088c2ecf20Sopenharmony_ci	DUMMY_INDEX_DIFFVOLTAGE_3M4,
1098c2ecf20Sopenharmony_ci	DUMMY_INDEX_ACCELX,
1108c2ecf20Sopenharmony_ci};
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
1138c2ecf20Sopenharmony_ciint iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev);
1148c2ecf20Sopenharmony_civoid iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
1158c2ecf20Sopenharmony_ci#else
1168c2ecf20Sopenharmony_cistatic inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
1178c2ecf20Sopenharmony_ci{
1188c2ecf20Sopenharmony_ci	return 0;
1198c2ecf20Sopenharmony_ci}
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistatic inline
1228c2ecf20Sopenharmony_civoid iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
1238c2ecf20Sopenharmony_ci{}
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci#endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */
1268c2ecf20Sopenharmony_ci#endif /* _IIO_SIMPLE_DUMMY_H_ */
127