alsps.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #ifndef __ALSPS_H__
  2. #define __ALSPS_H__
  3. #include <linux/i2c.h>
  4. #include <linux/irq.h>
  5. #include <linux/uaccess.h>
  6. #include <linux/kobject.h>
  7. #include <linux/types.h>
  8. #include <linux/atomic.h>
  9. #include <linux/io.h>
  10. #include <linux/sched.h>
  11. #include <linux/wakelock.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/miscdevice.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/input.h>
  16. #include <linux/workqueue.h>
  17. #include <linux/slab.h>
  18. #include <linux/delay.h>
  19. #include <linux/module.h>
  20. #include <batch.h>
  21. #include <sensors_io.h>
  22. #include <hwmsensor.h>
  23. #include <hwmsen_dev.h>
  24. #include "alsps_factory.h"
  25. #define ALSPS_TAG "<ALS/PS> "
  26. #define ALSPS_FUN(f) printk(ALSPS_TAG"%s\n", __func__)
  27. #define ALSPS_ERR(fmt, args...) printk(ALSPS_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
  28. #define ALSPS_LOG(fmt, args...) printk(ALSPS_TAG fmt, ##args)
  29. #define ALSPS_VER(fmt, args...) printk(ALSPS_TAG"%s: "fmt, __func__, ##args) /* ((void)0) */
  30. #define OP_ALSPS_DELAY 0X01
  31. #define OP_ALSPS_ENABLE 0X02
  32. #define OP_ALSPS_GET_DATA 0X04
  33. #define ALSPS_INVALID_VALUE -1
  34. #define EVENT_TYPE_ALS_VALUE ABS_X
  35. #define EVENT_TYPE_PS_VALUE REL_Z
  36. #define EVENT_TYPE_ALS_STATUS ABS_WHEEL
  37. #define EVENT_TYPE_PS_STATUS REL_Y
  38. #define ALSPS_VALUE_MAX (32767)
  39. #define ALSPS_VALUE_MIN (-32768)
  40. #define ALSPS_STATUS_MIN (0)
  41. #define ALSPS_STATUS_MAX (64)
  42. #define ALSPS_DIV_MAX (32767)
  43. #define ALSPS_DIV_MIN (1)
  44. #define MAX_CHOOSE_ALSPS_NUM 5
  45. struct als_control_path {
  46. int (*open_report_data)(int open);/* open data rerport to HAL */
  47. int (*enable_nodata)(int en);/* only enable not report event to HAL */
  48. int (*set_delay)(u64 delay);
  49. int (*access_data_fifo)(void);/* version2.used for flush operate */
  50. bool is_report_input_direct;
  51. bool is_support_batch;/* version2.used for batch mode support flag */
  52. bool is_polling_mode;
  53. bool is_use_common_factory;
  54. };
  55. struct ps_control_path {
  56. int (*open_report_data)(int open);/* open data rerport to HAL */
  57. int (*enable_nodata)(int en);/* only enable not report event to HAL */
  58. int (*set_delay)(u64 delay);
  59. int (*access_data_fifo)(void);/* version2.used for flush operate */
  60. int (*ps_calibration)(int type, int value);
  61. int (*ps_threshold_setting)(int type, int value[2]);
  62. bool is_report_input_direct;
  63. bool is_support_batch;/* version2.used for batch mode support flag */
  64. bool is_polling_mode;
  65. bool is_use_common_factory;
  66. };
  67. struct als_data_path {
  68. int (*get_data)(int *als_value, int *status);
  69. int (*als_get_raw_data)(int *als_value);
  70. int vender_div;
  71. };
  72. struct ps_data_path {
  73. int (*get_data)(int *ps_value, int *status);
  74. int (*ps_get_raw_data)(int *ps_value);
  75. int vender_div;
  76. };
  77. struct alsps_init_info {
  78. char *name;
  79. int (*init)(void);
  80. int (*uninit)(void);
  81. struct platform_driver *platform_diver_addr;
  82. };
  83. struct alsps_data {
  84. struct hwm_sensor_data als_data;
  85. struct hwm_sensor_data ps_data;
  86. int data_updata;
  87. };
  88. struct alsps_drv_obj {
  89. void *self;
  90. int polling;
  91. int (*alsps_operate)(void *self, uint32_t command, void *buff_in, int size_in,
  92. void *buff_out, int size_out, int *actualout);
  93. };
  94. struct alsps_context {
  95. struct input_dev *idev;
  96. struct miscdevice mdev;
  97. struct work_struct report_ps;
  98. struct work_struct report_als;
  99. struct mutex alsps_op_mutex;
  100. struct timer_list timer_als; /*als polling timer */
  101. struct timer_list timer_ps; /* ps polling timer */
  102. atomic_t trace;
  103. atomic_t delay_als; /*als polling period for reporting input event*/
  104. atomic_t delay_ps;/*ps polling period for reporting input event*/
  105. atomic_t wake; /*user-space request to wake-up, used with stop*/
  106. atomic_t early_suspend;
  107. struct alsps_data drv_data;
  108. struct als_control_path als_ctl;
  109. struct als_data_path als_data;
  110. struct ps_control_path ps_ctl;
  111. struct ps_data_path ps_data;
  112. bool is_als_active_nodata;/* Active, but HAL don't need data sensor. such as orientation need */
  113. bool is_als_active_data;/* Active and HAL need data . */
  114. bool is_ps_active_nodata;/* Active, but HAL don't need data sensor. such as orientation need */
  115. bool is_ps_active_data;/* Active and HAL need data . */
  116. bool is_als_first_data_after_enable;
  117. bool is_ps_first_data_after_enable;
  118. bool is_als_polling_run;
  119. bool is_ps_polling_run;
  120. bool is_als_batch_enable;/* version2.this is used for judging whether sensor is in batch mode */
  121. bool is_ps_batch_enable; /* version2.this is used for judging whether sensor is in batch mode */
  122. bool is_get_valid_ps_data_after_enable;
  123. bool is_get_valid_als_data_after_enable;
  124. };
  125. /* AAL Functions */
  126. extern int alsps_aal_enable(int enable);
  127. extern int alsps_aal_get_status(void);
  128. extern int alsps_aal_get_data(void);
  129. /* for auto detect */
  130. extern int alsps_driver_add(struct alsps_init_info *obj);
  131. extern int ps_report_interrupt_data(int value);
  132. extern int als_data_report(struct input_dev *dev, int value, int status);
  133. extern int als_register_control_path(struct als_control_path *ctl);
  134. extern int als_register_data_path(struct als_data_path *data);
  135. extern int ps_data_report(struct input_dev *dev, int value, int status);
  136. extern int ps_register_control_path(struct ps_control_path *ctl);
  137. extern int ps_register_data_path(struct ps_data_path *data);
  138. extern struct platform_device *get_alsps_platformdev(void);
  139. #endif