2 *Copyright 2014,2015 NXP Semiconductors
4 *Licensed under the Apache License, Version 2.0 (the "License");
5 *you may not use this file except in compliance with the License.
6 *You may obtain a copy of the License at
8 *http://www.apache.org/licenses/LICENSE-2.0
10 *Unless required by applicable law or agreed to in writing, software
11 *distributed under the License is distributed on an "AS IS" BASIS,
12 *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 *See the License for the specific language governing permissions and
14 *limitations under the License.
17 #include "tfa_dsp_fw.h"
18 #include "tfa_service.h"
19 #include "tfa_internal.h"
21 #include "tfa98xx_tfafieldnames.h"
23 static enum Tfa98xx_Error tfa9897_specific(Tfa98xx_handle_t handle)
25 enum Tfa98xx_Error error = Tfa98xx_Error_Ok;
26 unsigned short check_value;
28 if (!tfa98xx_handle_is_open(handle))
29 return Tfa98xx_Error_NotOpen;
31 /* all i2C registers must already set to default POR value */
33 /* $48:[3] - 1 ==> 0; iddqtestbst - default value changed.
34 * When Iddqtestbst is set to "0", the slewrate is reduced.
35 * This will lower the overshoot on IN-B to avoid NMOS damage of booster.
37 error = tfa98xx_write_register16(handle, 0x48, 0x0300); /* POR value = 0x308 */
39 /* $49:[0] - 1 ==> 0; CLIP - default value changed. 0 means CLIPPER on
41 error = tfa98xx_read_register16(handle, 0x49, &check_value);
43 error = tfa98xx_write_register16(handle, 0x49, check_value);
49 * the int24 values for the vsfw delay table
51 static unsigned char vsfwdelay_table[] = {
52 0, 0, 2, /*Index 0 - Current/Volt Fractional Delay for 8KHz */
53 0, 0, 0, /*Index 1 - Current/Volt Fractional Delay for 11KHz */
54 0, 0, 0, /*Index 2 - Current/Volt Fractional Delay for 12KHz */
55 0, 0, 2, /*Index 3 - Current/Volt Fractional Delay for 16KHz */
56 0, 0, 2, /*Index 4 - Current/Volt Fractional Delay for 22KHz */
57 0, 0, 2, /*Index 5 - Current/Volt Fractional Delay for 24KHz */
58 0, 0, 2, /*Index 6 - Current/Volt Fractional Delay for 32KHz */
59 0, 0, 2, /*Index 7 - Current/Volt Fractional Delay for 44KHz */
60 0, 0, 3 /*Index 8 - Current/Volt Fractional Delay for 48KHz */
64 * TODO make this tfa98xx
65 * Note that the former products write this table via the patch
66 * so moving this to the tfa98xx API requires also updating all patches
68 static enum Tfa98xx_Error tfa9897_dsp_write_vsfwdelay_table(Tfa98xx_handle_t handle)
70 enum Tfa98xx_Error error;
72 error = tfa_dsp_cmd_id_write(handle, MODULE_FRAMEWORK,
73 TFA1_FW_PAR_ID_SET_CURRENT_DELAY,
74 sizeof(vsfwdelay_table),
80 * The int24 values for the fracdelay table
81 * For now applicable only for 8 and 48 kHz
83 static unsigned char cvfracdelay_table[] = {
84 0, 0, 51, /*Index 0 - Current/Volt Fractional Delay for 8KHz */
85 0, 0, 0, /*Index 1 - Current/Volt Fractional Delay for 11KHz */
86 0, 0, 0, /*Index 2 - Current/Volt Fractional Delay for 12KHz */
87 0, 0, 38, /*Index 3 - Current/Volt Fractional Delay for 16KHz */
88 0, 0, 34, /*Index 4 - Current/Volt Fractional Delay for 22KHz */
89 0, 0, 33, /*Index 5 - Current/Volt Fractional Delay for 24KHz */
90 0, 0, 11, /*Index 6 - Current/Volt Fractional Delay for 32KHz */
91 0, 0, 2, /*Index 7 - Current/Volt Fractional Delay for 44KHz */
92 0, 0, 62 /*Index 8 - Current/Volt Fractional Delay for 48KHz */
95 enum Tfa98xx_Error tfa9897_dsp_write_cvfracdelay_table(Tfa98xx_handle_t handle)
97 enum Tfa98xx_Error error;
99 error = tfa_dsp_cmd_id_write(handle, MODULE_FRAMEWORK,
100 TFA1_FW_PAR_ID_SET_CURFRAC_DELAY,
101 sizeof(cvfracdelay_table),
106 static enum Tfa98xx_Error tfa9897_tfa_dsp_write_tables(Tfa98xx_handle_t dev_idx, int sample_rate)
108 enum Tfa98xx_Error error;
110 /* Not used for max1! */
111 sample_rate = sample_rate;
113 error = tfa9897_dsp_write_vsfwdelay_table(dev_idx);
114 if (error == Tfa98xx_Error_Ok)
115 error = tfa9897_dsp_write_cvfracdelay_table(dev_idx);
117 tfa98xx_dsp_reset(dev_idx, 1);
118 tfa98xx_dsp_reset(dev_idx, 0);
124 * register device specifics functions
126 void tfa9897_ops(struct tfa_device_ops *ops)
128 ops->tfa_init = tfa9897_specific;
129 ops->tfa_dsp_write_tables = tfa9897_tfa_dsp_write_tables;