blob: 3d0bddb64b3d1f6abc4367c52f82a883060a1247 [file] [log] [blame]
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001/*
2
3 Broadcom B43 wireless driver
4 IEEE 802.11n HT-PHY support
5
Rafał Miłecki108f4f32011-09-03 21:01:02 +02006 Copyright (c) 2011 Rafał Miłecki <zajec5@gmail.com>
7
Rafał Miłeckid7520b12011-06-13 16:20:06 +02008 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22
23*/
24
25#include <linux/slab.h>
26
27#include "b43.h"
28#include "phy_ht.h"
Rafał Miłeckie5b61002011-06-27 14:58:52 +020029#include "tables_phy_ht.h"
Rafał Miłecki5192bf52011-06-19 12:17:19 +020030#include "radio_2059.h"
Rafał Miłeckid7520b12011-06-13 16:20:06 +020031#include "main.h"
32
Rafał Miłecki3e644ab2011-06-28 00:08:53 +020033/**************************************************
34 * Radio 2059.
35 **************************************************/
36
Rafał Miłecki39ca5542011-06-19 12:17:20 +020037static void b43_radio_2059_channel_setup(struct b43_wldev *dev,
38 const struct b43_phy_ht_channeltab_e_radio2059 *e)
39{
Rafał Miłecki9a0bc412013-03-16 23:40:01 +010040 static const u16 routing[] = { R2059_C1, R2059_C2, R2059_C3, };
41 u16 r;
42 int core;
Rafał Miłeckia6b7da52011-06-19 12:17:21 +020043
44 b43_radio_write(dev, 0x16, e->radio_syn16);
45 b43_radio_write(dev, 0x17, e->radio_syn17);
46 b43_radio_write(dev, 0x22, e->radio_syn22);
47 b43_radio_write(dev, 0x25, e->radio_syn25);
48 b43_radio_write(dev, 0x27, e->radio_syn27);
49 b43_radio_write(dev, 0x28, e->radio_syn28);
50 b43_radio_write(dev, 0x29, e->radio_syn29);
51 b43_radio_write(dev, 0x2c, e->radio_syn2c);
52 b43_radio_write(dev, 0x2d, e->radio_syn2d);
53 b43_radio_write(dev, 0x37, e->radio_syn37);
54 b43_radio_write(dev, 0x41, e->radio_syn41);
55 b43_radio_write(dev, 0x43, e->radio_syn43);
56 b43_radio_write(dev, 0x47, e->radio_syn47);
Rafał Miłeckia6b7da52011-06-19 12:17:21 +020057
Rafał Miłecki9a0bc412013-03-16 23:40:01 +010058 for (core = 0; core < 3; core++) {
59 r = routing[core];
60 b43_radio_write(dev, r | 0x4a, e->radio_rxtx4a);
61 b43_radio_write(dev, r | 0x58, e->radio_rxtx58);
62 b43_radio_write(dev, r | 0x5a, e->radio_rxtx5a);
63 b43_radio_write(dev, r | 0x6a, e->radio_rxtx6a);
64 b43_radio_write(dev, r | 0x6d, e->radio_rxtx6d);
65 b43_radio_write(dev, r | 0x6e, e->radio_rxtx6e);
66 b43_radio_write(dev, r | 0x92, e->radio_rxtx92);
67 b43_radio_write(dev, r | 0x98, e->radio_rxtx98);
Rafał Miłeckia6b7da52011-06-19 12:17:21 +020068 }
69
70 udelay(50);
71
Rafał Miłeckic1c3dae2011-06-20 03:12:19 +020072 /* Calibration */
73 b43_radio_mask(dev, 0x2b, ~0x1);
74 b43_radio_mask(dev, 0x2e, ~0x4);
75 b43_radio_set(dev, 0x2e, 0x4);
76 b43_radio_set(dev, 0x2b, 0x1);
77
78 udelay(300);
Rafał Miłecki39ca5542011-06-19 12:17:20 +020079}
80
Rafał Miłecki3e644ab2011-06-28 00:08:53 +020081static void b43_radio_2059_init(struct b43_wldev *dev)
82{
Rafał Miłeckid6657db2013-03-16 23:24:21 +010083 const u16 routing[] = { R2059_C1, R2059_C2, R2059_C3 };
Rafał Miłeckia5f377f2011-06-29 00:56:49 +020084 const u16 radio_values[3][2] = {
85 { 0x61, 0xE9 }, { 0x69, 0xD5 }, { 0x73, 0x99 },
86 };
87 u16 i, j;
Rafał Miłecki3e644ab2011-06-28 00:08:53 +020088
89 b43_radio_write(dev, R2059_ALL | 0x51, 0x0070);
90 b43_radio_write(dev, R2059_ALL | 0x5a, 0x0003);
91
92 for (i = 0; i < ARRAY_SIZE(routing); i++)
93 b43_radio_set(dev, routing[i] | 0x146, 0x3);
94
95 b43_radio_set(dev, 0x2e, 0x0078);
96 b43_radio_set(dev, 0xc0, 0x0080);
97 msleep(2);
98 b43_radio_mask(dev, 0x2e, ~0x0078);
99 b43_radio_mask(dev, 0xc0, ~0x0080);
100
Rafał Miłeckia5f377f2011-06-29 00:56:49 +0200101 if (1) { /* FIXME */
Rafał Miłeckid6657db2013-03-16 23:24:21 +0100102 b43_radio_set(dev, R2059_C3 | 0x4, 0x1);
Rafał Miłeckia5f377f2011-06-29 00:56:49 +0200103 udelay(10);
Rafał Miłeckid6657db2013-03-16 23:24:21 +0100104 b43_radio_set(dev, R2059_C3 | 0x0BF, 0x1);
105 b43_radio_maskset(dev, R2059_C3 | 0x19B, 0x3, 0x2);
Rafał Miłeckia5f377f2011-06-29 00:56:49 +0200106
Rafał Miłeckid6657db2013-03-16 23:24:21 +0100107 b43_radio_set(dev, R2059_C3 | 0x4, 0x2);
Rafał Miłeckia5f377f2011-06-29 00:56:49 +0200108 udelay(100);
Rafał Miłeckid6657db2013-03-16 23:24:21 +0100109 b43_radio_mask(dev, R2059_C3 | 0x4, ~0x2);
Rafał Miłeckia5f377f2011-06-29 00:56:49 +0200110
111 for (i = 0; i < 10000; i++) {
Rafał Miłeckid6657db2013-03-16 23:24:21 +0100112 if (b43_radio_read(dev, R2059_C3 | 0x145) & 1) {
Rafał Miłeckia5f377f2011-06-29 00:56:49 +0200113 i = 0;
114 break;
115 }
116 udelay(100);
117 }
118 if (i)
119 b43err(dev->wl, "radio 0x945 timeout\n");
120
Rafał Miłeckid6657db2013-03-16 23:24:21 +0100121 b43_radio_mask(dev, R2059_C3 | 0x4, ~0x1);
Rafał Miłeckia5f377f2011-06-29 00:56:49 +0200122 b43_radio_set(dev, 0xa, 0x60);
123
124 for (i = 0; i < 3; i++) {
125 b43_radio_write(dev, 0x17F, radio_values[i][0]);
126 b43_radio_write(dev, 0x13D, 0x6E);
127 b43_radio_write(dev, 0x13E, radio_values[i][1]);
128 b43_radio_write(dev, 0x13C, 0x55);
129
130 for (j = 0; j < 10000; j++) {
131 if (b43_radio_read(dev, 0x140) & 2) {
132 j = 0;
133 break;
134 }
135 udelay(500);
136 }
137 if (j)
138 b43err(dev->wl, "radio 0x140 timeout\n");
139
140 b43_radio_write(dev, 0x13C, 0x15);
141 }
142
143 b43_radio_mask(dev, 0x17F, ~0x1);
144 }
145
Rafał Miłeckib473bc12011-07-17 10:30:34 +0200146 b43_radio_mask(dev, 0x11, ~0x0008);
Rafał Miłecki3e644ab2011-06-28 00:08:53 +0200147}
148
149/**************************************************
Rafał Miłecki4cce0952013-03-07 16:47:20 +0100150 * RF
151 **************************************************/
152
153static void b43_phy_ht_force_rf_sequence(struct b43_wldev *dev, u16 rf_seq)
154{
155 u8 i;
156
157 u16 save_seq_mode = b43_phy_read(dev, B43_PHY_HT_RF_SEQ_MODE);
158 b43_phy_set(dev, B43_PHY_HT_RF_SEQ_MODE, 0x3);
159
160 b43_phy_set(dev, B43_PHY_HT_RF_SEQ_TRIG, rf_seq);
161 for (i = 0; i < 200; i++) {
162 if (!(b43_phy_read(dev, B43_PHY_HT_RF_SEQ_STATUS) & rf_seq)) {
163 i = 0;
164 break;
165 }
166 msleep(1);
167 }
168 if (i)
169 b43err(dev->wl, "Forcing RF sequence timeout\n");
170
171 b43_phy_write(dev, B43_PHY_HT_RF_SEQ_MODE, save_seq_mode);
172}
173
Rafał Miłeckia51ab252013-03-09 13:49:01 +0100174static void b43_phy_ht_pa_override(struct b43_wldev *dev, bool enable)
175{
176 struct b43_phy_ht *htphy = dev->phy.ht;
177 static const u16 regs[3] = { B43_PHY_HT_RF_CTL_INT_C1,
178 B43_PHY_HT_RF_CTL_INT_C2,
179 B43_PHY_HT_RF_CTL_INT_C3 };
180 int i;
181
182 if (enable) {
183 for (i = 0; i < 3; i++)
184 b43_phy_write(dev, regs[i], htphy->rf_ctl_int_save[i]);
185 } else {
186 for (i = 0; i < 3; i++)
187 htphy->rf_ctl_int_save[i] = b43_phy_read(dev, regs[i]);
188 /* TODO: Does 5GHz band use different value (not 0x0400)? */
189 for (i = 0; i < 3; i++)
190 b43_phy_write(dev, regs[i], 0x0400);
191 }
192}
193
Rafał Miłecki4cce0952013-03-07 16:47:20 +0100194/**************************************************
Rafał Miłecki15222b52011-08-12 13:13:44 +0200195 * Various PHY ops
196 **************************************************/
197
Rafał Miłeckib372afa2013-03-07 16:47:16 +0100198static u16 b43_phy_ht_classifier(struct b43_wldev *dev, u16 mask, u16 val)
199{
200 u16 tmp;
201 u16 allowed = B43_PHY_HT_CLASS_CTL_CCK_EN |
202 B43_PHY_HT_CLASS_CTL_OFDM_EN |
203 B43_PHY_HT_CLASS_CTL_WAITED_EN;
204
205 tmp = b43_phy_read(dev, B43_PHY_HT_CLASS_CTL);
206 tmp &= allowed;
207 tmp &= ~mask;
208 tmp |= (val & mask);
209 b43_phy_maskset(dev, B43_PHY_HT_CLASS_CTL, ~allowed, tmp);
210
211 return tmp;
212}
213
Rafał Miłecki4cce0952013-03-07 16:47:20 +0100214static void b43_phy_ht_reset_cca(struct b43_wldev *dev)
215{
216 u16 bbcfg;
217
218 b43_phy_force_clock(dev, true);
219 bbcfg = b43_phy_read(dev, B43_PHY_HT_BBCFG);
220 b43_phy_write(dev, B43_PHY_HT_BBCFG, bbcfg | B43_PHY_HT_BBCFG_RSTCCA);
221 udelay(1);
222 b43_phy_write(dev, B43_PHY_HT_BBCFG, bbcfg & ~B43_PHY_HT_BBCFG_RSTCCA);
223 b43_phy_force_clock(dev, false);
224
225 b43_phy_ht_force_rf_sequence(dev, B43_PHY_HT_RF_SEQ_TRIG_RST2RX);
226}
227
Rafał Miłecki15222b52011-08-12 13:13:44 +0200228static void b43_phy_ht_zero_extg(struct b43_wldev *dev)
229{
230 u8 i, j;
231 u16 base[] = { 0x40, 0x60, 0x80 };
232
233 for (i = 0; i < ARRAY_SIZE(base); i++) {
234 for (j = 0; j < 4; j++)
235 b43_phy_write(dev, B43_PHY_EXTG(base[i] + j), 0);
236 }
237
238 for (i = 0; i < ARRAY_SIZE(base); i++)
239 b43_phy_write(dev, B43_PHY_EXTG(base[i] + 0xc), 0);
240}
241
Rafał Miłeckia4042bb2011-08-13 01:41:12 +0200242/* Some unknown AFE (Analog Frondned) op */
243static void b43_phy_ht_afe_unk1(struct b43_wldev *dev)
244{
245 u8 i;
246
Rafał Miłecki47606922013-03-09 13:43:49 +0100247 static const u16 ctl_regs[3][2] = {
248 { B43_PHY_HT_AFE_C1_OVER, B43_PHY_HT_AFE_C1 },
249 { B43_PHY_HT_AFE_C2_OVER, B43_PHY_HT_AFE_C2 },
250 { B43_PHY_HT_AFE_C3_OVER, B43_PHY_HT_AFE_C3},
Rafał Miłeckia4042bb2011-08-13 01:41:12 +0200251 };
252
253 for (i = 0; i < 3; i++) {
254 /* TODO: verify masks&sets */
255 b43_phy_set(dev, ctl_regs[i][1], 0x4);
256 b43_phy_set(dev, ctl_regs[i][0], 0x4);
257 b43_phy_mask(dev, ctl_regs[i][1], ~0x1);
258 b43_phy_set(dev, ctl_regs[i][0], 0x1);
259 b43_httab_write(dev, B43_HTTAB16(8, 5 + (i * 0x10)), 0);
260 b43_phy_mask(dev, ctl_regs[i][0], ~0x4);
261 }
262}
263
Rafał Miłeckiea5a08c2011-08-24 11:52:35 +0200264static void b43_phy_ht_read_clip_detection(struct b43_wldev *dev, u16 *clip_st)
265{
266 clip_st[0] = b43_phy_read(dev, B43_PHY_HT_C1_CLIP1THRES);
267 clip_st[1] = b43_phy_read(dev, B43_PHY_HT_C2_CLIP1THRES);
268 clip_st[2] = b43_phy_read(dev, B43_PHY_HT_C3_CLIP1THRES);
269}
270
Rafał Miłeckib5058342011-08-12 15:27:34 +0200271static void b43_phy_ht_bphy_init(struct b43_wldev *dev)
272{
273 unsigned int i;
274 u16 val;
275
276 val = 0x1E1F;
277 for (i = 0; i < 16; i++) {
278 b43_phy_write(dev, B43_PHY_N_BMODE(0x88 + i), val);
279 val -= 0x202;
280 }
281 val = 0x3E3F;
282 for (i = 0; i < 16; i++) {
283 b43_phy_write(dev, B43_PHY_N_BMODE(0x98 + i), val);
284 val -= 0x202;
285 }
286 b43_phy_write(dev, B43_PHY_N_BMODE(0x38), 0x668);
287}
288
Rafał Miłecki15222b52011-08-12 13:13:44 +0200289/**************************************************
Rafał Miłecki371ec462013-03-07 16:47:23 +0100290 * Samples
291 **************************************************/
292
Rafał Miłecki371ec462013-03-07 16:47:23 +0100293static void b43_phy_ht_stop_playback(struct b43_wldev *dev)
294{
295 struct b43_phy_ht *phy_ht = dev->phy.ht;
296 u16 tmp;
297 int i;
298
299 tmp = b43_phy_read(dev, B43_PHY_HT_SAMP_STAT);
300 if (tmp & 0x1)
301 b43_phy_set(dev, B43_PHY_HT_SAMP_CMD, B43_PHY_HT_SAMP_CMD_STOP);
302 else if (tmp & 0x2)
303 b43_phy_mask(dev, B43_PHY_HT_IQLOCAL_CMDGCTL, 0x7FFF);
304
305 b43_phy_mask(dev, B43_PHY_HT_SAMP_CMD, ~0x0004);
306
307 for (i = 0; i < 3; i++) {
308 if (phy_ht->bb_mult_save[i] >= 0) {
309 b43_httab_write(dev, B43_HTTAB16(13, 0x63 + i * 4),
310 phy_ht->bb_mult_save[i]);
311 b43_httab_write(dev, B43_HTTAB16(13, 0x67 + i * 4),
312 phy_ht->bb_mult_save[i]);
313 }
314 }
315}
Rafał Miłecki396535e2013-03-07 16:47:24 +0100316
317static u16 b43_phy_ht_load_samples(struct b43_wldev *dev)
318{
319 int i;
320 u16 len = 20 << 3;
321
322 b43_phy_write(dev, B43_PHY_HT_TABLE_ADDR, 0x4400);
323
324 for (i = 0; i < len; i++) {
325 b43_phy_write(dev, B43_PHY_HT_TABLE_DATAHI, 0);
326 b43_phy_write(dev, B43_PHY_HT_TABLE_DATALO, 0);
327 }
328
329 return len;
330}
331
332static void b43_phy_ht_run_samples(struct b43_wldev *dev, u16 samps, u16 loops,
333 u16 wait)
334{
335 struct b43_phy_ht *phy_ht = dev->phy.ht;
336 u16 save_seq_mode;
337 int i;
338
339 for (i = 0; i < 3; i++) {
340 if (phy_ht->bb_mult_save[i] < 0)
341 phy_ht->bb_mult_save[i] = b43_httab_read(dev, B43_HTTAB16(13, 0x63 + i * 4));
342 }
343
344 b43_phy_write(dev, B43_PHY_HT_SAMP_DEP_CNT, samps - 1);
345 if (loops != 0xFFFF)
346 loops--;
347 b43_phy_write(dev, B43_PHY_HT_SAMP_LOOP_CNT, loops);
348 b43_phy_write(dev, B43_PHY_HT_SAMP_WAIT_CNT, wait);
349
350 save_seq_mode = b43_phy_read(dev, B43_PHY_HT_RF_SEQ_MODE);
351 b43_phy_set(dev, B43_PHY_HT_RF_SEQ_MODE,
352 B43_PHY_HT_RF_SEQ_MODE_CA_OVER);
353
354 /* TODO: find out mask bits! Do we need more function arguments? */
355 b43_phy_mask(dev, B43_PHY_HT_SAMP_CMD, ~0);
356 b43_phy_mask(dev, B43_PHY_HT_SAMP_CMD, ~0);
357 b43_phy_mask(dev, B43_PHY_HT_IQLOCAL_CMDGCTL, ~0);
358 b43_phy_set(dev, B43_PHY_HT_SAMP_CMD, 0x1);
359
360 for (i = 0; i < 100; i++) {
361 if (!(b43_phy_read(dev, B43_PHY_HT_RF_SEQ_STATUS) & 1)) {
362 i = 0;
363 break;
364 }
365 udelay(10);
366 }
367 if (i)
368 b43err(dev->wl, "run samples timeout\n");
369
370 b43_phy_write(dev, B43_PHY_HT_RF_SEQ_MODE, save_seq_mode);
371}
372
373static void b43_phy_ht_tx_tone(struct b43_wldev *dev)
374{
375 u16 samp;
376
377 samp = b43_phy_ht_load_samples(dev);
378 b43_phy_ht_run_samples(dev, samp, 0xFFFF, 0);
379}
Rafał Miłecki371ec462013-03-07 16:47:23 +0100380
381/**************************************************
Rafał Miłecki4409a232013-03-09 13:56:26 +0100382 * RSSI
383 **************************************************/
384
Rafał Miłecki4409a232013-03-09 13:56:26 +0100385static void b43_phy_ht_rssi_select(struct b43_wldev *dev, u8 core_sel,
386 u8 rssi_type)
387{
388 static const u16 ctl_regs[3][2] = {
389 { B43_PHY_HT_AFE_C1, B43_PHY_HT_AFE_C1_OVER, },
390 { B43_PHY_HT_AFE_C2, B43_PHY_HT_AFE_C2_OVER, },
391 { B43_PHY_HT_AFE_C3, B43_PHY_HT_AFE_C3_OVER, },
392 };
Rafał Miłeckid6657db2013-03-16 23:24:21 +0100393 static const u16 radio_r[] = { R2059_C1, R2059_C2, R2059_C3, };
Rafał Miłecki4409a232013-03-09 13:56:26 +0100394 int core;
395
396 if (core_sel == 0) {
397 b43err(dev->wl, "RSSI selection for core off not implemented yet\n");
398 } else {
399 for (core = 0; core < 3; core++) {
400 /* Check if caller requested a one specific core */
401 if ((core_sel == 1 && core != 0) ||
402 (core_sel == 2 && core != 1) ||
403 (core_sel == 3 && core != 2))
404 continue;
405
406 switch (rssi_type) {
407 case 4:
408 b43_phy_set(dev, ctl_regs[core][0], 0x3 << 8);
409 b43_phy_set(dev, ctl_regs[core][0], 0x3 << 10);
410 b43_phy_set(dev, ctl_regs[core][1], 0x1 << 9);
411 b43_phy_set(dev, ctl_regs[core][1], 0x1 << 10);
412
Rafał Miłeckid6657db2013-03-16 23:24:21 +0100413 b43_radio_set(dev, R2059_C3 | 0xbf, 0x1);
Rafał Miłecki4409a232013-03-09 13:56:26 +0100414 b43_radio_write(dev, radio_r[core] | 0x159,
415 0x11);
416 break;
417 default:
418 b43err(dev->wl, "RSSI selection for type %d not implemented yet\n",
419 rssi_type);
420 }
421 }
422 }
423}
424
425static void b43_phy_ht_poll_rssi(struct b43_wldev *dev, u8 type, s32 *buf,
426 u8 nsamp)
427{
428 u16 phy_regs_values[12];
429 static const u16 phy_regs_to_save[] = {
430 B43_PHY_HT_AFE_C1, B43_PHY_HT_AFE_C1_OVER,
431 0x848, 0x841,
432 B43_PHY_HT_AFE_C2, B43_PHY_HT_AFE_C2_OVER,
433 0x868, 0x861,
434 B43_PHY_HT_AFE_C3, B43_PHY_HT_AFE_C3_OVER,
435 0x888, 0x881,
436 };
437 u16 tmp[3];
438 int i;
439
440 for (i = 0; i < 12; i++)
441 phy_regs_values[i] = b43_phy_read(dev, phy_regs_to_save[i]);
442
443 b43_phy_ht_rssi_select(dev, 5, type);
444
445 for (i = 0; i < 6; i++)
446 buf[i] = 0;
447
448 for (i = 0; i < nsamp; i++) {
449 tmp[0] = b43_phy_read(dev, B43_PHY_HT_RSSI_C1);
450 tmp[1] = b43_phy_read(dev, B43_PHY_HT_RSSI_C2);
451 tmp[2] = b43_phy_read(dev, B43_PHY_HT_RSSI_C3);
452
453 buf[0] += ((s8)((tmp[0] & 0x3F) << 2)) >> 2;
454 buf[1] += ((s8)(((tmp[0] >> 8) & 0x3F) << 2)) >> 2;
455 buf[2] += ((s8)((tmp[1] & 0x3F) << 2)) >> 2;
456 buf[3] += ((s8)(((tmp[1] >> 8) & 0x3F) << 2)) >> 2;
457 buf[4] += ((s8)((tmp[2] & 0x3F) << 2)) >> 2;
458 buf[5] += ((s8)(((tmp[2] >> 8) & 0x3F) << 2)) >> 2;
459 }
460
461 for (i = 0; i < 12; i++)
462 b43_phy_write(dev, phy_regs_to_save[i], phy_regs_values[i]);
463}
Rafał Miłecki4409a232013-03-09 13:56:26 +0100464
465/**************************************************
Rafał Miłeckif6099f82013-03-07 16:47:17 +0100466 * Tx/Rx
467 **************************************************/
468
469static void b43_phy_ht_tx_power_fix(struct b43_wldev *dev)
470{
471 int i;
472
473 for (i = 0; i < 3; i++) {
474 u16 mask;
475 u32 tmp = b43_httab_read(dev, B43_HTTAB32(26, 0xE8));
476
477 if (0) /* FIXME */
478 mask = 0x2 << (i * 4);
479 else
480 mask = 0;
481 b43_phy_mask(dev, B43_PHY_EXTG(0x108), mask);
482
483 b43_httab_write(dev, B43_HTTAB16(7, 0x110 + i), tmp >> 16);
484 b43_httab_write(dev, B43_HTTAB8(13, 0x63 + (i * 4)),
485 tmp & 0xFF);
486 b43_httab_write(dev, B43_HTTAB8(13, 0x73 + (i * 4)),
487 tmp & 0xFF);
488 }
489}
490
Rafał Miłecki60e8fb92013-03-09 13:52:12 +0100491static void b43_phy_ht_tx_power_ctl(struct b43_wldev *dev, bool enable)
492{
493 struct b43_phy_ht *phy_ht = dev->phy.ht;
494 u16 en_bits = B43_PHY_HT_TXPCTL_CMD_C1_COEFF |
495 B43_PHY_HT_TXPCTL_CMD_C1_HWPCTLEN |
496 B43_PHY_HT_TXPCTL_CMD_C1_PCTLEN;
497 static const u16 cmd_regs[3] = { B43_PHY_HT_TXPCTL_CMD_C1,
498 B43_PHY_HT_TXPCTL_CMD_C2,
499 B43_PHY_HT_TXPCTL_CMD_C3 };
500 int i;
501
502 if (!enable) {
503 if (b43_phy_read(dev, B43_PHY_HT_TXPCTL_CMD_C1) & en_bits) {
504 /* We disable enabled TX pwr ctl, save it's state */
505 /*
506 * TODO: find the registers. On N-PHY they were 0x1ed
507 * and 0x1ee, we need 3 such a registers for HT-PHY
508 */
509 }
510 b43_phy_mask(dev, B43_PHY_HT_TXPCTL_CMD_C1, ~en_bits);
511 } else {
512 b43_phy_set(dev, B43_PHY_HT_TXPCTL_CMD_C1, en_bits);
513
514 if (b43_current_band(dev->wl) == IEEE80211_BAND_5GHZ) {
515 for (i = 0; i < 3; i++)
516 b43_phy_write(dev, cmd_regs[i], 0x32);
517 }
518
519 for (i = 0; i < 3; i++)
520 if (phy_ht->tx_pwr_idx[i] <=
521 B43_PHY_HT_TXPCTL_CMD_C1_INIT)
522 b43_phy_write(dev, cmd_regs[i],
523 phy_ht->tx_pwr_idx[i]);
524 }
525
526 phy_ht->tx_pwr_ctl = enable;
527}
Rafał Miłecki371ec462013-03-07 16:47:23 +0100528
529static void b43_phy_ht_tx_power_ctl_idle_tssi(struct b43_wldev *dev)
530{
Rafał Miłecki4409a232013-03-09 13:56:26 +0100531 struct b43_phy_ht *phy_ht = dev->phy.ht;
532 s32 rssi_buf[6];
533
Rafał Miłecki371ec462013-03-07 16:47:23 +0100534 /* TODO */
Rafał Miłecki396535e2013-03-07 16:47:24 +0100535
536 b43_phy_ht_tx_tone(dev);
537 udelay(20);
Rafał Miłecki4409a232013-03-09 13:56:26 +0100538 b43_phy_ht_poll_rssi(dev, 4, rssi_buf, 1);
Rafał Miłecki371ec462013-03-07 16:47:23 +0100539 b43_phy_ht_stop_playback(dev);
Rafał Miłecki4409a232013-03-09 13:56:26 +0100540 b43_phy_ht_reset_cca(dev);
541
542 phy_ht->idle_tssi[0] = rssi_buf[0] & 0xff;
543 phy_ht->idle_tssi[1] = rssi_buf[2] & 0xff;
544 phy_ht->idle_tssi[2] = rssi_buf[4] & 0xff;
Rafał Miłecki396535e2013-03-07 16:47:24 +0100545
Rafał Miłecki371ec462013-03-07 16:47:23 +0100546 /* TODO */
547}
Rafał Miłecki5949e042013-03-07 16:47:26 +0100548
549static void b43_phy_ht_tx_power_ctl_setup(struct b43_wldev *dev)
550{
551 struct b43_phy_ht *phy_ht = dev->phy.ht;
552 struct ssb_sprom *sprom = dev->dev->bus_sprom;
553
554 u8 *idle = phy_ht->idle_tssi;
555 u8 target[3];
556 s16 a1[3], b0[3], b1[3];
557
558 u16 freq = dev->phy.channel_freq;
559 int i, c;
560
561 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
562 for (c = 0; c < 3; c++) {
563 target[c] = sprom->core_pwr_info[c].maxpwr_2g;
564 a1[c] = sprom->core_pwr_info[c].pa_2g[0];
565 b0[c] = sprom->core_pwr_info[c].pa_2g[1];
566 b1[c] = sprom->core_pwr_info[c].pa_2g[2];
567 }
568 } else if (freq >= 4900 && freq < 5100) {
569 for (c = 0; c < 3; c++) {
570 target[c] = sprom->core_pwr_info[c].maxpwr_5gl;
571 a1[c] = sprom->core_pwr_info[c].pa_5gl[0];
572 b0[c] = sprom->core_pwr_info[c].pa_5gl[1];
573 b1[c] = sprom->core_pwr_info[c].pa_5gl[2];
574 }
575 } else if (freq >= 5100 && freq < 5500) {
576 for (c = 0; c < 3; c++) {
577 target[c] = sprom->core_pwr_info[c].maxpwr_5g;
578 a1[c] = sprom->core_pwr_info[c].pa_5g[0];
579 b0[c] = sprom->core_pwr_info[c].pa_5g[1];
580 b1[c] = sprom->core_pwr_info[c].pa_5g[2];
581 }
582 } else if (freq >= 5500) {
583 for (c = 0; c < 3; c++) {
584 target[c] = sprom->core_pwr_info[c].maxpwr_5gh;
585 a1[c] = sprom->core_pwr_info[c].pa_5gh[0];
586 b0[c] = sprom->core_pwr_info[c].pa_5gh[1];
587 b1[c] = sprom->core_pwr_info[c].pa_5gh[2];
588 }
589 } else {
590 target[0] = target[1] = target[2] = 52;
591 a1[0] = a1[1] = a1[2] = -424;
592 b0[0] = b0[1] = b0[2] = 5612;
593 b1[0] = b1[1] = b1[2] = -1393;
594 }
595
596 b43_phy_set(dev, B43_PHY_HT_TSSIMODE, B43_PHY_HT_TSSIMODE_EN);
597 b43_phy_mask(dev, B43_PHY_HT_TXPCTL_CMD_C1,
598 ~B43_PHY_HT_TXPCTL_CMD_C1_PCTLEN & 0xFFFF);
599
600 /* TODO: Does it depend on sprom->fem.ghz2.tssipos? */
601 b43_phy_set(dev, B43_PHY_HT_TXPCTL_IDLE_TSSI, 0x4000);
602
603 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_CMD_C1,
604 ~B43_PHY_HT_TXPCTL_CMD_C1_INIT, 0x19);
605 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_CMD_C2,
606 ~B43_PHY_HT_TXPCTL_CMD_C2_INIT, 0x19);
607 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_CMD_C3,
608 ~B43_PHY_HT_TXPCTL_CMD_C3_INIT, 0x19);
609
610 b43_phy_set(dev, B43_PHY_HT_TXPCTL_IDLE_TSSI,
611 B43_PHY_HT_TXPCTL_IDLE_TSSI_BINF);
612
613 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_IDLE_TSSI,
614 ~B43_PHY_HT_TXPCTL_IDLE_TSSI_C1,
615 idle[0] << B43_PHY_HT_TXPCTL_IDLE_TSSI_C1_SHIFT);
616 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_IDLE_TSSI,
617 ~B43_PHY_HT_TXPCTL_IDLE_TSSI_C2,
618 idle[1] << B43_PHY_HT_TXPCTL_IDLE_TSSI_C2_SHIFT);
619 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_IDLE_TSSI2,
620 ~B43_PHY_HT_TXPCTL_IDLE_TSSI2_C3,
621 idle[2] << B43_PHY_HT_TXPCTL_IDLE_TSSI2_C3_SHIFT);
622
623 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_N, ~B43_PHY_HT_TXPCTL_N_TSSID,
624 0xf0);
625 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_N, ~B43_PHY_HT_TXPCTL_N_NPTIL2,
626 0x3 << B43_PHY_HT_TXPCTL_N_NPTIL2_SHIFT);
627#if 0
628 /* TODO: what to mask/set? */
629 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_CMD_C1, 0x800, 0)
630 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_CMD_C1, 0x400, 0)
631#endif
632
633 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_TARG_PWR,
634 ~B43_PHY_HT_TXPCTL_TARG_PWR_C1,
635 target[0] << B43_PHY_HT_TXPCTL_TARG_PWR_C1_SHIFT);
636 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_TARG_PWR,
637 ~B43_PHY_HT_TXPCTL_TARG_PWR_C2 & 0xFFFF,
638 target[1] << B43_PHY_HT_TXPCTL_TARG_PWR_C2_SHIFT);
639 b43_phy_maskset(dev, B43_PHY_HT_TXPCTL_TARG_PWR2,
640 ~B43_PHY_HT_TXPCTL_TARG_PWR2_C3,
641 target[2] << B43_PHY_HT_TXPCTL_TARG_PWR2_C3_SHIFT);
642
643 for (c = 0; c < 3; c++) {
644 s32 num, den, pwr;
645 u32 regval[64];
646
647 for (i = 0; i < 64; i++) {
648 num = 8 * (16 * b0[c] + b1[c] * i);
649 den = 32768 + a1[c] * i;
650 pwr = max((4 * num + den / 2) / den, -8);
651 regval[i] = pwr;
652 }
653 b43_httab_write_bulk(dev, B43_HTTAB16(26 + c, 0), 64, regval);
654 }
655}
Rafał Miłecki60e8fb92013-03-09 13:52:12 +0100656
Rafał Miłeckif6099f82013-03-07 16:47:17 +0100657/**************************************************
Rafał Miłecki3e644ab2011-06-28 00:08:53 +0200658 * Channel switching ops.
659 **************************************************/
660
Rafał Miłecki2dacfe72013-03-07 16:47:18 +0100661static void b43_phy_ht_spur_avoid(struct b43_wldev *dev,
662 struct ieee80211_channel *new_channel)
663{
664 struct bcma_device *core = dev->dev->bdev;
665 int spuravoid = 0;
Rafał Miłeckid7bb7ca2013-03-07 16:47:19 +0100666 u16 tmp;
Rafał Miłecki2dacfe72013-03-07 16:47:18 +0100667
668 /* Check for 13 and 14 is just a guess, we don't have enough logs. */
669 if (new_channel->hw_value == 13 || new_channel->hw_value == 14)
670 spuravoid = 1;
671 bcma_core_pll_ctl(core, B43_BCMA_CLKCTLST_PHY_PLL_REQ, 0, false);
672 bcma_pmu_spuravoid_pllupdate(&core->bus->drv_cc, spuravoid);
673 bcma_core_pll_ctl(core,
674 B43_BCMA_CLKCTLST_80211_PLL_REQ |
675 B43_BCMA_CLKCTLST_PHY_PLL_REQ,
676 B43_BCMA_CLKCTLST_80211_PLL_ST |
677 B43_BCMA_CLKCTLST_PHY_PLL_ST, false);
Rafał Miłeckid7bb7ca2013-03-07 16:47:19 +0100678
679 /* Values has been taken from wlc_bmac_switch_macfreq comments */
680 switch (spuravoid) {
681 case 2: /* 126MHz */
682 tmp = 0x2082;
683 break;
684 case 1: /* 123MHz */
685 tmp = 0x5341;
686 break;
687 default: /* 120MHz */
688 tmp = 0x8889;
689 }
690
691 b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_LOW, tmp);
692 b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_HIGH, 0x8);
693
694 /* TODO: reset PLL */
Rafał Miłecki4cce0952013-03-07 16:47:20 +0100695
696 if (spuravoid)
697 b43_phy_set(dev, B43_PHY_HT_BBCFG, B43_PHY_HT_BBCFG_RSTRX);
698 else
699 b43_phy_mask(dev, B43_PHY_HT_BBCFG,
700 ~B43_PHY_HT_BBCFG_RSTRX & 0xFFFF);
701
702 b43_phy_ht_reset_cca(dev);
Rafał Miłecki2dacfe72013-03-07 16:47:18 +0100703}
704
Rafał Miłecki39ca5542011-06-19 12:17:20 +0200705static void b43_phy_ht_channel_setup(struct b43_wldev *dev,
706 const struct b43_phy_ht_channeltab_e_phy *e,
707 struct ieee80211_channel *new_channel)
708{
Rafał Miłeckibdb2dfb2011-06-27 14:58:51 +0200709 bool old_band_5ghz;
710
711 old_band_5ghz = b43_phy_read(dev, B43_PHY_HT_BANDCTL) & 0; /* FIXME */
712 if (new_channel->band == IEEE80211_BAND_5GHZ && !old_band_5ghz) {
713 /* TODO */
714 } else if (new_channel->band == IEEE80211_BAND_2GHZ && old_band_5ghz) {
715 /* TODO */
716 }
717
718 b43_phy_write(dev, B43_PHY_HT_BW1, e->bw1);
719 b43_phy_write(dev, B43_PHY_HT_BW2, e->bw2);
720 b43_phy_write(dev, B43_PHY_HT_BW3, e->bw3);
721 b43_phy_write(dev, B43_PHY_HT_BW4, e->bw4);
722 b43_phy_write(dev, B43_PHY_HT_BW5, e->bw5);
723 b43_phy_write(dev, B43_PHY_HT_BW6, e->bw6);
Rafał Miłeckie5b61002011-06-27 14:58:52 +0200724
Rafał Miłeckib372afa2013-03-07 16:47:16 +0100725 if (new_channel->hw_value == 14) {
726 b43_phy_ht_classifier(dev, B43_PHY_HT_CLASS_CTL_OFDM_EN, 0);
727 b43_phy_set(dev, B43_PHY_HT_TEST, 0x0800);
728 } else {
729 b43_phy_ht_classifier(dev, B43_PHY_HT_CLASS_CTL_OFDM_EN,
730 B43_PHY_HT_CLASS_CTL_OFDM_EN);
731 if (new_channel->band == IEEE80211_BAND_2GHZ)
732 b43_phy_mask(dev, B43_PHY_HT_TEST, ~0x840);
733 }
Rafał Miłeckie5b61002011-06-27 14:58:52 +0200734
Rafał Miłeckif6099f82013-03-07 16:47:17 +0100735 if (1) /* TODO: On N it's for early devices only, what about HT? */
736 b43_phy_ht_tx_power_fix(dev);
Rafał Miłeckie5b61002011-06-27 14:58:52 +0200737
Rafał Miłecki2dacfe72013-03-07 16:47:18 +0100738 b43_phy_ht_spur_avoid(dev, new_channel);
739
Rafał Miłeckie5b61002011-06-27 14:58:52 +0200740 b43_phy_write(dev, 0x017e, 0x3830);
Rafał Miłecki39ca5542011-06-19 12:17:20 +0200741}
742
743static int b43_phy_ht_set_channel(struct b43_wldev *dev,
744 struct ieee80211_channel *channel,
745 enum nl80211_channel_type channel_type)
746{
747 struct b43_phy *phy = &dev->phy;
748
749 const struct b43_phy_ht_channeltab_e_radio2059 *chent_r2059 = NULL;
750
751 if (phy->radio_ver == 0x2059) {
752 chent_r2059 = b43_phy_ht_get_channeltab_e_r2059(dev,
753 channel->center_freq);
754 if (!chent_r2059)
755 return -ESRCH;
756 } else {
757 return -ESRCH;
758 }
759
760 /* TODO: In case of N-PHY some bandwidth switching goes here */
761
762 if (phy->radio_ver == 0x2059) {
763 b43_radio_2059_channel_setup(dev, chent_r2059);
764 b43_phy_ht_channel_setup(dev, &(chent_r2059->phy_regs),
765 channel);
766 } else {
767 return -ESRCH;
768 }
769
770 return 0;
771}
772
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200773/**************************************************
774 * Basic PHY ops.
775 **************************************************/
776
777static int b43_phy_ht_op_allocate(struct b43_wldev *dev)
778{
779 struct b43_phy_ht *phy_ht;
780
781 phy_ht = kzalloc(sizeof(*phy_ht), GFP_KERNEL);
782 if (!phy_ht)
783 return -ENOMEM;
784 dev->phy.ht = phy_ht;
785
786 return 0;
787}
788
789static void b43_phy_ht_op_prepare_structs(struct b43_wldev *dev)
790{
791 struct b43_phy *phy = &dev->phy;
792 struct b43_phy_ht *phy_ht = phy->ht;
Rafał Miłecki60e8fb92013-03-09 13:52:12 +0100793 int i;
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200794
795 memset(phy_ht, 0, sizeof(*phy_ht));
Rafał Miłecki60e8fb92013-03-09 13:52:12 +0100796
797 phy_ht->tx_pwr_ctl = true;
798 for (i = 0; i < 3; i++)
799 phy_ht->tx_pwr_idx[i] = B43_PHY_HT_TXPCTL_CMD_C1_INIT + 1;
Rafał Miłecki371ec462013-03-07 16:47:23 +0100800
801 for (i = 0; i < 3; i++)
802 phy_ht->bb_mult_save[i] = -1;
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200803}
804
Rafał Miłecki2d02c862011-06-28 09:28:39 +0200805static int b43_phy_ht_op_init(struct b43_wldev *dev)
806{
Rafał Miłecki60e8fb92013-03-09 13:52:12 +0100807 struct b43_phy_ht *phy_ht = dev->phy.ht;
Rafał Miłecki19240f32011-08-12 13:13:46 +0200808 u16 tmp;
Rafał Miłeckiea5a08c2011-08-24 11:52:35 +0200809 u16 clip_state[3];
Rafał Miłecki60e8fb92013-03-09 13:52:12 +0100810 bool saved_tx_pwr_ctl;
Rafał Miłecki19240f32011-08-12 13:13:46 +0200811
Rafał Miłecki7c2332b2013-03-04 16:39:10 +0100812 if (dev->dev->bus_type != B43_BUS_BCMA) {
813 b43err(dev->wl, "HT-PHY is supported only on BCMA bus!\n");
814 return -EOPNOTSUPP;
815 }
816
Rafał Miłecki2d02c862011-06-28 09:28:39 +0200817 b43_phy_ht_tables_init(dev);
818
Rafał Miłecki357e24d2011-08-13 01:41:11 +0200819 b43_phy_mask(dev, 0x0be, ~0x2);
820 b43_phy_set(dev, 0x23f, 0x7ff);
821 b43_phy_set(dev, 0x240, 0x7ff);
822 b43_phy_set(dev, 0x241, 0x7ff);
Rafał Miłecki15222b52011-08-12 13:13:44 +0200823
824 b43_phy_ht_zero_extg(dev);
825
Rafał Miłecki357e24d2011-08-13 01:41:11 +0200826 b43_phy_mask(dev, B43_PHY_EXTG(0), ~0x3);
Rafał Miłeckif457f182011-08-12 13:13:45 +0200827
Rafał Miłecki47606922013-03-09 13:43:49 +0100828 b43_phy_write(dev, B43_PHY_HT_AFE_C1_OVER, 0);
829 b43_phy_write(dev, B43_PHY_HT_AFE_C2_OVER, 0);
830 b43_phy_write(dev, B43_PHY_HT_AFE_C3_OVER, 0);
Rafał Miłeckif457f182011-08-12 13:13:45 +0200831
832 b43_phy_write(dev, B43_PHY_EXTG(0x103), 0x20);
833 b43_phy_write(dev, B43_PHY_EXTG(0x101), 0x20);
834 b43_phy_write(dev, 0x20d, 0xb8);
835 b43_phy_write(dev, B43_PHY_EXTG(0x14f), 0xc8);
836 b43_phy_write(dev, 0x70, 0x50);
837 b43_phy_write(dev, 0x1ff, 0x30);
838
839 if (0) /* TODO: condition */
840 ; /* TODO: PHY op on reg 0x217 */
841
Rafał Miłeckib372afa2013-03-07 16:47:16 +0100842 if (b43_current_band(dev->wl) == IEEE80211_BAND_5GHZ)
843 b43_phy_ht_classifier(dev, B43_PHY_HT_CLASS_CTL_CCK_EN, 0);
844 else
845 b43_phy_ht_classifier(dev, B43_PHY_HT_CLASS_CTL_CCK_EN,
846 B43_PHY_HT_CLASS_CTL_CCK_EN);
Rafał Miłeckif457f182011-08-12 13:13:45 +0200847
Rafał Miłecki357e24d2011-08-13 01:41:11 +0200848 b43_phy_set(dev, 0xb1, 0x91);
849 b43_phy_write(dev, 0x32f, 0x0003);
850 b43_phy_write(dev, 0x077, 0x0010);
851 b43_phy_write(dev, 0x0b4, 0x0258);
852 b43_phy_mask(dev, 0x17e, ~0x4000);
Rafał Miłeckif457f182011-08-12 13:13:45 +0200853
854 b43_phy_write(dev, 0x0b9, 0x0072);
855
Rafał Miłecki98f8dc72011-08-13 17:54:04 +0200856 b43_httab_write_few(dev, B43_HTTAB16(7, 0x14e), 2, 0x010f, 0x010f);
857 b43_httab_write_few(dev, B43_HTTAB16(7, 0x15e), 2, 0x010f, 0x010f);
858 b43_httab_write_few(dev, B43_HTTAB16(7, 0x16e), 2, 0x010f, 0x010f);
Rafał Miłecki19240f32011-08-12 13:13:46 +0200859
Rafał Miłeckia4042bb2011-08-13 01:41:12 +0200860 b43_phy_ht_afe_unk1(dev);
861
Rafał Miłecki98f8dc72011-08-13 17:54:04 +0200862 b43_httab_write_few(dev, B43_HTTAB16(7, 0x130), 9, 0x777, 0x111, 0x111,
863 0x777, 0x111, 0x111, 0x777, 0x111, 0x111);
864
865 b43_httab_write(dev, B43_HTTAB16(7, 0x120), 0x0777);
866 b43_httab_write(dev, B43_HTTAB16(7, 0x124), 0x0777);
867
868 b43_httab_write(dev, B43_HTTAB16(8, 0x00), 0x02);
869 b43_httab_write(dev, B43_HTTAB16(8, 0x10), 0x02);
870 b43_httab_write(dev, B43_HTTAB16(8, 0x20), 0x02);
871
872 b43_httab_write_few(dev, B43_HTTAB16(8, 0x08), 4,
873 0x8e, 0x96, 0x96, 0x96);
874 b43_httab_write_few(dev, B43_HTTAB16(8, 0x18), 4,
875 0x8f, 0x9f, 0x9f, 0x9f);
876 b43_httab_write_few(dev, B43_HTTAB16(8, 0x28), 4,
877 0x8f, 0x9f, 0x9f, 0x9f);
878
879 b43_httab_write_few(dev, B43_HTTAB16(8, 0x0c), 4, 0x2, 0x2, 0x2, 0x2);
880 b43_httab_write_few(dev, B43_HTTAB16(8, 0x1c), 4, 0x2, 0x2, 0x2, 0x2);
881 b43_httab_write_few(dev, B43_HTTAB16(8, 0x2c), 4, 0x2, 0x2, 0x2, 0x2);
Rafał Miłeckia4042bb2011-08-13 01:41:12 +0200882
Rafał Miłecki357e24d2011-08-13 01:41:11 +0200883 b43_phy_maskset(dev, 0x0280, 0xff00, 0x3e);
884 b43_phy_maskset(dev, 0x0283, 0xff00, 0x3e);
885 b43_phy_maskset(dev, B43_PHY_OFDM(0x0141), 0xff00, 0x46);
886 b43_phy_maskset(dev, 0x0283, 0xff00, 0x40);
887
Rafał Miłecki98f8dc72011-08-13 17:54:04 +0200888 b43_httab_write_few(dev, B43_HTTAB16(00, 0x8), 4,
889 0x09, 0x0e, 0x13, 0x18);
890 b43_httab_write_few(dev, B43_HTTAB16(01, 0x8), 4,
891 0x09, 0x0e, 0x13, 0x18);
892 /* TODO: Did wl mean 2 instead of 40? */
893 b43_httab_write_few(dev, B43_HTTAB16(40, 0x8), 4,
894 0x09, 0x0e, 0x13, 0x18);
Rafał Miłecki357e24d2011-08-13 01:41:11 +0200895
896 b43_phy_maskset(dev, B43_PHY_OFDM(0x24), 0x3f, 0xd);
897 b43_phy_maskset(dev, B43_PHY_OFDM(0x64), 0x3f, 0xd);
898 b43_phy_maskset(dev, B43_PHY_OFDM(0xa4), 0x3f, 0xd);
899
900 b43_phy_set(dev, B43_PHY_EXTG(0x060), 0x1);
901 b43_phy_set(dev, B43_PHY_EXTG(0x064), 0x1);
902 b43_phy_set(dev, B43_PHY_EXTG(0x080), 0x1);
903 b43_phy_set(dev, B43_PHY_EXTG(0x084), 0x1);
904
Rafał Miłecki19240f32011-08-12 13:13:46 +0200905 /* Copy some tables entries */
906 tmp = b43_httab_read(dev, B43_HTTAB16(7, 0x144));
907 b43_httab_write(dev, B43_HTTAB16(7, 0x14a), tmp);
908 tmp = b43_httab_read(dev, B43_HTTAB16(7, 0x154));
909 b43_httab_write(dev, B43_HTTAB16(7, 0x15a), tmp);
910 tmp = b43_httab_read(dev, B43_HTTAB16(7, 0x164));
911 b43_httab_write(dev, B43_HTTAB16(7, 0x16a), tmp);
912
913 /* Reset CCA */
914 b43_phy_force_clock(dev, true);
915 tmp = b43_phy_read(dev, B43_PHY_HT_BBCFG);
916 b43_phy_write(dev, B43_PHY_HT_BBCFG, tmp | B43_PHY_HT_BBCFG_RSTCCA);
917 b43_phy_write(dev, B43_PHY_HT_BBCFG, tmp & ~B43_PHY_HT_BBCFG_RSTCCA);
918 b43_phy_force_clock(dev, false);
919
920 b43_mac_phy_clock_set(dev, true);
921
Rafał Miłeckia51ab252013-03-09 13:49:01 +0100922 b43_phy_ht_pa_override(dev, false);
Rafał Miłeckic750f792011-08-24 11:52:34 +0200923 b43_phy_ht_force_rf_sequence(dev, B43_PHY_HT_RF_SEQ_TRIG_RX2TX);
924 b43_phy_ht_force_rf_sequence(dev, B43_PHY_HT_RF_SEQ_TRIG_RST2RX);
Rafał Miłeckia51ab252013-03-09 13:49:01 +0100925 b43_phy_ht_pa_override(dev, true);
Rafał Miłecki357e24d2011-08-13 01:41:11 +0200926
Rafał Miłeckiea5a08c2011-08-24 11:52:35 +0200927 /* TODO: Should we restore it? Or store it in global PHY info? */
Rafał Miłeckib372afa2013-03-07 16:47:16 +0100928 b43_phy_ht_classifier(dev, 0, 0);
Rafał Miłeckiea5a08c2011-08-24 11:52:35 +0200929 b43_phy_ht_read_clip_detection(dev, clip_state);
Rafał Miłeckib5058342011-08-12 15:27:34 +0200930
931 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ)
932 b43_phy_ht_bphy_init(dev);
933
934 b43_httab_write_bulk(dev, B43_HTTAB32(0x1a, 0xc0),
935 B43_HTTAB_1A_C0_LATE_SIZE, b43_httab_0x1a_0xc0_late);
936
Rafał Miłecki60e8fb92013-03-09 13:52:12 +0100937 saved_tx_pwr_ctl = phy_ht->tx_pwr_ctl;
938 b43_phy_ht_tx_power_fix(dev);
Rafał Miłecki60e8fb92013-03-09 13:52:12 +0100939 b43_phy_ht_tx_power_ctl(dev, false);
Rafał Miłecki371ec462013-03-07 16:47:23 +0100940 b43_phy_ht_tx_power_ctl_idle_tssi(dev);
Rafał Miłecki5949e042013-03-07 16:47:26 +0100941 b43_phy_ht_tx_power_ctl_setup(dev);
Rafał Miłecki60e8fb92013-03-09 13:52:12 +0100942 b43_phy_ht_tx_power_ctl(dev, saved_tx_pwr_ctl);
Rafał Miłecki60e8fb92013-03-09 13:52:12 +0100943
Rafał Miłecki2d02c862011-06-28 09:28:39 +0200944 return 0;
945}
946
Rafał Miłeckid7520b12011-06-13 16:20:06 +0200947static void b43_phy_ht_op_free(struct b43_wldev *dev)
948{
949 struct b43_phy *phy = &dev->phy;
950 struct b43_phy_ht *phy_ht = phy->ht;
951
952 kfree(phy_ht);
953 phy->ht = NULL;
954}
955
Rafał Miłeckie7c62552011-06-19 02:18:11 +0200956/* http://bcm-v4.sipsolutions.net/802.11/Radio/Switch%20Radio */
957static void b43_phy_ht_op_software_rfkill(struct b43_wldev *dev,
958 bool blocked)
959{
960 if (b43_read32(dev, B43_MMIO_MACCTL) & B43_MACCTL_ENABLED)
961 b43err(dev->wl, "MAC not suspended\n");
962
Rafał Miłecki0b5dd732011-07-18 02:13:23 +0200963 /* In the following PHY ops we copy wl's dummy behaviour.
964 * TODO: Find out if reads (currently hidden in masks/masksets) are
965 * needed and replace following ops with just writes or w&r.
966 * Note: B43_PHY_HT_RF_CTL1 register is tricky, wrong operation can
967 * cause delayed (!) machine lock up. */
Rafał Miłeckie7c62552011-06-19 02:18:11 +0200968 if (blocked) {
Rafał Miłecki0b5dd732011-07-18 02:13:23 +0200969 b43_phy_mask(dev, B43_PHY_HT_RF_CTL1, 0);
Rafał Miłeckie7c62552011-06-19 02:18:11 +0200970 } else {
Rafał Miłecki0b5dd732011-07-18 02:13:23 +0200971 b43_phy_mask(dev, B43_PHY_HT_RF_CTL1, 0);
972 b43_phy_maskset(dev, B43_PHY_HT_RF_CTL1, 0, 0x1);
973 b43_phy_mask(dev, B43_PHY_HT_RF_CTL1, 0);
974 b43_phy_maskset(dev, B43_PHY_HT_RF_CTL1, 0, 0x2);
Rafał Miłecki3e644ab2011-06-28 00:08:53 +0200975
976 if (dev->phy.radio_ver == 0x2059)
977 b43_radio_2059_init(dev);
978 else
979 B43_WARN_ON(1);
Rafał Miłecki315a6852011-07-17 10:30:32 +0200980
981 b43_switch_channel(dev, dev->phy.channel);
Rafał Miłeckie7c62552011-06-19 02:18:11 +0200982 }
983}
984
Rafał Miłeckia8e82742011-06-16 01:59:20 +0200985static void b43_phy_ht_op_switch_analog(struct b43_wldev *dev, bool on)
986{
987 if (on) {
Rafał Miłecki47606922013-03-09 13:43:49 +0100988 b43_phy_write(dev, B43_PHY_HT_AFE_C1, 0x00cd);
989 b43_phy_write(dev, B43_PHY_HT_AFE_C1_OVER, 0x0000);
990 b43_phy_write(dev, B43_PHY_HT_AFE_C2, 0x00cd);
991 b43_phy_write(dev, B43_PHY_HT_AFE_C2_OVER, 0x0000);
992 b43_phy_write(dev, B43_PHY_HT_AFE_C3, 0x00cd);
993 b43_phy_write(dev, B43_PHY_HT_AFE_C3_OVER, 0x0000);
Rafał Miłeckia8e82742011-06-16 01:59:20 +0200994 } else {
Rafał Miłecki47606922013-03-09 13:43:49 +0100995 b43_phy_write(dev, B43_PHY_HT_AFE_C1_OVER, 0x07ff);
996 b43_phy_write(dev, B43_PHY_HT_AFE_C1, 0x00fd);
997 b43_phy_write(dev, B43_PHY_HT_AFE_C2_OVER, 0x07ff);
998 b43_phy_write(dev, B43_PHY_HT_AFE_C2, 0x00fd);
999 b43_phy_write(dev, B43_PHY_HT_AFE_C3_OVER, 0x07ff);
1000 b43_phy_write(dev, B43_PHY_HT_AFE_C3, 0x00fd);
Rafał Miłeckia8e82742011-06-16 01:59:20 +02001001 }
1002}
1003
Rafał Miłecki39ca5542011-06-19 12:17:20 +02001004static int b43_phy_ht_op_switch_channel(struct b43_wldev *dev,
1005 unsigned int new_channel)
1006{
Karl Beldan675a0b02013-03-25 16:26:57 +01001007 struct ieee80211_channel *channel = dev->wl->hw->conf.chandef.chan;
1008 enum nl80211_channel_type channel_type =
1009 cfg80211_get_chandef_type(&dev->wl->hw->conf.chandef);
Rafał Miłecki39ca5542011-06-19 12:17:20 +02001010
1011 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
1012 if ((new_channel < 1) || (new_channel > 14))
1013 return -EINVAL;
1014 } else {
1015 return -EINVAL;
1016 }
1017
1018 return b43_phy_ht_set_channel(dev, channel, channel_type);
1019}
1020
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001021static unsigned int b43_phy_ht_op_get_default_chan(struct b43_wldev *dev)
1022{
1023 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ)
Rafał Miłecki315a6852011-07-17 10:30:32 +02001024 return 11;
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001025 return 36;
1026}
1027
1028/**************************************************
1029 * R/W ops.
1030 **************************************************/
1031
1032static u16 b43_phy_ht_op_read(struct b43_wldev *dev, u16 reg)
1033{
1034 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
1035 return b43_read16(dev, B43_MMIO_PHY_DATA);
1036}
1037
1038static void b43_phy_ht_op_write(struct b43_wldev *dev, u16 reg, u16 value)
1039{
1040 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
1041 b43_write16(dev, B43_MMIO_PHY_DATA, value);
1042}
1043
1044static void b43_phy_ht_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
1045 u16 set)
1046{
1047 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
1048 b43_write16(dev, B43_MMIO_PHY_DATA,
1049 (b43_read16(dev, B43_MMIO_PHY_DATA) & mask) | set);
1050}
1051
Rafał Miłecki4cabd422011-06-16 01:59:19 +02001052static u16 b43_phy_ht_op_radio_read(struct b43_wldev *dev, u16 reg)
1053{
1054 /* HT-PHY needs 0x200 for read access */
1055 reg |= 0x200;
1056
1057 b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
1058 return b43_read16(dev, B43_MMIO_RADIO24_DATA);
1059}
1060
1061static void b43_phy_ht_op_radio_write(struct b43_wldev *dev, u16 reg,
1062 u16 value)
1063{
1064 b43_write16(dev, B43_MMIO_RADIO24_CONTROL, reg);
1065 b43_write16(dev, B43_MMIO_RADIO24_DATA, value);
1066}
1067
Rafał Miłecki21a18f22011-07-07 20:06:56 +02001068static enum b43_txpwr_result
1069b43_phy_ht_op_recalc_txpower(struct b43_wldev *dev, bool ignore_tssi)
1070{
1071 return B43_TXPWR_RES_DONE;
1072}
1073
1074static void b43_phy_ht_op_adjust_txpower(struct b43_wldev *dev)
1075{
1076}
1077
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001078/**************************************************
1079 * PHY ops struct.
1080 **************************************************/
1081
1082const struct b43_phy_operations b43_phyops_ht = {
1083 .allocate = b43_phy_ht_op_allocate,
1084 .free = b43_phy_ht_op_free,
1085 .prepare_structs = b43_phy_ht_op_prepare_structs,
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001086 .init = b43_phy_ht_op_init,
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001087 .phy_read = b43_phy_ht_op_read,
1088 .phy_write = b43_phy_ht_op_write,
1089 .phy_maskset = b43_phy_ht_op_maskset,
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001090 .radio_read = b43_phy_ht_op_radio_read,
1091 .radio_write = b43_phy_ht_op_radio_write,
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001092 .software_rfkill = b43_phy_ht_op_software_rfkill,
1093 .switch_analog = b43_phy_ht_op_switch_analog,
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001094 .switch_channel = b43_phy_ht_op_switch_channel,
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001095 .get_default_chan = b43_phy_ht_op_get_default_chan,
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001096 .recalc_txpower = b43_phy_ht_op_recalc_txpower,
1097 .adjust_txpower = b43_phy_ht_op_adjust_txpower,
Rafał Miłeckid7520b12011-06-13 16:20:06 +02001098};