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