pedometer.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef __PEDOMETER_H__
  2. #define __PEDOMETER_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 PDR_TAG "<PEDOMETER> "
  15. #define PDR_FUN(f) pr_debug(PDR_TAG"%s\n", __func__)
  16. #define PDR_ERR(fmt, args...) pr_err(PDR_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
  17. #define PDR_LOG(fmt, args...) pr_debug(PDR_TAG fmt, ##args)
  18. #define PDR_VER(fmt, args...) pr_debug(PDR_TAG"%s: "fmt, __func__, ##args) /* ((void)0) */
  19. #define OP_PDR_DELAY 0X01
  20. #define OP_PDR_ENABLE 0X02
  21. #define OP_PDR_GET_DATA 0X04
  22. #define PDR_INVALID_VALUE -1
  23. #define EVENT_TYPE_PDR_LENGTH ABS_X
  24. #define EVENT_TYPE_PDR_FREQUENCY ABS_Y
  25. #define EVENT_TYPE_PDR_COUNT ABS_Z
  26. #define EVENT_TYPE_PDR_DISTANCE ABS_RX
  27. #define EVENT_TYPE_PDR_STATUS ABS_WHEEL
  28. #define PDR_VALUE_MAX (32767)
  29. #define PDR_VALUE_MIN (-32768)
  30. #define PDR_STATUS_MIN (0)
  31. #define PDR_STATUS_MAX (64)
  32. #define PDR_DIV_MAX (32767)
  33. #define PDR_DIV_MIN (1)
  34. #define MAX_CHOOSE_PDR_NUM 5
  35. struct pdr_control_path {
  36. int (*open_report_data)(int open); /* open data rerport to HAL */
  37. int (*enable_nodata)(int en); /* only enable not report event to HAL */
  38. int (*set_delay)(u64 delay);
  39. bool is_report_input_direct;
  40. bool is_support_batch;
  41. };
  42. typedef struct {
  43. uint32_t length; /* milli-meter */
  44. uint32_t frequency; /* freq*1000 */
  45. uint32_t count;
  46. uint32_t distance;
  47. } pedometer_t;
  48. struct pdr_data_path {
  49. int (*get_data)(u32 *value, int *status);
  50. int vender_div;
  51. };
  52. struct pdr_init_info {
  53. char *name;
  54. int (*init)(void);
  55. int (*uninit)(void);
  56. struct platform_driver *platform_diver_addr;
  57. };
  58. struct pdr_data {
  59. hwm_sensor_data pdr_data;
  60. int data_updata;
  61. /* struct mutex lock; */
  62. };
  63. struct pdr_drv_obj {
  64. void *self;
  65. int polling;
  66. int (*pdr_operate)(void *self, uint32_t command, void *buff_in, int size_in,
  67. void *buff_out, int size_out, int *actualout);
  68. };
  69. struct pdr_context {
  70. struct input_dev *idev;
  71. struct miscdevice mdev;
  72. struct work_struct report;
  73. struct mutex pdr_op_mutex;
  74. atomic_t delay; /*polling period for reporting input event */
  75. atomic_t wake; /*user-space request to wake-up, used with stop */
  76. struct timer_list timer; /* polling timer */
  77. atomic_t trace;
  78. struct early_suspend early_drv;
  79. atomic_t early_suspend;
  80. struct pdr_data drv_data;
  81. struct pdr_control_path pdr_ctl;
  82. struct pdr_data_path pdr_data;
  83. bool is_active_nodata; /* Active, but HAL don't need data sensor. such as orientation need */
  84. bool is_active_data; /* Active and HAL need data . */
  85. bool is_first_data_after_enable;
  86. bool is_polling_run;
  87. bool is_batch_enable;
  88. };
  89. /* driver API for internal */
  90. /* extern int pdr_enable_nodata(int enable); */
  91. /* extern int pdr_attach(struct pdr_drv_obj *obj); */
  92. /* driver API for third party vendor */
  93. /* for auto detect */
  94. extern int pdr_driver_add(struct pdr_init_info *obj);
  95. extern int pdr_data_report(hwm_sensor_data data, int status);
  96. extern int pdr_register_control_path(struct pdr_control_path *ctl);
  97. extern int pdr_register_data_path(struct pdr_data_path *data);
  98. #endif