blob: b126196cdf3d99562bd855496b18a9dc2cafa1f3 [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
11#include <linux/kernel.h>
12
13struct iio_dummy_accel_calibscale;
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 theshold 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 const struct iio_dummy_accel_calibscale *accel_calibscale;
35 struct mutex lock;
36#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
37 int event_irq;
38 int event_val;
39 bool event_en;
40#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
41};
42
43#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
44
45struct iio_dev;
46
47int iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
Lars-Peter Clausenbda624b2013-10-07 15:11:00 +010048 const struct iio_chan_spec *chan,
49 enum iio_event_type type,
50 enum iio_event_direction dir);
Jonathan Camerone6477002011-10-14 16:34:14 +010051
52int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
Lars-Peter Clausenbda624b2013-10-07 15:11:00 +010053 const struct iio_chan_spec *chan,
54 enum iio_event_type type,
55 enum iio_event_direction dir,
Jonathan Camerone6477002011-10-14 16:34:14 +010056 int state);
57
58int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
Lars-Peter Clausenbda624b2013-10-07 15:11:00 +010059 const struct iio_chan_spec *chan,
60 enum iio_event_type type,
61 enum iio_event_direction dir,
62 enum iio_event_info info, int *val,
63 int *val2);
Jonathan Camerone6477002011-10-14 16:34:14 +010064
65int iio_simple_dummy_write_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_events_register(struct iio_dev *indio_dev);
73int iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
74
75#else /* Stubs for when events are disabled at compile time */
76
77static inline int
78iio_simple_dummy_events_register(struct iio_dev *indio_dev)
79{
80 return 0;
81};
82
83static inline int
84iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
85{
86 return 0;
87};
88
89#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
90
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +010091/**
92 * enum iio_simple_dummy_scan_elements - scan index enum
93 * @voltage0: the single ended voltage channel
94 * @diffvoltage1m2: first differential channel
95 * @diffvoltage3m4: second differenial channel
96 * @accelx: acceleration channel
97 *
98 * Enum provides convenient numbering for the scan index.
99 */
100enum iio_simple_dummy_scan_elements {
101 voltage0,
102 diffvoltage1m2,
103 diffvoltage3m4,
104 accelx,
105};
Jonathan Camerone6477002011-10-14 16:34:14 +0100106
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100107#ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
Lars-Peter Clausen3fff2272012-09-12 12:06:00 +0100108int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev,
109 const struct iio_chan_spec *channels, unsigned int num_channels);
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100110void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
111#else
Lars-Peter Clausen3fff2272012-09-12 12:06:00 +0100112static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev,
113 const struct iio_chan_spec *channels, unsigned int num_channels)
Jonathan Cameron9ad2e2e2011-10-14 16:34:15 +0100114{
115 return 0;
116};
117static inline
118void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
119{};
120#endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */