iio_simple_dummy.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /**
  3. * Copyright (c) 2011 Jonathan Cameron
  4. *
  5. * Join together the various functionality of iio_simple_dummy driver
  6. */
  7. #ifndef _IIO_SIMPLE_DUMMY_H_
  8. #define _IIO_SIMPLE_DUMMY_H_
  9. #include <linux/kernel.h>
  10. struct iio_dummy_accel_calibscale;
  11. struct iio_dummy_regs;
  12. /**
  13. * struct iio_dummy_state - device instance specific state.
  14. * @dac_val: cache for dac value
  15. * @single_ended_adc_val: cache for single ended adc value
  16. * @differential_adc_val: cache for differential adc value
  17. * @accel_val: cache for acceleration value
  18. * @accel_calibbias: cache for acceleration calibbias
  19. * @accel_calibscale: cache for acceleration calibscale
  20. * @lock: lock to ensure state is consistent
  21. * @event_irq: irq number for event line (faked)
  22. * @event_val: cache for event threshold value
  23. * @event_en: cache of whether event is enabled
  24. */
  25. struct iio_dummy_state {
  26. int dac_val;
  27. int single_ended_adc_val;
  28. int differential_adc_val[2];
  29. int accel_val;
  30. int accel_calibbias;
  31. int activity_running;
  32. int activity_walking;
  33. const struct iio_dummy_accel_calibscale *accel_calibscale;
  34. struct mutex lock;
  35. struct iio_dummy_regs *regs;
  36. int steps_enabled;
  37. int steps;
  38. int height;
  39. #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
  40. int event_irq;
  41. int event_val;
  42. bool event_en;
  43. s64 event_timestamp;
  44. #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
  45. };
  46. #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
  47. struct iio_dev;
  48. int iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
  49. const struct iio_chan_spec *chan,
  50. enum iio_event_type type,
  51. enum iio_event_direction dir);
  52. int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
  53. const struct iio_chan_spec *chan,
  54. enum iio_event_type type,
  55. enum iio_event_direction dir,
  56. int state);
  57. int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
  58. const struct iio_chan_spec *chan,
  59. enum iio_event_type type,
  60. enum iio_event_direction dir,
  61. enum iio_event_info info, int *val,
  62. int *val2);
  63. int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
  64. const struct iio_chan_spec *chan,
  65. enum iio_event_type type,
  66. enum iio_event_direction dir,
  67. enum iio_event_info info, int val,
  68. int val2);
  69. int iio_simple_dummy_events_register(struct iio_dev *indio_dev);
  70. void iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
  71. #else /* Stubs for when events are disabled at compile time */
  72. static inline int
  73. iio_simple_dummy_events_register(struct iio_dev *indio_dev)
  74. {
  75. return 0;
  76. }
  77. static inline void
  78. iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
  79. {}
  80. #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
  81. /**
  82. * enum iio_simple_dummy_scan_elements - scan index enum
  83. * @DUMMY_INDEX_VOLTAGE_0: the single ended voltage channel
  84. * @DUMMY_INDEX_DIFFVOLTAGE_1M2: first differential channel
  85. * @DUMMY_INDEX_DIFFVOLTAGE_3M4: second differential channel
  86. * @DUMMY_INDEX_ACCELX: acceleration channel
  87. *
  88. * Enum provides convenient numbering for the scan index.
  89. */
  90. enum iio_simple_dummy_scan_elements {
  91. DUMMY_INDEX_VOLTAGE_0,
  92. DUMMY_INDEX_DIFFVOLTAGE_1M2,
  93. DUMMY_INDEX_DIFFVOLTAGE_3M4,
  94. DUMMY_INDEX_ACCELX,
  95. };
  96. #ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
  97. int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev);
  98. void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
  99. #else
  100. static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
  101. {
  102. return 0;
  103. }
  104. static inline
  105. void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
  106. {}
  107. #endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */
  108. #endif /* _IIO_SIMPLE_DUMMY_H_ */