1 /*
2  * Copyright 2019 NXP
3  * All rights reserved.
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _FSL_TFA9896_H_
8 #define _FSL_TFA9896_H_
9 
10 #include "fsl_common.h"
11 #include "fsl_codec_i2c.h"
12 
13 /*!
14  * @addtogroup tfa9896
15  * @ingroup codec
16  * @{
17  */
18 
19 /*******************************************************************************
20  * Definitions
21  ******************************************************************************/
22 #ifdef TFA9896_DEBUG
23 #include "fsl_debug_console.h"
24 #define TFA9896_Printf DbgConsole_Printf
25 #else
26 #define TFA9896_Printf(format, args...) ((void)0)
27 #endif
28 
29 #define TFA9896_PATCH_EXTRA        6
30 #define FSL_TFA9896_DRIVER_VERSION (MAKE_VERSION(6, 0, 2))
31 
32 /*!@brief TFA I2S bit clock */
33 #define TFA_I2C_BITRATE (400000U)
34 
35 /*! @brief tfa9896 handle size */
36 #ifndef TFA9896_I2C_HANDLER_SIZE
37 #define TFA9896_I2C_HANDLER_SIZE (CODEC_I2C_MASTER_HANDLER_SIZE)
38 #endif
39 
40 #define Sleep(ms)                 usleep((ms)*1000)
41 #define TFA9896_I2C_ADDRESS_LEFT  (0x34)
42 #define TFA9896_I2C_ADDRESS_RIGHT (0x36)
43 #define TFA9896_LIVEDATA_CAPTURE
44 #define TFA1_FW_ReZ_SCALE             16384
45 #define MAX_PARAM_SIZE                (145 * 3)
46 #define TFA1_MAX_PARAM_SIZE           (145 * 3) /* TFA1 */
47 #define NXP_I2C_MAX_SIZE              254
48 #define MAX_I2C_LENGTH                NXP_I2C_MAX_SIZE
49 #define ROUND_DOWN(a, n)              (((a) / (n)) * (n))
50 #define TFA9896_API_WAITRESULT_NTRIES 30000
51 #define TFA1_BF_PWDN                  0x0900
52 /* RPC Status results */
53 #define STATUS_OK                0
54 #define STATUS_INVALID_MODULE_ID 2
55 #define STATUS_INVALID_PARAM_ID  3
56 #define STATUS_INVALID_INFO_ID   4
57 /* module Ids */
58 #define MODULE_FRAMEWORK        0
59 #define MODULE_SPEAKERBOOST     1
60 #define MODULE_BIQUADFILTERBANK 2
61 #define SB_PARAM_GET_STATE      0xC0
62 #define FW_PARAM_GET_STATE      0x84
63 /* RPC commands */
64 #define SB_PARAM_GET_RE0     0x85
65 #define SB_PARAM_SET_LSMODEL 0x06 /* Load a full model into SpeakerBoost.*/
66 #define SB_PARAM_SET_EQ      0x0A /* 2 Equaliser Filters.*/
67 #define SB_PARAM_SET_PRESET  0x0D /* Load a preset*/
68 #define SB_PARAM_SET_CONFIG  0x0E /* Load a config*/
69 #define SB_PARAM_SET_DRC     0x0F
70 #define SB_PARAM_SET_AGCINS  0x10
71 #define PARAM_GET_LSMODEL    0x86 /* Gets current LoudSpeaker impedance Model.*/
72 #define PARAM_GET_LSMODELW   0xC1 /* Gets current LoudSpeaker xcursion Model.*/
73 
74 #define FW_STATE_SIZE           9
75 #define FW_STATE_MAX_SIZE       FW_STATE_SIZE
76 #define SPKRBST_HEADROOM        7                /* Headroom applied to the main input signal */
77 #define SPKRBST_AGCGAIN_EXP     SPKRBST_HEADROOM /* Exponent used for AGC Gain related variables */
78 #define SPKRBST_TEMPERATURE_EXP 9
79 #define SPKRBST_LIMGAIN_EXP     4 /* Exponent used for Gain Corection related variables */
80 #define SPKRBST_TIMECTE_EXP     1
81 #define TFA1_BF_VOL             0x0687
82 #define TFA1_BF_ACS             0x00b0
83 #define TFA1_BF_DMEM            0x7011
84 #define TFA1_BF_MADD            0x710f
85 #define TFA1_BF_I2SDOE          0x04b0
86 #define TFA1_BF_PLLS            0x0010
87 #define TFA1_BF_SBSL            0x0950
88 #define TFA1_BF_RST             0x7000
89 #define TFA1_BF_I2CR            0x0910
90 #define TFA1_BF_AMPS            0x00e0
91 #define TFA1_BF_MTPB            0x0080
92 #define TFA1_BF_MTPK            0x0b07
93 #define TFA1_BF_SPKS            0x00a0
94 #define TFA1_BF_MTPOTC          0x8000
95 #define TFA1_BF_MTPEX           0x8010
96 #define TFA1_BF_MTP0            TFA1_BF_MTPOTC
97 #define TFA1_BF_CIMTP           0x62b0
98 #define TFA_MTPOTC_POS          0
99 #define TFA_MTPEX_POS           1
100 #ifndef MIN
101 #define MIN(A, B) (A < B ? A : B)
102 #endif //
103 #define TFA9896_CURRENTSENSE4_CTRL_CLKGATECFOFF (1 << 2)
104 #define TFA1_BF_RST                             0x7000
105 #define TFA1_BF_AREFS                           0x00f0
106 #define TFA1_BF_CLKS                            0x0060
107 #define TFA1_BF_AMPS                            0x00e0
108 #define TFA1_BF_MTPB                            0x0080
109 #ifdef ENABLE_AEC_DIRECTION
110 #define TFA1_BF_DOLS 0xa02
111 #define TFA1_BF_DORS 0xa32
112 #endif //
113 #define TFA1_BF_TDMSAMSZ           0x10a4
114 #define TFA1_BF_NBCK               0x14c3
115 #define TFA1_BF_AUDFS              0x04c3
116 #define TFA1_BF_CLIP               0x4900
117 #define TFA1_BF_CHS12              0x0431
118 #define TFA1_BF_CFE                0x0920
119 #define TFA1_BF_CHSA               0x0461
120 #define TFA1_BF_AMPC               0x0960
121 #define TFA1_BF_IPLL               0x09e0
122 #define TFA1_BF_ATTEN              0x0613
123 #define TFA1_BF_DCTRIP             0x0a04
124 #define TFA1_BF_DCPWM              0x07d0
125 #define bst_slpcmplvl              0xaa1
126 #define ignore_flag_voutcomp86     0x7e0
127 #define TFA9896_AUDIO_CTR          0x06
128 #define TFA9896_SYS_CTRL           0x09
129 #define TFA9896_CURRENTSENSE4      0x49
130 #define TFA9896_AUDIO_CTR_CFSM_MSK 0x20
131 #define TFA9896_SYS_CTRL_AMPE_MSK  0x8
132 #define TFA9896_SYS_CTRL_DCA_MSK   0x10
133 #define OPTIMIZED_RPC
134 #define PLL_READ_TRIAL 50
135 
136 /*! @brief status flag
137  *  @anchor _tfa9896_error
138  */
139 enum
140 {
141     kStatus_TFA9896_Ok              = MAKE_STATUS(kStatusGroup_Generic, 0), /*!< kStatus_TFA9896_Ok = 0,*/
142     kStatus_TFA9896_DSP_not_running = MAKE_STATUS(kStatusGroup_Generic, 1),
143     /*!< communication with the DSP failed, presumably because DSP not running  kStatus_TFA9896_DSP_not_running */
144     kStatus_TFA9896_Bad_Parameter = MAKE_STATUS(kStatusGroup_Generic, 2), /*!< kStatus_TFA9896_Bad_Parameter*/
145     kStatus_TFA9896_NotOpen =
146         MAKE_STATUS(kStatusGroup_Generic, 3), /*!< kStatus_TFA9896_NotOpen, the given handle is not open */
147     kStatus_TFA9896_OutOfHandles = MAKE_STATUS(kStatusGroup_Generic, 4), /*!< too many handles*/
148     kStatus_TFA9896_StateTimedOut =
149         MAKE_STATUS(kStatusGroup_Generic,
150                     5), /*!< the expected response did not occur within the expected time  Tfa9896_Error_StateTimedOut,
151                        the expected response did not occur within the expected time */
152     kStatus_TFA9896_RpcBase    = MAKE_STATUS(kStatusGroup_Generic, 100), /*!< kStatus_TFA9896_RpcBase = 100,*/
153     kStatus_TFA9896_RpcBusy    = MAKE_STATUS(kStatusGroup_Generic, 101), /*!< kStatus_TFA9896_RpcBusy = 101,*/
154     kStatus_TFA9896_RpcModId   = MAKE_STATUS(kStatusGroup_Generic, 102), /*!< kStatus_TFA9896_RpcModId = 102,*/
155     kStatus_TFA9896_RpcParamId = MAKE_STATUS(kStatusGroup_Generic, 103), /*!< kStatus_TFA9896_RpcParamId = 103*/
156     kStatus_TFA9896_RpcInfoId  = MAKE_STATUS(kStatusGroup_Generic, 104), /*!< kStatus_TFA9896_RpcInfoId = 104*/
157     kStatus_TFA9896_RpcNotAllowedSpeaker =
158         MAKE_STATUS(kStatusGroup_Generic, 105), /*!< kStatus_TFA9896_RpcNotAllowedSpeaker = 105*/
159     kStatus_TFA9896_Not_Implemented = MAKE_STATUS(kStatusGroup_Generic, 106), /*!< kStatus_TFA9896_Not_Implemented*/
160     kStatus_TFA9896_Not_Supported   = MAKE_STATUS(kStatusGroup_Generic, 107), /*!< kStatus_TFA9896_Not_Supported*/
161     kStatus_TFA9896_I2C_Fatal =
162         MAKE_STATUS(kStatusGroup_Generic, 108), /*!< Fatal I2C error occurred  kStatus_TFA9896_I2C_Fatal*/
163     kStatus_TFA9896_I2C_NonFatal =
164         MAKE_STATUS(kStatusGroup_Generic, 109),                     /*!< Nonfatal I2C error, and retry count reached */
165     kStatus_TFA9896_Other = MAKE_STATUS(kStatusGroup_Generic, 1000) /*!< kStatus_TFA9896_Other = 1000*/
166 };
167 
168 /*! @brief type definition */
169 typedef int int24;
170 typedef struct uint24M
171 {
172     uint8_t b[3];
173 } uint24M_t;
174 
175 /*! @brief biquadm */
176 typedef struct _tfa9896BiquadM
177 {
178     uint8_t bytes[6 * sizeof(uint24M_t)];
179 } tfa9896BiquadM_t;
180 
181 /*! @brief filter */
182 typedef struct _tfa9896FilterM
183 {
184     tfa9896BiquadM_t biquad;
185     uint8_t enabled;
186     uint8_t type; /*!< (== enum FilterTypes, assure 8bits length)*/
187     float frequency;
188     float Q;
189     float gain;
190 } tfa9896FilterM_t; /*!< 8 * float + int32 + byte == 37*/
191 
192 #ifdef SUPPORT_EXCURSION_FILTER
193 /*! @brief cont anti alias*/
194 typedef struct _tfa9896ContAntiAliasM
195 {
196     unsigned char index; /*!< index determines destination type; anti-alias, integrator,eq */
197     unsigned char type;
198     float cutOffFreq; /*!< cut off frequency*/
199     float samplingFreq;
200     float rippleDb; /*!< integrator leakage*/
201     float rolloff;
202     uint8_t bytes[5 * 3]; /*!< payload 5*24buts coeffs*/
203 } tfa9896ContAntiAliasM_t;
204 
205 /*! @brief cont integrator */
206 typedef struct _tfa9896ContIntegratorM
207 {
208     int8_t index; /*!< index determines destination type; anti-alias, integrator,eq */
209     uint8_t type;
210     float cutOffFreq; /*!< cut off frequency*/
211     float samplingFreq;
212     float leakage; /*!< integrator leakage*/
213     float reserved;
214     uint8_t bytes[5 * 3]; /*!< payload 5*24buts coeffs*/
215 } tfa9896ContIntegratorM_t;
216 
217 /*! @brief cont eqm */
218 typedef struct _tfa9896ContEqM
219 {
220     int8_t index;
221     uint8_t type;         /*!< (== enum FilterTypes, assure 8bits length)*/
222     float cutOffFreq;     /*!< cut off frequency, // range: [100.0 4000.0]*/
223     float samplingFreq;   /*!< sampling frequency*/
224     float Q;              /*!< range: [0.5 5.0]*/
225     float gainDb;         /*!< range: [-10.0 10.0]*/
226     uint8_t bytes[5 * 3]; /*!< payload 5*24buts coeffs*/
227 } tfa9896ContEqM_t;
228 
229 /*! @brief cont biquadm */
230 typedef struct _tfa9896ContBiquadM
231 {
232     /*tfaContEqM_t eq;*/
233     tfaContAntiAliasM_t aa;
234     /*tfaContIntegratorM_t in;*/
235 } tfaContBiquadM_t;
236 #endif
237 
238 /*! @brief mute dmem */
239 typedef enum _tfa9896_DMEM
240 {
241     DMEM_PMEM  = 0, /*!< pmem */
242     DMEM_XMEM  = 1, /*!< xmem */
243     DMEM_YMEM  = 2, /*!< ymem */
244     DMEM_IOMEM = 3, /*!< iomem */
245 } tfa9896_DMEM_t;
246 
247 /*! @brief mute status */
248 typedef enum _tfa9896_Mute
249 {
250     Mute_Off,
251     Mute_Digital,
252     Mute_Amplifier
253 } tfa9896_mute_t;
254 
255 /*! @brief status info live */
256 typedef struct _tfa9896_StateInfoLive
257 {
258     /* SpeakerBoost State */
259     float agcGain;  /* Current AGC Gain value */
260     float limGain;  /* Current Limiter Gain value */
261     float sMax;     /* Current Clip/Lim threshold */
262     int T;          /* Current Speaker Temperature value */
263     int statusFlag; /* Masked bit word, see TFA9896_SpeakerBoostStatusFlags */
264     float X1;       /* Current estimated Excursion value caused by Speakerboost gain control */
265     float X2;       /* Current estimated Excursion value caused by manual gain setting */
266     float Re;       /* Current Loudspeaker blocked resistance */
267     /* Framework state */
268     int shortOnMips; /* increments each time a MIPS problem is detected on the DSP, only presenton newer ICs */
269 } tfa9896_StateInfoLive_t;
270 
271 /*! @brief speaker boost status flag*/
272 typedef enum _tfa9896_SpeakerBoostStatusFlagsLive
273 {
274     tfa9896_SpeakerBoost_ActivityLive = 0,  /* Input signal activity. */
275     tfa9896_SpeakerBoost_S_CtrlLive,        /* S Control triggers the limiter */
276     tfa9896_SpeakerBoost_MutedLive,         /* 1 when signal is muted */
277     tfa9896_SpeakerBoost_X_CtrlLive,        /* X Control triggers the limiter */
278     tfa9896_SpeakerBoost_T_CtrlLive,        /* T Control triggers the limiter */
279     tfa9896_SpeakerBoost_NewModelLive,      /* New model is available */
280     tfa9896_SpeakerBoost_VolumeRdyLive,     /* 0 means stable volume, 1 means volume is still smoothing */
281     tfa9896_SpeakerBoost_DamagedLive,       /* Speaker Damage detected  */
282     tfa9896_SpeakerBoost_SignalClippingLive /* Input Signal clipping detected */
283 } tfa9896_SpeakerBoostStatusFlagsLive_t;
284 
285 /*! @brief speaker mode */
286 typedef struct _tfa9896SPKRBST_SpkrModel
287 {
288     double pFIR[128];         /* Pointer to Excurcussion  Impulse response or
289       Admittance Impulse response (reversed order!!) */
290     int Shift_FIR;            /* Exponent of HX data */
291     float leakageFactor;      /* Excursion model integration leakage */
292     float ReCorrection;       /* Correction factor for Re */
293     float xInitMargin;        /*(1)Margin on excursion model during startup */
294     float xDamageMargin;      /* Margin on excursion modelwhen damage has been detected */
295     float xMargin;            /* Margin on excursion model activated when LookaHead is 0 */
296     float Bl;                 /* Loudspeaker force factor */
297     int fRes;                 /*(1)Estimated Speaker Resonance Compensation Filter cutoff frequency */
298     int fResInit;             /* Initial Speaker Resonance Compensation Filter cutoff frequency */
299     float Qt;                 /* Speaker Resonance Compensation Filter Q-factor */
300     float xMax;               /* Maximum excursion of the speaker membrane */
301     float tMax;               /* Maximum Temperature of the speaker coil */
302     float tCoefA;             /*(1)Temperature coefficient */
303 } tfa9896SPKRBST_SpkrModel_t; /* (1) this value may change dynamically */
304 
305 /*! @brief Bit width. */
306 typedef enum _tfa9896_bit_width
307 {
308     ktfa9896_BitWidth16 = 0x0, /*!< 16 bits */
309 
310 } tfa9896_bit_width_t;
311 
312 /*! @brief The audio data transfer protocol. */
313 typedef enum _tfa9896_protocol
314 {
315     kTFA9896_ProtocolI2S = 0x2, /*!< I2S type */
316 } tfa9896_protocol_t;
317 
318 /*! @brief Sample rate. */
319 typedef enum _tfa9896_sample_rate
320 {
321     ktfa9896_SampleRate48kHz = 0x5 /*48kHz */
322 } tfa9896_sample_rate_t;
323 
324 /*! @brief Audio format configuration. */
325 typedef struct _tfa9896_audio_format
326 {
327     tfa9896_sample_rate_t sampleRate; /*!< Sample rate */
328     tfa9896_bit_width_t bitWidth;     /*!< Bit width */
329 } tfa9896_audio_format_t;
330 
331 /*! @brief Initialize structure of TFA9896 */
332 typedef struct _tfa9896_config
333 {
334     tfa9896_protocol_t protocol;   /*!< Audio transfer protocol */
335     tfa9896_audio_format_t format; /*!< Audio format */
336     bool master;                   /*!< true is master, false is slave */
337     uint8_t slaveAddress;          /*!< slave address */
338     codec_i2c_config_t i2cConfig;  /*!< i2c bus configuration */
339     uint8_t calibrate;             /*!< user handles calibration! */
340 
341 } tfa9896_config_t;
342 
343 /*! @brief tfa9896 handler */
344 typedef struct _tfa9896_handle
345 {
346     tfa9896_config_t *config; /*!< tfa9896 config pointer */
347     uint8_t i2cHandle[TFA9896_I2C_HANDLER_SIZE];
348 } tfa9896_handle_t;
349 /*******************************************************************************
350  * API
351  ******************************************************************************/
352 #if defined(__cplusplus)
353 extern "C" {
354 #endif
355 
356 /*!
357  * @brief check if TFA9896 Hardware factory registers are set .
358  *
359  * @param handle TFA9896 codec handle.
360  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
361  */
362 uint16_t TFA9896_isFactory(tfa9896_handle_t *handle);
363 
364 /*!
365  * @brief get TFA9896 bitfield value .
366  *
367  * @param handle TFA9896 codec handle.
368  * @param bf to be read
369  * @return Returns 16 bits read value.
370  */
371 uint16_t TFA9896_GetBits(tfa9896_handle_t *handle, const uint16_t bf);
372 /*!
373  * @brief set TFA9896 bitfield value .
374  *
375  * @param handle TFA9896 codec handle.
376  * @param bf to be set
377  * @param value to be set
378  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
379  */
380 status_t TFA9896_SetBits(tfa9896_handle_t *handle, const uint16_t bf, const uint16_t value);
381 /*!
382  * @brief wait for DSP to be stable before RPC communictaons .
383  *
384  * @param handle TFA9896 codec handle.
385  * @param ready DSP system stable status.
386  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
387  */
388 status_t TFA9896_DSP_System_Stable(tfa9896_handle_t *handle, int *ready);
389 /*!
390  * @brief clear MTP regsiters to prepare calibraion .
391  *
392  * @param handle TFA9896 codec handle.
393  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
394  */
395 status_t TFA9896_ClearOneTimeCalibration(tfa9896_handle_t *handle);
396 
397 /*!
398  * @brief set calibartion once registers.
399  *
400  * @param handle TFA9896 codec handle.
401  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
402  */
403 status_t TFA9896_SetOneTimeCalibration(tfa9896_handle_t *handle);
404 /*!
405  * @brief set MTP factory values .
406  *
407  * @param handle TFA9896 codec handle.
408  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
409  */
410 status_t TFA9896_SetFactoryValues(tfa9896_handle_t *handle);
411 /*!
412  * @brief check DSP patch suitability to the TFA9896 device .
413  *
414  * @param handle TFA9896 codec handle.
415  * @param patchheader pattern to check with.
416  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
417  */
418 status_t TFA9896_CheckICROMversion(tfa9896_handle_t *handle, const unsigned char patchheader[]);
419 /*!
420  * @brief load DSP patch to DSP memeory .
421  *
422  * @param handle TFA9896 codec handle.
423  * @param length of the patch.
424  * @param bytes that contains patch data.
425  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
426  */
427 status_t TFA9896_ProcessPatchFile(tfa9896_handle_t *handle, int length, const unsigned char *bytes);
428 /*!
429  * @brief set DSP memery table .
430  *
431  * @param handle TFA9896 codec handle.
432  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
433  */
434 status_t TFA9896_DSPWriteTables(tfa9896_handle_t *handle);
435 
436 /*!
437  * @brief write DSP config file to DSP memery .
438  *
439  * @param handle TFA9896 codec handle.
440  * @param length of the config.
441  * @param pConfigBytes that contains config data.
442  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
443  */
444 status_t TFA9896_DspWriteConfig(tfa9896_handle_t *handle, int length, const unsigned char *pConfigBytes);
445 /*!
446  * @brief write DSP speaker file to DSP memery .
447  *
448  * @param handle TFA9896 codec handle.
449  * @param length of the speaker data.
450  * @param pSpeakerBytes that contains speaker data.
451  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
452  */
453 status_t TFA9896_DspWriteSpeakerParameters(tfa9896_handle_t *handle, int length, const unsigned char *pSpeakerBytes);
454 /*!
455  * @brief write DSP preset file to DSP memery .
456  *
457  * @param handle TFA9896 codec handle.
458  * @param length of the preset data.
459  * @param pPresetBytes that contains preset data.
460  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
461  */
462 status_t TFA9896_DspWritePreset(tfa9896_handle_t *handle, int length, const unsigned char *pPresetBytes);
463 /*!
464  * @brief write DSP filter params to DSP memery .
465  *
466  * @param handle TFA9896 codec handle.
467  * @param filter of the filter data.
468  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
469  */
470 status_t TFA9896_Write_FilterBank(tfa9896_handle_t *handle, tfa9896FilterM_t *filter);
471 /*!
472  * @brief wait calibration to be finalized .
473  *
474  * @param handle TFA9896 codec handle.
475  * @param calibrateDone calibration done flag.
476  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
477  */
478 status_t TFA9896_WaitCalibrateDone(tfa9896_handle_t *handle, int *calibrateDone);
479 /*!
480  * @brief retrieve calibration impedance value and expose it to user.
481  *
482  * @param handle TFA9896 codec handle.
483  * @param pRe25 calibration value.
484  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
485  */
486 status_t TFA9896_DspGetCalibrationImpedance(tfa9896_handle_t *handle, float *pRe25);
487 /*!
488  * @brief print calibration value .
489  *
490  * @param handle TFA9896 codec handle.
491  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
492  */
493 status_t TFA9896_PrintCalibration(tfa9896_handle_t *handle);
494 
495 /*!
496  * @brief write word to IOMEM DSP memeory  .
497  *
498  * @param handle TFA9896 codec handle.
499  * @param address to be written.
500  * @param value value write.
501  * @param memtype to be written.
502  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
503  */
504 status_t TFA9896_DSP_Write_Mem_Word(tfa9896_handle_t *handle, unsigned short address, int value, int memtype);
505 
506 /*!
507  * @brief read a hardware regsiter .
508  *
509  * @param handle TFA9896 codec handle.
510  * @param subaddress register address.
511  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
512  */
513 status_t TFA9896_ReadRegister(tfa9896_handle_t *handle, uint8_t subaddress, unsigned short *value);
514 
515 /*!
516  * @brief write a hardware register .
517  *
518  * @param handle TFA9896 codec handle.
519  * @param subaddress register address.
520  * @param value value to write.
521  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
522  */
523 status_t TFA9896_WriteRegister(tfa9896_handle_t *handle, uint8_t subaddress, uint16_t value);
524 
525 /*!
526  * @brief mute/unmute TFA9896 codec
527  *
528  * @param handle TFA9896 codec handle.
529  * @param mute mute mode.
530  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
531  */
532 status_t TFA9896_SetMute(tfa9896_handle_t *handle, tfa9896_mute_t mute);
533 
534 /*!
535  * @brief Set amplifier volume.
536  * @param handle TFA9896 codec handle.
537  * @param volume_level volume level.
538  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
539  */
540 status_t TFA9896_SetVolume(tfa9896_handle_t *handle, uint8_t volume_level);
541 
542 /*!
543  * @brief set OVP in bypass .
544  *
545  * @param handle TFA98xx codec handle.
546  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
547  */
548 status_t TFA9896_SetOVPBypass(tfa9896_handle_t *handle);
549 
550 /*!
551  * @brief Initialize TFA9896.
552  *
553  * @param handle TFA98xx codec handle.
554  * @param tfa9896Config Codec configuration.
555  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
556  */
557 status_t TFA9896_Init(tfa9896_handle_t *handle, tfa9896_config_t *tfa9896Config);
558 
559 /*!
560  * @brief DeInitilize TFA9896.
561  *
562  * @param handle TFA98xx codec handle.
563  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
564  */
565 status_t TFA9896_Deinit(tfa9896_handle_t *handle);
566 
567 /*!
568  * @brief read a hardware regsiter .
569  *
570  * @param handle TFA98xx codec handle.
571  * @param subaddress register address.
572  * @param value read out register value.
573  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
574  */
575 status_t TFA9896_ReadRegister(tfa9896_handle_t *handle, uint8_t subaddress, unsigned short *value);
576 /*!
577  * @brief write a hardware register .
578  *
579  * @param handle TFA98xx codec handle.
580  * @param subaddress register address.
581  * @param value value to write.
582  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
583  */
584 status_t TFA9896_WriteRegister(tfa9896_handle_t *handle, uint8_t subaddress, uint16_t value);
585 /*!
586  * @brief set audio input format .
587  *
588  * @param handle TFA98xx codec handle.
589  * @param mclk master clock frequency
590  * @param sampleRate to be set.
591  * @param bitWidth to be set.
592  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
593  */
594 status_t TFA9896_SetFormat(tfa9896_handle_t *handle, uint32_t mclk, uint32_t sampleRate, uint32_t bitWidth);
595 /*!
596  * @brief power-on/off TFA98xx device.
597  *
598  * @param handle TFA98xx codec handle.
599  * @param powerdown to on/off
600  */
601 void TFA9896_Powerdown(tfa9896_handle_t *handle, int powerdown);
602 
603 /*!
604  * @brief mute/unmute TFA98XX codec
605  *
606  * @param handle TFA98xx codec handle.
607  * @param mute mute mode.
608  * @return Returns ::kStatus_TFA9896_Ok if success, otherwise returns error code.
609  */
610 status_t TFA9896_SetMute(tfa9896_handle_t *handle, tfa9896_mute_t mute);
611 
612 #if defined(__cplusplus)
613 }
614 #endif
615 
616 /*! @} */
617 
618 #endif /* _FSL_TFA9896_H_ */
619