xref: /linux/sound/aoa/codecs/tas-basstreble.h (revision fa35aa46077794de446ddd4bcaf809c2fd041ce2)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * This file is only included exactly once!
4  *
5  * The tables here are derived from the tas3004 datasheet,
6  * modulo typo corrections and some smoothing...
7  */
8 
9 #define TAS3004_TREBLE_MIN	0
10 #define TAS3004_TREBLE_MAX	72
11 #define TAS3004_BASS_MIN	0
12 #define TAS3004_BASS_MAX	72
13 #define TAS3004_TREBLE_ZERO	36
14 #define TAS3004_BASS_ZERO	36
15 
16 static const u8 tas3004_treble_table[] = {
17 	150, /* -18 dB */
18 	149,
19 	148,
20 	147,
21 	146,
22 	145,
23 	144,
24 	143,
25 	142,
26 	141,
27 	140,
28 	139,
29 	138,
30 	137,
31 	136,
32 	135,
33 	134,
34 	133,
35 	132,
36 	131,
37 	130,
38 	129,
39 	128,
40 	127,
41 	126,
42 	125,
43 	124,
44 	123,
45 	122,
46 	121,
47 	120,
48 	119,
49 	118,
50 	117,
51 	116,
52 	115,
53 	114, /* 0 dB */
54 	113,
55 	112,
56 	111,
57 	109,
58 	108,
59 	107,
60 	105,
61 	104,
62 	103,
63 	101,
64 	99,
65 	98,
66 	96,
67 	93,
68 	91,
69 	89,
70 	86,
71 	83,
72 	81,
73 	77,
74 	74,
75 	71,
76 	67,
77 	63,
78 	59,
79 	54,
80 	49,
81 	44,
82 	38,
83 	32,
84 	26,
85 	19,
86 	10,
87 	4,
88 	2,
89 	1, /* +18 dB */
90 };
91 
92 static inline u8 tas3004_treble(int idx)
93 {
94 	return tas3004_treble_table[idx];
95 }
96 
97 /* I only save the difference here to the treble table
98  * so that the binary is smaller...
99  * I have also ignored completely differences of
100  * +/- 1
101  */
102 static const s8 tas3004_bass_diff_to_treble[] = {
103 	2, /* 7 dB, offset 50 */
104 	2,
105 	2,
106 	2,
107 	2,
108 	1,
109 	2,
110 	2,
111 	2,
112 	3,
113 	4,
114 	4,
115 	5,
116 	6,
117 	7,
118 	8,
119 	9,
120 	10,
121 	11,
122 	14,
123 	13,
124 	8,
125 	1, /* 18 dB */
126 };
127 
128 static inline u8 tas3004_bass(int idx)
129 {
130 	u8 result = tas3004_treble_table[idx];
131 
132 	if (idx >= 50)
133 		result += tas3004_bass_diff_to_treble[idx-50];
134 	return result;
135 }
136