first commit
[drv262xsw-android/drv2624-android-driver.git] / drv2624.h
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
94 #define DRV2624_REG_SEQUENCER_1         0x0f
96 #define DRV2624_REG_SEQ_LOOP_1          0x17
98 #define DRV2624_REG_SEQ_LOOP_2          0x18
100 #define DRV2624_REG_MAIN_LOOP           0x19
102 #define DRV2624_REG_RATED_VOLTAGE       0x1f
104 #define DRV2624_REG_OVERDRIVE_CLAMP     0x20
106 #define DRV2624_REG_CAL_COMP            0x21
108 #define DRV2624_REG_CAL_BEMF            0x22
110 #define DRV2624_REG_LOOP_CONTROL        0x23
111 #define BEMFGAIN_MASK                           0x03
113 #define DRV2624_REG_DRIVE_TIME          0x27
114 #define DRIVE_TIME_MASK                         0x1f
115 #define MINFREQ_SEL_45HZ                        0x01
116 #define MINFREQ_SEL_MASK                        0x80
117 #define MINFREQ_SEL_SHIFT                       0x07
119 #define DRV2624_REG_OL_PERIOD_H         0x2e
121 #define DRV2624_REG_OL_PERIOD_L         0x2f
123 #define DRV2624_REG_DIAG_K                      0x30
125 #define GO_BIT_POLL_INTERVAL    15
126 #define STANDBY_WAKE_DELAY      1
127 #define WAKE_STANDBY_DELAY      3
129 #define DRV2624_REG_RAM_ADDR_UPPER      0xfd
130 #define DRV2624_REG_RAM_ADDR_LOWER      0xfe
131 #define DRV2624_REG_RAM_DATA                    0xff
133 /* Commands */
134 #define HAPTIC_CMDID_PLAY_SINGLE_EFFECT     0x01
135 #define HAPTIC_CMDID_PLAY_EFFECT_SEQUENCE   0x02
136 #define HAPTIC_CMDID_PLAY_TIMED_EFFECT      0x03
137 #define HAPTIC_CMDID_GET_DEV_ID             0x04
138 #define HAPTIC_CMDID_RUN_DIAG               0x05
139 #define HAPTIC_CMDID_AUDIOHAPTIC_ENABLE     0x06
140 #define HAPTIC_CMDID_AUDIOHAPTIC_DISABLE    0x07
141 #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
147 #define HAPTIC_CMDID_PATTERN_RTP      0x0c
148 #define HAPTIC_CMDID_RTP_SEQUENCE         0x0d
149 #define HAPTIC_CMDID_GET_EFFECT_COUNT           0x10
150 #define HAPTIC_CMDID_UPDATE_FIRMWARE            0x11
151 #define HAPTIC_CMDID_READ_FIRMWARE                      0x12
152 #define HAPTIC_CMDID_RUN_CALIBRATION        0x13
153 #define HAPTIC_CMDID_CONFIG_WAVEFORM            0x14
154 #define HAPTIC_CMDID_SET_SEQUENCER                      0x15
156 #define HAPTIC_CMDID_STOP                   0xFF
158 #define MAX_TIMEOUT     10000 /* 10s */
159 #define MAX_READ_BYTES  0xff
160 #define DRV2624_SEQUENCER_SIZE  8
162 #define WORK_IDLE                                       0
163 #define WORK_VIBRATOR                           0x01
164 #define WORK_IRQ                                        0x02
166 #define YES             1
167 #define NO              0
168 #define GO              1
169 #define STOP    0
172 enum actuator_type {
173         ERM,
174         LRA
175 };
177 enum loop_type {
178         CLOSE_LOOP,
179         OPEN_LOOP
180 };
182 struct actuator_data {
183         unsigned char mnActuatorType;
184         unsigned char mnRatedVoltage;
185         unsigned char mnOverDriveClampVoltage;
186         unsigned char mnLRAFreq;        
187 };
189 enum wave_seq_loop {
190         SEQ_NO_LOOP,
191         SEQ_LOOP_ONCE,
192         SEQ_LOOP_TWICE,
193         SEQ_LOOP_TRIPPLE
194 };
196 enum wave_main_loop {
197         MAIN_NO_LOOP,
198         MAIN_LOOP_ONCE,
199         MAIN_LOOP_TWICE,
200         MAIN_LOOP_3_TIMES,
201         MAIN_LOOP_4_TIMES,
202         MAIN_LOOP_5_TIMES,
203         MAIN_LOOP_6_TIMES,
204         MAIN_LOOP_INFINITELY
205 };
207 enum wave_main_scale {
208         PERCENTAGE_100,
209         PERCENTAGE_75,
210         PERCENTAGE_50,
211         PERCENTAGE_25
212 };
214 enum wave_main_interval {
215         INTERVAL_5MS,
216         INTERVAL_1MS
217 };
219 struct drv2624_waveform {
220         unsigned char mnEffect;
221         unsigned char mnLoop;   
222 };
224 struct drv2624_waveform_sequencer {
225         struct drv2624_waveform msWaveform[DRV2624_SEQUENCER_SIZE];
226 };
228 struct drv2624_wave_setting {
229         unsigned char mnLoop;
230         unsigned char mnInterval;
231         unsigned char mnScale;  
232 };
234 struct drv2624_autocal_result {
235         int mnFinished;
236         unsigned char mnResult;
237         unsigned char mnCalComp;
238         unsigned char mnCalBemf;
239         unsigned char mnCalGain;
240 };
242 struct drv2624_diag_result {
243         int mnFinished;
244         unsigned char mnResult;
245         unsigned char mnDiagZ;
246         unsigned char mnDiagK;
247 };
249 struct drv2624_platform_data {
250         int     mnGpioNRST;
251         int     mnGpioINT;
252         unsigned char mnLoop; 
253         struct actuator_data msActuator;
254 };
256 struct drv2624_fw_header{
257         int fw_magic;
258         int fw_size;
259         int fw_date;
260         int fw_chksum;
261         int fw_effCount;
262 };
264 #define DRV2624_MAGIC   0x2624
266 struct drv2624_data {
267         struct drv2624_platform_data msPlatData;
268         struct mutex dev_lock;  
269         unsigned char mnDeviceID;
270         struct device *dev;
271         struct regmap *mpRegmap;
272         unsigned int mnIRQ;
273         unsigned char mnIntStatus;
274         struct drv2624_wave_setting msWaveformSetting;
275         struct drv2624_waveform_sequencer msWaveformSequencer;  
276         unsigned char mnFileCmd;
277         volatile int mnVibratorPlaying;
278         volatile char mnWorkMode;
279         unsigned char mnCurrentReg;
280     struct wake_lock wklock;
281     struct hrtimer timer;
282     struct mutex lock;
283     struct work_struct vibrator_work;
284         struct timed_output_dev to_dev; 
285         
286         struct drv2624_autocal_result mAutoCalResult;
287         struct drv2624_diag_result mDiagResult;
288         
289         struct drv2624_fw_header fw_header;
290         unsigned char mRAMLSB;
291         unsigned char mRAMMSB;
292 };
294 #define DRV2624_MAGIC_NUMBER    0x32363234      /* '2624' */
298 #define DRV2624_WAVSEQ_PLAY                                     _IOWR(DRV2624_MAGIC_NUMBER, 4, unsigned long)
299 #define DRV2624_STOP                                            _IOWR(DRV2624_MAGIC_NUMBER, 5, unsigned long)
300 #define DRV2624_RUN_DIAGNOSTIC                          _IOWR(DRV2624_MAGIC_NUMBER, 6, unsigned long)
301 #define DRV2624_GET_DIAGRESULT                          _IOWR(DRV2624_MAGIC_NUMBER, 7, struct drv2624_diag_result *)
302 #define DRV2624_RUN_AUTOCAL                                     _IOWR(DRV2624_MAGIC_NUMBER, 8, unsigned long)
303 #define DRV2624_GET_CALRESULT                           _IOWR(DRV2624_MAGIC_NUMBER, 9, struct drv2624_autocal_result *)
306 #endif