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