2 * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
3 * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com>
4 * Copyright (c) 2008-2009 Felix Fietkau <nbd@openwrt.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 /*************************************\
21 * EEPROM access functions and helpers *
22 \*************************************/
32 static int ath5k_hw_eeprom_read(struct ath5k_hw
*ah
, u32 offset
, u16
*data
)
36 ATH5K_TRACE(ah
->ah_sc
);
38 * Initialize EEPROM access
40 if (ah
->ah_version
== AR5K_AR5210
) {
41 AR5K_REG_ENABLE_BITS(ah
, AR5K_PCICFG
, AR5K_PCICFG_EEAE
);
42 (void)ath5k_hw_reg_read(ah
, AR5K_EEPROM_BASE
+ (4 * offset
));
44 ath5k_hw_reg_write(ah
, offset
, AR5K_EEPROM_BASE
);
45 AR5K_REG_ENABLE_BITS(ah
, AR5K_EEPROM_CMD
,
46 AR5K_EEPROM_CMD_READ
);
49 for (timeout
= AR5K_TUNE_REGISTER_TIMEOUT
; timeout
> 0; timeout
--) {
50 status
= ath5k_hw_reg_read(ah
, AR5K_EEPROM_STATUS
);
51 if (status
& AR5K_EEPROM_STAT_RDDONE
) {
52 if (status
& AR5K_EEPROM_STAT_RDERR
)
54 *data
= (u16
)(ath5k_hw_reg_read(ah
, AR5K_EEPROM_DATA
) &
65 * Translate binary channel representation in EEPROM to frequency
67 static u16
ath5k_eeprom_bin2freq(struct ath5k_eeprom_info
*ee
, u16 bin
,
72 if (bin
== AR5K_EEPROM_CHANNEL_DIS
)
75 if (mode
== AR5K_EEPROM_MODE_11A
) {
76 if (ee
->ee_version
> AR5K_EEPROM_VERSION_3_2
)
77 val
= (5 * bin
) + 4800;
79 val
= bin
> 62 ? (10 * 62) + (5 * (bin
- 62)) + 5100 :
82 if (ee
->ee_version
> AR5K_EEPROM_VERSION_3_2
)
92 * Initialize eeprom & capabilities structs
95 ath5k_eeprom_init_header(struct ath5k_hw
*ah
)
97 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
102 * Read values from EEPROM and store them in the capability structure
104 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC
, ee_magic
);
105 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT
, ee_protect
);
106 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN
, ee_regdomain
);
107 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION
, ee_version
);
108 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR
, ee_header
);
110 /* Return if we have an old EEPROM */
111 if (ah
->ah_ee_version
< AR5K_EEPROM_VERSION_3_0
)
116 * Validate the checksum of the EEPROM date. There are some
117 * devices with invalid EEPROMs.
119 for (cksum
= 0, offset
= 0; offset
< AR5K_EEPROM_INFO_MAX
; offset
++) {
120 AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset
), val
);
123 if (cksum
!= AR5K_EEPROM_INFO_CKSUM
) {
124 ATH5K_ERR(ah
->ah_sc
, "Invalid EEPROM checksum 0x%04x\n", cksum
);
129 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah
->ah_ee_version
),
132 if (ah
->ah_ee_version
>= AR5K_EEPROM_VERSION_4_0
) {
133 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0
, ee_misc0
);
134 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1
, ee_misc1
);
136 /* XXX: Don't know which versions include these two */
137 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC2
, ee_misc2
);
139 if (ee
->ee_version
>= AR5K_EEPROM_VERSION_4_3
)
140 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC3
, ee_misc3
);
142 if (ee
->ee_version
>= AR5K_EEPROM_VERSION_5_0
) {
143 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC4
, ee_misc4
);
144 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC5
, ee_misc5
);
145 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC6
, ee_misc6
);
149 if (ah
->ah_ee_version
< AR5K_EEPROM_VERSION_3_3
) {
150 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ
, val
);
151 ee
->ee_ob
[AR5K_EEPROM_MODE_11B
][0] = val
& 0x7;
152 ee
->ee_db
[AR5K_EEPROM_MODE_11B
][0] = (val
>> 3) & 0x7;
154 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ
, val
);
155 ee
->ee_ob
[AR5K_EEPROM_MODE_11G
][0] = val
& 0x7;
156 ee
->ee_db
[AR5K_EEPROM_MODE_11G
][0] = (val
>> 3) & 0x7;
159 AR5K_EEPROM_READ(AR5K_EEPROM_IS_HB63
, val
);
161 if ((ah
->ah_mac_version
== (AR5K_SREV_AR2425
>> 4)) && val
)
162 ee
->ee_is_hb63
= true;
164 ee
->ee_is_hb63
= false;
166 AR5K_EEPROM_READ(AR5K_EEPROM_RFKILL
, val
);
167 ee
->ee_rfkill_pin
= (u8
) AR5K_REG_MS(val
, AR5K_EEPROM_RFKILL_GPIO_SEL
);
168 ee
->ee_rfkill_pol
= val
& AR5K_EEPROM_RFKILL_POLARITY
? true : false;
170 /* Check if PCIE_OFFSET points to PCIE_SERDES_SECTION
171 * and enable serdes programming if needed.
173 * XXX: Serdes values seem to be fixed so
174 * no need to read them here, we write them
175 * during ath5k_hw_attach */
176 AR5K_EEPROM_READ(AR5K_EEPROM_PCIE_OFFSET
, val
);
177 ee
->ee_serdes
= (val
== AR5K_EEPROM_PCIE_SERDES_SECTION
) ?
185 * Read antenna infos from eeprom
187 static int ath5k_eeprom_read_ants(struct ath5k_hw
*ah
, u32
*offset
,
190 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
195 AR5K_EEPROM_READ(o
++, val
);
196 ee
->ee_switch_settling
[mode
] = (val
>> 8) & 0x7f;
197 ee
->ee_atn_tx_rx
[mode
] = (val
>> 2) & 0x3f;
198 ee
->ee_ant_control
[mode
][i
] = (val
<< 4) & 0x3f;
200 AR5K_EEPROM_READ(o
++, val
);
201 ee
->ee_ant_control
[mode
][i
++] |= (val
>> 12) & 0xf;
202 ee
->ee_ant_control
[mode
][i
++] = (val
>> 6) & 0x3f;
203 ee
->ee_ant_control
[mode
][i
++] = val
& 0x3f;
205 AR5K_EEPROM_READ(o
++, val
);
206 ee
->ee_ant_control
[mode
][i
++] = (val
>> 10) & 0x3f;
207 ee
->ee_ant_control
[mode
][i
++] = (val
>> 4) & 0x3f;
208 ee
->ee_ant_control
[mode
][i
] = (val
<< 2) & 0x3f;
210 AR5K_EEPROM_READ(o
++, val
);
211 ee
->ee_ant_control
[mode
][i
++] |= (val
>> 14) & 0x3;
212 ee
->ee_ant_control
[mode
][i
++] = (val
>> 8) & 0x3f;
213 ee
->ee_ant_control
[mode
][i
++] = (val
>> 2) & 0x3f;
214 ee
->ee_ant_control
[mode
][i
] = (val
<< 4) & 0x3f;
216 AR5K_EEPROM_READ(o
++, val
);
217 ee
->ee_ant_control
[mode
][i
++] |= (val
>> 12) & 0xf;
218 ee
->ee_ant_control
[mode
][i
++] = (val
>> 6) & 0x3f;
219 ee
->ee_ant_control
[mode
][i
++] = val
& 0x3f;
221 /* Get antenna switch tables */
222 ah
->ah_ant_ctl
[mode
][AR5K_ANT_CTL
] =
223 (ee
->ee_ant_control
[mode
][0] << 4);
224 ah
->ah_ant_ctl
[mode
][AR5K_ANT_SWTABLE_A
] =
225 ee
->ee_ant_control
[mode
][1] |
226 (ee
->ee_ant_control
[mode
][2] << 6) |
227 (ee
->ee_ant_control
[mode
][3] << 12) |
228 (ee
->ee_ant_control
[mode
][4] << 18) |
229 (ee
->ee_ant_control
[mode
][5] << 24);
230 ah
->ah_ant_ctl
[mode
][AR5K_ANT_SWTABLE_B
] =
231 ee
->ee_ant_control
[mode
][6] |
232 (ee
->ee_ant_control
[mode
][7] << 6) |
233 (ee
->ee_ant_control
[mode
][8] << 12) |
234 (ee
->ee_ant_control
[mode
][9] << 18) |
235 (ee
->ee_ant_control
[mode
][10] << 24);
237 /* return new offset */
244 * Read supported modes and some mode-specific calibration data
247 static int ath5k_eeprom_read_modes(struct ath5k_hw
*ah
, u32
*offset
,
250 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
255 ee
->ee_n_piers
[mode
] = 0;
256 AR5K_EEPROM_READ(o
++, val
);
257 ee
->ee_adc_desired_size
[mode
] = (s8
)((val
>> 8) & 0xff);
259 case AR5K_EEPROM_MODE_11A
:
260 ee
->ee_ob
[mode
][3] = (val
>> 5) & 0x7;
261 ee
->ee_db
[mode
][3] = (val
>> 2) & 0x7;
262 ee
->ee_ob
[mode
][2] = (val
<< 1) & 0x7;
264 AR5K_EEPROM_READ(o
++, val
);
265 ee
->ee_ob
[mode
][2] |= (val
>> 15) & 0x1;
266 ee
->ee_db
[mode
][2] = (val
>> 12) & 0x7;
267 ee
->ee_ob
[mode
][1] = (val
>> 9) & 0x7;
268 ee
->ee_db
[mode
][1] = (val
>> 6) & 0x7;
269 ee
->ee_ob
[mode
][0] = (val
>> 3) & 0x7;
270 ee
->ee_db
[mode
][0] = val
& 0x7;
272 case AR5K_EEPROM_MODE_11G
:
273 case AR5K_EEPROM_MODE_11B
:
274 ee
->ee_ob
[mode
][1] = (val
>> 4) & 0x7;
275 ee
->ee_db
[mode
][1] = val
& 0x7;
279 AR5K_EEPROM_READ(o
++, val
);
280 ee
->ee_tx_end2xlna_enable
[mode
] = (val
>> 8) & 0xff;
281 ee
->ee_thr_62
[mode
] = val
& 0xff;
283 if (ah
->ah_ee_version
<= AR5K_EEPROM_VERSION_3_2
)
284 ee
->ee_thr_62
[mode
] = mode
== AR5K_EEPROM_MODE_11A
? 15 : 28;
286 AR5K_EEPROM_READ(o
++, val
);
287 ee
->ee_tx_end2xpa_disable
[mode
] = (val
>> 8) & 0xff;
288 ee
->ee_tx_frm2xpa_enable
[mode
] = val
& 0xff;
290 AR5K_EEPROM_READ(o
++, val
);
291 ee
->ee_pga_desired_size
[mode
] = (val
>> 8) & 0xff;
293 if ((val
& 0xff) & 0x80)
294 ee
->ee_noise_floor_thr
[mode
] = -((((val
& 0xff) ^ 0xff)) + 1);
296 ee
->ee_noise_floor_thr
[mode
] = val
& 0xff;
298 if (ah
->ah_ee_version
<= AR5K_EEPROM_VERSION_3_2
)
299 ee
->ee_noise_floor_thr
[mode
] =
300 mode
== AR5K_EEPROM_MODE_11A
? -54 : -1;
302 AR5K_EEPROM_READ(o
++, val
);
303 ee
->ee_xlna_gain
[mode
] = (val
>> 5) & 0xff;
304 ee
->ee_x_gain
[mode
] = (val
>> 1) & 0xf;
305 ee
->ee_xpd
[mode
] = val
& 0x1;
307 if (ah
->ah_ee_version
>= AR5K_EEPROM_VERSION_4_0
)
308 ee
->ee_fixed_bias
[mode
] = (val
>> 13) & 0x1;
310 if (ah
->ah_ee_version
>= AR5K_EEPROM_VERSION_3_3
) {
311 AR5K_EEPROM_READ(o
++, val
);
312 ee
->ee_false_detect
[mode
] = (val
>> 6) & 0x7f;
314 if (mode
== AR5K_EEPROM_MODE_11A
)
315 ee
->ee_xr_power
[mode
] = val
& 0x3f;
317 ee
->ee_ob
[mode
][0] = val
& 0x7;
318 ee
->ee_db
[mode
][0] = (val
>> 3) & 0x7;
322 if (ah
->ah_ee_version
< AR5K_EEPROM_VERSION_3_4
) {
323 ee
->ee_i_gain
[mode
] = AR5K_EEPROM_I_GAIN
;
324 ee
->ee_cck_ofdm_power_delta
= AR5K_EEPROM_CCK_OFDM_DELTA
;
326 ee
->ee_i_gain
[mode
] = (val
>> 13) & 0x7;
328 AR5K_EEPROM_READ(o
++, val
);
329 ee
->ee_i_gain
[mode
] |= (val
<< 3) & 0x38;
331 if (mode
== AR5K_EEPROM_MODE_11G
) {
332 ee
->ee_cck_ofdm_power_delta
= (val
>> 3) & 0xff;
333 if (ah
->ah_ee_version
>= AR5K_EEPROM_VERSION_4_6
)
334 ee
->ee_scaled_cck_delta
= (val
>> 11) & 0x1f;
338 if (ah
->ah_ee_version
>= AR5K_EEPROM_VERSION_4_0
&&
339 mode
== AR5K_EEPROM_MODE_11A
) {
340 ee
->ee_i_cal
[mode
] = (val
>> 8) & 0x3f;
341 ee
->ee_q_cal
[mode
] = (val
>> 3) & 0x1f;
344 if (ah
->ah_ee_version
< AR5K_EEPROM_VERSION_4_0
)
347 /* Note: >= v5 have bg freq piers on another location
348 * so these freq piers are ignored for >= v5 (should be 0xff
351 case AR5K_EEPROM_MODE_11A
:
352 if (ah
->ah_ee_version
< AR5K_EEPROM_VERSION_4_1
)
355 AR5K_EEPROM_READ(o
++, val
);
356 ee
->ee_margin_tx_rx
[mode
] = val
& 0x3f;
358 case AR5K_EEPROM_MODE_11B
:
359 AR5K_EEPROM_READ(o
++, val
);
361 ee
->ee_pwr_cal_b
[0].freq
=
362 ath5k_eeprom_bin2freq(ee
, val
& 0xff, mode
);
363 if (ee
->ee_pwr_cal_b
[0].freq
!= AR5K_EEPROM_CHANNEL_DIS
)
364 ee
->ee_n_piers
[mode
]++;
366 ee
->ee_pwr_cal_b
[1].freq
=
367 ath5k_eeprom_bin2freq(ee
, (val
>> 8) & 0xff, mode
);
368 if (ee
->ee_pwr_cal_b
[1].freq
!= AR5K_EEPROM_CHANNEL_DIS
)
369 ee
->ee_n_piers
[mode
]++;
371 AR5K_EEPROM_READ(o
++, val
);
372 ee
->ee_pwr_cal_b
[2].freq
=
373 ath5k_eeprom_bin2freq(ee
, val
& 0xff, mode
);
374 if (ee
->ee_pwr_cal_b
[2].freq
!= AR5K_EEPROM_CHANNEL_DIS
)
375 ee
->ee_n_piers
[mode
]++;
377 if (ah
->ah_ee_version
>= AR5K_EEPROM_VERSION_4_1
)
378 ee
->ee_margin_tx_rx
[mode
] = (val
>> 8) & 0x3f;
380 case AR5K_EEPROM_MODE_11G
:
381 AR5K_EEPROM_READ(o
++, val
);
383 ee
->ee_pwr_cal_g
[0].freq
=
384 ath5k_eeprom_bin2freq(ee
, val
& 0xff, mode
);
385 if (ee
->ee_pwr_cal_g
[0].freq
!= AR5K_EEPROM_CHANNEL_DIS
)
386 ee
->ee_n_piers
[mode
]++;
388 ee
->ee_pwr_cal_g
[1].freq
=
389 ath5k_eeprom_bin2freq(ee
, (val
>> 8) & 0xff, mode
);
390 if (ee
->ee_pwr_cal_g
[1].freq
!= AR5K_EEPROM_CHANNEL_DIS
)
391 ee
->ee_n_piers
[mode
]++;
393 AR5K_EEPROM_READ(o
++, val
);
394 ee
->ee_turbo_max_power
[mode
] = val
& 0x7f;
395 ee
->ee_xr_power
[mode
] = (val
>> 7) & 0x3f;
397 AR5K_EEPROM_READ(o
++, val
);
398 ee
->ee_pwr_cal_g
[2].freq
=
399 ath5k_eeprom_bin2freq(ee
, val
& 0xff, mode
);
400 if (ee
->ee_pwr_cal_g
[2].freq
!= AR5K_EEPROM_CHANNEL_DIS
)
401 ee
->ee_n_piers
[mode
]++;
403 if (ah
->ah_ee_version
>= AR5K_EEPROM_VERSION_4_1
)
404 ee
->ee_margin_tx_rx
[mode
] = (val
>> 8) & 0x3f;
406 AR5K_EEPROM_READ(o
++, val
);
407 ee
->ee_i_cal
[mode
] = (val
>> 8) & 0x3f;
408 ee
->ee_q_cal
[mode
] = (val
>> 3) & 0x1f;
410 if (ah
->ah_ee_version
>= AR5K_EEPROM_VERSION_4_2
) {
411 AR5K_EEPROM_READ(o
++, val
);
412 ee
->ee_cck_ofdm_gain_delta
= val
& 0xff;
418 * Read turbo mode information on newer EEPROM versions
420 if (ee
->ee_version
< AR5K_EEPROM_VERSION_5_0
)
424 case AR5K_EEPROM_MODE_11A
:
425 ee
->ee_switch_settling_turbo
[mode
] = (val
>> 6) & 0x7f;
427 ee
->ee_atn_tx_rx_turbo
[mode
] = (val
>> 13) & 0x7;
428 AR5K_EEPROM_READ(o
++, val
);
429 ee
->ee_atn_tx_rx_turbo
[mode
] |= (val
& 0x7) << 3;
430 ee
->ee_margin_tx_rx_turbo
[mode
] = (val
>> 3) & 0x3f;
432 ee
->ee_adc_desired_size_turbo
[mode
] = (val
>> 9) & 0x7f;
433 AR5K_EEPROM_READ(o
++, val
);
434 ee
->ee_adc_desired_size_turbo
[mode
] |= (val
& 0x1) << 7;
435 ee
->ee_pga_desired_size_turbo
[mode
] = (val
>> 1) & 0xff;
437 if (AR5K_EEPROM_EEMAP(ee
->ee_misc0
) >=2)
438 ee
->ee_pd_gain_overlap
= (val
>> 9) & 0xf;
440 case AR5K_EEPROM_MODE_11G
:
441 ee
->ee_switch_settling_turbo
[mode
] = (val
>> 8) & 0x7f;
443 ee
->ee_atn_tx_rx_turbo
[mode
] = (val
>> 15) & 0x7;
444 AR5K_EEPROM_READ(o
++, val
);
445 ee
->ee_atn_tx_rx_turbo
[mode
] |= (val
& 0x1f) << 1;
446 ee
->ee_margin_tx_rx_turbo
[mode
] = (val
>> 5) & 0x3f;
448 ee
->ee_adc_desired_size_turbo
[mode
] = (val
>> 11) & 0x7f;
449 AR5K_EEPROM_READ(o
++, val
);
450 ee
->ee_adc_desired_size_turbo
[mode
] |= (val
& 0x7) << 5;
451 ee
->ee_pga_desired_size_turbo
[mode
] = (val
>> 3) & 0xff;
456 /* return new offset */
462 /* Read mode-specific data (except power calibration data) */
464 ath5k_eeprom_init_modes(struct ath5k_hw
*ah
)
466 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
473 * Get values for all modes
475 mode_offset
[AR5K_EEPROM_MODE_11A
] = AR5K_EEPROM_MODES_11A(ah
->ah_ee_version
);
476 mode_offset
[AR5K_EEPROM_MODE_11B
] = AR5K_EEPROM_MODES_11B(ah
->ah_ee_version
);
477 mode_offset
[AR5K_EEPROM_MODE_11G
] = AR5K_EEPROM_MODES_11G(ah
->ah_ee_version
);
479 ee
->ee_turbo_max_power
[AR5K_EEPROM_MODE_11A
] =
480 AR5K_EEPROM_HDR_T_5GHZ_DBM(ee
->ee_header
);
482 for (mode
= AR5K_EEPROM_MODE_11A
; mode
<= AR5K_EEPROM_MODE_11G
; mode
++) {
483 offset
= mode_offset
[mode
];
485 ret
= ath5k_eeprom_read_ants(ah
, &offset
, mode
);
489 ret
= ath5k_eeprom_read_modes(ah
, &offset
, mode
);
494 /* override for older eeprom versions for better performance */
495 if (ah
->ah_ee_version
<= AR5K_EEPROM_VERSION_3_2
) {
496 ee
->ee_thr_62
[AR5K_EEPROM_MODE_11A
] = 15;
497 ee
->ee_thr_62
[AR5K_EEPROM_MODE_11B
] = 28;
498 ee
->ee_thr_62
[AR5K_EEPROM_MODE_11G
] = 28;
504 /* Read the frequency piers for each mode (mostly used on newer eeproms with 0xff
507 ath5k_eeprom_read_freq_list(struct ath5k_hw
*ah
, int *offset
, int max
,
508 struct ath5k_chan_pcal_info
*pc
, unsigned int mode
)
510 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
517 ee
->ee_n_piers
[mode
] = 0;
519 AR5K_EEPROM_READ(o
++, val
);
525 pc
[i
++].freq
= ath5k_eeprom_bin2freq(ee
,
527 ee
->ee_n_piers
[mode
]++;
529 freq2
= (val
>> 8) & 0xff;
533 pc
[i
++].freq
= ath5k_eeprom_bin2freq(ee
,
535 ee
->ee_n_piers
[mode
]++;
538 /* return new offset */
544 /* Read frequency piers for 802.11a */
546 ath5k_eeprom_init_11a_pcal_freq(struct ath5k_hw
*ah
, int offset
)
548 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
549 struct ath5k_chan_pcal_info
*pcal
= ee
->ee_pwr_cal_a
;
554 if (ee
->ee_version
>= AR5K_EEPROM_VERSION_3_3
) {
555 ath5k_eeprom_read_freq_list(ah
, &offset
,
556 AR5K_EEPROM_N_5GHZ_CHAN
, pcal
,
557 AR5K_EEPROM_MODE_11A
);
559 mask
= AR5K_EEPROM_FREQ_M(ah
->ah_ee_version
);
561 AR5K_EEPROM_READ(offset
++, val
);
562 pcal
[0].freq
= (val
>> 9) & mask
;
563 pcal
[1].freq
= (val
>> 2) & mask
;
564 pcal
[2].freq
= (val
<< 5) & mask
;
566 AR5K_EEPROM_READ(offset
++, val
);
567 pcal
[2].freq
|= (val
>> 11) & 0x1f;
568 pcal
[3].freq
= (val
>> 4) & mask
;
569 pcal
[4].freq
= (val
<< 3) & mask
;
571 AR5K_EEPROM_READ(offset
++, val
);
572 pcal
[4].freq
|= (val
>> 13) & 0x7;
573 pcal
[5].freq
= (val
>> 6) & mask
;
574 pcal
[6].freq
= (val
<< 1) & mask
;
576 AR5K_EEPROM_READ(offset
++, val
);
577 pcal
[6].freq
|= (val
>> 15) & 0x1;
578 pcal
[7].freq
= (val
>> 8) & mask
;
579 pcal
[8].freq
= (val
>> 1) & mask
;
580 pcal
[9].freq
= (val
<< 6) & mask
;
582 AR5K_EEPROM_READ(offset
++, val
);
583 pcal
[9].freq
|= (val
>> 10) & 0x3f;
585 /* Fixed number of piers */
586 ee
->ee_n_piers
[AR5K_EEPROM_MODE_11A
] = 10;
588 for (i
= 0; i
< AR5K_EEPROM_N_5GHZ_CHAN
; i
++) {
589 pcal
[i
].freq
= ath5k_eeprom_bin2freq(ee
,
590 pcal
[i
].freq
, AR5K_EEPROM_MODE_11A
);
597 /* Read frequency piers for 802.11bg on eeprom versions >= 5 and eemap >= 2 */
599 ath5k_eeprom_init_11bg_2413(struct ath5k_hw
*ah
, unsigned int mode
, int offset
)
601 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
602 struct ath5k_chan_pcal_info
*pcal
;
605 case AR5K_EEPROM_MODE_11B
:
606 pcal
= ee
->ee_pwr_cal_b
;
608 case AR5K_EEPROM_MODE_11G
:
609 pcal
= ee
->ee_pwr_cal_g
;
615 ath5k_eeprom_read_freq_list(ah
, &offset
,
616 AR5K_EEPROM_N_2GHZ_CHAN_2413
, pcal
,
623 * Read power calibration for RF5111 chips
625 * For RF5111 we have an XPD -eXternal Power Detector- curve
626 * for each calibrated channel. Each curve has 0,5dB Power steps
627 * on x axis and PCDAC steps (offsets) on y axis and looks like an
628 * exponential function. To recreate the curve we read 11 points
629 * here and interpolate later.
632 /* Used to match PCDAC steps with power values on RF5111 chips
633 * (eeprom versions < 4). For RF5111 we have 11 pre-defined PCDAC
634 * steps that match with the power values we read from eeprom. On
635 * older eeprom versions (< 3.2) these steps are equaly spaced at
636 * 10% of the pcdac curve -until the curve reaches it's maximum-
637 * (11 steps from 0 to 100%) but on newer eeprom versions (>= 3.2)
638 * these 11 steps are spaced in a different way. This function returns
639 * the pcdac steps based on eeprom version and curve min/max so that we
640 * can have pcdac/pwr points.
643 ath5k_get_pcdac_intercepts(struct ath5k_hw
*ah
, u8 min
, u8 max
, u8
*vp
)
645 static const u16 intercepts3
[] =
646 { 0, 5, 10, 20, 30, 50, 70, 85, 90, 95, 100 };
647 static const u16 intercepts3_2
[] =
648 { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
652 if (ah
->ah_ee_version
>= AR5K_EEPROM_VERSION_3_2
)
657 for (i
= 0; i
< ARRAY_SIZE(intercepts3
); i
++)
658 vp
[i
] = (ip
[i
] * max
+ (100 - ip
[i
]) * min
) / 100;
661 /* Convert RF5111 specific data to generic raw data
662 * used by interpolation code */
664 ath5k_eeprom_convert_pcal_info_5111(struct ath5k_hw
*ah
, int mode
,
665 struct ath5k_chan_pcal_info
*chinfo
)
667 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
668 struct ath5k_chan_pcal_info_rf5111
*pcinfo
;
669 struct ath5k_pdgain_info
*pd
;
671 u8
*pdgain_idx
= ee
->ee_pdc_to_idx
[mode
];
673 /* Fill raw data for each calibration pier */
674 for (pier
= 0; pier
< ee
->ee_n_piers
[mode
]; pier
++) {
676 pcinfo
= &chinfo
[pier
].rf5111_info
;
678 /* Allocate pd_curves for this cal pier */
679 chinfo
[pier
].pd_curves
=
680 kcalloc(AR5K_EEPROM_N_PD_CURVES
,
681 sizeof(struct ath5k_pdgain_info
),
684 if (!chinfo
[pier
].pd_curves
)
687 /* Only one curve for RF5111
688 * find out which one and place
690 * Note: ee_x_gain is reversed here */
691 for (idx
= 0; idx
< AR5K_EEPROM_N_PD_CURVES
; idx
++) {
693 if (!((ee
->ee_x_gain
[mode
] >> idx
) & 0x1)) {
699 ee
->ee_pd_gains
[mode
] = 1;
701 pd
= &chinfo
[pier
].pd_curves
[idx
];
703 pd
->pd_points
= AR5K_EEPROM_N_PWR_POINTS_5111
;
705 /* Allocate pd points for this curve */
706 pd
->pd_step
= kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111
,
707 sizeof(u8
), GFP_KERNEL
);
711 pd
->pd_pwr
= kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111
,
712 sizeof(s16
), GFP_KERNEL
);
717 * (convert power to 0.25dB units
718 * for RF5112 combatibility) */
719 for (point
= 0; point
< pd
->pd_points
; point
++) {
721 /* Absolute values */
722 pd
->pd_pwr
[point
] = 2 * pcinfo
->pwr
[point
];
725 pd
->pd_step
[point
] = pcinfo
->pcdac
[point
];
728 /* Set min/max pwr */
729 chinfo
[pier
].min_pwr
= pd
->pd_pwr
[0];
730 chinfo
[pier
].max_pwr
= pd
->pd_pwr
[10];
737 /* Parse EEPROM data */
739 ath5k_eeprom_read_pcal_info_5111(struct ath5k_hw
*ah
, int mode
)
741 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
742 struct ath5k_chan_pcal_info
*pcal
;
747 offset
= AR5K_EEPROM_GROUPS_START(ee
->ee_version
);
749 case AR5K_EEPROM_MODE_11A
:
750 if (!AR5K_EEPROM_HDR_11A(ee
->ee_header
))
753 ret
= ath5k_eeprom_init_11a_pcal_freq(ah
,
754 offset
+ AR5K_EEPROM_GROUP1_OFFSET
);
758 offset
+= AR5K_EEPROM_GROUP2_OFFSET
;
759 pcal
= ee
->ee_pwr_cal_a
;
761 case AR5K_EEPROM_MODE_11B
:
762 if (!AR5K_EEPROM_HDR_11B(ee
->ee_header
) &&
763 !AR5K_EEPROM_HDR_11G(ee
->ee_header
))
766 pcal
= ee
->ee_pwr_cal_b
;
767 offset
+= AR5K_EEPROM_GROUP3_OFFSET
;
773 ee
->ee_n_piers
[mode
] = 3;
775 case AR5K_EEPROM_MODE_11G
:
776 if (!AR5K_EEPROM_HDR_11G(ee
->ee_header
))
779 pcal
= ee
->ee_pwr_cal_g
;
780 offset
+= AR5K_EEPROM_GROUP4_OFFSET
;
786 ee
->ee_n_piers
[mode
] = 3;
792 for (i
= 0; i
< ee
->ee_n_piers
[mode
]; i
++) {
793 struct ath5k_chan_pcal_info_rf5111
*cdata
=
794 &pcal
[i
].rf5111_info
;
796 AR5K_EEPROM_READ(offset
++, val
);
797 cdata
->pcdac_max
= ((val
>> 10) & AR5K_EEPROM_PCDAC_M
);
798 cdata
->pcdac_min
= ((val
>> 4) & AR5K_EEPROM_PCDAC_M
);
799 cdata
->pwr
[0] = ((val
<< 2) & AR5K_EEPROM_POWER_M
);
801 AR5K_EEPROM_READ(offset
++, val
);
802 cdata
->pwr
[0] |= ((val
>> 14) & 0x3);
803 cdata
->pwr
[1] = ((val
>> 8) & AR5K_EEPROM_POWER_M
);
804 cdata
->pwr
[2] = ((val
>> 2) & AR5K_EEPROM_POWER_M
);
805 cdata
->pwr
[3] = ((val
<< 4) & AR5K_EEPROM_POWER_M
);
807 AR5K_EEPROM_READ(offset
++, val
);
808 cdata
->pwr
[3] |= ((val
>> 12) & 0xf);
809 cdata
->pwr
[4] = ((val
>> 6) & AR5K_EEPROM_POWER_M
);
810 cdata
->pwr
[5] = (val
& AR5K_EEPROM_POWER_M
);
812 AR5K_EEPROM_READ(offset
++, val
);
813 cdata
->pwr
[6] = ((val
>> 10) & AR5K_EEPROM_POWER_M
);
814 cdata
->pwr
[7] = ((val
>> 4) & AR5K_EEPROM_POWER_M
);
815 cdata
->pwr
[8] = ((val
<< 2) & AR5K_EEPROM_POWER_M
);
817 AR5K_EEPROM_READ(offset
++, val
);
818 cdata
->pwr
[8] |= ((val
>> 14) & 0x3);
819 cdata
->pwr
[9] = ((val
>> 8) & AR5K_EEPROM_POWER_M
);
820 cdata
->pwr
[10] = ((val
>> 2) & AR5K_EEPROM_POWER_M
);
822 ath5k_get_pcdac_intercepts(ah
, cdata
->pcdac_min
,
823 cdata
->pcdac_max
, cdata
->pcdac
);
826 return ath5k_eeprom_convert_pcal_info_5111(ah
, mode
, pcal
);
831 * Read power calibration for RF5112 chips
833 * For RF5112 we have 4 XPD -eXternal Power Detector- curves
834 * for each calibrated channel on 0, -6, -12 and -18dbm but we only
835 * use the higher (3) and the lower (0) curves. Each curve has 0.5dB
836 * power steps on x axis and PCDAC steps on y axis and looks like a
837 * linear function. To recreate the curve and pass the power values
838 * on hw, we read 4 points for xpd 0 (lower gain -> max power)
839 * and 3 points for xpd 3 (higher gain -> lower power) here and
842 * Note: Many vendors just use xpd 0 so xpd 3 is zeroed.
845 /* Convert RF5112 specific data to generic raw data
846 * used by interpolation code */
848 ath5k_eeprom_convert_pcal_info_5112(struct ath5k_hw
*ah
, int mode
,
849 struct ath5k_chan_pcal_info
*chinfo
)
851 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
852 struct ath5k_chan_pcal_info_rf5112
*pcinfo
;
853 u8
*pdgain_idx
= ee
->ee_pdc_to_idx
[mode
];
854 unsigned int pier
, pdg
, point
;
856 /* Fill raw data for each calibration pier */
857 for (pier
= 0; pier
< ee
->ee_n_piers
[mode
]; pier
++) {
859 pcinfo
= &chinfo
[pier
].rf5112_info
;
861 /* Allocate pd_curves for this cal pier */
862 chinfo
[pier
].pd_curves
=
863 kcalloc(AR5K_EEPROM_N_PD_CURVES
,
864 sizeof(struct ath5k_pdgain_info
),
867 if (!chinfo
[pier
].pd_curves
)
871 for (pdg
= 0; pdg
< ee
->ee_pd_gains
[mode
]; pdg
++) {
873 u8 idx
= pdgain_idx
[pdg
];
874 struct ath5k_pdgain_info
*pd
=
875 &chinfo
[pier
].pd_curves
[idx
];
877 /* Lowest gain curve (max power) */
879 /* One more point for better accuracy */
880 pd
->pd_points
= AR5K_EEPROM_N_XPD0_POINTS
;
882 /* Allocate pd points for this curve */
883 pd
->pd_step
= kcalloc(pd
->pd_points
,
884 sizeof(u8
), GFP_KERNEL
);
889 pd
->pd_pwr
= kcalloc(pd
->pd_points
,
890 sizeof(s16
), GFP_KERNEL
);
897 * (all power levels are in 0.25dB units) */
898 pd
->pd_step
[0] = pcinfo
->pcdac_x0
[0];
899 pd
->pd_pwr
[0] = pcinfo
->pwr_x0
[0];
901 for (point
= 1; point
< pd
->pd_points
;
903 /* Absolute values */
905 pcinfo
->pwr_x0
[point
];
909 pd
->pd_step
[point
- 1] +
910 pcinfo
->pcdac_x0
[point
];
913 /* Set min power for this frequency */
914 chinfo
[pier
].min_pwr
= pd
->pd_pwr
[0];
916 /* Highest gain curve (min power) */
917 } else if (pdg
== 1) {
919 pd
->pd_points
= AR5K_EEPROM_N_XPD3_POINTS
;
921 /* Allocate pd points for this curve */
922 pd
->pd_step
= kcalloc(pd
->pd_points
,
923 sizeof(u8
), GFP_KERNEL
);
928 pd
->pd_pwr
= kcalloc(pd
->pd_points
,
929 sizeof(s16
), GFP_KERNEL
);
935 * (all power levels are in 0.25dB units) */
936 for (point
= 0; point
< pd
->pd_points
;
938 /* Absolute values */
940 pcinfo
->pwr_x3
[point
];
944 pcinfo
->pcdac_x3
[point
];
947 /* Since we have a higher gain curve
948 * override min power */
949 chinfo
[pier
].min_pwr
= pd
->pd_pwr
[0];
957 /* Parse EEPROM data */
959 ath5k_eeprom_read_pcal_info_5112(struct ath5k_hw
*ah
, int mode
)
961 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
962 struct ath5k_chan_pcal_info_rf5112
*chan_pcal_info
;
963 struct ath5k_chan_pcal_info
*gen_chan_info
;
964 u8
*pdgain_idx
= ee
->ee_pdc_to_idx
[mode
];
971 /* Count how many curves we have and
972 * identify them (which one of the 4
973 * available curves we have on each count).
974 * Curves are stored from lower (x0) to
975 * higher (x3) gain */
976 for (i
= 0; i
< AR5K_EEPROM_N_PD_CURVES
; i
++) {
977 /* ee_x_gain[mode] is x gain mask */
978 if ((ee
->ee_x_gain
[mode
] >> i
) & 0x1)
979 pdgain_idx
[pd_gains
++] = i
;
981 ee
->ee_pd_gains
[mode
] = pd_gains
;
983 if (pd_gains
== 0 || pd_gains
> 2)
987 case AR5K_EEPROM_MODE_11A
:
989 * Read 5GHz EEPROM channels
991 offset
= AR5K_EEPROM_GROUPS_START(ee
->ee_version
);
992 ath5k_eeprom_init_11a_pcal_freq(ah
, offset
);
994 offset
+= AR5K_EEPROM_GROUP2_OFFSET
;
995 gen_chan_info
= ee
->ee_pwr_cal_a
;
997 case AR5K_EEPROM_MODE_11B
:
998 offset
= AR5K_EEPROM_GROUPS_START(ee
->ee_version
);
999 if (AR5K_EEPROM_HDR_11A(ee
->ee_header
))
1000 offset
+= AR5K_EEPROM_GROUP3_OFFSET
;
1002 /* NB: frequency piers parsed during mode init */
1003 gen_chan_info
= ee
->ee_pwr_cal_b
;
1005 case AR5K_EEPROM_MODE_11G
:
1006 offset
= AR5K_EEPROM_GROUPS_START(ee
->ee_version
);
1007 if (AR5K_EEPROM_HDR_11A(ee
->ee_header
))
1008 offset
+= AR5K_EEPROM_GROUP4_OFFSET
;
1009 else if (AR5K_EEPROM_HDR_11B(ee
->ee_header
))
1010 offset
+= AR5K_EEPROM_GROUP2_OFFSET
;
1012 /* NB: frequency piers parsed during mode init */
1013 gen_chan_info
= ee
->ee_pwr_cal_g
;
1019 for (i
= 0; i
< ee
->ee_n_piers
[mode
]; i
++) {
1020 chan_pcal_info
= &gen_chan_info
[i
].rf5112_info
;
1022 /* Power values in quarter dB
1023 * for the lower xpd gain curve
1024 * (0 dBm -> higher output power) */
1025 for (c
= 0; c
< AR5K_EEPROM_N_XPD0_POINTS
; c
++) {
1026 AR5K_EEPROM_READ(offset
++, val
);
1027 chan_pcal_info
->pwr_x0
[c
] = (s8
) (val
& 0xff);
1028 chan_pcal_info
->pwr_x0
[++c
] = (s8
) ((val
>> 8) & 0xff);
1032 * corresponding to the above power
1034 AR5K_EEPROM_READ(offset
++, val
);
1035 chan_pcal_info
->pcdac_x0
[1] = (val
& 0x1f);
1036 chan_pcal_info
->pcdac_x0
[2] = ((val
>> 5) & 0x1f);
1037 chan_pcal_info
->pcdac_x0
[3] = ((val
>> 10) & 0x1f);
1039 /* Power values in quarter dB
1040 * for the higher xpd gain curve
1041 * (18 dBm -> lower output power) */
1042 AR5K_EEPROM_READ(offset
++, val
);
1043 chan_pcal_info
->pwr_x3
[0] = (s8
) (val
& 0xff);
1044 chan_pcal_info
->pwr_x3
[1] = (s8
) ((val
>> 8) & 0xff);
1046 AR5K_EEPROM_READ(offset
++, val
);
1047 chan_pcal_info
->pwr_x3
[2] = (val
& 0xff);
1050 * corresponding to the above power
1051 * measurements (fixed) */
1052 chan_pcal_info
->pcdac_x3
[0] = 20;
1053 chan_pcal_info
->pcdac_x3
[1] = 35;
1054 chan_pcal_info
->pcdac_x3
[2] = 63;
1056 if (ee
->ee_version
>= AR5K_EEPROM_VERSION_4_3
) {
1057 chan_pcal_info
->pcdac_x0
[0] = ((val
>> 8) & 0x3f);
1059 /* Last xpd0 power level is also channel maximum */
1060 gen_chan_info
[i
].max_pwr
= chan_pcal_info
->pwr_x0
[3];
1062 chan_pcal_info
->pcdac_x0
[0] = 1;
1063 gen_chan_info
[i
].max_pwr
= (s8
) ((val
>> 8) & 0xff);
1068 return ath5k_eeprom_convert_pcal_info_5112(ah
, mode
, gen_chan_info
);
1073 * Read power calibration for RF2413 chips
1075 * For RF2413 we have a Power to PDDAC table (Power Detector)
1076 * instead of a PCDAC and 4 pd gain curves for each calibrated channel.
1077 * Each curve has power on x axis in 0.5 db steps and PDDADC steps on y
1078 * axis and looks like an exponential function like the RF5111 curve.
1080 * To recreate the curves we read here the points and interpolate
1081 * later. Note that in most cases only 2 (higher and lower) curves are
1082 * used (like RF5112) but vendors have the oportunity to include all
1083 * 4 curves on eeprom. The final curve (higher power) has an extra
1084 * point for better accuracy like RF5112.
1087 /* For RF2413 power calibration data doesn't start on a fixed location and
1088 * if a mode is not supported, it's section is missing -not zeroed-.
1089 * So we need to calculate the starting offset for each section by using
1090 * these two functions */
1092 /* Return the size of each section based on the mode and the number of pd
1093 * gains available (maximum 4). */
1094 static inline unsigned int
1095 ath5k_pdgains_size_2413(struct ath5k_eeprom_info
*ee
, unsigned int mode
)
1097 static const unsigned int pdgains_size
[] = { 4, 6, 9, 12 };
1100 sz
= pdgains_size
[ee
->ee_pd_gains
[mode
] - 1];
1101 sz
*= ee
->ee_n_piers
[mode
];
1106 /* Return the starting offset for a section based on the modes supported
1107 * and each section's size. */
1109 ath5k_cal_data_offset_2413(struct ath5k_eeprom_info
*ee
, int mode
)
1111 u32 offset
= AR5K_EEPROM_CAL_DATA_START(ee
->ee_misc4
);
1114 case AR5K_EEPROM_MODE_11G
:
1115 if (AR5K_EEPROM_HDR_11B(ee
->ee_header
))
1116 offset
+= ath5k_pdgains_size_2413(ee
,
1117 AR5K_EEPROM_MODE_11B
) +
1118 AR5K_EEPROM_N_2GHZ_CHAN_2413
/ 2;
1120 case AR5K_EEPROM_MODE_11B
:
1121 if (AR5K_EEPROM_HDR_11A(ee
->ee_header
))
1122 offset
+= ath5k_pdgains_size_2413(ee
,
1123 AR5K_EEPROM_MODE_11A
) +
1124 AR5K_EEPROM_N_5GHZ_CHAN
/ 2;
1126 case AR5K_EEPROM_MODE_11A
:
1135 /* Convert RF2413 specific data to generic raw data
1136 * used by interpolation code */
1138 ath5k_eeprom_convert_pcal_info_2413(struct ath5k_hw
*ah
, int mode
,
1139 struct ath5k_chan_pcal_info
*chinfo
)
1141 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
1142 struct ath5k_chan_pcal_info_rf2413
*pcinfo
;
1143 u8
*pdgain_idx
= ee
->ee_pdc_to_idx
[mode
];
1144 unsigned int pier
, pdg
, point
;
1146 /* Fill raw data for each calibration pier */
1147 for (pier
= 0; pier
< ee
->ee_n_piers
[mode
]; pier
++) {
1149 pcinfo
= &chinfo
[pier
].rf2413_info
;
1151 /* Allocate pd_curves for this cal pier */
1152 chinfo
[pier
].pd_curves
=
1153 kcalloc(AR5K_EEPROM_N_PD_CURVES
,
1154 sizeof(struct ath5k_pdgain_info
),
1157 if (!chinfo
[pier
].pd_curves
)
1160 /* Fill pd_curves */
1161 for (pdg
= 0; pdg
< ee
->ee_pd_gains
[mode
]; pdg
++) {
1163 u8 idx
= pdgain_idx
[pdg
];
1164 struct ath5k_pdgain_info
*pd
=
1165 &chinfo
[pier
].pd_curves
[idx
];
1167 /* One more point for the highest power
1168 * curve (lowest gain) */
1169 if (pdg
== ee
->ee_pd_gains
[mode
] - 1)
1170 pd
->pd_points
= AR5K_EEPROM_N_PD_POINTS
;
1172 pd
->pd_points
= AR5K_EEPROM_N_PD_POINTS
- 1;
1174 /* Allocate pd points for this curve */
1175 pd
->pd_step
= kcalloc(pd
->pd_points
,
1176 sizeof(u8
), GFP_KERNEL
);
1181 pd
->pd_pwr
= kcalloc(pd
->pd_points
,
1182 sizeof(s16
), GFP_KERNEL
);
1188 * convert all pwr levels to
1189 * quarter dB for RF5112 combatibility */
1190 pd
->pd_step
[0] = pcinfo
->pddac_i
[pdg
];
1191 pd
->pd_pwr
[0] = 4 * pcinfo
->pwr_i
[pdg
];
1193 for (point
= 1; point
< pd
->pd_points
; point
++) {
1195 pd
->pd_pwr
[point
] = pd
->pd_pwr
[point
- 1] +
1196 2 * pcinfo
->pwr
[pdg
][point
- 1];
1198 pd
->pd_step
[point
] = pd
->pd_step
[point
- 1] +
1199 pcinfo
->pddac
[pdg
][point
- 1];
1203 /* Highest gain curve -> min power */
1205 chinfo
[pier
].min_pwr
= pd
->pd_pwr
[0];
1207 /* Lowest gain curve -> max power */
1208 if (pdg
== ee
->ee_pd_gains
[mode
] - 1)
1209 chinfo
[pier
].max_pwr
=
1210 pd
->pd_pwr
[pd
->pd_points
- 1];
1217 /* Parse EEPROM data */
1219 ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw
*ah
, int mode
)
1221 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
1222 struct ath5k_chan_pcal_info_rf2413
*pcinfo
;
1223 struct ath5k_chan_pcal_info
*chinfo
;
1224 u8
*pdgain_idx
= ee
->ee_pdc_to_idx
[mode
];
1230 /* Count how many curves we have and
1231 * identify them (which one of the 4
1232 * available curves we have on each count).
1233 * Curves are stored from higher to
1234 * lower gain so we go backwards */
1235 for (idx
= AR5K_EEPROM_N_PD_CURVES
- 1; idx
>= 0; idx
--) {
1236 /* ee_x_gain[mode] is x gain mask */
1237 if ((ee
->ee_x_gain
[mode
] >> idx
) & 0x1)
1238 pdgain_idx
[pd_gains
++] = idx
;
1241 ee
->ee_pd_gains
[mode
] = pd_gains
;
1246 offset
= ath5k_cal_data_offset_2413(ee
, mode
);
1248 case AR5K_EEPROM_MODE_11A
:
1249 if (!AR5K_EEPROM_HDR_11A(ee
->ee_header
))
1252 ath5k_eeprom_init_11a_pcal_freq(ah
, offset
);
1253 offset
+= AR5K_EEPROM_N_5GHZ_CHAN
/ 2;
1254 chinfo
= ee
->ee_pwr_cal_a
;
1256 case AR5K_EEPROM_MODE_11B
:
1257 if (!AR5K_EEPROM_HDR_11B(ee
->ee_header
))
1260 ath5k_eeprom_init_11bg_2413(ah
, mode
, offset
);
1261 offset
+= AR5K_EEPROM_N_2GHZ_CHAN_2413
/ 2;
1262 chinfo
= ee
->ee_pwr_cal_b
;
1264 case AR5K_EEPROM_MODE_11G
:
1265 if (!AR5K_EEPROM_HDR_11G(ee
->ee_header
))
1268 ath5k_eeprom_init_11bg_2413(ah
, mode
, offset
);
1269 offset
+= AR5K_EEPROM_N_2GHZ_CHAN_2413
/ 2;
1270 chinfo
= ee
->ee_pwr_cal_g
;
1276 for (i
= 0; i
< ee
->ee_n_piers
[mode
]; i
++) {
1277 pcinfo
= &chinfo
[i
].rf2413_info
;
1280 * Read pwr_i, pddac_i and the first
1281 * 2 pd points (pwr, pddac)
1283 AR5K_EEPROM_READ(offset
++, val
);
1284 pcinfo
->pwr_i
[0] = val
& 0x1f;
1285 pcinfo
->pddac_i
[0] = (val
>> 5) & 0x7f;
1286 pcinfo
->pwr
[0][0] = (val
>> 12) & 0xf;
1288 AR5K_EEPROM_READ(offset
++, val
);
1289 pcinfo
->pddac
[0][0] = val
& 0x3f;
1290 pcinfo
->pwr
[0][1] = (val
>> 6) & 0xf;
1291 pcinfo
->pddac
[0][1] = (val
>> 10) & 0x3f;
1293 AR5K_EEPROM_READ(offset
++, val
);
1294 pcinfo
->pwr
[0][2] = val
& 0xf;
1295 pcinfo
->pddac
[0][2] = (val
>> 4) & 0x3f;
1297 pcinfo
->pwr
[0][3] = 0;
1298 pcinfo
->pddac
[0][3] = 0;
1302 * Pd gain 0 is not the last pd gain
1303 * so it only has 2 pd points.
1304 * Continue wih pd gain 1.
1306 pcinfo
->pwr_i
[1] = (val
>> 10) & 0x1f;
1308 pcinfo
->pddac_i
[1] = (val
>> 15) & 0x1;
1309 AR5K_EEPROM_READ(offset
++, val
);
1310 pcinfo
->pddac_i
[1] |= (val
& 0x3F) << 1;
1312 pcinfo
->pwr
[1][0] = (val
>> 6) & 0xf;
1313 pcinfo
->pddac
[1][0] = (val
>> 10) & 0x3f;
1315 AR5K_EEPROM_READ(offset
++, val
);
1316 pcinfo
->pwr
[1][1] = val
& 0xf;
1317 pcinfo
->pddac
[1][1] = (val
>> 4) & 0x3f;
1318 pcinfo
->pwr
[1][2] = (val
>> 10) & 0xf;
1320 pcinfo
->pddac
[1][2] = (val
>> 14) & 0x3;
1321 AR5K_EEPROM_READ(offset
++, val
);
1322 pcinfo
->pddac
[1][2] |= (val
& 0xF) << 2;
1324 pcinfo
->pwr
[1][3] = 0;
1325 pcinfo
->pddac
[1][3] = 0;
1326 } else if (pd_gains
== 1) {
1328 * Pd gain 0 is the last one so
1329 * read the extra point.
1331 pcinfo
->pwr
[0][3] = (val
>> 10) & 0xf;
1333 pcinfo
->pddac
[0][3] = (val
>> 14) & 0x3;
1334 AR5K_EEPROM_READ(offset
++, val
);
1335 pcinfo
->pddac
[0][3] |= (val
& 0xF) << 2;
1339 * Proceed with the other pd_gains
1343 pcinfo
->pwr_i
[2] = (val
>> 4) & 0x1f;
1344 pcinfo
->pddac_i
[2] = (val
>> 9) & 0x7f;
1346 AR5K_EEPROM_READ(offset
++, val
);
1347 pcinfo
->pwr
[2][0] = (val
>> 0) & 0xf;
1348 pcinfo
->pddac
[2][0] = (val
>> 4) & 0x3f;
1349 pcinfo
->pwr
[2][1] = (val
>> 10) & 0xf;
1351 pcinfo
->pddac
[2][1] = (val
>> 14) & 0x3;
1352 AR5K_EEPROM_READ(offset
++, val
);
1353 pcinfo
->pddac
[2][1] |= (val
& 0xF) << 2;
1355 pcinfo
->pwr
[2][2] = (val
>> 4) & 0xf;
1356 pcinfo
->pddac
[2][2] = (val
>> 8) & 0x3f;
1358 pcinfo
->pwr
[2][3] = 0;
1359 pcinfo
->pddac
[2][3] = 0;
1360 } else if (pd_gains
== 2) {
1361 pcinfo
->pwr
[1][3] = (val
>> 4) & 0xf;
1362 pcinfo
->pddac
[1][3] = (val
>> 8) & 0x3f;
1366 pcinfo
->pwr_i
[3] = (val
>> 14) & 0x3;
1367 AR5K_EEPROM_READ(offset
++, val
);
1368 pcinfo
->pwr_i
[3] |= ((val
>> 0) & 0x7) << 2;
1370 pcinfo
->pddac_i
[3] = (val
>> 3) & 0x7f;
1371 pcinfo
->pwr
[3][0] = (val
>> 10) & 0xf;
1372 pcinfo
->pddac
[3][0] = (val
>> 14) & 0x3;
1374 AR5K_EEPROM_READ(offset
++, val
);
1375 pcinfo
->pddac
[3][0] |= (val
& 0xF) << 2;
1376 pcinfo
->pwr
[3][1] = (val
>> 4) & 0xf;
1377 pcinfo
->pddac
[3][1] = (val
>> 8) & 0x3f;
1379 pcinfo
->pwr
[3][2] = (val
>> 14) & 0x3;
1380 AR5K_EEPROM_READ(offset
++, val
);
1381 pcinfo
->pwr
[3][2] |= ((val
>> 0) & 0x3) << 2;
1383 pcinfo
->pddac
[3][2] = (val
>> 2) & 0x3f;
1384 pcinfo
->pwr
[3][3] = (val
>> 8) & 0xf;
1386 pcinfo
->pddac
[3][3] = (val
>> 12) & 0xF;
1387 AR5K_EEPROM_READ(offset
++, val
);
1388 pcinfo
->pddac
[3][3] |= ((val
>> 0) & 0x3) << 4;
1389 } else if (pd_gains
== 3) {
1390 pcinfo
->pwr
[2][3] = (val
>> 14) & 0x3;
1391 AR5K_EEPROM_READ(offset
++, val
);
1392 pcinfo
->pwr
[2][3] |= ((val
>> 0) & 0x3) << 2;
1394 pcinfo
->pddac
[2][3] = (val
>> 2) & 0x3f;
1398 return ath5k_eeprom_convert_pcal_info_2413(ah
, mode
, chinfo
);
1403 * Read per rate target power (this is the maximum tx power
1404 * supported by the card). This info is used when setting
1405 * tx power, no matter the channel.
1407 * This also works for v5 EEPROMs.
1410 ath5k_eeprom_read_target_rate_pwr_info(struct ath5k_hw
*ah
, unsigned int mode
)
1412 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
1413 struct ath5k_rate_pcal_info
*rate_pcal_info
;
1414 u8
*rate_target_pwr_num
;
1419 offset
= AR5K_EEPROM_TARGET_PWRSTART(ee
->ee_misc1
);
1420 rate_target_pwr_num
= &ee
->ee_rate_target_pwr_num
[mode
];
1422 case AR5K_EEPROM_MODE_11A
:
1423 offset
+= AR5K_EEPROM_TARGET_PWR_OFF_11A(ee
->ee_version
);
1424 rate_pcal_info
= ee
->ee_rate_tpwr_a
;
1425 ee
->ee_rate_target_pwr_num
[mode
] = AR5K_EEPROM_N_5GHZ_CHAN
;
1427 case AR5K_EEPROM_MODE_11B
:
1428 offset
+= AR5K_EEPROM_TARGET_PWR_OFF_11B(ee
->ee_version
);
1429 rate_pcal_info
= ee
->ee_rate_tpwr_b
;
1430 ee
->ee_rate_target_pwr_num
[mode
] = 2; /* 3rd is g mode's 1st */
1432 case AR5K_EEPROM_MODE_11G
:
1433 offset
+= AR5K_EEPROM_TARGET_PWR_OFF_11G(ee
->ee_version
);
1434 rate_pcal_info
= ee
->ee_rate_tpwr_g
;
1435 ee
->ee_rate_target_pwr_num
[mode
] = AR5K_EEPROM_N_2GHZ_CHAN
;
1441 /* Different freq mask for older eeproms (<= v3.2) */
1442 if (ee
->ee_version
<= AR5K_EEPROM_VERSION_3_2
) {
1443 for (i
= 0; i
< (*rate_target_pwr_num
); i
++) {
1444 AR5K_EEPROM_READ(offset
++, val
);
1445 rate_pcal_info
[i
].freq
=
1446 ath5k_eeprom_bin2freq(ee
, (val
>> 9) & 0x7f, mode
);
1448 rate_pcal_info
[i
].target_power_6to24
= ((val
>> 3) & 0x3f);
1449 rate_pcal_info
[i
].target_power_36
= (val
<< 3) & 0x3f;
1451 AR5K_EEPROM_READ(offset
++, val
);
1453 if (rate_pcal_info
[i
].freq
== AR5K_EEPROM_CHANNEL_DIS
||
1455 (*rate_target_pwr_num
) = i
;
1459 rate_pcal_info
[i
].target_power_36
|= ((val
>> 13) & 0x7);
1460 rate_pcal_info
[i
].target_power_48
= ((val
>> 7) & 0x3f);
1461 rate_pcal_info
[i
].target_power_54
= ((val
>> 1) & 0x3f);
1464 for (i
= 0; i
< (*rate_target_pwr_num
); i
++) {
1465 AR5K_EEPROM_READ(offset
++, val
);
1466 rate_pcal_info
[i
].freq
=
1467 ath5k_eeprom_bin2freq(ee
, (val
>> 8) & 0xff, mode
);
1469 rate_pcal_info
[i
].target_power_6to24
= ((val
>> 2) & 0x3f);
1470 rate_pcal_info
[i
].target_power_36
= (val
<< 4) & 0x3f;
1472 AR5K_EEPROM_READ(offset
++, val
);
1474 if (rate_pcal_info
[i
].freq
== AR5K_EEPROM_CHANNEL_DIS
||
1476 (*rate_target_pwr_num
) = i
;
1480 rate_pcal_info
[i
].target_power_36
|= (val
>> 12) & 0xf;
1481 rate_pcal_info
[i
].target_power_48
= ((val
>> 6) & 0x3f);
1482 rate_pcal_info
[i
].target_power_54
= (val
& 0x3f);
1490 * Read per channel calibration info from EEPROM
1492 * This info is used to calibrate the baseband power table. Imagine
1493 * that for each channel there is a power curve that's hw specific
1494 * (depends on amplifier etc) and we try to "correct" this curve using
1495 * offests we pass on to phy chip (baseband -> before amplifier) so that
1496 * it can use accurate power values when setting tx power (takes amplifier's
1497 * performance on each channel into account).
1499 * EEPROM provides us with the offsets for some pre-calibrated channels
1500 * and we have to interpolate to create the full table for these channels and
1501 * also the table for any channel.
1504 ath5k_eeprom_read_pcal_info(struct ath5k_hw
*ah
)
1506 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
1507 int (*read_pcal
)(struct ath5k_hw
*hw
, int mode
);
1511 if ((ah
->ah_ee_version
>= AR5K_EEPROM_VERSION_4_0
) &&
1512 (AR5K_EEPROM_EEMAP(ee
->ee_misc0
) == 1))
1513 read_pcal
= ath5k_eeprom_read_pcal_info_5112
;
1514 else if ((ah
->ah_ee_version
>= AR5K_EEPROM_VERSION_5_0
) &&
1515 (AR5K_EEPROM_EEMAP(ee
->ee_misc0
) == 2))
1516 read_pcal
= ath5k_eeprom_read_pcal_info_2413
;
1518 read_pcal
= ath5k_eeprom_read_pcal_info_5111
;
1521 for (mode
= AR5K_EEPROM_MODE_11A
; mode
<= AR5K_EEPROM_MODE_11G
;
1523 err
= read_pcal(ah
, mode
);
1527 err
= ath5k_eeprom_read_target_rate_pwr_info(ah
, mode
);
1536 ath5k_eeprom_free_pcal_info(struct ath5k_hw
*ah
, int mode
)
1538 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
1539 struct ath5k_chan_pcal_info
*chinfo
;
1543 case AR5K_EEPROM_MODE_11A
:
1544 if (!AR5K_EEPROM_HDR_11A(ee
->ee_header
))
1546 chinfo
= ee
->ee_pwr_cal_a
;
1548 case AR5K_EEPROM_MODE_11B
:
1549 if (!AR5K_EEPROM_HDR_11B(ee
->ee_header
))
1551 chinfo
= ee
->ee_pwr_cal_b
;
1553 case AR5K_EEPROM_MODE_11G
:
1554 if (!AR5K_EEPROM_HDR_11G(ee
->ee_header
))
1556 chinfo
= ee
->ee_pwr_cal_g
;
1562 for (pier
= 0; pier
< ee
->ee_n_piers
[mode
]; pier
++) {
1563 if (!chinfo
[pier
].pd_curves
)
1566 for (pdg
= 0; pdg
< ee
->ee_pd_gains
[mode
]; pdg
++) {
1567 struct ath5k_pdgain_info
*pd
=
1568 &chinfo
[pier
].pd_curves
[pdg
];
1576 kfree(chinfo
[pier
].pd_curves
);
1583 ath5k_eeprom_detach(struct ath5k_hw
*ah
)
1587 for (mode
= AR5K_EEPROM_MODE_11A
; mode
<= AR5K_EEPROM_MODE_11G
; mode
++)
1588 ath5k_eeprom_free_pcal_info(ah
, mode
);
1591 /* Read conformance test limits used for regulatory control */
1593 ath5k_eeprom_read_ctl_info(struct ath5k_hw
*ah
)
1595 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
1596 struct ath5k_edge_power
*rep
;
1597 unsigned int fmask
, pmask
;
1598 unsigned int ctl_mode
;
1603 pmask
= AR5K_EEPROM_POWER_M
;
1604 fmask
= AR5K_EEPROM_FREQ_M(ee
->ee_version
);
1605 offset
= AR5K_EEPROM_CTL(ee
->ee_version
);
1606 ee
->ee_ctls
= AR5K_EEPROM_N_CTLS(ee
->ee_version
);
1607 for (i
= 0; i
< ee
->ee_ctls
; i
+= 2) {
1608 AR5K_EEPROM_READ(offset
++, val
);
1609 ee
->ee_ctl
[i
] = (val
>> 8) & 0xff;
1610 ee
->ee_ctl
[i
+ 1] = val
& 0xff;
1613 offset
= AR5K_EEPROM_GROUP8_OFFSET
;
1614 if (ee
->ee_version
>= AR5K_EEPROM_VERSION_4_0
)
1615 offset
+= AR5K_EEPROM_TARGET_PWRSTART(ee
->ee_misc1
) -
1616 AR5K_EEPROM_GROUP5_OFFSET
;
1618 offset
+= AR5K_EEPROM_GROUPS_START(ee
->ee_version
);
1620 rep
= ee
->ee_ctl_pwr
;
1621 for(i
= 0; i
< ee
->ee_ctls
; i
++) {
1622 switch(ee
->ee_ctl
[i
] & AR5K_CTL_MODE_M
) {
1624 case AR5K_CTL_TURBO
:
1625 ctl_mode
= AR5K_EEPROM_MODE_11A
;
1628 ctl_mode
= AR5K_EEPROM_MODE_11G
;
1631 if (ee
->ee_ctl
[i
] == 0) {
1632 if (ee
->ee_version
>= AR5K_EEPROM_VERSION_3_3
)
1636 rep
+= AR5K_EEPROM_N_EDGES
;
1639 if (ee
->ee_version
>= AR5K_EEPROM_VERSION_3_3
) {
1640 for (j
= 0; j
< AR5K_EEPROM_N_EDGES
; j
+= 2) {
1641 AR5K_EEPROM_READ(offset
++, val
);
1642 rep
[j
].freq
= (val
>> 8) & fmask
;
1643 rep
[j
+ 1].freq
= val
& fmask
;
1645 for (j
= 0; j
< AR5K_EEPROM_N_EDGES
; j
+= 2) {
1646 AR5K_EEPROM_READ(offset
++, val
);
1647 rep
[j
].edge
= (val
>> 8) & pmask
;
1648 rep
[j
].flag
= (val
>> 14) & 1;
1649 rep
[j
+ 1].edge
= val
& pmask
;
1650 rep
[j
+ 1].flag
= (val
>> 6) & 1;
1653 AR5K_EEPROM_READ(offset
++, val
);
1654 rep
[0].freq
= (val
>> 9) & fmask
;
1655 rep
[1].freq
= (val
>> 2) & fmask
;
1656 rep
[2].freq
= (val
<< 5) & fmask
;
1658 AR5K_EEPROM_READ(offset
++, val
);
1659 rep
[2].freq
|= (val
>> 11) & 0x1f;
1660 rep
[3].freq
= (val
>> 4) & fmask
;
1661 rep
[4].freq
= (val
<< 3) & fmask
;
1663 AR5K_EEPROM_READ(offset
++, val
);
1664 rep
[4].freq
|= (val
>> 13) & 0x7;
1665 rep
[5].freq
= (val
>> 6) & fmask
;
1666 rep
[6].freq
= (val
<< 1) & fmask
;
1668 AR5K_EEPROM_READ(offset
++, val
);
1669 rep
[6].freq
|= (val
>> 15) & 0x1;
1670 rep
[7].freq
= (val
>> 8) & fmask
;
1672 rep
[0].edge
= (val
>> 2) & pmask
;
1673 rep
[1].edge
= (val
<< 4) & pmask
;
1675 AR5K_EEPROM_READ(offset
++, val
);
1676 rep
[1].edge
|= (val
>> 12) & 0xf;
1677 rep
[2].edge
= (val
>> 6) & pmask
;
1678 rep
[3].edge
= val
& pmask
;
1680 AR5K_EEPROM_READ(offset
++, val
);
1681 rep
[4].edge
= (val
>> 10) & pmask
;
1682 rep
[5].edge
= (val
>> 4) & pmask
;
1683 rep
[6].edge
= (val
<< 2) & pmask
;
1685 AR5K_EEPROM_READ(offset
++, val
);
1686 rep
[6].edge
|= (val
>> 14) & 0x3;
1687 rep
[7].edge
= (val
>> 8) & pmask
;
1689 for (j
= 0; j
< AR5K_EEPROM_N_EDGES
; j
++) {
1690 rep
[j
].freq
= ath5k_eeprom_bin2freq(ee
,
1691 rep
[j
].freq
, ctl_mode
);
1693 rep
+= AR5K_EEPROM_N_EDGES
;
1700 ath5k_eeprom_read_spur_chans(struct ath5k_hw
*ah
)
1702 struct ath5k_eeprom_info
*ee
= &ah
->ah_capabilities
.cap_eeprom
;
1707 offset
= AR5K_EEPROM_CTL(ee
->ee_version
) +
1708 AR5K_EEPROM_N_CTLS(ee
->ee_version
);
1710 if (ee
->ee_version
< AR5K_EEPROM_VERSION_5_3
) {
1711 /* No spur info for 5GHz */
1712 ee
->ee_spur_chans
[0][0] = AR5K_EEPROM_NO_SPUR
;
1713 /* 2 channels for 2GHz (2464/2420) */
1714 ee
->ee_spur_chans
[0][1] = AR5K_EEPROM_5413_SPUR_CHAN_1
;
1715 ee
->ee_spur_chans
[1][1] = AR5K_EEPROM_5413_SPUR_CHAN_2
;
1716 ee
->ee_spur_chans
[2][1] = AR5K_EEPROM_NO_SPUR
;
1717 } else if (ee
->ee_version
>= AR5K_EEPROM_VERSION_5_3
) {
1718 for (i
= 0; i
< AR5K_EEPROM_N_SPUR_CHANS
; i
++) {
1719 AR5K_EEPROM_READ(offset
, val
);
1720 ee
->ee_spur_chans
[i
][0] = val
;
1721 AR5K_EEPROM_READ(offset
+ AR5K_EEPROM_N_SPUR_CHANS
,
1723 ee
->ee_spur_chans
[i
][1] = val
;
1732 * Initialize eeprom data structure
1735 ath5k_eeprom_init(struct ath5k_hw
*ah
)
1739 err
= ath5k_eeprom_init_header(ah
);
1743 err
= ath5k_eeprom_init_modes(ah
);
1747 err
= ath5k_eeprom_read_pcal_info(ah
);
1751 err
= ath5k_eeprom_read_ctl_info(ah
);
1755 err
= ath5k_eeprom_read_spur_chans(ah
);
1763 * Read the MAC address from eeprom
1765 int ath5k_eeprom_read_mac(struct ath5k_hw
*ah
, u8
*mac
)
1767 u8 mac_d
[ETH_ALEN
] = {};
1772 ret
= ath5k_hw_eeprom_read(ah
, 0x20, &data
);
1776 for (offset
= 0x1f, octet
= 0, total
= 0; offset
>= 0x1d; offset
--) {
1777 ret
= ath5k_hw_eeprom_read(ah
, offset
, &data
);
1782 mac_d
[octet
+ 1] = data
& 0xff;
1783 mac_d
[octet
] = data
>> 8;
1787 if (!total
|| total
== 3 * 0xffff)
1790 memcpy(mac
, mac_d
, ETH_ALEN
);