1 #ifndef __DRV2624_H__
2 #define __DRV2624_H__
3 /*
4 ** =============================================================================
5 ** Copyright (c)2016 Texas Instruments Inc.
6 **
7 ** This program is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU General Public License
9 ** as published by the Free Software Foundation; either version 2
10 ** of the License, or (at your option) any later version.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; if not, write to the Free Software
19 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 **
21 ** File:
22 ** drv2624.h
23 **
24 ** Description:
25 ** Header file for drv2624.c
26 **
27 ** =============================================================================
28 */
31 #include <linux/regmap.h>
32 #include <linux/timer.h>
33 #include <linux/workqueue.h>
34 #include <linux/hrtimer.h>
35 #include <linux/mutex.h>
36 #include <linux/cdev.h>
37 #include <linux/firmware.h>
38 #ifdef ANDROID
39 #include <../../../drivers/staging/android/timed_output.h>
40 #elif defined ANDROID_TIMED_OUTPUT
41 #include "timed_output.h"
42 #endif
44 #define HAPTICS_DEVICE_NAME "drv2624"
45 #define NEED_RELOAD_FIRMWARE 1
46 #define DRV2624_REG_ID 0x00
47 #define DRV2624_ID_MASK 0xf0
48 #define DRV2624_ID (0x02&DRV2624_ID_MASK)
50 #define DRV2624_REG_STATUS 0x01
51 #define DIAG_MASK 0x80
52 #define DIAG_SUCCESS 0x00
53 #define DIAG_SHIFT 0x07
54 #define INT_MASK 0x1f
55 #define PRG_ERR_MASK 0x10
56 #define PROCESS_DONE_MASK 0x08
57 #define ULVO_MASK 0x04
58 #define OVERTEMPRATURE_MASK 0x02
59 #define OVERCURRENT_MASK 0x01
61 #define DRV2624_REG_INT_ENABLE 0x02
62 #define INT_MASK_ALL 0x1f
63 #define INT_ENABLE_ALL 0x00
64 #define INT_ENABLE_CRITICAL 0x08
66 #define DRV2624_REG_DIAG_Z 0x03
68 #define DRV2624_REG_MODE 0x07
69 #define WORKMODE_MASK 0x03
70 #define MODE_RTP 0x00
71 #define MODE_WAVEFORM_SEQUENCER 0x01
72 #define MODE_DIAGNOSTIC 0x02
73 #define MODE_CALIBRATION 0x03
74 #define PINFUNC_MASK 0x0c
75 #define PINFUNC_INT 0x02
76 #define PINFUNC_SHIFT 0x02
77 #define DRV2624_CALIBRATION_MODE_CFG 0x4B
79 #define DRV2624_REG_CONTROL1 0x08
80 #define DRV2624_AUTO_BRK_INTO_STBY_MASK (0x01 << 3)
81 #define DRV2624_STBY_MODE_WITH_AUTO_BRAKE (0x01 << 3)
82 #define DRV2624_STBY_MODE_WITHOUT_AUTO_BRAKE 0x00
83 #define DRV2624_REMOVE_STBY_MODE 0x00
85 #define ACTUATOR_MASK 0x80
86 #define ACTUATOR_SHIFT 7
87 #define LOOP_MASK 0x40
88 #define LOOP_SHIFT 6
89 #define AUTOBRK_OK_MASK 0x10
90 #define AUTOBRK_OK_ENABLE 0x10
92 #define DRV2624_REG_GO 0x0c
93 #define DRV2624_GO_BIT_MASK 0x01
95 #define DRV2624_REG_CONTROL2 0x0d
96 #define LIB_LRA 0x00
97 #define LIB_ERM 0x01
98 #define LIB_MASK 0x80
99 #define LIB_SHIFT 0x07
100 #define SCALE_MASK 0x03
101 #define INTERVAL_MASK 0x20
102 #define INTERVAL_SHIFT 0x05
104 #define DRV2624_REG_RTP_INPUT 0x0e
105 #define DRV2624_REG_SEQUENCER_1 0x0f
106 #define DRV2624_REG_SEQ_LOOP_1 0x17
107 #define DRV2624_REG_SEQ_LOOP_2 0x18
108 #define DRV2624_REG_MAIN_LOOP 0x19
109 #define DRV2624_REG_RATED_VOLTAGE 0x1f
110 #define DRV2624_REG_OVERDRIVE_CLAMP 0x20
111 #define DRV2624_REG_CAL_COMP 0x21
112 #define DRV2624_REG_CAL_BEMF 0x22
113 #define DRV2624_REG_LOOP_CONTROL 0x23
114 #define BEMFGAIN_MASK 0x03
116 #define DRV2624_REG_DRIVE_TIME 0x27
117 #define DRIVE_TIME_MASK 0x1f
118 #define MINFREQ_SEL_45HZ 0x01
119 #define MINFREQ_SEL_MASK 0x80
120 #define MINFREQ_SEL_SHIFT 0x07
122 #define DRV2624_REG_OL_PERIOD_H 0x2e
123 #define DRV2624_REG_OL_PERIOD_L 0x2f
124 #define DRV2624_REG_DIAG_K 0x30
126 #define GO_BIT_POLL_INTERVAL 15
127 #define STANDBY_WAKE_DELAY 1
128 #define WAKE_STANDBY_DELAY 3
130 #define DRV2624_REG_RAM_ADDR_UPPER 0xfd
131 #define DRV2624_REG_RAM_ADDR_LOWER 0xfe
132 #define DRV2624_REG_RAM_DATA 0xff
134 /* Commands */
135 #define HAPTIC_CMDID_PLAY_SINGLE_EFFECT 0x01
136 #define HAPTIC_CMDID_PLAY_EFFECT_SEQUENCE 0x02
137 #define HAPTIC_CMDID_PLAY_TIMED_EFFECT 0x03
138 #define HAPTIC_CMDID_GET_DEV_ID 0x04
139 #define HAPTIC_CMDID_RUN_DIAG 0x05
140 #define HAPTIC_CMDID_AUDIOHAPTIC_ENABLE 0x06
141 #define HAPTIC_CMDID_AUDIOHAPTIC_DISABLE 0x07
142 #define HAPTIC_CMDID_AUDIOHAPTIC_GETSTATUS 0x08
143 #define HAPTIC_CMDID_REG_WRITE 0x09
144 #define HAPTIC_CMDID_REG_READ 0x0a
145 #define HAPTIC_CMDID_REG_SETBIT 0x0b
146 #define HAPTIC_CMDID_PATTERN_RTP 0x0c
147 #define HAPTIC_CMDID_RTP_SEQUENCE 0x0d
148 #define HAPTIC_CMDID_GET_EFFECT_COUNT 0x10
149 #define HAPTIC_CMDID_UPDATE_FIRMWARE 0x11
150 #define HAPTIC_CMDID_READ_FIRMWARE 0x12
151 #define HAPTIC_CMDID_RUN_CALIBRATION 0x13
152 #define HAPTIC_CMDID_CONFIG_WAVEFORM 0x14
153 #define HAPTIC_CMDID_SET_SEQUENCER 0x15
154 #define HAPTIC_CMDID_REGLOG_ENABLE 0x16
155 #define HAPTIC_SET_CALIBRATION_RESULT 0x17
157 #define HAPTIC_CMDID_STOP 0xFF
159 #define MAX_TIMEOUT 10000 /* 10s */
160 #define MAX_READ_BYTES 0xff
161 #define DRV2624_SEQUENCER_SIZE 8
163 #define WORK_IDLE 0
164 #define WORK_VIBRATOR 0x01
165 #define WORK_IRQ 0x02
166 #define WORK_EFFECTSEQUENCER 0x04
167 #define WORK_CALIBRATION 0x08
168 #define WORK_DIAGNOSTIC 0x10
170 #define YES 1
171 #define NO 0
172 #define GO 1
173 #define STOP 0
175 #define GO_BIT_CHECK_INTERVAL 5 /* 5 ms */
176 #define GO_BIT_MAX_RETRY_CNT 20 /* 50 times */
178 #define DRV2624_MAGIC 0x2624
179 #define STRONG_MAGNITUDE 0x7fff
180 #define MEDIUM_MAGNITUDE 0x5fff
181 #define LIGHT_MAGNITUDE 0x3fff
182 #define DRV2624_RAM_SIZE 1024
183 #define EFFECT_MAX_NUM 32
185 /* auto calibration */
186 #define AUTO_CAL_TIME_REG 0x2A
187 #define AUTO_CAL_TIME_MASK 0x03
188 #define AUTO_CAL_TIME_250MS 0x00
189 #define AUTO_CAL_TIME_500MS 0x01
190 #define AUTO_CAL_TIME_1000MS 0x10
191 #define AUTO_CAL_TIME_AUTO_TRIGGER 0x11
193 typedef enum {
194 DRV2624_RTP_MODE = 0x00,
195 DRV2624_RAM_MODE,
196 DRV2624_WAVE_SEQ_MODE = DRV2624_RAM_MODE,
197 DRV2624_DIAG_MODE,
198 DRV2624_CALIBRATION_MODE,
199 } drv2624_mode_t;
201 enum actuator_type {
202 ERM = 0,
203 LRA
204 };
206 enum loop_type {
207 CLOSE_LOOP = 0x00,
208 OPEN_LOOP
209 };
211 struct actuator_data {
212 unsigned char mnActuatorType;
213 unsigned char mnRatedVoltage;
214 unsigned char mnOverDriveClampVoltage;
215 unsigned char mnLRAFreq;
216 };
218 enum wave_seq_loop {
219 SEQ_NO_LOOP,
220 SEQ_LOOP_ONCE,
221 SEQ_LOOP_TWICE,
222 SEQ_LOOP_TRIPPLE
223 };
225 enum wave_main_loop {
226 MAIN_NO_LOOP,
227 MAIN_LOOP_ONCE,
228 MAIN_LOOP_TWICE,
229 MAIN_LOOP_3_TIMES,
230 MAIN_LOOP_4_TIMES,
231 MAIN_LOOP_5_TIMES,
232 MAIN_LOOP_6_TIMES,
233 MAIN_LOOP_INFINITELY
234 };
236 enum wave_main_scale {
237 PERCENTAGE_100,
238 PERCENTAGE_75,
239 PERCENTAGE_50,
240 PERCENTAGE_25
241 };
243 enum wave_main_interval {
244 INTERVAL_5MS,
245 INTERVAL_1MS
246 };
248 struct drv2624_waveform {
249 unsigned char mnEffect;
250 unsigned char mnLoop;
251 };
253 struct drv2624_waveform_sequencer {
254 struct drv2624_waveform msWaveform[DRV2624_SEQUENCER_SIZE];
255 };
257 struct drv2624_wave_setting {
258 unsigned char mnLoop;
259 unsigned char mnInterval;
260 unsigned char mnScale;
261 };
263 struct drv2624_autocal_result {
264 int mnFinished;
265 unsigned char mnResult;
266 unsigned char mnCalComp;
267 unsigned char mnCalBemf;
268 unsigned char mnCalGain;
269 };
271 struct drv2624_diag_result {
272 int mnFinished;
273 unsigned char mnResult;
274 unsigned char mnDiagZ;
275 unsigned char mnDiagK;
276 };
278 struct drv2624_platform_data {
279 int mnGpioNRST;
280 int mnGpioINT;
281 unsigned char mnLoop;
282 struct actuator_data msActuator;
283 };
285 struct drv2624_fw_header{
286 int fw_magic;
287 int fw_size;
288 int fw_date;
289 int fw_chksum;
290 int fw_effCount;
291 };
293 struct drv2624_constant_playinfo {
294 int effect_count;
295 int effect_id;
296 int length;
297 int magnitude;
298 unsigned char rtp_input;
299 };
301 enum haptics_custom_effect_param {
302 CUSTOM_DATA_EFFECT_IDX,
303 CUSTOM_DATA_TIMEOUT_SEC_IDX,
304 CUSTOM_DATA_TIMEOUT_MSEC_IDX,
305 CUSTOM_DATA_LEN,
306 };
308 struct drv2624_data {
309 struct input_dev *input_dev;
310 struct i2c_client *client;
311 struct drv2624_platform_data msPlatData;
312 struct mutex lock;
313 struct mutex dev_lock;
314 unsigned char mnDeviceID;
315 struct device *dev;
316 struct regmap *mpRegmap;
317 unsigned int mnIRQ;
318 unsigned char mnIntStatus;
319 bool mbIRQEnabled;
320 bool mbIRQUsed;
321 struct drv2624_wave_setting msWaveformSetting;
322 struct drv2624_waveform_sequencer msWaveformSequencer;
323 unsigned char mnFileCmd;
324 volatile int mnVibratorPlaying;
325 volatile char mnWorkMode;
326 unsigned char mnCurrentReg;
327 struct hrtimer haptics_timer;
329 struct drv2624_autocal_result mAutoCalResult;
330 struct drv2624_diag_result mDiagResult;
332 struct drv2624_fw_header fw_header;
333 unsigned char mRAMLSB;
334 unsigned char mRAMMSB;
336 int mnEffectType;
337 unsigned char mnFwRam[DRV2624_RAM_SIZE];
338 unsigned int mnEffectTimems[EFFECT_MAX_NUM];
339 struct drv2624_constant_playinfo play;
341 struct work_struct vibrator_work;
342 #ifdef ANDROID_TIMED_OUTPUT
343 struct timed_output_dev to_dev;
344 #endif
345 struct work_struct upload_periodic_work;
346 struct work_struct haptics_playback_work;
347 struct work_struct haptics_set_gain_work;
348 };
350 #define DRV2624_MAGIC_NUMBER 0x32363234 /* '2624' */
352 #define DRV2624_WAVSEQ_PLAY _IOWR(DRV2624_MAGIC_NUMBER, 4, unsigned long)
353 #define DRV2624_STOP _IOWR(DRV2624_MAGIC_NUMBER, 5, unsigned long)
354 #define DRV2624_RUN_DIAGNOSTIC _IOWR(DRV2624_MAGIC_NUMBER, 6, unsigned long)
355 #define DRV2624_GET_DIAGRESULT _IOWR(DRV2624_MAGIC_NUMBER, 7, struct drv2624_diag_result *)
356 #define DRV2624_RUN_AUTOCAL _IOWR(DRV2624_MAGIC_NUMBER, 8, unsigned long)
357 #define DRV2624_GET_CALRESULT _IOWR(DRV2624_MAGIC_NUMBER, 9, struct drv2624_autocal_result *)
359 #endif