6 #include <linux/wakelock.h>
7 #include <linux/interrupt.h>
8 #include <linux/miscdevice.h>
9 #include <linux/platform_device.h>
10 #include <linux/input.h>
11 #include <linux/workqueue.h>
12 #include <linux/slab.h>
13 #include <linux/module.h>
14 #include <linux/hwmsensor.h>
15 #include <linux/earlysuspend.h>
16 #include <linux/string.h>
17 #include <linux/hwmsen_dev.h>
19 #define BATCH_TAG "<BATCHDEV> "
20 #define BATCH_FUN(f) printk(BATCH_TAG"%s\n", __func__)
21 #define BATCH_ERR(fmt, args...) printk(BATCH_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
22 #define BATCH_LOG(fmt, args...) printk(BATCH_TAG fmt, ##args)
23 #define BATCH_VER(fmt, args...) printk(BATCH_TAG"%s: "fmt, __func__, ##args) //((void)0)
25 #define OP_BATCH_DELAY 0X01
26 #define OP_BATCH_ENABLE 0X02
27 #define OP_BATCH_GET_DATA 0X04
29 #define BATCH_INVALID_VALUE -1
31 #define EVENT_TYPE_BATCH_X ABS_X
32 #define EVENT_TYPE_BATCH_Y ABS_Y
33 #define EVENT_TYPE_BATCH_Z ABS_Z
34 #define EVENT_TYPE_BATCH_STATUS ABS_WHEEL
35 #define EVENT_TYPE_SENSORTYPE REL_RZ
36 #define EVENT_TYPE_BATCH_VALUE ABS_RX
37 #define EVENT_TYPE_END_FLAG REL_RY
38 #define EVENT_TYPE_TIMESTAMP_HI REL_HWHEEL
39 #define EVENT_TYPE_TIMESTAMP_LO REL_DIAL
42 #define BATCH_VALUE_MAX (32767)
43 #define BATCH_VALUE_MIN (-32768)
44 #define BATCH_STATUS_MIN (0)
45 #define BATCH_STATUS_MAX (64)
46 #define BATCH_TYPE_MIN (0)
47 #define BATCH_TYPE_MAX (64)
48 #define BATCH_DIV_MAX (32767)
49 #define BATCH_DIV_MIN (1)
52 SENSORS_BATCH_DRY_RUN
= 0x00000001,
53 SENSORS_BATCH_WAKE_UPON_FIFO_FULL
= 0x00000002
55 #define MAX_CHOOSE_BATCH_NUM 5
56 struct batch_init_info
61 struct platform_driver
* platform_diver_addr
;
64 struct batch_control_path
66 int (*enable_hw_batch
)(int handle
, int enable
, long long samplingPeriodNs
,long long maxBatchReportLatencyNs
);//let the hardware know that data should be written to fifo
67 int (*flush
)(int handle
);//open data rerport to HAL
70 struct batch_timestamp_info
78 struct batch_data_path
80 int (*get_data
)(int handle
, hwm_sensor_data
*data
);//sensor data is got one by one, return value: 1 stands for data read not finish 0 stands for read data done
81 int (*get_fifo_status
)(int *len
, int *status
, char *reserved
, struct batch_timestamp_info
*p_batch_timestampe_info
);
82 int delay
;//report latency for every sensor
84 int is_batch_supported
;//batch mode supporting status
86 int is_timestamp_supported
;
91 struct batch_control_path ctl_dev
[MAX_ANDROID_SENSOR_NUM
+1];//ctl_dev[max] is used for sensor HUB driver to control sensor HUB , ctl_dev[1]... are for single sensor batch mode control
92 struct batch_data_path data_dev
[MAX_ANDROID_SENSOR_NUM
+1];//data_dev[max] is used for sensor HUB driver to access single fifo sensor data, data_dev[1]... are for single sensor fifo sensor data
96 struct batch_context
{
97 struct input_dev
*idev
;
98 struct miscdevice mdev
;
99 struct work_struct report
;
100 struct mutex batch_op_mutex
;
102 atomic_t delay
; /*polling period for reporting input event*/
103 atomic_t wake
; /*user-space request to wake-up, used with stop*/
104 struct timer_list timer
; /* polling timer */
107 struct early_suspend early_drv
;
108 struct wake_lock read_data_wake_lock
;
109 atomic_t early_suspend
;
111 struct batch_dev_list dev_list
;
113 uint32_t active_sensor
;
116 bool is_first_data_after_enable
;
120 struct batch_timestamp_info timestamp_info
[MAX_ANDROID_SENSOR_NUM
+1];
127 TYPE_BATCHTIMEOUT
= 3,
133 //driver API for third party vendor
134 extern int batch_notify(BATCH_NOTIFY_TYPE type
);
135 extern int batch_driver_add(struct batch_init_info
* obj
);
136 extern void report_batch_data(struct input_dev
*dev
, hwm_sensor_data
*data
);
137 extern void report_batch_finish(struct input_dev
*dev
, int handle
);
138 extern int batch_register_control_path(int handle
, struct batch_control_path
*ctl
);//when you register control path of sensor hub driver, use handle = [MAX_ANDROID_SENSOR_NUM+1]
139 extern int batch_register_data_path(int handle
, struct batch_data_path
*data
);//when you register control path of sensor hub driver, use handle = [MAX_ANDROID_SENSOR_NUM+1]
140 extern int batch_register_support_info(int handle
, int support
, int div
, int timestamp_supported
);