1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 
4   Broadcom B43 wireless driver
5 
6   Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
7   Copyright (c) 2005-2007 Stefano Brivio <stefano.brivio@polimi.it>
8   Copyright (c) 2006, 2006 Michael Buesch <m@bues.ch>
9   Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
10   Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
11 
12 
13 */
14 
15 #include "b43.h"
16 #include "tables.h"
17 #include "phy_g.h"
18 
19 
20 const u32 b43_tab_rotor[] = {
21 	0xFEB93FFD, 0xFEC63FFD,	/* 0 */
22 	0xFED23FFD, 0xFEDF3FFD,
23 	0xFEEC3FFE, 0xFEF83FFE,
24 	0xFF053FFE, 0xFF113FFE,
25 	0xFF1E3FFE, 0xFF2A3FFF,	/* 8 */
26 	0xFF373FFF, 0xFF443FFF,
27 	0xFF503FFF, 0xFF5D3FFF,
28 	0xFF693FFF, 0xFF763FFF,
29 	0xFF824000, 0xFF8F4000,	/* 16 */
30 	0xFF9B4000, 0xFFA84000,
31 	0xFFB54000, 0xFFC14000,
32 	0xFFCE4000, 0xFFDA4000,
33 	0xFFE74000, 0xFFF34000,	/* 24 */
34 	0x00004000, 0x000D4000,
35 	0x00194000, 0x00264000,
36 	0x00324000, 0x003F4000,
37 	0x004B4000, 0x00584000,	/* 32 */
38 	0x00654000, 0x00714000,
39 	0x007E4000, 0x008A3FFF,
40 	0x00973FFF, 0x00A33FFF,
41 	0x00B03FFF, 0x00BC3FFF,	/* 40 */
42 	0x00C93FFF, 0x00D63FFF,
43 	0x00E23FFE, 0x00EF3FFE,
44 	0x00FB3FFE, 0x01083FFE,
45 	0x01143FFE, 0x01213FFD,	/* 48 */
46 	0x012E3FFD, 0x013A3FFD,
47 	0x01473FFD,
48 };
49 
50 const u32 b43_tab_retard[] = {
51 	0xDB93CB87, 0xD666CF64,	/* 0 */
52 	0xD1FDD358, 0xCDA6D826,
53 	0xCA38DD9F, 0xC729E2B4,
54 	0xC469E88E, 0xC26AEE2B,
55 	0xC0DEF46C, 0xC073FA62,	/* 8 */
56 	0xC01D00D5, 0xC0760743,
57 	0xC1560D1E, 0xC2E51369,
58 	0xC4ED18FF, 0xC7AC1ED7,
59 	0xCB2823B2, 0xCEFA28D9,	/* 16 */
60 	0xD2F62D3F, 0xD7BB3197,
61 	0xDCE53568, 0xE1FE3875,
62 	0xE7D13B35, 0xED663D35,
63 	0xF39B3EC4, 0xF98E3FA7,	/* 24 */
64 	0x00004000, 0x06723FA7,
65 	0x0C653EC4, 0x129A3D35,
66 	0x182F3B35, 0x1E023875,
67 	0x231B3568, 0x28453197,	/* 32 */
68 	0x2D0A2D3F, 0x310628D9,
69 	0x34D823B2, 0x38541ED7,
70 	0x3B1318FF, 0x3D1B1369,
71 	0x3EAA0D1E, 0x3F8A0743,	/* 40 */
72 	0x3FE300D5, 0x3F8DFA62,
73 	0x3F22F46C, 0x3D96EE2B,
74 	0x3B97E88E, 0x38D7E2B4,
75 	0x35C8DD9F, 0x325AD826,	/* 48 */
76 	0x2E03D358, 0x299ACF64,
77 	0x246DCB87,
78 };
79 
80 const u16 b43_tab_finefreqa[] = {
81 	0x0082, 0x0082, 0x0102, 0x0182,	/* 0 */
82 	0x0202, 0x0282, 0x0302, 0x0382,
83 	0x0402, 0x0482, 0x0502, 0x0582,
84 	0x05E2, 0x0662, 0x06E2, 0x0762,
85 	0x07E2, 0x0842, 0x08C2, 0x0942,	/* 16 */
86 	0x09C2, 0x0A22, 0x0AA2, 0x0B02,
87 	0x0B82, 0x0BE2, 0x0C62, 0x0CC2,
88 	0x0D42, 0x0DA2, 0x0E02, 0x0E62,
89 	0x0EE2, 0x0F42, 0x0FA2, 0x1002,	/* 32 */
90 	0x1062, 0x10C2, 0x1122, 0x1182,
91 	0x11E2, 0x1242, 0x12A2, 0x12E2,
92 	0x1342, 0x13A2, 0x1402, 0x1442,
93 	0x14A2, 0x14E2, 0x1542, 0x1582,	/* 48 */
94 	0x15E2, 0x1622, 0x1662, 0x16C1,
95 	0x1701, 0x1741, 0x1781, 0x17E1,
96 	0x1821, 0x1861, 0x18A1, 0x18E1,
97 	0x1921, 0x1961, 0x19A1, 0x19E1,	/* 64 */
98 	0x1A21, 0x1A61, 0x1AA1, 0x1AC1,
99 	0x1B01, 0x1B41, 0x1B81, 0x1BA1,
100 	0x1BE1, 0x1C21, 0x1C41, 0x1C81,
101 	0x1CA1, 0x1CE1, 0x1D01, 0x1D41,	/* 80 */
102 	0x1D61, 0x1DA1, 0x1DC1, 0x1E01,
103 	0x1E21, 0x1E61, 0x1E81, 0x1EA1,
104 	0x1EE1, 0x1F01, 0x1F21, 0x1F41,
105 	0x1F81, 0x1FA1, 0x1FC1, 0x1FE1,	/* 96 */
106 	0x2001, 0x2041, 0x2061, 0x2081,
107 	0x20A1, 0x20C1, 0x20E1, 0x2101,
108 	0x2121, 0x2141, 0x2161, 0x2181,
109 	0x21A1, 0x21C1, 0x21E1, 0x2201,	/* 112 */
110 	0x2221, 0x2241, 0x2261, 0x2281,
111 	0x22A1, 0x22C1, 0x22C1, 0x22E1,
112 	0x2301, 0x2321, 0x2341, 0x2361,
113 	0x2361, 0x2381, 0x23A1, 0x23C1,	/* 128 */
114 	0x23E1, 0x23E1, 0x2401, 0x2421,
115 	0x2441, 0x2441, 0x2461, 0x2481,
116 	0x2481, 0x24A1, 0x24C1, 0x24C1,
117 	0x24E1, 0x2501, 0x2501, 0x2521,	/* 144 */
118 	0x2541, 0x2541, 0x2561, 0x2561,
119 	0x2581, 0x25A1, 0x25A1, 0x25C1,
120 	0x25C1, 0x25E1, 0x2601, 0x2601,
121 	0x2621, 0x2621, 0x2641, 0x2641,	/* 160 */
122 	0x2661, 0x2661, 0x2681, 0x2681,
123 	0x26A1, 0x26A1, 0x26C1, 0x26C1,
124 	0x26E1, 0x26E1, 0x2701, 0x2701,
125 	0x2721, 0x2721, 0x2740, 0x2740,	/* 176 */
126 	0x2760, 0x2760, 0x2780, 0x2780,
127 	0x2780, 0x27A0, 0x27A0, 0x27C0,
128 	0x27C0, 0x27E0, 0x27E0, 0x27E0,
129 	0x2800, 0x2800, 0x2820, 0x2820,	/* 192 */
130 	0x2820, 0x2840, 0x2840, 0x2840,
131 	0x2860, 0x2860, 0x2880, 0x2880,
132 	0x2880, 0x28A0, 0x28A0, 0x28A0,
133 	0x28C0, 0x28C0, 0x28C0, 0x28E0,	/* 208 */
134 	0x28E0, 0x28E0, 0x2900, 0x2900,
135 	0x2900, 0x2920, 0x2920, 0x2920,
136 	0x2940, 0x2940, 0x2940, 0x2960,
137 	0x2960, 0x2960, 0x2960, 0x2980,	/* 224 */
138 	0x2980, 0x2980, 0x29A0, 0x29A0,
139 	0x29A0, 0x29A0, 0x29C0, 0x29C0,
140 	0x29C0, 0x29E0, 0x29E0, 0x29E0,
141 	0x29E0, 0x2A00, 0x2A00, 0x2A00,	/* 240 */
142 	0x2A00, 0x2A20, 0x2A20, 0x2A20,
143 	0x2A20, 0x2A40, 0x2A40, 0x2A40,
144 	0x2A40, 0x2A60, 0x2A60, 0x2A60,
145 };
146 
147 const u16 b43_tab_finefreqg[] = {
148 	0x0089, 0x02E9, 0x0409, 0x04E9,	/* 0 */
149 	0x05A9, 0x0669, 0x0709, 0x0789,
150 	0x0829, 0x08A9, 0x0929, 0x0989,
151 	0x0A09, 0x0A69, 0x0AC9, 0x0B29,
152 	0x0BA9, 0x0BE9, 0x0C49, 0x0CA9,	/* 16 */
153 	0x0D09, 0x0D69, 0x0DA9, 0x0E09,
154 	0x0E69, 0x0EA9, 0x0F09, 0x0F49,
155 	0x0FA9, 0x0FE9, 0x1029, 0x1089,
156 	0x10C9, 0x1109, 0x1169, 0x11A9,	/* 32 */
157 	0x11E9, 0x1229, 0x1289, 0x12C9,
158 	0x1309, 0x1349, 0x1389, 0x13C9,
159 	0x1409, 0x1449, 0x14A9, 0x14E9,
160 	0x1529, 0x1569, 0x15A9, 0x15E9,	/* 48 */
161 	0x1629, 0x1669, 0x16A9, 0x16E8,
162 	0x1728, 0x1768, 0x17A8, 0x17E8,
163 	0x1828, 0x1868, 0x18A8, 0x18E8,
164 	0x1928, 0x1968, 0x19A8, 0x19E8,	/* 64 */
165 	0x1A28, 0x1A68, 0x1AA8, 0x1AE8,
166 	0x1B28, 0x1B68, 0x1BA8, 0x1BE8,
167 	0x1C28, 0x1C68, 0x1CA8, 0x1CE8,
168 	0x1D28, 0x1D68, 0x1DC8, 0x1E08,	/* 80 */
169 	0x1E48, 0x1E88, 0x1EC8, 0x1F08,
170 	0x1F48, 0x1F88, 0x1FE8, 0x2028,
171 	0x2068, 0x20A8, 0x2108, 0x2148,
172 	0x2188, 0x21C8, 0x2228, 0x2268,	/* 96 */
173 	0x22C8, 0x2308, 0x2348, 0x23A8,
174 	0x23E8, 0x2448, 0x24A8, 0x24E8,
175 	0x2548, 0x25A8, 0x2608, 0x2668,
176 	0x26C8, 0x2728, 0x2787, 0x27E7,	/* 112 */
177 	0x2847, 0x28C7, 0x2947, 0x29A7,
178 	0x2A27, 0x2AC7, 0x2B47, 0x2BE7,
179 	0x2CA7, 0x2D67, 0x2E47, 0x2F67,
180 	0x3247, 0x3526, 0x3646, 0x3726,	/* 128 */
181 	0x3806, 0x38A6, 0x3946, 0x39E6,
182 	0x3A66, 0x3AE6, 0x3B66, 0x3BC6,
183 	0x3C45, 0x3CA5, 0x3D05, 0x3D85,
184 	0x3DE5, 0x3E45, 0x3EA5, 0x3EE5,	/* 144 */
185 	0x3F45, 0x3FA5, 0x4005, 0x4045,
186 	0x40A5, 0x40E5, 0x4145, 0x4185,
187 	0x41E5, 0x4225, 0x4265, 0x42C5,
188 	0x4305, 0x4345, 0x43A5, 0x43E5,	/* 160 */
189 	0x4424, 0x4464, 0x44C4, 0x4504,
190 	0x4544, 0x4584, 0x45C4, 0x4604,
191 	0x4644, 0x46A4, 0x46E4, 0x4724,
192 	0x4764, 0x47A4, 0x47E4, 0x4824,	/* 176 */
193 	0x4864, 0x48A4, 0x48E4, 0x4924,
194 	0x4964, 0x49A4, 0x49E4, 0x4A24,
195 	0x4A64, 0x4AA4, 0x4AE4, 0x4B23,
196 	0x4B63, 0x4BA3, 0x4BE3, 0x4C23,	/* 192 */
197 	0x4C63, 0x4CA3, 0x4CE3, 0x4D23,
198 	0x4D63, 0x4DA3, 0x4DE3, 0x4E23,
199 	0x4E63, 0x4EA3, 0x4EE3, 0x4F23,
200 	0x4F63, 0x4FC3, 0x5003, 0x5043,	/* 208 */
201 	0x5083, 0x50C3, 0x5103, 0x5143,
202 	0x5183, 0x51E2, 0x5222, 0x5262,
203 	0x52A2, 0x52E2, 0x5342, 0x5382,
204 	0x53C2, 0x5402, 0x5462, 0x54A2,	/* 224 */
205 	0x5502, 0x5542, 0x55A2, 0x55E2,
206 	0x5642, 0x5682, 0x56E2, 0x5722,
207 	0x5782, 0x57E1, 0x5841, 0x58A1,
208 	0x5901, 0x5961, 0x59C1, 0x5A21,	/* 240 */
209 	0x5AA1, 0x5B01, 0x5B81, 0x5BE1,
210 	0x5C61, 0x5D01, 0x5D80, 0x5E20,
211 	0x5EE0, 0x5FA0, 0x6080, 0x61C0,
212 };
213 
214 const u16 b43_tab_noisea2[] = {
215 	0x0001, 0x0001, 0x0001, 0xFFFE,
216 	0xFFFE, 0x3FFF, 0x1000, 0x0393,
217 };
218 
219 const u16 b43_tab_noisea3[] = {
220 	0x5E5E, 0x5E5E, 0x5E5E, 0x3F48,
221 	0x4C4C, 0x4C4C, 0x4C4C, 0x2D36,
222 };
223 
224 const u16 b43_tab_noiseg1[] = {
225 	0x013C, 0x01F5, 0x031A, 0x0631,
226 	0x0001, 0x0001, 0x0001, 0x0001,
227 };
228 
229 const u16 b43_tab_noiseg2[] = {
230 	0x5484, 0x3C40, 0x0000, 0x0000,
231 	0x0000, 0x0000, 0x0000, 0x0000,
232 };
233 
234 const u16 b43_tab_noisescalea2[] = {
235 	0x6767, 0x6767, 0x6767, 0x6767, /* 0 */
236 	0x6767, 0x6767, 0x6767, 0x6767,
237 	0x6767, 0x6767, 0x6767, 0x6767,
238 	0x6767, 0x6700, 0x6767, 0x6767,
239 	0x6767, 0x6767, 0x6767, 0x6767, /* 16 */
240 	0x6767, 0x6767, 0x6767, 0x6767,
241 	0x6767, 0x6767, 0x0067,
242 };
243 
244 const u16 b43_tab_noisescalea3[] = {
245 	0x2323, 0x2323, 0x2323, 0x2323, /* 0 */
246 	0x2323, 0x2323, 0x2323, 0x2323,
247 	0x2323, 0x2323, 0x2323, 0x2323,
248 	0x2323, 0x2300, 0x2323, 0x2323,
249 	0x2323, 0x2323, 0x2323, 0x2323, /* 16 */
250 	0x2323, 0x2323, 0x2323, 0x2323,
251 	0x2323, 0x2323, 0x0023,
252 };
253 
254 const u16 b43_tab_noisescaleg1[] = {
255 	0x6C77, 0x5162, 0x3B40, 0x3335,	/* 0 */
256 	0x2F2D, 0x2A2A, 0x2527, 0x1F21,
257 	0x1A1D, 0x1719, 0x1616, 0x1414,
258 	0x1414, 0x1400, 0x1414, 0x1614,
259 	0x1716, 0x1A19, 0x1F1D, 0x2521,	/* 16 */
260 	0x2A27, 0x2F2A, 0x332D, 0x3B35,
261 	0x5140, 0x6C62, 0x0077,
262 };
263 
264 const u16 b43_tab_noisescaleg2[] = {
265 	0xD8DD, 0xCBD4, 0xBCC0, 0xB6B7,	/* 0 */
266 	0xB2B0, 0xADAD, 0xA7A9, 0x9FA1,
267 	0x969B, 0x9195, 0x8F8F, 0x8A8A,
268 	0x8A8A, 0x8A00, 0x8A8A, 0x8F8A,
269 	0x918F, 0x9695, 0x9F9B, 0xA7A1,	/* 16 */
270 	0xADA9, 0xB2AD, 0xB6B0, 0xBCB7,
271 	0xCBC0, 0xD8D4, 0x00DD,
272 };
273 
274 const u16 b43_tab_noisescaleg3[] = {
275 	0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,	/* 0 */
276 	0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,
277 	0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,
278 	0xA4A4, 0xA400, 0xA4A4, 0xA4A4,
279 	0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,	/* 16 */
280 	0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,
281 	0xA4A4, 0xA4A4, 0x00A4,
282 };
283 
284 const u16 b43_tab_sigmasqr1[] = {
285 	0x007A, 0x0075, 0x0071, 0x006C,	/* 0 */
286 	0x0067, 0x0063, 0x005E, 0x0059,
287 	0x0054, 0x0050, 0x004B, 0x0046,
288 	0x0042, 0x003D, 0x003D, 0x003D,
289 	0x003D, 0x003D, 0x003D, 0x003D,	/* 16 */
290 	0x003D, 0x003D, 0x003D, 0x003D,
291 	0x003D, 0x003D, 0x0000, 0x003D,
292 	0x003D, 0x003D, 0x003D, 0x003D,
293 	0x003D, 0x003D, 0x003D, 0x003D,	/* 32 */
294 	0x003D, 0x003D, 0x003D, 0x003D,
295 	0x0042, 0x0046, 0x004B, 0x0050,
296 	0x0054, 0x0059, 0x005E, 0x0063,
297 	0x0067, 0x006C, 0x0071, 0x0075,	/* 48 */
298 	0x007A,
299 };
300 
301 const u16 b43_tab_sigmasqr2[] = {
302 	0x00DE, 0x00DC, 0x00DA, 0x00D8,	/* 0 */
303 	0x00D6, 0x00D4, 0x00D2, 0x00CF,
304 	0x00CD, 0x00CA, 0x00C7, 0x00C4,
305 	0x00C1, 0x00BE, 0x00BE, 0x00BE,
306 	0x00BE, 0x00BE, 0x00BE, 0x00BE,	/* 16 */
307 	0x00BE, 0x00BE, 0x00BE, 0x00BE,
308 	0x00BE, 0x00BE, 0x0000, 0x00BE,
309 	0x00BE, 0x00BE, 0x00BE, 0x00BE,
310 	0x00BE, 0x00BE, 0x00BE, 0x00BE,	/* 32 */
311 	0x00BE, 0x00BE, 0x00BE, 0x00BE,
312 	0x00C1, 0x00C4, 0x00C7, 0x00CA,
313 	0x00CD, 0x00CF, 0x00D2, 0x00D4,
314 	0x00D6, 0x00D8, 0x00DA, 0x00DC,	/* 48 */
315 	0x00DE,
316 };
317 
318 const u16 b43_tab_rssiagc1[] = {
319 	0xFFF8, 0xFFF8, 0xFFF8, 0xFFF8, /* 0 */
320 	0xFFF8, 0xFFF9, 0xFFFC, 0xFFFE,
321 	0xFFF8, 0xFFF8, 0xFFF8, 0xFFF8,
322 	0xFFF8, 0xFFF8, 0xFFF8, 0xFFF8,
323 };
324 
325 const u16 b43_tab_rssiagc2[] = {
326 	0x0820, 0x0820, 0x0920, 0x0C38, /* 0 */
327 	0x0820, 0x0820, 0x0820, 0x0820,
328 	0x0820, 0x0820, 0x0920, 0x0A38,
329 	0x0820, 0x0820, 0x0820, 0x0820,
330 	0x0820, 0x0820, 0x0920, 0x0A38, /* 16 */
331 	0x0820, 0x0820, 0x0820, 0x0820,
332 	0x0820, 0x0820, 0x0920, 0x0A38,
333 	0x0820, 0x0820, 0x0820, 0x0820,
334 	0x0820, 0x0820, 0x0920, 0x0A38, /* 32 */
335 	0x0820, 0x0820, 0x0820, 0x0820,
336 	0x0820, 0x0820, 0x0920, 0x0A38,
337 	0x0820, 0x0820, 0x0820, 0x0820,
338 };
339 
assert_sizes(void)340 static inline void assert_sizes(void)
341 {
342 	BUILD_BUG_ON(B43_TAB_ROTOR_SIZE != ARRAY_SIZE(b43_tab_rotor));
343 	BUILD_BUG_ON(B43_TAB_RETARD_SIZE != ARRAY_SIZE(b43_tab_retard));
344 	BUILD_BUG_ON(B43_TAB_FINEFREQA_SIZE != ARRAY_SIZE(b43_tab_finefreqa));
345 	BUILD_BUG_ON(B43_TAB_FINEFREQG_SIZE != ARRAY_SIZE(b43_tab_finefreqg));
346 	BUILD_BUG_ON(B43_TAB_NOISEA2_SIZE != ARRAY_SIZE(b43_tab_noisea2));
347 	BUILD_BUG_ON(B43_TAB_NOISEA3_SIZE != ARRAY_SIZE(b43_tab_noisea3));
348 	BUILD_BUG_ON(B43_TAB_NOISEG1_SIZE != ARRAY_SIZE(b43_tab_noiseg1));
349 	BUILD_BUG_ON(B43_TAB_NOISEG2_SIZE != ARRAY_SIZE(b43_tab_noiseg2));
350 	BUILD_BUG_ON(B43_TAB_NOISESCALE_SIZE !=
351 		     ARRAY_SIZE(b43_tab_noisescalea2));
352 	BUILD_BUG_ON(B43_TAB_NOISESCALE_SIZE !=
353 		     ARRAY_SIZE(b43_tab_noisescalea3));
354 	BUILD_BUG_ON(B43_TAB_NOISESCALE_SIZE !=
355 		     ARRAY_SIZE(b43_tab_noisescaleg1));
356 	BUILD_BUG_ON(B43_TAB_NOISESCALE_SIZE !=
357 		     ARRAY_SIZE(b43_tab_noisescaleg2));
358 	BUILD_BUG_ON(B43_TAB_NOISESCALE_SIZE !=
359 		     ARRAY_SIZE(b43_tab_noisescaleg3));
360 	BUILD_BUG_ON(B43_TAB_SIGMASQR_SIZE != ARRAY_SIZE(b43_tab_sigmasqr1));
361 	BUILD_BUG_ON(B43_TAB_SIGMASQR_SIZE != ARRAY_SIZE(b43_tab_sigmasqr2));
362 	BUILD_BUG_ON(B43_TAB_RSSIAGC1_SIZE != ARRAY_SIZE(b43_tab_rssiagc1));
363 	BUILD_BUG_ON(B43_TAB_RSSIAGC2_SIZE != ARRAY_SIZE(b43_tab_rssiagc2));
364 }
365 
b43_ofdmtab_read16(struct b43_wldev * dev,u16 table,u16 offset)366 u16 b43_ofdmtab_read16(struct b43_wldev *dev, u16 table, u16 offset)
367 {
368 	struct b43_phy_g *gphy = dev->phy.g;
369 	u16 addr;
370 
371 	addr = table + offset;
372 	if ((gphy->ofdmtab_addr_direction != B43_OFDMTAB_DIRECTION_READ) ||
373 	    (addr - 1 != gphy->ofdmtab_addr)) {
374 		/* The hardware has a different address in memory. Update it. */
375 		b43_phy_write(dev, B43_PHY_OTABLECTL, addr);
376 		gphy->ofdmtab_addr_direction = B43_OFDMTAB_DIRECTION_READ;
377 	}
378 	gphy->ofdmtab_addr = addr;
379 
380 	return b43_phy_read(dev, B43_PHY_OTABLEI);
381 
382 	/* Some compiletime assertions... */
383 	assert_sizes();
384 }
385 
b43_ofdmtab_write16(struct b43_wldev * dev,u16 table,u16 offset,u16 value)386 void b43_ofdmtab_write16(struct b43_wldev *dev, u16 table,
387 			 u16 offset, u16 value)
388 {
389 	struct b43_phy_g *gphy = dev->phy.g;
390 	u16 addr;
391 
392 	addr = table + offset;
393 	if ((gphy->ofdmtab_addr_direction != B43_OFDMTAB_DIRECTION_WRITE) ||
394 	    (addr - 1 != gphy->ofdmtab_addr)) {
395 		/* The hardware has a different address in memory. Update it. */
396 		b43_phy_write(dev, B43_PHY_OTABLECTL, addr);
397 		gphy->ofdmtab_addr_direction = B43_OFDMTAB_DIRECTION_WRITE;
398 	}
399 	gphy->ofdmtab_addr = addr;
400 	b43_phy_write(dev, B43_PHY_OTABLEI, value);
401 }
402 
b43_ofdmtab_read32(struct b43_wldev * dev,u16 table,u16 offset)403 u32 b43_ofdmtab_read32(struct b43_wldev *dev, u16 table, u16 offset)
404 {
405 	struct b43_phy_g *gphy = dev->phy.g;
406 	u32 ret;
407 	u16 addr;
408 
409 	addr = table + offset;
410 	if ((gphy->ofdmtab_addr_direction != B43_OFDMTAB_DIRECTION_READ) ||
411 	    (addr - 1 != gphy->ofdmtab_addr)) {
412 		/* The hardware has a different address in memory. Update it. */
413 		b43_phy_write(dev, B43_PHY_OTABLECTL, addr);
414 		gphy->ofdmtab_addr_direction = B43_OFDMTAB_DIRECTION_READ;
415 	}
416 	gphy->ofdmtab_addr = addr;
417 	ret = b43_phy_read(dev, B43_PHY_OTABLEQ);
418 	ret <<= 16;
419 	ret |= b43_phy_read(dev, B43_PHY_OTABLEI);
420 
421 	return ret;
422 }
423 
b43_ofdmtab_write32(struct b43_wldev * dev,u16 table,u16 offset,u32 value)424 void b43_ofdmtab_write32(struct b43_wldev *dev, u16 table,
425 			 u16 offset, u32 value)
426 {
427 	struct b43_phy_g *gphy = dev->phy.g;
428 	u16 addr;
429 
430 	addr = table + offset;
431 	if ((gphy->ofdmtab_addr_direction != B43_OFDMTAB_DIRECTION_WRITE) ||
432 	    (addr - 1 != gphy->ofdmtab_addr)) {
433 		/* The hardware has a different address in memory. Update it. */
434 		b43_phy_write(dev, B43_PHY_OTABLECTL, addr);
435 		gphy->ofdmtab_addr_direction = B43_OFDMTAB_DIRECTION_WRITE;
436 	}
437 	gphy->ofdmtab_addr = addr;
438 
439 	b43_phy_write(dev, B43_PHY_OTABLEI, value);
440 	b43_phy_write(dev, B43_PHY_OTABLEQ, (value >> 16));
441 }
442 
b43_gtab_read(struct b43_wldev * dev,u16 table,u16 offset)443 u16 b43_gtab_read(struct b43_wldev *dev, u16 table, u16 offset)
444 {
445 	b43_phy_write(dev, B43_PHY_GTABCTL, table + offset);
446 	return b43_phy_read(dev, B43_PHY_GTABDATA);
447 }
448 
b43_gtab_write(struct b43_wldev * dev,u16 table,u16 offset,u16 value)449 void b43_gtab_write(struct b43_wldev *dev, u16 table, u16 offset, u16 value)
450 {
451 	b43_phy_write(dev, B43_PHY_GTABCTL, table + offset);
452 	b43_phy_write(dev, B43_PHY_GTABDATA, value);
453 }
454