Linux Audio

Check our new training course

Loading...
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/**
  3 * Copyright (c) 2011 Jonathan Cameron
  4 *
  5 * Join together the various functionality of iio_simple_dummy driver
  6 */
  7
  8#ifndef _IIO_SIMPLE_DUMMY_H_
  9#define _IIO_SIMPLE_DUMMY_H_
 10#include <linux/kernel.h>
 11
 12struct iio_dummy_accel_calibscale;
 13struct iio_dummy_regs;
 14
 15/**
 16 * struct iio_dummy_state - device instance specific state.
 17 * @dac_val:			cache for dac value
 18 * @single_ended_adc_val:	cache for single ended adc value
 19 * @differential_adc_val:	cache for differential adc value
 20 * @accel_val:			cache for acceleration value
 21 * @accel_calibbias:		cache for acceleration calibbias
 22 * @accel_calibscale:		cache for acceleration calibscale
 23 * @lock:			lock to ensure state is consistent
 24 * @event_irq:			irq number for event line (faked)
 25 * @event_val:			cache for event threshold value
 26 * @event_en:			cache of whether event is enabled
 27 */
 28struct iio_dummy_state {
 29	int dac_val;
 30	int single_ended_adc_val;
 31	int differential_adc_val[2];
 32	int accel_val;
 33	int accel_calibbias;
 34	int activity_running;
 35	int activity_walking;
 36	const struct iio_dummy_accel_calibscale *accel_calibscale;
 37	struct mutex lock;
 38	struct iio_dummy_regs *regs;
 39	int steps_enabled;
 40	int steps;
 41	int height;
 42#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
 43	int event_irq;
 44	int event_val;
 45	bool event_en;
 46	s64 event_timestamp;
 47#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
 48};
 49
 50#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
 51
 52struct iio_dev;
 53
 54int iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
 55				       const struct iio_chan_spec *chan,
 56				       enum iio_event_type type,
 57				       enum iio_event_direction dir);
 58
 59int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
 60					const struct iio_chan_spec *chan,
 61					enum iio_event_type type,
 62					enum iio_event_direction dir,
 63					int state);
 64
 65int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
 66				      const struct iio_chan_spec *chan,
 67				      enum iio_event_type type,
 68				      enum iio_event_direction dir,
 69				      enum iio_event_info info, int *val,
 70				      int *val2);
 71
 72int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
 73				       const struct iio_chan_spec *chan,
 74				       enum iio_event_type type,
 75				       enum iio_event_direction dir,
 76				       enum iio_event_info info, int val,
 77				       int val2);
 78
 79int iio_simple_dummy_events_register(struct iio_dev *indio_dev);
 80void iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
 81
 82#else /* Stubs for when events are disabled at compile time */
 83
 84static inline int
 85iio_simple_dummy_events_register(struct iio_dev *indio_dev)
 86{
 87	return 0;
 88}
 89
 90static inline void
 91iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
 92{}
 93
 94#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
 95
 96/**
 97 * enum iio_simple_dummy_scan_elements - scan index enum
 98 * @DUMMY_INDEX_VOLTAGE_0:         the single ended voltage channel
 99 * @DUMMY_INDEX_DIFFVOLTAGE_1M2:   first differential channel
100 * @DUMMY_INDEX_DIFFVOLTAGE_3M4:   second differential channel
101 * @DUMMY_INDEX_ACCELX:            acceleration channel
102 *
103 * Enum provides convenient numbering for the scan index.
104 */
105enum iio_simple_dummy_scan_elements {
106	DUMMY_INDEX_VOLTAGE_0,
107	DUMMY_INDEX_DIFFVOLTAGE_1M2,
108	DUMMY_INDEX_DIFFVOLTAGE_3M4,
109	DUMMY_INDEX_ACCELX,
110};
111
112#ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
113int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev);
114void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
115#else
116static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
117{
118	return 0;
119}
120
121static inline
122void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
123{}
124
125#endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */
126#endif /* _IIO_SIMPLE_DUMMY_H_ */