audio: Add License info for tfa9887 driver.
[linux-3.10.git] / include / linux / tfa9887.h
1 /*
2  * include/linux/tfa9887.h
3  *
4  * Copyright (c) 2013, NVIDIA CORPORATION.  All rights reserved.
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16
17 #ifndef __LINUX_TFA9887_H
18 #define __LINUX_TFA9887_H
19
20 #define IN_HAND_MODE 2
21 #define ON_DESK_MODE 1
22 #define DB_CUTOFF_INDEX 12
23 #define MAX_DB_INDEX 15
24 #define PRESET_DEFAULT 4
25 struct tfa9887_priv {
26         struct regmap *regmap;
27         int irq;
28         bool deviceInit;
29         struct mutex lock;
30 };
31
32 typedef enum Tfa9887_Mute {
33         Tfa9887_Mute_Off,
34         Tfa9887_Mute_Digital,
35         Tfa9887_Mute_Amplifier
36 } Tfa9887_Mute_t;
37
38
39 int Tfa9887_Powerdown(int powerdown);
40
41 int Powerdown(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, int powerdown);
42
43 int Tfa9887_WriteRegister(struct tfa9887_priv *tfa9887, unsigned int subaddress, unsigned int value);
44
45 int Tfa9887_ReadRegister(struct tfa9887_priv *tfa9887, unsigned int subaddress, unsigned int *pValue);
46
47 int Tfa9887_Init(int sRate);
48
49 int Init(struct tfa9887_priv *tfa9887,struct tfa9887_priv *tfa9887_byte, int sRate);
50
51 int Tfa9887_ReadRegister(struct tfa9887_priv *tfa9887, unsigned int subaddress, unsigned int *pValue);
52
53 int Tfa9887_WriteRegister(struct tfa9887_priv *tfa9887, unsigned int subaddress, unsigned int value);
54
55 int ProcessPatchFile(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, int length, const unsigned char *bytes);
56
57 int DspSetParam(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, unsigned char module_id, unsigned char param_id, int num_bytes, const unsigned char *data);
58
59 int DspGetParam(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, unsigned char module_id, unsigned char param_id, int num_bytes, unsigned char *data);
60 int DspWriteMem(struct tfa9887_priv *tfa9887, unsigned int address, int value);
61
62 int DspReadMem(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, unsigned short start_offset, int num_words, int *pValues);
63
64 int coldStartup(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, int sRate);
65
66 int loadSettings(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte);
67
68 int stereoRouting(struct tfa9887_priv *tfa9887);
69
70 int Tfa9887_SetEq(void);
71
72 int SetEq(struct tfa9887_priv *tfa9887,struct tfa9887_priv *tfa9887_byte);
73
74 int Tfa9887_SetPreset(unsigned int preset);
75
76 int SetPreset(struct tfa9887_priv *tfa9887,struct tfa9887_priv *tfa9887_byte);
77
78 int SetMute(struct tfa9887_priv *tfa9887, Tfa9887_Mute_t mute);
79
80 void calibrate (struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, char *calibdata);
81
82 void recalibrate(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte);
83
84 void resetMtpEx(struct tfa9887_priv *tfa9887);
85
86 int checkMTPEX(struct tfa9887_priv *tfa9887);
87
88 void setOtc(struct tfa9887_priv *tfa9887, unsigned short otcOn);
89
90 typedef enum Tfa9887_AmpInputSel {
91         Tfa9887_AmpInputSel_I2SLeft,
92         Tfa9887_AmpInputSel_I2SRight,
93         Tfa9887_AmpInputSel_DSP
94 } Tfa9887_AmpInputSel_t;
95
96 typedef enum Tfa9887_OutputSel {
97         Tfa9887_I2SOutputSel_CurrentSense,
98         Tfa9887_I2SOutputSel_DSP_Gain,
99         Tfa9887_I2SOutputSel_DSP_AEC,
100         Tfa9887_I2SOutputSel_Amp,
101         Tfa9887_I2SOutputSel_DataI3R,
102         Tfa9887_I2SOutputSel_DataI3L,
103         Tfa9887_I2SOutputSel_DcdcFFwdCur,
104 } Tfa9887_OutputSel_t;
105
106 typedef enum Tfa9887_StereoGainSel {
107         Tfa9887_StereoGainSel_Left,
108         Tfa9887_StereoGainSel_Right
109 } Tfa9887_StereoGainSel_t;
110
111 #define TFA9887_SPEAKERPARAMETER_LENGTH 423
112 typedef unsigned char Tfa9887_SpeakerParameters_t[TFA9887_SPEAKERPARAMETER_LENGTH];
113
114 #define TFA9887_CONFIG_LENGTH 165
115 typedef unsigned char Tfa9887_Config_t[TFA9887_CONFIG_LENGTH];
116
117 #define TFA9887_PRESET_LENGTH    87
118 typedef unsigned char Tfa9887_Preset_t[TFA9887_PRESET_LENGTH];
119
120 #define TFA9887_MAXPATCH_LENGTH (3*1024)
121
122
123 /* the number of biquads supported */
124 #define TFA9887_BIQUAD_NUM              10
125
126 #define Tfa9887_Error_Ok        0
127
128 typedef enum Tfa9887_SpeakerType {
129         Tfa9887_Speaker_FreeSpeaker=0,
130         Tfa9887_Speaker_RA11x15,
131         Tfa9887_Speaker_RA13x18,
132         Tfa9887_Speaker_RA9x13,
133
134         Tfa9887_Speaker_Max
135
136 } Tfa9887_SpeakerType_t;
137
138
139 typedef enum Tfa9887_Channel {
140         Tfa9887_Channel_L,
141         Tfa9887_Channel_R,
142         Tfa9887_Channel_L_R,
143         Tfa9887_Channel_Stereo
144 } Tfa9887_Channel_t;
145
146
147
148 typedef enum Tfa9887_SpeakerBoostStatusFlags
149 {
150         Tfa9887_SpeakerBoost_Activity=0         ,               /* Input signal activity. */
151         Tfa9887_SpeakerBoost_S_Ctrl                             ,               /* S Control triggers the limiter */
152         Tfa9887_SpeakerBoost_Muted                        ,             /* 1 when signal is muted */
153         Tfa9887_SpeakerBoost_X_Ctrl                     ,               /* X Control triggers the limiter */
154         Tfa9887_SpeakerBoost_T_Ctrl                     ,               /* T Control triggers the limiter */
155         Tfa9887_SpeakerBoost_NewModel                   ,               /* New model is available */
156         Tfa9887_SpeakerBoost_VolumeRdy          ,               /* 0 means stable volume, 1 means volume is still smoothing */
157         Tfa9887_SpeakerBoost_Damaged                    ,               /* Speaker Damage detected  */
158         Tfa9887_SpeakerBoost_SignalClipping             /* Input Signal clipping detected */
159 } Tfa9887_SpeakerBoostStatusFlags_t ;
160
161 typedef struct Tfa9887_SpeakerBoost_StateInfo
162 {
163         float   agcGain;                        /* Current AGC Gain value */
164         float   limGain;                        /* Current Limiter Gain value */
165         float   sMax;                             /* Current Clip/Lim threshold */
166         int             T;                                        /* Current Speaker Temperature value */
167         int       statusFlag;           /* Masked bit word, see Tfa9887_SpeakerBoostStatusFlags */
168         float   X1;                                       /* Current estimated Excursion value caused by Speakerboost gain control */
169         float   X2;                                       /* Current estimated Excursion value caused by manual gain setting */
170         float Re;           /* Current Loudspeaker blocked resistance */
171 } Tfa9887_SpeakerBoost_StateInfo_t;
172
173 typedef unsigned char subaddress_t;
174
175 #define TFA9887_I2S_CONTROL    (subaddress_t)0x04
176 #define TFA9887_AUDIO_CONTROL  (subaddress_t)0x06
177 #define TFA9887_SYSTEM_CONTROL (subaddress_t)0x09
178 #define TFA9887_I2S_SEL        (subaddress_t)0x0A
179 //#define TFA9887_CF_CONTROLS    (subaddress_t)0x70 //TODO cleanup reg defs
180 //#define TFA9887_CF_MAD         (subaddress_t)0x71
181 //#define TFA9887_CF_MEM         (subaddress_t)0x72
182 //#define TFA9887_CF_STATUS      (subaddress_t)0x73
183
184
185 /* REVISION values */
186 #define TFA9887_REV_N1C       0x11
187 #define TFA9887_REV_N1D       0x12
188
189
190 /* I2S_CONTROL bits */
191 #define TFA9887_I2SCTRL_RATE_SHIFT (12)
192 #define TFA9887_I2SCTRL_RATE_08000 (0<<TFA9887_I2SCTRL_RATE_SHIFT)
193 #define TFA9887_I2SCTRL_RATE_11025 (1<<TFA9887_I2SCTRL_RATE_SHIFT)
194 #define TFA9887_I2SCTRL_RATE_12000 (2<<TFA9887_I2SCTRL_RATE_SHIFT)
195 #define TFA9887_I2SCTRL_RATE_16000 (3<<TFA9887_I2SCTRL_RATE_SHIFT)
196 #define TFA9887_I2SCTRL_RATE_22050 (4<<TFA9887_I2SCTRL_RATE_SHIFT)
197 #define TFA9887_I2SCTRL_RATE_24000 (5<<TFA9887_I2SCTRL_RATE_SHIFT)
198 #define TFA9887_I2SCTRL_RATE_32000 (6<<TFA9887_I2SCTRL_RATE_SHIFT)
199 #define TFA9887_I2SCTRL_RATE_44100 (7<<TFA9887_I2SCTRL_RATE_SHIFT)
200 #define TFA9887_I2SCTRL_RATE_48000 (8<<TFA9887_I2SCTRL_RATE_SHIFT)
201
202 #define TFA9887_I2SCTRL_CHANSEL_SHIFT      3
203 #define TFA9887_I2SCTRL_INPUT_SEL_SHIFT    6
204
205 #define TFA9887_I2SCTRL_DATAI2_SHIFT      5
206
207 #define TFA9887_I2SSEL_I2SOUT_LEFT_SHIFT  0
208 #define TFA9887_I2SSEL_I2SOUT_RIGHT_SHIFT 3
209
210
211 /* SYSTEM CONTROL bits */
212 #define TFA9887_SYSCTRL_POWERDOWN    (1<<0)
213 #define TFA9887_SYSCTRL_RESETI2C     (1<<1)
214 #define TFA9887_SYSCTRL_ENBL_AMP     (1<<3)
215 #define TFA9887_SYSCTRL_CONFIGURED   (1<<5)
216 #define TFA9887_SYSCTRL_SEL_ENBL_AMP (1<<6)
217
218 /* Audio control bits */
219 #define TFA9887_AUDIOCTRL_MUTE       (1<<5)
220
221 /* modules */
222 #define MODULE_SPEAKERBOOST  1
223
224 /* RPC commands */
225 #define PARAM_SET_LSMODEL        0x06  // Load a full model into SpeakerBoost.
226 #define PARAM_SET_LSMODEL_SEL    0x07  // Select one of the default models present in Tfa9887 ROM.
227 #define PARAM_SET_EQ                     0x0A  // 2 Equaliser Filters.
228 #define PARAM_SET_PRESET         0x0D  // Load a preset
229 #define PARAM_SET_CONFIG                 0x0E  // Load a config
230
231 #define PARAM_GET_RE0            0x85  /* gets the speaker calibration impedance (@25 degrees celsius) */
232 #define PARAM_GET_LSMODEL        0x86  // Gets current LoudSpeaker Model.
233 #define PARAM_GET_STATE                                  0xC0
234
235 /* RPC Status results */
236 #define STATUS_OK                  0
237 #define STATUS_INVALID_MODULE_ID   2
238 #define STATUS_INVALID_PARAM_ID    3
239 #define STATUS_INVALID_INFO_ID     4
240
241
242 /* the maximum message length in the communication with the DSP */
243 #define MAX_PARAM_SIZE (145*3)
244
245 #define MIN(a,b) ((a)<(b)?(a):(b))
246 #define ROUND_DOWN(a,n) (((a)/(n))*(n))
247
248 /* maximum number of bytes in 1 I2C write transaction */
249 #define MAX_I2C_LENGTH                  254
250
251 #define TFA9887_CF_RESET  1
252 /* possible memory values for DMEM in CF_CONTROLs */
253 typedef enum {
254         Tfa9887_DMEM_PMEM=0,
255         Tfa9887_DMEM_XMEM=1,
256         Tfa9887_DMEM_YMEM=2,
257         Tfa9887_DMEM_IOMEM=3,
258 } Tfa9887_DMEM_e;
259
260
261 #define MODULE_BIQUADFILTERBANK 2
262 #define BIQUAD_PARAM_SET_COEFF  1
263 #define BIQUAD_COEFF_SIZE       6
264
265 #define EQ_COEFF_SIZE           7
266
267 /* the number of elements in Tfa9887_SpeakerBoost_StateInfo */
268 #define STATE_SIZE             8
269
270 #define SPKRBST_HEADROOM                         7                                                                              /* Headroom applied to the main input signal */
271 #define SPKRBST_AGCGAIN_EXP                     SPKRBST_HEADROOM          /* Exponent used for AGC Gain related variables */
272 #define SPKRBST_TEMPERATURE_EXP     9
273 #define SPKRBST_LIMGAIN_EXP                         4                                        /* Exponent used for Gain Corection related variables */
274 #define SPKRBST_TIMECTE_EXP         1
275
276
277
278 //Tfa_Registers.h
279 #define TFA9887_STATUS         (unsigned int)0x00
280
281 #define TFA9887_MTP            (unsigned int)0x80
282
283 /* STATUS bits */
284 #define TFA9887_STATUS_VDDS       (1<<0) /*  */
285 #define TFA9887_STATUS_PLLS       (1<<1) /* plls locked */
286 #define TFA9887_STATUS_OTDS       (1<<2) /*  */
287 #define TFA9887_STATUS_OVDS       (1<<3) /*  */
288 #define TFA9887_STATUS_UVDS       (1<<4) /*  */
289 #define TFA9887_STATUS_OCDS       (1<<5) /*  */
290 #define TFA9887_STATUS_CLKS       (1<<6) /* clocks stable */
291 //
292 //
293 #define TFA9887_STATUS_MTPB     (1<<8) /*MTP busy operation*/
294 #define TFA9887_STATUS_DCCS       (1<<9) /*  */
295
296 #define TFA9887_STATUS_ACS        (1<<11) /* cold started */
297 #define TFA9887_STATUS_SWS        (1<<12) /* amplifier switching */
298
299 /* MTP bits */
300 #define TFA9887_MTP_MTPOTC        (1<<0)  /* one time calibration */
301 #define TFA9887_MTP_MTPEX         (1<<1)  /* one time calibration done */
302
303 /*
304  * generated defines
305  */
306 #define TFA9887_STATUSREG (0x00)
307 #define TFA9887_BATTERYVOLTAGE (0x01)
308 #define TFA9887_TEMPERATURE (0x02)
309 #define TFA9887_I2SREG (0x04)
310 #define TFA9887_BAT_PROT (0x05)
311 #define TFA9887_AUDIO_CTR (0x06)
312 #define TFA9887_DCDCBOOST (0x07)
313 #define TFA9887_SPKR_CALIBRATION (0x08)
314 #define TFA9887_SYS_CTRL (0x09)
315 #define TFA9887_I2S_SEL_REG (0x0a)
316 #define TFA9887_REVISIONNUMBER (0x03)
317 #define TFA9887_HIDE_UNHIDE_KEY (0x40)
318 #define TFA9887_PWM_CONTROL (0x41)
319 #define TFA9887_CURRENTSENSE1 (0x46)
320 #define TFA9887_CURRENTSENSE2 (0x47)
321 #define TFA9887_CURRENTSENSE3 (0x48)
322 #define TFA9887_CURRENTSENSE4 (0x49)
323 #define TFA9887_ABISTTEST (0x4c)
324 #define TFA9887_RESERVE1 (0x0c)
325 #define TFA9887_MTP_COPY (0x62)
326 #define TFA9887_CF_CONTROLS (0x70)
327 #define TFA9887_CF_MAD (0x71)
328 #define TFA9887_CF_MEM (0x72)
329 #define TFA9887_CF_STATUS (0x73)
330 #define TFA9887_RESERVE2 (0x0d)
331
332 #endif