blob: b9069a18067212d0a1e52f50d1b053aa91a160ac [file] [log] [blame]
Jonathan Camerone6477002011-10-14 16:34:14 +01001/**
2 * Copyright (c) 2011 Jonathan Cameron
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
7 *
8 * Join together the various functionality of iio_simple_dummy driver
9 */
10
Roberta Dobrescuf3f883b2014-09-25 16:58:07 +030011#ifndef _IIO_SIMPLE_DUMMY_H_
12#define _IIO_SIMPLE_DUMMY_H_
Jonathan Camerone6477002011-10-14 16:34:14 +010013#include <linux/kernel.h>
14
15struct iio_dummy_accel_calibscale;
Daniel Baluta356ae942014-11-10 14:45:29 +020016struct iio_dummy_regs;
Jonathan Camerone6477002011-10-14 16:34:14 +010017
18/**
19 * struct iio_dummy_state - device instance specific state.
20 * @dac_val: cache for dac value
21 * @single_ended_adc_val: cache for single ended adc value
22 * @differential_adc_val: cache for differential adc value
23 * @accel_val: cache for acceleration value
24 * @accel_calibbias: cache for acceleration calibbias
25 * @accel_calibscale: cache for acceleration calibscale
26 * @lock: lock to ensure state is consistent
27 * @event_irq: irq number for event line (faked)
Carlos E. Garcia69e98df2015-04-24 09:40:42 -040028 * @event_val: cache for event threshold value
Jonathan Camerone6477002011-10-14 16:34:14 +010029 * @event_en: cache of whether event is enabled
30 */
31struct iio_dummy_state {
32 int dac_val;
33 int single_ended_adc_val;
34 int differential_adc_val[2];
35 int accel_val;
36 int accel_calibbias;
Daniel Baluta3e34e652014-11-10 14:45:34 +020037 int activity_running;
38 int activity_walking;
Jonathan Camerone6477002011-10-14 16:34:14 +010039 const struct iio_dummy_accel_calibscale *accel_calibscale;
40 struct mutex lock;
Daniel Baluta356ae942014-11-10 14:45:29 +020041 struct iio_dummy_regs *regs;
Daniel Baluta3e34e652014-11-10 14:45:34 +020042 int steps_enabled;
43 int steps;
44 int height;
Jonathan Camerone6477002011-10-14 16:34:14 +010045#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
46 int event_irq;
47 int event_val;
48 bool event_en;
Cristina Opriceanafd2bb312015-09-11 16:59:30 +030049 s64 event_timestamp;
Jonathan Camerone6477002011-10-14 16:34:14 +010050#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
51};
52
53#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
54
55struct iio_dev;
56
57int iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
Lars-Peter Clausenbda624b2013-10-07 15:11:00 +010058 const struct iio_chan_spec *chan,
59 enum iio_event_type type,
60 enum iio_event_direction dir);
Jonathan Camerone6477002011-10-14 16:34:14 +010061
62int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
Lars-Peter Clausenbda624b2013-10-07 15:11:00 +010063 const struct iio_chan_spec *chan,
64 enum iio_event_type type,
65 enum iio_event_direction dir,
Jonathan Camerone6477002011-10-14 16:34:14 +010066 int state);
67
68int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
Lars-Peter Clausenbda624b2013-10-07 15:11:00 +010069 const struct iio_chan_spec *chan,
70 enum iio_event_type type,
71 enum iio_event_direction dir,
72 enum iio_event_info info, int *val,
73 int *val2);
Jonathan Camerone6477002011-10-14 16:34:14 +010074
75int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
Lars-Peter Clausenbda624b2013-10-07 15:11:00 +010076 const struct iio_chan_spec *chan,
77 enum iio_event_type type,
78 enum iio_event_direction dir,
79 enum iio_event_info info, int val,
80 int val2);
Jonathan Camerone6477002011-10-14 16:34:14 +010081
82int iio_simple_dummy_events_register(struct iio_dev *indio_dev);
Vladimirs Ambrosovs62a90da2015-05-30 11:20:16 +030083void iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
Jonathan Camerone6477002011-10-14 16:34:14 +010084
85#else /* Stubs for when events are disabled at compile time */
86
87static inline int
88iio_simple_dummy_events_register(struct iio_dev *indio_dev)
89{
90 return 0;
91};
92
Vladimirs Ambrosovs62a90da2015-05-30 11:20:16 +030093static inline void
Jonathan Camerone6477002011-10-14 16:34:14 +010094iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
Vladimirs Ambrosovs62a90da2015-05-30 11:20:16 +030095{ };
Jonathan Camerone6477002011-10-14 16:34:14 +010096
97#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
98
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +010099/**
100 * enum iio_simple_dummy_scan_elements - scan index enum
Alison Schofieldf8087ab2015-10-26 13:48:23 -0700101 * @DUMMY_INDEX_VOLTAGE_0: the single ended voltage channel
102 * @DUMMY_INDEX_DIFFVOLTAGE_1M2: first differential channel
103 * @DUMMY_INDEX_DIFFVOLTAGE_3M4: second differential channel
104 * @DUMMY_INDEX_ACCELX: acceleration channel
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100105 *
106 * Enum provides convenient numbering for the scan index.
107 */
108enum iio_simple_dummy_scan_elements {
Alison Schofieldf8087ab2015-10-26 13:48:23 -0700109 DUMMY_INDEX_VOLTAGE_0,
110 DUMMY_INDEX_DIFFVOLTAGE_1M2,
111 DUMMY_INDEX_DIFFVOLTAGE_3M4,
112 DUMMY_INDEX_ACCELX,
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100113};
Jonathan Camerone6477002011-10-14 16:34:14 +0100114
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100115#ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
Lars-Peter Clausen4ae03012014-11-26 18:55:11 +0100116int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev);
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100117void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
118#else
Vlad Dogaru75d44ce2014-12-29 11:50:16 +0200119static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100120{
121 return 0;
122};
Cristina Opriceana862cb6c2015-07-10 17:10:21 +0300123
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100124static inline
125void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
126{};
Roberta Dobrescuf3f883b2014-09-25 16:58:07 +0300127
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100128#endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */
Roberta Dobrescuf3f883b2014-09-25 16:58:07 +0300129#endif /* _IIO_SIMPLE_DUMMY_H_ */