pdr_sensor.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef __PDR_H__
  2. #define __PDR_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 PDR_TAG "<PDR> "
  17. #define PDR_FUN(f) pr_debug(PDR_TAG"%s\n", __func__)
  18. #define PDR_ERR(fmt, args...) pr_err(PDR_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
  19. #define PDR_LOG(fmt, args...) pr_debug(PDR_TAG fmt, ##args)
  20. #define PDR_VER(fmt, args...) pr_debug(PDR_TAG"%s: "fmt, __func__, ##args) /* ((void)0) */
  21. #else
  22. #define PDR_TAG "<PDR> "
  23. #define PDR_FUN(f)
  24. #define PDR_ERR(fmt, args...)
  25. #define PDR_LOG(fmt, args...)
  26. #define PDR_VER(fmt, args...)
  27. endif
  28. #define OP_PDR_DELAY 0X01
  29. #define OP_PDR_ENABLE 0X02
  30. #define OP_PDR_GET_DATA 0X04
  31. #define PDR_INVALID_VALUE -1
  32. #define EVENT_TYPE_PDR_X ABS_RY
  33. #define EVENT_TYPE_PDR_Y ABS_RZ
  34. #define EVENT_TYPE_PDR_Z ABS_THROTTLE
  35. #define EVENT_TYPE_PDR_SCALAR ABS_RUDDER
  36. #define EVENT_TYPE_PDR_STATUS REL_X
  37. #define PDR_VALUE_MAX (32767)
  38. #define PDR_VALUE_MIN (-32768)
  39. #define PDR_STATUS_MIN (0)
  40. #define PDR_STATUS_MAX (64)
  41. #define PDR_DIV_MAX (32767)
  42. #define PDR_DIV_MIN (1)
  43. #define MAX_CHOOSE_PDR_NUM 5
  44. struct pdr_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 (*pdr_calibration)(int type, int cali[3]); /* version3 sensor common layer factory mode API1 */
  52. };
  53. struct pdr_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);
  56. int vender_div;
  57. };
  58. struct pdr_init_info {
  59. char *name;
  60. int (*init)(void);
  61. int (*uninit)(void);
  62. struct platform_driver *platform_diver_addr;
  63. };
  64. struct pdr_data {
  65. hwm_sensor_data pdr_data;
  66. int data_updata;
  67. /* struct mutex lock; */
  68. };
  69. struct pdr_drv_obj {
  70. void *self;
  71. int polling;
  72. int (*pdr_operate)(void *self, uint32_t command, void *buff_in, int size_in,
  73. void *buff_out, int size_out, int *actualout);
  74. };
  75. struct pdr_context {
  76. struct input_dev *idev;
  77. struct miscdevice mdev;
  78. struct work_struct report;
  79. struct mutex pdr_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 pdr_drv_obj drv_obj; */
  87. struct pdr_data drv_data;
  88. struct pdr_control_path pdr_ctl;
  89. struct pdr_data_path pdr_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 pdr_enable_nodata(int enable); */
  98. /* extern int pdr_attach(struct pdr_drv_obj *obj); */
  99. /* driver API for third party vendor */
  100. /* for auto detect */
  101. extern int pdr_driver_add(struct pdr_init_info *obj);
  102. extern int pdr_data_report(int x, int y, int z, int scalar, int status);
  103. extern int pdr_register_control_path(struct pdr_control_path *ctl);
  104. extern int pdr_register_data_path(struct pdr_data_path *data);
  105. #endif