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 */
30 #include <linux/regmap.h>
31 #include <linux/timer.h>
32 #include <linux/workqueue.h>
33 #include <../../../drivers/staging/android/timed_output.h>
34 #include <linux/hrtimer.h>
35 #include <linux/wakelock.h>
36 #include <linux/mutex.h>
37 #include <linux/cdev.h>
38 #include <linux/firmware.h>
40 #define HAPTICS_DEVICE_NAME "drv2624"
42 #define DRV2624_REG_ID 0x00
43 #define DRV2624_ID (0x02&0xf0)
45 #define DRV2624_REG_STATUS 0x01
46 #define DIAG_MASK 0x80
47 #define DIAG_SUCCESS 0x00
48 #define DIAG_SHIFT 0x07
49 #define INT_MASK 0x1f
50 #define PRG_ERR_MASK 0x10
51 #define PROCESS_DONE_MASK 0x08
52 #define ULVO_MASK 0x04
53 #define OVERTEMPRATURE_MASK 0x02
54 #define OVERCURRENT_MASK 0x01
56 #define DRV2624_REG_INT_ENABLE 0x02
57 #define INT_MASK_ALL 0x1f
58 #define INT_ENABLE_ALL 0x00
59 #define INT_ENABLE_CRITICAL 0x08
61 #define DRV2624_REG_DIAG_Z 0x03
63 #define DRV2624_REG_MODE 0x07
64 #define WORKMODE_MASK 0x03
65 #define MODE_RTP 0x00
66 #define MODE_WAVEFORM_SEQUENCER 0x01
67 #define MODE_DIAGNOSTIC 0x02
68 #define MODE_CALIBRATION 0x03
69 #define PINFUNC_MASK 0x0c
70 #define PINFUNC_INT 0x02
71 #define PINFUNC_SHIFT 0x02
73 #define DRV2624_REG_CONTROL1 0x08
74 #define ACTUATOR_MASK 0x80
75 #define ACTUATOR_SHIFT 7
76 #define LOOP_MASK 0x40
77 #define LOOP_SHIFT 6
78 #define AUTOBRK_OK_MASK 0x10
79 #define AUTOBRK_OK_ENABLE 0x10
81 #define DRV2624_REG_GO 0x0c
83 #define DRV2624_REG_CONTROL2 0x0d
84 #define LIB_LRA 0x00
85 #define LIB_ERM 0x01
86 #define LIB_MASK 0x80
87 #define LIB_SHIFT 0x07
88 #define SCALE_MASK 0x03
89 #define INTERVAL_MASK 0x20
90 #define INTERVAL_SHIFT 0x05
92 #define DRV2624_REG_RTP_INPUT 0x0e
93 #define DRV2624_REG_SEQUENCER_1 0x0f
94 #define DRV2624_REG_SEQ_LOOP_1 0x17
95 #define DRV2624_REG_SEQ_LOOP_2 0x18
96 #define DRV2624_REG_MAIN_LOOP 0x19
97 #define DRV2624_REG_RATED_VOLTAGE 0x1f
98 #define DRV2624_REG_OVERDRIVE_CLAMP 0x20
99 #define DRV2624_REG_CAL_COMP 0x21
100 #define DRV2624_REG_CAL_BEMF 0x22
101 #define DRV2624_REG_LOOP_CONTROL 0x23
102 #define BEMFGAIN_MASK 0x03
104 #define DRV2624_REG_DRIVE_TIME 0x27
105 #define DRIVE_TIME_MASK 0x1f
106 #define MINFREQ_SEL_45HZ 0x01
107 #define MINFREQ_SEL_MASK 0x80
108 #define MINFREQ_SEL_SHIFT 0x07
110 #define DRV2624_REG_OL_PERIOD_H 0x2e
111 #define DRV2624_REG_OL_PERIOD_L 0x2f
112 #define DRV2624_REG_DIAG_K 0x30
114 #define GO_BIT_POLL_INTERVAL 15
115 #define STANDBY_WAKE_DELAY 1
116 #define WAKE_STANDBY_DELAY 3
118 #define DRV2624_REG_RAM_ADDR_UPPER 0xfd
119 #define DRV2624_REG_RAM_ADDR_LOWER 0xfe
120 #define DRV2624_REG_RAM_DATA 0xff
122 /* Commands */
123 #define HAPTIC_CMDID_PLAY_SINGLE_EFFECT 0x01
124 #define HAPTIC_CMDID_PLAY_EFFECT_SEQUENCE 0x02
125 #define HAPTIC_CMDID_PLAY_TIMED_EFFECT 0x03
126 #define HAPTIC_CMDID_GET_DEV_ID 0x04
127 #define HAPTIC_CMDID_RUN_DIAG 0x05
128 #define HAPTIC_CMDID_AUDIOHAPTIC_ENABLE 0x06
129 #define HAPTIC_CMDID_AUDIOHAPTIC_DISABLE 0x07
130 #define HAPTIC_CMDID_AUDIOHAPTIC_GETSTATUS 0x08
131 #define HAPTIC_CMDID_REG_WRITE 0x09
132 #define HAPTIC_CMDID_REG_READ 0x0a
133 #define HAPTIC_CMDID_REG_SETBIT 0x0b
134 #define HAPTIC_CMDID_PATTERN_RTP 0x0c
135 #define HAPTIC_CMDID_RTP_SEQUENCE 0x0d
136 #define HAPTIC_CMDID_GET_EFFECT_COUNT 0x10
137 #define HAPTIC_CMDID_UPDATE_FIRMWARE 0x11
138 #define HAPTIC_CMDID_READ_FIRMWARE 0x12
139 #define HAPTIC_CMDID_RUN_CALIBRATION 0x13
140 #define HAPTIC_CMDID_CONFIG_WAVEFORM 0x14
141 #define HAPTIC_CMDID_SET_SEQUENCER 0x15
142 #define HAPTIC_CMDID_REGLOG_ENABLE 0x16
144 #define HAPTIC_CMDID_STOP 0xFF
146 #define MAX_TIMEOUT 10000 /* 10s */
147 #define MAX_READ_BYTES 0xff
148 #define DRV2624_SEQUENCER_SIZE 8
150 #define WORK_IDLE 0
151 #define WORK_VIBRATOR 0x01
152 #define WORK_IRQ 0x02
153 #define WORK_EFFECTSEQUENCER 0x04
154 #define WORK_CALIBRATION 0x08
155 #define WORK_DIAGNOSTIC 0x10
157 #define YES 1
158 #define NO 0
159 #define GO 1
160 #define STOP 0
162 #define POLL_GO_BIT_INTERVAL 5 /* 5 ms */
163 #define POLL_GO_BIT_RETRY 20 /* 50 times */
165 enum actuator_type {
166 ERM,
167 LRA
168 };
170 enum loop_type {
171 CLOSE_LOOP,
172 OPEN_LOOP
173 };
175 struct actuator_data {
176 unsigned char mnActuatorType;
177 unsigned char mnRatedVoltage;
178 unsigned char mnOverDriveClampVoltage;
179 unsigned char mnLRAFreq;
180 };
182 enum wave_seq_loop {
183 SEQ_NO_LOOP,
184 SEQ_LOOP_ONCE,
185 SEQ_LOOP_TWICE,
186 SEQ_LOOP_TRIPPLE
187 };
189 enum wave_main_loop {
190 MAIN_NO_LOOP,
191 MAIN_LOOP_ONCE,
192 MAIN_LOOP_TWICE,
193 MAIN_LOOP_3_TIMES,
194 MAIN_LOOP_4_TIMES,
195 MAIN_LOOP_5_TIMES,
196 MAIN_LOOP_6_TIMES,
197 MAIN_LOOP_INFINITELY
198 };
200 enum wave_main_scale {
201 PERCENTAGE_100,
202 PERCENTAGE_75,
203 PERCENTAGE_50,
204 PERCENTAGE_25
205 };
207 enum wave_main_interval {
208 INTERVAL_5MS,
209 INTERVAL_1MS
210 };
212 struct drv2624_waveform {
213 unsigned char mnEffect;
214 unsigned char mnLoop;
215 };
217 struct drv2624_waveform_sequencer {
218 struct drv2624_waveform msWaveform[DRV2624_SEQUENCER_SIZE];
219 };
221 struct drv2624_wave_setting {
222 unsigned char mnLoop;
223 unsigned char mnInterval;
224 unsigned char mnScale;
225 };
227 struct drv2624_autocal_result {
228 int mnFinished;
229 unsigned char mnResult;
230 unsigned char mnCalComp;
231 unsigned char mnCalBemf;
232 unsigned char mnCalGain;
233 };
235 struct drv2624_diag_result {
236 int mnFinished;
237 unsigned char mnResult;
238 unsigned char mnDiagZ;
239 unsigned char mnDiagK;
240 };
242 struct drv2624_platform_data {
243 int mnGpioNRST;
244 int mnGpioINT;
245 unsigned char mnLoop;
246 struct actuator_data msActuator;
247 };
249 struct drv2624_fw_header{
250 int fw_magic;
251 int fw_size;
252 int fw_date;
253 int fw_chksum;
254 int fw_effCount;
255 };
257 #define DRV2624_MAGIC 0x2624
259 struct drv2624_data {
260 struct drv2624_platform_data msPlatData;
261 struct mutex dev_lock;
262 unsigned char mnDeviceID;
263 struct device *dev;
264 struct regmap *mpRegmap;
265 unsigned int mnIRQ;
266 unsigned char mnIntStatus;
267 bool mbIRQEnabled;
268 bool mbIRQUsed;
269 struct drv2624_wave_setting msWaveformSetting;
270 struct drv2624_waveform_sequencer msWaveformSequencer;
271 unsigned char mnFileCmd;
272 volatile int mnVibratorPlaying;
273 volatile char mnWorkMode;
274 unsigned char mnCurrentReg;
275 struct wake_lock wklock;
276 struct hrtimer timer;
277 struct mutex lock;
278 struct work_struct vibrator_work;
279 struct timed_output_dev to_dev;
281 struct drv2624_autocal_result mAutoCalResult;
282 struct drv2624_diag_result mDiagResult;
284 struct drv2624_fw_header fw_header;
285 unsigned char mRAMLSB;
286 unsigned char mRAMMSB;
287 };
289 #define DRV2624_MAGIC_NUMBER 0x32363234 /* '2624' */
291 #define DRV2624_WAVSEQ_PLAY _IOWR(DRV2624_MAGIC_NUMBER, 4, unsigned long)
292 #define DRV2624_STOP _IOWR(DRV2624_MAGIC_NUMBER, 5, unsigned long)
293 #define DRV2624_RUN_DIAGNOSTIC _IOWR(DRV2624_MAGIC_NUMBER, 6, unsigned long)
294 #define DRV2624_GET_DIAGRESULT _IOWR(DRV2624_MAGIC_NUMBER, 7, struct drv2624_diag_result *)
295 #define DRV2624_RUN_AUTOCAL _IOWR(DRV2624_MAGIC_NUMBER, 8, unsigned long)
296 #define DRV2624_GET_CALRESULT _IOWR(DRV2624_MAGIC_NUMBER, 9, struct drv2624_autocal_result *)
298 #endif