1 /* include/linux/sensor-dev.h - sensor header file
\r
3 * Copyright (C) 2012-2015 ROCKCHIP.
\r
4 * Author: luowei <lw@rock-chips.com>
\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
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
17 #include <linux/miscdevice.h>
\r
18 #ifdef CONFIG_HAS_EARLYSUSPEND
\r
19 #include <linux/earlysuspend.h>
\r
24 #define SENSOR_OFF 0
\r
25 #define SENSOR_UNKNOW_DATA -1
\r
30 SENSOR_TYPE_COMPASS,
\r
31 SENSOR_TYPE_GYROSCOPE,
\r
33 SENSOR_TYPE_PROXIMITY,
\r
34 SENSOR_TYPE_TEMPERATURE,
\r
35 //SENSOR_TYPE_PRESSURE,
\r
67 COMPASS_ID_LSM303DLH,
\r
68 COMPASS_ID_LSM303DLM,
\r
70 COMPASS_ID_HSCDTD002B,
\r
71 COMPASS_ID_HSCDTD004A,
\r
85 PROXIMITY_ID_AL3006,
\r
86 PROXIMITY_ID_STK3171,
\r
87 PROXIMITY_ID_AP321XX,
\r
96 struct sensor_axis {
\r
102 struct sensor_operate {
\r
107 int brightness[2];//backlight min_brightness max_brightness
\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
128 /* Platform data for the sensor */
\r
129 struct sensor_private_data {
\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
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
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
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
167 #define GSENSOR_IO 0xA1
\r
168 #define GBUFF_SIZE 12 /* Rx buffer size */
\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
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
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
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