1203c4805SLuis R. Rodriguez /* 2203c4805SLuis R. Rodriguez * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org> 3203c4805SLuis R. Rodriguez * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com> 4203c4805SLuis R. Rodriguez * Copyright (c) 2008-2009 Felix Fietkau <nbd@openwrt.org> 5203c4805SLuis R. Rodriguez * 6203c4805SLuis R. Rodriguez * Permission to use, copy, modify, and distribute this software for any 7203c4805SLuis R. Rodriguez * purpose with or without fee is hereby granted, provided that the above 8203c4805SLuis R. Rodriguez * copyright notice and this permission notice appear in all copies. 9203c4805SLuis R. Rodriguez * 10203c4805SLuis R. Rodriguez * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11203c4805SLuis R. Rodriguez * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12203c4805SLuis R. Rodriguez * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13203c4805SLuis R. Rodriguez * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14203c4805SLuis R. Rodriguez * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15203c4805SLuis R. Rodriguez * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16203c4805SLuis R. Rodriguez * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17203c4805SLuis R. Rodriguez * 18203c4805SLuis R. Rodriguez */ 19203c4805SLuis R. Rodriguez 20203c4805SLuis R. Rodriguez /*************************************\ 21203c4805SLuis R. Rodriguez * EEPROM access functions and helpers * 22203c4805SLuis R. Rodriguez \*************************************/ 23203c4805SLuis R. Rodriguez 24*5a0e3ad6STejun Heo #include <linux/slab.h> 25*5a0e3ad6STejun Heo 26203c4805SLuis R. Rodriguez #include "ath5k.h" 27203c4805SLuis R. Rodriguez #include "reg.h" 28203c4805SLuis R. Rodriguez #include "debug.h" 29203c4805SLuis R. Rodriguez #include "base.h" 30203c4805SLuis R. Rodriguez 31203c4805SLuis R. Rodriguez /* 32203c4805SLuis R. Rodriguez * Read from eeprom 33203c4805SLuis R. Rodriguez */ 34203c4805SLuis R. Rodriguez static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data) 35203c4805SLuis R. Rodriguez { 36203c4805SLuis R. Rodriguez u32 status, timeout; 37203c4805SLuis R. Rodriguez 38203c4805SLuis R. Rodriguez ATH5K_TRACE(ah->ah_sc); 39203c4805SLuis R. Rodriguez /* 40203c4805SLuis R. Rodriguez * Initialize EEPROM access 41203c4805SLuis R. Rodriguez */ 42203c4805SLuis R. Rodriguez if (ah->ah_version == AR5K_AR5210) { 43203c4805SLuis R. Rodriguez AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE); 44203c4805SLuis R. Rodriguez (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset)); 45203c4805SLuis R. Rodriguez } else { 46203c4805SLuis R. Rodriguez ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE); 47203c4805SLuis R. Rodriguez AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD, 48203c4805SLuis R. Rodriguez AR5K_EEPROM_CMD_READ); 49203c4805SLuis R. Rodriguez } 50203c4805SLuis R. Rodriguez 51203c4805SLuis R. Rodriguez for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) { 52203c4805SLuis R. Rodriguez status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS); 53203c4805SLuis R. Rodriguez if (status & AR5K_EEPROM_STAT_RDDONE) { 54203c4805SLuis R. Rodriguez if (status & AR5K_EEPROM_STAT_RDERR) 55203c4805SLuis R. Rodriguez return -EIO; 56203c4805SLuis R. Rodriguez *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) & 57203c4805SLuis R. Rodriguez 0xffff); 58203c4805SLuis R. Rodriguez return 0; 59203c4805SLuis R. Rodriguez } 60203c4805SLuis R. Rodriguez udelay(15); 61203c4805SLuis R. Rodriguez } 62203c4805SLuis R. Rodriguez 63203c4805SLuis R. Rodriguez return -ETIMEDOUT; 64203c4805SLuis R. Rodriguez } 65203c4805SLuis R. Rodriguez 66203c4805SLuis R. Rodriguez /* 67203c4805SLuis R. Rodriguez * Translate binary channel representation in EEPROM to frequency 68203c4805SLuis R. Rodriguez */ 69203c4805SLuis R. Rodriguez static u16 ath5k_eeprom_bin2freq(struct ath5k_eeprom_info *ee, u16 bin, 70203c4805SLuis R. Rodriguez unsigned int mode) 71203c4805SLuis R. Rodriguez { 72203c4805SLuis R. Rodriguez u16 val; 73203c4805SLuis R. Rodriguez 74203c4805SLuis R. Rodriguez if (bin == AR5K_EEPROM_CHANNEL_DIS) 75203c4805SLuis R. Rodriguez return bin; 76203c4805SLuis R. Rodriguez 77203c4805SLuis R. Rodriguez if (mode == AR5K_EEPROM_MODE_11A) { 78203c4805SLuis R. Rodriguez if (ee->ee_version > AR5K_EEPROM_VERSION_3_2) 79203c4805SLuis R. Rodriguez val = (5 * bin) + 4800; 80203c4805SLuis R. Rodriguez else 81203c4805SLuis R. Rodriguez val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 : 82203c4805SLuis R. Rodriguez (bin * 10) + 5100; 83203c4805SLuis R. Rodriguez } else { 84203c4805SLuis R. Rodriguez if (ee->ee_version > AR5K_EEPROM_VERSION_3_2) 85203c4805SLuis R. Rodriguez val = bin + 2300; 86203c4805SLuis R. Rodriguez else 87203c4805SLuis R. Rodriguez val = bin + 2400; 88203c4805SLuis R. Rodriguez } 89203c4805SLuis R. Rodriguez 90203c4805SLuis R. Rodriguez return val; 91203c4805SLuis R. Rodriguez } 92203c4805SLuis R. Rodriguez 93203c4805SLuis R. Rodriguez /* 94203c4805SLuis R. Rodriguez * Initialize eeprom & capabilities structs 95203c4805SLuis R. Rodriguez */ 96203c4805SLuis R. Rodriguez static int 97203c4805SLuis R. Rodriguez ath5k_eeprom_init_header(struct ath5k_hw *ah) 98203c4805SLuis R. Rodriguez { 99203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 100203c4805SLuis R. Rodriguez int ret; 101203c4805SLuis R. Rodriguez u16 val; 102359207c6SLuis R. Rodriguez u32 cksum, offset, eep_max = AR5K_EEPROM_INFO_MAX; 103203c4805SLuis R. Rodriguez 104203c4805SLuis R. Rodriguez /* 105203c4805SLuis R. Rodriguez * Read values from EEPROM and store them in the capability structure 106203c4805SLuis R. Rodriguez */ 107203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic); 108203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect); 109203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain); 110203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version); 111203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header); 112203c4805SLuis R. Rodriguez 113203c4805SLuis R. Rodriguez /* Return if we have an old EEPROM */ 114203c4805SLuis R. Rodriguez if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0) 115203c4805SLuis R. Rodriguez return 0; 116203c4805SLuis R. Rodriguez 117203c4805SLuis R. Rodriguez /* 118203c4805SLuis R. Rodriguez * Validate the checksum of the EEPROM date. There are some 119203c4805SLuis R. Rodriguez * devices with invalid EEPROMs. 120203c4805SLuis R. Rodriguez */ 121359207c6SLuis R. Rodriguez AR5K_EEPROM_READ(AR5K_EEPROM_SIZE_UPPER, val); 122359207c6SLuis R. Rodriguez if (val) { 123359207c6SLuis R. Rodriguez eep_max = (val & AR5K_EEPROM_SIZE_UPPER_MASK) << 124359207c6SLuis R. Rodriguez AR5K_EEPROM_SIZE_ENDLOC_SHIFT; 125359207c6SLuis R. Rodriguez AR5K_EEPROM_READ(AR5K_EEPROM_SIZE_LOWER, val); 126359207c6SLuis R. Rodriguez eep_max = (eep_max | val) - AR5K_EEPROM_INFO_BASE; 127359207c6SLuis R. Rodriguez 128359207c6SLuis R. Rodriguez /* 129359207c6SLuis R. Rodriguez * Fail safe check to prevent stupid loops due 130359207c6SLuis R. Rodriguez * to busted EEPROMs. XXX: This value is likely too 131359207c6SLuis R. Rodriguez * big still, waiting on a better value. 132359207c6SLuis R. Rodriguez */ 133359207c6SLuis R. Rodriguez if (eep_max > (3 * AR5K_EEPROM_INFO_MAX)) { 134359207c6SLuis R. Rodriguez ATH5K_ERR(ah->ah_sc, "Invalid max custom EEPROM size: " 135359207c6SLuis R. Rodriguez "%d (0x%04x) max expected: %d (0x%04x)\n", 136359207c6SLuis R. Rodriguez eep_max, eep_max, 137359207c6SLuis R. Rodriguez 3 * AR5K_EEPROM_INFO_MAX, 138359207c6SLuis R. Rodriguez 3 * AR5K_EEPROM_INFO_MAX); 139359207c6SLuis R. Rodriguez return -EIO; 140359207c6SLuis R. Rodriguez } 141359207c6SLuis R. Rodriguez } 142359207c6SLuis R. Rodriguez 143359207c6SLuis R. Rodriguez for (cksum = 0, offset = 0; offset < eep_max; offset++) { 144203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val); 145203c4805SLuis R. Rodriguez cksum ^= val; 146203c4805SLuis R. Rodriguez } 147203c4805SLuis R. Rodriguez if (cksum != AR5K_EEPROM_INFO_CKSUM) { 148359207c6SLuis R. Rodriguez ATH5K_ERR(ah->ah_sc, "Invalid EEPROM " 149359207c6SLuis R. Rodriguez "checksum: 0x%04x eep_max: 0x%04x (%s)\n", 150359207c6SLuis R. Rodriguez cksum, eep_max, 151359207c6SLuis R. Rodriguez eep_max == AR5K_EEPROM_INFO_MAX ? 152359207c6SLuis R. Rodriguez "default size" : "custom size"); 153203c4805SLuis R. Rodriguez return -EIO; 154203c4805SLuis R. Rodriguez } 155203c4805SLuis R. Rodriguez 156203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version), 157203c4805SLuis R. Rodriguez ee_ant_gain); 158203c4805SLuis R. Rodriguez 159203c4805SLuis R. Rodriguez if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) { 160203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0); 161203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1); 162203c4805SLuis R. Rodriguez 163203c4805SLuis R. Rodriguez /* XXX: Don't know which versions include these two */ 164203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC2, ee_misc2); 165203c4805SLuis R. Rodriguez 166203c4805SLuis R. Rodriguez if (ee->ee_version >= AR5K_EEPROM_VERSION_4_3) 167203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC3, ee_misc3); 168203c4805SLuis R. Rodriguez 169203c4805SLuis R. Rodriguez if (ee->ee_version >= AR5K_EEPROM_VERSION_5_0) { 170203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC4, ee_misc4); 171203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC5, ee_misc5); 172203c4805SLuis R. Rodriguez AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC6, ee_misc6); 173203c4805SLuis R. Rodriguez } 174203c4805SLuis R. Rodriguez } 175203c4805SLuis R. Rodriguez 176203c4805SLuis R. Rodriguez if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) { 177203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val); 178203c4805SLuis R. Rodriguez ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7; 179203c4805SLuis R. Rodriguez ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7; 180203c4805SLuis R. Rodriguez 181203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val); 182203c4805SLuis R. Rodriguez ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7; 183203c4805SLuis R. Rodriguez ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7; 184203c4805SLuis R. Rodriguez } 185203c4805SLuis R. Rodriguez 1861889ba0aSNick Kossifidis AR5K_EEPROM_READ(AR5K_EEPROM_IS_HB63, val); 1871889ba0aSNick Kossifidis 1881889ba0aSNick Kossifidis if ((ah->ah_mac_version == (AR5K_SREV_AR2425 >> 4)) && val) 1891889ba0aSNick Kossifidis ee->ee_is_hb63 = true; 1901889ba0aSNick Kossifidis else 1911889ba0aSNick Kossifidis ee->ee_is_hb63 = false; 1921889ba0aSNick Kossifidis 1931889ba0aSNick Kossifidis AR5K_EEPROM_READ(AR5K_EEPROM_RFKILL, val); 1941889ba0aSNick Kossifidis ee->ee_rfkill_pin = (u8) AR5K_REG_MS(val, AR5K_EEPROM_RFKILL_GPIO_SEL); 1951889ba0aSNick Kossifidis ee->ee_rfkill_pol = val & AR5K_EEPROM_RFKILL_POLARITY ? true : false; 1961889ba0aSNick Kossifidis 197c38e7a93SNick Kossifidis /* Check if PCIE_OFFSET points to PCIE_SERDES_SECTION 198c38e7a93SNick Kossifidis * and enable serdes programming if needed. 199c38e7a93SNick Kossifidis * 200c38e7a93SNick Kossifidis * XXX: Serdes values seem to be fixed so 201c38e7a93SNick Kossifidis * no need to read them here, we write them 202c38e7a93SNick Kossifidis * during ath5k_hw_attach */ 203c38e7a93SNick Kossifidis AR5K_EEPROM_READ(AR5K_EEPROM_PCIE_OFFSET, val); 204c38e7a93SNick Kossifidis ee->ee_serdes = (val == AR5K_EEPROM_PCIE_SERDES_SECTION) ? 205c38e7a93SNick Kossifidis true : false; 206c38e7a93SNick Kossifidis 207203c4805SLuis R. Rodriguez return 0; 208203c4805SLuis R. Rodriguez } 209203c4805SLuis R. Rodriguez 210203c4805SLuis R. Rodriguez 211203c4805SLuis R. Rodriguez /* 212203c4805SLuis R. Rodriguez * Read antenna infos from eeprom 213203c4805SLuis R. Rodriguez */ 214203c4805SLuis R. Rodriguez static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset, 215203c4805SLuis R. Rodriguez unsigned int mode) 216203c4805SLuis R. Rodriguez { 217203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 218203c4805SLuis R. Rodriguez u32 o = *offset; 219203c4805SLuis R. Rodriguez u16 val; 220203c4805SLuis R. Rodriguez int ret, i = 0; 221203c4805SLuis R. Rodriguez 222203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 223203c4805SLuis R. Rodriguez ee->ee_switch_settling[mode] = (val >> 8) & 0x7f; 224203c4805SLuis R. Rodriguez ee->ee_atn_tx_rx[mode] = (val >> 2) & 0x3f; 225203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i] = (val << 4) & 0x3f; 226203c4805SLuis R. Rodriguez 227203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 228203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf; 229203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f; 230203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i++] = val & 0x3f; 231203c4805SLuis R. Rodriguez 232203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 233203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f; 234203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f; 235203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i] = (val << 2) & 0x3f; 236203c4805SLuis R. Rodriguez 237203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 238203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3; 239203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f; 240203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f; 241203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i] = (val << 4) & 0x3f; 242203c4805SLuis R. Rodriguez 243203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 244203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf; 245203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f; 246203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][i++] = val & 0x3f; 247203c4805SLuis R. Rodriguez 2482bed03ebSNick Kossifidis /* Get antenna switch tables */ 2492bed03ebSNick Kossifidis ah->ah_ant_ctl[mode][AR5K_ANT_CTL] = 250203c4805SLuis R. Rodriguez (ee->ee_ant_control[mode][0] << 4); 2512bed03ebSNick Kossifidis ah->ah_ant_ctl[mode][AR5K_ANT_SWTABLE_A] = 252203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][1] | 253203c4805SLuis R. Rodriguez (ee->ee_ant_control[mode][2] << 6) | 254203c4805SLuis R. Rodriguez (ee->ee_ant_control[mode][3] << 12) | 255203c4805SLuis R. Rodriguez (ee->ee_ant_control[mode][4] << 18) | 256203c4805SLuis R. Rodriguez (ee->ee_ant_control[mode][5] << 24); 2572bed03ebSNick Kossifidis ah->ah_ant_ctl[mode][AR5K_ANT_SWTABLE_B] = 258203c4805SLuis R. Rodriguez ee->ee_ant_control[mode][6] | 259203c4805SLuis R. Rodriguez (ee->ee_ant_control[mode][7] << 6) | 260203c4805SLuis R. Rodriguez (ee->ee_ant_control[mode][8] << 12) | 261203c4805SLuis R. Rodriguez (ee->ee_ant_control[mode][9] << 18) | 262203c4805SLuis R. Rodriguez (ee->ee_ant_control[mode][10] << 24); 263203c4805SLuis R. Rodriguez 264203c4805SLuis R. Rodriguez /* return new offset */ 265203c4805SLuis R. Rodriguez *offset = o; 266203c4805SLuis R. Rodriguez 267203c4805SLuis R. Rodriguez return 0; 268203c4805SLuis R. Rodriguez } 269203c4805SLuis R. Rodriguez 270203c4805SLuis R. Rodriguez /* 271203c4805SLuis R. Rodriguez * Read supported modes and some mode-specific calibration data 272203c4805SLuis R. Rodriguez * from eeprom 273203c4805SLuis R. Rodriguez */ 274203c4805SLuis R. Rodriguez static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset, 275203c4805SLuis R. Rodriguez unsigned int mode) 276203c4805SLuis R. Rodriguez { 277203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 278203c4805SLuis R. Rodriguez u32 o = *offset; 279203c4805SLuis R. Rodriguez u16 val; 280203c4805SLuis R. Rodriguez int ret; 281203c4805SLuis R. Rodriguez 282203c4805SLuis R. Rodriguez ee->ee_n_piers[mode] = 0; 283203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 284203c4805SLuis R. Rodriguez ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff); 285203c4805SLuis R. Rodriguez switch(mode) { 286203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11A: 287203c4805SLuis R. Rodriguez ee->ee_ob[mode][3] = (val >> 5) & 0x7; 288203c4805SLuis R. Rodriguez ee->ee_db[mode][3] = (val >> 2) & 0x7; 289203c4805SLuis R. Rodriguez ee->ee_ob[mode][2] = (val << 1) & 0x7; 290203c4805SLuis R. Rodriguez 291203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 292203c4805SLuis R. Rodriguez ee->ee_ob[mode][2] |= (val >> 15) & 0x1; 293203c4805SLuis R. Rodriguez ee->ee_db[mode][2] = (val >> 12) & 0x7; 294203c4805SLuis R. Rodriguez ee->ee_ob[mode][1] = (val >> 9) & 0x7; 295203c4805SLuis R. Rodriguez ee->ee_db[mode][1] = (val >> 6) & 0x7; 296203c4805SLuis R. Rodriguez ee->ee_ob[mode][0] = (val >> 3) & 0x7; 297203c4805SLuis R. Rodriguez ee->ee_db[mode][0] = val & 0x7; 298203c4805SLuis R. Rodriguez break; 299203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11G: 300203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11B: 301203c4805SLuis R. Rodriguez ee->ee_ob[mode][1] = (val >> 4) & 0x7; 302203c4805SLuis R. Rodriguez ee->ee_db[mode][1] = val & 0x7; 303203c4805SLuis R. Rodriguez break; 304203c4805SLuis R. Rodriguez } 305203c4805SLuis R. Rodriguez 306203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 307203c4805SLuis R. Rodriguez ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff; 308203c4805SLuis R. Rodriguez ee->ee_thr_62[mode] = val & 0xff; 309203c4805SLuis R. Rodriguez 310203c4805SLuis R. Rodriguez if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2) 311203c4805SLuis R. Rodriguez ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28; 312203c4805SLuis R. Rodriguez 313203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 314203c4805SLuis R. Rodriguez ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff; 315203c4805SLuis R. Rodriguez ee->ee_tx_frm2xpa_enable[mode] = val & 0xff; 316203c4805SLuis R. Rodriguez 317203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 318203c4805SLuis R. Rodriguez ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff; 319203c4805SLuis R. Rodriguez 320203c4805SLuis R. Rodriguez if ((val & 0xff) & 0x80) 321203c4805SLuis R. Rodriguez ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1); 322203c4805SLuis R. Rodriguez else 323203c4805SLuis R. Rodriguez ee->ee_noise_floor_thr[mode] = val & 0xff; 324203c4805SLuis R. Rodriguez 325203c4805SLuis R. Rodriguez if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2) 326203c4805SLuis R. Rodriguez ee->ee_noise_floor_thr[mode] = 327203c4805SLuis R. Rodriguez mode == AR5K_EEPROM_MODE_11A ? -54 : -1; 328203c4805SLuis R. Rodriguez 329203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 330203c4805SLuis R. Rodriguez ee->ee_xlna_gain[mode] = (val >> 5) & 0xff; 331203c4805SLuis R. Rodriguez ee->ee_x_gain[mode] = (val >> 1) & 0xf; 332203c4805SLuis R. Rodriguez ee->ee_xpd[mode] = val & 0x1; 333203c4805SLuis R. Rodriguez 334203c4805SLuis R. Rodriguez if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) 335203c4805SLuis R. Rodriguez ee->ee_fixed_bias[mode] = (val >> 13) & 0x1; 336203c4805SLuis R. Rodriguez 337203c4805SLuis R. Rodriguez if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) { 338203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 339203c4805SLuis R. Rodriguez ee->ee_false_detect[mode] = (val >> 6) & 0x7f; 340203c4805SLuis R. Rodriguez 341203c4805SLuis R. Rodriguez if (mode == AR5K_EEPROM_MODE_11A) 342203c4805SLuis R. Rodriguez ee->ee_xr_power[mode] = val & 0x3f; 343203c4805SLuis R. Rodriguez else { 344203c4805SLuis R. Rodriguez ee->ee_ob[mode][0] = val & 0x7; 345203c4805SLuis R. Rodriguez ee->ee_db[mode][0] = (val >> 3) & 0x7; 346203c4805SLuis R. Rodriguez } 347203c4805SLuis R. Rodriguez } 348203c4805SLuis R. Rodriguez 349203c4805SLuis R. Rodriguez if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) { 350203c4805SLuis R. Rodriguez ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN; 351203c4805SLuis R. Rodriguez ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA; 352203c4805SLuis R. Rodriguez } else { 353203c4805SLuis R. Rodriguez ee->ee_i_gain[mode] = (val >> 13) & 0x7; 354203c4805SLuis R. Rodriguez 355203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 356203c4805SLuis R. Rodriguez ee->ee_i_gain[mode] |= (val << 3) & 0x38; 357203c4805SLuis R. Rodriguez 358203c4805SLuis R. Rodriguez if (mode == AR5K_EEPROM_MODE_11G) { 359203c4805SLuis R. Rodriguez ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff; 360203c4805SLuis R. Rodriguez if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6) 361203c4805SLuis R. Rodriguez ee->ee_scaled_cck_delta = (val >> 11) & 0x1f; 362203c4805SLuis R. Rodriguez } 363203c4805SLuis R. Rodriguez } 364203c4805SLuis R. Rodriguez 365203c4805SLuis R. Rodriguez if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 && 366203c4805SLuis R. Rodriguez mode == AR5K_EEPROM_MODE_11A) { 367203c4805SLuis R. Rodriguez ee->ee_i_cal[mode] = (val >> 8) & 0x3f; 368203c4805SLuis R. Rodriguez ee->ee_q_cal[mode] = (val >> 3) & 0x1f; 369203c4805SLuis R. Rodriguez } 370203c4805SLuis R. Rodriguez 371203c4805SLuis R. Rodriguez if (ah->ah_ee_version < AR5K_EEPROM_VERSION_4_0) 372203c4805SLuis R. Rodriguez goto done; 373203c4805SLuis R. Rodriguez 374203c4805SLuis R. Rodriguez /* Note: >= v5 have bg freq piers on another location 375203c4805SLuis R. Rodriguez * so these freq piers are ignored for >= v5 (should be 0xff 376203c4805SLuis R. Rodriguez * anyway) */ 377203c4805SLuis R. Rodriguez switch(mode) { 378203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11A: 379203c4805SLuis R. Rodriguez if (ah->ah_ee_version < AR5K_EEPROM_VERSION_4_1) 380203c4805SLuis R. Rodriguez break; 381203c4805SLuis R. Rodriguez 382203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 383203c4805SLuis R. Rodriguez ee->ee_margin_tx_rx[mode] = val & 0x3f; 384203c4805SLuis R. Rodriguez break; 385203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11B: 386203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 387203c4805SLuis R. Rodriguez 388203c4805SLuis R. Rodriguez ee->ee_pwr_cal_b[0].freq = 389203c4805SLuis R. Rodriguez ath5k_eeprom_bin2freq(ee, val & 0xff, mode); 390203c4805SLuis R. Rodriguez if (ee->ee_pwr_cal_b[0].freq != AR5K_EEPROM_CHANNEL_DIS) 391203c4805SLuis R. Rodriguez ee->ee_n_piers[mode]++; 392203c4805SLuis R. Rodriguez 393203c4805SLuis R. Rodriguez ee->ee_pwr_cal_b[1].freq = 394203c4805SLuis R. Rodriguez ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode); 395203c4805SLuis R. Rodriguez if (ee->ee_pwr_cal_b[1].freq != AR5K_EEPROM_CHANNEL_DIS) 396203c4805SLuis R. Rodriguez ee->ee_n_piers[mode]++; 397203c4805SLuis R. Rodriguez 398203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 399203c4805SLuis R. Rodriguez ee->ee_pwr_cal_b[2].freq = 400203c4805SLuis R. Rodriguez ath5k_eeprom_bin2freq(ee, val & 0xff, mode); 401203c4805SLuis R. Rodriguez if (ee->ee_pwr_cal_b[2].freq != AR5K_EEPROM_CHANNEL_DIS) 402203c4805SLuis R. Rodriguez ee->ee_n_piers[mode]++; 403203c4805SLuis R. Rodriguez 404203c4805SLuis R. Rodriguez if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) 405203c4805SLuis R. Rodriguez ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f; 406203c4805SLuis R. Rodriguez break; 407203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11G: 408203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 409203c4805SLuis R. Rodriguez 410203c4805SLuis R. Rodriguez ee->ee_pwr_cal_g[0].freq = 411203c4805SLuis R. Rodriguez ath5k_eeprom_bin2freq(ee, val & 0xff, mode); 412203c4805SLuis R. Rodriguez if (ee->ee_pwr_cal_g[0].freq != AR5K_EEPROM_CHANNEL_DIS) 413203c4805SLuis R. Rodriguez ee->ee_n_piers[mode]++; 414203c4805SLuis R. Rodriguez 415203c4805SLuis R. Rodriguez ee->ee_pwr_cal_g[1].freq = 416203c4805SLuis R. Rodriguez ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode); 417203c4805SLuis R. Rodriguez if (ee->ee_pwr_cal_g[1].freq != AR5K_EEPROM_CHANNEL_DIS) 418203c4805SLuis R. Rodriguez ee->ee_n_piers[mode]++; 419203c4805SLuis R. Rodriguez 420203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 421203c4805SLuis R. Rodriguez ee->ee_turbo_max_power[mode] = val & 0x7f; 422203c4805SLuis R. Rodriguez ee->ee_xr_power[mode] = (val >> 7) & 0x3f; 423203c4805SLuis R. Rodriguez 424203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 425203c4805SLuis R. Rodriguez ee->ee_pwr_cal_g[2].freq = 426203c4805SLuis R. Rodriguez ath5k_eeprom_bin2freq(ee, val & 0xff, mode); 427203c4805SLuis R. Rodriguez if (ee->ee_pwr_cal_g[2].freq != AR5K_EEPROM_CHANNEL_DIS) 428203c4805SLuis R. Rodriguez ee->ee_n_piers[mode]++; 429203c4805SLuis R. Rodriguez 430203c4805SLuis R. Rodriguez if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) 431203c4805SLuis R. Rodriguez ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f; 432203c4805SLuis R. Rodriguez 433203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 4345f13bfacSBruno Randolf ee->ee_i_cal[mode] = (val >> 5) & 0x3f; 4355f13bfacSBruno Randolf ee->ee_q_cal[mode] = val & 0x1f; 436203c4805SLuis R. Rodriguez 437203c4805SLuis R. Rodriguez if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) { 438203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 439203c4805SLuis R. Rodriguez ee->ee_cck_ofdm_gain_delta = val & 0xff; 440203c4805SLuis R. Rodriguez } 441203c4805SLuis R. Rodriguez break; 442203c4805SLuis R. Rodriguez } 443203c4805SLuis R. Rodriguez 444203c4805SLuis R. Rodriguez /* 445203c4805SLuis R. Rodriguez * Read turbo mode information on newer EEPROM versions 446203c4805SLuis R. Rodriguez */ 447203c4805SLuis R. Rodriguez if (ee->ee_version < AR5K_EEPROM_VERSION_5_0) 4483b3ee43dSPavel Roskin goto done; 449203c4805SLuis R. Rodriguez 450203c4805SLuis R. Rodriguez switch (mode){ 451203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11A: 452203c4805SLuis R. Rodriguez ee->ee_switch_settling_turbo[mode] = (val >> 6) & 0x7f; 453203c4805SLuis R. Rodriguez 454203c4805SLuis R. Rodriguez ee->ee_atn_tx_rx_turbo[mode] = (val >> 13) & 0x7; 455203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 456203c4805SLuis R. Rodriguez ee->ee_atn_tx_rx_turbo[mode] |= (val & 0x7) << 3; 457203c4805SLuis R. Rodriguez ee->ee_margin_tx_rx_turbo[mode] = (val >> 3) & 0x3f; 458203c4805SLuis R. Rodriguez 459203c4805SLuis R. Rodriguez ee->ee_adc_desired_size_turbo[mode] = (val >> 9) & 0x7f; 460203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 461203c4805SLuis R. Rodriguez ee->ee_adc_desired_size_turbo[mode] |= (val & 0x1) << 7; 462203c4805SLuis R. Rodriguez ee->ee_pga_desired_size_turbo[mode] = (val >> 1) & 0xff; 463203c4805SLuis R. Rodriguez 464203c4805SLuis R. Rodriguez if (AR5K_EEPROM_EEMAP(ee->ee_misc0) >=2) 465203c4805SLuis R. Rodriguez ee->ee_pd_gain_overlap = (val >> 9) & 0xf; 466203c4805SLuis R. Rodriguez break; 467203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11G: 468203c4805SLuis R. Rodriguez ee->ee_switch_settling_turbo[mode] = (val >> 8) & 0x7f; 469203c4805SLuis R. Rodriguez 470203c4805SLuis R. Rodriguez ee->ee_atn_tx_rx_turbo[mode] = (val >> 15) & 0x7; 471203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 472203c4805SLuis R. Rodriguez ee->ee_atn_tx_rx_turbo[mode] |= (val & 0x1f) << 1; 473203c4805SLuis R. Rodriguez ee->ee_margin_tx_rx_turbo[mode] = (val >> 5) & 0x3f; 474203c4805SLuis R. Rodriguez 475203c4805SLuis R. Rodriguez ee->ee_adc_desired_size_turbo[mode] = (val >> 11) & 0x7f; 476203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 477203c4805SLuis R. Rodriguez ee->ee_adc_desired_size_turbo[mode] |= (val & 0x7) << 5; 478203c4805SLuis R. Rodriguez ee->ee_pga_desired_size_turbo[mode] = (val >> 3) & 0xff; 479203c4805SLuis R. Rodriguez break; 480203c4805SLuis R. Rodriguez } 481203c4805SLuis R. Rodriguez 4823b3ee43dSPavel Roskin done: 483203c4805SLuis R. Rodriguez /* return new offset */ 484203c4805SLuis R. Rodriguez *offset = o; 485203c4805SLuis R. Rodriguez 486203c4805SLuis R. Rodriguez return 0; 487203c4805SLuis R. Rodriguez } 488203c4805SLuis R. Rodriguez 489203c4805SLuis R. Rodriguez /* Read mode-specific data (except power calibration data) */ 490203c4805SLuis R. Rodriguez static int 491203c4805SLuis R. Rodriguez ath5k_eeprom_init_modes(struct ath5k_hw *ah) 492203c4805SLuis R. Rodriguez { 493203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 494203c4805SLuis R. Rodriguez u32 mode_offset[3]; 495203c4805SLuis R. Rodriguez unsigned int mode; 496203c4805SLuis R. Rodriguez u32 offset; 497203c4805SLuis R. Rodriguez int ret; 498203c4805SLuis R. Rodriguez 499203c4805SLuis R. Rodriguez /* 500203c4805SLuis R. Rodriguez * Get values for all modes 501203c4805SLuis R. Rodriguez */ 502203c4805SLuis R. Rodriguez mode_offset[AR5K_EEPROM_MODE_11A] = AR5K_EEPROM_MODES_11A(ah->ah_ee_version); 503203c4805SLuis R. Rodriguez mode_offset[AR5K_EEPROM_MODE_11B] = AR5K_EEPROM_MODES_11B(ah->ah_ee_version); 504203c4805SLuis R. Rodriguez mode_offset[AR5K_EEPROM_MODE_11G] = AR5K_EEPROM_MODES_11G(ah->ah_ee_version); 505203c4805SLuis R. Rodriguez 506203c4805SLuis R. Rodriguez ee->ee_turbo_max_power[AR5K_EEPROM_MODE_11A] = 507203c4805SLuis R. Rodriguez AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header); 508203c4805SLuis R. Rodriguez 509203c4805SLuis R. Rodriguez for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++) { 510203c4805SLuis R. Rodriguez offset = mode_offset[mode]; 511203c4805SLuis R. Rodriguez 512203c4805SLuis R. Rodriguez ret = ath5k_eeprom_read_ants(ah, &offset, mode); 513203c4805SLuis R. Rodriguez if (ret) 514203c4805SLuis R. Rodriguez return ret; 515203c4805SLuis R. Rodriguez 516203c4805SLuis R. Rodriguez ret = ath5k_eeprom_read_modes(ah, &offset, mode); 517203c4805SLuis R. Rodriguez if (ret) 518203c4805SLuis R. Rodriguez return ret; 519203c4805SLuis R. Rodriguez } 520203c4805SLuis R. Rodriguez 521203c4805SLuis R. Rodriguez /* override for older eeprom versions for better performance */ 522203c4805SLuis R. Rodriguez if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2) { 523203c4805SLuis R. Rodriguez ee->ee_thr_62[AR5K_EEPROM_MODE_11A] = 15; 524203c4805SLuis R. Rodriguez ee->ee_thr_62[AR5K_EEPROM_MODE_11B] = 28; 525203c4805SLuis R. Rodriguez ee->ee_thr_62[AR5K_EEPROM_MODE_11G] = 28; 526203c4805SLuis R. Rodriguez } 527203c4805SLuis R. Rodriguez 528203c4805SLuis R. Rodriguez return 0; 529203c4805SLuis R. Rodriguez } 530203c4805SLuis R. Rodriguez 531203c4805SLuis R. Rodriguez /* Read the frequency piers for each mode (mostly used on newer eeproms with 0xff 532203c4805SLuis R. Rodriguez * frequency mask) */ 533203c4805SLuis R. Rodriguez static inline int 534203c4805SLuis R. Rodriguez ath5k_eeprom_read_freq_list(struct ath5k_hw *ah, int *offset, int max, 535203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info *pc, unsigned int mode) 536203c4805SLuis R. Rodriguez { 537203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 538203c4805SLuis R. Rodriguez int o = *offset; 539203c4805SLuis R. Rodriguez int i = 0; 540203c4805SLuis R. Rodriguez u8 freq1, freq2; 541203c4805SLuis R. Rodriguez int ret; 542203c4805SLuis R. Rodriguez u16 val; 543203c4805SLuis R. Rodriguez 544203c4805SLuis R. Rodriguez ee->ee_n_piers[mode] = 0; 545203c4805SLuis R. Rodriguez while(i < max) { 546203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(o++, val); 547203c4805SLuis R. Rodriguez 548203c4805SLuis R. Rodriguez freq1 = val & 0xff; 549203c4805SLuis R. Rodriguez if (!freq1) 550203c4805SLuis R. Rodriguez break; 551203c4805SLuis R. Rodriguez 552203c4805SLuis R. Rodriguez pc[i++].freq = ath5k_eeprom_bin2freq(ee, 553203c4805SLuis R. Rodriguez freq1, mode); 554203c4805SLuis R. Rodriguez ee->ee_n_piers[mode]++; 555203c4805SLuis R. Rodriguez 556203c4805SLuis R. Rodriguez freq2 = (val >> 8) & 0xff; 557203c4805SLuis R. Rodriguez if (!freq2) 558203c4805SLuis R. Rodriguez break; 559203c4805SLuis R. Rodriguez 560203c4805SLuis R. Rodriguez pc[i++].freq = ath5k_eeprom_bin2freq(ee, 561203c4805SLuis R. Rodriguez freq2, mode); 562203c4805SLuis R. Rodriguez ee->ee_n_piers[mode]++; 563203c4805SLuis R. Rodriguez } 564203c4805SLuis R. Rodriguez 565203c4805SLuis R. Rodriguez /* return new offset */ 566203c4805SLuis R. Rodriguez *offset = o; 567203c4805SLuis R. Rodriguez 568203c4805SLuis R. Rodriguez return 0; 569203c4805SLuis R. Rodriguez } 570203c4805SLuis R. Rodriguez 571203c4805SLuis R. Rodriguez /* Read frequency piers for 802.11a */ 572203c4805SLuis R. Rodriguez static int 573203c4805SLuis R. Rodriguez ath5k_eeprom_init_11a_pcal_freq(struct ath5k_hw *ah, int offset) 574203c4805SLuis R. Rodriguez { 575203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 576203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info *pcal = ee->ee_pwr_cal_a; 577203c4805SLuis R. Rodriguez int i, ret; 578203c4805SLuis R. Rodriguez u16 val; 579203c4805SLuis R. Rodriguez u8 mask; 580203c4805SLuis R. Rodriguez 581203c4805SLuis R. Rodriguez if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3) { 582203c4805SLuis R. Rodriguez ath5k_eeprom_read_freq_list(ah, &offset, 583203c4805SLuis R. Rodriguez AR5K_EEPROM_N_5GHZ_CHAN, pcal, 584203c4805SLuis R. Rodriguez AR5K_EEPROM_MODE_11A); 585203c4805SLuis R. Rodriguez } else { 586203c4805SLuis R. Rodriguez mask = AR5K_EEPROM_FREQ_M(ah->ah_ee_version); 587203c4805SLuis R. Rodriguez 588203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 589203c4805SLuis R. Rodriguez pcal[0].freq = (val >> 9) & mask; 590203c4805SLuis R. Rodriguez pcal[1].freq = (val >> 2) & mask; 591203c4805SLuis R. Rodriguez pcal[2].freq = (val << 5) & mask; 592203c4805SLuis R. Rodriguez 593203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 594203c4805SLuis R. Rodriguez pcal[2].freq |= (val >> 11) & 0x1f; 595203c4805SLuis R. Rodriguez pcal[3].freq = (val >> 4) & mask; 596203c4805SLuis R. Rodriguez pcal[4].freq = (val << 3) & mask; 597203c4805SLuis R. Rodriguez 598203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 599203c4805SLuis R. Rodriguez pcal[4].freq |= (val >> 13) & 0x7; 600203c4805SLuis R. Rodriguez pcal[5].freq = (val >> 6) & mask; 601203c4805SLuis R. Rodriguez pcal[6].freq = (val << 1) & mask; 602203c4805SLuis R. Rodriguez 603203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 604203c4805SLuis R. Rodriguez pcal[6].freq |= (val >> 15) & 0x1; 605203c4805SLuis R. Rodriguez pcal[7].freq = (val >> 8) & mask; 606203c4805SLuis R. Rodriguez pcal[8].freq = (val >> 1) & mask; 607203c4805SLuis R. Rodriguez pcal[9].freq = (val << 6) & mask; 608203c4805SLuis R. Rodriguez 609203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 610203c4805SLuis R. Rodriguez pcal[9].freq |= (val >> 10) & 0x3f; 611203c4805SLuis R. Rodriguez 612203c4805SLuis R. Rodriguez /* Fixed number of piers */ 613203c4805SLuis R. Rodriguez ee->ee_n_piers[AR5K_EEPROM_MODE_11A] = 10; 614203c4805SLuis R. Rodriguez 615203c4805SLuis R. Rodriguez for (i = 0; i < AR5K_EEPROM_N_5GHZ_CHAN; i++) { 616203c4805SLuis R. Rodriguez pcal[i].freq = ath5k_eeprom_bin2freq(ee, 617203c4805SLuis R. Rodriguez pcal[i].freq, AR5K_EEPROM_MODE_11A); 618203c4805SLuis R. Rodriguez } 619203c4805SLuis R. Rodriguez } 620203c4805SLuis R. Rodriguez 621203c4805SLuis R. Rodriguez return 0; 622203c4805SLuis R. Rodriguez } 623203c4805SLuis R. Rodriguez 624203c4805SLuis R. Rodriguez /* Read frequency piers for 802.11bg on eeprom versions >= 5 and eemap >= 2 */ 625203c4805SLuis R. Rodriguez static inline int 626203c4805SLuis R. Rodriguez ath5k_eeprom_init_11bg_2413(struct ath5k_hw *ah, unsigned int mode, int offset) 627203c4805SLuis R. Rodriguez { 628203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 629203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info *pcal; 630203c4805SLuis R. Rodriguez 631203c4805SLuis R. Rodriguez switch(mode) { 632203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11B: 633203c4805SLuis R. Rodriguez pcal = ee->ee_pwr_cal_b; 634203c4805SLuis R. Rodriguez break; 635203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11G: 636203c4805SLuis R. Rodriguez pcal = ee->ee_pwr_cal_g; 637203c4805SLuis R. Rodriguez break; 638203c4805SLuis R. Rodriguez default: 639203c4805SLuis R. Rodriguez return -EINVAL; 640203c4805SLuis R. Rodriguez } 641203c4805SLuis R. Rodriguez 642203c4805SLuis R. Rodriguez ath5k_eeprom_read_freq_list(ah, &offset, 643203c4805SLuis R. Rodriguez AR5K_EEPROM_N_2GHZ_CHAN_2413, pcal, 644203c4805SLuis R. Rodriguez mode); 645203c4805SLuis R. Rodriguez 646203c4805SLuis R. Rodriguez return 0; 647203c4805SLuis R. Rodriguez } 648203c4805SLuis R. Rodriguez 649203c4805SLuis R. Rodriguez /* 650203c4805SLuis R. Rodriguez * Read power calibration for RF5111 chips 651203c4805SLuis R. Rodriguez * 652203c4805SLuis R. Rodriguez * For RF5111 we have an XPD -eXternal Power Detector- curve 653203c4805SLuis R. Rodriguez * for each calibrated channel. Each curve has 0,5dB Power steps 654203c4805SLuis R. Rodriguez * on x axis and PCDAC steps (offsets) on y axis and looks like an 655203c4805SLuis R. Rodriguez * exponential function. To recreate the curve we read 11 points 656203c4805SLuis R. Rodriguez * here and interpolate later. 657203c4805SLuis R. Rodriguez */ 658203c4805SLuis R. Rodriguez 659203c4805SLuis R. Rodriguez /* Used to match PCDAC steps with power values on RF5111 chips 660203c4805SLuis R. Rodriguez * (eeprom versions < 4). For RF5111 we have 11 pre-defined PCDAC 661203c4805SLuis R. Rodriguez * steps that match with the power values we read from eeprom. On 662203c4805SLuis R. Rodriguez * older eeprom versions (< 3.2) these steps are equaly spaced at 663203c4805SLuis R. Rodriguez * 10% of the pcdac curve -until the curve reaches it's maximum- 664203c4805SLuis R. Rodriguez * (11 steps from 0 to 100%) but on newer eeprom versions (>= 3.2) 665203c4805SLuis R. Rodriguez * these 11 steps are spaced in a different way. This function returns 666203c4805SLuis R. Rodriguez * the pcdac steps based on eeprom version and curve min/max so that we 667203c4805SLuis R. Rodriguez * can have pcdac/pwr points. 668203c4805SLuis R. Rodriguez */ 669203c4805SLuis R. Rodriguez static inline void 670203c4805SLuis R. Rodriguez ath5k_get_pcdac_intercepts(struct ath5k_hw *ah, u8 min, u8 max, u8 *vp) 671203c4805SLuis R. Rodriguez { 672bbb33881STobias Klauser static const u16 intercepts3[] = 673203c4805SLuis R. Rodriguez { 0, 5, 10, 20, 30, 50, 70, 85, 90, 95, 100 }; 674bbb33881STobias Klauser static const u16 intercepts3_2[] = 675203c4805SLuis R. Rodriguez { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; 676203c4805SLuis R. Rodriguez const u16 *ip; 677203c4805SLuis R. Rodriguez int i; 678203c4805SLuis R. Rodriguez 679203c4805SLuis R. Rodriguez if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_2) 680203c4805SLuis R. Rodriguez ip = intercepts3_2; 681203c4805SLuis R. Rodriguez else 682203c4805SLuis R. Rodriguez ip = intercepts3; 683203c4805SLuis R. Rodriguez 684203c4805SLuis R. Rodriguez for (i = 0; i < ARRAY_SIZE(intercepts3); i++) 685203c4805SLuis R. Rodriguez vp[i] = (ip[i] * max + (100 - ip[i]) * min) / 100; 686203c4805SLuis R. Rodriguez } 687203c4805SLuis R. Rodriguez 688203c4805SLuis R. Rodriguez /* Convert RF5111 specific data to generic raw data 689203c4805SLuis R. Rodriguez * used by interpolation code */ 690203c4805SLuis R. Rodriguez static int 691203c4805SLuis R. Rodriguez ath5k_eeprom_convert_pcal_info_5111(struct ath5k_hw *ah, int mode, 692203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info *chinfo) 693203c4805SLuis R. Rodriguez { 694203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 695203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info_rf5111 *pcinfo; 696203c4805SLuis R. Rodriguez struct ath5k_pdgain_info *pd; 697203c4805SLuis R. Rodriguez u8 pier, point, idx; 698203c4805SLuis R. Rodriguez u8 *pdgain_idx = ee->ee_pdc_to_idx[mode]; 699203c4805SLuis R. Rodriguez 700203c4805SLuis R. Rodriguez /* Fill raw data for each calibration pier */ 701203c4805SLuis R. Rodriguez for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) { 702203c4805SLuis R. Rodriguez 703203c4805SLuis R. Rodriguez pcinfo = &chinfo[pier].rf5111_info; 704203c4805SLuis R. Rodriguez 705203c4805SLuis R. Rodriguez /* Allocate pd_curves for this cal pier */ 706203c4805SLuis R. Rodriguez chinfo[pier].pd_curves = 707203c4805SLuis R. Rodriguez kcalloc(AR5K_EEPROM_N_PD_CURVES, 708203c4805SLuis R. Rodriguez sizeof(struct ath5k_pdgain_info), 709203c4805SLuis R. Rodriguez GFP_KERNEL); 710203c4805SLuis R. Rodriguez 711203c4805SLuis R. Rodriguez if (!chinfo[pier].pd_curves) 712203c4805SLuis R. Rodriguez return -ENOMEM; 713203c4805SLuis R. Rodriguez 714203c4805SLuis R. Rodriguez /* Only one curve for RF5111 715203c4805SLuis R. Rodriguez * find out which one and place 716203c4805SLuis R. Rodriguez * in in pd_curves. 717203c4805SLuis R. Rodriguez * Note: ee_x_gain is reversed here */ 718203c4805SLuis R. Rodriguez for (idx = 0; idx < AR5K_EEPROM_N_PD_CURVES; idx++) { 719203c4805SLuis R. Rodriguez 720203c4805SLuis R. Rodriguez if (!((ee->ee_x_gain[mode] >> idx) & 0x1)) { 721203c4805SLuis R. Rodriguez pdgain_idx[0] = idx; 722203c4805SLuis R. Rodriguez break; 723203c4805SLuis R. Rodriguez } 724203c4805SLuis R. Rodriguez } 725203c4805SLuis R. Rodriguez 726203c4805SLuis R. Rodriguez ee->ee_pd_gains[mode] = 1; 727203c4805SLuis R. Rodriguez 728203c4805SLuis R. Rodriguez pd = &chinfo[pier].pd_curves[idx]; 729203c4805SLuis R. Rodriguez 730203c4805SLuis R. Rodriguez pd->pd_points = AR5K_EEPROM_N_PWR_POINTS_5111; 731203c4805SLuis R. Rodriguez 732203c4805SLuis R. Rodriguez /* Allocate pd points for this curve */ 733203c4805SLuis R. Rodriguez pd->pd_step = kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111, 734203c4805SLuis R. Rodriguez sizeof(u8), GFP_KERNEL); 735203c4805SLuis R. Rodriguez if (!pd->pd_step) 736203c4805SLuis R. Rodriguez return -ENOMEM; 737203c4805SLuis R. Rodriguez 738203c4805SLuis R. Rodriguez pd->pd_pwr = kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111, 739203c4805SLuis R. Rodriguez sizeof(s16), GFP_KERNEL); 740203c4805SLuis R. Rodriguez if (!pd->pd_pwr) 741203c4805SLuis R. Rodriguez return -ENOMEM; 742203c4805SLuis R. Rodriguez 743203c4805SLuis R. Rodriguez /* Fill raw dataset 744203c4805SLuis R. Rodriguez * (convert power to 0.25dB units 745203c4805SLuis R. Rodriguez * for RF5112 combatibility) */ 746203c4805SLuis R. Rodriguez for (point = 0; point < pd->pd_points; point++) { 747203c4805SLuis R. Rodriguez 748203c4805SLuis R. Rodriguez /* Absolute values */ 749203c4805SLuis R. Rodriguez pd->pd_pwr[point] = 2 * pcinfo->pwr[point]; 750203c4805SLuis R. Rodriguez 751203c4805SLuis R. Rodriguez /* Already sorted */ 752203c4805SLuis R. Rodriguez pd->pd_step[point] = pcinfo->pcdac[point]; 753203c4805SLuis R. Rodriguez } 754203c4805SLuis R. Rodriguez 755203c4805SLuis R. Rodriguez /* Set min/max pwr */ 756203c4805SLuis R. Rodriguez chinfo[pier].min_pwr = pd->pd_pwr[0]; 757203c4805SLuis R. Rodriguez chinfo[pier].max_pwr = pd->pd_pwr[10]; 758203c4805SLuis R. Rodriguez 759203c4805SLuis R. Rodriguez } 760203c4805SLuis R. Rodriguez 761203c4805SLuis R. Rodriguez return 0; 762203c4805SLuis R. Rodriguez } 763203c4805SLuis R. Rodriguez 764203c4805SLuis R. Rodriguez /* Parse EEPROM data */ 765203c4805SLuis R. Rodriguez static int 766203c4805SLuis R. Rodriguez ath5k_eeprom_read_pcal_info_5111(struct ath5k_hw *ah, int mode) 767203c4805SLuis R. Rodriguez { 768203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 769203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info *pcal; 770203c4805SLuis R. Rodriguez int offset, ret; 771203c4805SLuis R. Rodriguez int i; 772203c4805SLuis R. Rodriguez u16 val; 773203c4805SLuis R. Rodriguez 774203c4805SLuis R. Rodriguez offset = AR5K_EEPROM_GROUPS_START(ee->ee_version); 775203c4805SLuis R. Rodriguez switch(mode) { 776203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11A: 777203c4805SLuis R. Rodriguez if (!AR5K_EEPROM_HDR_11A(ee->ee_header)) 778203c4805SLuis R. Rodriguez return 0; 779203c4805SLuis R. Rodriguez 780203c4805SLuis R. Rodriguez ret = ath5k_eeprom_init_11a_pcal_freq(ah, 781203c4805SLuis R. Rodriguez offset + AR5K_EEPROM_GROUP1_OFFSET); 782203c4805SLuis R. Rodriguez if (ret < 0) 783203c4805SLuis R. Rodriguez return ret; 784203c4805SLuis R. Rodriguez 785203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_GROUP2_OFFSET; 786203c4805SLuis R. Rodriguez pcal = ee->ee_pwr_cal_a; 787203c4805SLuis R. Rodriguez break; 788203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11B: 789203c4805SLuis R. Rodriguez if (!AR5K_EEPROM_HDR_11B(ee->ee_header) && 790203c4805SLuis R. Rodriguez !AR5K_EEPROM_HDR_11G(ee->ee_header)) 791203c4805SLuis R. Rodriguez return 0; 792203c4805SLuis R. Rodriguez 793203c4805SLuis R. Rodriguez pcal = ee->ee_pwr_cal_b; 794203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_GROUP3_OFFSET; 795203c4805SLuis R. Rodriguez 796203c4805SLuis R. Rodriguez /* fixed piers */ 797203c4805SLuis R. Rodriguez pcal[0].freq = 2412; 798203c4805SLuis R. Rodriguez pcal[1].freq = 2447; 799203c4805SLuis R. Rodriguez pcal[2].freq = 2484; 800203c4805SLuis R. Rodriguez ee->ee_n_piers[mode] = 3; 801203c4805SLuis R. Rodriguez break; 802203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11G: 803203c4805SLuis R. Rodriguez if (!AR5K_EEPROM_HDR_11G(ee->ee_header)) 804203c4805SLuis R. Rodriguez return 0; 805203c4805SLuis R. Rodriguez 806203c4805SLuis R. Rodriguez pcal = ee->ee_pwr_cal_g; 807203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_GROUP4_OFFSET; 808203c4805SLuis R. Rodriguez 809203c4805SLuis R. Rodriguez /* fixed piers */ 810203c4805SLuis R. Rodriguez pcal[0].freq = 2312; 811203c4805SLuis R. Rodriguez pcal[1].freq = 2412; 812203c4805SLuis R. Rodriguez pcal[2].freq = 2484; 813203c4805SLuis R. Rodriguez ee->ee_n_piers[mode] = 3; 814203c4805SLuis R. Rodriguez break; 815203c4805SLuis R. Rodriguez default: 816203c4805SLuis R. Rodriguez return -EINVAL; 817203c4805SLuis R. Rodriguez } 818203c4805SLuis R. Rodriguez 819203c4805SLuis R. Rodriguez for (i = 0; i < ee->ee_n_piers[mode]; i++) { 820203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info_rf5111 *cdata = 821203c4805SLuis R. Rodriguez &pcal[i].rf5111_info; 822203c4805SLuis R. Rodriguez 823203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 824203c4805SLuis R. Rodriguez cdata->pcdac_max = ((val >> 10) & AR5K_EEPROM_PCDAC_M); 825203c4805SLuis R. Rodriguez cdata->pcdac_min = ((val >> 4) & AR5K_EEPROM_PCDAC_M); 826203c4805SLuis R. Rodriguez cdata->pwr[0] = ((val << 2) & AR5K_EEPROM_POWER_M); 827203c4805SLuis R. Rodriguez 828203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 829203c4805SLuis R. Rodriguez cdata->pwr[0] |= ((val >> 14) & 0x3); 830203c4805SLuis R. Rodriguez cdata->pwr[1] = ((val >> 8) & AR5K_EEPROM_POWER_M); 831203c4805SLuis R. Rodriguez cdata->pwr[2] = ((val >> 2) & AR5K_EEPROM_POWER_M); 832203c4805SLuis R. Rodriguez cdata->pwr[3] = ((val << 4) & AR5K_EEPROM_POWER_M); 833203c4805SLuis R. Rodriguez 834203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 835203c4805SLuis R. Rodriguez cdata->pwr[3] |= ((val >> 12) & 0xf); 836203c4805SLuis R. Rodriguez cdata->pwr[4] = ((val >> 6) & AR5K_EEPROM_POWER_M); 837203c4805SLuis R. Rodriguez cdata->pwr[5] = (val & AR5K_EEPROM_POWER_M); 838203c4805SLuis R. Rodriguez 839203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 840203c4805SLuis R. Rodriguez cdata->pwr[6] = ((val >> 10) & AR5K_EEPROM_POWER_M); 841203c4805SLuis R. Rodriguez cdata->pwr[7] = ((val >> 4) & AR5K_EEPROM_POWER_M); 842203c4805SLuis R. Rodriguez cdata->pwr[8] = ((val << 2) & AR5K_EEPROM_POWER_M); 843203c4805SLuis R. Rodriguez 844203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 845203c4805SLuis R. Rodriguez cdata->pwr[8] |= ((val >> 14) & 0x3); 846203c4805SLuis R. Rodriguez cdata->pwr[9] = ((val >> 8) & AR5K_EEPROM_POWER_M); 847203c4805SLuis R. Rodriguez cdata->pwr[10] = ((val >> 2) & AR5K_EEPROM_POWER_M); 848203c4805SLuis R. Rodriguez 849203c4805SLuis R. Rodriguez ath5k_get_pcdac_intercepts(ah, cdata->pcdac_min, 850203c4805SLuis R. Rodriguez cdata->pcdac_max, cdata->pcdac); 851203c4805SLuis R. Rodriguez } 852203c4805SLuis R. Rodriguez 853203c4805SLuis R. Rodriguez return ath5k_eeprom_convert_pcal_info_5111(ah, mode, pcal); 854203c4805SLuis R. Rodriguez } 855203c4805SLuis R. Rodriguez 856203c4805SLuis R. Rodriguez 857203c4805SLuis R. Rodriguez /* 858203c4805SLuis R. Rodriguez * Read power calibration for RF5112 chips 859203c4805SLuis R. Rodriguez * 860203c4805SLuis R. Rodriguez * For RF5112 we have 4 XPD -eXternal Power Detector- curves 861203c4805SLuis R. Rodriguez * for each calibrated channel on 0, -6, -12 and -18dbm but we only 862203c4805SLuis R. Rodriguez * use the higher (3) and the lower (0) curves. Each curve has 0.5dB 863203c4805SLuis R. Rodriguez * power steps on x axis and PCDAC steps on y axis and looks like a 864203c4805SLuis R. Rodriguez * linear function. To recreate the curve and pass the power values 865203c4805SLuis R. Rodriguez * on hw, we read 4 points for xpd 0 (lower gain -> max power) 866203c4805SLuis R. Rodriguez * and 3 points for xpd 3 (higher gain -> lower power) here and 867203c4805SLuis R. Rodriguez * interpolate later. 868203c4805SLuis R. Rodriguez * 869203c4805SLuis R. Rodriguez * Note: Many vendors just use xpd 0 so xpd 3 is zeroed. 870203c4805SLuis R. Rodriguez */ 871203c4805SLuis R. Rodriguez 872203c4805SLuis R. Rodriguez /* Convert RF5112 specific data to generic raw data 873203c4805SLuis R. Rodriguez * used by interpolation code */ 874203c4805SLuis R. Rodriguez static int 875203c4805SLuis R. Rodriguez ath5k_eeprom_convert_pcal_info_5112(struct ath5k_hw *ah, int mode, 876203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info *chinfo) 877203c4805SLuis R. Rodriguez { 878203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 879203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info_rf5112 *pcinfo; 880203c4805SLuis R. Rodriguez u8 *pdgain_idx = ee->ee_pdc_to_idx[mode]; 881203c4805SLuis R. Rodriguez unsigned int pier, pdg, point; 882203c4805SLuis R. Rodriguez 883203c4805SLuis R. Rodriguez /* Fill raw data for each calibration pier */ 884203c4805SLuis R. Rodriguez for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) { 885203c4805SLuis R. Rodriguez 886203c4805SLuis R. Rodriguez pcinfo = &chinfo[pier].rf5112_info; 887203c4805SLuis R. Rodriguez 888203c4805SLuis R. Rodriguez /* Allocate pd_curves for this cal pier */ 889203c4805SLuis R. Rodriguez chinfo[pier].pd_curves = 890203c4805SLuis R. Rodriguez kcalloc(AR5K_EEPROM_N_PD_CURVES, 891203c4805SLuis R. Rodriguez sizeof(struct ath5k_pdgain_info), 892203c4805SLuis R. Rodriguez GFP_KERNEL); 893203c4805SLuis R. Rodriguez 894203c4805SLuis R. Rodriguez if (!chinfo[pier].pd_curves) 895203c4805SLuis R. Rodriguez return -ENOMEM; 896203c4805SLuis R. Rodriguez 897203c4805SLuis R. Rodriguez /* Fill pd_curves */ 898203c4805SLuis R. Rodriguez for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) { 899203c4805SLuis R. Rodriguez 900203c4805SLuis R. Rodriguez u8 idx = pdgain_idx[pdg]; 901203c4805SLuis R. Rodriguez struct ath5k_pdgain_info *pd = 902203c4805SLuis R. Rodriguez &chinfo[pier].pd_curves[idx]; 903203c4805SLuis R. Rodriguez 904203c4805SLuis R. Rodriguez /* Lowest gain curve (max power) */ 905203c4805SLuis R. Rodriguez if (pdg == 0) { 906203c4805SLuis R. Rodriguez /* One more point for better accuracy */ 907203c4805SLuis R. Rodriguez pd->pd_points = AR5K_EEPROM_N_XPD0_POINTS; 908203c4805SLuis R. Rodriguez 909203c4805SLuis R. Rodriguez /* Allocate pd points for this curve */ 910203c4805SLuis R. Rodriguez pd->pd_step = kcalloc(pd->pd_points, 911203c4805SLuis R. Rodriguez sizeof(u8), GFP_KERNEL); 912203c4805SLuis R. Rodriguez 913203c4805SLuis R. Rodriguez if (!pd->pd_step) 914203c4805SLuis R. Rodriguez return -ENOMEM; 915203c4805SLuis R. Rodriguez 916203c4805SLuis R. Rodriguez pd->pd_pwr = kcalloc(pd->pd_points, 917203c4805SLuis R. Rodriguez sizeof(s16), GFP_KERNEL); 918203c4805SLuis R. Rodriguez 919203c4805SLuis R. Rodriguez if (!pd->pd_pwr) 920203c4805SLuis R. Rodriguez return -ENOMEM; 921203c4805SLuis R. Rodriguez 922203c4805SLuis R. Rodriguez 923203c4805SLuis R. Rodriguez /* Fill raw dataset 924203c4805SLuis R. Rodriguez * (all power levels are in 0.25dB units) */ 925203c4805SLuis R. Rodriguez pd->pd_step[0] = pcinfo->pcdac_x0[0]; 926203c4805SLuis R. Rodriguez pd->pd_pwr[0] = pcinfo->pwr_x0[0]; 927203c4805SLuis R. Rodriguez 928203c4805SLuis R. Rodriguez for (point = 1; point < pd->pd_points; 929203c4805SLuis R. Rodriguez point++) { 930203c4805SLuis R. Rodriguez /* Absolute values */ 931203c4805SLuis R. Rodriguez pd->pd_pwr[point] = 932203c4805SLuis R. Rodriguez pcinfo->pwr_x0[point]; 933203c4805SLuis R. Rodriguez 934203c4805SLuis R. Rodriguez /* Deltas */ 935203c4805SLuis R. Rodriguez pd->pd_step[point] = 936203c4805SLuis R. Rodriguez pd->pd_step[point - 1] + 937203c4805SLuis R. Rodriguez pcinfo->pcdac_x0[point]; 938203c4805SLuis R. Rodriguez } 939203c4805SLuis R. Rodriguez 940203c4805SLuis R. Rodriguez /* Set min power for this frequency */ 941203c4805SLuis R. Rodriguez chinfo[pier].min_pwr = pd->pd_pwr[0]; 942203c4805SLuis R. Rodriguez 943203c4805SLuis R. Rodriguez /* Highest gain curve (min power) */ 944203c4805SLuis R. Rodriguez } else if (pdg == 1) { 945203c4805SLuis R. Rodriguez 946203c4805SLuis R. Rodriguez pd->pd_points = AR5K_EEPROM_N_XPD3_POINTS; 947203c4805SLuis R. Rodriguez 948203c4805SLuis R. Rodriguez /* Allocate pd points for this curve */ 949203c4805SLuis R. Rodriguez pd->pd_step = kcalloc(pd->pd_points, 950203c4805SLuis R. Rodriguez sizeof(u8), GFP_KERNEL); 951203c4805SLuis R. Rodriguez 952203c4805SLuis R. Rodriguez if (!pd->pd_step) 953203c4805SLuis R. Rodriguez return -ENOMEM; 954203c4805SLuis R. Rodriguez 955203c4805SLuis R. Rodriguez pd->pd_pwr = kcalloc(pd->pd_points, 956203c4805SLuis R. Rodriguez sizeof(s16), GFP_KERNEL); 957203c4805SLuis R. Rodriguez 958203c4805SLuis R. Rodriguez if (!pd->pd_pwr) 959203c4805SLuis R. Rodriguez return -ENOMEM; 960203c4805SLuis R. Rodriguez 961203c4805SLuis R. Rodriguez /* Fill raw dataset 962203c4805SLuis R. Rodriguez * (all power levels are in 0.25dB units) */ 963203c4805SLuis R. Rodriguez for (point = 0; point < pd->pd_points; 964203c4805SLuis R. Rodriguez point++) { 965203c4805SLuis R. Rodriguez /* Absolute values */ 966203c4805SLuis R. Rodriguez pd->pd_pwr[point] = 967203c4805SLuis R. Rodriguez pcinfo->pwr_x3[point]; 968203c4805SLuis R. Rodriguez 969203c4805SLuis R. Rodriguez /* Fixed points */ 970203c4805SLuis R. Rodriguez pd->pd_step[point] = 971203c4805SLuis R. Rodriguez pcinfo->pcdac_x3[point]; 972203c4805SLuis R. Rodriguez } 973203c4805SLuis R. Rodriguez 974203c4805SLuis R. Rodriguez /* Since we have a higher gain curve 975203c4805SLuis R. Rodriguez * override min power */ 976203c4805SLuis R. Rodriguez chinfo[pier].min_pwr = pd->pd_pwr[0]; 977203c4805SLuis R. Rodriguez } 978203c4805SLuis R. Rodriguez } 979203c4805SLuis R. Rodriguez } 980203c4805SLuis R. Rodriguez 981203c4805SLuis R. Rodriguez return 0; 982203c4805SLuis R. Rodriguez } 983203c4805SLuis R. Rodriguez 984203c4805SLuis R. Rodriguez /* Parse EEPROM data */ 985203c4805SLuis R. Rodriguez static int 986203c4805SLuis R. Rodriguez ath5k_eeprom_read_pcal_info_5112(struct ath5k_hw *ah, int mode) 987203c4805SLuis R. Rodriguez { 988203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 989203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info_rf5112 *chan_pcal_info; 990203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info *gen_chan_info; 991203c4805SLuis R. Rodriguez u8 *pdgain_idx = ee->ee_pdc_to_idx[mode]; 992203c4805SLuis R. Rodriguez u32 offset; 993203c4805SLuis R. Rodriguez u8 i, c; 994203c4805SLuis R. Rodriguez u16 val; 995203c4805SLuis R. Rodriguez int ret; 996203c4805SLuis R. Rodriguez u8 pd_gains = 0; 997203c4805SLuis R. Rodriguez 998203c4805SLuis R. Rodriguez /* Count how many curves we have and 999203c4805SLuis R. Rodriguez * identify them (which one of the 4 1000203c4805SLuis R. Rodriguez * available curves we have on each count). 1001203c4805SLuis R. Rodriguez * Curves are stored from lower (x0) to 1002203c4805SLuis R. Rodriguez * higher (x3) gain */ 1003203c4805SLuis R. Rodriguez for (i = 0; i < AR5K_EEPROM_N_PD_CURVES; i++) { 1004203c4805SLuis R. Rodriguez /* ee_x_gain[mode] is x gain mask */ 1005203c4805SLuis R. Rodriguez if ((ee->ee_x_gain[mode] >> i) & 0x1) 1006203c4805SLuis R. Rodriguez pdgain_idx[pd_gains++] = i; 1007203c4805SLuis R. Rodriguez } 1008203c4805SLuis R. Rodriguez ee->ee_pd_gains[mode] = pd_gains; 1009203c4805SLuis R. Rodriguez 1010203c4805SLuis R. Rodriguez if (pd_gains == 0 || pd_gains > 2) 1011203c4805SLuis R. Rodriguez return -EINVAL; 1012203c4805SLuis R. Rodriguez 1013203c4805SLuis R. Rodriguez switch (mode) { 1014203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11A: 1015203c4805SLuis R. Rodriguez /* 1016203c4805SLuis R. Rodriguez * Read 5GHz EEPROM channels 1017203c4805SLuis R. Rodriguez */ 1018203c4805SLuis R. Rodriguez offset = AR5K_EEPROM_GROUPS_START(ee->ee_version); 1019203c4805SLuis R. Rodriguez ath5k_eeprom_init_11a_pcal_freq(ah, offset); 1020203c4805SLuis R. Rodriguez 1021203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_GROUP2_OFFSET; 1022203c4805SLuis R. Rodriguez gen_chan_info = ee->ee_pwr_cal_a; 1023203c4805SLuis R. Rodriguez break; 1024203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11B: 1025203c4805SLuis R. Rodriguez offset = AR5K_EEPROM_GROUPS_START(ee->ee_version); 1026203c4805SLuis R. Rodriguez if (AR5K_EEPROM_HDR_11A(ee->ee_header)) 1027203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_GROUP3_OFFSET; 1028203c4805SLuis R. Rodriguez 1029203c4805SLuis R. Rodriguez /* NB: frequency piers parsed during mode init */ 1030203c4805SLuis R. Rodriguez gen_chan_info = ee->ee_pwr_cal_b; 1031203c4805SLuis R. Rodriguez break; 1032203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11G: 1033203c4805SLuis R. Rodriguez offset = AR5K_EEPROM_GROUPS_START(ee->ee_version); 1034203c4805SLuis R. Rodriguez if (AR5K_EEPROM_HDR_11A(ee->ee_header)) 1035203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_GROUP4_OFFSET; 1036203c4805SLuis R. Rodriguez else if (AR5K_EEPROM_HDR_11B(ee->ee_header)) 1037203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_GROUP2_OFFSET; 1038203c4805SLuis R. Rodriguez 1039203c4805SLuis R. Rodriguez /* NB: frequency piers parsed during mode init */ 1040203c4805SLuis R. Rodriguez gen_chan_info = ee->ee_pwr_cal_g; 1041203c4805SLuis R. Rodriguez break; 1042203c4805SLuis R. Rodriguez default: 1043203c4805SLuis R. Rodriguez return -EINVAL; 1044203c4805SLuis R. Rodriguez } 1045203c4805SLuis R. Rodriguez 1046203c4805SLuis R. Rodriguez for (i = 0; i < ee->ee_n_piers[mode]; i++) { 1047203c4805SLuis R. Rodriguez chan_pcal_info = &gen_chan_info[i].rf5112_info; 1048203c4805SLuis R. Rodriguez 1049203c4805SLuis R. Rodriguez /* Power values in quarter dB 1050203c4805SLuis R. Rodriguez * for the lower xpd gain curve 1051203c4805SLuis R. Rodriguez * (0 dBm -> higher output power) */ 1052203c4805SLuis R. Rodriguez for (c = 0; c < AR5K_EEPROM_N_XPD0_POINTS; c++) { 1053203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1054203c4805SLuis R. Rodriguez chan_pcal_info->pwr_x0[c] = (s8) (val & 0xff); 1055203c4805SLuis R. Rodriguez chan_pcal_info->pwr_x0[++c] = (s8) ((val >> 8) & 0xff); 1056203c4805SLuis R. Rodriguez } 1057203c4805SLuis R. Rodriguez 1058203c4805SLuis R. Rodriguez /* PCDAC steps 1059203c4805SLuis R. Rodriguez * corresponding to the above power 1060203c4805SLuis R. Rodriguez * measurements */ 1061203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1062203c4805SLuis R. Rodriguez chan_pcal_info->pcdac_x0[1] = (val & 0x1f); 1063203c4805SLuis R. Rodriguez chan_pcal_info->pcdac_x0[2] = ((val >> 5) & 0x1f); 1064203c4805SLuis R. Rodriguez chan_pcal_info->pcdac_x0[3] = ((val >> 10) & 0x1f); 1065203c4805SLuis R. Rodriguez 1066203c4805SLuis R. Rodriguez /* Power values in quarter dB 1067203c4805SLuis R. Rodriguez * for the higher xpd gain curve 1068203c4805SLuis R. Rodriguez * (18 dBm -> lower output power) */ 1069203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1070203c4805SLuis R. Rodriguez chan_pcal_info->pwr_x3[0] = (s8) (val & 0xff); 1071203c4805SLuis R. Rodriguez chan_pcal_info->pwr_x3[1] = (s8) ((val >> 8) & 0xff); 1072203c4805SLuis R. Rodriguez 1073203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1074203c4805SLuis R. Rodriguez chan_pcal_info->pwr_x3[2] = (val & 0xff); 1075203c4805SLuis R. Rodriguez 1076203c4805SLuis R. Rodriguez /* PCDAC steps 1077203c4805SLuis R. Rodriguez * corresponding to the above power 1078203c4805SLuis R. Rodriguez * measurements (fixed) */ 1079203c4805SLuis R. Rodriguez chan_pcal_info->pcdac_x3[0] = 20; 1080203c4805SLuis R. Rodriguez chan_pcal_info->pcdac_x3[1] = 35; 1081203c4805SLuis R. Rodriguez chan_pcal_info->pcdac_x3[2] = 63; 1082203c4805SLuis R. Rodriguez 1083203c4805SLuis R. Rodriguez if (ee->ee_version >= AR5K_EEPROM_VERSION_4_3) { 1084203c4805SLuis R. Rodriguez chan_pcal_info->pcdac_x0[0] = ((val >> 8) & 0x3f); 1085203c4805SLuis R. Rodriguez 1086203c4805SLuis R. Rodriguez /* Last xpd0 power level is also channel maximum */ 1087203c4805SLuis R. Rodriguez gen_chan_info[i].max_pwr = chan_pcal_info->pwr_x0[3]; 1088203c4805SLuis R. Rodriguez } else { 1089203c4805SLuis R. Rodriguez chan_pcal_info->pcdac_x0[0] = 1; 1090203c4805SLuis R. Rodriguez gen_chan_info[i].max_pwr = (s8) ((val >> 8) & 0xff); 1091203c4805SLuis R. Rodriguez } 1092203c4805SLuis R. Rodriguez 1093203c4805SLuis R. Rodriguez } 1094203c4805SLuis R. Rodriguez 1095203c4805SLuis R. Rodriguez return ath5k_eeprom_convert_pcal_info_5112(ah, mode, gen_chan_info); 1096203c4805SLuis R. Rodriguez } 1097203c4805SLuis R. Rodriguez 1098203c4805SLuis R. Rodriguez 1099203c4805SLuis R. Rodriguez /* 1100203c4805SLuis R. Rodriguez * Read power calibration for RF2413 chips 1101203c4805SLuis R. Rodriguez * 1102203c4805SLuis R. Rodriguez * For RF2413 we have a Power to PDDAC table (Power Detector) 1103203c4805SLuis R. Rodriguez * instead of a PCDAC and 4 pd gain curves for each calibrated channel. 1104203c4805SLuis R. Rodriguez * Each curve has power on x axis in 0.5 db steps and PDDADC steps on y 1105203c4805SLuis R. Rodriguez * axis and looks like an exponential function like the RF5111 curve. 1106203c4805SLuis R. Rodriguez * 1107203c4805SLuis R. Rodriguez * To recreate the curves we read here the points and interpolate 1108203c4805SLuis R. Rodriguez * later. Note that in most cases only 2 (higher and lower) curves are 1109203c4805SLuis R. Rodriguez * used (like RF5112) but vendors have the oportunity to include all 1110203c4805SLuis R. Rodriguez * 4 curves on eeprom. The final curve (higher power) has an extra 1111203c4805SLuis R. Rodriguez * point for better accuracy like RF5112. 1112203c4805SLuis R. Rodriguez */ 1113203c4805SLuis R. Rodriguez 1114203c4805SLuis R. Rodriguez /* For RF2413 power calibration data doesn't start on a fixed location and 1115203c4805SLuis R. Rodriguez * if a mode is not supported, it's section is missing -not zeroed-. 1116203c4805SLuis R. Rodriguez * So we need to calculate the starting offset for each section by using 1117203c4805SLuis R. Rodriguez * these two functions */ 1118203c4805SLuis R. Rodriguez 1119203c4805SLuis R. Rodriguez /* Return the size of each section based on the mode and the number of pd 1120203c4805SLuis R. Rodriguez * gains available (maximum 4). */ 1121203c4805SLuis R. Rodriguez static inline unsigned int 1122203c4805SLuis R. Rodriguez ath5k_pdgains_size_2413(struct ath5k_eeprom_info *ee, unsigned int mode) 1123203c4805SLuis R. Rodriguez { 1124203c4805SLuis R. Rodriguez static const unsigned int pdgains_size[] = { 4, 6, 9, 12 }; 1125203c4805SLuis R. Rodriguez unsigned int sz; 1126203c4805SLuis R. Rodriguez 1127203c4805SLuis R. Rodriguez sz = pdgains_size[ee->ee_pd_gains[mode] - 1]; 1128203c4805SLuis R. Rodriguez sz *= ee->ee_n_piers[mode]; 1129203c4805SLuis R. Rodriguez 1130203c4805SLuis R. Rodriguez return sz; 1131203c4805SLuis R. Rodriguez } 1132203c4805SLuis R. Rodriguez 1133203c4805SLuis R. Rodriguez /* Return the starting offset for a section based on the modes supported 1134203c4805SLuis R. Rodriguez * and each section's size. */ 1135203c4805SLuis R. Rodriguez static unsigned int 1136203c4805SLuis R. Rodriguez ath5k_cal_data_offset_2413(struct ath5k_eeprom_info *ee, int mode) 1137203c4805SLuis R. Rodriguez { 1138203c4805SLuis R. Rodriguez u32 offset = AR5K_EEPROM_CAL_DATA_START(ee->ee_misc4); 1139203c4805SLuis R. Rodriguez 1140203c4805SLuis R. Rodriguez switch(mode) { 1141203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11G: 1142203c4805SLuis R. Rodriguez if (AR5K_EEPROM_HDR_11B(ee->ee_header)) 1143203c4805SLuis R. Rodriguez offset += ath5k_pdgains_size_2413(ee, 1144203c4805SLuis R. Rodriguez AR5K_EEPROM_MODE_11B) + 1145203c4805SLuis R. Rodriguez AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2; 1146203c4805SLuis R. Rodriguez /* fall through */ 1147203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11B: 1148203c4805SLuis R. Rodriguez if (AR5K_EEPROM_HDR_11A(ee->ee_header)) 1149203c4805SLuis R. Rodriguez offset += ath5k_pdgains_size_2413(ee, 1150203c4805SLuis R. Rodriguez AR5K_EEPROM_MODE_11A) + 1151203c4805SLuis R. Rodriguez AR5K_EEPROM_N_5GHZ_CHAN / 2; 1152203c4805SLuis R. Rodriguez /* fall through */ 1153203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11A: 1154203c4805SLuis R. Rodriguez break; 1155203c4805SLuis R. Rodriguez default: 1156203c4805SLuis R. Rodriguez break; 1157203c4805SLuis R. Rodriguez } 1158203c4805SLuis R. Rodriguez 1159203c4805SLuis R. Rodriguez return offset; 1160203c4805SLuis R. Rodriguez } 1161203c4805SLuis R. Rodriguez 1162203c4805SLuis R. Rodriguez /* Convert RF2413 specific data to generic raw data 1163203c4805SLuis R. Rodriguez * used by interpolation code */ 1164203c4805SLuis R. Rodriguez static int 1165203c4805SLuis R. Rodriguez ath5k_eeprom_convert_pcal_info_2413(struct ath5k_hw *ah, int mode, 1166203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info *chinfo) 1167203c4805SLuis R. Rodriguez { 1168203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 1169203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info_rf2413 *pcinfo; 1170203c4805SLuis R. Rodriguez u8 *pdgain_idx = ee->ee_pdc_to_idx[mode]; 1171203c4805SLuis R. Rodriguez unsigned int pier, pdg, point; 1172203c4805SLuis R. Rodriguez 1173203c4805SLuis R. Rodriguez /* Fill raw data for each calibration pier */ 1174203c4805SLuis R. Rodriguez for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) { 1175203c4805SLuis R. Rodriguez 1176203c4805SLuis R. Rodriguez pcinfo = &chinfo[pier].rf2413_info; 1177203c4805SLuis R. Rodriguez 1178203c4805SLuis R. Rodriguez /* Allocate pd_curves for this cal pier */ 1179203c4805SLuis R. Rodriguez chinfo[pier].pd_curves = 1180203c4805SLuis R. Rodriguez kcalloc(AR5K_EEPROM_N_PD_CURVES, 1181203c4805SLuis R. Rodriguez sizeof(struct ath5k_pdgain_info), 1182203c4805SLuis R. Rodriguez GFP_KERNEL); 1183203c4805SLuis R. Rodriguez 1184203c4805SLuis R. Rodriguez if (!chinfo[pier].pd_curves) 1185203c4805SLuis R. Rodriguez return -ENOMEM; 1186203c4805SLuis R. Rodriguez 1187203c4805SLuis R. Rodriguez /* Fill pd_curves */ 1188203c4805SLuis R. Rodriguez for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) { 1189203c4805SLuis R. Rodriguez 1190203c4805SLuis R. Rodriguez u8 idx = pdgain_idx[pdg]; 1191203c4805SLuis R. Rodriguez struct ath5k_pdgain_info *pd = 1192203c4805SLuis R. Rodriguez &chinfo[pier].pd_curves[idx]; 1193203c4805SLuis R. Rodriguez 1194203c4805SLuis R. Rodriguez /* One more point for the highest power 1195203c4805SLuis R. Rodriguez * curve (lowest gain) */ 1196203c4805SLuis R. Rodriguez if (pdg == ee->ee_pd_gains[mode] - 1) 1197203c4805SLuis R. Rodriguez pd->pd_points = AR5K_EEPROM_N_PD_POINTS; 1198203c4805SLuis R. Rodriguez else 1199203c4805SLuis R. Rodriguez pd->pd_points = AR5K_EEPROM_N_PD_POINTS - 1; 1200203c4805SLuis R. Rodriguez 1201203c4805SLuis R. Rodriguez /* Allocate pd points for this curve */ 1202203c4805SLuis R. Rodriguez pd->pd_step = kcalloc(pd->pd_points, 1203203c4805SLuis R. Rodriguez sizeof(u8), GFP_KERNEL); 1204203c4805SLuis R. Rodriguez 1205203c4805SLuis R. Rodriguez if (!pd->pd_step) 1206203c4805SLuis R. Rodriguez return -ENOMEM; 1207203c4805SLuis R. Rodriguez 1208203c4805SLuis R. Rodriguez pd->pd_pwr = kcalloc(pd->pd_points, 1209203c4805SLuis R. Rodriguez sizeof(s16), GFP_KERNEL); 1210203c4805SLuis R. Rodriguez 1211203c4805SLuis R. Rodriguez if (!pd->pd_pwr) 1212203c4805SLuis R. Rodriguez return -ENOMEM; 1213203c4805SLuis R. Rodriguez 1214203c4805SLuis R. Rodriguez /* Fill raw dataset 1215203c4805SLuis R. Rodriguez * convert all pwr levels to 1216203c4805SLuis R. Rodriguez * quarter dB for RF5112 combatibility */ 1217203c4805SLuis R. Rodriguez pd->pd_step[0] = pcinfo->pddac_i[pdg]; 1218203c4805SLuis R. Rodriguez pd->pd_pwr[0] = 4 * pcinfo->pwr_i[pdg]; 1219203c4805SLuis R. Rodriguez 1220203c4805SLuis R. Rodriguez for (point = 1; point < pd->pd_points; point++) { 1221203c4805SLuis R. Rodriguez 1222203c4805SLuis R. Rodriguez pd->pd_pwr[point] = pd->pd_pwr[point - 1] + 1223203c4805SLuis R. Rodriguez 2 * pcinfo->pwr[pdg][point - 1]; 1224203c4805SLuis R. Rodriguez 1225203c4805SLuis R. Rodriguez pd->pd_step[point] = pd->pd_step[point - 1] + 1226203c4805SLuis R. Rodriguez pcinfo->pddac[pdg][point - 1]; 1227203c4805SLuis R. Rodriguez 1228203c4805SLuis R. Rodriguez } 1229203c4805SLuis R. Rodriguez 1230203c4805SLuis R. Rodriguez /* Highest gain curve -> min power */ 1231203c4805SLuis R. Rodriguez if (pdg == 0) 1232203c4805SLuis R. Rodriguez chinfo[pier].min_pwr = pd->pd_pwr[0]; 1233203c4805SLuis R. Rodriguez 1234203c4805SLuis R. Rodriguez /* Lowest gain curve -> max power */ 1235203c4805SLuis R. Rodriguez if (pdg == ee->ee_pd_gains[mode] - 1) 1236203c4805SLuis R. Rodriguez chinfo[pier].max_pwr = 1237203c4805SLuis R. Rodriguez pd->pd_pwr[pd->pd_points - 1]; 1238203c4805SLuis R. Rodriguez } 1239203c4805SLuis R. Rodriguez } 1240203c4805SLuis R. Rodriguez 1241203c4805SLuis R. Rodriguez return 0; 1242203c4805SLuis R. Rodriguez } 1243203c4805SLuis R. Rodriguez 1244203c4805SLuis R. Rodriguez /* Parse EEPROM data */ 1245203c4805SLuis R. Rodriguez static int 1246203c4805SLuis R. Rodriguez ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode) 1247203c4805SLuis R. Rodriguez { 1248203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 1249203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info_rf2413 *pcinfo; 1250203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info *chinfo; 1251203c4805SLuis R. Rodriguez u8 *pdgain_idx = ee->ee_pdc_to_idx[mode]; 1252203c4805SLuis R. Rodriguez u32 offset; 1253203c4805SLuis R. Rodriguez int idx, i, ret; 1254203c4805SLuis R. Rodriguez u16 val; 1255203c4805SLuis R. Rodriguez u8 pd_gains = 0; 1256203c4805SLuis R. Rodriguez 1257203c4805SLuis R. Rodriguez /* Count how many curves we have and 1258203c4805SLuis R. Rodriguez * identify them (which one of the 4 1259203c4805SLuis R. Rodriguez * available curves we have on each count). 1260203c4805SLuis R. Rodriguez * Curves are stored from higher to 1261203c4805SLuis R. Rodriguez * lower gain so we go backwards */ 1262203c4805SLuis R. Rodriguez for (idx = AR5K_EEPROM_N_PD_CURVES - 1; idx >= 0; idx--) { 1263203c4805SLuis R. Rodriguez /* ee_x_gain[mode] is x gain mask */ 1264203c4805SLuis R. Rodriguez if ((ee->ee_x_gain[mode] >> idx) & 0x1) 1265203c4805SLuis R. Rodriguez pdgain_idx[pd_gains++] = idx; 1266203c4805SLuis R. Rodriguez 1267203c4805SLuis R. Rodriguez } 1268203c4805SLuis R. Rodriguez ee->ee_pd_gains[mode] = pd_gains; 1269203c4805SLuis R. Rodriguez 1270203c4805SLuis R. Rodriguez if (pd_gains == 0) 1271203c4805SLuis R. Rodriguez return -EINVAL; 1272203c4805SLuis R. Rodriguez 1273203c4805SLuis R. Rodriguez offset = ath5k_cal_data_offset_2413(ee, mode); 1274203c4805SLuis R. Rodriguez switch (mode) { 1275203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11A: 1276203c4805SLuis R. Rodriguez if (!AR5K_EEPROM_HDR_11A(ee->ee_header)) 1277203c4805SLuis R. Rodriguez return 0; 1278203c4805SLuis R. Rodriguez 1279203c4805SLuis R. Rodriguez ath5k_eeprom_init_11a_pcal_freq(ah, offset); 1280203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_N_5GHZ_CHAN / 2; 1281203c4805SLuis R. Rodriguez chinfo = ee->ee_pwr_cal_a; 1282203c4805SLuis R. Rodriguez break; 1283203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11B: 1284203c4805SLuis R. Rodriguez if (!AR5K_EEPROM_HDR_11B(ee->ee_header)) 1285203c4805SLuis R. Rodriguez return 0; 1286203c4805SLuis R. Rodriguez 1287203c4805SLuis R. Rodriguez ath5k_eeprom_init_11bg_2413(ah, mode, offset); 1288203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2; 1289203c4805SLuis R. Rodriguez chinfo = ee->ee_pwr_cal_b; 1290203c4805SLuis R. Rodriguez break; 1291203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11G: 1292203c4805SLuis R. Rodriguez if (!AR5K_EEPROM_HDR_11G(ee->ee_header)) 1293203c4805SLuis R. Rodriguez return 0; 1294203c4805SLuis R. Rodriguez 1295203c4805SLuis R. Rodriguez ath5k_eeprom_init_11bg_2413(ah, mode, offset); 1296203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2; 1297203c4805SLuis R. Rodriguez chinfo = ee->ee_pwr_cal_g; 1298203c4805SLuis R. Rodriguez break; 1299203c4805SLuis R. Rodriguez default: 1300203c4805SLuis R. Rodriguez return -EINVAL; 1301203c4805SLuis R. Rodriguez } 1302203c4805SLuis R. Rodriguez 1303203c4805SLuis R. Rodriguez for (i = 0; i < ee->ee_n_piers[mode]; i++) { 1304203c4805SLuis R. Rodriguez pcinfo = &chinfo[i].rf2413_info; 1305203c4805SLuis R. Rodriguez 1306203c4805SLuis R. Rodriguez /* 1307203c4805SLuis R. Rodriguez * Read pwr_i, pddac_i and the first 1308203c4805SLuis R. Rodriguez * 2 pd points (pwr, pddac) 1309203c4805SLuis R. Rodriguez */ 1310203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1311203c4805SLuis R. Rodriguez pcinfo->pwr_i[0] = val & 0x1f; 1312203c4805SLuis R. Rodriguez pcinfo->pddac_i[0] = (val >> 5) & 0x7f; 1313203c4805SLuis R. Rodriguez pcinfo->pwr[0][0] = (val >> 12) & 0xf; 1314203c4805SLuis R. Rodriguez 1315203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1316203c4805SLuis R. Rodriguez pcinfo->pddac[0][0] = val & 0x3f; 1317203c4805SLuis R. Rodriguez pcinfo->pwr[0][1] = (val >> 6) & 0xf; 1318203c4805SLuis R. Rodriguez pcinfo->pddac[0][1] = (val >> 10) & 0x3f; 1319203c4805SLuis R. Rodriguez 1320203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1321203c4805SLuis R. Rodriguez pcinfo->pwr[0][2] = val & 0xf; 1322203c4805SLuis R. Rodriguez pcinfo->pddac[0][2] = (val >> 4) & 0x3f; 1323203c4805SLuis R. Rodriguez 1324203c4805SLuis R. Rodriguez pcinfo->pwr[0][3] = 0; 1325203c4805SLuis R. Rodriguez pcinfo->pddac[0][3] = 0; 1326203c4805SLuis R. Rodriguez 1327203c4805SLuis R. Rodriguez if (pd_gains > 1) { 1328203c4805SLuis R. Rodriguez /* 1329203c4805SLuis R. Rodriguez * Pd gain 0 is not the last pd gain 1330203c4805SLuis R. Rodriguez * so it only has 2 pd points. 1331203c4805SLuis R. Rodriguez * Continue wih pd gain 1. 1332203c4805SLuis R. Rodriguez */ 1333203c4805SLuis R. Rodriguez pcinfo->pwr_i[1] = (val >> 10) & 0x1f; 1334203c4805SLuis R. Rodriguez 1335203c4805SLuis R. Rodriguez pcinfo->pddac_i[1] = (val >> 15) & 0x1; 1336203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1337203c4805SLuis R. Rodriguez pcinfo->pddac_i[1] |= (val & 0x3F) << 1; 1338203c4805SLuis R. Rodriguez 1339203c4805SLuis R. Rodriguez pcinfo->pwr[1][0] = (val >> 6) & 0xf; 1340203c4805SLuis R. Rodriguez pcinfo->pddac[1][0] = (val >> 10) & 0x3f; 1341203c4805SLuis R. Rodriguez 1342203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1343203c4805SLuis R. Rodriguez pcinfo->pwr[1][1] = val & 0xf; 1344203c4805SLuis R. Rodriguez pcinfo->pddac[1][1] = (val >> 4) & 0x3f; 1345203c4805SLuis R. Rodriguez pcinfo->pwr[1][2] = (val >> 10) & 0xf; 1346203c4805SLuis R. Rodriguez 1347203c4805SLuis R. Rodriguez pcinfo->pddac[1][2] = (val >> 14) & 0x3; 1348203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1349203c4805SLuis R. Rodriguez pcinfo->pddac[1][2] |= (val & 0xF) << 2; 1350203c4805SLuis R. Rodriguez 1351203c4805SLuis R. Rodriguez pcinfo->pwr[1][3] = 0; 1352203c4805SLuis R. Rodriguez pcinfo->pddac[1][3] = 0; 1353203c4805SLuis R. Rodriguez } else if (pd_gains == 1) { 1354203c4805SLuis R. Rodriguez /* 1355203c4805SLuis R. Rodriguez * Pd gain 0 is the last one so 1356203c4805SLuis R. Rodriguez * read the extra point. 1357203c4805SLuis R. Rodriguez */ 1358203c4805SLuis R. Rodriguez pcinfo->pwr[0][3] = (val >> 10) & 0xf; 1359203c4805SLuis R. Rodriguez 1360203c4805SLuis R. Rodriguez pcinfo->pddac[0][3] = (val >> 14) & 0x3; 1361203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1362203c4805SLuis R. Rodriguez pcinfo->pddac[0][3] |= (val & 0xF) << 2; 1363203c4805SLuis R. Rodriguez } 1364203c4805SLuis R. Rodriguez 1365203c4805SLuis R. Rodriguez /* 1366203c4805SLuis R. Rodriguez * Proceed with the other pd_gains 1367203c4805SLuis R. Rodriguez * as above. 1368203c4805SLuis R. Rodriguez */ 1369203c4805SLuis R. Rodriguez if (pd_gains > 2) { 1370203c4805SLuis R. Rodriguez pcinfo->pwr_i[2] = (val >> 4) & 0x1f; 1371203c4805SLuis R. Rodriguez pcinfo->pddac_i[2] = (val >> 9) & 0x7f; 1372203c4805SLuis R. Rodriguez 1373203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1374203c4805SLuis R. Rodriguez pcinfo->pwr[2][0] = (val >> 0) & 0xf; 1375203c4805SLuis R. Rodriguez pcinfo->pddac[2][0] = (val >> 4) & 0x3f; 1376203c4805SLuis R. Rodriguez pcinfo->pwr[2][1] = (val >> 10) & 0xf; 1377203c4805SLuis R. Rodriguez 1378203c4805SLuis R. Rodriguez pcinfo->pddac[2][1] = (val >> 14) & 0x3; 1379203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1380203c4805SLuis R. Rodriguez pcinfo->pddac[2][1] |= (val & 0xF) << 2; 1381203c4805SLuis R. Rodriguez 1382203c4805SLuis R. Rodriguez pcinfo->pwr[2][2] = (val >> 4) & 0xf; 1383203c4805SLuis R. Rodriguez pcinfo->pddac[2][2] = (val >> 8) & 0x3f; 1384203c4805SLuis R. Rodriguez 1385203c4805SLuis R. Rodriguez pcinfo->pwr[2][3] = 0; 1386203c4805SLuis R. Rodriguez pcinfo->pddac[2][3] = 0; 1387203c4805SLuis R. Rodriguez } else if (pd_gains == 2) { 1388203c4805SLuis R. Rodriguez pcinfo->pwr[1][3] = (val >> 4) & 0xf; 1389203c4805SLuis R. Rodriguez pcinfo->pddac[1][3] = (val >> 8) & 0x3f; 1390203c4805SLuis R. Rodriguez } 1391203c4805SLuis R. Rodriguez 1392203c4805SLuis R. Rodriguez if (pd_gains > 3) { 1393203c4805SLuis R. Rodriguez pcinfo->pwr_i[3] = (val >> 14) & 0x3; 1394203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1395203c4805SLuis R. Rodriguez pcinfo->pwr_i[3] |= ((val >> 0) & 0x7) << 2; 1396203c4805SLuis R. Rodriguez 1397203c4805SLuis R. Rodriguez pcinfo->pddac_i[3] = (val >> 3) & 0x7f; 1398203c4805SLuis R. Rodriguez pcinfo->pwr[3][0] = (val >> 10) & 0xf; 1399203c4805SLuis R. Rodriguez pcinfo->pddac[3][0] = (val >> 14) & 0x3; 1400203c4805SLuis R. Rodriguez 1401203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1402203c4805SLuis R. Rodriguez pcinfo->pddac[3][0] |= (val & 0xF) << 2; 1403203c4805SLuis R. Rodriguez pcinfo->pwr[3][1] = (val >> 4) & 0xf; 1404203c4805SLuis R. Rodriguez pcinfo->pddac[3][1] = (val >> 8) & 0x3f; 1405203c4805SLuis R. Rodriguez 1406203c4805SLuis R. Rodriguez pcinfo->pwr[3][2] = (val >> 14) & 0x3; 1407203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1408203c4805SLuis R. Rodriguez pcinfo->pwr[3][2] |= ((val >> 0) & 0x3) << 2; 1409203c4805SLuis R. Rodriguez 1410203c4805SLuis R. Rodriguez pcinfo->pddac[3][2] = (val >> 2) & 0x3f; 1411203c4805SLuis R. Rodriguez pcinfo->pwr[3][3] = (val >> 8) & 0xf; 1412203c4805SLuis R. Rodriguez 1413203c4805SLuis R. Rodriguez pcinfo->pddac[3][3] = (val >> 12) & 0xF; 1414203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1415203c4805SLuis R. Rodriguez pcinfo->pddac[3][3] |= ((val >> 0) & 0x3) << 4; 1416203c4805SLuis R. Rodriguez } else if (pd_gains == 3) { 1417203c4805SLuis R. Rodriguez pcinfo->pwr[2][3] = (val >> 14) & 0x3; 1418203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1419203c4805SLuis R. Rodriguez pcinfo->pwr[2][3] |= ((val >> 0) & 0x3) << 2; 1420203c4805SLuis R. Rodriguez 1421203c4805SLuis R. Rodriguez pcinfo->pddac[2][3] = (val >> 2) & 0x3f; 1422203c4805SLuis R. Rodriguez } 1423203c4805SLuis R. Rodriguez } 1424203c4805SLuis R. Rodriguez 1425203c4805SLuis R. Rodriguez return ath5k_eeprom_convert_pcal_info_2413(ah, mode, chinfo); 1426203c4805SLuis R. Rodriguez } 1427203c4805SLuis R. Rodriguez 1428203c4805SLuis R. Rodriguez 1429203c4805SLuis R. Rodriguez /* 1430203c4805SLuis R. Rodriguez * Read per rate target power (this is the maximum tx power 1431203c4805SLuis R. Rodriguez * supported by the card). This info is used when setting 1432203c4805SLuis R. Rodriguez * tx power, no matter the channel. 1433203c4805SLuis R. Rodriguez * 1434203c4805SLuis R. Rodriguez * This also works for v5 EEPROMs. 1435203c4805SLuis R. Rodriguez */ 1436203c4805SLuis R. Rodriguez static int 1437203c4805SLuis R. Rodriguez ath5k_eeprom_read_target_rate_pwr_info(struct ath5k_hw *ah, unsigned int mode) 1438203c4805SLuis R. Rodriguez { 1439203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 1440203c4805SLuis R. Rodriguez struct ath5k_rate_pcal_info *rate_pcal_info; 1441203c4805SLuis R. Rodriguez u8 *rate_target_pwr_num; 1442203c4805SLuis R. Rodriguez u32 offset; 1443203c4805SLuis R. Rodriguez u16 val; 1444203c4805SLuis R. Rodriguez int ret, i; 1445203c4805SLuis R. Rodriguez 1446203c4805SLuis R. Rodriguez offset = AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1); 1447203c4805SLuis R. Rodriguez rate_target_pwr_num = &ee->ee_rate_target_pwr_num[mode]; 1448203c4805SLuis R. Rodriguez switch (mode) { 1449203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11A: 1450203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_TARGET_PWR_OFF_11A(ee->ee_version); 1451203c4805SLuis R. Rodriguez rate_pcal_info = ee->ee_rate_tpwr_a; 1452203c4805SLuis R. Rodriguez ee->ee_rate_target_pwr_num[mode] = AR5K_EEPROM_N_5GHZ_CHAN; 1453203c4805SLuis R. Rodriguez break; 1454203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11B: 1455203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_TARGET_PWR_OFF_11B(ee->ee_version); 1456203c4805SLuis R. Rodriguez rate_pcal_info = ee->ee_rate_tpwr_b; 1457203c4805SLuis R. Rodriguez ee->ee_rate_target_pwr_num[mode] = 2; /* 3rd is g mode's 1st */ 1458203c4805SLuis R. Rodriguez break; 1459203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11G: 1460203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_TARGET_PWR_OFF_11G(ee->ee_version); 1461203c4805SLuis R. Rodriguez rate_pcal_info = ee->ee_rate_tpwr_g; 1462203c4805SLuis R. Rodriguez ee->ee_rate_target_pwr_num[mode] = AR5K_EEPROM_N_2GHZ_CHAN; 1463203c4805SLuis R. Rodriguez break; 1464203c4805SLuis R. Rodriguez default: 1465203c4805SLuis R. Rodriguez return -EINVAL; 1466203c4805SLuis R. Rodriguez } 1467203c4805SLuis R. Rodriguez 1468203c4805SLuis R. Rodriguez /* Different freq mask for older eeproms (<= v3.2) */ 1469203c4805SLuis R. Rodriguez if (ee->ee_version <= AR5K_EEPROM_VERSION_3_2) { 1470203c4805SLuis R. Rodriguez for (i = 0; i < (*rate_target_pwr_num); i++) { 1471203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1472203c4805SLuis R. Rodriguez rate_pcal_info[i].freq = 1473203c4805SLuis R. Rodriguez ath5k_eeprom_bin2freq(ee, (val >> 9) & 0x7f, mode); 1474203c4805SLuis R. Rodriguez 1475203c4805SLuis R. Rodriguez rate_pcal_info[i].target_power_6to24 = ((val >> 3) & 0x3f); 1476203c4805SLuis R. Rodriguez rate_pcal_info[i].target_power_36 = (val << 3) & 0x3f; 1477203c4805SLuis R. Rodriguez 1478203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1479203c4805SLuis R. Rodriguez 1480203c4805SLuis R. Rodriguez if (rate_pcal_info[i].freq == AR5K_EEPROM_CHANNEL_DIS || 1481203c4805SLuis R. Rodriguez val == 0) { 1482203c4805SLuis R. Rodriguez (*rate_target_pwr_num) = i; 1483203c4805SLuis R. Rodriguez break; 1484203c4805SLuis R. Rodriguez } 1485203c4805SLuis R. Rodriguez 1486203c4805SLuis R. Rodriguez rate_pcal_info[i].target_power_36 |= ((val >> 13) & 0x7); 1487203c4805SLuis R. Rodriguez rate_pcal_info[i].target_power_48 = ((val >> 7) & 0x3f); 1488203c4805SLuis R. Rodriguez rate_pcal_info[i].target_power_54 = ((val >> 1) & 0x3f); 1489203c4805SLuis R. Rodriguez } 1490203c4805SLuis R. Rodriguez } else { 1491203c4805SLuis R. Rodriguez for (i = 0; i < (*rate_target_pwr_num); i++) { 1492203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1493203c4805SLuis R. Rodriguez rate_pcal_info[i].freq = 1494203c4805SLuis R. Rodriguez ath5k_eeprom_bin2freq(ee, (val >> 8) & 0xff, mode); 1495203c4805SLuis R. Rodriguez 1496203c4805SLuis R. Rodriguez rate_pcal_info[i].target_power_6to24 = ((val >> 2) & 0x3f); 1497203c4805SLuis R. Rodriguez rate_pcal_info[i].target_power_36 = (val << 4) & 0x3f; 1498203c4805SLuis R. Rodriguez 1499203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1500203c4805SLuis R. Rodriguez 1501203c4805SLuis R. Rodriguez if (rate_pcal_info[i].freq == AR5K_EEPROM_CHANNEL_DIS || 1502203c4805SLuis R. Rodriguez val == 0) { 1503203c4805SLuis R. Rodriguez (*rate_target_pwr_num) = i; 1504203c4805SLuis R. Rodriguez break; 1505203c4805SLuis R. Rodriguez } 1506203c4805SLuis R. Rodriguez 1507203c4805SLuis R. Rodriguez rate_pcal_info[i].target_power_36 |= (val >> 12) & 0xf; 1508203c4805SLuis R. Rodriguez rate_pcal_info[i].target_power_48 = ((val >> 6) & 0x3f); 1509203c4805SLuis R. Rodriguez rate_pcal_info[i].target_power_54 = (val & 0x3f); 1510203c4805SLuis R. Rodriguez } 1511203c4805SLuis R. Rodriguez } 1512203c4805SLuis R. Rodriguez 1513203c4805SLuis R. Rodriguez return 0; 1514203c4805SLuis R. Rodriguez } 1515203c4805SLuis R. Rodriguez 1516203c4805SLuis R. Rodriguez /* 1517203c4805SLuis R. Rodriguez * Read per channel calibration info from EEPROM 1518203c4805SLuis R. Rodriguez * 1519203c4805SLuis R. Rodriguez * This info is used to calibrate the baseband power table. Imagine 1520203c4805SLuis R. Rodriguez * that for each channel there is a power curve that's hw specific 1521203c4805SLuis R. Rodriguez * (depends on amplifier etc) and we try to "correct" this curve using 1522bf48aabbSUwe Kleine-König * offsets we pass on to phy chip (baseband -> before amplifier) so that 1523203c4805SLuis R. Rodriguez * it can use accurate power values when setting tx power (takes amplifier's 1524203c4805SLuis R. Rodriguez * performance on each channel into account). 1525203c4805SLuis R. Rodriguez * 1526203c4805SLuis R. Rodriguez * EEPROM provides us with the offsets for some pre-calibrated channels 1527203c4805SLuis R. Rodriguez * and we have to interpolate to create the full table for these channels and 1528203c4805SLuis R. Rodriguez * also the table for any channel. 1529203c4805SLuis R. Rodriguez */ 1530203c4805SLuis R. Rodriguez static int 1531203c4805SLuis R. Rodriguez ath5k_eeprom_read_pcal_info(struct ath5k_hw *ah) 1532203c4805SLuis R. Rodriguez { 1533203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 1534203c4805SLuis R. Rodriguez int (*read_pcal)(struct ath5k_hw *hw, int mode); 1535203c4805SLuis R. Rodriguez int mode; 1536203c4805SLuis R. Rodriguez int err; 1537203c4805SLuis R. Rodriguez 1538203c4805SLuis R. Rodriguez if ((ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) && 1539203c4805SLuis R. Rodriguez (AR5K_EEPROM_EEMAP(ee->ee_misc0) == 1)) 1540203c4805SLuis R. Rodriguez read_pcal = ath5k_eeprom_read_pcal_info_5112; 1541203c4805SLuis R. Rodriguez else if ((ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0) && 1542203c4805SLuis R. Rodriguez (AR5K_EEPROM_EEMAP(ee->ee_misc0) == 2)) 1543203c4805SLuis R. Rodriguez read_pcal = ath5k_eeprom_read_pcal_info_2413; 1544203c4805SLuis R. Rodriguez else 1545203c4805SLuis R. Rodriguez read_pcal = ath5k_eeprom_read_pcal_info_5111; 1546203c4805SLuis R. Rodriguez 1547203c4805SLuis R. Rodriguez 1548203c4805SLuis R. Rodriguez for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; 1549203c4805SLuis R. Rodriguez mode++) { 1550203c4805SLuis R. Rodriguez err = read_pcal(ah, mode); 1551203c4805SLuis R. Rodriguez if (err) 1552203c4805SLuis R. Rodriguez return err; 1553203c4805SLuis R. Rodriguez 1554203c4805SLuis R. Rodriguez err = ath5k_eeprom_read_target_rate_pwr_info(ah, mode); 1555203c4805SLuis R. Rodriguez if (err < 0) 1556203c4805SLuis R. Rodriguez return err; 1557203c4805SLuis R. Rodriguez } 1558203c4805SLuis R. Rodriguez 1559203c4805SLuis R. Rodriguez return 0; 1560203c4805SLuis R. Rodriguez } 1561203c4805SLuis R. Rodriguez 1562203c4805SLuis R. Rodriguez static int 1563203c4805SLuis R. Rodriguez ath5k_eeprom_free_pcal_info(struct ath5k_hw *ah, int mode) 1564203c4805SLuis R. Rodriguez { 1565203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 1566203c4805SLuis R. Rodriguez struct ath5k_chan_pcal_info *chinfo; 1567203c4805SLuis R. Rodriguez u8 pier, pdg; 1568203c4805SLuis R. Rodriguez 1569203c4805SLuis R. Rodriguez switch (mode) { 1570203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11A: 1571203c4805SLuis R. Rodriguez if (!AR5K_EEPROM_HDR_11A(ee->ee_header)) 1572203c4805SLuis R. Rodriguez return 0; 1573203c4805SLuis R. Rodriguez chinfo = ee->ee_pwr_cal_a; 1574203c4805SLuis R. Rodriguez break; 1575203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11B: 1576203c4805SLuis R. Rodriguez if (!AR5K_EEPROM_HDR_11B(ee->ee_header)) 1577203c4805SLuis R. Rodriguez return 0; 1578203c4805SLuis R. Rodriguez chinfo = ee->ee_pwr_cal_b; 1579203c4805SLuis R. Rodriguez break; 1580203c4805SLuis R. Rodriguez case AR5K_EEPROM_MODE_11G: 1581203c4805SLuis R. Rodriguez if (!AR5K_EEPROM_HDR_11G(ee->ee_header)) 1582203c4805SLuis R. Rodriguez return 0; 1583203c4805SLuis R. Rodriguez chinfo = ee->ee_pwr_cal_g; 1584203c4805SLuis R. Rodriguez break; 1585203c4805SLuis R. Rodriguez default: 1586203c4805SLuis R. Rodriguez return -EINVAL; 1587203c4805SLuis R. Rodriguez } 1588203c4805SLuis R. Rodriguez 1589203c4805SLuis R. Rodriguez for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) { 1590203c4805SLuis R. Rodriguez if (!chinfo[pier].pd_curves) 1591203c4805SLuis R. Rodriguez continue; 1592203c4805SLuis R. Rodriguez 1593203c4805SLuis R. Rodriguez for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) { 1594203c4805SLuis R. Rodriguez struct ath5k_pdgain_info *pd = 1595203c4805SLuis R. Rodriguez &chinfo[pier].pd_curves[pdg]; 1596203c4805SLuis R. Rodriguez 1597203c4805SLuis R. Rodriguez if (pd != NULL) { 1598203c4805SLuis R. Rodriguez kfree(pd->pd_step); 1599203c4805SLuis R. Rodriguez kfree(pd->pd_pwr); 1600203c4805SLuis R. Rodriguez } 1601203c4805SLuis R. Rodriguez } 1602203c4805SLuis R. Rodriguez 1603203c4805SLuis R. Rodriguez kfree(chinfo[pier].pd_curves); 1604203c4805SLuis R. Rodriguez } 1605203c4805SLuis R. Rodriguez 1606203c4805SLuis R. Rodriguez return 0; 1607203c4805SLuis R. Rodriguez } 1608203c4805SLuis R. Rodriguez 1609203c4805SLuis R. Rodriguez void 1610203c4805SLuis R. Rodriguez ath5k_eeprom_detach(struct ath5k_hw *ah) 1611203c4805SLuis R. Rodriguez { 1612203c4805SLuis R. Rodriguez u8 mode; 1613203c4805SLuis R. Rodriguez 1614203c4805SLuis R. Rodriguez for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++) 1615203c4805SLuis R. Rodriguez ath5k_eeprom_free_pcal_info(ah, mode); 1616203c4805SLuis R. Rodriguez } 1617203c4805SLuis R. Rodriguez 1618203c4805SLuis R. Rodriguez /* Read conformance test limits used for regulatory control */ 1619203c4805SLuis R. Rodriguez static int 1620203c4805SLuis R. Rodriguez ath5k_eeprom_read_ctl_info(struct ath5k_hw *ah) 1621203c4805SLuis R. Rodriguez { 1622203c4805SLuis R. Rodriguez struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 1623203c4805SLuis R. Rodriguez struct ath5k_edge_power *rep; 1624203c4805SLuis R. Rodriguez unsigned int fmask, pmask; 1625203c4805SLuis R. Rodriguez unsigned int ctl_mode; 1626203c4805SLuis R. Rodriguez int ret, i, j; 1627203c4805SLuis R. Rodriguez u32 offset; 1628203c4805SLuis R. Rodriguez u16 val; 1629203c4805SLuis R. Rodriguez 1630203c4805SLuis R. Rodriguez pmask = AR5K_EEPROM_POWER_M; 1631203c4805SLuis R. Rodriguez fmask = AR5K_EEPROM_FREQ_M(ee->ee_version); 1632203c4805SLuis R. Rodriguez offset = AR5K_EEPROM_CTL(ee->ee_version); 1633203c4805SLuis R. Rodriguez ee->ee_ctls = AR5K_EEPROM_N_CTLS(ee->ee_version); 1634203c4805SLuis R. Rodriguez for (i = 0; i < ee->ee_ctls; i += 2) { 1635203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1636203c4805SLuis R. Rodriguez ee->ee_ctl[i] = (val >> 8) & 0xff; 1637203c4805SLuis R. Rodriguez ee->ee_ctl[i + 1] = val & 0xff; 1638203c4805SLuis R. Rodriguez } 1639203c4805SLuis R. Rodriguez 1640203c4805SLuis R. Rodriguez offset = AR5K_EEPROM_GROUP8_OFFSET; 1641203c4805SLuis R. Rodriguez if (ee->ee_version >= AR5K_EEPROM_VERSION_4_0) 1642203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1) - 1643203c4805SLuis R. Rodriguez AR5K_EEPROM_GROUP5_OFFSET; 1644203c4805SLuis R. Rodriguez else 1645203c4805SLuis R. Rodriguez offset += AR5K_EEPROM_GROUPS_START(ee->ee_version); 1646203c4805SLuis R. Rodriguez 1647203c4805SLuis R. Rodriguez rep = ee->ee_ctl_pwr; 1648203c4805SLuis R. Rodriguez for(i = 0; i < ee->ee_ctls; i++) { 1649203c4805SLuis R. Rodriguez switch(ee->ee_ctl[i] & AR5K_CTL_MODE_M) { 1650203c4805SLuis R. Rodriguez case AR5K_CTL_11A: 1651203c4805SLuis R. Rodriguez case AR5K_CTL_TURBO: 1652203c4805SLuis R. Rodriguez ctl_mode = AR5K_EEPROM_MODE_11A; 1653203c4805SLuis R. Rodriguez break; 1654203c4805SLuis R. Rodriguez default: 1655203c4805SLuis R. Rodriguez ctl_mode = AR5K_EEPROM_MODE_11G; 1656203c4805SLuis R. Rodriguez break; 1657203c4805SLuis R. Rodriguez } 1658203c4805SLuis R. Rodriguez if (ee->ee_ctl[i] == 0) { 1659203c4805SLuis R. Rodriguez if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3) 1660203c4805SLuis R. Rodriguez offset += 8; 1661203c4805SLuis R. Rodriguez else 1662203c4805SLuis R. Rodriguez offset += 7; 1663203c4805SLuis R. Rodriguez rep += AR5K_EEPROM_N_EDGES; 1664203c4805SLuis R. Rodriguez continue; 1665203c4805SLuis R. Rodriguez } 1666203c4805SLuis R. Rodriguez if (ee->ee_version >= AR5K_EEPROM_VERSION_3_3) { 1667203c4805SLuis R. Rodriguez for (j = 0; j < AR5K_EEPROM_N_EDGES; j += 2) { 1668203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1669203c4805SLuis R. Rodriguez rep[j].freq = (val >> 8) & fmask; 1670203c4805SLuis R. Rodriguez rep[j + 1].freq = val & fmask; 1671203c4805SLuis R. Rodriguez } 1672203c4805SLuis R. Rodriguez for (j = 0; j < AR5K_EEPROM_N_EDGES; j += 2) { 1673203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1674203c4805SLuis R. Rodriguez rep[j].edge = (val >> 8) & pmask; 1675203c4805SLuis R. Rodriguez rep[j].flag = (val >> 14) & 1; 1676203c4805SLuis R. Rodriguez rep[j + 1].edge = val & pmask; 1677203c4805SLuis R. Rodriguez rep[j + 1].flag = (val >> 6) & 1; 1678203c4805SLuis R. Rodriguez } 1679203c4805SLuis R. Rodriguez } else { 1680203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1681203c4805SLuis R. Rodriguez rep[0].freq = (val >> 9) & fmask; 1682203c4805SLuis R. Rodriguez rep[1].freq = (val >> 2) & fmask; 1683203c4805SLuis R. Rodriguez rep[2].freq = (val << 5) & fmask; 1684203c4805SLuis R. Rodriguez 1685203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1686203c4805SLuis R. Rodriguez rep[2].freq |= (val >> 11) & 0x1f; 1687203c4805SLuis R. Rodriguez rep[3].freq = (val >> 4) & fmask; 1688203c4805SLuis R. Rodriguez rep[4].freq = (val << 3) & fmask; 1689203c4805SLuis R. Rodriguez 1690203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1691203c4805SLuis R. Rodriguez rep[4].freq |= (val >> 13) & 0x7; 1692203c4805SLuis R. Rodriguez rep[5].freq = (val >> 6) & fmask; 1693203c4805SLuis R. Rodriguez rep[6].freq = (val << 1) & fmask; 1694203c4805SLuis R. Rodriguez 1695203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1696203c4805SLuis R. Rodriguez rep[6].freq |= (val >> 15) & 0x1; 1697203c4805SLuis R. Rodriguez rep[7].freq = (val >> 8) & fmask; 1698203c4805SLuis R. Rodriguez 1699203c4805SLuis R. Rodriguez rep[0].edge = (val >> 2) & pmask; 1700203c4805SLuis R. Rodriguez rep[1].edge = (val << 4) & pmask; 1701203c4805SLuis R. Rodriguez 1702203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1703203c4805SLuis R. Rodriguez rep[1].edge |= (val >> 12) & 0xf; 1704203c4805SLuis R. Rodriguez rep[2].edge = (val >> 6) & pmask; 1705203c4805SLuis R. Rodriguez rep[3].edge = val & pmask; 1706203c4805SLuis R. Rodriguez 1707203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1708203c4805SLuis R. Rodriguez rep[4].edge = (val >> 10) & pmask; 1709203c4805SLuis R. Rodriguez rep[5].edge = (val >> 4) & pmask; 1710203c4805SLuis R. Rodriguez rep[6].edge = (val << 2) & pmask; 1711203c4805SLuis R. Rodriguez 1712203c4805SLuis R. Rodriguez AR5K_EEPROM_READ(offset++, val); 1713203c4805SLuis R. Rodriguez rep[6].edge |= (val >> 14) & 0x3; 1714203c4805SLuis R. Rodriguez rep[7].edge = (val >> 8) & pmask; 1715203c4805SLuis R. Rodriguez } 1716203c4805SLuis R. Rodriguez for (j = 0; j < AR5K_EEPROM_N_EDGES; j++) { 1717203c4805SLuis R. Rodriguez rep[j].freq = ath5k_eeprom_bin2freq(ee, 1718203c4805SLuis R. Rodriguez rep[j].freq, ctl_mode); 1719203c4805SLuis R. Rodriguez } 1720203c4805SLuis R. Rodriguez rep += AR5K_EEPROM_N_EDGES; 1721203c4805SLuis R. Rodriguez } 1722203c4805SLuis R. Rodriguez 1723203c4805SLuis R. Rodriguez return 0; 1724203c4805SLuis R. Rodriguez } 1725203c4805SLuis R. Rodriguez 1726cd417519SNick Kossifidis static int 1727cd417519SNick Kossifidis ath5k_eeprom_read_spur_chans(struct ath5k_hw *ah) 1728cd417519SNick Kossifidis { 1729cd417519SNick Kossifidis struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; 1730cd417519SNick Kossifidis u32 offset; 1731cd417519SNick Kossifidis u16 val; 1732cd417519SNick Kossifidis int ret = 0, i; 1733cd417519SNick Kossifidis 1734cd417519SNick Kossifidis offset = AR5K_EEPROM_CTL(ee->ee_version) + 1735cd417519SNick Kossifidis AR5K_EEPROM_N_CTLS(ee->ee_version); 1736cd417519SNick Kossifidis 1737cd417519SNick Kossifidis if (ee->ee_version < AR5K_EEPROM_VERSION_5_3) { 1738cd417519SNick Kossifidis /* No spur info for 5GHz */ 1739cd417519SNick Kossifidis ee->ee_spur_chans[0][0] = AR5K_EEPROM_NO_SPUR; 1740cd417519SNick Kossifidis /* 2 channels for 2GHz (2464/2420) */ 1741cd417519SNick Kossifidis ee->ee_spur_chans[0][1] = AR5K_EEPROM_5413_SPUR_CHAN_1; 1742cd417519SNick Kossifidis ee->ee_spur_chans[1][1] = AR5K_EEPROM_5413_SPUR_CHAN_2; 1743cd417519SNick Kossifidis ee->ee_spur_chans[2][1] = AR5K_EEPROM_NO_SPUR; 1744cd417519SNick Kossifidis } else if (ee->ee_version >= AR5K_EEPROM_VERSION_5_3) { 1745cd417519SNick Kossifidis for (i = 0; i < AR5K_EEPROM_N_SPUR_CHANS; i++) { 1746cd417519SNick Kossifidis AR5K_EEPROM_READ(offset, val); 1747cd417519SNick Kossifidis ee->ee_spur_chans[i][0] = val; 1748cd417519SNick Kossifidis AR5K_EEPROM_READ(offset + AR5K_EEPROM_N_SPUR_CHANS, 1749cd417519SNick Kossifidis val); 1750cd417519SNick Kossifidis ee->ee_spur_chans[i][1] = val; 1751cd417519SNick Kossifidis offset++; 1752cd417519SNick Kossifidis } 1753cd417519SNick Kossifidis } 1754cd417519SNick Kossifidis 1755cd417519SNick Kossifidis return ret; 1756cd417519SNick Kossifidis } 1757203c4805SLuis R. Rodriguez 1758203c4805SLuis R. Rodriguez /* 1759cd417519SNick Kossifidis * Initialize eeprom data structure 1760203c4805SLuis R. Rodriguez */ 1761203c4805SLuis R. Rodriguez int 1762203c4805SLuis R. Rodriguez ath5k_eeprom_init(struct ath5k_hw *ah) 1763203c4805SLuis R. Rodriguez { 1764203c4805SLuis R. Rodriguez int err; 1765203c4805SLuis R. Rodriguez 1766203c4805SLuis R. Rodriguez err = ath5k_eeprom_init_header(ah); 1767203c4805SLuis R. Rodriguez if (err < 0) 1768203c4805SLuis R. Rodriguez return err; 1769203c4805SLuis R. Rodriguez 1770203c4805SLuis R. Rodriguez err = ath5k_eeprom_init_modes(ah); 1771203c4805SLuis R. Rodriguez if (err < 0) 1772203c4805SLuis R. Rodriguez return err; 1773203c4805SLuis R. Rodriguez 1774203c4805SLuis R. Rodriguez err = ath5k_eeprom_read_pcal_info(ah); 1775203c4805SLuis R. Rodriguez if (err < 0) 1776203c4805SLuis R. Rodriguez return err; 1777203c4805SLuis R. Rodriguez 1778203c4805SLuis R. Rodriguez err = ath5k_eeprom_read_ctl_info(ah); 1779203c4805SLuis R. Rodriguez if (err < 0) 1780203c4805SLuis R. Rodriguez return err; 1781203c4805SLuis R. Rodriguez 1782cd417519SNick Kossifidis err = ath5k_eeprom_read_spur_chans(ah); 1783cd417519SNick Kossifidis if (err < 0) 1784cd417519SNick Kossifidis return err; 1785cd417519SNick Kossifidis 1786203c4805SLuis R. Rodriguez return 0; 1787203c4805SLuis R. Rodriguez } 1788203c4805SLuis R. Rodriguez 1789203c4805SLuis R. Rodriguez /* 1790203c4805SLuis R. Rodriguez * Read the MAC address from eeprom 1791203c4805SLuis R. Rodriguez */ 1792203c4805SLuis R. Rodriguez int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac) 1793203c4805SLuis R. Rodriguez { 1794203c4805SLuis R. Rodriguez u8 mac_d[ETH_ALEN] = {}; 1795203c4805SLuis R. Rodriguez u32 total, offset; 1796203c4805SLuis R. Rodriguez u16 data; 1797203c4805SLuis R. Rodriguez int octet, ret; 1798203c4805SLuis R. Rodriguez 1799203c4805SLuis R. Rodriguez ret = ath5k_hw_eeprom_read(ah, 0x20, &data); 1800203c4805SLuis R. Rodriguez if (ret) 1801203c4805SLuis R. Rodriguez return ret; 1802203c4805SLuis R. Rodriguez 1803203c4805SLuis R. Rodriguez for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) { 1804203c4805SLuis R. Rodriguez ret = ath5k_hw_eeprom_read(ah, offset, &data); 1805203c4805SLuis R. Rodriguez if (ret) 1806203c4805SLuis R. Rodriguez return ret; 1807203c4805SLuis R. Rodriguez 1808203c4805SLuis R. Rodriguez total += data; 1809203c4805SLuis R. Rodriguez mac_d[octet + 1] = data & 0xff; 1810203c4805SLuis R. Rodriguez mac_d[octet] = data >> 8; 1811203c4805SLuis R. Rodriguez octet += 2; 1812203c4805SLuis R. Rodriguez } 1813203c4805SLuis R. Rodriguez 1814203c4805SLuis R. Rodriguez if (!total || total == 3 * 0xffff) 1815203c4805SLuis R. Rodriguez return -EINVAL; 1816203c4805SLuis R. Rodriguez 1817203c4805SLuis R. Rodriguez memcpy(mac, mac_d, ETH_ALEN); 1818203c4805SLuis R. Rodriguez 1819203c4805SLuis R. Rodriguez return 0; 1820203c4805SLuis R. Rodriguez } 1821