iio_simple_dummy.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #ifndef _IIO_SIMPLE_DUMMY_H_
  11. #define _IIO_SIMPLE_DUMMY_H_
  12. #include <linux/kernel.h>
  13. struct iio_dummy_accel_calibscale;
  14. struct iio_dummy_regs;
  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 threshold 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. int activity_running;
  35. int activity_walking;
  36. const struct iio_dummy_accel_calibscale *accel_calibscale;
  37. struct mutex lock;
  38. struct iio_dummy_regs *regs;
  39. int steps_enabled;
  40. int steps;
  41. int height;
  42. #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
  43. int event_irq;
  44. int event_val;
  45. bool event_en;
  46. s64 event_timestamp;
  47. #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
  48. };
  49. #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
  50. struct iio_dev;
  51. int iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
  52. const struct iio_chan_spec *chan,
  53. enum iio_event_type type,
  54. enum iio_event_direction dir);
  55. int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
  56. const struct iio_chan_spec *chan,
  57. enum iio_event_type type,
  58. enum iio_event_direction dir,
  59. int state);
  60. int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
  61. const struct iio_chan_spec *chan,
  62. enum iio_event_type type,
  63. enum iio_event_direction dir,
  64. enum iio_event_info info, int *val,
  65. int *val2);
  66. int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
  67. const struct iio_chan_spec *chan,
  68. enum iio_event_type type,
  69. enum iio_event_direction dir,
  70. enum iio_event_info info, int val,
  71. int val2);
  72. int iio_simple_dummy_events_register(struct iio_dev *indio_dev);
  73. void iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
  74. #else /* Stubs for when events are disabled at compile time */
  75. static inline int
  76. iio_simple_dummy_events_register(struct iio_dev *indio_dev)
  77. {
  78. return 0;
  79. }
  80. static inline void
  81. iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
  82. {}
  83. #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
  84. /**
  85. * enum iio_simple_dummy_scan_elements - scan index enum
  86. * @DUMMY_INDEX_VOLTAGE_0: the single ended voltage channel
  87. * @DUMMY_INDEX_DIFFVOLTAGE_1M2: first differential channel
  88. * @DUMMY_INDEX_DIFFVOLTAGE_3M4: second differential channel
  89. * @DUMMY_INDEX_ACCELX: acceleration channel
  90. *
  91. * Enum provides convenient numbering for the scan index.
  92. */
  93. enum iio_simple_dummy_scan_elements {
  94. DUMMY_INDEX_VOLTAGE_0,
  95. DUMMY_INDEX_DIFFVOLTAGE_1M2,
  96. DUMMY_INDEX_DIFFVOLTAGE_3M4,
  97. DUMMY_INDEX_ACCELX,
  98. };
  99. #ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
  100. int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev);
  101. void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
  102. #else
  103. static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
  104. {
  105. return 0;
  106. }
  107. static inline
  108. void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
  109. {}
  110. #endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */
  111. #endif /* _IIO_SIMPLE_DUMMY_H_ */