gyroscope.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifndef __GYROSCOPE_H__
  2. #define __GYROSCOPE_H__
  3. #include <linux/wakelock.h>
  4. #include <linux/interrupt.h>
  5. #include <linux/miscdevice.h>
  6. #include <linux/platform_device.h>
  7. #include <linux/input.h>
  8. #include <linux/workqueue.h>
  9. #include <linux/slab.h>
  10. #include <linux/module.h>
  11. #include <linux/i2c.h>
  12. #include <linux/irq.h>
  13. #include <linux/uaccess.h>
  14. #include <linux/delay.h>
  15. #include <linux/kobject.h>
  16. #include <linux/atomic.h>
  17. #include <linux/kernel.h>
  18. #include <hwmsensor.h>
  19. #include <hwmsen_dev.h>
  20. #include <sensors_io.h>
  21. #include <hwmsen_helper.h>
  22. #include <batch.h>
  23. #include "gyro_factory.h"
  24. #ifndef FALSE
  25. #define FALSE (0)
  26. #endif
  27. #ifndef TRUE
  28. #define TRUE (1)
  29. #endif
  30. #define GYRO_TAG "<GYROSCOPE> "
  31. #define GYRO_FUN(f) pr_debug(GYRO_TAG"%s\n", __func__)
  32. #define GYRO_ERR(fmt, args...) pr_err(GYRO_TAG fmt, ##args)
  33. #define GYRO_LOG(fmt, args...) pr_debug(GYRO_TAG fmt, ##args)
  34. #define GYRO_VER(fmt, args...) pr_debug(GYRO_TAG fmt, ##args)
  35. #define OP_GYRO_DELAY 0X01
  36. #define OP_GYRO_ENABLE 0X02
  37. #define OP_GYRO_GET_DATA 0X04
  38. #define GYRO_INVALID_VALUE -1
  39. #define EVENT_TYPE_GYRO_X ABS_X
  40. #define EVENT_TYPE_GYRO_Y ABS_Y
  41. #define EVENT_TYPE_GYRO_Z ABS_Z
  42. #define EVENT_TYPE_GYRO_UPDATE REL_X
  43. #define EVENT_TYPE_GYRO_STATUS ABS_WHEEL
  44. #define EVENT_TYPE_GYRO_UPDATE REL_X
  45. #define EVENT_TYPE_GYRO_TIMESTAMP_HI REL_HWHEEL
  46. #define EVENT_TYPE_GYRO_TIMESTAMP_LO REL_DIAL
  47. #define GYRO_VALUE_MAX (32767)
  48. #define GYRO_VALUE_MIN (-32768)
  49. #define GYRO_STATUS_MIN (0)
  50. #define GYRO_STATUS_MAX (64)
  51. #define GYRO_DIV_MAX (32767)
  52. #define GYRO_DIV_MIN (1)
  53. #define GYRO_AXIS_X 0
  54. #define GYRO_AXIS_Y 1
  55. #define GYRO_AXIS_Z 2
  56. #define MAX_CHOOSE_GYRO_NUM 5
  57. #define GYRO_AXES_NUM 3
  58. struct gyro_control_path {
  59. int (*open_report_data)(int open);
  60. int (*enable_nodata)(int en);
  61. int (*set_delay)(u64 delay);
  62. bool is_report_input_direct;
  63. bool is_support_batch;
  64. int (*gyro_calibration)(int type, int cali[3]);
  65. bool is_use_common_factory;
  66. };
  67. struct gyro_data_path {
  68. int (*get_data)(int *x, int *y, int *z, int *status);
  69. int (*get_raw_data)(int *x, int *y, int *z);
  70. int vender_div;
  71. };
  72. struct gyro_init_info {
  73. char *name;
  74. int (*init)(struct platform_device *pdev);
  75. int (*uninit)(void);
  76. struct platform_driver *platform_diver_addr;
  77. };
  78. struct gyro_data {
  79. struct hwm_sensor_data gyro_data;
  80. int data_updata;
  81. };
  82. struct gyro_drv_obj {
  83. void *self;
  84. int polling;
  85. int (*gyro_operate)(void *self, uint32_t command, void *buff_in, int size_in,
  86. void *buff_out, int size_out, int *actualout);
  87. };
  88. struct gyro_context {
  89. struct input_dev *idev;
  90. struct miscdevice mdev;
  91. struct work_struct report;
  92. struct mutex gyro_op_mutex;
  93. atomic_t delay; /*polling period for reporting input event*/
  94. atomic_t wake; /*user-space request to wake-up, used with stop*/
  95. struct timer_list timer; /* polling timer */
  96. struct hrtimer hrTimer;
  97. ktime_t target_ktime;
  98. atomic_t trace;
  99. struct workqueue_struct *gyro_workqueue;
  100. struct gyro_data drv_data;
  101. int cali_sw[GYRO_AXES_NUM+1];
  102. struct gyro_control_path gyro_ctl;
  103. struct gyro_data_path gyro_data;
  104. bool is_active_nodata; /*Active, but HAL don't need data sensor. such as orientation need*/
  105. bool is_active_data; /* Active and HAL need data .*/
  106. bool is_first_data_after_enable;
  107. bool is_polling_run;
  108. bool is_batch_enable;
  109. };
  110. extern int gyro_driver_add(struct gyro_init_info *obj);
  111. extern int gyro_data_report(int x, int y, int z, int status, int64_t nt);
  112. extern int gyro_register_control_path(struct gyro_control_path *ctl);
  113. extern int gyro_register_data_path(struct gyro_data_path *data);
  114. #endif