1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef __SSP_SENSORHUB_H__
17#define __SSP_SENSORHUB_H__
18
19#include <linux/delay.h>
20#include <linux/gpio.h>
21#include <linux/iio/common/ssp_sensors.h>
22#include <linux/iio/iio.h>
23#include <linux/spi/spi.h>
24
25#define SSP_DEVICE_ID 0x55
26
27#ifdef SSP_DBG
28#define ssp_dbg(format, ...) pr_info("[SSP] "format, ##__VA_ARGS__)
29#else
30#define ssp_dbg(format, ...)
31#endif
32
33#define SSP_SW_RESET_TIME 3000
34
35#define SSP_DEFAULT_POLLING_DELAY 200
36#define SSP_DEFAULT_RETRIES 3
37#define SSP_DATA_PACKET_SIZE 960
38#define SSP_HEADER_BUFFER_SIZE 4
39
40enum {
41 SSP_KERNEL_BINARY = 0,
42 SSP_KERNEL_CRASHED_BINARY,
43};
44
45enum {
46 SSP_INITIALIZATION_STATE = 0,
47 SSP_NO_SENSOR_STATE,
48 SSP_ADD_SENSOR_STATE,
49 SSP_RUNNING_SENSOR_STATE,
50};
51
52
53enum {
54 SSP_FW_DL_STATE_FAIL = -1,
55 SSP_FW_DL_STATE_NONE = 0,
56 SSP_FW_DL_STATE_NEED_TO_SCHEDULE,
57 SSP_FW_DL_STATE_SCHEDULED,
58 SSP_FW_DL_STATE_DOWNLOADING,
59 SSP_FW_DL_STATE_SYNC,
60 SSP_FW_DL_STATE_DONE,
61};
62
63#define SSP_INVALID_REVISION 99999
64#define SSP_INVALID_REVISION2 0xffffff
65
66
67#define SSP_MSG2SSP_INST_BYPASS_SENSOR_ADD 0xa1
68#define SSP_MSG2SSP_INST_BYPASS_SENSOR_RM 0xa2
69#define SSP_MSG2SSP_INST_REMOVE_ALL 0xa3
70#define SSP_MSG2SSP_INST_CHANGE_DELAY 0xa4
71#define SSP_MSG2SSP_INST_LIBRARY_ADD 0xb1
72#define SSP_MSG2SSP_INST_LIBRARY_REMOVE 0xb2
73#define SSP_MSG2SSP_INST_LIB_NOTI 0xb4
74#define SSP_MSG2SSP_INST_LIB_DATA 0xc1
75
76#define SSP_MSG2SSP_AP_MCU_SET_GYRO_CAL 0xcd
77#define SSP_MSG2SSP_AP_MCU_SET_ACCEL_CAL 0xce
78#define SSP_MSG2SSP_AP_STATUS_SHUTDOWN 0xd0
79#define SSP_MSG2SSP_AP_STATUS_WAKEUP 0xd1
80#define SSP_MSG2SSP_AP_STATUS_SLEEP 0xd2
81#define SSP_MSG2SSP_AP_STATUS_RESUME 0xd3
82#define SSP_MSG2SSP_AP_STATUS_SUSPEND 0xd4
83#define SSP_MSG2SSP_AP_STATUS_RESET 0xd5
84#define SSP_MSG2SSP_AP_STATUS_POW_CONNECTED 0xd6
85#define SSP_MSG2SSP_AP_STATUS_POW_DISCONNECTED 0xd7
86#define SSP_MSG2SSP_AP_TEMPHUMIDITY_CAL_DONE 0xda
87#define SSP_MSG2SSP_AP_MCU_SET_DUMPMODE 0xdb
88#define SSP_MSG2SSP_AP_MCU_DUMP_CHECK 0xdc
89#define SSP_MSG2SSP_AP_MCU_BATCH_FLUSH 0xdd
90#define SSP_MSG2SSP_AP_MCU_BATCH_COUNT 0xdf
91
92#define SSP_MSG2SSP_AP_WHOAMI 0x0f
93#define SSP_MSG2SSP_AP_FIRMWARE_REV 0xf0
94#define SSP_MSG2SSP_AP_SENSOR_FORMATION 0xf1
95#define SSP_MSG2SSP_AP_SENSOR_PROXTHRESHOLD 0xf2
96#define SSP_MSG2SSP_AP_SENSOR_BARCODE_EMUL 0xf3
97#define SSP_MSG2SSP_AP_SENSOR_SCANNING 0xf4
98#define SSP_MSG2SSP_AP_SET_MAGNETIC_HWOFFSET 0xf5
99#define SSP_MSG2SSP_AP_GET_MAGNETIC_HWOFFSET 0xf6
100#define SSP_MSG2SSP_AP_SENSOR_GESTURE_CURRENT 0xf7
101#define SSP_MSG2SSP_AP_GET_THERM 0xf8
102#define SSP_MSG2SSP_AP_GET_BIG_DATA 0xf9
103#define SSP_MSG2SSP_AP_SET_BIG_DATA 0xfa
104#define SSP_MSG2SSP_AP_START_BIG_DATA 0xfb
105#define SSP_MSG2SSP_AP_SET_MAGNETIC_STATIC_MATRIX 0xfd
106#define SSP_MSG2SSP_AP_SENSOR_TILT 0xea
107#define SSP_MSG2SSP_AP_MCU_SET_TIME 0xfe
108#define SSP_MSG2SSP_AP_MCU_GET_TIME 0xff
109
110#define SSP_MSG2SSP_AP_FUSEROM 0x01
111
112
113#define SSP_TYPE_WAKE_UP_VOICE_SERVICE 0x01
114#define SSP_TYPE_WAKE_UP_VOICE_SOUND_SOURCE_AM 0x01
115#define SSP_TYPE_WAKE_UP_VOICE_SOUND_SOURCE_GRAMMER 0x02
116
117
118#define SSP_ACCELEROMETER_FACTORY 0x80
119#define SSP_GYROSCOPE_FACTORY 0x81
120#define SSP_GEOMAGNETIC_FACTORY 0x82
121#define SSP_PRESSURE_FACTORY 0x85
122#define SSP_GESTURE_FACTORY 0x86
123#define SSP_TEMPHUMIDITY_CRC_FACTORY 0x88
124#define SSP_GYROSCOPE_TEMP_FACTORY 0x8a
125#define SSP_GYROSCOPE_DPS_FACTORY 0x8b
126#define SSP_MCU_FACTORY 0x8c
127#define SSP_MCU_SLEEP_FACTORY 0x8d
128
129
130#define SSP_MSG_ACK 0x80
131#define SSP_MSG_NAK 0x70
132
133struct ssp_sensorhub_info {
134 char *fw_name;
135 char *fw_crashed_name;
136 unsigned int fw_rev;
137 const u8 * const mag_table;
138 const unsigned int mag_length;
139};
140
141
142#define SSP_RW 0
143#define SSP_INDEX 3
144
145#define SSP_AP2HUB_READ 0
146#define SSP_AP2HUB_WRITE 1
147#define SSP_HUB2AP_WRITE 2
148#define SSP_AP2HUB_READY 3
149#define SSP_AP2HUB_RETURN 4
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
186
187
188
189struct ssp_data {
190 struct spi_device *spi;
191 const struct ssp_sensorhub_info *sensorhub_info;
192 struct timer_list wdt_timer;
193 struct work_struct work_wdt;
194 struct delayed_work work_refresh;
195
196 bool shut_down;
197 bool mcu_dump_mode;
198 bool time_syncing;
199 int64_t timestamp;
200
201 int check_status[SSP_SENSOR_MAX];
202
203 unsigned int com_fail_cnt;
204 unsigned int reset_cnt;
205 unsigned int timeout_cnt;
206
207 unsigned int available_sensors;
208 unsigned int cur_firm_rev;
209
210 char last_resume_state;
211 char last_ap_state;
212
213 unsigned int sensor_enable;
214 u32 delay_buf[SSP_SENSOR_MAX];
215 s32 batch_latency_buf[SSP_SENSOR_MAX];
216 s8 batch_opt_buf[SSP_SENSOR_MAX];
217
218 int accel_position;
219 int mag_position;
220 int fw_dl_state;
221
222 struct mutex comm_lock;
223 struct mutex pending_lock;
224
225 int mcu_reset_gpio;
226 int ap_mcu_gpio;
227 int mcu_ap_gpio;
228
229 struct list_head pending_list;
230
231 struct iio_dev *sensor_devs[SSP_SENSOR_MAX];
232 atomic_t enable_refcount;
233
234 __le16 header_buffer[SSP_HEADER_BUFFER_SIZE / sizeof(__le16)]
235 ____cacheline_aligned;
236};
237
238void ssp_clean_pending_list(struct ssp_data *data);
239
240int ssp_command(struct ssp_data *data, char command, int arg);
241
242int ssp_send_instruction(struct ssp_data *data, u8 inst, u8 sensor_type,
243 u8 *send_buf, u8 length);
244
245int ssp_irq_msg(struct ssp_data *data);
246
247int ssp_get_chipid(struct ssp_data *data);
248
249int ssp_set_magnetic_matrix(struct ssp_data *data);
250
251unsigned int ssp_get_sensor_scanning_info(struct ssp_data *data);
252
253unsigned int ssp_get_firmware_rev(struct ssp_data *data);
254
255int ssp_queue_ssp_refresh_task(struct ssp_data *data, unsigned int delay);
256
257#endif
258