Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 2 | /** |
| 3 | * Copyright (c) 2011 Jonathan Cameron |
| 4 | * |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 5 | * Join together the various functionality of iio_simple_dummy driver |
| 6 | */ |
| 7 | |
Roberta Dobrescu | f3f883b | 2014-09-25 16:58:07 +0300 | [diff] [blame] | 8 | #ifndef _IIO_SIMPLE_DUMMY_H_ |
| 9 | #define _IIO_SIMPLE_DUMMY_H_ |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 10 | #include <linux/kernel.h> |
| 11 | |
| 12 | struct iio_dummy_accel_calibscale; |
Daniel Baluta | 356ae94 | 2014-11-10 14:45:29 +0200 | [diff] [blame] | 13 | struct iio_dummy_regs; |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 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) |
Carlos E. Garcia | 69e98df | 2015-04-24 09:40:42 -0400 | [diff] [blame] | 25 | * @event_val: cache for event threshold value |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 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; |
Daniel Baluta | 3e34e65 | 2014-11-10 14:45:34 +0200 | [diff] [blame] | 34 | int activity_running; |
| 35 | int activity_walking; |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 36 | const struct iio_dummy_accel_calibscale *accel_calibscale; |
| 37 | struct mutex lock; |
Daniel Baluta | 356ae94 | 2014-11-10 14:45:29 +0200 | [diff] [blame] | 38 | struct iio_dummy_regs *regs; |
Daniel Baluta | 3e34e65 | 2014-11-10 14:45:34 +0200 | [diff] [blame] | 39 | int steps_enabled; |
| 40 | int steps; |
| 41 | int height; |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 42 | #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS |
| 43 | int event_irq; |
| 44 | int event_val; |
| 45 | bool event_en; |
Cristina Opriceana | fd2bb31 | 2015-09-11 16:59:30 +0300 | [diff] [blame] | 46 | s64 event_timestamp; |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 47 | #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */ |
| 48 | }; |
| 49 | |
| 50 | #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS |
| 51 | |
| 52 | struct iio_dev; |
| 53 | |
| 54 | int iio_simple_dummy_read_event_config(struct iio_dev *indio_dev, |
Lars-Peter Clausen | bda624b | 2013-10-07 15:11:00 +0100 | [diff] [blame] | 55 | const struct iio_chan_spec *chan, |
| 56 | enum iio_event_type type, |
| 57 | enum iio_event_direction dir); |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 58 | |
| 59 | int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev, |
Lars-Peter Clausen | bda624b | 2013-10-07 15:11:00 +0100 | [diff] [blame] | 60 | const struct iio_chan_spec *chan, |
| 61 | enum iio_event_type type, |
| 62 | enum iio_event_direction dir, |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 63 | int state); |
| 64 | |
| 65 | int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev, |
Lars-Peter Clausen | bda624b | 2013-10-07 15:11:00 +0100 | [diff] [blame] | 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); |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 71 | |
| 72 | int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev, |
Lars-Peter Clausen | bda624b | 2013-10-07 15:11:00 +0100 | [diff] [blame] | 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); |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 78 | |
| 79 | int iio_simple_dummy_events_register(struct iio_dev *indio_dev); |
Vladimirs Ambrosovs | 62a90da | 2015-05-30 11:20:16 +0300 | [diff] [blame] | 80 | void iio_simple_dummy_events_unregister(struct iio_dev *indio_dev); |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 81 | |
| 82 | #else /* Stubs for when events are disabled at compile time */ |
| 83 | |
| 84 | static inline int |
| 85 | iio_simple_dummy_events_register(struct iio_dev *indio_dev) |
| 86 | { |
| 87 | return 0; |
Peter Meerwald-Stadler | 83b0b39 | 2016-12-20 17:38:10 +0100 | [diff] [blame] | 88 | } |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 89 | |
Vladimirs Ambrosovs | 62a90da | 2015-05-30 11:20:16 +0300 | [diff] [blame] | 90 | static inline void |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 91 | iio_simple_dummy_events_unregister(struct iio_dev *indio_dev) |
Peter Meerwald-Stadler | 83b0b39 | 2016-12-20 17:38:10 +0100 | [diff] [blame] | 92 | {} |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 93 | |
| 94 | #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/ |
| 95 | |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 96 | /** |
| 97 | * enum iio_simple_dummy_scan_elements - scan index enum |
Alison Schofield | f8087ab | 2015-10-26 13:48:23 -0700 | [diff] [blame] | 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 |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 102 | * |
| 103 | * Enum provides convenient numbering for the scan index. |
| 104 | */ |
| 105 | enum iio_simple_dummy_scan_elements { |
Alison Schofield | f8087ab | 2015-10-26 13:48:23 -0700 | [diff] [blame] | 106 | DUMMY_INDEX_VOLTAGE_0, |
| 107 | DUMMY_INDEX_DIFFVOLTAGE_1M2, |
| 108 | DUMMY_INDEX_DIFFVOLTAGE_3M4, |
| 109 | DUMMY_INDEX_ACCELX, |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 110 | }; |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 111 | |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 112 | #ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER |
Lars-Peter Clausen | 4ae0301 | 2014-11-26 18:55:11 +0100 | [diff] [blame] | 113 | int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev); |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 114 | void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev); |
| 115 | #else |
Vlad Dogaru | 75d44ce | 2014-12-29 11:50:16 +0200 | [diff] [blame] | 116 | static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev) |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 117 | { |
| 118 | return 0; |
Peter Meerwald-Stadler | 83b0b39 | 2016-12-20 17:38:10 +0100 | [diff] [blame] | 119 | } |
Cristina Opriceana | 862cb6c | 2015-07-10 17:10:21 +0300 | [diff] [blame] | 120 | |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 121 | static inline |
| 122 | void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev) |
Peter Meerwald-Stadler | 83b0b39 | 2016-12-20 17:38:10 +0100 | [diff] [blame] | 123 | {} |
Roberta Dobrescu | f3f883b | 2014-09-25 16:58:07 +0300 | [diff] [blame] | 124 | |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 125 | #endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */ |
Roberta Dobrescu | f3f883b | 2014-09-25 16:58:07 +0300 | [diff] [blame] | 126 | #endif /* _IIO_SIMPLE_DUMMY_H_ */ |