OSDN Git Service

tfa98xx: fix self assigment errors
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / sound / soc / codecs / tfa98xx / tfa9897_init.c
1 /*
2  *Copyright 2014,2015 NXP Semiconductors
3  *
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
7  *
8  *http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "tfa_dsp_fw.h"
18 #include "tfa_service.h"
19 #include "tfa_internal.h"
20
21 #include "tfa98xx_tfafieldnames.h"
22
23 static enum Tfa98xx_Error tfa9897_specific(Tfa98xx_handle_t handle)
24 {
25         enum Tfa98xx_Error error = Tfa98xx_Error_Ok;
26         unsigned short check_value;
27
28         if (!tfa98xx_handle_is_open(handle))
29                 return Tfa98xx_Error_NotOpen;
30
31         /* all i2C registers must already set to default POR value */
32
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.
36         */
37         error = tfa98xx_write_register16(handle, 0x48, 0x0300); /* POR value = 0x308 */
38
39         /* $49:[0] - 1 ==> 0; CLIP - default value changed. 0 means CLIPPER on
40         */
41         error = tfa98xx_read_register16(handle, 0x49, &check_value);
42         check_value &= ~0x1;
43         error = tfa98xx_write_register16(handle, 0x49, check_value);
44
45         return error;
46 }
47
48 /*
49  * the int24 values for the vsfw delay table
50  */
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 */
61 };
62
63 /*
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
67  */
68 static enum Tfa98xx_Error tfa9897_dsp_write_vsfwdelay_table(Tfa98xx_handle_t handle)
69 {
70         enum Tfa98xx_Error error;
71
72         error = tfa_dsp_cmd_id_write(handle, MODULE_FRAMEWORK,
73                                 TFA1_FW_PAR_ID_SET_CURRENT_DELAY,
74                                 sizeof(vsfwdelay_table),
75                                 vsfwdelay_table);
76         return error;
77 }
78
79 /*
80  * The int24 values for the fracdelay table
81  * For now applicable only for 8 and 48 kHz
82  */
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 */
93 };
94
95 enum Tfa98xx_Error tfa9897_dsp_write_cvfracdelay_table(Tfa98xx_handle_t handle)
96 {
97         enum Tfa98xx_Error error;
98
99         error = tfa_dsp_cmd_id_write(handle, MODULE_FRAMEWORK,
100                                 TFA1_FW_PAR_ID_SET_CURFRAC_DELAY,
101                                 sizeof(cvfracdelay_table),
102                                 cvfracdelay_table);
103         return error;
104 }
105
106 static enum Tfa98xx_Error tfa9897_tfa_dsp_write_tables(Tfa98xx_handle_t dev_idx, int sample_rate)
107 {
108         enum Tfa98xx_Error error;
109
110         /* Not used for max1! */
111         (void)sample_rate;
112
113         error = tfa9897_dsp_write_vsfwdelay_table(dev_idx);
114         if (error == Tfa98xx_Error_Ok)
115                 error = tfa9897_dsp_write_cvfracdelay_table(dev_idx);
116
117         tfa98xx_dsp_reset(dev_idx, 1);
118         tfa98xx_dsp_reset(dev_idx, 0);
119
120         return error;
121 }
122
123 /*
124  * register device specifics functions
125  */
126 void tfa9897_ops(struct tfa_device_ops *ops)
127 {
128         ops->tfa_init = tfa9897_specific;
129         ops->tfa_dsp_write_tables = tfa9897_tfa_dsp_write_tables;
130 }