Merge remote-tracking branch 'stable/linux-3.0.y' into develop-3.0
[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         ACCEL_ID_MXC6225,\r
58 \r
59         COMPASS_ID_ALL,\r
60         COMPASS_ID_AK8975,\r
61         COMPASS_ID_AK8972,\r
62         COMPASS_ID_AMI30X,\r
63         COMPASS_ID_AMI306,\r
64         COMPASS_ID_YAS529,\r
65         COMPASS_ID_YAS530,\r
66         COMPASS_ID_HMC5883,\r
67         COMPASS_ID_LSM303DLH,\r
68         COMPASS_ID_LSM303DLM,\r
69         COMPASS_ID_MMC314X,\r
70         COMPASS_ID_HSCDTD002B,\r
71         COMPASS_ID_HSCDTD004A,\r
72 \r
73         GYRO_ID_ALL,\r
74         GYRO_ID_L3G4200D,\r
75         GYRO_ID_K3G,\r
76 \r
77         LIGHT_ID_ALL,\r
78         LIGHT_ID_CM3217,\r
79         LIGHT_ID_AL3006,\r
80         LIGHT_ID_STK3171,\r
81         LIGHT_ID_ISL29023,\r
82         LIGHT_ID_AP321XX,\r
83         \r
84         PROXIMITY_ID_ALL,\r
85         PROXIMITY_ID_AL3006,\r
86         PROXIMITY_ID_STK3171,\r
87         PROXIMITY_ID_AP321XX,\r
88         TEMPERATURE_ID_ALL,\r
89 \r
90         PRESSURE_ID_ALL,\r
91         PRESSURE_ID_BMA085,\r
92         SENSOR_NUM_ID,\r
93 };\r
94 \r
95 \r
96 struct sensor_axis {\r
97         int x;\r
98         int y;\r
99         int z;\r
100 };\r
101 \r
102 struct sensor_operate {\r
103         char *name;\r
104         int type;\r
105         int     id_i2c;\r
106         int     range[2];\r
107         int     brightness[2];//backlight min_brightness max_brightness \r
108         int read_reg;\r
109         int read_len;\r
110         int id_reg;\r
111         int id_data;\r
112         int precision;\r
113         int ctrl_reg;\r
114         int ctrl_data;\r
115         int int_ctrl_reg;\r
116         int     int_status_reg;\r
117         int trig;       //intterupt trigger\r
118         int (*active)(struct i2c_client *client, int enable, int rate); \r
119         int (*init)(struct i2c_client *client); \r
120         int (*report)(struct i2c_client *client);\r
121         int (*suspend)(struct i2c_client *client);\r
122         int (*resume)(struct i2c_client *client);\r
123         struct miscdevice *misc_dev;\r
124 \r
125 };\r
126 \r
127 \r
128 /* Platform data for the sensor */\r
129 struct sensor_private_data {\r
130         int type;\r
131         struct i2c_client *client;      \r
132         struct input_dev *input_dev;\r
133         struct work_struct work;\r
134         struct delayed_work delaywork;  /*report second event*/\r
135         struct sensor_axis axis;\r
136         char sensor_data[40];           //max support40 bytes data\r
137         atomic_t data_ready;\r
138         wait_queue_head_t data_ready_wq;                \r
139         struct mutex data_mutex;\r
140         struct mutex operation_mutex;   \r
141         struct mutex sensor_mutex;\r
142         struct mutex i2c_mutex;\r
143         int status_cur;\r
144         int start_count;\r
145         int devid;\r
146         struct i2c_device_id *i2c_id;\r
147         struct sensor_platform_data *pdata;\r
148         struct sensor_operate *ops; \r
149         struct file_operations fops;\r
150         struct miscdevice miscdev;\r
151 #ifdef CONFIG_HAS_EARLYSUSPEND\r
152         struct  early_suspend early_suspend;\r
153 #endif\r
154 };\r
155 \r
156 \r
157 extern int sensor_register_slave(int type,struct i2c_client *client,\r
158                         struct sensor_platform_data *slave_pdata,\r
159                         struct sensor_operate *(*get_sensor_ops)(void));\r
160 \r
161 \r
162 extern int sensor_unregister_slave(int type,struct i2c_client *client,\r
163                         struct sensor_platform_data *slave_pdata,\r
164                         struct sensor_operate *(*get_sensor_ops)(void));\r
165 \r
166 \r
167 #define GSENSOR_IO                              0xA1\r
168 #define GBUFF_SIZE                              12      /* Rx buffer size */\r
169 \r
170 /* IOCTLs for MMA8452 library */\r
171 #define GSENSOR_IOCTL_INIT                  _IO(GSENSOR_IO, 0x01)\r
172 #define GSENSOR_IOCTL_RESET                     _IO(GSENSOR_IO, 0x04)\r
173 #define GSENSOR_IOCTL_CLOSE                             _IO(GSENSOR_IO, 0x02)\r
174 #define GSENSOR_IOCTL_START                         _IO(GSENSOR_IO, 0x03)\r
175 #define GSENSOR_IOCTL_GETDATA               _IOR(GSENSOR_IO, 0x08, char[GBUFF_SIZE+1])\r
176 /* IOCTLs for APPs */\r
177 #define GSENSOR_IOCTL_APP_SET_RATE                      _IOW(GSENSOR_IO, 0x10, char)\r
178 \r
179 \r
180 #define LIGHTSENSOR_IOCTL_MAGIC 'l'\r
181 #define LIGHTSENSOR_IOCTL_GET_ENABLED           _IOR(LIGHTSENSOR_IOCTL_MAGIC, 1, int *) \r
182 #define LIGHTSENSOR_IOCTL_ENABLE                        _IOW(LIGHTSENSOR_IOCTL_MAGIC, 2, int *) \r
183 #define LIGHTSENSOR_IOCTL_DISABLE                       _IOW(LIGHTSENSOR_IOCTL_MAGIC, 3, int *)\r
184 \r
185 #define PSENSOR_IOCTL_MAGIC 'c'\r
186 #define PSENSOR_IOCTL_GET_ENABLED                       _IOR(PSENSOR_IOCTL_MAGIC, 1, int *)\r
187 #define PSENSOR_IOCTL_ENABLE                            _IOW(PSENSOR_IOCTL_MAGIC, 2, int *)\r
188 #define PSENSOR_IOCTL_DISABLE                   _IOW(PSENSOR_IOCTL_MAGIC, 3, int *)\r
189 \r
190 \r
191 \r
192 \r
193 extern int sensor_rx_data(struct i2c_client *client, char *rxData, int length);\r
194 extern int sensor_tx_data(struct i2c_client *client, char *txData, int length);\r
195 extern int sensor_write_reg(struct i2c_client *client, int addr, int value);\r
196 extern int sensor_read_reg(struct i2c_client *client, int addr);\r
197 extern int sensor_tx_data_normal(struct i2c_client *client, char *buf, int num);\r
198 extern int sensor_rx_data_normal(struct i2c_client *client, char *buf, int num);\r
199 extern int sensor_write_reg_normal(struct i2c_client *client, char value);\r
200 extern int sensor_read_reg_normal(struct i2c_client *client);\r
201 \r