Merge remote-tracking branch 'aosp/android-3.0' into develop-3.0-jb
[firefly-linux-kernel-4.4.55.git] / include / linux / sensor-dev.h
1 /* include/linux/sensor-dev.h - sensor header file\r
2  *\r
3  * Copyright (C) 2012-2015 ROCKCHIP.\r
4  * Author: luowei <lw@rock-chips.com>\r
5  *\r
6  * This software is licensed under the terms of the GNU General Public\r
7  * License version 2, as published by the Free Software Foundation, and\r
8  * may be copied, distributed, and modified under those terms.\r
9  *\r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  *\r
15  */\r
16 \r
17 #include <linux/miscdevice.h>\r
18 #ifdef CONFIG_HAS_EARLYSUSPEND\r
19 #include <linux/earlysuspend.h>\r
20 #endif\r
21 \r
22 \r
23 #define SENSOR_ON               1\r
24 #define SENSOR_OFF              0\r
25 #define SENSOR_UNKNOW_DATA      -1\r
26 \r
27 enum sensor_type {\r
28         SENSOR_TYPE_NULL,\r
29         SENSOR_TYPE_ACCEL,\r
30         SENSOR_TYPE_COMPASS,    \r
31         SENSOR_TYPE_GYROSCOPE,  \r
32         SENSOR_TYPE_LIGHT,      \r
33         SENSOR_TYPE_PROXIMITY,\r
34         SENSOR_TYPE_TEMPERATURE,        \r
35         //SENSOR_TYPE_PRESSURE,\r
36         SENSOR_NUM_TYPES\r
37 };\r
38 \r
39 enum sensor_id {\r
40         ID_INVALID = 0,\r
41                 \r
42         ACCEL_ID_ALL,\r
43         ACCEL_ID_LIS331,\r
44         ACCEL_ID_LSM303DLX,\r
45         ACCEL_ID_LIS3DH,\r
46         ACCEL_ID_KXSD9,\r
47         ACCEL_ID_KXTF9,\r
48         ACCEL_ID_KXTIK,\r
49         ACCEL_ID_BMA150,\r
50         ACCEL_ID_BMA222,\r
51         ACCEL_ID_BMA250,\r
52         ACCEL_ID_ADXL34X,\r
53         ACCEL_ID_MMA8450,\r
54         ACCEL_ID_MMA845X,\r
55         ACCEL_ID_MMA7660,\r
56         ACCEL_ID_MPU6050,\r
57 \r
58         COMPASS_ID_ALL,\r
59         COMPASS_ID_AK8975,\r
60         COMPASS_ID_AK8972,\r
61         COMPASS_ID_AMI30X,\r
62         COMPASS_ID_AMI306,\r
63         COMPASS_ID_YAS529,\r
64         COMPASS_ID_YAS530,\r
65         COMPASS_ID_HMC5883,\r
66         COMPASS_ID_LSM303DLH,\r
67         COMPASS_ID_LSM303DLM,\r
68         COMPASS_ID_MMC314X,\r
69         COMPASS_ID_HSCDTD002B,\r
70         COMPASS_ID_HSCDTD004A,\r
71 \r
72         GYRO_ID_ALL,\r
73         GYRO_ID_L3G4200D,\r
74         GYRO_ID_K3G,\r
75 \r
76         LIGHT_ID_ALL,\r
77         LIGHT_ID_CM3217,\r
78         LIGHT_ID_AL3006,\r
79         LIGHT_ID_STK3171,\r
80         \r
81         PROXIMITY_ID_ALL,\r
82         PROXIMITY_ID_AL3006,\r
83         PROXIMITY_ID_STK3171,\r
84         TEMPERATURE_ID_ALL,\r
85 \r
86         PRESSURE_ID_ALL,\r
87         PRESSURE_ID_BMA085,\r
88         SENSOR_NUM_ID,\r
89 };\r
90 \r
91 \r
92 struct sensor_axis {\r
93         int x;\r
94         int y;\r
95         int z;\r
96 };\r
97 \r
98 struct sensor_operate {\r
99         char *name;\r
100         int type;\r
101         int     id_i2c;\r
102         int     range[2];\r
103         int     brightness[2];//backlight min_brightness max_brightness \r
104         int read_reg;\r
105         int read_len;\r
106         int id_reg;\r
107         int id_data;\r
108         int precision;\r
109         int ctrl_reg;\r
110         int ctrl_data;\r
111         int int_ctrl_reg;\r
112         int     int_status_reg;\r
113         int trig;       //intterupt trigger\r
114         int (*active)(struct i2c_client *client, int enable, int rate); \r
115         int (*init)(struct i2c_client *client); \r
116         int (*report)(struct i2c_client *client);\r
117         int (*suspend)(struct i2c_client *client);\r
118         int (*resume)(struct i2c_client *client);\r
119         struct miscdevice *misc_dev;\r
120 \r
121 };\r
122 \r
123 \r
124 /* Platform data for the sensor */\r
125 struct sensor_private_data {\r
126         int type;\r
127         struct i2c_client *client;      \r
128         struct input_dev *input_dev;\r
129         struct work_struct work;\r
130         struct delayed_work delaywork;  /*report second event*/\r
131         struct sensor_axis axis;\r
132         char sensor_data[40];           //max support40 bytes data\r
133         atomic_t data_ready;\r
134         wait_queue_head_t data_ready_wq;                \r
135         struct mutex data_mutex;\r
136         struct mutex operation_mutex;   \r
137         struct mutex sensor_mutex;\r
138         struct mutex i2c_mutex;\r
139         int status_cur;\r
140         int start_count;\r
141         int devid;\r
142         struct i2c_device_id *i2c_id;\r
143         struct sensor_platform_data *pdata;\r
144         struct sensor_operate *ops; \r
145         struct file_operations fops;\r
146         struct miscdevice miscdev;\r
147 #ifdef CONFIG_HAS_EARLYSUSPEND\r
148         struct  early_suspend early_suspend;\r
149 #endif\r
150 };\r
151 \r
152 \r
153 extern int sensor_register_slave(int type,struct i2c_client *client,\r
154                         struct sensor_platform_data *slave_pdata,\r
155                         struct sensor_operate *(*get_sensor_ops)(void));\r
156 \r
157 \r
158 extern int sensor_unregister_slave(int type,struct i2c_client *client,\r
159                         struct sensor_platform_data *slave_pdata,\r
160                         struct sensor_operate *(*get_sensor_ops)(void));\r
161 \r
162 \r
163 #define GSENSOR_IO                              0xA1\r
164 #define GBUFF_SIZE                              12      /* Rx buffer size */\r
165 \r
166 /* IOCTLs for MMA8452 library */\r
167 #define GSENSOR_IOCTL_INIT                  _IO(GSENSOR_IO, 0x01)\r
168 #define GSENSOR_IOCTL_RESET                     _IO(GSENSOR_IO, 0x04)\r
169 #define GSENSOR_IOCTL_CLOSE                             _IO(GSENSOR_IO, 0x02)\r
170 #define GSENSOR_IOCTL_START                         _IO(GSENSOR_IO, 0x03)\r
171 #define GSENSOR_IOCTL_GETDATA               _IOR(GSENSOR_IO, 0x08, char[GBUFF_SIZE+1])\r
172 /* IOCTLs for APPs */\r
173 #define GSENSOR_IOCTL_APP_SET_RATE                      _IOW(GSENSOR_IO, 0x10, char)\r
174 \r
175 \r
176 #define LIGHTSENSOR_IOCTL_MAGIC 'l'\r
177 #define LIGHTSENSOR_IOCTL_GET_ENABLED           _IOR(LIGHTSENSOR_IOCTL_MAGIC, 1, int *) \r
178 #define LIGHTSENSOR_IOCTL_ENABLE                        _IOW(LIGHTSENSOR_IOCTL_MAGIC, 2, int *) \r
179 #define LIGHTSENSOR_IOCTL_DISABLE                       _IOW(LIGHTSENSOR_IOCTL_MAGIC, 3, int *)\r
180 \r
181 #define PSENSOR_IOCTL_MAGIC 'c'\r
182 #define PSENSOR_IOCTL_GET_ENABLED                       _IOR(PSENSOR_IOCTL_MAGIC, 1, int *)\r
183 #define PSENSOR_IOCTL_ENABLE                            _IOW(PSENSOR_IOCTL_MAGIC, 2, int *)\r
184 #define PSENSOR_IOCTL_DISABLE                   _IOW(PSENSOR_IOCTL_MAGIC, 3, int *)\r
185 \r
186 \r
187 \r
188 \r
189 extern int sensor_rx_data(struct i2c_client *client, char *rxData, int length);\r
190 extern int sensor_tx_data(struct i2c_client *client, char *txData, int length);\r
191 extern int sensor_write_reg(struct i2c_client *client, int addr, int value);\r
192 extern int sensor_read_reg(struct i2c_client *client, int addr);\r
193 extern int sensor_tx_data_normal(struct i2c_client *client, char *buf, int num);\r
194 extern int sensor_rx_data_normal(struct i2c_client *client, char *buf, int num);\r
195 extern int sensor_write_reg_normal(struct i2c_client *client, char value);\r
196 extern int sensor_read_reg_normal(struct i2c_client *client);\r
197 \r