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