blob: 99cc9739aceddeb6f773f7f199a38fc227f1eeb8 [file] [log] [blame]
Michael Buesche63e4362008-08-30 10:55:48 +02001/*
2
3 Broadcom B43 wireless driver
4 IEEE 802.11g LP-PHY driver
5
Michael Buesch6c1bb922009-01-31 16:52:29 +01006 Copyright (c) 2008-2009 Michael Buesch <mb@bu3sch.de>
Michael Buesche63e4362008-08-30 10:55:48 +02007
8 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 "b43.h"
26#include "phy_lp.h"
27#include "phy_common.h"
Michael Buesch6c1bb922009-01-31 16:52:29 +010028#include "tables_lpphy.h"
Michael Buesche63e4362008-08-30 10:55:48 +020029
30
31static int b43_lpphy_op_allocate(struct b43_wldev *dev)
32{
33 struct b43_phy_lp *lpphy;
34
35 lpphy = kzalloc(sizeof(*lpphy), GFP_KERNEL);
36 if (!lpphy)
37 return -ENOMEM;
38 dev->phy.lp = lpphy;
39
Michael Buesche63e4362008-08-30 10:55:48 +020040 return 0;
41}
42
Michael Bueschfb111372008-09-02 13:00:34 +020043static void b43_lpphy_op_prepare_structs(struct b43_wldev *dev)
44{
45 struct b43_phy *phy = &dev->phy;
46 struct b43_phy_lp *lpphy = phy->lp;
47
48 memset(lpphy, 0, sizeof(*lpphy));
49
50 //TODO
51}
52
53static void b43_lpphy_op_free(struct b43_wldev *dev)
54{
55 struct b43_phy_lp *lpphy = dev->phy.lp;
56
57 kfree(lpphy);
58 dev->phy.lp = NULL;
59}
60
Michael Buescha387cc72009-01-31 14:20:44 +010061static void lpphy_table_init(struct b43_wldev *dev)
62{
63 //TODO
64}
65
66static void lpphy_baseband_rev0_1_init(struct b43_wldev *dev)
67{
68 B43_WARN_ON(1);//TODO rev < 2 not supported, yet.
69}
70
71static void lpphy_baseband_rev2plus_init(struct b43_wldev *dev)
72{
Michael Buesch6c1bb922009-01-31 16:52:29 +010073 struct b43_phy_lp *lpphy = dev->phy.lp;
74
75 b43_phy_write(dev, B43_LPPHY_AFE_DAC_CTL, 0x50);
76 b43_phy_write(dev, B43_LPPHY_AFE_CTL, 0x8800);
77 b43_phy_write(dev, B43_LPPHY_AFE_CTL_OVR, 0);
78 b43_phy_write(dev, B43_LPPHY_AFE_CTL_OVRVAL, 0);
79 b43_phy_write(dev, B43_LPPHY_RF_OVERRIDE_0, 0);
80 b43_phy_write(dev, B43_LPPHY_RF_OVERRIDE_2, 0);
81 b43_phy_write(dev, B43_PHY_OFDM(0xF9), 0);
82 b43_phy_write(dev, B43_LPPHY_TR_LOOKUP_1, 0);
83 b43_phy_set(dev, B43_LPPHY_ADC_COMPENSATION_CTL, 0x10);
84 b43_phy_maskset(dev, B43_LPPHY_OFDMSYNCTHRESH0, 0xFF00, 0x78);
85 b43_phy_maskset(dev, B43_LPPHY_DCOFFSETTRANSIENT, 0xF8FF, 0x200);
86 b43_phy_maskset(dev, B43_LPPHY_DCOFFSETTRANSIENT, 0xFF00, 0x7F);
87 b43_phy_maskset(dev, B43_LPPHY_GAINDIRECTMISMATCH, 0xFF0F, 0x40);
88 b43_phy_maskset(dev, B43_LPPHY_PREAMBLECONFIRMTO, 0xFF00, 0x2);
89 b43_phy_mask(dev, B43_LPPHY_CRSGAIN_CTL, ~0x4000);
90 b43_phy_mask(dev, B43_LPPHY_CRSGAIN_CTL, ~0x2000);
91 b43_phy_set(dev, B43_PHY_OFDM(0x10A), 0x1);
92 b43_phy_maskset(dev, B43_LPPHY_CCKLMSSTEPSIZE, 0xFF01, 0x10);
93 b43_phy_maskset(dev, B43_PHY_OFDM(0xDF), 0xFF00, 0xF4);
Michael Buesch24b5bcc2009-01-31 19:34:53 +010094 b43_phy_maskset(dev, B43_PHY_OFDM(0xDF), 0x00FF, 0xF100);
Michael Buesch6c1bb922009-01-31 16:52:29 +010095 b43_phy_write(dev, B43_LPPHY_CLIPTHRESH, 0x48);
96 b43_phy_maskset(dev, B43_LPPHY_HIGAINDB, 0xFF00, 0x46);
97 b43_phy_maskset(dev, B43_PHY_OFDM(0xE4), 0xFF00, 0x10);
98 b43_phy_maskset(dev, B43_LPPHY_PWR_THRESH1, 0xFFF0, 0x9);
99 b43_phy_mask(dev, B43_LPPHY_GAINDIRECTMISMATCH, ~0xF);
100 b43_phy_maskset(dev, B43_LPPHY_VERYLOWGAINDB, 0x00FF, 0x5500);
101 b43_phy_maskset(dev, B43_LPPHY_CLIPCTRTHRESH, 0xF81F, 0xA0);
102 b43_phy_maskset(dev, B43_LPPHY_GAINDIRECTMISMATCH, 0xE0FF, 0x300);
103 b43_phy_maskset(dev, B43_LPPHY_HIGAINDB, 0x00FF, 0x2A00);
104 b43_phy_maskset(dev, B43_LPPHY_LOWGAINDB, 0x00FF, 0x1E00);
105 b43_phy_maskset(dev, B43_LPPHY_VERYLOWGAINDB, 0xFF00, 0xD);
106 b43_phy_maskset(dev, B43_PHY_OFDM(0xFE), 0xFFE0, 0x1F);
107 b43_phy_maskset(dev, B43_PHY_OFDM(0xFF), 0xFFE0, 0xC);
108 b43_phy_maskset(dev, B43_PHY_OFDM(0x100), 0xFF00, 0x19);
109 b43_phy_maskset(dev, B43_PHY_OFDM(0xFF), 0x03FF, 0x3C00);
110 b43_phy_maskset(dev, B43_PHY_OFDM(0xFE), 0xFC1F, 0x3E0);
111 b43_phy_maskset(dev, B43_PHY_OFDM(0xFF), 0xFFE0, 0xC);
112 b43_phy_maskset(dev, B43_PHY_OFDM(0x100), 0x00FF, 0x1900);
113 b43_phy_maskset(dev, B43_LPPHY_CLIPCTRTHRESH, 0x83FF, 0x5800);
114 b43_phy_maskset(dev, B43_LPPHY_CLIPCTRTHRESH, 0xFFE0, 0x12);
115 b43_phy_maskset(dev, B43_LPPHY_GAINMISMATCH, 0x0FFF, 0x9000);
116
117 if (dev->phy.rev < 2) {
118 //FIXME this will never execute.
119
120 //FIXME 32bit?
121 b43_lptab_write(dev, B43_LPTAB32(0x11, 0x14), 0);
122 b43_lptab_write(dev, B43_LPTAB32(0x08, 0x12), 0x40);
123 } else {
124 //FIXME 32bit?
125 b43_lptab_write(dev, B43_LPTAB32(0x08, 0x14), 0);
126 b43_lptab_write(dev, B43_LPTAB32(0x08, 0x12), 0x40);
127 }
128
129 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
130 b43_phy_set(dev, B43_LPPHY_CRSGAIN_CTL, 0x40);
131 b43_phy_maskset(dev, B43_LPPHY_CRSGAIN_CTL, 0xF0FF, 0xB00);
132 b43_phy_maskset(dev, B43_LPPHY_SYNCPEAKCNT, 0xFFF8, 0x6);
133 b43_phy_maskset(dev, B43_LPPHY_MINPWR_LEVEL, 0x00FF, 0x9D00);
134 b43_phy_maskset(dev, B43_LPPHY_MINPWR_LEVEL, 0xFF00, 0xA1);
135 } else /* 5GHz */
136 b43_phy_mask(dev, B43_LPPHY_CRSGAIN_CTL, ~0x40);
137
138 b43_phy_maskset(dev, B43_LPPHY_CRS_ED_THRESH, 0xFF00, 0xB3);
139 b43_phy_maskset(dev, B43_LPPHY_CRS_ED_THRESH, 0x00FF, 0xAD00);
140 b43_phy_maskset(dev, B43_LPPHY_INPUT_PWRDB, 0xFF00, lpphy->rx_pwr_offset);
141 b43_phy_set(dev, B43_LPPHY_RESET_CTL, 0x44);
142 b43_phy_write(dev, B43_LPPHY_RESET_CTL, 0x80);
143 b43_phy_write(dev, B43_LPPHY_AFE_RSSI_CTL_0, 0xA954);
144 b43_phy_write(dev, B43_LPPHY_AFE_RSSI_CTL_1,
145 0x2000 | ((u16)lpphy->rssi_gs << 10) |
146 ((u16)lpphy->rssi_vc << 4) | lpphy->rssi_vf);
Michael Buescha387cc72009-01-31 14:20:44 +0100147}
148
149static void lpphy_baseband_init(struct b43_wldev *dev)
150{
151 lpphy_table_init(dev);
152 if (dev->phy.rev >= 2)
153 lpphy_baseband_rev2plus_init(dev);
154 else
155 lpphy_baseband_rev0_1_init(dev);
156}
157
Michael Buesch24b5bcc2009-01-31 19:34:53 +0100158struct b2062_freqdata {
159 u16 freq;
160 u8 data[6];
161};
162
163/* Initialize the 2062 radio. */
164static void lpphy_2062_init(struct b43_wldev *dev)
165{
166 u32 crystalfreq, pdiv, tmp, ref;
167 unsigned int i;
168 const struct b2062_freqdata *fd = NULL;
169
170 static const struct b2062_freqdata freqdata_tab[] = {
171 { .freq = 12000, .data[0] = 6, .data[1] = 6, .data[2] = 6,
172 .data[3] = 6, .data[4] = 10, .data[5] = 6, },
173 { .freq = 13000, .data[0] = 4, .data[1] = 4, .data[2] = 4,
174 .data[3] = 4, .data[4] = 11, .data[5] = 7, },
175 { .freq = 14400, .data[0] = 3, .data[1] = 3, .data[2] = 3,
176 .data[3] = 3, .data[4] = 12, .data[5] = 7, },
177 { .freq = 16200, .data[0] = 3, .data[1] = 3, .data[2] = 3,
178 .data[3] = 3, .data[4] = 13, .data[5] = 8, },
179 { .freq = 18000, .data[0] = 2, .data[1] = 2, .data[2] = 2,
180 .data[3] = 2, .data[4] = 14, .data[5] = 8, },
181 { .freq = 19200, .data[0] = 1, .data[1] = 1, .data[2] = 1,
182 .data[3] = 1, .data[4] = 14, .data[5] = 9, },
183 };
184
185 b2062_upload_init_table(dev);
186
187 b43_radio_write(dev, B2062_N_TX_CTL3, 0);
188 b43_radio_write(dev, B2062_N_TX_CTL4, 0);
189 b43_radio_write(dev, B2062_N_TX_CTL5, 0);
190 b43_radio_write(dev, B2062_N_PDN_CTL0, 0x40);
191 b43_radio_write(dev, B2062_N_PDN_CTL0, 0);
192 b43_radio_write(dev, B2062_N_CALIB_TS, 0x10);
193 b43_radio_write(dev, B2062_N_CALIB_TS, 0);
194 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ)
195 b43_radio_set(dev, B2062_N_TSSI_CTL0, 0x1);
196 else
197 b43_radio_mask(dev, B2062_N_TSSI_CTL0, ~0x1);
198
199 crystalfreq = 0;//FIXME
200
201 if (crystalfreq >= 30000000) {
202 pdiv = 1;
203 b43_radio_mask(dev, B2062_S_RFPLL_CTL1, 0xFFFB);
204 } else {
205 pdiv = 2;
206 b43_radio_set(dev, B2062_S_RFPLL_CTL1, 0x4);
207 }
208
209 tmp = (800000000 * pdiv + crystalfreq) / (32000000 * pdiv);
210 tmp = (tmp - 1) & 0xFF;
211 b43_radio_write(dev, B2062_S_RFPLL_CTL18, tmp);
212
213 tmp = (2 * crystalfreq + 1000000 * pdiv) / (2000000 * pdiv);
214 tmp = ((tmp & 0xFF) - 1) & 0xFFFF;
215 b43_radio_write(dev, B2062_S_RFPLL_CTL19, tmp);
216
217 ref = (1000 * pdiv + 2 * crystalfreq) / (2000 * pdiv);
218 ref &= 0xFFFF;
219 for (i = 0; i < ARRAY_SIZE(freqdata_tab); i++) {
220 if (ref < freqdata_tab[i].freq) {
221 fd = &freqdata_tab[i];
222 break;
223 }
224 }
225 if (B43_WARN_ON(!fd))
226 return;
227
228 b43_radio_write(dev, B2062_S_RFPLL_CTL8,
229 ((u16)(fd->data[1]) << 4) | fd->data[0]);
230 b43_radio_write(dev, B2062_S_RFPLL_CTL9,
231 ((u16)(fd->data[3]) << 4) | fd->data[2]);//FIXME specs are different
232 b43_radio_write(dev, B2062_S_RFPLL_CTL10, fd->data[4]);
233 b43_radio_write(dev, B2062_S_RFPLL_CTL11, fd->data[5]);
234}
235
236/* Initialize the 2063 radio. */
237static void lpphy_2063_init(struct b43_wldev *dev)
Michael Buescha387cc72009-01-31 14:20:44 +0100238{
239 //TODO
240}
241
Michael Buesch24b5bcc2009-01-31 19:34:53 +0100242static void lpphy_sync_stx(struct b43_wldev *dev)
243{
244 //TODO
245}
246
247static void lpphy_radio_init(struct b43_wldev *dev)
248{
249 /* The radio is attached through the 4wire bus. */
250 b43_phy_set(dev, B43_LPPHY_FOURWIRE_CTL, 0x2);
251 udelay(1);
252 b43_phy_mask(dev, B43_LPPHY_FOURWIRE_CTL, 0xFFFD);
253 udelay(1);
254
255 if (dev->phy.rev < 2) {
256 lpphy_2062_init(dev);
257 } else {
258 lpphy_2063_init(dev);
259 lpphy_sync_stx(dev);
260 b43_phy_write(dev, B43_PHY_OFDM(0xF0), 0x5F80);
261 b43_phy_write(dev, B43_PHY_OFDM(0xF1), 0);
262 //TODO Do something on the backplane
263 }
264}
265
Michael Buesche63e4362008-08-30 10:55:48 +0200266static int b43_lpphy_op_init(struct b43_wldev *dev)
267{
Michael Buescha387cc72009-01-31 14:20:44 +0100268 /* TODO: band SPROM */
269 lpphy_baseband_init(dev);
270 lpphy_radio_init(dev);
271
Michael Buesche63e4362008-08-30 10:55:48 +0200272 //TODO
Michael Buesche63e4362008-08-30 10:55:48 +0200273
274 return 0;
275}
276
Michael Buesche63e4362008-08-30 10:55:48 +0200277static u16 b43_lpphy_op_read(struct b43_wldev *dev, u16 reg)
278{
Michael Buesch08887072008-08-30 11:49:45 +0200279 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
280 return b43_read16(dev, B43_MMIO_PHY_DATA);
Michael Buesche63e4362008-08-30 10:55:48 +0200281}
282
283static void b43_lpphy_op_write(struct b43_wldev *dev, u16 reg, u16 value)
284{
Michael Buesch08887072008-08-30 11:49:45 +0200285 b43_write16(dev, B43_MMIO_PHY_CONTROL, reg);
286 b43_write16(dev, B43_MMIO_PHY_DATA, value);
Michael Buesche63e4362008-08-30 10:55:48 +0200287}
288
289static u16 b43_lpphy_op_radio_read(struct b43_wldev *dev, u16 reg)
290{
Michael Buesch08887072008-08-30 11:49:45 +0200291 /* Register 1 is a 32-bit register. */
292 B43_WARN_ON(reg == 1);
293 /* LP-PHY needs a special bit set for read access */
294 if (dev->phy.rev < 2) {
295 if (reg != 0x4001)
296 reg |= 0x100;
297 } else
298 reg |= 0x200;
299
300 b43_write16(dev, B43_MMIO_RADIO_CONTROL, reg);
301 return b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
Michael Buesche63e4362008-08-30 10:55:48 +0200302}
303
304static void b43_lpphy_op_radio_write(struct b43_wldev *dev, u16 reg, u16 value)
305{
306 /* Register 1 is a 32-bit register. */
307 B43_WARN_ON(reg == 1);
308
Michael Buesch08887072008-08-30 11:49:45 +0200309 b43_write16(dev, B43_MMIO_RADIO_CONTROL, reg);
310 b43_write16(dev, B43_MMIO_RADIO_DATA_LOW, value);
Michael Buesche63e4362008-08-30 10:55:48 +0200311}
312
313static void b43_lpphy_op_software_rfkill(struct b43_wldev *dev,
314 enum rfkill_state state)
315{
316 //TODO
317}
318
319static int b43_lpphy_op_switch_channel(struct b43_wldev *dev,
320 unsigned int new_channel)
321{
322 //TODO
323 return 0;
324}
325
326static unsigned int b43_lpphy_op_get_default_chan(struct b43_wldev *dev)
327{
Michael Buesch24b5bcc2009-01-31 19:34:53 +0100328 if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ)
329 return 1;
330 return 36;
Michael Buesche63e4362008-08-30 10:55:48 +0200331}
332
333static void b43_lpphy_op_set_rx_antenna(struct b43_wldev *dev, int antenna)
334{
335 //TODO
336}
337
338static void b43_lpphy_op_adjust_txpower(struct b43_wldev *dev)
339{
340 //TODO
341}
342
343static enum b43_txpwr_result b43_lpphy_op_recalc_txpower(struct b43_wldev *dev,
344 bool ignore_tssi)
345{
346 //TODO
347 return B43_TXPWR_RES_DONE;
348}
349
350
351const struct b43_phy_operations b43_phyops_lp = {
352 .allocate = b43_lpphy_op_allocate,
Michael Bueschfb111372008-09-02 13:00:34 +0200353 .free = b43_lpphy_op_free,
354 .prepare_structs = b43_lpphy_op_prepare_structs,
Michael Buesche63e4362008-08-30 10:55:48 +0200355 .init = b43_lpphy_op_init,
Michael Buesche63e4362008-08-30 10:55:48 +0200356 .phy_read = b43_lpphy_op_read,
357 .phy_write = b43_lpphy_op_write,
358 .radio_read = b43_lpphy_op_radio_read,
359 .radio_write = b43_lpphy_op_radio_write,
360 .software_rfkill = b43_lpphy_op_software_rfkill,
Michael Bueschcb24f572008-09-03 12:12:20 +0200361 .switch_analog = b43_phyop_switch_analog_generic,
Michael Buesche63e4362008-08-30 10:55:48 +0200362 .switch_channel = b43_lpphy_op_switch_channel,
363 .get_default_chan = b43_lpphy_op_get_default_chan,
364 .set_rx_antenna = b43_lpphy_op_set_rx_antenna,
365 .recalc_txpower = b43_lpphy_op_recalc_txpower,
366 .adjust_txpower = b43_lpphy_op_adjust_txpower,
367};