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