heart_rate.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef __HEART_RATE_H__
  2. #define __HEART_RATE_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 HRM_TAG "<HEART_RATE> "
  15. #define HRM_FUN(f) printk(HRM_TAG"%s\n", __func__)
  16. #define HRM_ERR(fmt, args...) printk(HRM_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
  17. #define HRM_LOG(fmt, args...) printk(HRM_TAG fmt, ##args)
  18. #define HRM_VER(fmt, args...) printk(HRM_TAG"%s: "fmt, __func__, ##args) /* ((void)0) */
  19. #define OP_HRM_DELAY 0X01
  20. #define OP_HRM_ENABLE 0X02
  21. #define OP_HRM_GET_DATA 0X04
  22. #define HRM_INVALID_VALUE -1
  23. #define EVENT_TYPE_HRM_BPM ABS_X
  24. #define EVENT_TYPE_HRM_STATUS ABS_Y
  25. #define HRM_VALUE_MAX (32767)
  26. #define HRM_VALUE_MIN (-32768)
  27. #define HRM_STATUS_MIN (0)
  28. #define HRM_STATUS_MAX (64)
  29. #define HRM_DIV_MAX (32767)
  30. #define HRM_DIV_MIN (1)
  31. #define MAX_CHOOSE_HRM_NUM 5
  32. struct hrm_control_path {
  33. int (*open_report_data)(int open); /* open data rerport to HAL */
  34. int (*enable_nodata)(int en); /* only enable not report event to HAL */
  35. int (*set_delay)(u64 delay);
  36. bool is_report_input_direct;
  37. bool is_support_batch;
  38. };
  39. typedef struct {
  40. uint32_t bpm; /* BPM * 1000 */
  41. uint32_t status; /* freq*1000 */
  42. } heart_rate_t;
  43. struct hrm_data_path {
  44. int (*get_data)(u32 *value, int *status);
  45. int vender_div;
  46. };
  47. struct hrm_init_info {
  48. char *name;
  49. int (*init)(void);
  50. int (*uninit)(void);
  51. struct platform_driver *platform_diver_addr;
  52. };
  53. struct hrm_data {
  54. hwm_sensor_data hrm_data;
  55. int data_updata;
  56. /* struct mutex lock; */
  57. };
  58. struct hrm_drv_obj {
  59. void *self;
  60. int polling;
  61. int (*hrm_operate)(void *self, uint32_t command, void *buff_in, int size_in,
  62. void *buff_out, int size_out, int *actualout);
  63. };
  64. struct hrm_context {
  65. struct input_dev *idev;
  66. struct miscdevice mdev;
  67. struct work_struct report;
  68. struct mutex hrm_op_mutex;
  69. atomic_t delay; /*polling period for reporting input event */
  70. atomic_t wake; /*user-space request to wake-up, used with stop */
  71. struct timer_list timer; /* polling timer */
  72. atomic_t trace;
  73. struct early_suspend early_drv;
  74. atomic_t early_suspend;
  75. struct hrm_data drv_data;
  76. struct hrm_control_path hrm_ctl;
  77. struct hrm_data_path hrm_data;
  78. bool is_active_nodata; /* Active, but HAL don't need data sensor. such as orientation need */
  79. bool is_active_data; /* Active and HAL need data . */
  80. bool is_first_data_after_enable;
  81. bool is_polling_run;
  82. bool is_batch_enable;
  83. };
  84. /* driver API for internal */
  85. /* extern int hrm_enable_nodata(int enable); */
  86. /* extern int hrm_attach(struct hrm_drv_obj *obj); */
  87. /* driver API for third party vendor */
  88. /* for auto detect */
  89. extern int hrm_driver_add(struct hrm_init_info *obj);
  90. extern int hrm_data_report(hwm_sensor_data data, int status);
  91. extern int hrm_register_control_path(struct hrm_control_path *ctl);
  92. extern int hrm_register_data_path(struct hrm_data_path *data);
  93. #endif