mag.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #ifndef __MAG_H__
  2. #define __MAG_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/i2c.h>
  12. #include <linux/irq.h>
  13. #include <linux/uaccess.h>
  14. #include <linux/delay.h>
  15. #include <linux/kobject.h>
  16. #include <linux/atomic.h>
  17. #include <linux/proc_fs.h>
  18. #include <sensors_io.h>
  19. #include <hwmsen_helper.h>
  20. #include <batch.h>
  21. #include <hwmsensor.h>
  22. #include <hwmsen_dev.h>
  23. #include "mag_factory.h"
  24. #define MAG_TAG "<MAGNETIC> "
  25. #define MAG_FUN(f) pr_debug(MAG_TAG"%s\n", __func__)
  26. #define MAG_ERR(fmt, args...) pr_err(MAG_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
  27. #define MAG_LOG(fmt, args...) pr_debug(MAG_TAG fmt, ##args)
  28. #define MAG_VER(fmt, args...) pr_debug(MAG_TAG"%s: "fmt, __func__, ##args) /*((void)0)*/
  29. #define OP_MAG_DELAY 0X01
  30. #define OP_MAG_ENABLE 0X02
  31. #define OP_MAG_GET_DATA 0X04
  32. #define MAG_INVALID_VALUE -1
  33. #define EVENT_TYPE_MAGEL_X ABS_X
  34. #define EVENT_TYPE_MAGEL_Y ABS_Y
  35. #define EVENT_TYPE_MAGEL_Z ABS_Z
  36. #define EVENT_TYPE_MAGEL_UPDATE REL_X
  37. #define EVENT_DIV_MAGEL ABS_RUDDER
  38. #define EVENT_TYPE_MAGEL_STATUS ABS_WHEEL
  39. #define EVENT_TYPE_MAG_UPDATE REL_X
  40. #define EVENT_TYPE_MAG_TIMESTAMP_HI REL_HWHEEL
  41. #define EVENT_TYPE_MAG_TIMESTAMP_LO REL_DIAL
  42. #define EVENT_TYPE_O_X ABS_RX
  43. #define EVENT_TYPE_O_Y ABS_RY
  44. #define EVENT_TYPE_O_Z ABS_RZ
  45. #define EVENT_TYPE_O_UPDATE REL_RX
  46. #define EVENT_DIV_O ABS_GAS
  47. #define EVENT_TYPE_O_STATUS ABS_THROTTLE
  48. #define EVENT_TYPE_ORIENT_UPDATE REL_RX
  49. #define EVENT_TYPE_ORIENT_TIMESTAMP_HI REL_WHEEL
  50. #define EVENT_TYPE_ORIENT_TIMESTAMP_LO REL_MISC
  51. #define MAG_DIV_MAX (32767)
  52. #define MAG_DIV_MIN (1)
  53. #define MAG_VALUE_MAX (32767)
  54. #define MAG_VALUE_MIN (-32768)
  55. #define MAG_STATUS_MIN (0)
  56. #define MAG_STATUS_MAX (64)
  57. #define MAX_CHOOSE_G_NUM 5
  58. #define MAX_M_V_SENSOR 5
  59. #define ID_M_V_MAGNETIC 0
  60. #define ID_M_V_ORIENTATION 1
  61. enum MAG_TYPE {
  62. MAGNETIC = 0,
  63. ORIENTATION = 1,
  64. };
  65. struct mag_data_path {
  66. int div_m;
  67. int div_o;
  68. int (*get_data_m)(int *x, int *y, int *z, int *status);
  69. int (*get_data_o)(int *x, int *y, int *z, int *status);
  70. int (*get_raw_data)(int *x, int *y, int *z);
  71. };
  72. struct mag_control_path {
  73. int (*m_open_report_data)(int en);
  74. int (*m_set_delay)(u64 delay);
  75. int (*m_enable)(int en);
  76. int (*o_open_report_data)(int en);
  77. int (*o_set_delay)(u64 delay);
  78. int (*o_enable)(int en);
  79. bool is_report_input_direct;
  80. bool is_support_batch;
  81. bool is_use_common_factory;
  82. };
  83. struct mag_init_info {
  84. char *name;
  85. int (*init)(void);
  86. int (*uninit)(void);
  87. struct platform_driver *platform_diver_addr;
  88. };
  89. struct mag_data {
  90. struct hwm_sensor_data mag_data;
  91. int data_updata;
  92. /* struct mutex lock; */
  93. };
  94. struct mag_drv_obj {
  95. void *self;
  96. int polling;
  97. int (*mag_operate)(void *self, uint32_t command, void *buff_in, int size_in,
  98. void *buff_out, int size_out, int *actualout);
  99. };
  100. struct mag_context {
  101. struct input_dev *idev;
  102. struct miscdevice mdev;
  103. struct work_struct report;
  104. struct mutex mag_op_mutex;
  105. atomic_t delay; /*polling period for reporting input event*/
  106. atomic_t wake; /*user-space request to wake-up, used with stop*/
  107. struct timer_list timer; /* polling timer */
  108. struct hrtimer hrTimer;
  109. ktime_t target_ktime;
  110. atomic_t trace;
  111. struct workqueue_struct *mag_workqueue;
  112. struct mag_data_path mag_dev_data;
  113. struct mag_control_path mag_ctl;
  114. atomic_t early_suspend;
  115. struct mag_drv_obj *drv_obj[MAX_M_V_SENSOR];
  116. struct mag_data drv_data[MAX_M_V_SENSOR];
  117. bool is_first_data_after_enable;
  118. bool is_polling_run;
  119. bool is_batch_enable;
  120. uint32_t active_nodata_sensor;
  121. uint32_t active_data_sensor;
  122. };
  123. extern int mag_attach(int sensor, struct mag_drv_obj *obj);
  124. extern int mag_driver_add(struct mag_init_info *obj);
  125. extern int mag_data_report(enum MAG_TYPE type, int x, int y, int z, int status, int64_t nt);
  126. extern int mag_register_control_path(struct mag_control_path *ctl);
  127. extern int mag_register_data_path(struct mag_data_path *ctl);
  128. #endif