rotationvector.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef __RV_H__
  2. #define __RV_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 RV_TAG "<RV> "
  17. #define RV_FUN(f) pr_debug(RV_TAG"%s\n", __func__)
  18. #define RV_ERR(fmt, args...) pr_err(RV_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
  19. #define RV_LOG(fmt, args...) pr_debug(RV_TAG fmt, ##args)
  20. #define RV_VER(fmt, args...) pr_debug(RV_TAG"%s: "fmt, __func__, ##args) /* ((void)0) */
  21. #else
  22. #define RV_TAG "<RV> "
  23. #define RV_FUN(f)
  24. #define RV_ERR(fmt, args...)
  25. #define RV_LOG(fmt, args...)
  26. #define RV_VER(fmt, args...)
  27. #endif
  28. #define OP_RV_DELAY 0X01
  29. #define OP_RV_ENABLE 0X02
  30. #define OP_RV_GET_DATA 0X04
  31. #define RV_INVALID_VALUE -1
  32. #define EVENT_TYPE_RV_X ABS_RY
  33. #define EVENT_TYPE_RV_Y ABS_RZ
  34. #define EVENT_TYPE_RV_Z ABS_THROTTLE
  35. #define EVENT_TYPE_RV_SCALAR ABS_RUDDER
  36. #define EVENT_TYPE_RV_STATUS REL_X
  37. #define RV_VALUE_MAX (32767)
  38. #define RV_VALUE_MIN (-32768)
  39. #define RV_STATUS_MIN (0)
  40. #define RV_STATUS_MAX (64)
  41. #define RV_DIV_MAX (32767)
  42. #define RV_DIV_MIN (1)
  43. #define MAX_CHOOSE_RV_NUM 5
  44. struct rotationvector_control_path {
  45. int (*open_report_data)(int open); /* open data rerport to HAL */
  46. int (*enable_nodata)(int en); /* only enable not report event to HAL */
  47. int (*set_delay)(u64 delay);
  48. int (*access_data_fifo)(void); /* version2.used for flush operate */
  49. bool is_report_input_direct;
  50. bool is_support_batch; /* version2.used for batch mode support flag */
  51. int (*rotationvector_calibration)(int type, int cali[3]);/* common layer factory mode API1 */
  52. };
  53. struct rotationvector_data_path {
  54. int (*get_data)(int *x, int *y, int *z, int *scalar, int *status);
  55. int (*get_raw_data)(int *x, int *y, int *z, int *scalar);/* common layer factory mode API2 */
  56. int vender_div;
  57. };
  58. struct rotationvector_init_info {
  59. char *name;
  60. int (*init)(void);
  61. int (*uninit)(void);
  62. struct platform_driver *platform_diver_addr;
  63. };
  64. struct rotationvector_data {
  65. hwm_sensor_data rotationvector_data;
  66. int data_updata;
  67. /* struct mutex lock; */
  68. };
  69. struct rotationvector_drv_obj {
  70. void *self;
  71. int polling;
  72. int (*rotationvector_operate)(void *self, uint32_t command, void *buff_in, int size_in,
  73. void *buff_out, int size_out, int *actualout);
  74. };
  75. struct rotationvector_context {
  76. struct input_dev *idev;
  77. struct miscdevice mdev;
  78. struct work_struct report;
  79. struct mutex rotationvector_op_mutex;
  80. atomic_t delay; /*polling period for reporting input event */
  81. atomic_t wake; /*user-space request to wake-up, used with stop */
  82. struct timer_list timer; /* polling timer */
  83. atomic_t trace;
  84. struct early_suspend early_drv;
  85. atomic_t early_suspend;
  86. /* struct rotationvector_drv_obj drv_obj; */
  87. struct rotationvector_data drv_data;
  88. struct rotationvector_control_path rotationvector_ctl;
  89. struct rotationvector_data_path rotationvector_data;
  90. bool is_active_nodata; /* Active, but HAL don't need data sensor. such as orientation need */
  91. bool is_active_data; /* Active and HAL need data . */
  92. bool is_first_data_after_enable;
  93. bool is_polling_run;
  94. bool is_batch_enable; /* version2.this is used for judging whether sensor is in batch mode */
  95. };
  96. /* driver API for internal */
  97. /* extern int rotationvector_enable_nodata(int enable); */
  98. /* extern int rotationvector_attach(struct rotationvector_drv_obj *obj); */
  99. /* driver API for third party vendor */
  100. /* for auto detect */
  101. extern int rotationvector_driver_add(struct rotationvector_init_info *obj);
  102. extern int rotationvector_data_report(int x, int y, int z, int scalar, int status);
  103. extern int rotationvector_register_control_path(struct rotationvector_control_path *ctl);
  104. extern int rotationvector_register_data_path(struct rotationvector_data_path *data);
  105. #endif