Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 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 | |
Roberta Dobrescu | f3f883b | 2014-09-25 16:58:07 +0300 | [diff] [blame] | 11 | #ifndef _IIO_SIMPLE_DUMMY_H_ |
| 12 | #define _IIO_SIMPLE_DUMMY_H_ |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 13 | #include <linux/kernel.h> |
| 14 | |
| 15 | struct iio_dummy_accel_calibscale; |
Daniel Baluta | 356ae94 | 2014-11-10 14:45:29 +0200 | [diff] [blame] | 16 | struct iio_dummy_regs; |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 17 | |
| 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. Garcia | 69e98df | 2015-04-24 09:40:42 -0400 | [diff] [blame] | 28 | * @event_val: cache for event threshold value |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 29 | * @event_en: cache of whether event is enabled |
| 30 | */ |
| 31 | struct 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 Baluta | 3e34e65 | 2014-11-10 14:45:34 +0200 | [diff] [blame] | 37 | int activity_running; |
| 38 | int activity_walking; |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 39 | const struct iio_dummy_accel_calibscale *accel_calibscale; |
| 40 | struct mutex lock; |
Daniel Baluta | 356ae94 | 2014-11-10 14:45:29 +0200 | [diff] [blame] | 41 | struct iio_dummy_regs *regs; |
Daniel Baluta | 3e34e65 | 2014-11-10 14:45:34 +0200 | [diff] [blame] | 42 | int steps_enabled; |
| 43 | int steps; |
| 44 | int height; |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 45 | #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS |
| 46 | int event_irq; |
| 47 | int event_val; |
| 48 | bool event_en; |
| 49 | #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */ |
| 50 | }; |
| 51 | |
| 52 | #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS |
| 53 | |
| 54 | struct iio_dev; |
| 55 | |
| 56 | 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] | 57 | const struct iio_chan_spec *chan, |
| 58 | enum iio_event_type type, |
| 59 | enum iio_event_direction dir); |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 60 | |
| 61 | 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] | 62 | const struct iio_chan_spec *chan, |
| 63 | enum iio_event_type type, |
| 64 | enum iio_event_direction dir, |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 65 | int state); |
| 66 | |
| 67 | 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] | 68 | const struct iio_chan_spec *chan, |
| 69 | enum iio_event_type type, |
| 70 | enum iio_event_direction dir, |
| 71 | enum iio_event_info info, int *val, |
| 72 | int *val2); |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 73 | |
| 74 | 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] | 75 | const struct iio_chan_spec *chan, |
| 76 | enum iio_event_type type, |
| 77 | enum iio_event_direction dir, |
| 78 | enum iio_event_info info, int val, |
| 79 | int val2); |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 80 | |
| 81 | int iio_simple_dummy_events_register(struct iio_dev *indio_dev); |
Vladimirs Ambrosovs | 62a90da | 2015-05-30 11:20:16 +0300 | [diff] [blame] | 82 | void iio_simple_dummy_events_unregister(struct iio_dev *indio_dev); |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 83 | |
| 84 | #else /* Stubs for when events are disabled at compile time */ |
| 85 | |
| 86 | static inline int |
| 87 | iio_simple_dummy_events_register(struct iio_dev *indio_dev) |
| 88 | { |
| 89 | return 0; |
| 90 | }; |
| 91 | |
Vladimirs Ambrosovs | 62a90da | 2015-05-30 11:20:16 +0300 | [diff] [blame] | 92 | static inline void |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 93 | iio_simple_dummy_events_unregister(struct iio_dev *indio_dev) |
Vladimirs Ambrosovs | 62a90da | 2015-05-30 11:20:16 +0300 | [diff] [blame] | 94 | { }; |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 95 | |
| 96 | #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/ |
| 97 | |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 98 | /** |
| 99 | * enum iio_simple_dummy_scan_elements - scan index enum |
| 100 | * @voltage0: the single ended voltage channel |
| 101 | * @diffvoltage1m2: first differential channel |
| 102 | * @diffvoltage3m4: second differenial channel |
| 103 | * @accelx: acceleration channel |
| 104 | * |
| 105 | * Enum provides convenient numbering for the scan index. |
| 106 | */ |
| 107 | enum iio_simple_dummy_scan_elements { |
| 108 | voltage0, |
| 109 | diffvoltage1m2, |
| 110 | diffvoltage3m4, |
| 111 | accelx, |
| 112 | }; |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 113 | |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 114 | #ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER |
Lars-Peter Clausen | 4ae0301 | 2014-11-26 18:55:11 +0100 | [diff] [blame] | 115 | int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev); |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 116 | void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev); |
| 117 | #else |
Vlad Dogaru | 75d44ce | 2014-12-29 11:50:16 +0200 | [diff] [blame] | 118 | 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] | 119 | { |
| 120 | return 0; |
| 121 | }; |
Cristina Opriceana | 862cb6c | 2015-07-10 17:10:21 +0300 | [diff] [blame] | 122 | |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 123 | static inline |
| 124 | void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev) |
| 125 | {}; |
Roberta Dobrescu | f3f883b | 2014-09-25 16:58:07 +0300 | [diff] [blame] | 126 | |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 127 | #endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */ |
Roberta Dobrescu | f3f883b | 2014-09-25 16:58:07 +0300 | [diff] [blame] | 128 | #endif /* _IIO_SIMPLE_DUMMY_H_ */ |