import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm / mach-mt8127 / kr076_nand / magnetometer / mag.h
1
2 #ifndef __MAG_H__
3 #define __MAG_H__
4
5
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/hwmsen_dev.h>
17
18
19 #define MAG_TAG "<MAGNETIC> "
20 #define MAG_FUN(f) printk(MAG_TAG"%s\n", __func__)
21 #define MAG_ERR(fmt, args...) printk(MAG_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
22 #define MAG_LOG(fmt, args...) printk(MAG_TAG fmt, ##args)
23 #define MAG_VER(fmt, args...) printk(MAG_TAG"%s: "fmt, __func__, ##args) //((void)0)
24
25 #define OP_MAG_DELAY 0X01
26 #define OP_MAG_ENABLE 0X02
27 #define OP_MAG_GET_DATA 0X04
28
29
30 #define MAG_INVALID_VALUE -1
31
32 #define EVENT_TYPE_MAGEL_X ABS_X
33 #define EVENT_TYPE_MAGEL_Y ABS_Y
34 #define EVENT_TYPE_MAGEL_Z ABS_Z
35 #define EVENT_DIV_MAGEL ABS_RUDDER
36 #define EVENT_TYPE_MAGEL_STATUS ABS_WHEEL
37
38 #define EVENT_TYPE_O_X ABS_RX
39 #define EVENT_TYPE_O_Y ABS_RY
40 #define EVENT_TYPE_O_Z ABS_RZ
41 #define EVENT_DIV_O ABS_GAS
42 #define EVENT_TYPE_O_STATUS ABS_THROTTLE
43
44 #define MAG_DIV_MAX (32767)
45 #define MAG_DIV_MIN (1)
46
47 #define MAG_VALUE_MAX (32767)
48 #define MAG_VALUE_MIN (-32768)
49 #define MAG_STATUS_MIN (0)
50 #define MAG_STATUS_MAX (64)
51
52 #define MAX_CHOOSE_G_NUM 5
53
54 #define MAX_M_V_SENSOR 5
55
56 #define ID_M_V_MAGNETIC 0
57 #define ID_M_V_ORIENTATION 1
58
59 typedef enum mag_type {
60 MAGNETIC=0,
61 ORIENTATION=1,
62 }MAG_TYPE;
63
64 struct mag_data_path
65 {
66 int div_m;
67 int div_o;
68
69 };
70
71 struct mag_control_path
72 {
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 };
82
83
84 struct mag_init_info
85 {
86 char *name;
87 int (*init)(void);
88 int (*uninit)(void);
89 struct platform_driver* platform_diver_addr;
90 };
91
92 struct mag_data{
93 hwm_sensor_data mag_data ;
94 int data_updata;
95 //struct mutex lock;
96 };
97
98 struct mag_drv_obj {
99 void *self;
100 int polling;
101 int (*mag_operate)(void* self, uint32_t command, void* buff_in, int size_in,
102 void* buff_out, int size_out, int* actualout);
103 };
104
105 struct mag_context {
106 struct input_dev *idev;
107 struct miscdevice mdev;
108 struct work_struct report;
109 struct mutex mag_op_mutex;
110 atomic_t delay; /*polling period for reporting input event*/
111 atomic_t wake; /*user-space request to wake-up, used with stop*/
112 struct timer_list timer; /* polling timer */
113 atomic_t trace;
114
115 struct early_suspend early_drv;
116 struct mag_data_path mag_dev_data;
117 struct mag_control_path mag_ctl;
118 atomic_t early_suspend;
119 struct mag_drv_obj* drv_obj[MAX_M_V_SENSOR];
120 struct mag_data drv_data[MAX_M_V_SENSOR];
121 bool is_first_data_after_enable;
122 bool is_polling_run;
123 bool is_batch_enable;
124 uint32_t active_nodata_sensor;
125 uint32_t active_data_sensor;
126 //bool mag_type_enabled[MAX_M_V_SENSOR];
127 //uint32_t mag_active_sensor;
128
129 };
130
131 extern int mag_attach(int sensor,struct mag_drv_obj *obj);
132
133 extern int mag_driver_add(struct mag_init_info* obj) ;
134 extern int mag_data_report(MAG_TYPE type,int x, int y, int z,int status);
135 extern int mag_register_control_path(struct mag_control_path *ctl);
136 extern int mag_register_data_path(struct mag_data_path *ctl);
137
138
139
140
141 #endif