sensors.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Copyright (c) 2013, 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. /**
  46. * struct sensors_classdev - hold the sensor general parameters and APIs
  47. * @dev: The device to register.
  48. * @node: The list for the all the sensor drivers.
  49. * @name: Name of this sensor.
  50. * @vendor: The vendor of the hardware part.
  51. * @handle: The handle that identifies this sensors.
  52. * @type: The sensor type.
  53. * @max_range: The maximum range of this sensor's value in SI units.
  54. * @resolution: The smallest difference between two values reported by
  55. * this sensor.
  56. * @sensor_power: The rough estimate of this sensor's power consumption
  57. * in mA.
  58. * @min_delay: This value depends on the trigger mode:
  59. * continuous: minimum period allowed in microseconds
  60. * on-change : 0
  61. * one-shot :-1
  62. * special : 0, unless otherwise noted
  63. * @fifo_reserved_event_count: The number of events reserved for this sensor
  64. * in the batch mode FIFO.
  65. * @fifo_max_event_count: The maximum number of events of this sensor
  66. * that could be batched.
  67. * @enabled: Store the sensor driver enable status.
  68. * @delay_msec: Store the sensor driver delay value. The data unit is
  69. * millisecond.
  70. * @sensors_enable: The handle for enable and disable sensor.
  71. * @sensors_poll_delay: The handle for set the sensor polling delay time.
  72. */
  73. struct sensors_classdev {
  74. struct device *dev;
  75. struct list_head node;
  76. const char *name;
  77. const char *vendor;
  78. int version;
  79. int handle;
  80. int type;
  81. const char *max_range;
  82. const char *resolution;
  83. const char *sensor_power;
  84. int min_delay;
  85. int fifo_reserved_event_count;
  86. int fifo_max_event_count;
  87. unsigned int enabled;
  88. unsigned int delay_msec;
  89. /* enable and disable the sensor handle*/
  90. int (*sensors_enable)(struct sensors_classdev *sensors_cdev,
  91. unsigned int enabled);
  92. int (*sensors_poll_delay)(struct sensors_classdev *sensors_cdev,
  93. unsigned int delay_msec);
  94. };
  95. extern int sensors_classdev_register(struct device *parent,
  96. struct sensors_classdev *sensors_cdev);
  97. extern void sensors_classdev_unregister(struct sensors_classdev *sensors_cdev);
  98. #endif /* __LINUX_SENSORS_H_INCLUDED */