batch.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef __BATCH_H__
  2. #define __BATCH_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 <hwmsensor.h>
  12. #include <linux/string.h>
  13. #include <hwmsen_dev.h>
  14. #define BATCH_TAG "<BATCHDEV> "
  15. #define BATCH_FUN(f) pr_debug(BATCH_TAG"%s\n", __func__)
  16. #define BATCH_ERR(fmt, args...) pr_err(BATCH_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
  17. #define BATCH_LOG(fmt, args...) pr_debug(BATCH_TAG fmt, ##args)
  18. #define BATCH_VER(fmt, args...) pr_debug(BATCH_TAG"%s: "fmt, __func__, ##args)
  19. #define OP_BATCH_DELAY 0X01
  20. #define OP_BATCH_ENABLE 0X02
  21. #define OP_BATCH_GET_DATA 0X04
  22. #define BATCH_INVALID_VALUE -1
  23. #define EVENT_TYPE_BATCH_X ABS_X
  24. #define EVENT_TYPE_BATCH_Y ABS_Y
  25. #define EVENT_TYPE_BATCH_Z ABS_Z
  26. #define EVENT_TYPE_BATCH_STATUS ABS_WHEEL
  27. #define EVENT_TYPE_SENSORTYPE REL_RZ
  28. #define EVENT_TYPE_BATCH_VALUE ABS_RX
  29. #define EVENT_TYPE_END_FLAG REL_RY
  30. #define EVENT_TYPE_TIMESTAMP_HI REL_HWHEEL
  31. #define EVENT_TYPE_TIMESTAMP_LO REL_DIAL
  32. #define EVENT_TYPE_BATCH_READY REL_X
  33. #define BATCH_VALUE_MAX (32767)
  34. #define BATCH_VALUE_MIN (-32768)
  35. #define BATCH_STATUS_MIN (0)
  36. #define BATCH_STATUS_MAX (64)
  37. #define BATCH_TYPE_MIN (0)
  38. #define BATCH_TYPE_MAX (64)
  39. #define BATCH_DIV_MAX (32767)
  40. #define BATCH_DIV_MIN (1)
  41. enum {
  42. SENSORS_BATCH_DRY_RUN = 0x00000001,
  43. SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002
  44. };
  45. #define MAX_CHOOSE_BATCH_NUM 5
  46. struct batch_init_info {
  47. char *name;
  48. int (*init)(void);
  49. int (*uninit)(void);
  50. struct platform_driver *platform_diver_addr;
  51. };
  52. struct batch_control_path {
  53. int (*enable_hw_batch)(int handle, int enable, int flag, long long samplingPeriodNs,
  54. long long maxBatchReportLatencyNs);
  55. int (*flush)(int handle);/* open data rerport to HAL */
  56. };
  57. struct batch_timestamp_info {
  58. int64_t start_t;
  59. int64_t end_t;
  60. uint32_t total_count;
  61. uint32_t num;
  62. };
  63. struct batch_data_path {
  64. /* sensor data is got one by one, return value: 1 stands for data read not finish 0 stands for read data done */
  65. int (*get_data)(int handle, struct hwm_sensor_data *data);
  66. int (*get_fifo_status)(int *len, int *status, char *reserved,
  67. struct batch_timestamp_info *p_batch_timestampe_info);
  68. int samplingPeriodMs;
  69. int maxBatchReportLatencyMs;/* report latency for every sensor */
  70. int flags;/* reserved */
  71. int is_batch_supported;/* batch mode supporting status */
  72. int div;
  73. int is_timestamp_supported;
  74. };
  75. struct batch_dev_list {
  76. /* ctl_dev[max] is used for sensor HUB driver to control sensor HUB , ctl_dev[1]...
  77. *are for single sensor batch mode control */
  78. struct batch_control_path ctl_dev[ID_SENSOR_MAX_HANDLE+1];
  79. /* data_dev[max] is used for sensor HUB driver to access single fifo sensor data,
  80. *data_dev[1]... are for single sensor fifo sensor data */
  81. struct batch_data_path data_dev[ID_SENSOR_MAX_HANDLE+1];
  82. };
  83. struct batch_context {
  84. struct input_dev *idev;
  85. struct miscdevice mdev;
  86. struct work_struct report;
  87. struct mutex batch_op_mutex;
  88. atomic_t delay; /*polling period for reporting input event*/
  89. atomic_t wake; /*user-space request to wake-up, used with stop*/
  90. struct timer_list timer; /* polling timer */
  91. atomic_t trace;
  92. struct wakeup_source read_data_wake_lock;
  93. struct batch_dev_list dev_list;
  94. uint32_t active_sensor;
  95. int batch_result;
  96. int flush_result;
  97. bool is_first_data_after_enable;
  98. bool is_polling_run;
  99. int div_flag;
  100. int numOfDataLeft;
  101. int force_wake_upon_fifo_full;
  102. struct batch_timestamp_info timestamp_info[ID_SENSOR_MAX_HANDLE+1];
  103. };
  104. enum BATCH_NOTIFY_TYPE {
  105. TYPE_NON = 0,
  106. TYPE_MOTION = 1,
  107. TYPE_GESTURE = 2,
  108. TYPE_BATCHTIMEOUT = 3,
  109. TYPE_BATCHFULL = 4,
  110. TYPE_ERROR = 5,
  111. TYPE_DATAREADY = 6
  112. };
  113. /* driver API for third party vendor */
  114. extern int batch_notify(enum BATCH_NOTIFY_TYPE type);
  115. extern int batch_driver_add(struct batch_init_info *obj);
  116. extern void report_batch_data(struct input_dev *dev, struct hwm_sensor_data *data);
  117. extern void report_batch_finish(struct input_dev *dev, int handle);
  118. extern int batch_register_control_path(int handle, struct batch_control_path *ctl);
  119. extern int batch_register_data_path(int handle, struct batch_data_path *data);
  120. extern int batch_register_support_info(int handle, int support, int div, int timestamp_supported);
  121. #endif