162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/**
362306a36Sopenharmony_ci * Copyright (c) 2011 Jonathan Cameron
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Join together the various functionality of iio_simple_dummy driver
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef _IIO_SIMPLE_DUMMY_H_
962306a36Sopenharmony_ci#define _IIO_SIMPLE_DUMMY_H_
1062306a36Sopenharmony_ci#include <linux/kernel.h>
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_cistruct iio_dummy_accel_calibscale;
1362306a36Sopenharmony_cistruct iio_dummy_regs;
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/**
1662306a36Sopenharmony_ci * struct iio_dummy_state - device instance specific state.
1762306a36Sopenharmony_ci * @dac_val:			cache for dac value
1862306a36Sopenharmony_ci * @single_ended_adc_val:	cache for single ended adc value
1962306a36Sopenharmony_ci * @differential_adc_val:	cache for differential adc value
2062306a36Sopenharmony_ci * @accel_val:			cache for acceleration value
2162306a36Sopenharmony_ci * @accel_calibbias:		cache for acceleration calibbias
2262306a36Sopenharmony_ci * @accel_calibscale:		cache for acceleration calibscale
2362306a36Sopenharmony_ci * @lock:			lock to ensure state is consistent
2462306a36Sopenharmony_ci * @event_irq:			irq number for event line (faked)
2562306a36Sopenharmony_ci * @event_val:			cache for event threshold value
2662306a36Sopenharmony_ci * @event_en:			cache of whether event is enabled
2762306a36Sopenharmony_ci */
2862306a36Sopenharmony_cistruct iio_dummy_state {
2962306a36Sopenharmony_ci	int dac_val;
3062306a36Sopenharmony_ci	int single_ended_adc_val;
3162306a36Sopenharmony_ci	int differential_adc_val[2];
3262306a36Sopenharmony_ci	int accel_val;
3362306a36Sopenharmony_ci	int accel_calibbias;
3462306a36Sopenharmony_ci	int activity_running;
3562306a36Sopenharmony_ci	int activity_walking;
3662306a36Sopenharmony_ci	const struct iio_dummy_accel_calibscale *accel_calibscale;
3762306a36Sopenharmony_ci	struct mutex lock;
3862306a36Sopenharmony_ci	struct iio_dummy_regs *regs;
3962306a36Sopenharmony_ci	int steps_enabled;
4062306a36Sopenharmony_ci	int steps;
4162306a36Sopenharmony_ci	int height;
4262306a36Sopenharmony_ci#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
4362306a36Sopenharmony_ci	int event_irq;
4462306a36Sopenharmony_ci	int event_val;
4562306a36Sopenharmony_ci	bool event_en;
4662306a36Sopenharmony_ci	s64 event_timestamp;
4762306a36Sopenharmony_ci#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
4862306a36Sopenharmony_ci};
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_cistruct iio_dev;
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ciint iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
5562306a36Sopenharmony_ci				       const struct iio_chan_spec *chan,
5662306a36Sopenharmony_ci				       enum iio_event_type type,
5762306a36Sopenharmony_ci				       enum iio_event_direction dir);
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ciint iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
6062306a36Sopenharmony_ci					const struct iio_chan_spec *chan,
6162306a36Sopenharmony_ci					enum iio_event_type type,
6262306a36Sopenharmony_ci					enum iio_event_direction dir,
6362306a36Sopenharmony_ci					int state);
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ciint iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
6662306a36Sopenharmony_ci				      const struct iio_chan_spec *chan,
6762306a36Sopenharmony_ci				      enum iio_event_type type,
6862306a36Sopenharmony_ci				      enum iio_event_direction dir,
6962306a36Sopenharmony_ci				      enum iio_event_info info, int *val,
7062306a36Sopenharmony_ci				      int *val2);
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ciint iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
7362306a36Sopenharmony_ci				       const struct iio_chan_spec *chan,
7462306a36Sopenharmony_ci				       enum iio_event_type type,
7562306a36Sopenharmony_ci				       enum iio_event_direction dir,
7662306a36Sopenharmony_ci				       enum iio_event_info info, int val,
7762306a36Sopenharmony_ci				       int val2);
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ciint iio_simple_dummy_events_register(struct iio_dev *indio_dev);
8062306a36Sopenharmony_civoid iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#else /* Stubs for when events are disabled at compile time */
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_cistatic inline int
8562306a36Sopenharmony_ciiio_simple_dummy_events_register(struct iio_dev *indio_dev)
8662306a36Sopenharmony_ci{
8762306a36Sopenharmony_ci	return 0;
8862306a36Sopenharmony_ci}
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_cistatic inline void
9162306a36Sopenharmony_ciiio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
9262306a36Sopenharmony_ci{}
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci/**
9762306a36Sopenharmony_ci * enum iio_simple_dummy_scan_elements - scan index enum
9862306a36Sopenharmony_ci * @DUMMY_INDEX_VOLTAGE_0:         the single ended voltage channel
9962306a36Sopenharmony_ci * @DUMMY_INDEX_DIFFVOLTAGE_1M2:   first differential channel
10062306a36Sopenharmony_ci * @DUMMY_INDEX_DIFFVOLTAGE_3M4:   second differential channel
10162306a36Sopenharmony_ci * @DUMMY_INDEX_ACCELX:            acceleration channel
10262306a36Sopenharmony_ci *
10362306a36Sopenharmony_ci * Enum provides convenient numbering for the scan index.
10462306a36Sopenharmony_ci */
10562306a36Sopenharmony_cienum iio_simple_dummy_scan_elements {
10662306a36Sopenharmony_ci	DUMMY_INDEX_VOLTAGE_0,
10762306a36Sopenharmony_ci	DUMMY_INDEX_DIFFVOLTAGE_1M2,
10862306a36Sopenharmony_ci	DUMMY_INDEX_DIFFVOLTAGE_3M4,
10962306a36Sopenharmony_ci	DUMMY_INDEX_ACCELX,
11062306a36Sopenharmony_ci};
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci#ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
11362306a36Sopenharmony_ciint iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev);
11462306a36Sopenharmony_civoid iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
11562306a36Sopenharmony_ci#else
11662306a36Sopenharmony_cistatic inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
11762306a36Sopenharmony_ci{
11862306a36Sopenharmony_ci	return 0;
11962306a36Sopenharmony_ci}
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_cistatic inline
12262306a36Sopenharmony_civoid iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
12362306a36Sopenharmony_ci{}
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci#endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */
12662306a36Sopenharmony_ci#endif /* _IIO_SIMPLE_DUMMY_H_ */
127