xref: /linux/drivers/net/wireless/ath/ath5k/rfgain.h (revision c47faa36)
1 /*
2  * RF Gain optimization
3  *
4  * Copyright (c) 2004-2009 Reyk Floeter <reyk@openbsd.org>
5  * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  *
19  */
20 
21 /**
22  * struct ath5k_ini_rfgain - RF Gain table
23  * @rfg_register: RF Gain register address
24  * @rfg_value: Register value for 5 and 2GHz
25  *
26  * Mode-specific RF Gain table (64bytes) for RF5111/5112
27  * (RF5110 only comes with AR5210 and only supports a/turbo a mode so initial
28  * RF Gain values are included in AR5K_AR5210_INI)
29  */
30 struct ath5k_ini_rfgain {
31 	u16	rfg_register;
32 	u32	rfg_value[2];	/* [freq (see below)] */
33 };
34 
35 /* Initial RF Gain settings for RF5111 */
36 static const struct ath5k_ini_rfgain rfgain_5111[] = {
37 	/*			      5GHz	2GHz	*/
38 	{ AR5K_RF_GAIN(0),	{ 0x000001a9, 0x00000000 } },
39 	{ AR5K_RF_GAIN(1),	{ 0x000001e9, 0x00000040 } },
40 	{ AR5K_RF_GAIN(2),	{ 0x00000029, 0x00000080 } },
41 	{ AR5K_RF_GAIN(3),	{ 0x00000069, 0x00000150 } },
42 	{ AR5K_RF_GAIN(4),	{ 0x00000199, 0x00000190 } },
43 	{ AR5K_RF_GAIN(5),	{ 0x000001d9, 0x000001d0 } },
44 	{ AR5K_RF_GAIN(6),	{ 0x00000019, 0x00000010 } },
45 	{ AR5K_RF_GAIN(7),	{ 0x00000059, 0x00000044 } },
46 	{ AR5K_RF_GAIN(8),	{ 0x00000099, 0x00000084 } },
47 	{ AR5K_RF_GAIN(9),	{ 0x000001a5, 0x00000148 } },
48 	{ AR5K_RF_GAIN(10),	{ 0x000001e5, 0x00000188 } },
49 	{ AR5K_RF_GAIN(11),	{ 0x00000025, 0x000001c8 } },
50 	{ AR5K_RF_GAIN(12),	{ 0x000001c8, 0x00000014 } },
51 	{ AR5K_RF_GAIN(13),	{ 0x00000008, 0x00000042 } },
52 	{ AR5K_RF_GAIN(14),	{ 0x00000048, 0x00000082 } },
53 	{ AR5K_RF_GAIN(15),	{ 0x00000088, 0x00000178 } },
54 	{ AR5K_RF_GAIN(16),	{ 0x00000198, 0x000001b8 } },
55 	{ AR5K_RF_GAIN(17),	{ 0x000001d8, 0x000001f8 } },
56 	{ AR5K_RF_GAIN(18),	{ 0x00000018, 0x00000012 } },
57 	{ AR5K_RF_GAIN(19),	{ 0x00000058, 0x00000052 } },
58 	{ AR5K_RF_GAIN(20),	{ 0x00000098, 0x00000092 } },
59 	{ AR5K_RF_GAIN(21),	{ 0x000001a4, 0x0000017c } },
60 	{ AR5K_RF_GAIN(22),	{ 0x000001e4, 0x000001bc } },
61 	{ AR5K_RF_GAIN(23),	{ 0x00000024, 0x000001fc } },
62 	{ AR5K_RF_GAIN(24),	{ 0x00000064, 0x0000000a } },
63 	{ AR5K_RF_GAIN(25),	{ 0x000000a4, 0x0000004a } },
64 	{ AR5K_RF_GAIN(26),	{ 0x000000e4, 0x0000008a } },
65 	{ AR5K_RF_GAIN(27),	{ 0x0000010a, 0x0000015a } },
66 	{ AR5K_RF_GAIN(28),	{ 0x0000014a, 0x0000019a } },
67 	{ AR5K_RF_GAIN(29),	{ 0x0000018a, 0x000001da } },
68 	{ AR5K_RF_GAIN(30),	{ 0x000001ca, 0x0000000e } },
69 	{ AR5K_RF_GAIN(31),	{ 0x0000000a, 0x0000004e } },
70 	{ AR5K_RF_GAIN(32),	{ 0x0000004a, 0x0000008e } },
71 	{ AR5K_RF_GAIN(33),	{ 0x0000008a, 0x0000015e } },
72 	{ AR5K_RF_GAIN(34),	{ 0x000001ba, 0x0000019e } },
73 	{ AR5K_RF_GAIN(35),	{ 0x000001fa, 0x000001de } },
74 	{ AR5K_RF_GAIN(36),	{ 0x0000003a, 0x00000009 } },
75 	{ AR5K_RF_GAIN(37),	{ 0x0000007a, 0x00000049 } },
76 	{ AR5K_RF_GAIN(38),	{ 0x00000186, 0x00000089 } },
77 	{ AR5K_RF_GAIN(39),	{ 0x000001c6, 0x00000179 } },
78 	{ AR5K_RF_GAIN(40),	{ 0x00000006, 0x000001b9 } },
79 	{ AR5K_RF_GAIN(41),	{ 0x00000046, 0x000001f9 } },
80 	{ AR5K_RF_GAIN(42),	{ 0x00000086, 0x00000039 } },
81 	{ AR5K_RF_GAIN(43),	{ 0x000000c6, 0x00000079 } },
82 	{ AR5K_RF_GAIN(44),	{ 0x000000c6, 0x000000b9 } },
83 	{ AR5K_RF_GAIN(45),	{ 0x000000c6, 0x000001bd } },
84 	{ AR5K_RF_GAIN(46),	{ 0x000000c6, 0x000001fd } },
85 	{ AR5K_RF_GAIN(47),	{ 0x000000c6, 0x0000003d } },
86 	{ AR5K_RF_GAIN(48),	{ 0x000000c6, 0x0000007d } },
87 	{ AR5K_RF_GAIN(49),	{ 0x000000c6, 0x000000bd } },
88 	{ AR5K_RF_GAIN(50),	{ 0x000000c6, 0x000000fd } },
89 	{ AR5K_RF_GAIN(51),	{ 0x000000c6, 0x000000fd } },
90 	{ AR5K_RF_GAIN(52),	{ 0x000000c6, 0x000000fd } },
91 	{ AR5K_RF_GAIN(53),	{ 0x000000c6, 0x000000fd } },
92 	{ AR5K_RF_GAIN(54),	{ 0x000000c6, 0x000000fd } },
93 	{ AR5K_RF_GAIN(55),	{ 0x000000c6, 0x000000fd } },
94 	{ AR5K_RF_GAIN(56),	{ 0x000000c6, 0x000000fd } },
95 	{ AR5K_RF_GAIN(57),	{ 0x000000c6, 0x000000fd } },
96 	{ AR5K_RF_GAIN(58),	{ 0x000000c6, 0x000000fd } },
97 	{ AR5K_RF_GAIN(59),	{ 0x000000c6, 0x000000fd } },
98 	{ AR5K_RF_GAIN(60),	{ 0x000000c6, 0x000000fd } },
99 	{ AR5K_RF_GAIN(61),	{ 0x000000c6, 0x000000fd } },
100 	{ AR5K_RF_GAIN(62),	{ 0x000000c6, 0x000000fd } },
101 	{ AR5K_RF_GAIN(63),	{ 0x000000c6, 0x000000fd } },
102 };
103 
104 /* Initial RF Gain settings for RF5112 */
105 static const struct ath5k_ini_rfgain rfgain_5112[] = {
106 	/*			      5GHz	2GHz	*/
107 	{ AR5K_RF_GAIN(0),	{ 0x00000007, 0x00000007 } },
108 	{ AR5K_RF_GAIN(1),	{ 0x00000047, 0x00000047 } },
109 	{ AR5K_RF_GAIN(2),	{ 0x00000087, 0x00000087 } },
110 	{ AR5K_RF_GAIN(3),	{ 0x000001a0, 0x000001a0 } },
111 	{ AR5K_RF_GAIN(4),	{ 0x000001e0, 0x000001e0 } },
112 	{ AR5K_RF_GAIN(5),	{ 0x00000020, 0x00000020 } },
113 	{ AR5K_RF_GAIN(6),	{ 0x00000060, 0x00000060 } },
114 	{ AR5K_RF_GAIN(7),	{ 0x000001a1, 0x000001a1 } },
115 	{ AR5K_RF_GAIN(8),	{ 0x000001e1, 0x000001e1 } },
116 	{ AR5K_RF_GAIN(9),	{ 0x00000021, 0x00000021 } },
117 	{ AR5K_RF_GAIN(10),	{ 0x00000061, 0x00000061 } },
118 	{ AR5K_RF_GAIN(11),	{ 0x00000162, 0x00000162 } },
119 	{ AR5K_RF_GAIN(12),	{ 0x000001a2, 0x000001a2 } },
120 	{ AR5K_RF_GAIN(13),	{ 0x000001e2, 0x000001e2 } },
121 	{ AR5K_RF_GAIN(14),	{ 0x00000022, 0x00000022 } },
122 	{ AR5K_RF_GAIN(15),	{ 0x00000062, 0x00000062 } },
123 	{ AR5K_RF_GAIN(16),	{ 0x00000163, 0x00000163 } },
124 	{ AR5K_RF_GAIN(17),	{ 0x000001a3, 0x000001a3 } },
125 	{ AR5K_RF_GAIN(18),	{ 0x000001e3, 0x000001e3 } },
126 	{ AR5K_RF_GAIN(19),	{ 0x00000023, 0x00000023 } },
127 	{ AR5K_RF_GAIN(20),	{ 0x00000063, 0x00000063 } },
128 	{ AR5K_RF_GAIN(21),	{ 0x00000184, 0x00000184 } },
129 	{ AR5K_RF_GAIN(22),	{ 0x000001c4, 0x000001c4 } },
130 	{ AR5K_RF_GAIN(23),	{ 0x00000004, 0x00000004 } },
131 	{ AR5K_RF_GAIN(24),	{ 0x000001ea, 0x0000000b } },
132 	{ AR5K_RF_GAIN(25),	{ 0x0000002a, 0x0000004b } },
133 	{ AR5K_RF_GAIN(26),	{ 0x0000006a, 0x0000008b } },
134 	{ AR5K_RF_GAIN(27),	{ 0x000000aa, 0x000001ac } },
135 	{ AR5K_RF_GAIN(28),	{ 0x000001ab, 0x000001ec } },
136 	{ AR5K_RF_GAIN(29),	{ 0x000001eb, 0x0000002c } },
137 	{ AR5K_RF_GAIN(30),	{ 0x0000002b, 0x00000012 } },
138 	{ AR5K_RF_GAIN(31),	{ 0x0000006b, 0x00000052 } },
139 	{ AR5K_RF_GAIN(32),	{ 0x000000ab, 0x00000092 } },
140 	{ AR5K_RF_GAIN(33),	{ 0x000001ac, 0x00000193 } },
141 	{ AR5K_RF_GAIN(34),	{ 0x000001ec, 0x000001d3 } },
142 	{ AR5K_RF_GAIN(35),	{ 0x0000002c, 0x00000013 } },
143 	{ AR5K_RF_GAIN(36),	{ 0x0000003a, 0x00000053 } },
144 	{ AR5K_RF_GAIN(37),	{ 0x0000007a, 0x00000093 } },
145 	{ AR5K_RF_GAIN(38),	{ 0x000000ba, 0x00000194 } },
146 	{ AR5K_RF_GAIN(39),	{ 0x000001bb, 0x000001d4 } },
147 	{ AR5K_RF_GAIN(40),	{ 0x000001fb, 0x00000014 } },
148 	{ AR5K_RF_GAIN(41),	{ 0x0000003b, 0x0000003a } },
149 	{ AR5K_RF_GAIN(42),	{ 0x0000007b, 0x0000007a } },
150 	{ AR5K_RF_GAIN(43),	{ 0x000000bb, 0x000000ba } },
151 	{ AR5K_RF_GAIN(44),	{ 0x000001bc, 0x000001bb } },
152 	{ AR5K_RF_GAIN(45),	{ 0x000001fc, 0x000001fb } },
153 	{ AR5K_RF_GAIN(46),	{ 0x0000003c, 0x0000003b } },
154 	{ AR5K_RF_GAIN(47),	{ 0x0000007c, 0x0000007b } },
155 	{ AR5K_RF_GAIN(48),	{ 0x000000bc, 0x000000bb } },
156 	{ AR5K_RF_GAIN(49),	{ 0x000000fc, 0x000001bc } },
157 	{ AR5K_RF_GAIN(50),	{ 0x000000fc, 0x000001fc } },
158 	{ AR5K_RF_GAIN(51),	{ 0x000000fc, 0x0000003c } },
159 	{ AR5K_RF_GAIN(52),	{ 0x000000fc, 0x0000007c } },
160 	{ AR5K_RF_GAIN(53),	{ 0x000000fc, 0x000000bc } },
161 	{ AR5K_RF_GAIN(54),	{ 0x000000fc, 0x000000fc } },
162 	{ AR5K_RF_GAIN(55),	{ 0x000000fc, 0x000000fc } },
163 	{ AR5K_RF_GAIN(56),	{ 0x000000fc, 0x000000fc } },
164 	{ AR5K_RF_GAIN(57),	{ 0x000000fc, 0x000000fc } },
165 	{ AR5K_RF_GAIN(58),	{ 0x000000fc, 0x000000fc } },
166 	{ AR5K_RF_GAIN(59),	{ 0x000000fc, 0x000000fc } },
167 	{ AR5K_RF_GAIN(60),	{ 0x000000fc, 0x000000fc } },
168 	{ AR5K_RF_GAIN(61),	{ 0x000000fc, 0x000000fc } },
169 	{ AR5K_RF_GAIN(62),	{ 0x000000fc, 0x000000fc } },
170 	{ AR5K_RF_GAIN(63),	{ 0x000000fc, 0x000000fc } },
171 };
172 
173 /* Initial RF Gain settings for RF2413 */
174 static const struct ath5k_ini_rfgain rfgain_2413[] = {
175 	{ AR5K_RF_GAIN(0),	{ 0x00000000, 0x00000000 } },
176 	{ AR5K_RF_GAIN(1),	{ 0x00000000, 0x00000040 } },
177 	{ AR5K_RF_GAIN(2),	{ 0x00000000, 0x00000080 } },
178 	{ AR5K_RF_GAIN(3),	{ 0x00000000, 0x00000181 } },
179 	{ AR5K_RF_GAIN(4),	{ 0x00000000, 0x000001c1 } },
180 	{ AR5K_RF_GAIN(5),	{ 0x00000000, 0x00000001 } },
181 	{ AR5K_RF_GAIN(6),	{ 0x00000000, 0x00000041 } },
182 	{ AR5K_RF_GAIN(7),	{ 0x00000000, 0x00000081 } },
183 	{ AR5K_RF_GAIN(8),	{ 0x00000000, 0x00000168 } },
184 	{ AR5K_RF_GAIN(9),	{ 0x00000000, 0x000001a8 } },
185 	{ AR5K_RF_GAIN(10),	{ 0x00000000, 0x000001e8 } },
186 	{ AR5K_RF_GAIN(11),	{ 0x00000000, 0x00000028 } },
187 	{ AR5K_RF_GAIN(12),	{ 0x00000000, 0x00000068 } },
188 	{ AR5K_RF_GAIN(13),	{ 0x00000000, 0x00000189 } },
189 	{ AR5K_RF_GAIN(14),	{ 0x00000000, 0x000001c9 } },
190 	{ AR5K_RF_GAIN(15),	{ 0x00000000, 0x00000009 } },
191 	{ AR5K_RF_GAIN(16),	{ 0x00000000, 0x00000049 } },
192 	{ AR5K_RF_GAIN(17),	{ 0x00000000, 0x00000089 } },
193 	{ AR5K_RF_GAIN(18),	{ 0x00000000, 0x00000190 } },
194 	{ AR5K_RF_GAIN(19),	{ 0x00000000, 0x000001d0 } },
195 	{ AR5K_RF_GAIN(20),	{ 0x00000000, 0x00000010 } },
196 	{ AR5K_RF_GAIN(21),	{ 0x00000000, 0x00000050 } },
197 	{ AR5K_RF_GAIN(22),	{ 0x00000000, 0x00000090 } },
198 	{ AR5K_RF_GAIN(23),	{ 0x00000000, 0x00000191 } },
199 	{ AR5K_RF_GAIN(24),	{ 0x00000000, 0x000001d1 } },
200 	{ AR5K_RF_GAIN(25),	{ 0x00000000, 0x00000011 } },
201 	{ AR5K_RF_GAIN(26),	{ 0x00000000, 0x00000051 } },
202 	{ AR5K_RF_GAIN(27),	{ 0x00000000, 0x00000091 } },
203 	{ AR5K_RF_GAIN(28),	{ 0x00000000, 0x00000178 } },
204 	{ AR5K_RF_GAIN(29),	{ 0x00000000, 0x000001b8 } },
205 	{ AR5K_RF_GAIN(30),	{ 0x00000000, 0x000001f8 } },
206 	{ AR5K_RF_GAIN(31),	{ 0x00000000, 0x00000038 } },
207 	{ AR5K_RF_GAIN(32),	{ 0x00000000, 0x00000078 } },
208 	{ AR5K_RF_GAIN(33),	{ 0x00000000, 0x00000199 } },
209 	{ AR5K_RF_GAIN(34),	{ 0x00000000, 0x000001d9 } },
210 	{ AR5K_RF_GAIN(35),	{ 0x00000000, 0x00000019 } },
211 	{ AR5K_RF_GAIN(36),	{ 0x00000000, 0x00000059 } },
212 	{ AR5K_RF_GAIN(37),	{ 0x00000000, 0x00000099 } },
213 	{ AR5K_RF_GAIN(38),	{ 0x00000000, 0x000000d9 } },
214 	{ AR5K_RF_GAIN(39),	{ 0x00000000, 0x000000f9 } },
215 	{ AR5K_RF_GAIN(40),	{ 0x00000000, 0x000000f9 } },
216 	{ AR5K_RF_GAIN(41),	{ 0x00000000, 0x000000f9 } },
217 	{ AR5K_RF_GAIN(42),	{ 0x00000000, 0x000000f9 } },
218 	{ AR5K_RF_GAIN(43),	{ 0x00000000, 0x000000f9 } },
219 	{ AR5K_RF_GAIN(44),	{ 0x00000000, 0x000000f9 } },
220 	{ AR5K_RF_GAIN(45),	{ 0x00000000, 0x000000f9 } },
221 	{ AR5K_RF_GAIN(46),	{ 0x00000000, 0x000000f9 } },
222 	{ AR5K_RF_GAIN(47),	{ 0x00000000, 0x000000f9 } },
223 	{ AR5K_RF_GAIN(48),	{ 0x00000000, 0x000000f9 } },
224 	{ AR5K_RF_GAIN(49),	{ 0x00000000, 0x000000f9 } },
225 	{ AR5K_RF_GAIN(50),	{ 0x00000000, 0x000000f9 } },
226 	{ AR5K_RF_GAIN(51),	{ 0x00000000, 0x000000f9 } },
227 	{ AR5K_RF_GAIN(52),	{ 0x00000000, 0x000000f9 } },
228 	{ AR5K_RF_GAIN(53),	{ 0x00000000, 0x000000f9 } },
229 	{ AR5K_RF_GAIN(54),	{ 0x00000000, 0x000000f9 } },
230 	{ AR5K_RF_GAIN(55),	{ 0x00000000, 0x000000f9 } },
231 	{ AR5K_RF_GAIN(56),	{ 0x00000000, 0x000000f9 } },
232 	{ AR5K_RF_GAIN(57),	{ 0x00000000, 0x000000f9 } },
233 	{ AR5K_RF_GAIN(58),	{ 0x00000000, 0x000000f9 } },
234 	{ AR5K_RF_GAIN(59),	{ 0x00000000, 0x000000f9 } },
235 	{ AR5K_RF_GAIN(60),	{ 0x00000000, 0x000000f9 } },
236 	{ AR5K_RF_GAIN(61),	{ 0x00000000, 0x000000f9 } },
237 	{ AR5K_RF_GAIN(62),	{ 0x00000000, 0x000000f9 } },
238 	{ AR5K_RF_GAIN(63),	{ 0x00000000, 0x000000f9 } },
239 };
240 
241 /* Initial RF Gain settings for AR2316 */
242 static const struct ath5k_ini_rfgain rfgain_2316[] = {
243 	{ AR5K_RF_GAIN(0),	{ 0x00000000, 0x00000000 } },
244 	{ AR5K_RF_GAIN(1),	{ 0x00000000, 0x00000040 } },
245 	{ AR5K_RF_GAIN(2),	{ 0x00000000, 0x00000080 } },
246 	{ AR5K_RF_GAIN(3),	{ 0x00000000, 0x000000c0 } },
247 	{ AR5K_RF_GAIN(4),	{ 0x00000000, 0x000000e0 } },
248 	{ AR5K_RF_GAIN(5),	{ 0x00000000, 0x000000e0 } },
249 	{ AR5K_RF_GAIN(6),	{ 0x00000000, 0x00000128 } },
250 	{ AR5K_RF_GAIN(7),	{ 0x00000000, 0x00000128 } },
251 	{ AR5K_RF_GAIN(8),	{ 0x00000000, 0x00000128 } },
252 	{ AR5K_RF_GAIN(9),	{ 0x00000000, 0x00000168 } },
253 	{ AR5K_RF_GAIN(10),	{ 0x00000000, 0x000001a8 } },
254 	{ AR5K_RF_GAIN(11),	{ 0x00000000, 0x000001e8 } },
255 	{ AR5K_RF_GAIN(12),	{ 0x00000000, 0x00000028 } },
256 	{ AR5K_RF_GAIN(13),	{ 0x00000000, 0x00000068 } },
257 	{ AR5K_RF_GAIN(14),	{ 0x00000000, 0x000000a8 } },
258 	{ AR5K_RF_GAIN(15),	{ 0x00000000, 0x000000e8 } },
259 	{ AR5K_RF_GAIN(16),	{ 0x00000000, 0x000000e8 } },
260 	{ AR5K_RF_GAIN(17),	{ 0x00000000, 0x00000130 } },
261 	{ AR5K_RF_GAIN(18),	{ 0x00000000, 0x00000130 } },
262 	{ AR5K_RF_GAIN(19),	{ 0x00000000, 0x00000170 } },
263 	{ AR5K_RF_GAIN(20),	{ 0x00000000, 0x000001b0 } },
264 	{ AR5K_RF_GAIN(21),	{ 0x00000000, 0x000001f0 } },
265 	{ AR5K_RF_GAIN(22),	{ 0x00000000, 0x00000030 } },
266 	{ AR5K_RF_GAIN(23),	{ 0x00000000, 0x00000070 } },
267 	{ AR5K_RF_GAIN(24),	{ 0x00000000, 0x000000b0 } },
268 	{ AR5K_RF_GAIN(25),	{ 0x00000000, 0x000000f0 } },
269 	{ AR5K_RF_GAIN(26),	{ 0x00000000, 0x000000f0 } },
270 	{ AR5K_RF_GAIN(27),	{ 0x00000000, 0x000000f0 } },
271 	{ AR5K_RF_GAIN(28),	{ 0x00000000, 0x000000f0 } },
272 	{ AR5K_RF_GAIN(29),	{ 0x00000000, 0x000000f0 } },
273 	{ AR5K_RF_GAIN(30),	{ 0x00000000, 0x000000f0 } },
274 	{ AR5K_RF_GAIN(31),	{ 0x00000000, 0x000000f0 } },
275 	{ AR5K_RF_GAIN(32),	{ 0x00000000, 0x000000f0 } },
276 	{ AR5K_RF_GAIN(33),	{ 0x00000000, 0x000000f0 } },
277 	{ AR5K_RF_GAIN(34),	{ 0x00000000, 0x000000f0 } },
278 	{ AR5K_RF_GAIN(35),	{ 0x00000000, 0x000000f0 } },
279 	{ AR5K_RF_GAIN(36),	{ 0x00000000, 0x000000f0 } },
280 	{ AR5K_RF_GAIN(37),	{ 0x00000000, 0x000000f0 } },
281 	{ AR5K_RF_GAIN(38),	{ 0x00000000, 0x000000f0 } },
282 	{ AR5K_RF_GAIN(39),	{ 0x00000000, 0x000000f0 } },
283 	{ AR5K_RF_GAIN(40),	{ 0x00000000, 0x000000f0 } },
284 	{ AR5K_RF_GAIN(41),	{ 0x00000000, 0x000000f0 } },
285 	{ AR5K_RF_GAIN(42),	{ 0x00000000, 0x000000f0 } },
286 	{ AR5K_RF_GAIN(43),	{ 0x00000000, 0x000000f0 } },
287 	{ AR5K_RF_GAIN(44),	{ 0x00000000, 0x000000f0 } },
288 	{ AR5K_RF_GAIN(45),	{ 0x00000000, 0x000000f0 } },
289 	{ AR5K_RF_GAIN(46),	{ 0x00000000, 0x000000f0 } },
290 	{ AR5K_RF_GAIN(47),	{ 0x00000000, 0x000000f0 } },
291 	{ AR5K_RF_GAIN(48),	{ 0x00000000, 0x000000f0 } },
292 	{ AR5K_RF_GAIN(49),	{ 0x00000000, 0x000000f0 } },
293 	{ AR5K_RF_GAIN(50),	{ 0x00000000, 0x000000f0 } },
294 	{ AR5K_RF_GAIN(51),	{ 0x00000000, 0x000000f0 } },
295 	{ AR5K_RF_GAIN(52),	{ 0x00000000, 0x000000f0 } },
296 	{ AR5K_RF_GAIN(53),	{ 0x00000000, 0x000000f0 } },
297 	{ AR5K_RF_GAIN(54),	{ 0x00000000, 0x000000f0 } },
298 	{ AR5K_RF_GAIN(55),	{ 0x00000000, 0x000000f0 } },
299 	{ AR5K_RF_GAIN(56),	{ 0x00000000, 0x000000f0 } },
300 	{ AR5K_RF_GAIN(57),	{ 0x00000000, 0x000000f0 } },
301 	{ AR5K_RF_GAIN(58),	{ 0x00000000, 0x000000f0 } },
302 	{ AR5K_RF_GAIN(59),	{ 0x00000000, 0x000000f0 } },
303 	{ AR5K_RF_GAIN(60),	{ 0x00000000, 0x000000f0 } },
304 	{ AR5K_RF_GAIN(61),	{ 0x00000000, 0x000000f0 } },
305 	{ AR5K_RF_GAIN(62),	{ 0x00000000, 0x000000f0 } },
306 	{ AR5K_RF_GAIN(63),	{ 0x00000000, 0x000000f0 } },
307 };
308 
309 
310 /* Initial RF Gain settings for RF5413 */
311 static const struct ath5k_ini_rfgain rfgain_5413[] = {
312 	/*			      5GHz	2GHz	*/
313 	{ AR5K_RF_GAIN(0),	{ 0x00000000, 0x00000000 } },
314 	{ AR5K_RF_GAIN(1),	{ 0x00000040, 0x00000040 } },
315 	{ AR5K_RF_GAIN(2),	{ 0x00000080, 0x00000080 } },
316 	{ AR5K_RF_GAIN(3),	{ 0x000001a1, 0x00000161 } },
317 	{ AR5K_RF_GAIN(4),	{ 0x000001e1, 0x000001a1 } },
318 	{ AR5K_RF_GAIN(5),	{ 0x00000021, 0x000001e1 } },
319 	{ AR5K_RF_GAIN(6),	{ 0x00000061, 0x00000021 } },
320 	{ AR5K_RF_GAIN(7),	{ 0x00000188, 0x00000061 } },
321 	{ AR5K_RF_GAIN(8),	{ 0x000001c8, 0x00000188 } },
322 	{ AR5K_RF_GAIN(9),	{ 0x00000008, 0x000001c8 } },
323 	{ AR5K_RF_GAIN(10),	{ 0x00000048, 0x00000008 } },
324 	{ AR5K_RF_GAIN(11),	{ 0x00000088, 0x00000048 } },
325 	{ AR5K_RF_GAIN(12),	{ 0x000001a9, 0x00000088 } },
326 	{ AR5K_RF_GAIN(13),	{ 0x000001e9, 0x00000169 } },
327 	{ AR5K_RF_GAIN(14),	{ 0x00000029, 0x000001a9 } },
328 	{ AR5K_RF_GAIN(15),	{ 0x00000069, 0x000001e9 } },
329 	{ AR5K_RF_GAIN(16),	{ 0x000001d0, 0x00000029 } },
330 	{ AR5K_RF_GAIN(17),	{ 0x00000010, 0x00000069 } },
331 	{ AR5K_RF_GAIN(18),	{ 0x00000050, 0x00000190 } },
332 	{ AR5K_RF_GAIN(19),	{ 0x00000090, 0x000001d0 } },
333 	{ AR5K_RF_GAIN(20),	{ 0x000001b1, 0x00000010 } },
334 	{ AR5K_RF_GAIN(21),	{ 0x000001f1, 0x00000050 } },
335 	{ AR5K_RF_GAIN(22),	{ 0x00000031, 0x00000090 } },
336 	{ AR5K_RF_GAIN(23),	{ 0x00000071, 0x00000171 } },
337 	{ AR5K_RF_GAIN(24),	{ 0x000001b8, 0x000001b1 } },
338 	{ AR5K_RF_GAIN(25),	{ 0x000001f8, 0x000001f1 } },
339 	{ AR5K_RF_GAIN(26),	{ 0x00000038, 0x00000031 } },
340 	{ AR5K_RF_GAIN(27),	{ 0x00000078, 0x00000071 } },
341 	{ AR5K_RF_GAIN(28),	{ 0x00000199, 0x00000198 } },
342 	{ AR5K_RF_GAIN(29),	{ 0x000001d9, 0x000001d8 } },
343 	{ AR5K_RF_GAIN(30),	{ 0x00000019, 0x00000018 } },
344 	{ AR5K_RF_GAIN(31),	{ 0x00000059, 0x00000058 } },
345 	{ AR5K_RF_GAIN(32),	{ 0x00000099, 0x00000098 } },
346 	{ AR5K_RF_GAIN(33),	{ 0x000000d9, 0x00000179 } },
347 	{ AR5K_RF_GAIN(34),	{ 0x000000f9, 0x000001b9 } },
348 	{ AR5K_RF_GAIN(35),	{ 0x000000f9, 0x000001f9 } },
349 	{ AR5K_RF_GAIN(36),	{ 0x000000f9, 0x00000039 } },
350 	{ AR5K_RF_GAIN(37),	{ 0x000000f9, 0x00000079 } },
351 	{ AR5K_RF_GAIN(38),	{ 0x000000f9, 0x000000b9 } },
352 	{ AR5K_RF_GAIN(39),	{ 0x000000f9, 0x000000f9 } },
353 	{ AR5K_RF_GAIN(40),	{ 0x000000f9, 0x000000f9 } },
354 	{ AR5K_RF_GAIN(41),	{ 0x000000f9, 0x000000f9 } },
355 	{ AR5K_RF_GAIN(42),	{ 0x000000f9, 0x000000f9 } },
356 	{ AR5K_RF_GAIN(43),	{ 0x000000f9, 0x000000f9 } },
357 	{ AR5K_RF_GAIN(44),	{ 0x000000f9, 0x000000f9 } },
358 	{ AR5K_RF_GAIN(45),	{ 0x000000f9, 0x000000f9 } },
359 	{ AR5K_RF_GAIN(46),	{ 0x000000f9, 0x000000f9 } },
360 	{ AR5K_RF_GAIN(47),	{ 0x000000f9, 0x000000f9 } },
361 	{ AR5K_RF_GAIN(48),	{ 0x000000f9, 0x000000f9 } },
362 	{ AR5K_RF_GAIN(49),	{ 0x000000f9, 0x000000f9 } },
363 	{ AR5K_RF_GAIN(50),	{ 0x000000f9, 0x000000f9 } },
364 	{ AR5K_RF_GAIN(51),	{ 0x000000f9, 0x000000f9 } },
365 	{ AR5K_RF_GAIN(52),	{ 0x000000f9, 0x000000f9 } },
366 	{ AR5K_RF_GAIN(53),	{ 0x000000f9, 0x000000f9 } },
367 	{ AR5K_RF_GAIN(54),	{ 0x000000f9, 0x000000f9 } },
368 	{ AR5K_RF_GAIN(55),	{ 0x000000f9, 0x000000f9 } },
369 	{ AR5K_RF_GAIN(56),	{ 0x000000f9, 0x000000f9 } },
370 	{ AR5K_RF_GAIN(57),	{ 0x000000f9, 0x000000f9 } },
371 	{ AR5K_RF_GAIN(58),	{ 0x000000f9, 0x000000f9 } },
372 	{ AR5K_RF_GAIN(59),	{ 0x000000f9, 0x000000f9 } },
373 	{ AR5K_RF_GAIN(60),	{ 0x000000f9, 0x000000f9 } },
374 	{ AR5K_RF_GAIN(61),	{ 0x000000f9, 0x000000f9 } },
375 	{ AR5K_RF_GAIN(62),	{ 0x000000f9, 0x000000f9 } },
376 	{ AR5K_RF_GAIN(63),	{ 0x000000f9, 0x000000f9 } },
377 };
378 
379 
380 /* Initial RF Gain settings for RF2425 */
381 static const struct ath5k_ini_rfgain rfgain_2425[] = {
382 	{ AR5K_RF_GAIN(0),	{ 0x00000000, 0x00000000 } },
383 	{ AR5K_RF_GAIN(1),	{ 0x00000000, 0x00000040 } },
384 	{ AR5K_RF_GAIN(2),	{ 0x00000000, 0x00000080 } },
385 	{ AR5K_RF_GAIN(3),	{ 0x00000000, 0x00000181 } },
386 	{ AR5K_RF_GAIN(4),	{ 0x00000000, 0x000001c1 } },
387 	{ AR5K_RF_GAIN(5),	{ 0x00000000, 0x00000001 } },
388 	{ AR5K_RF_GAIN(6),	{ 0x00000000, 0x00000041 } },
389 	{ AR5K_RF_GAIN(7),	{ 0x00000000, 0x00000081 } },
390 	{ AR5K_RF_GAIN(8),	{ 0x00000000, 0x00000188 } },
391 	{ AR5K_RF_GAIN(9),	{ 0x00000000, 0x000001c8 } },
392 	{ AR5K_RF_GAIN(10),	{ 0x00000000, 0x00000008 } },
393 	{ AR5K_RF_GAIN(11),	{ 0x00000000, 0x00000048 } },
394 	{ AR5K_RF_GAIN(12),	{ 0x00000000, 0x00000088 } },
395 	{ AR5K_RF_GAIN(13),	{ 0x00000000, 0x00000189 } },
396 	{ AR5K_RF_GAIN(14),	{ 0x00000000, 0x000001c9 } },
397 	{ AR5K_RF_GAIN(15),	{ 0x00000000, 0x00000009 } },
398 	{ AR5K_RF_GAIN(16),	{ 0x00000000, 0x00000049 } },
399 	{ AR5K_RF_GAIN(17),	{ 0x00000000, 0x00000089 } },
400 	{ AR5K_RF_GAIN(18),	{ 0x00000000, 0x000001b0 } },
401 	{ AR5K_RF_GAIN(19),	{ 0x00000000, 0x000001f0 } },
402 	{ AR5K_RF_GAIN(20),	{ 0x00000000, 0x00000030 } },
403 	{ AR5K_RF_GAIN(21),	{ 0x00000000, 0x00000070 } },
404 	{ AR5K_RF_GAIN(22),	{ 0x00000000, 0x00000171 } },
405 	{ AR5K_RF_GAIN(23),	{ 0x00000000, 0x000001b1 } },
406 	{ AR5K_RF_GAIN(24),	{ 0x00000000, 0x000001f1 } },
407 	{ AR5K_RF_GAIN(25),	{ 0x00000000, 0x00000031 } },
408 	{ AR5K_RF_GAIN(26),	{ 0x00000000, 0x00000071 } },
409 	{ AR5K_RF_GAIN(27),	{ 0x00000000, 0x000001b8 } },
410 	{ AR5K_RF_GAIN(28),	{ 0x00000000, 0x000001f8 } },
411 	{ AR5K_RF_GAIN(29),	{ 0x00000000, 0x00000038 } },
412 	{ AR5K_RF_GAIN(30),	{ 0x00000000, 0x00000078 } },
413 	{ AR5K_RF_GAIN(31),	{ 0x00000000, 0x000000b8 } },
414 	{ AR5K_RF_GAIN(32),	{ 0x00000000, 0x000001b9 } },
415 	{ AR5K_RF_GAIN(33),	{ 0x00000000, 0x000001f9 } },
416 	{ AR5K_RF_GAIN(34),	{ 0x00000000, 0x00000039 } },
417 	{ AR5K_RF_GAIN(35),	{ 0x00000000, 0x00000079 } },
418 	{ AR5K_RF_GAIN(36),	{ 0x00000000, 0x000000b9 } },
419 	{ AR5K_RF_GAIN(37),	{ 0x00000000, 0x000000f9 } },
420 	{ AR5K_RF_GAIN(38),	{ 0x00000000, 0x000000f9 } },
421 	{ AR5K_RF_GAIN(39),	{ 0x00000000, 0x000000f9 } },
422 	{ AR5K_RF_GAIN(40),	{ 0x00000000, 0x000000f9 } },
423 	{ AR5K_RF_GAIN(41),	{ 0x00000000, 0x000000f9 } },
424 	{ AR5K_RF_GAIN(42),	{ 0x00000000, 0x000000f9 } },
425 	{ AR5K_RF_GAIN(43),	{ 0x00000000, 0x000000f9 } },
426 	{ AR5K_RF_GAIN(44),	{ 0x00000000, 0x000000f9 } },
427 	{ AR5K_RF_GAIN(45),	{ 0x00000000, 0x000000f9 } },
428 	{ AR5K_RF_GAIN(46),	{ 0x00000000, 0x000000f9 } },
429 	{ AR5K_RF_GAIN(47),	{ 0x00000000, 0x000000f9 } },
430 	{ AR5K_RF_GAIN(48),	{ 0x00000000, 0x000000f9 } },
431 	{ AR5K_RF_GAIN(49),	{ 0x00000000, 0x000000f9 } },
432 	{ AR5K_RF_GAIN(50),	{ 0x00000000, 0x000000f9 } },
433 	{ AR5K_RF_GAIN(51),	{ 0x00000000, 0x000000f9 } },
434 	{ AR5K_RF_GAIN(52),	{ 0x00000000, 0x000000f9 } },
435 	{ AR5K_RF_GAIN(53),	{ 0x00000000, 0x000000f9 } },
436 	{ AR5K_RF_GAIN(54),	{ 0x00000000, 0x000000f9 } },
437 	{ AR5K_RF_GAIN(55),	{ 0x00000000, 0x000000f9 } },
438 	{ AR5K_RF_GAIN(56),	{ 0x00000000, 0x000000f9 } },
439 	{ AR5K_RF_GAIN(57),	{ 0x00000000, 0x000000f9 } },
440 	{ AR5K_RF_GAIN(58),	{ 0x00000000, 0x000000f9 } },
441 	{ AR5K_RF_GAIN(59),	{ 0x00000000, 0x000000f9 } },
442 	{ AR5K_RF_GAIN(60),	{ 0x00000000, 0x000000f9 } },
443 	{ AR5K_RF_GAIN(61),	{ 0x00000000, 0x000000f9 } },
444 	{ AR5K_RF_GAIN(62),	{ 0x00000000, 0x000000f9 } },
445 	{ AR5K_RF_GAIN(63),	{ 0x00000000, 0x000000f9 } },
446 };
447 
448 #define AR5K_GAIN_CRN_FIX_BITS_5111		4
449 #define AR5K_GAIN_CRN_FIX_BITS_5112		7
450 #define AR5K_GAIN_CRN_MAX_FIX_BITS		AR5K_GAIN_CRN_FIX_BITS_5112
451 #define AR5K_GAIN_DYN_ADJUST_HI_MARGIN		15
452 #define AR5K_GAIN_DYN_ADJUST_LO_MARGIN		20
453 #define AR5K_GAIN_CCK_PROBE_CORR		5
454 #define AR5K_GAIN_CCK_OFDM_GAIN_DELTA		15
455 #define AR5K_GAIN_STEP_COUNT			10
456 
457 /* Check if our current measurement is inside our
458  * current variable attenuation window */
459 #define AR5K_GAIN_CHECK_ADJUST(_g)		\
460 	((_g)->g_current <= (_g)->g_low || (_g)->g_current >= (_g)->g_high)
461 
462 /**
463  * struct ath5k_gain_opt_step - An RF gain optimization step
464  * @gos_param: Set of parameters
465  * @gos_gain: Gain
466  */
467 struct ath5k_gain_opt_step {
468 	s8				gos_param[AR5K_GAIN_CRN_MAX_FIX_BITS];
469 	s8				gos_gain;
470 };
471 
472 /**
473  * struct ath5k_gain_opt - RF Gain optimization ladder
474  * @go_default: The default step
475  * @go_steps_count: How many optimization steps
476  * @go_step: Array of &struct ath5k_gain_opt_step
477  */
478 struct ath5k_gain_opt {
479 	u8				go_default;
480 	u8				go_steps_count;
481 	const struct ath5k_gain_opt_step	go_step[AR5K_GAIN_STEP_COUNT];
482 };
483 
484 
485 /*
486  * RF5111
487  * Parameters on gos_param:
488  * 1) Tx clip PHY register
489  * 2) PWD 90 RF register
490  * 3) PWD 84 RF register
491  * 4) RFGainSel RF register
492  */
493 static const struct ath5k_gain_opt rfgain_opt_5111 = {
494 	4,
495 	9,
496 	{
497 		{ { 4, 1, 1, 1 }, 6 },
498 		{ { 4, 0, 1, 1 }, 4 },
499 		{ { 3, 1, 1, 1 }, 3 },
500 		{ { 4, 0, 0, 1 }, 1 },
501 		{ { 4, 1, 1, 0 }, 0 },
502 		{ { 4, 0, 1, 0 }, -2 },
503 		{ { 3, 1, 1, 0 }, -3 },
504 		{ { 4, 0, 0, 0 }, -4 },
505 		{ { 2, 1, 1, 0 }, -6 }
506 	}
507 };
508 
509 /*
510  * RF5112
511  * Parameters on gos_param:
512  * 1) Mixgain ovr RF register
513  * 2) PWD 138 RF register
514  * 3) PWD 137 RF register
515  * 4) PWD 136 RF register
516  * 5) PWD 132 RF register
517  * 6) PWD 131 RF register
518  * 7) PWD 130 RF register
519  */
520 static const struct ath5k_gain_opt rfgain_opt_5112 = {
521 	1,
522 	8,
523 	{
524 		{ { 3, 0, 0, 0, 0, 0, 0 }, 6 },
525 		{ { 2, 0, 0, 0, 0, 0, 0 }, 0 },
526 		{ { 1, 0, 0, 0, 0, 0, 0 }, -3 },
527 		{ { 0, 0, 0, 0, 0, 0, 0 }, -6 },
528 		{ { 0, 1, 1, 0, 0, 0, 0 }, -8 },
529 		{ { 0, 1, 1, 0, 1, 1, 0 }, -10 },
530 		{ { 0, 1, 0, 1, 1, 1, 0 }, -13 },
531 		{ { 0, 1, 0, 1, 1, 0, 1 }, -16 },
532 	}
533 };
534 
535