1 /**
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
13 struct 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 */
28 struct 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
45 struct iio_dev;
46
47 int iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
48 u64 event_code);
49
50 int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
51 u64 event_code,
52 int state);
53
54 int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
55 u64 event_code,
56 int *val);
57
58 int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
59 u64 event_code,
60 int val);
61
62 int iio_simple_dummy_events_register(struct iio_dev *indio_dev);
63 int iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
64
65 #else /* Stubs for when events are disabled at compile time */
66
67 static inline int
iio_simple_dummy_events_register(struct iio_dev * indio_dev)68 iio_simple_dummy_events_register(struct iio_dev *indio_dev)
69 {
70 return 0;
71 };
72
73 static inline int
iio_simple_dummy_events_unregister(struct iio_dev * indio_dev)74 iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
75 {
76 return 0;
77 };
78
79 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
80
81 /**
82 * enum iio_simple_dummy_scan_elements - scan index enum
83 * @voltage0: the single ended voltage channel
84 * @diffvoltage1m2: first differential channel
85 * @diffvoltage3m4: second differenial channel
86 * @accelx: acceleration channel
87 *
88 * Enum provides convenient numbering for the scan index.
89 */
90 enum iio_simple_dummy_scan_elements {
91 voltage0,
92 diffvoltage1m2,
93 diffvoltage3m4,
94 accelx,
95 };
96
97 #ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
98 int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev);
99 void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
100 #else
iio_simple_dummy_configure_buffer(struct iio_dev * indio_dev)101 static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
102 {
103 return 0;
104 };
105 static inline
iio_simple_dummy_unconfigure_buffer(struct iio_dev * indio_dev)106 void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
107 {};
108 #endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */
109