blob: a91622ac54e06e037502fbc956f0bd7c35de7509 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Jonathan Camerone6477002011-10-14 16:34:14 +01002/**
3 * Copyright (c) 2011 Jonathan Cameron
4 *
Jonathan Camerone6477002011-10-14 16:34:14 +01005 * Join together the various functionality of iio_simple_dummy driver
6 */
7
Roberta Dobrescuf3f883b2014-09-25 16:58:07 +03008#ifndef _IIO_SIMPLE_DUMMY_H_
9#define _IIO_SIMPLE_DUMMY_H_
Jonathan Camerone6477002011-10-14 16:34:14 +010010#include <linux/kernel.h>
11
12struct iio_dummy_accel_calibscale;
Daniel Baluta356ae942014-11-10 14:45:29 +020013struct iio_dummy_regs;
Jonathan Camerone6477002011-10-14 16:34:14 +010014
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)
Carlos E. Garcia69e98df2015-04-24 09:40:42 -040025 * @event_val: cache for event threshold value
Jonathan Camerone6477002011-10-14 16:34:14 +010026 * @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;
Daniel Baluta3e34e652014-11-10 14:45:34 +020034 int activity_running;
35 int activity_walking;
Jonathan Camerone6477002011-10-14 16:34:14 +010036 const struct iio_dummy_accel_calibscale *accel_calibscale;
37 struct mutex lock;
Daniel Baluta356ae942014-11-10 14:45:29 +020038 struct iio_dummy_regs *regs;
Daniel Baluta3e34e652014-11-10 14:45:34 +020039 int steps_enabled;
40 int steps;
41 int height;
Jonathan Camerone6477002011-10-14 16:34:14 +010042#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
43 int event_irq;
44 int event_val;
45 bool event_en;
Cristina Opriceanafd2bb312015-09-11 16:59:30 +030046 s64 event_timestamp;
Jonathan Camerone6477002011-10-14 16:34:14 +010047#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,
Lars-Peter Clausenbda624b2013-10-07 15:11:00 +010055 const struct iio_chan_spec *chan,
56 enum iio_event_type type,
57 enum iio_event_direction dir);
Jonathan Camerone6477002011-10-14 16:34:14 +010058
59int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
Lars-Peter Clausenbda624b2013-10-07 15:11:00 +010060 const struct iio_chan_spec *chan,
61 enum iio_event_type type,
62 enum iio_event_direction dir,
Jonathan Camerone6477002011-10-14 16:34:14 +010063 int state);
64
65int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
Lars-Peter Clausenbda624b2013-10-07 15:11:00 +010066 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);
Jonathan Camerone6477002011-10-14 16:34:14 +010071
72int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
Lars-Peter Clausenbda624b2013-10-07 15:11:00 +010073 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);
Jonathan Camerone6477002011-10-14 16:34:14 +010078
79int iio_simple_dummy_events_register(struct iio_dev *indio_dev);
Vladimirs Ambrosovs62a90da2015-05-30 11:20:16 +030080void iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
Jonathan Camerone6477002011-10-14 16:34:14 +010081
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;
Peter Meerwald-Stadler83b0b392016-12-20 17:38:10 +010088}
Jonathan Camerone6477002011-10-14 16:34:14 +010089
Vladimirs Ambrosovs62a90da2015-05-30 11:20:16 +030090static inline void
Jonathan Camerone6477002011-10-14 16:34:14 +010091iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
Peter Meerwald-Stadler83b0b392016-12-20 17:38:10 +010092{}
Jonathan Camerone6477002011-10-14 16:34:14 +010093
94#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
95
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +010096/**
97 * enum iio_simple_dummy_scan_elements - scan index enum
Alison Schofieldf8087ab2015-10-26 13:48:23 -070098 * @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
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100102 *
103 * Enum provides convenient numbering for the scan index.
104 */
105enum iio_simple_dummy_scan_elements {
Alison Schofieldf8087ab2015-10-26 13:48:23 -0700106 DUMMY_INDEX_VOLTAGE_0,
107 DUMMY_INDEX_DIFFVOLTAGE_1M2,
108 DUMMY_INDEX_DIFFVOLTAGE_3M4,
109 DUMMY_INDEX_ACCELX,
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100110};
Jonathan Camerone6477002011-10-14 16:34:14 +0100111
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100112#ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
Lars-Peter Clausen4ae03012014-11-26 18:55:11 +0100113int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev);
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100114void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
115#else
Vlad Dogaru75d44ce2014-12-29 11:50:16 +0200116static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100117{
118 return 0;
Peter Meerwald-Stadler83b0b392016-12-20 17:38:10 +0100119}
Cristina Opriceana862cb6c2015-07-10 17:10:21 +0300120
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100121static inline
122void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
Peter Meerwald-Stadler83b0b392016-12-20 17:38:10 +0100123{}
Roberta Dobrescuf3f883b2014-09-25 16:58:07 +0300124
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100125#endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */
Roberta Dobrescuf3f883b2014-09-25 16:58:07 +0300126#endif /* _IIO_SIMPLE_DUMMY_H_ */