accel.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef __ACC_H__
  2. #define __ACC_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/ioctl.h>
  18. #include <batch.h>
  19. #include <sensors_io.h>
  20. #include <hwmsen_helper.h>
  21. #include <hwmsensor.h>
  22. #include <hwmsen_dev.h>
  23. #define ACC_TAG "<ACCELEROMETER> "
  24. #define ACC_ERR(fmt, args...) pr_err(ACC_TAG fmt, ##args)
  25. #define ACC_LOG(fmt, args...) pr_debug(ACC_TAG fmt, ##args)
  26. #define ACC_VER(fmt, args...) pr_debug(ACC_TAG fmt, ##args)
  27. #define OP_ACC_DELAY 0X01
  28. #define OP_ACC_ENABLE 0X02
  29. #define OP_ACC_GET_DATA 0X04
  30. #define ACC_INVALID_VALUE -1
  31. #define EVENT_TYPE_ACCEL_X ABS_X
  32. #define EVENT_TYPE_ACCEL_Y ABS_Y
  33. #define EVENT_TYPE_ACCEL_Z ABS_Z
  34. #define EVENT_TYPE_ACCEL_UPDATE REL_X
  35. #define EVENT_TYPE_ACCEL_TIMESTAMP_HI REL_HWHEEL
  36. #define EVENT_TYPE_ACCEL_TIMESTAMP_LO REL_DIAL
  37. #define EVENT_TYPE_ACCEL_STATUS ABS_WHEEL
  38. #define EVENT_TYPE_ACCEL_DIV ABS_GAS
  39. #define ACC_VALUE_MAX (32767)
  40. #define ACC_VALUE_MIN (-32768)
  41. #define ACC_STATUS_MIN (0)
  42. #define ACC_STATUS_MAX (64)
  43. #define ACC_DIV_MAX (32767)
  44. #define ACC_DIV_MIN (1)
  45. #define ACC_AXIS_X 0
  46. #define ACC_AXIS_Y 1
  47. #define ACC_AXIS_Z 2
  48. #define MAX_CHOOSE_G_NUM 5
  49. #define ACC_AXES_NUM 3
  50. struct acc_control_path {
  51. int (*open_report_data)(int open);/* open data rerport to HAL */
  52. int (*enable_nodata)(int en);/* only enable not report event to HAL */
  53. int (*set_delay)(u64 delay);
  54. int (*access_data_fifo)(void);/* version2.used for flush operate */
  55. bool is_report_input_direct;
  56. bool is_support_batch;/* version2.used for batch mode support flag */
  57. bool is_use_common_factory;
  58. int (*acc_calibration)(int type, int cali[3]);/* version3 sensor common layer factory mode API1 */
  59. };
  60. struct acc_data_path {
  61. int (*get_data)(int *x, int *y, int *z, int *status);
  62. int (*get_raw_data)(int *x, int *y, int *z);
  63. int vender_div;
  64. };
  65. struct acc_init_info {
  66. char *name;
  67. int (*init)(void);
  68. int (*uninit)(void);
  69. struct platform_driver *platform_diver_addr;
  70. };
  71. struct acc_data {
  72. struct hwm_sensor_data acc_data;
  73. int data_updata;
  74. /* struct mutex lock; */
  75. };
  76. struct acc_drv_obj {
  77. void *self;
  78. int polling;
  79. int (*acc_operate)(void *self, uint32_t command, void *buff_in, int size_in,
  80. void *buff_out, int size_out, int *actualout);
  81. };
  82. struct acc_context {
  83. struct input_dev *idev;
  84. struct miscdevice mdev;
  85. struct work_struct report;
  86. struct mutex acc_op_mutex;
  87. atomic_t delay; /*polling period for reporting input event*/
  88. atomic_t wake; /*user-space request to wake-up, used with stop*/
  89. struct timer_list timer; /* polling timer */
  90. struct hrtimer hrTimer;
  91. ktime_t target_ktime;
  92. atomic_t trace;
  93. struct workqueue_struct *accel_workqueue;
  94. atomic_t early_suspend;
  95. /* struct acc_drv_obj drv_obj; */
  96. struct acc_data drv_data;
  97. int cali_sw[ACC_AXES_NUM+1];
  98. struct acc_control_path acc_ctl;
  99. struct acc_data_path acc_data;
  100. /* Active, but HAL don't need data sensor. such as orientation need */
  101. bool is_active_nodata;
  102. bool is_active_data; /* Active and HAL need data . */
  103. bool is_first_data_after_enable;
  104. bool is_polling_run;
  105. bool is_batch_enable; /* version2.this is used for judging whether sensor is in batch mode */
  106. };
  107. /* for auto detect */
  108. extern int acc_driver_add(struct acc_init_info *obj);
  109. extern int acc_data_report(int x, int y, int z, int status, int64_t nt);
  110. extern int acc_register_control_path(struct acc_control_path *ctl);
  111. extern int acc_register_data_path(struct acc_data_path *data);
  112. #endif