Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /**
0003  * Copyright (c) 2011 Jonathan Cameron
0004  *
0005  * Join together the various functionality of iio_simple_dummy driver
0006  */
0007 
0008 #ifndef _IIO_SIMPLE_DUMMY_H_
0009 #define _IIO_SIMPLE_DUMMY_H_
0010 #include <linux/kernel.h>
0011 
0012 struct iio_dummy_accel_calibscale;
0013 struct iio_dummy_regs;
0014 
0015 /**
0016  * struct iio_dummy_state - device instance specific state.
0017  * @dac_val:            cache for dac value
0018  * @single_ended_adc_val:   cache for single ended adc value
0019  * @differential_adc_val:   cache for differential adc value
0020  * @accel_val:          cache for acceleration value
0021  * @accel_calibbias:        cache for acceleration calibbias
0022  * @accel_calibscale:       cache for acceleration calibscale
0023  * @lock:           lock to ensure state is consistent
0024  * @event_irq:          irq number for event line (faked)
0025  * @event_val:          cache for event threshold value
0026  * @event_en:           cache of whether event is enabled
0027  */
0028 struct iio_dummy_state {
0029     int dac_val;
0030     int single_ended_adc_val;
0031     int differential_adc_val[2];
0032     int accel_val;
0033     int accel_calibbias;
0034     int activity_running;
0035     int activity_walking;
0036     const struct iio_dummy_accel_calibscale *accel_calibscale;
0037     struct mutex lock;
0038     struct iio_dummy_regs *regs;
0039     int steps_enabled;
0040     int steps;
0041     int height;
0042 #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
0043     int event_irq;
0044     int event_val;
0045     bool event_en;
0046     s64 event_timestamp;
0047 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
0048 };
0049 
0050 #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
0051 
0052 struct iio_dev;
0053 
0054 int iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
0055                        const struct iio_chan_spec *chan,
0056                        enum iio_event_type type,
0057                        enum iio_event_direction dir);
0058 
0059 int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
0060                     const struct iio_chan_spec *chan,
0061                     enum iio_event_type type,
0062                     enum iio_event_direction dir,
0063                     int state);
0064 
0065 int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
0066                       const struct iio_chan_spec *chan,
0067                       enum iio_event_type type,
0068                       enum iio_event_direction dir,
0069                       enum iio_event_info info, int *val,
0070                       int *val2);
0071 
0072 int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
0073                        const struct iio_chan_spec *chan,
0074                        enum iio_event_type type,
0075                        enum iio_event_direction dir,
0076                        enum iio_event_info info, int val,
0077                        int val2);
0078 
0079 int iio_simple_dummy_events_register(struct iio_dev *indio_dev);
0080 void iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
0081 
0082 #else /* Stubs for when events are disabled at compile time */
0083 
0084 static inline int
0085 iio_simple_dummy_events_register(struct iio_dev *indio_dev)
0086 {
0087     return 0;
0088 }
0089 
0090 static inline void
0091 iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
0092 {}
0093 
0094 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
0095 
0096 /**
0097  * enum iio_simple_dummy_scan_elements - scan index enum
0098  * @DUMMY_INDEX_VOLTAGE_0:         the single ended voltage channel
0099  * @DUMMY_INDEX_DIFFVOLTAGE_1M2:   first differential channel
0100  * @DUMMY_INDEX_DIFFVOLTAGE_3M4:   second differential channel
0101  * @DUMMY_INDEX_ACCELX:            acceleration channel
0102  *
0103  * Enum provides convenient numbering for the scan index.
0104  */
0105 enum iio_simple_dummy_scan_elements {
0106     DUMMY_INDEX_VOLTAGE_0,
0107     DUMMY_INDEX_DIFFVOLTAGE_1M2,
0108     DUMMY_INDEX_DIFFVOLTAGE_3M4,
0109     DUMMY_INDEX_ACCELX,
0110 };
0111 
0112 #ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
0113 int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev);
0114 void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
0115 #else
0116 static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
0117 {
0118     return 0;
0119 }
0120 
0121 static inline
0122 void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
0123 {}
0124 
0125 #endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */
0126 #endif /* _IIO_SIMPLE_DUMMY_H_ */