aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/mediatek/sensorHub/inc/SCP_sensorHub.h
blob: 0ff3a42ae0564a144d79e629f1a90fe863e58dff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* SCP sensor hub driver
 *
 *
 * This software program is licensed subject to the GNU General Public License
 * (GPL).Version 2,June 1991, available at http://www.fsf.org/copyleft/gpl.html

 * (C) Copyright 2011 Bosch Sensortec GmbH
 * All Rights Reserved
 */

#ifndef SCP_SENSOR_HUB_H
#define SCP_SENSOR_HUB_H
	 
#include <linux/ioctl.h>
#include <cust_acc.h>
	 
#define SCP_SENSOR_HUB_TEMP_BUFSIZE     256

#define SCP_SENSOR_HUB_FIFO_SIZE        32768

#define SCP_SENSOR_HUB_SUCCESS          0
#define SCP_SENSOR_HUB_FAILURE          (-1)

struct scp_acc_hw {
	int i2c_num;		/*!< the i2c bus used by the chip */
	int direction;		/*!< the direction of the chip */
	int power_id;		/*!< the VDD LDO ID of the chip, MT6516_POWER_NONE means the power is always on */
	int power_vol;		/*!< the VDD Power Voltage used by the chip */
	int firlen;		/*!< the length of low pass filter */
	int reserved;
	unsigned char i2c_addr[G_CUST_I2C_ADDR_NUM];	/*!< i2c address list,for chips which has different addresses with different HW layout */
	int power_vio_id;	/*!< the VIO LDO ID of the chip, MT6516_POWER_NONE means the power is always on */
	int power_vio_vol;	/*!< the VIO Power Voltage used by the chip */
    bool is_batch_supported;
};

typedef enum{
    SENSOR_HUB_ACTIVATE = 0,
    SENSOR_HUB_SET_DELAY,
    SENSOR_HUB_GET_DATA,
    SENSOR_HUB_BATCH,
    SENSOR_HUB_SET_CONFIG,
    SENSOR_HUB_SET_CUST,
    SENSOR_HUB_NOTIFY,
}SCP_ACTION;

typedef enum{
    SCP_INIT_DONE = 0,
    SCP_FIFO_FULL,
    SCP_NOTIFY,
}SCP_NOTIFY_EVENT;

struct SCP_sensorData{
    uint8_t     dataLength;
    uint8_t     sensorType;
    uint8_t     reserve[2];
    uint32_t    timeStampH;
    uint32_t    timeStampL;
    int16_t    data[8];
};

struct sensorFIFO {
//    volatile struct SCP_sensorData * volatile rp;
//    volatile struct SCP_sensorData * volatile wp;
    int rp; //use int for store DRAM FIFO LSB 32bit read pointer
    int wp;
    uint32_t                FIFOSize;
    struct SCP_sensorData   data[0];
};

typedef struct{
    uint32_t    sensorType;
    SCP_ACTION  action;
    uint32_t    data[10];
}SCP_SENSOR_HUB_REQ;

typedef struct{
    uint32_t    sensorType;
    SCP_ACTION  action;
    uint32_t    errCode;
    //uint32_t    reserved[9];
}SCP_SENSOR_HUB_RSP;

typedef struct{
    uint32_t    sensorType;
    SCP_ACTION  action;
    uint32_t    enable;         //0 : disable ; 1 : enable
    //uint32_t    reserved[9];
}SCP_SENSOR_HUB_ACTIVATE_REQ;

typedef SCP_SENSOR_HUB_RSP SCP_SENSOR_HUB_ACTIVATE_RSP;

typedef struct{
    uint32_t    sensorType;
    SCP_ACTION  action;
    uint32_t    delay;          //ms
    //uint32_t    reserved[9];
}SCP_SENSOR_HUB_SET_DELAY_REQ;

typedef SCP_SENSOR_HUB_RSP SCP_SENSOR_HUB_SET_DELAY_RSP;

typedef struct{
    uint32_t    sensorType;
    SCP_ACTION  action;
    //uint32_t    reserved[10];
}SCP_SENSOR_HUB_GET_DATA_REQ;

typedef struct{
    uint32_t    sensorType;
    SCP_ACTION  action;
    uint32_t    errCode;
    union{
        int8_t      int8_Data[0];
        int16_t     int16_Data[0];
        int32_t     int32_Data[0];
    };
}SCP_SENSOR_HUB_GET_DATA_RSP;

typedef struct{
    uint32_t    sensorType;
    SCP_ACTION  action;
    uint32_t    flag;           //see SENSORS_BATCH_WAKE_UPON_FIFO_FULL definition in hardware/libhardware/include/hardware/sensors.h
    uint32_t    period_ms;      //batch reporting time in ms
    uint32_t    timeout_ms;     //sampling time in ms
    //uint32_t    reserved[7];
}SCP_SENSOR_HUB_BATCH_REQ;

typedef SCP_SENSOR_HUB_RSP SCP_SENSOR_HUB_BATCH_RSP;

typedef struct{
    uint32_t            sensorType;
    SCP_ACTION          action;
    //struct sensorFIFO   *bufferBase;
    int                 bufferBase; //use int to store buffer DRAM base LSB 32 bits
    uint32_t            bufferSize;
    //uint32_t    reserved[8];
}SCP_SENSOR_HUB_SET_CONFIG_REQ;

typedef SCP_SENSOR_HUB_RSP SCP_SENSOR_HUB_SET_CONFIG_RSP;

typedef struct{
    uint32_t    sensorType;
    SCP_ACTION  action;
    uint32_t    custData[10];
}SCP_SENSOR_HUB_SET_CUST_REQ;

typedef struct{
    uint32_t    sensorType;
    SCP_ACTION  action;
    uint32_t    errCode;
    uint32_t    custData[0];
}SCP_SENSOR_HUB_SET_CUST_RSP;

typedef struct{
    uint32_t            sensorType;
    SCP_ACTION          action;
    SCP_NOTIFY_EVENT    event;
    uint32_t            data[0];
}SCP_SENSOR_HUB_NOTIFY_RSP;

typedef union{
    SCP_SENSOR_HUB_REQ req;
    SCP_SENSOR_HUB_RSP rsp;
    SCP_SENSOR_HUB_ACTIVATE_REQ activate_req;
    SCP_SENSOR_HUB_ACTIVATE_RSP activate_rsp;
    SCP_SENSOR_HUB_SET_DELAY_REQ set_delay_req;
    SCP_SENSOR_HUB_SET_DELAY_RSP set_delay_rsp;
    SCP_SENSOR_HUB_GET_DATA_REQ get_data_req;
    SCP_SENSOR_HUB_GET_DATA_RSP get_data_rsp;
    SCP_SENSOR_HUB_BATCH_REQ batch_req;
    SCP_SENSOR_HUB_BATCH_RSP batch_rsp;
    SCP_SENSOR_HUB_SET_CONFIG_REQ set_config_req;
    SCP_SENSOR_HUB_SET_CONFIG_RSP set_config_rsp;
    SCP_SENSOR_HUB_SET_CUST_REQ set_cust_req;
    SCP_SENSOR_HUB_SET_CUST_RSP set_cust_rsp;
    SCP_SENSOR_HUB_NOTIFY_RSP notify_rsp;
}SCP_SENSOR_HUB_DATA, *SCP_SENSOR_HUB_DATA_P;

typedef int (*SCP_sensorHub_handler)(void* data, uint len);

int SCP_sensorHub_req_send(SCP_SENSOR_HUB_DATA_P data, uint *len, unsigned int wait);
int SCP_sensorHub_rsp_registration(int sensor, SCP_sensorHub_handler handler);

#endif