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;
175 * Read antenna infos from eeprom
177 static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
180 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
185 AR5K_EEPROM_READ(o++, val);
186 ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
187 ee->ee_atn_tx_rx[mode] = (val >> 2) & 0x3f;
188 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
190 AR5K_EEPROM_READ(o++, val);
191 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
192 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
193 ee->ee_ant_control[mode][i++] = val & 0x3f;
195 AR5K_EEPROM_READ(o++, val);
196 ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
197 ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
198 ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
200 AR5K_EEPROM_READ(o++, val);
201 ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
202 ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
203 ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
204 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
206 AR5K_EEPROM_READ(o++, val);
207 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
208 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
209 ee->ee_ant_control[mode][i++] = val & 0x3f;
211 /* Get antenna switch tables */
212 ah->ah_ant_ctl[mode][AR5K_ANT_CTL] =
213 (ee->ee_ant_control[mode][0] << 4);
214 ah->ah_ant_ctl[mode][AR5K_ANT_SWTABLE_A] =
215 ee->ee_ant_control[mode][1] |
216 (ee->ee_ant_control[mode][2] << 6) |
217 (ee->ee_ant_control[mode][3] << 12) |
218 (ee->ee_ant_control[mode][4] << 18) |
219 (ee->ee_ant_control[mode][5] << 24);
220 ah->ah_ant_ctl[mode][AR5K_ANT_SWTABLE_B] =
221 ee->ee_ant_control[mode][6] |
222 (ee->ee_ant_control[mode][7] << 6) |
223 (ee->ee_ant_control[mode][8] << 12) |
224 (ee->ee_ant_control[mode][9] << 18) |
225 (ee->ee_ant_control[mode][10] << 24);
227 /* return new offset */
234 * Read supported modes and some mode-specific calibration data
237 static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
240 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
245 ee->ee_n_piers[mode] = 0;
246 AR5K_EEPROM_READ(o++, val);
247 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
249 case AR5K_EEPROM_MODE_11A:
250 ee->ee_ob[mode][3] = (val >> 5) & 0x7;
251 ee->ee_db[mode][3] = (val >> 2) & 0x7;
252 ee->ee_ob[mode][2] = (val << 1) & 0x7;
254 AR5K_EEPROM_READ(o++, val);
255 ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
256 ee->ee_db[mode][2] = (val >> 12) & 0x7;
257 ee->ee_ob[mode][1] = (val >> 9) & 0x7;
258 ee->ee_db[mode][1] = (val >> 6) & 0x7;
259 ee->ee_ob[mode][0] = (val >> 3) & 0x7;
260 ee->ee_db[mode][0] = val & 0x7;
262 case AR5K_EEPROM_MODE_11G:
263 case AR5K_EEPROM_MODE_11B:
264 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
265 ee->ee_db[mode][1] = val & 0x7;
269 AR5K_EEPROM_READ(o++, val);
270 ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
271 ee->ee_thr_62[mode] = val & 0xff;
273 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
274 ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
276 AR5K_EEPROM_READ(o++, val);
277 ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
278 ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
280 AR5K_EEPROM_READ(o++, val);
281 ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
283 if ((val & 0xff) & 0x80)
284 ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
286 ee->ee_noise_floor_thr[mode] = val & 0xff;
288 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
289 ee->ee_noise_floor_thr[mode] =
290 mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
292 AR5K_EEPROM_READ(o++, val);
293 ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
294 ee->ee_x_gain[mode] = (val >> 1) & 0xf;
295 ee->ee_xpd[mode] = val & 0x1;
297 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
298 ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
300 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
301 AR5K_EEPROM_READ(o++, val);
302 ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
304 if (mode == AR5K_EEPROM_MODE_11A)
305 ee->ee_xr_power[mode] = val & 0x3f;
307 ee->ee_ob[mode][0] = val & 0x7;
308 ee->ee_db[mode][0] = (val >> 3) & 0x7;
312 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
313 ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
314 ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
316 ee->ee_i_gain[mode] = (val >> 13) & 0x7;
318 AR5K_EEPROM_READ(o++, val);
319 ee->ee_i_gain[mode] |= (val << 3) & 0x38;
321 if (mode == AR5K_EEPROM_MODE_11G) {
322 ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
323 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6)
324 ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
328 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
329 mode == AR5K_EEPROM_MODE_11A) {
330 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
331 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
334 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_4_0)
337 /* Note: >= v5 have bg freq piers on another location
338 * so these freq piers are ignored for >= v5 (should be 0xff
341 case AR5K_EEPROM_MODE_11A:
342 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_4_1)
345 AR5K_EEPROM_READ(o++, val);
346 ee->ee_margin_tx_rx[mode] = val & 0x3f;
348 case AR5K_EEPROM_MODE_11B:
349 AR5K_EEPROM_READ(o++, val);
351 ee->ee_pwr_cal_b[0].freq =
352 ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
353 if (ee->ee_pwr_cal_b[0].freq != AR5K_EEPROM_CHANNEL_DIS)
354 ee->ee_n_piers[mode]++;
356 ee->ee_pwr_cal_b[1].freq =
357 ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
358 if (ee->ee_pwr_cal_b[1].freq != AR5K_EEPROM_CHANNEL_DIS)
359 ee->ee_n_piers[mode]++;
361 AR5K_EEPROM_READ(o++, val);
362 ee->ee_pwr_cal_b[2].freq =
363 ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
364 if (ee->ee_pwr_cal_b[2].freq != AR5K_EEPROM_CHANNEL_DIS)
365 ee->ee_n_piers[mode]++;
367 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
368 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
370 case AR5K_EEPROM_MODE_11G:
371 AR5K_EEPROM_READ(o++, val);
373 ee->ee_pwr_cal_g[0].freq =
374 ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
375 if (ee->ee_pwr_cal_g[0].freq != AR5K_EEPROM_CHANNEL_DIS)
376 ee->ee_n_piers[mode]++;
378 ee->ee_pwr_cal_g[1].freq =
379 ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
380 if (ee->ee_pwr_cal_g[1].freq != AR5K_EEPROM_CHANNEL_DIS)
381 ee->ee_n_piers[mode]++;
383 AR5K_EEPROM_READ(o++, val);
384 ee->ee_turbo_max_power[mode] = val & 0x7f;
385 ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
387 AR5K_EEPROM_READ(o++, val);
388 ee->ee_pwr_cal_g[2].freq =
389 ath5k_eeprom_bin2freq(ee, val & 0xff, mode);
390 if (ee->ee_pwr_cal_g[2].freq != AR5K_EEPROM_CHANNEL_DIS)
391 ee->ee_n_piers[mode]++;
393 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
394 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
396 AR5K_EEPROM_READ(o++, val);
397 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
398 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
400 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
401 AR5K_EEPROM_READ(o++, val);
402 ee->ee_cck_ofdm_gain_delta = val & 0xff;
408 /* return new offset */
415 * Read turbo mode information on newer EEPROM versions
418 ath5k_eeprom_read_turbo_modes(struct ath5k_hw *ah,
419 u32 *offset, unsigned int mode)
421 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
426 if (ee->ee_version < AR5K_EEPROM_VERSION_5_0)
430 case AR5K_EEPROM_MODE_11A:
431 ee->ee_switch_settling_turbo[mode] = (val >> 6) & 0x7f;
433 ee->ee_atn_tx_rx_turbo[mode] = (val >> 13) & 0x7;
434 AR5K_EEPROM_READ(o++, val);
435 ee->ee_atn_tx_rx_turbo[mode] |= (val & 0x7) << 3;
436 ee->ee_margin_tx_rx_turbo[mode] = (val >> 3) & 0x3f;
438 ee->ee_adc_desired_size_turbo[mode] = (val >> 9) & 0x7f;
439 AR5K_EEPROM_READ(o++, val);
440 ee->ee_adc_desired_size_turbo[mode] |= (val & 0x1) << 7;
441 ee->ee_pga_desired_size_turbo[mode] = (val >> 1) & 0xff;
443 if (AR5K_EEPROM_EEMAP(ee->ee_misc0) >=2)
444 ee->ee_pd_gain_overlap = (val >> 9) & 0xf;
446 case AR5K_EEPROM_MODE_11G:
447 ee->ee_switch_settling_turbo[mode] = (val >> 8) & 0x7f;
449 ee->ee_atn_tx_rx_turbo[mode] = (val >> 15) & 0x7;
450 AR5K_EEPROM_READ(o++, val);
451 ee->ee_atn_tx_rx_turbo[mode] |= (val & 0x1f) << 1;
452 ee->ee_margin_tx_rx_turbo[mode] = (val >> 5) & 0x3f;
454 ee->ee_adc_desired_size_turbo[mode] = (val >> 11) & 0x7f;
455 AR5K_EEPROM_READ(o++, val);
456 ee->ee_adc_desired_size_turbo[mode] |= (val & 0x7) << 5;
457 ee->ee_pga_desired_size_turbo[mode] = (val >> 3) & 0xff;
461 /* return new offset */
467 /* Read mode-specific data (except power calibration data) */
469 ath5k_eeprom_init_modes(struct ath5k_hw *ah)
471 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
478 * Get values for all modes
480 mode_offset[AR5K_EEPROM_MODE_11A] = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
481 mode_offset[AR5K_EEPROM_MODE_11B] = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
482 mode_offset[AR5K_EEPROM_MODE_11G] = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
484 ee->ee_turbo_max_power[AR5K_EEPROM_MODE_11A] =
485 AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
487 for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++) {
488 offset = mode_offset[mode];
490 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
494 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
498 ret = ath5k_eeprom_read_turbo_modes(ah, &offset, mode);
503 /* override for older eeprom versions for better performance */
504 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2) {
505 ee->ee_thr_62[AR5K_EEPROM_MODE_11A] = 15;
506 ee->ee_thr_62[AR5K_EEPROM_MODE_11B] = 28;
507 ee->ee_thr_62[AR5K_EEPROM_MODE_11G] = 28;
513 /* Read the frequency piers for each mode (mostly used on newer eeproms with 0xff
516 ath5k_eeprom_read_freq_list(struct ath5k_hw *ah, int *offset, int max,
517 struct ath5k_chan_pcal_info *pc, unsigned int mode)
519 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
526 ee->ee_n_piers[mode] = 0;
528 AR5K_EEPROM_READ(o++, val);
534 pc[i++].freq = ath5k_eeprom_bin2freq(ee,
536 ee->ee_n_piers[mode]++;
538 freq2 = (val >> 8) & 0xff;
542 pc[i++].freq = ath5k_eeprom_bin2freq(ee,
544 ee->ee_n_piers[mode]++;
547 /* return new offset */
553 /* Read frequency piers for 802.11a */
555 ath5k_eeprom_init_11a_pcal_freq(struct ath5k_hw *ah, int offset)
557 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
558 struct ath5k_chan_pcal_info *pcal = ee->ee_pwr_cal_a;
563 if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3) {
564 ath5k_eeprom_read_freq_list(ah, &offset,
565 AR5K_EEPROM_N_5GHZ_CHAN, pcal,
566 AR5K_EEPROM_MODE_11A);
568 mask = AR5K_EEPROM_FREQ_M(ah->ah_ee_version);
570 AR5K_EEPROM_READ(offset++, val);
571 pcal[0].freq = (val >> 9) & mask;
572 pcal[1].freq = (val >> 2) & mask;
573 pcal[2].freq = (val << 5) & mask;
575 AR5K_EEPROM_READ(offset++, val);
576 pcal[2].freq |= (val >> 11) & 0x1f;
577 pcal[3].freq = (val >> 4) & mask;
578 pcal[4].freq = (val << 3) & mask;
580 AR5K_EEPROM_READ(offset++, val);
581 pcal[4].freq |= (val >> 13) & 0x7;
582 pcal[5].freq = (val >> 6) & mask;
583 pcal[6].freq = (val << 1) & mask;
585 AR5K_EEPROM_READ(offset++, val);
586 pcal[6].freq |= (val >> 15) & 0x1;
587 pcal[7].freq = (val >> 8) & mask;
588 pcal[8].freq = (val >> 1) & mask;
589 pcal[9].freq = (val << 6) & mask;
591 AR5K_EEPROM_READ(offset++, val);
592 pcal[9].freq |= (val >> 10) & 0x3f;
594 /* Fixed number of piers */
595 ee->ee_n_piers[AR5K_EEPROM_MODE_11A] = 10;
597 for (i = 0; i < AR5K_EEPROM_N_5GHZ_CHAN; i++) {
598 pcal[i].freq = ath5k_eeprom_bin2freq(ee,
599 pcal[i].freq, AR5K_EEPROM_MODE_11A);
606 /* Read frequency piers for 802.11bg on eeprom versions >= 5 and eemap >= 2 */
608 ath5k_eeprom_init_11bg_2413(struct ath5k_hw *ah, unsigned int mode, int offset)
610 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
611 struct ath5k_chan_pcal_info *pcal;
614 case AR5K_EEPROM_MODE_11B:
615 pcal = ee->ee_pwr_cal_b;
617 case AR5K_EEPROM_MODE_11G:
618 pcal = ee->ee_pwr_cal_g;
624 ath5k_eeprom_read_freq_list(ah, &offset,
625 AR5K_EEPROM_N_2GHZ_CHAN_2413, pcal,
632 * Read power calibration for RF5111 chips
634 * For RF5111 we have an XPD -eXternal Power Detector- curve
635 * for each calibrated channel. Each curve has 0,5dB Power steps
636 * on x axis and PCDAC steps (offsets) on y axis and looks like an
637 * exponential function. To recreate the curve we read 11 points
638 * here and interpolate later.
641 /* Used to match PCDAC steps with power values on RF5111 chips
642 * (eeprom versions < 4). For RF5111 we have 11 pre-defined PCDAC
643 * steps that match with the power values we read from eeprom. On
644 * older eeprom versions (< 3.2) these steps are equaly spaced at
645 * 10% of the pcdac curve -until the curve reaches it's maximum-
646 * (11 steps from 0 to 100%) but on newer eeprom versions (>= 3.2)
647 * these 11 steps are spaced in a different way. This function returns
648 * the pcdac steps based on eeprom version and curve min/max so that we
649 * can have pcdac/pwr points.
652 ath5k_get_pcdac_intercepts(struct ath5k_hw *ah, u8 min, u8 max, u8 *vp)
654 static const u16 intercepts3[] =
655 { 0, 5, 10, 20, 30, 50, 70, 85, 90, 95, 100 };
656 static const u16 intercepts3_2[] =
657 { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
661 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_2)
666 for (i = 0; i < ARRAY_SIZE(intercepts3); i++)
667 vp[i] = (ip[i] * max + (100 - ip[i]) * min) / 100;
670 /* Convert RF5111 specific data to generic raw data
671 * used by interpolation code */
673 ath5k_eeprom_convert_pcal_info_5111(struct ath5k_hw *ah, int mode,
674 struct ath5k_chan_pcal_info *chinfo)
676 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
677 struct ath5k_chan_pcal_info_rf5111 *pcinfo;
678 struct ath5k_pdgain_info *pd;
680 u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
682 /* Fill raw data for each calibration pier */
683 for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
685 pcinfo = &chinfo[pier].rf5111_info;
687 /* Allocate pd_curves for this cal pier */
688 chinfo[pier].pd_curves =
689 kcalloc(AR5K_EEPROM_N_PD_CURVES,
690 sizeof(struct ath5k_pdgain_info),
693 if (!chinfo[pier].pd_curves)
696 /* Only one curve for RF5111
697 * find out which one and place
699 * Note: ee_x_gain is reversed here */
700 for (idx = 0; idx < AR5K_EEPROM_N_PD_CURVES; idx++) {
702 if (!((ee->ee_x_gain[mode] >> idx) & 0x1)) {
708 ee->ee_pd_gains[mode] = 1;
710 pd = &chinfo[pier].pd_curves[idx];
712 pd->pd_points = AR5K_EEPROM_N_PWR_POINTS_5111;
714 /* Allocate pd points for this curve */
715 pd->pd_step = kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111,
716 sizeof(u8), GFP_KERNEL);
720 pd->pd_pwr = kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111,
721 sizeof(s16), GFP_KERNEL);
726 * (convert power to 0.25dB units
727 * for RF5112 combatibility) */
728 for (point = 0; point < pd->pd_points; point++) {
730 /* Absolute values */
731 pd->pd_pwr[point] = 2 * pcinfo->pwr[point];
734 pd->pd_step[point] = pcinfo->pcdac[point];
737 /* Set min/max pwr */
738 chinfo[pier].min_pwr = pd->pd_pwr[0];
739 chinfo[pier].max_pwr = pd->pd_pwr[10];
746 /* Parse EEPROM data */
748 ath5k_eeprom_read_pcal_info_5111(struct ath5k_hw *ah, int mode)
750 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
751 struct ath5k_chan_pcal_info *pcal;
756 offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
758 case AR5K_EEPROM_MODE_11A:
759 if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
762 ret = ath5k_eeprom_init_11a_pcal_freq(ah,
763 offset + AR5K_EEPROM_GROUP1_OFFSET);
767 offset += AR5K_EEPROM_GROUP2_OFFSET;
768 pcal = ee->ee_pwr_cal_a;
770 case AR5K_EEPROM_MODE_11B:
771 if (!AR5K_EEPROM_HDR_11B(ee->ee_header) &&
772 !AR5K_EEPROM_HDR_11G(ee->ee_header))
775 pcal = ee->ee_pwr_cal_b;
776 offset += AR5K_EEPROM_GROUP3_OFFSET;
782 ee->ee_n_piers[mode] = 3;
784 case AR5K_EEPROM_MODE_11G:
785 if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
788 pcal = ee->ee_pwr_cal_g;
789 offset += AR5K_EEPROM_GROUP4_OFFSET;
795 ee->ee_n_piers[mode] = 3;
801 for (i = 0; i < ee->ee_n_piers[mode]; i++) {
802 struct ath5k_chan_pcal_info_rf5111 *cdata =
803 &pcal[i].rf5111_info;
805 AR5K_EEPROM_READ(offset++, val);
806 cdata->pcdac_max = ((val >> 10) & AR5K_EEPROM_PCDAC_M);
807 cdata->pcdac_min = ((val >> 4) & AR5K_EEPROM_PCDAC_M);
808 cdata->pwr[0] = ((val << 2) & AR5K_EEPROM_POWER_M);
810 AR5K_EEPROM_READ(offset++, val);
811 cdata->pwr[0] |= ((val >> 14) & 0x3);
812 cdata->pwr[1] = ((val >> 8) & AR5K_EEPROM_POWER_M);
813 cdata->pwr[2] = ((val >> 2) & AR5K_EEPROM_POWER_M);
814 cdata->pwr[3] = ((val << 4) & AR5K_EEPROM_POWER_M);
816 AR5K_EEPROM_READ(offset++, val);
817 cdata->pwr[3] |= ((val >> 12) & 0xf);
818 cdata->pwr[4] = ((val >> 6) & AR5K_EEPROM_POWER_M);
819 cdata->pwr[5] = (val & AR5K_EEPROM_POWER_M);
821 AR5K_EEPROM_READ(offset++, val);
822 cdata->pwr[6] = ((val >> 10) & AR5K_EEPROM_POWER_M);
823 cdata->pwr[7] = ((val >> 4) & AR5K_EEPROM_POWER_M);
824 cdata->pwr[8] = ((val << 2) & AR5K_EEPROM_POWER_M);
826 AR5K_EEPROM_READ(offset++, val);
827 cdata->pwr[8] |= ((val >> 14) & 0x3);
828 cdata->pwr[9] = ((val >> 8) & AR5K_EEPROM_POWER_M);
829 cdata->pwr[10] = ((val >> 2) & AR5K_EEPROM_POWER_M);
831 ath5k_get_pcdac_intercepts(ah, cdata->pcdac_min,
832 cdata->pcdac_max, cdata->pcdac);
835 return ath5k_eeprom_convert_pcal_info_5111(ah, mode, pcal);
840 * Read power calibration for RF5112 chips
842 * For RF5112 we have 4 XPD -eXternal Power Detector- curves
843 * for each calibrated channel on 0, -6, -12 and -18dbm but we only
844 * use the higher (3) and the lower (0) curves. Each curve has 0.5dB
845 * power steps on x axis and PCDAC steps on y axis and looks like a
846 * linear function. To recreate the curve and pass the power values
847 * on hw, we read 4 points for xpd 0 (lower gain -> max power)
848 * and 3 points for xpd 3 (higher gain -> lower power) here and
851 * Note: Many vendors just use xpd 0 so xpd 3 is zeroed.
854 /* Convert RF5112 specific data to generic raw data
855 * used by interpolation code */
857 ath5k_eeprom_convert_pcal_info_5112(struct ath5k_hw *ah, int mode,
858 struct ath5k_chan_pcal_info *chinfo)
860 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
861 struct ath5k_chan_pcal_info_rf5112 *pcinfo;
862 u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
863 unsigned int pier, pdg, point;
865 /* Fill raw data for each calibration pier */
866 for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
868 pcinfo = &chinfo[pier].rf5112_info;
870 /* Allocate pd_curves for this cal pier */
871 chinfo[pier].pd_curves =
872 kcalloc(AR5K_EEPROM_N_PD_CURVES,
873 sizeof(struct ath5k_pdgain_info),
876 if (!chinfo[pier].pd_curves)
880 for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
882 u8 idx = pdgain_idx[pdg];
883 struct ath5k_pdgain_info *pd =
884 &chinfo[pier].pd_curves[idx];
886 /* Lowest gain curve (max power) */
888 /* One more point for better accuracy */
889 pd->pd_points = AR5K_EEPROM_N_XPD0_POINTS;
891 /* Allocate pd points for this curve */
892 pd->pd_step = kcalloc(pd->pd_points,
893 sizeof(u8), GFP_KERNEL);
898 pd->pd_pwr = kcalloc(pd->pd_points,
899 sizeof(s16), GFP_KERNEL);
906 * (all power levels are in 0.25dB units) */
907 pd->pd_step[0] = pcinfo->pcdac_x0[0];
908 pd->pd_pwr[0] = pcinfo->pwr_x0[0];
910 for (point = 1; point < pd->pd_points;
912 /* Absolute values */
914 pcinfo->pwr_x0[point];
918 pd->pd_step[point - 1] +
919 pcinfo->pcdac_x0[point];
922 /* Set min power for this frequency */
923 chinfo[pier].min_pwr = pd->pd_pwr[0];
925 /* Highest gain curve (min power) */
926 } else if (pdg == 1) {
928 pd->pd_points = AR5K_EEPROM_N_XPD3_POINTS;
930 /* Allocate pd points for this curve */
931 pd->pd_step = kcalloc(pd->pd_points,
932 sizeof(u8), GFP_KERNEL);
937 pd->pd_pwr = kcalloc(pd->pd_points,
938 sizeof(s16), GFP_KERNEL);
944 * (all power levels are in 0.25dB units) */
945 for (point = 0; point < pd->pd_points;
947 /* Absolute values */
949 pcinfo->pwr_x3[point];
953 pcinfo->pcdac_x3[point];
956 /* Since we have a higher gain curve
957 * override min power */
958 chinfo[pier].min_pwr = pd->pd_pwr[0];
966 /* Parse EEPROM data */
968 ath5k_eeprom_read_pcal_info_5112(struct ath5k_hw *ah, int mode)
970 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
971 struct ath5k_chan_pcal_info_rf5112 *chan_pcal_info;
972 struct ath5k_chan_pcal_info *gen_chan_info;
973 u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
980 /* Count how many curves we have and
981 * identify them (which one of the 4
982 * available curves we have on each count).
983 * Curves are stored from lower (x0) to
984 * higher (x3) gain */
985 for (i = 0; i < AR5K_EEPROM_N_PD_CURVES; i++) {
986 /* ee_x_gain[mode] is x gain mask */
987 if ((ee->ee_x_gain[mode] >> i) & 0x1)
988 pdgain_idx[pd_gains++] = i;
990 ee->ee_pd_gains[mode] = pd_gains;
992 if (pd_gains == 0 || pd_gains > 2)
996 case AR5K_EEPROM_MODE_11A:
998 * Read 5GHz EEPROM channels
1000 offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
1001 ath5k_eeprom_init_11a_pcal_freq(ah, offset);
1003 offset += AR5K_EEPROM_GROUP2_OFFSET;
1004 gen_chan_info = ee->ee_pwr_cal_a;
1006 case AR5K_EEPROM_MODE_11B:
1007 offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
1008 if (AR5K_EEPROM_HDR_11A(ee->ee_header))
1009 offset += AR5K_EEPROM_GROUP3_OFFSET;
1011 /* NB: frequency piers parsed during mode init */
1012 gen_chan_info = ee->ee_pwr_cal_b;
1014 case AR5K_EEPROM_MODE_11G:
1015 offset = AR5K_EEPROM_GROUPS_START(ee->ee_version);
1016 if (AR5K_EEPROM_HDR_11A(ee->ee_header))
1017 offset += AR5K_EEPROM_GROUP4_OFFSET;
1018 else if (AR5K_EEPROM_HDR_11B(ee->ee_header))
1019 offset += AR5K_EEPROM_GROUP2_OFFSET;
1021 /* NB: frequency piers parsed during mode init */
1022 gen_chan_info = ee->ee_pwr_cal_g;
1028 for (i = 0; i < ee->ee_n_piers[mode]; i++) {
1029 chan_pcal_info = &gen_chan_info[i].rf5112_info;
1031 /* Power values in quarter dB
1032 * for the lower xpd gain curve
1033 * (0 dBm -> higher output power) */
1034 for (c = 0; c < AR5K_EEPROM_N_XPD0_POINTS; c++) {
1035 AR5K_EEPROM_READ(offset++, val);
1036 chan_pcal_info->pwr_x0[c] = (s8) (val & 0xff);
1037 chan_pcal_info->pwr_x0[++c] = (s8) ((val >> 8) & 0xff);
1041 * corresponding to the above power
1043 AR5K_EEPROM_READ(offset++, val);
1044 chan_pcal_info->pcdac_x0[1] = (val & 0x1f);
1045 chan_pcal_info->pcdac_x0[2] = ((val >> 5) & 0x1f);
1046 chan_pcal_info->pcdac_x0[3] = ((val >> 10) & 0x1f);
1048 /* Power values in quarter dB
1049 * for the higher xpd gain curve
1050 * (18 dBm -> lower output power) */
1051 AR5K_EEPROM_READ(offset++, val);
1052 chan_pcal_info->pwr_x3[0] = (s8) (val & 0xff);
1053 chan_pcal_info->pwr_x3[1] = (s8) ((val >> 8) & 0xff);
1055 AR5K_EEPROM_READ(offset++, val);
1056 chan_pcal_info->pwr_x3[2] = (val & 0xff);
1059 * corresponding to the above power
1060 * measurements (fixed) */
1061 chan_pcal_info->pcdac_x3[0] = 20;
1062 chan_pcal_info->pcdac_x3[1] = 35;
1063 chan_pcal_info->pcdac_x3[2] = 63;
1065 if (ee->ee_version >= AR5K_EEPROM_VERSION_4_3) {
1066 chan_pcal_info->pcdac_x0[0] = ((val >> 8) & 0x3f);
1068 /* Last xpd0 power level is also channel maximum */
1069 gen_chan_info[i].max_pwr = chan_pcal_info->pwr_x0[3];
1071 chan_pcal_info->pcdac_x0[0] = 1;
1072 gen_chan_info[i].max_pwr = (s8) ((val >> 8) & 0xff);
1077 return ath5k_eeprom_convert_pcal_info_5112(ah, mode, gen_chan_info);
1082 * Read power calibration for RF2413 chips
1084 * For RF2413 we have a Power to PDDAC table (Power Detector)
1085 * instead of a PCDAC and 4 pd gain curves for each calibrated channel.
1086 * Each curve has power on x axis in 0.5 db steps and PDDADC steps on y
1087 * axis and looks like an exponential function like the RF5111 curve.
1089 * To recreate the curves we read here the points and interpolate
1090 * later. Note that in most cases only 2 (higher and lower) curves are
1091 * used (like RF5112) but vendors have the oportunity to include all
1092 * 4 curves on eeprom. The final curve (higher power) has an extra
1093 * point for better accuracy like RF5112.
1096 /* For RF2413 power calibration data doesn't start on a fixed location and
1097 * if a mode is not supported, it's section is missing -not zeroed-.
1098 * So we need to calculate the starting offset for each section by using
1099 * these two functions */
1101 /* Return the size of each section based on the mode and the number of pd
1102 * gains available (maximum 4). */
1103 static inline unsigned int
1104 ath5k_pdgains_size_2413(struct ath5k_eeprom_info *ee, unsigned int mode)
1106 static const unsigned int pdgains_size[] = { 4, 6, 9, 12 };
1109 sz = pdgains_size[ee->ee_pd_gains[mode] - 1];
1110 sz *= ee->ee_n_piers[mode];
1115 /* Return the starting offset for a section based on the modes supported
1116 * and each section's size. */
1118 ath5k_cal_data_offset_2413(struct ath5k_eeprom_info *ee, int mode)
1120 u32 offset = AR5K_EEPROM_CAL_DATA_START(ee->ee_misc4);
1123 case AR5K_EEPROM_MODE_11G:
1124 if (AR5K_EEPROM_HDR_11B(ee->ee_header))
1125 offset += ath5k_pdgains_size_2413(ee,
1126 AR5K_EEPROM_MODE_11B) +
1127 AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
1129 case AR5K_EEPROM_MODE_11B:
1130 if (AR5K_EEPROM_HDR_11A(ee->ee_header))
1131 offset += ath5k_pdgains_size_2413(ee,
1132 AR5K_EEPROM_MODE_11A) +
1133 AR5K_EEPROM_N_5GHZ_CHAN / 2;
1135 case AR5K_EEPROM_MODE_11A:
1144 /* Convert RF2413 specific data to generic raw data
1145 * used by interpolation code */
1147 ath5k_eeprom_convert_pcal_info_2413(struct ath5k_hw *ah, int mode,
1148 struct ath5k_chan_pcal_info *chinfo)
1150 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1151 struct ath5k_chan_pcal_info_rf2413 *pcinfo;
1152 u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
1153 unsigned int pier, pdg, point;
1155 /* Fill raw data for each calibration pier */
1156 for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
1158 pcinfo = &chinfo[pier].rf2413_info;
1160 /* Allocate pd_curves for this cal pier */
1161 chinfo[pier].pd_curves =
1162 kcalloc(AR5K_EEPROM_N_PD_CURVES,
1163 sizeof(struct ath5k_pdgain_info),
1166 if (!chinfo[pier].pd_curves)
1169 /* Fill pd_curves */
1170 for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
1172 u8 idx = pdgain_idx[pdg];
1173 struct ath5k_pdgain_info *pd =
1174 &chinfo[pier].pd_curves[idx];
1176 /* One more point for the highest power
1177 * curve (lowest gain) */
1178 if (pdg == ee->ee_pd_gains[mode] - 1)
1179 pd->pd_points = AR5K_EEPROM_N_PD_POINTS;
1181 pd->pd_points = AR5K_EEPROM_N_PD_POINTS - 1;
1183 /* Allocate pd points for this curve */
1184 pd->pd_step = kcalloc(pd->pd_points,
1185 sizeof(u8), GFP_KERNEL);
1190 pd->pd_pwr = kcalloc(pd->pd_points,
1191 sizeof(s16), GFP_KERNEL);
1197 * convert all pwr levels to
1198 * quarter dB for RF5112 combatibility */
1199 pd->pd_step[0] = pcinfo->pddac_i[pdg];
1200 pd->pd_pwr[0] = 4 * pcinfo->pwr_i[pdg];
1202 for (point = 1; point < pd->pd_points; point++) {
1204 pd->pd_pwr[point] = pd->pd_pwr[point - 1] +
1205 2 * pcinfo->pwr[pdg][point - 1];
1207 pd->pd_step[point] = pd->pd_step[point - 1] +
1208 pcinfo->pddac[pdg][point - 1];
1212 /* Highest gain curve -> min power */
1214 chinfo[pier].min_pwr = pd->pd_pwr[0];
1216 /* Lowest gain curve -> max power */
1217 if (pdg == ee->ee_pd_gains[mode] - 1)
1218 chinfo[pier].max_pwr =
1219 pd->pd_pwr[pd->pd_points - 1];
1226 /* Parse EEPROM data */
1228 ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode)
1230 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1231 struct ath5k_chan_pcal_info_rf2413 *pcinfo;
1232 struct ath5k_chan_pcal_info *chinfo;
1233 u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
1239 /* Count how many curves we have and
1240 * identify them (which one of the 4
1241 * available curves we have on each count).
1242 * Curves are stored from higher to
1243 * lower gain so we go backwards */
1244 for (idx = AR5K_EEPROM_N_PD_CURVES - 1; idx >= 0; idx--) {
1245 /* ee_x_gain[mode] is x gain mask */
1246 if ((ee->ee_x_gain[mode] >> idx) & 0x1)
1247 pdgain_idx[pd_gains++] = idx;
1250 ee->ee_pd_gains[mode] = pd_gains;
1255 offset = ath5k_cal_data_offset_2413(ee, mode);
1257 case AR5K_EEPROM_MODE_11A:
1258 if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
1261 ath5k_eeprom_init_11a_pcal_freq(ah, offset);
1262 offset += AR5K_EEPROM_N_5GHZ_CHAN / 2;
1263 chinfo = ee->ee_pwr_cal_a;
1265 case AR5K_EEPROM_MODE_11B:
1266 if (!AR5K_EEPROM_HDR_11B(ee->ee_header))
1269 ath5k_eeprom_init_11bg_2413(ah, mode, offset);
1270 offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
1271 chinfo = ee->ee_pwr_cal_b;
1273 case AR5K_EEPROM_MODE_11G:
1274 if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
1277 ath5k_eeprom_init_11bg_2413(ah, mode, offset);
1278 offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2;
1279 chinfo = ee->ee_pwr_cal_g;
1285 for (i = 0; i < ee->ee_n_piers[mode]; i++) {
1286 pcinfo = &chinfo[i].rf2413_info;
1289 * Read pwr_i, pddac_i and the first
1290 * 2 pd points (pwr, pddac)
1292 AR5K_EEPROM_READ(offset++, val);
1293 pcinfo->pwr_i[0] = val & 0x1f;
1294 pcinfo->pddac_i[0] = (val >> 5) & 0x7f;
1295 pcinfo->pwr[0][0] = (val >> 12) & 0xf;
1297 AR5K_EEPROM_READ(offset++, val);
1298 pcinfo->pddac[0][0] = val & 0x3f;
1299 pcinfo->pwr[0][1] = (val >> 6) & 0xf;
1300 pcinfo->pddac[0][1] = (val >> 10) & 0x3f;
1302 AR5K_EEPROM_READ(offset++, val);
1303 pcinfo->pwr[0][2] = val & 0xf;
1304 pcinfo->pddac[0][2] = (val >> 4) & 0x3f;
1306 pcinfo->pwr[0][3] = 0;
1307 pcinfo->pddac[0][3] = 0;
1311 * Pd gain 0 is not the last pd gain
1312 * so it only has 2 pd points.
1313 * Continue wih pd gain 1.
1315 pcinfo->pwr_i[1] = (val >> 10) & 0x1f;
1317 pcinfo->pddac_i[1] = (val >> 15) & 0x1;
1318 AR5K_EEPROM_READ(offset++, val);
1319 pcinfo->pddac_i[1] |= (val & 0x3F) << 1;
1321 pcinfo->pwr[1][0] = (val >> 6) & 0xf;
1322 pcinfo->pddac[1][0] = (val >> 10) & 0x3f;
1324 AR5K_EEPROM_READ(offset++, val);
1325 pcinfo->pwr[1][1] = val & 0xf;
1326 pcinfo->pddac[1][1] = (val >> 4) & 0x3f;
1327 pcinfo->pwr[1][2] = (val >> 10) & 0xf;
1329 pcinfo->pddac[1][2] = (val >> 14) & 0x3;
1330 AR5K_EEPROM_READ(offset++, val);
1331 pcinfo->pddac[1][2] |= (val & 0xF) << 2;
1333 pcinfo->pwr[1][3] = 0;
1334 pcinfo->pddac[1][3] = 0;
1335 } else if (pd_gains == 1) {
1337 * Pd gain 0 is the last one so
1338 * read the extra point.
1340 pcinfo->pwr[0][3] = (val >> 10) & 0xf;
1342 pcinfo->pddac[0][3] = (val >> 14) & 0x3;
1343 AR5K_EEPROM_READ(offset++, val);
1344 pcinfo->pddac[0][3] |= (val & 0xF) << 2;
1348 * Proceed with the other pd_gains
1352 pcinfo->pwr_i[2] = (val >> 4) & 0x1f;
1353 pcinfo->pddac_i[2] = (val >> 9) & 0x7f;
1355 AR5K_EEPROM_READ(offset++, val);
1356 pcinfo->pwr[2][0] = (val >> 0) & 0xf;
1357 pcinfo->pddac[2][0] = (val >> 4) & 0x3f;
1358 pcinfo->pwr[2][1] = (val >> 10) & 0xf;
1360 pcinfo->pddac[2][1] = (val >> 14) & 0x3;
1361 AR5K_EEPROM_READ(offset++, val);
1362 pcinfo->pddac[2][1] |= (val & 0xF) << 2;
1364 pcinfo->pwr[2][2] = (val >> 4) & 0xf;
1365 pcinfo->pddac[2][2] = (val >> 8) & 0x3f;
1367 pcinfo->pwr[2][3] = 0;
1368 pcinfo->pddac[2][3] = 0;
1369 } else if (pd_gains == 2) {
1370 pcinfo->pwr[1][3] = (val >> 4) & 0xf;
1371 pcinfo->pddac[1][3] = (val >> 8) & 0x3f;
1375 pcinfo->pwr_i[3] = (val >> 14) & 0x3;
1376 AR5K_EEPROM_READ(offset++, val);
1377 pcinfo->pwr_i[3] |= ((val >> 0) & 0x7) << 2;
1379 pcinfo->pddac_i[3] = (val >> 3) & 0x7f;
1380 pcinfo->pwr[3][0] = (val >> 10) & 0xf;
1381 pcinfo->pddac[3][0] = (val >> 14) & 0x3;
1383 AR5K_EEPROM_READ(offset++, val);
1384 pcinfo->pddac[3][0] |= (val & 0xF) << 2;
1385 pcinfo->pwr[3][1] = (val >> 4) & 0xf;
1386 pcinfo->pddac[3][1] = (val >> 8) & 0x3f;
1388 pcinfo->pwr[3][2] = (val >> 14) & 0x3;
1389 AR5K_EEPROM_READ(offset++, val);
1390 pcinfo->pwr[3][2] |= ((val >> 0) & 0x3) << 2;
1392 pcinfo->pddac[3][2] = (val >> 2) & 0x3f;
1393 pcinfo->pwr[3][3] = (val >> 8) & 0xf;
1395 pcinfo->pddac[3][3] = (val >> 12) & 0xF;
1396 AR5K_EEPROM_READ(offset++, val);
1397 pcinfo->pddac[3][3] |= ((val >> 0) & 0x3) << 4;
1398 } else if (pd_gains == 3) {
1399 pcinfo->pwr[2][3] = (val >> 14) & 0x3;
1400 AR5K_EEPROM_READ(offset++, val);
1401 pcinfo->pwr[2][3] |= ((val >> 0) & 0x3) << 2;
1403 pcinfo->pddac[2][3] = (val >> 2) & 0x3f;
1407 return ath5k_eeprom_convert_pcal_info_2413(ah, mode, chinfo);
1412 * Read per rate target power (this is the maximum tx power
1413 * supported by the card). This info is used when setting
1414 * tx power, no matter the channel.
1416 * This also works for v5 EEPROMs.
1419 ath5k_eeprom_read_target_rate_pwr_info(struct ath5k_hw *ah, unsigned int mode)
1421 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1422 struct ath5k_rate_pcal_info *rate_pcal_info;
1423 u8 *rate_target_pwr_num;
1428 offset = AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1);
1429 rate_target_pwr_num = &ee->ee_rate_target_pwr_num[mode];
1431 case AR5K_EEPROM_MODE_11A:
1432 offset += AR5K_EEPROM_TARGET_PWR_OFF_11A(ee->ee_version);
1433 rate_pcal_info = ee->ee_rate_tpwr_a;
1434 ee->ee_rate_target_pwr_num[mode] = AR5K_EEPROM_N_5GHZ_CHAN;
1436 case AR5K_EEPROM_MODE_11B:
1437 offset += AR5K_EEPROM_TARGET_PWR_OFF_11B(ee->ee_version);
1438 rate_pcal_info = ee->ee_rate_tpwr_b;
1439 ee->ee_rate_target_pwr_num[mode] = 2; /* 3rd is g mode's 1st */
1441 case AR5K_EEPROM_MODE_11G:
1442 offset += AR5K_EEPROM_TARGET_PWR_OFF_11G(ee->ee_version);
1443 rate_pcal_info = ee->ee_rate_tpwr_g;
1444 ee->ee_rate_target_pwr_num[mode] = AR5K_EEPROM_N_2GHZ_CHAN;
1450 /* Different freq mask for older eeproms (<= v3.2) */
1451 if (ee->ee_version <= AR5K_EEPROM_VERSION_3_2) {
1452 for (i = 0; i < (*rate_target_pwr_num); i++) {
1453 AR5K_EEPROM_READ(offset++, val);
1454 rate_pcal_info[i].freq =
1455 ath5k_eeprom_bin2freq(ee, (val >> 9) & 0x7f, mode);
1457 rate_pcal_info[i].target_power_6to24 = ((val >> 3) & 0x3f);
1458 rate_pcal_info[i].target_power_36 = (val << 3) & 0x3f;
1460 AR5K_EEPROM_READ(offset++, val);
1462 if (rate_pcal_info[i].freq == AR5K_EEPROM_CHANNEL_DIS ||
1464 (*rate_target_pwr_num) = i;
1468 rate_pcal_info[i].target_power_36 |= ((val >> 13) & 0x7);
1469 rate_pcal_info[i].target_power_48 = ((val >> 7) & 0x3f);
1470 rate_pcal_info[i].target_power_54 = ((val >> 1) & 0x3f);
1473 for (i = 0; i < (*rate_target_pwr_num); i++) {
1474 AR5K_EEPROM_READ(offset++, val);
1475 rate_pcal_info[i].freq =
1476 ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode);
1478 rate_pcal_info[i].target_power_6to24 = ((val >> 2) & 0x3f);
1479 rate_pcal_info[i].target_power_36 = (val << 4) & 0x3f;
1481 AR5K_EEPROM_READ(offset++, val);
1483 if (rate_pcal_info[i].freq == AR5K_EEPROM_CHANNEL_DIS ||
1485 (*rate_target_pwr_num) = i;
1489 rate_pcal_info[i].target_power_36 |= (val >> 12) & 0xf;
1490 rate_pcal_info[i].target_power_48 = ((val >> 6) & 0x3f);
1491 rate_pcal_info[i].target_power_54 = (val & 0x3f);
1499 * Read per channel calibration info from EEPROM
1501 * This info is used to calibrate the baseband power table. Imagine
1502 * that for each channel there is a power curve that's hw specific
1503 * (depends on amplifier etc) and we try to "correct" this curve using
1504 * offests we pass on to phy chip (baseband -> before amplifier) so that
1505 * it can use accurate power values when setting tx power (takes amplifier's
1506 * performance on each channel into account).
1508 * EEPROM provides us with the offsets for some pre-calibrated channels
1509 * and we have to interpolate to create the full table for these channels and
1510 * also the table for any channel.
1513 ath5k_eeprom_read_pcal_info(struct ath5k_hw *ah)
1515 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1516 int (*read_pcal)(struct ath5k_hw *hw, int mode);
1520 if ((ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) &&
1521 (AR5K_EEPROM_EEMAP(ee->ee_misc0) == 1))
1522 read_pcal = ath5k_eeprom_read_pcal_info_5112;
1523 else if ((ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0) &&
1524 (AR5K_EEPROM_EEMAP(ee->ee_misc0) == 2))
1525 read_pcal = ath5k_eeprom_read_pcal_info_2413;
1527 read_pcal = ath5k_eeprom_read_pcal_info_5111;
1530 for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G;
1532 err = read_pcal(ah, mode);
1536 err = ath5k_eeprom_read_target_rate_pwr_info(ah, mode);
1545 ath5k_eeprom_free_pcal_info(struct ath5k_hw *ah, int mode)
1547 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1548 struct ath5k_chan_pcal_info *chinfo;
1552 case AR5K_EEPROM_MODE_11A:
1553 if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
1555 chinfo = ee->ee_pwr_cal_a;
1557 case AR5K_EEPROM_MODE_11B:
1558 if (!AR5K_EEPROM_HDR_11B(ee->ee_header))
1560 chinfo = ee->ee_pwr_cal_b;
1562 case AR5K_EEPROM_MODE_11G:
1563 if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
1565 chinfo = ee->ee_pwr_cal_g;
1571 for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
1572 if (!chinfo[pier].pd_curves)
1575 for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
1576 struct ath5k_pdgain_info *pd =
1577 &chinfo[pier].pd_curves[pdg];
1585 kfree(chinfo[pier].pd_curves);
1592 ath5k_eeprom_detach(struct ath5k_hw *ah)
1596 for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++)
1597 ath5k_eeprom_free_pcal_info(ah, mode);
1600 /* Read conformance test limits used for regulatory control */
1602 ath5k_eeprom_read_ctl_info(struct ath5k_hw *ah)
1604 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1605 struct ath5k_edge_power *rep;
1606 unsigned int fmask, pmask;
1607 unsigned int ctl_mode;
1612 pmask = AR5K_EEPROM_POWER_M;
1613 fmask = AR5K_EEPROM_FREQ_M(ee->ee_version);
1614 offset = AR5K_EEPROM_CTL(ee->ee_version);
1615 ee->ee_ctls = AR5K_EEPROM_N_CTLS(ee->ee_version);
1616 for (i = 0; i < ee->ee_ctls; i += 2) {
1617 AR5K_EEPROM_READ(offset++, val);
1618 ee->ee_ctl[i] = (val >> 8) & 0xff;
1619 ee->ee_ctl[i + 1] = val & 0xff;
1622 offset = AR5K_EEPROM_GROUP8_OFFSET;
1623 if (ee->ee_version >= AR5K_EEPROM_VERSION_4_0)
1624 offset += AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1) -
1625 AR5K_EEPROM_GROUP5_OFFSET;
1627 offset += AR5K_EEPROM_GROUPS_START(ee->ee_version);
1629 rep = ee->ee_ctl_pwr;
1630 for(i = 0; i < ee->ee_ctls; i++) {
1631 switch(ee->ee_ctl[i] & AR5K_CTL_MODE_M) {
1633 case AR5K_CTL_TURBO:
1634 ctl_mode = AR5K_EEPROM_MODE_11A;
1637 ctl_mode = AR5K_EEPROM_MODE_11G;
1640 if (ee->ee_ctl[i] == 0) {
1641 if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3)
1645 rep += AR5K_EEPROM_N_EDGES;
1648 if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3) {
1649 for (j = 0; j < AR5K_EEPROM_N_EDGES; j += 2) {
1650 AR5K_EEPROM_READ(offset++, val);
1651 rep[j].freq = (val >> 8) & fmask;
1652 rep[j + 1].freq = val & fmask;
1654 for (j = 0; j < AR5K_EEPROM_N_EDGES; j += 2) {
1655 AR5K_EEPROM_READ(offset++, val);
1656 rep[j].edge = (val >> 8) & pmask;
1657 rep[j].flag = (val >> 14) & 1;
1658 rep[j + 1].edge = val & pmask;
1659 rep[j + 1].flag = (val >> 6) & 1;
1662 AR5K_EEPROM_READ(offset++, val);
1663 rep[0].freq = (val >> 9) & fmask;
1664 rep[1].freq = (val >> 2) & fmask;
1665 rep[2].freq = (val << 5) & fmask;
1667 AR5K_EEPROM_READ(offset++, val);
1668 rep[2].freq |= (val >> 11) & 0x1f;
1669 rep[3].freq = (val >> 4) & fmask;
1670 rep[4].freq = (val << 3) & fmask;
1672 AR5K_EEPROM_READ(offset++, val);
1673 rep[4].freq |= (val >> 13) & 0x7;
1674 rep[5].freq = (val >> 6) & fmask;
1675 rep[6].freq = (val << 1) & fmask;
1677 AR5K_EEPROM_READ(offset++, val);
1678 rep[6].freq |= (val >> 15) & 0x1;
1679 rep[7].freq = (val >> 8) & fmask;
1681 rep[0].edge = (val >> 2) & pmask;
1682 rep[1].edge = (val << 4) & pmask;
1684 AR5K_EEPROM_READ(offset++, val);
1685 rep[1].edge |= (val >> 12) & 0xf;
1686 rep[2].edge = (val >> 6) & pmask;
1687 rep[3].edge = val & pmask;
1689 AR5K_EEPROM_READ(offset++, val);
1690 rep[4].edge = (val >> 10) & pmask;
1691 rep[5].edge = (val >> 4) & pmask;
1692 rep[6].edge = (val << 2) & pmask;
1694 AR5K_EEPROM_READ(offset++, val);
1695 rep[6].edge |= (val >> 14) & 0x3;
1696 rep[7].edge = (val >> 8) & pmask;
1698 for (j = 0; j < AR5K_EEPROM_N_EDGES; j++) {
1699 rep[j].freq = ath5k_eeprom_bin2freq(ee,
1700 rep[j].freq, ctl_mode);
1702 rep += AR5K_EEPROM_N_EDGES;
1709 ath5k_eeprom_read_spur_chans(struct ath5k_hw *ah)
1711 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1716 offset = AR5K_EEPROM_CTL(ee->ee_version) +
1717 AR5K_EEPROM_N_CTLS(ee->ee_version);
1719 if (ee->ee_version < AR5K_EEPROM_VERSION_5_3) {
1720 /* No spur info for 5GHz */
1721 ee->ee_spur_chans[0][0] = AR5K_EEPROM_NO_SPUR;
1722 /* 2 channels for 2GHz (2464/2420) */
1723 ee->ee_spur_chans[0][1] = AR5K_EEPROM_5413_SPUR_CHAN_1;
1724 ee->ee_spur_chans[1][1] = AR5K_EEPROM_5413_SPUR_CHAN_2;
1725 ee->ee_spur_chans[2][1] = AR5K_EEPROM_NO_SPUR;
1726 } else if (ee->ee_version >= AR5K_EEPROM_VERSION_5_3) {
1727 for (i = 0; i < AR5K_EEPROM_N_SPUR_CHANS; i++) {
1728 AR5K_EEPROM_READ(offset, val);
1729 ee->ee_spur_chans[i][0] = val;
1730 AR5K_EEPROM_READ(offset + AR5K_EEPROM_N_SPUR_CHANS,
1732 ee->ee_spur_chans[i][1] = val;
1741 * Initialize eeprom data structure
1744 ath5k_eeprom_init(struct ath5k_hw *ah)
1748 err = ath5k_eeprom_init_header(ah);
1752 err = ath5k_eeprom_init_modes(ah);
1756 err = ath5k_eeprom_read_pcal_info(ah);
1760 err = ath5k_eeprom_read_ctl_info(ah);
1764 err = ath5k_eeprom_read_spur_chans(ah);
1772 * Read the MAC address from eeprom
1774 int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
1776 u8 mac_d[ETH_ALEN] = {};
1781 ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
1785 for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
1786 ret = ath5k_hw_eeprom_read(ah, offset, &data);
1791 mac_d[octet + 1] = data & 0xff;
1792 mac_d[octet] = data >> 8;
1796 if (!total || total == 3 * 0xffff)
1799 memcpy(mac, mac_d, ETH_ALEN);