]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - drv262xsw-android/drv2625-android-driver.git/blob - drv2625.h
2c9affede4c5f79c384cea5bb0534cd3bafc9ce7
[drv262xsw-android/drv2625-android-driver.git] / drv2625.h
1 #ifndef __DRV2625_H__
2 #define __DRV2625_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 **     drv2625.h
23 **
24 ** Description:
25 **     Header file for drv2625.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>
39 #define HAPTICS_DEVICE_NAME "drv2625"
41 #define DRV2625_REG_ID                          0x00
42 #define DRV2625_ID                                      (0x12&0xf0)
44 #define DRV2625_REG_STATUS                      0x01
45 #define DIAG_MASK                                       0x80
46 #define DIAG_SUCCESS                            0x00
47 #define DIAG_SHIFT                                      0x07
48 #define INT_MASK                                        0x1f
49 #define PRG_ERR_MASK                            0x10
50 #define PROCESS_DONE_MASK                       0x08
51 #define ULVO_MASK                                       0x04
52 #define OVERTEMPRATURE_MASK                     0x02
53 #define OVERCURRENT_MASK                        0x01
55 #define DRV2625_REG_INT_ENABLE          0x02
56 #define INT_MASK_ALL                            0x1f
57 #define INT_ENABLE_ALL                          0x00
58 #define INT_ENABLE_CRITICAL                     0x08
60 #define DRV2625_REG_DIAG_Z                      0x03
62 #define DRV2625_REG_MODE                        0x07
63 #define WORKMODE_MASK                           0x03
64 #define MODE_RTP                                        0x00
65 #define MODE_WAVEFORM_SEQUENCER         0x01
66 #define MODE_DIAGNOSTIC                         0x02
67 #define MODE_CALIBRATION                        0x03
68 #define PINFUNC_MASK                            0x0c
69 #define PINFUNC_INT                                     0x02
70 #define PINFUNC_SHIFT                           0x02
72 #define DRV2625_REG_CONTROL1            0x08
73 #define ACTUATOR_MASK                           0x80
74 #define ACTUATOR_SHIFT                          7
75 #define LOOP_MASK                                       0x40
76 #define LOOP_SHIFT                                      6
77 #define AUTOBRK_OK_MASK                         0x10
78 #define AUTOBRK_OK_ENABLE                       0x10
80 #define DRV2625_REG_GO                          0x0c
82 #define DRV2625_REG_CONTROL2            0x0d
83 #define LIB_LRA                                         0x00
84 #define LIB_ERM                                         0x01
85 #define LIB_MASK                                        0x80
86 #define LIB_SHIFT                                       0x07
87 #define SCALE_MASK                                      0x03
88 #define INTERVAL_MASK                           0x20
89 #define INTERVAL_SHIFT                          0x05
91 #define DRV2625_REG_RTP_INPUT           0x0e
93 #define DRV2625_REG_SEQUENCER_1         0x0f
95 #define DRV2625_REG_SEQ_LOOP_1          0x17
97 #define DRV2625_REG_SEQ_LOOP_2          0x18
99 #define DRV2625_REG_MAIN_LOOP           0x19
101 #define DRV2625_REG_RATED_VOLTAGE       0x1f
103 #define DRV2625_REG_OVERDRIVE_CLAMP     0x20
105 #define DRV2625_REG_CAL_COMP            0x21
107 #define DRV2625_REG_CAL_BEMF            0x22
109 #define DRV2625_REG_LOOP_CONTROL        0x23
110 #define BEMFGAIN_MASK                           0x03
112 #define DRV2625_REG_DRIVE_TIME          0x27
113 #define DRIVE_TIME_MASK                         0x1f
114 #define MINFREQ_SEL_45HZ                        0x01
115 #define MINFREQ_SEL_MASK                        0x80
116 #define MINFREQ_SEL_SHIFT                       0x07
118 #define DRV2625_REG_OL_PERIOD_H         0x2e
120 #define DRV2625_REG_OL_PERIOD_L         0x2f
122 #define DRV2625_REG_DIAG_K                      0x30
124 #define GO_BIT_POLL_INTERVAL    15
125 #define STANDBY_WAKE_DELAY      1
126 #define WAKE_STANDBY_DELAY      3
128 /* Commands */
129 #define HAPTIC_CMDID_PLAY_SINGLE_EFFECT     0x01
130 #define HAPTIC_CMDID_PLAY_EFFECT_SEQUENCE   0x02
131 #define HAPTIC_CMDID_PLAY_TIMED_EFFECT      0x03
132 #define HAPTIC_CMDID_GET_DEV_ID             0x04
133 #define HAPTIC_CMDID_RUN_DIAG               0x05
134 #define HAPTIC_CMDID_AUDIOHAPTIC_ENABLE     0x06
135 #define HAPTIC_CMDID_AUDIOHAPTIC_DISABLE    0x07
136 #define HAPTIC_CMDID_AUDIOHAPTIC_GETSTATUS  0x08
138 #define HAPTIC_CMDID_REG_WRITE          0x09
139 #define HAPTIC_CMDID_REG_READ           0x0a
140 #define HAPTIC_CMDID_REG_SETBIT         0x0b
142 #define HAPTIC_CMDID_PATTERN_RTP      0x0c
143 #define HAPTIC_CMDID_RTP_SEQUENCE         0x0d
144 #define HAPTIC_CMDID_GET_EFFECT_COUNT           0x10
145 #define HAPTIC_CMDID_UPDATE_FIRMWARE            0x11
146 #define HAPTIC_CMDID_READ_FIRMWARE                      0x12
147 #define HAPTIC_CMDID_RUN_CALIBRATION        0x13
148 #define HAPTIC_CMDID_CONFIG_WAVEFORM            0x14
149 #define HAPTIC_CMDID_SET_SEQUENCER                      0x15
151 #define HAPTIC_CMDID_STOP                   0xFF
153 #define MAX_TIMEOUT     10000 /* 10s */
154 #define MAX_READ_BYTES  0xff
155 #define DRV2625_SEQUENCER_SIZE  8
157 #define WORK_IDLE                                       0
158 #define WORK_VIBRATOR                           0x01
159 #define WORK_IRQ                                        0x02
161 #define YES             1
162 #define NO              0
163 #define GO              1
164 #define STOP    0
167 enum actuator_type {
168         ERM,
169         LRA
170 };
172 enum loop_type {
173         CLOSE_LOOP,
174         OPEN_LOOP
175 };
177 struct actuator_data {
178         unsigned char mnActuatorType;
179         unsigned char mnRatedVoltage;
180         unsigned char mnOverDriveClampVoltage;
181         unsigned char mnLRAFreq;        
182 };
184 enum wave_seq_loop {
185         SEQ_NO_LOOP,
186         SEQ_LOOP_ONCE,
187         SEQ_LOOP_TWICE,
188         SEQ_LOOP_TRIPPLE
189 };
191 enum wave_main_loop {
192         MAIN_NO_LOOP,
193         MAIN_LOOP_ONCE,
194         MAIN_LOOP_TWICE,
195         MAIN_LOOP_3_TIMES,
196         MAIN_LOOP_4_TIMES,
197         MAIN_LOOP_5_TIMES,
198         MAIN_LOOP_6_TIMES,
199         MAIN_LOOP_INFINITELY
200 };
202 enum wave_main_scale {
203         PERCENTAGE_100,
204         PERCENTAGE_75,
205         PERCENTAGE_50,
206         PERCENTAGE_25
207 };
209 enum wave_main_interval {
210         INTERVAL_5MS,
211         INTERVAL_1MS
212 };
214 struct drv2625_waveform {
215         unsigned char mnEffect;
216         unsigned char mnLoop;   
217 };
219 struct drv2625_waveform_sequencer {
220         struct drv2625_waveform msWaveform[DRV2625_SEQUENCER_SIZE];
221 };
223 struct drv2625_wave_setting {
224         unsigned char mnLoop;
225         unsigned char mnInterval;
226         unsigned char mnScale;  
227 };
229 struct drv2625_autocal_result {
230         int mnFinished;
231         unsigned char mnResult;
232         unsigned char mnCalComp;
233         unsigned char mnCalBemf;
234         unsigned char mnCalGain;
235 };
237 struct drv2625_diag_result {
238         int mnFinished;
239         unsigned char mnResult;
240         unsigned char mnDiagZ;
241         unsigned char mnDiagK;
242 };
244 struct drv2625_platform_data {
245         int     mnGpioNRST;
246         int     mnGpioINT;
247         unsigned char mnLoop; 
248         struct actuator_data msActuator;
249 };
251 struct drv2625_data {
252         struct drv2625_platform_data msPlatData;
253         unsigned char mnDeviceID;
254         struct device *dev;
255         struct regmap *mpRegmap;
256         unsigned int mnIRQ;
257         unsigned char mnIntStatus;
258         struct drv2625_wave_setting msWaveformSetting;
259         struct drv2625_waveform_sequencer msWaveformSequencer;  
260         unsigned char mnFileCmd;
261         volatile int mnVibratorPlaying;
262         volatile char mnWorkMode;
263         unsigned char mnCurrentReg;
264     struct wake_lock wklock;
265     struct hrtimer timer;
266     struct mutex lock;
267     struct work_struct vibrator_work;
268         struct timed_output_dev to_dev; 
269         
270         struct drv2625_autocal_result mAutoCalResult;
271         struct drv2625_diag_result mDiagResult;
272 };
274 #define DRV2625_MAGIC_NUMBER    0x32363235      /* '2625' */
278 #define DRV2625_WAVSEQ_PLAY                                     _IOWR(DRV2625_MAGIC_NUMBER, 4, unsigned long)
279 #define DRV2625_STOP                                            _IOWR(DRV2625_MAGIC_NUMBER, 5, unsigned long)
280 #define DRV2625_RUN_DIAGNOSTIC                          _IOWR(DRV2625_MAGIC_NUMBER, 6, unsigned long)
281 #define DRV2625_GET_DIAGRESULT                          _IOWR(DRV2625_MAGIC_NUMBER, 7, struct drv2625_diag_result *)
282 #define DRV2625_RUN_AUTOCAL                                     _IOWR(DRV2625_MAGIC_NUMBER, 8, unsigned long)
283 #define DRV2625_GET_CALRESULT                           _IOWR(DRV2625_MAGIC_NUMBER, 9, struct drv2625_autocal_result *)
286 #endif