gravity.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef __GRAV_H__
  2. #define __GRAV_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/hwmsensor.h>
  12. #include <linux/earlysuspend.h>
  13. #include <linux/hwmsen_dev.h>
  14. /* #define DEBUG */
  15. #ifdef DEBUG
  16. #define GRAV_TAG "<GRAVITYSENSOR> "
  17. #define GRAV_FUN(f) pr_debug(GRAV_TAG"%s\n", __func__)
  18. #define GRAV_ERR(fmt, args...) pr_err(GRAV_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
  19. #define GRAV_LOG(fmt, args...) pr_debug(GRAV_TAG fmt, ##args)
  20. #define GRAV_VER(fmt, args...) pr_debug(GRAV_TAG"%s: "fmt, __func__, ##args) /* ((void)0) */
  21. #else
  22. #define GRAV_TAG "<GRAVITYSENSOR> "
  23. #define GRAV_FUN(f)
  24. #define GRAV_ERR(fmt, args...)
  25. #define GRAV_LOG(fmt, args...)
  26. #define GRAV_VER(fmt, args...)
  27. #endif
  28. #define OP_GRAV_DELAY 0X01
  29. #define OP_GRAV_ENABLE 0X02
  30. #define OP_GRAV_GET_DATA 0X04
  31. #define GRAV_INVALID_VALUE -1
  32. #define EVENT_TYPE_GRAV_X ABS_RX
  33. #define EVENT_TYPE_GRAV_Y ABS_Y
  34. #define EVENT_TYPE_GRAV_Z ABS_Z
  35. #define EVENT_TYPE_GRAV_STATUS REL_X
  36. #define GRAV_VALUE_MAX (32767)
  37. #define GRAV_VALUE_MIN (-32768)
  38. #define GRAV_STATUS_MIN (0)
  39. #define GRAV_STATUS_MAX (64)
  40. #define GRAV_DIV_MAX (32767)
  41. #define GRAV_DIV_MIN (1)
  42. #define GRAV_AXIS_X 0
  43. #define GRAV_AXIS_Y 1
  44. #define GRAV_AXIS_Z 2
  45. #define MAX_CHOOSE_GRAV_NUM 5
  46. #define GRAV_AXES_NUM 3
  47. struct grav_control_path {
  48. int (*open_report_data)(int open); /* open data rerport to HAL */
  49. int (*enable_nodata)(int en); /* only enable not report event to HAL */
  50. int (*set_delay)(u64 delay);
  51. int (*access_data_fifo)(void); /* version2.used for flush operate */
  52. bool is_report_input_direct;
  53. bool is_support_batch; /* version2.used for batch mode support flag */
  54. int (*grav_calibration)(int type, int cali[3]); /* version3 sensor common layer factory mode API1 */
  55. };
  56. struct grav_data_path {
  57. int (*get_data)(int *x, int *y, int *z, int *status);
  58. int (*get_raw_data)(int *x, int *y, int *z); /* version3 sensor common layer factory mode API2 */
  59. int vender_div;
  60. };
  61. struct grav_init_info {
  62. char *name;
  63. int (*init)(void);
  64. int (*uninit)(void);
  65. struct platform_driver *platform_diver_addr;
  66. };
  67. struct grav_data {
  68. hwm_sensor_data grav_data;
  69. int data_updata;
  70. /* struct mutex lock; */
  71. };
  72. struct grav_drv_obj {
  73. void *self;
  74. int polling;
  75. int (*grav_operate)(void *self, uint32_t command, void *buff_in, int size_in,
  76. void *buff_out, int size_out, int *actualout);
  77. };
  78. struct grav_context {
  79. struct input_dev *idev;
  80. struct miscdevice mdev;
  81. struct work_struct report;
  82. struct mutex grav_op_mutex;
  83. atomic_t delay; /*polling period for reporting input event */
  84. atomic_t wake; /*user-space request to wake-up, used with stop */
  85. struct timer_list timer; /* polling timer */
  86. atomic_t trace;
  87. struct early_suspend early_drv;
  88. atomic_t early_suspend;
  89. /* struct grav_drv_obj drv_obj; */
  90. struct grav_data drv_data;
  91. int cali_sw[GRAV_AXES_NUM + 1];
  92. struct grav_control_path grav_ctl;
  93. struct grav_data_path grav_data;
  94. bool is_active_nodata; /* Active, but HAL don't need data sensor. such as orientation need */
  95. bool is_active_data; /* Active and HAL need data . */
  96. bool is_first_data_after_enable;
  97. bool is_polling_run;
  98. bool is_batch_enable; /* version2.this is used for judging whether sensor is in batch mode */
  99. };
  100. /* driver API for internal */
  101. /* extern int grav_enable_nodata(int enable); */
  102. /* extern int grav_attach(struct grav_drv_obj *obj); */
  103. /* driver API for third party vendor */
  104. /* for auto detect */
  105. extern int grav_driver_add(struct grav_init_info *obj);
  106. extern int grav_data_report(int x, int y, int z, int status);
  107. extern int grav_register_control_path(struct grav_control_path *ctl);
  108. extern int grav_register_data_path(struct grav_data_path *data);
  109. #endif