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 | |
| 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, |
Lars-Peter Clausen | bda624b | 2013-10-07 15:11:00 +0100 | [diff] [blame^] | 48 | const struct iio_chan_spec *chan, |
| 49 | enum iio_event_type type, |
| 50 | enum iio_event_direction dir); |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 51 | |
| 52 | 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^] | 53 | const struct iio_chan_spec *chan, |
| 54 | enum iio_event_type type, |
| 55 | enum iio_event_direction dir, |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 56 | int state); |
| 57 | |
| 58 | 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^] | 59 | 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 Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 64 | |
| 65 | 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^] | 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_events_register(struct iio_dev *indio_dev); |
| 73 | int iio_simple_dummy_events_unregister(struct iio_dev *indio_dev); |
| 74 | |
| 75 | #else /* Stubs for when events are disabled at compile time */ |
| 76 | |
| 77 | static inline int |
| 78 | iio_simple_dummy_events_register(struct iio_dev *indio_dev) |
| 79 | { |
| 80 | return 0; |
| 81 | }; |
| 82 | |
| 83 | static inline int |
| 84 | iio_simple_dummy_events_unregister(struct iio_dev *indio_dev) |
| 85 | { |
| 86 | return 0; |
| 87 | }; |
| 88 | |
| 89 | #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/ |
| 90 | |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 91 | /** |
| 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 | */ |
| 100 | enum iio_simple_dummy_scan_elements { |
| 101 | voltage0, |
| 102 | diffvoltage1m2, |
| 103 | diffvoltage3m4, |
| 104 | accelx, |
| 105 | }; |
Jonathan Cameron | e647700 | 2011-10-14 16:34:14 +0100 | [diff] [blame] | 106 | |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 107 | #ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER |
Lars-Peter Clausen | 3fff227 | 2012-09-12 12:06:00 +0100 | [diff] [blame] | 108 | int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev, |
| 109 | const struct iio_chan_spec *channels, unsigned int num_channels); |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 110 | void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev); |
| 111 | #else |
Lars-Peter Clausen | 3fff227 | 2012-09-12 12:06:00 +0100 | [diff] [blame] | 112 | static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev, |
| 113 | const struct iio_chan_spec *channels, unsigned int num_channels) |
Jonathan Cameron | 9ad2e2e | 2011-10-14 16:34:15 +0100 | [diff] [blame] | 114 | { |
| 115 | return 0; |
| 116 | }; |
| 117 | static inline |
| 118 | void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev) |
| 119 | {}; |
| 120 | #endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */ |