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