sensors.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef __LINUX_SENSORS_H_INCLUDED
  13. #define __LINUX_SENSORS_H_INCLUDED
  14. #include <linux/list.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/rwsem.h>
  17. #define SENSORS_ACCELERATION_HANDLE 0
  18. #define SENSORS_MAGNETIC_FIELD_HANDLE 1
  19. #define SENSORS_ORIENTATION_HANDLE 2
  20. #define SENSORS_LIGHT_HANDLE 3
  21. #define SENSORS_PROXIMITY_HANDLE 4
  22. #define SENSORS_GYROSCOPE_HANDLE 5
  23. #define SENSORS_PRESSURE_HANDLE 6
  24. #define SENSOR_TYPE_ACCELEROMETER 1
  25. #define SENSOR_TYPE_GEOMAGNETIC_FIELD 2
  26. #define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD
  27. #define SENSOR_TYPE_ORIENTATION 3
  28. #define SENSOR_TYPE_GYROSCOPE 4
  29. #define SENSOR_TYPE_LIGHT 5
  30. #define SENSOR_TYPE_PRESSURE 6
  31. #define SENSOR_TYPE_TEMPERATURE 7
  32. #define SENSOR_TYPE_PROXIMITY 8
  33. #define SENSOR_TYPE_GRAVITY 9
  34. #define SENSOR_TYPE_LINEAR_ACCELERATION 10
  35. #define SENSOR_TYPE_ROTATION_VECTOR 11
  36. #define SENSOR_TYPE_RELATIVE_HUMIDITY 12
  37. #define SENSOR_TYPE_AMBIENT_TEMPERATURE 13
  38. #define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED 14
  39. #define SENSOR_TYPE_GAME_ROTATION_VECTOR 15
  40. #define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED 16
  41. #define SENSOR_TYPE_SIGNIFICANT_MOTION 17
  42. #define SENSOR_TYPE_STEP_DETECTOR 18
  43. #define SENSOR_TYPE_STEP_COUNTER 19
  44. #define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR 20
  45. enum LIS3DH_AXIS {
  46. AXIS_X = 0,
  47. AXIS_Y,
  48. AXIS_Z,
  49. AXIS_XYZ,
  50. };
  51. enum LIS3DH_THRES {
  52. AXIS_THRESHOLD_H = 0,
  53. AXIS_THRESHOLD_L,
  54. AXIS_BIAS,
  55. };
  56. #define AXIS_FACTOR 0
  57. #define AXIS_OFFSET 1
  58. struct cal_result_t {
  59. union {
  60. struct {
  61. int offset_x; /*axis offset of x axis*/
  62. int offset_y; /*axis offset of x axis*/
  63. int offset_z; /*axis offset of x axis*/
  64. };
  65. struct {
  66. int threshold_h; /*proximity threshold_h*/
  67. int threshold_l; /*proximity threshold_l*/
  68. int bias; /*proximity measure data noise*/
  69. };
  70. int offset[3];
  71. };
  72. int factor; /*light sensor factor for real ligt strength*/
  73. int range;
  74. struct cal_result_t *node;
  75. };
  76. /**
  77. * struct sensors_classdev - hold the sensor general parameters and APIs
  78. * @dev: The device to register.
  79. * @node: The list for the all the sensor drivers.
  80. * @name: Name of this sensor.
  81. * @vendor: The vendor of the hardware part.
  82. * @handle: The handle that identifies this sensors.
  83. * @type: The sensor type.
  84. * @max_range: The maximum range of this sensor's value in SI units.
  85. * @resolution: The smallest difference between two values reported by
  86. * this sensor.
  87. * @sensor_power: The rough estimate of this sensor's power consumption
  88. * in mA.
  89. * @min_delay: This value depends on the trigger mode:
  90. * continuous: minimum period allowed in microseconds
  91. * on-change : 0
  92. * one-shot :-1
  93. * special : 0, unless otherwise noted
  94. * @fifo_reserved_event_count: The number of events reserved for this sensor
  95. * in the batch mode FIFO.
  96. * @fifo_max_event_count: The maximum number of events of this sensor
  97. * that could be batched.
  98. * @max_delay: The slowest rate the sensor supports in millisecond.
  99. * @flags: Should be '1' if the sensor is a wake up sensor.
  100. * set it to '0' otherwise.
  101. * @enabled: Store the sensor driver enable status.
  102. * @delay_msec: Store the sensor driver delay value. The data unit is
  103. * millisecond.
  104. * @wakeup: Indicate if the wake up interrupt has been enabled.
  105. * @max_latency: Max report latency in millisecond
  106. * @sensors_enable: The handle for enable and disable sensor.
  107. * @sensors_poll_delay: The handle for set the sensor polling delay time.
  108. * @sensors_set_latency:Set the max report latency of the sensor.
  109. * @sensors_flush: Flush sensor events in FIFO and report it to user space.
  110. * @params The sensor calibrate string format params up to userspace.
  111. * @cal_result The sensor calibrate parameters, cal_result is a struct for sensor.
  112. */
  113. struct sensors_classdev {
  114. struct device *dev;
  115. struct list_head node;
  116. const char *name;
  117. const char *vendor;
  118. int version;
  119. int handle;
  120. int type;
  121. const char *max_range;
  122. const char *resolution;
  123. const char *sensor_power;
  124. int min_delay;
  125. int fifo_reserved_event_count;
  126. int fifo_max_event_count;
  127. int32_t max_delay;
  128. uint32_t flags;
  129. unsigned int enabled;
  130. unsigned int delay_msec;
  131. unsigned int wakeup;
  132. unsigned int max_latency;
  133. char *params;
  134. struct cal_result_t cal_result;
  135. /* enable and disable the sensor handle*/
  136. int (*sensors_enable)(struct sensors_classdev *sensors_cdev,
  137. unsigned int enabled);
  138. int (*sensors_poll_delay)(struct sensors_classdev *sensors_cdev,
  139. unsigned int delay_msec);
  140. int (*sensors_self_test)(struct sensors_classdev *sensors_cdev);
  141. int (*sensors_set_latency)(struct sensors_classdev *sensor_cdev,
  142. unsigned int max_latency);
  143. int (*sensors_enable_wakeup)(struct sensors_classdev *sensor_cdev,
  144. unsigned int enable);
  145. int (*sensors_flush)(struct sensors_classdev *sensors_cdev);
  146. int (*sensors_calibrate)(struct sensors_classdev *sensor_cdev,
  147. int axis, int apply_now);
  148. int (*sensors_write_cal_params)(struct sensors_classdev
  149. *sensor_cdev, struct cal_result_t *cal_result);
  150. };
  151. extern int sensors_classdev_register(struct device *parent,
  152. struct sensors_classdev *sensors_cdev);
  153. extern void sensors_classdev_unregister(struct sensors_classdev *sensors_cdev);
  154. #endif /* __LINUX_SENSORS_H_INCLUDED */