1 1.5 thorpej /* $NetBSD: arn9285.c,v 1.5 2022/09/25 18:43:32 thorpej Exp $ */ 2 1.1 christos /* $OpenBSD: ar9285.c,v 1.19 2012/06/10 21:23:36 kettenis Exp $ */ 3 1.1 christos 4 1.1 christos /*- 5 1.1 christos * Copyright (c) 2009-2010 Damien Bergamini <damien.bergamini (at) free.fr> 6 1.1 christos * Copyright (c) 2008-2010 Atheros Communications Inc. 7 1.1 christos * 8 1.1 christos * Permission to use, copy, modify, and/or distribute this software for any 9 1.1 christos * purpose with or without fee is hereby granted, provided that the above 10 1.1 christos * copyright notice and this permission notice appear in all copies. 11 1.1 christos * 12 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 1.1 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 1.1 christos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 1.1 christos */ 20 1.1 christos 21 1.1 christos /* 22 1.1 christos * Driver for Atheros 802.11a/g/n chipsets. 23 1.1 christos * Routines for AR9285 and AR9271 chipsets. 24 1.1 christos */ 25 1.1 christos 26 1.1 christos #include <sys/cdefs.h> 27 1.5 thorpej __KERNEL_RCSID(0, "$NetBSD: arn9285.c,v 1.5 2022/09/25 18:43:32 thorpej Exp $"); 28 1.1 christos 29 1.1 christos #ifndef _MODULE 30 1.1 christos #include "athn_usb.h" 31 1.1 christos #endif 32 1.1 christos 33 1.1 christos #include <sys/param.h> 34 1.1 christos #include <sys/sockio.h> 35 1.1 christos #include <sys/mbuf.h> 36 1.1 christos #include <sys/kernel.h> 37 1.1 christos #include <sys/socket.h> 38 1.1 christos #include <sys/systm.h> 39 1.1 christos #include <sys/queue.h> 40 1.1 christos #include <sys/callout.h> 41 1.1 christos #include <sys/conf.h> 42 1.1 christos #include <sys/device.h> 43 1.1 christos 44 1.1 christos #include <sys/bus.h> 45 1.1 christos #include <sys/endian.h> 46 1.1 christos #include <sys/intr.h> 47 1.1 christos 48 1.1 christos #include <net/bpf.h> 49 1.1 christos #include <net/if.h> 50 1.1 christos #include <net/if_arp.h> 51 1.1 christos #include <net/if_dl.h> 52 1.2 christos #include <net/if_ether.h> 53 1.1 christos #include <net/if_media.h> 54 1.1 christos #include <net/if_types.h> 55 1.1 christos 56 1.1 christos #include <netinet/in.h> 57 1.1 christos #include <netinet/in_systm.h> 58 1.1 christos #include <netinet/in_var.h> 59 1.1 christos #include <netinet/ip.h> 60 1.1 christos 61 1.1 christos #include <net80211/ieee80211_var.h> 62 1.1 christos #include <net80211/ieee80211_amrr.h> 63 1.1 christos #include <net80211/ieee80211_radiotap.h> 64 1.1 christos 65 1.1 christos #include <dev/ic/athnreg.h> 66 1.1 christos #include <dev/ic/athnvar.h> 67 1.1 christos #include <dev/ic/arn9285.h> 68 1.1 christos 69 1.1 christos #include <dev/ic/arn5008reg.h> 70 1.1 christos #include <dev/ic/arn9280reg.h> 71 1.1 christos #include <dev/ic/arn9285reg.h> 72 1.1 christos 73 1.1 christos #include <dev/ic/arn5008.h> 74 1.1 christos #include <dev/ic/arn9280.h> 75 1.1 christos #include <dev/ic/arn9285.h> 76 1.1 christos 77 1.1 christos #define Static static 78 1.1 christos 79 1.1 christos Static int ar9285_cl_cal(struct athn_softc *, struct ieee80211_channel *, 80 1.1 christos struct ieee80211_channel *); 81 1.1 christos Static void ar9285_get_pdadcs(struct athn_softc *, 82 1.1 christos struct ieee80211_channel *, int, uint8_t, uint8_t *, 83 1.1 christos uint8_t *); 84 1.1 christos Static const struct ar_spur_chan * 85 1.1 christos ar9285_get_spur_chans(struct athn_softc *, int); 86 1.1 christos Static void ar9285_init_from_rom(struct athn_softc *, 87 1.1 christos struct ieee80211_channel *, struct ieee80211_channel *); 88 1.1 christos Static void ar9285_set_power_calib(struct athn_softc *, 89 1.1 christos struct ieee80211_channel *); 90 1.1 christos Static void ar9285_set_txpower(struct athn_softc *, 91 1.1 christos struct ieee80211_channel *, struct ieee80211_channel *); 92 1.1 christos Static void ar9285_setup(struct athn_softc *); 93 1.1 christos Static void ar9285_swap_rom(struct athn_softc *); 94 1.1 christos 95 1.1 christos PUBLIC int 96 1.1 christos ar9285_attach(struct athn_softc *sc) 97 1.1 christos { 98 1.1 christos 99 1.1 christos sc->sc_eep_base = AR9285_EEP_START_LOC; 100 1.1 christos sc->sc_eep_size = sizeof(struct ar9285_eeprom); 101 1.1 christos sc->sc_def_nf = AR9285_PHY_CCA_MAX_GOOD_VALUE; 102 1.1 christos sc->sc_ngpiopins = (sc->sc_flags & ATHN_FLAG_USB) ? 16 : 12; 103 1.1 christos sc->sc_led_pin = (sc->sc_flags & ATHN_FLAG_USB) ? 15 : 1; 104 1.1 christos sc->sc_workaround = AR9285_WA_DEFAULT; 105 1.1 christos sc->sc_ops.setup = ar9285_setup; 106 1.1 christos sc->sc_ops.swap_rom = ar9285_swap_rom; 107 1.1 christos sc->sc_ops.init_from_rom = ar9285_init_from_rom; 108 1.1 christos sc->sc_ops.set_txpower = ar9285_set_txpower; 109 1.1 christos sc->sc_ops.set_synth = ar9280_set_synth; 110 1.1 christos sc->sc_ops.spur_mitigate = ar9280_spur_mitigate; 111 1.1 christos sc->sc_ops.get_spur_chans = ar9285_get_spur_chans; 112 1.1 christos #if NATHN_USB > 0 113 1.1 christos if (AR_SREV_9271(sc)) 114 1.1 christos sc->sc_ini = &ar9271_ini; 115 1.1 christos else 116 1.1 christos #endif 117 1.1 christos sc->sc_ini = &ar9285_1_2_ini; 118 1.1 christos sc->sc_serdes = &ar9280_2_0_serdes; 119 1.1 christos 120 1.1 christos return ar5008_attach(sc); 121 1.1 christos } 122 1.1 christos 123 1.1 christos Static void 124 1.1 christos ar9285_setup(struct athn_softc *sc) 125 1.1 christos { 126 1.1 christos const struct ar9285_eeprom *eep = sc->sc_eep; 127 1.1 christos uint8_t type; 128 1.1 christos 129 1.1 christos /* Select initialization values based on ROM. */ 130 1.1 christos type = eep->baseEepHeader.txGainType; 131 1.1 christos DPRINTFN(DBG_TX, sc, "Tx gain type=0x%x\n", type); 132 1.1 christos #if NATHN_USB > 0 133 1.1 christos if (AR_SREV_9271(sc)) { 134 1.1 christos if (type == AR_EEP_TXGAIN_HIGH_POWER) 135 1.1 christos sc->sc_tx_gain = &ar9271_tx_gain_high_power; 136 1.1 christos else 137 1.1 christos sc->sc_tx_gain = &ar9271_tx_gain; 138 1.1 christos } 139 1.1 christos else 140 1.1 christos #endif /* NATHN_USB */ 141 1.1 christos if ((AR_READ(sc, AR_AN_SYNTH9) & 0x7) == 0x1) { /* XE rev. */ 142 1.1 christos if (type == AR_EEP_TXGAIN_HIGH_POWER) 143 1.1 christos sc->sc_tx_gain = &ar9285_2_0_tx_gain_high_power; 144 1.1 christos else 145 1.1 christos sc->sc_tx_gain = &ar9285_2_0_tx_gain; 146 1.1 christos } 147 1.1 christos else { 148 1.1 christos if (type == AR_EEP_TXGAIN_HIGH_POWER) 149 1.1 christos sc->sc_tx_gain = &ar9285_1_2_tx_gain_high_power; 150 1.1 christos else 151 1.1 christos sc->sc_tx_gain = &ar9285_1_2_tx_gain; 152 1.1 christos } 153 1.1 christos } 154 1.1 christos 155 1.1 christos Static void 156 1.1 christos ar9285_swap_rom(struct athn_softc *sc) 157 1.1 christos { 158 1.1 christos struct ar9285_eeprom *eep = sc->sc_eep; 159 1.1 christos int i; 160 1.1 christos 161 1.1 christos eep->modalHeader.antCtrlCommon = 162 1.1 christos bswap32(eep->modalHeader.antCtrlCommon); 163 1.1 christos eep->modalHeader.antCtrlChain = 164 1.1 christos bswap32(eep->modalHeader.antCtrlChain); 165 1.1 christos 166 1.1 christos for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) { 167 1.1 christos eep->modalHeader.spurChans[i].spurChan = 168 1.1 christos bswap16(eep->modalHeader.spurChans[i].spurChan); 169 1.1 christos } 170 1.1 christos } 171 1.1 christos 172 1.1 christos Static const struct ar_spur_chan * 173 1.1 christos ar9285_get_spur_chans(struct athn_softc *sc, int is2ghz) 174 1.1 christos { 175 1.1 christos const struct ar9285_eeprom *eep = sc->sc_eep; 176 1.1 christos 177 1.1 christos KASSERT(is2ghz); 178 1.1 christos return eep->modalHeader.spurChans; 179 1.1 christos } 180 1.1 christos 181 1.1 christos Static void 182 1.1 christos ar9285_init_from_rom(struct athn_softc *sc, struct ieee80211_channel *c, 183 1.1 christos struct ieee80211_channel *extc) 184 1.1 christos { 185 1.1 christos const struct ar9285_eeprom *eep = sc->sc_eep; 186 1.1 christos const struct ar9285_modal_eep_header *modal = &eep->modalHeader; 187 1.1 christos uint32_t reg, offset = 0x1000; 188 1.1 christos uint8_t ob[5], db1[5], db2[5]; 189 1.1 christos uint8_t txRxAtten; 190 1.1 christos 191 1.1 christos AR_WRITE(sc, AR_PHY_SWITCH_COM, modal->antCtrlCommon); 192 1.1 christos AR_WRITE(sc, AR_PHY_SWITCH_CHAIN_0, modal->antCtrlChain); 193 1.1 christos 194 1.1 christos reg = AR_READ(sc, AR_PHY_TIMING_CTRL4_0); 195 1.1 christos reg = RW(reg, AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF, modal->iqCalI); 196 1.1 christos reg = RW(reg, AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF, modal->iqCalQ); 197 1.1 christos AR_WRITE(sc, AR_PHY_TIMING_CTRL4_0, reg); 198 1.1 christos 199 1.1 christos if (sc->sc_eep_rev >= AR_EEP_MINOR_VER_3) { 200 1.1 christos reg = AR_READ(sc, AR_PHY_GAIN_2GHZ); 201 1.1 christos reg = RW(reg, AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, 202 1.1 christos modal->bswMargin); 203 1.1 christos reg = RW(reg, AR_PHY_GAIN_2GHZ_XATTEN1_DB, 204 1.1 christos modal->bswAtten); 205 1.1 christos reg = RW(reg, AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN, 206 1.1 christos modal->xatten2Margin); 207 1.1 christos reg = RW(reg, AR_PHY_GAIN_2GHZ_XATTEN2_DB, 208 1.1 christos modal->xatten2Db); 209 1.1 christos AR_WRITE(sc, AR_PHY_GAIN_2GHZ, reg); 210 1.1 christos 211 1.1 christos /* Duplicate values of chain 0 for chain 1. */ 212 1.1 christos reg = AR_READ(sc, AR_PHY_GAIN_2GHZ + offset); 213 1.1 christos reg = RW(reg, AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, 214 1.1 christos modal->bswMargin); 215 1.1 christos reg = RW(reg, AR_PHY_GAIN_2GHZ_XATTEN1_DB, 216 1.1 christos modal->bswAtten); 217 1.1 christos reg = RW(reg, AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN, 218 1.1 christos modal->xatten2Margin); 219 1.1 christos reg = RW(reg, AR_PHY_GAIN_2GHZ_XATTEN2_DB, 220 1.1 christos modal->xatten2Db); 221 1.1 christos AR_WRITE(sc, AR_PHY_GAIN_2GHZ + offset, reg); 222 1.1 christos } 223 1.1 christos if (sc->sc_eep_rev >= AR_EEP_MINOR_VER_3) 224 1.1 christos txRxAtten = modal->txRxAtten; 225 1.1 christos else /* Workaround for ROM versions < 14.3. */ 226 1.1 christos txRxAtten = 23; 227 1.1 christos reg = AR_READ(sc, AR_PHY_RXGAIN); 228 1.1 christos reg = RW(reg, AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAtten); 229 1.1 christos reg = RW(reg, AR9280_PHY_RXGAIN_TXRX_MARGIN, modal->rxTxMargin); 230 1.1 christos AR_WRITE(sc, AR_PHY_RXGAIN, reg); 231 1.1 christos 232 1.1 christos /* Duplicate values of chain 0 for chain 1. */ 233 1.1 christos reg = AR_READ(sc, AR_PHY_RXGAIN + offset); 234 1.1 christos reg = RW(reg, AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAtten); 235 1.1 christos reg = RW(reg, AR9280_PHY_RXGAIN_TXRX_MARGIN, modal->rxTxMargin); 236 1.1 christos AR_WRITE(sc, AR_PHY_RXGAIN + offset, reg); 237 1.1 christos 238 1.1 christos if (modal->version >= 3) { 239 1.1 christos /* Setup antenna diversity from ROM. */ 240 1.1 christos reg = AR_READ(sc, AR_PHY_MULTICHAIN_GAIN_CTL); 241 1.1 christos reg = RW(reg, AR9285_PHY_ANT_DIV_CTL_ALL, 0); 242 1.1 christos reg = RW(reg, AR9285_PHY_ANT_DIV_CTL, 243 1.1 christos (modal->ob_234 >> 12) & 0x1); 244 1.1 christos reg = RW(reg, AR9285_PHY_ANT_DIV_ALT_LNACONF, 245 1.1 christos (modal->db1_234 >> 12) & 0x3); 246 1.1 christos reg = RW(reg, AR9285_PHY_ANT_DIV_MAIN_LNACONF, 247 1.1 christos (modal->db1_234 >> 14) & 0x3); 248 1.1 christos reg = RW(reg, AR9285_PHY_ANT_DIV_ALT_GAINTB, 249 1.1 christos (modal->ob_234 >> 13) & 0x1); 250 1.1 christos reg = RW(reg, AR9285_PHY_ANT_DIV_MAIN_GAINTB, 251 1.1 christos (modal->ob_234 >> 14) & 0x1); 252 1.1 christos AR_WRITE(sc, AR_PHY_MULTICHAIN_GAIN_CTL, reg); 253 1.1 christos reg = AR_READ(sc, AR_PHY_MULTICHAIN_GAIN_CTL); /* Flush. */ 254 1.1 christos 255 1.1 christos reg = AR_READ(sc, AR_PHY_CCK_DETECT); 256 1.1 christos if (modal->ob_234 & (1 << 15)) 257 1.1 christos reg |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV; 258 1.1 christos else 259 1.1 christos reg &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV; 260 1.1 christos AR_WRITE(sc, AR_PHY_CCK_DETECT, reg); 261 1.1 christos reg = AR_READ(sc, AR_PHY_CCK_DETECT); /* Flush. */ 262 1.1 christos } 263 1.1 christos if (modal->version >= 2) { 264 1.1 christos ob [0] = (modal->ob_01 >> 0) & 0xf; 265 1.1 christos ob [1] = (modal->ob_01 >> 4) & 0xf; 266 1.1 christos ob [2] = (modal->ob_234 >> 0) & 0xf; 267 1.1 christos ob [3] = (modal->ob_234 >> 4) & 0xf; 268 1.1 christos ob [4] = (modal->ob_234 >> 8) & 0xf; 269 1.1 christos 270 1.1 christos db1[0] = (modal->db1_01 >> 0) & 0xf; 271 1.1 christos db1[1] = (modal->db1_01 >> 4) & 0xf; 272 1.1 christos db1[2] = (modal->db1_234 >> 0) & 0xf; 273 1.1 christos db1[3] = (modal->db1_234 >> 4) & 0xf; 274 1.1 christos db1[4] = (modal->db1_234 >> 8) & 0xf; 275 1.1 christos 276 1.1 christos db2[0] = (modal->db2_01 >> 0) & 0xf; 277 1.1 christos db2[1] = (modal->db2_01 >> 4) & 0xf; 278 1.1 christos db2[2] = (modal->db2_234 >> 0) & 0xf; 279 1.1 christos db2[3] = (modal->db2_234 >> 4) & 0xf; 280 1.1 christos db2[4] = (modal->db2_234 >> 8) & 0xf; 281 1.1 christos 282 1.1 christos } 283 1.1 christos else if (modal->version == 1) { 284 1.1 christos ob [0] = (modal->ob_01 >> 0) & 0xf; 285 1.1 christos ob [1] = (modal->ob_01 >> 4) & 0xf; 286 1.1 christos /* Field ob_234 does not exist, use ob_01. */ 287 1.1 christos ob [2] = ob [3] = ob [4] = ob [1]; 288 1.1 christos 289 1.1 christos db1[0] = (modal->db1_01 >> 0) & 0xf; 290 1.1 christos db1[1] = (modal->db1_01 >> 4) & 0xf; 291 1.1 christos /* Field db1_234 does not exist, use db1_01. */ 292 1.1 christos db1[2] = db1[3] = db1[4] = db1[1]; 293 1.1 christos 294 1.1 christos db2[0] = (modal->db2_01 >> 0) & 0xf; 295 1.1 christos db2[1] = (modal->db2_01 >> 4) & 0xf; 296 1.1 christos /* Field db2_234 does not exist, use db2_01. */ 297 1.1 christos db2[2] = db2[3] = db2[4] = db2[1]; 298 1.1 christos 299 1.1 christos } 300 1.1 christos else { 301 1.1 christos ob [0] = modal->ob_01; 302 1.1 christos ob [1] = ob [2] = ob [3] = ob [4] = ob [0]; 303 1.1 christos 304 1.1 christos db1[0] = modal->db1_01; 305 1.1 christos db1[1] = db1[2] = db1[3] = db1[4] = db1[0]; 306 1.1 christos 307 1.1 christos /* Field db2_01 does not exist, use db1_01. */ 308 1.1 christos db2[0] = modal->db1_01; 309 1.1 christos db2[1] = db2[2] = db2[3] = db2[4] = db2[0]; 310 1.1 christos } 311 1.1 christos #if NATHN_USB > 0 312 1.1 christos if (AR_SREV_9271(sc)) { 313 1.1 christos reg = AR_READ(sc, AR9285_AN_RF2G3); 314 1.1 christos reg = RW(reg, AR9271_AN_RF2G3_OB_CCK, ob [0]); 315 1.1 christos reg = RW(reg, AR9271_AN_RF2G3_OB_PSK, ob [1]); 316 1.1 christos reg = RW(reg, AR9271_AN_RF2G3_OB_QAM, ob [2]); 317 1.1 christos reg = RW(reg, AR9271_AN_RF2G3_DB1, db1[0]); 318 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G3, reg); 319 1.1 christos AR_WRITE_BARRIER(sc); 320 1.1 christos DELAY(100); 321 1.1 christos reg = AR_READ(sc, AR9285_AN_RF2G4); 322 1.4 msaitoh reg = RW(reg, AR9271_AN_RF2G4_DB2, (uint32_t)db2[0]); 323 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G4, reg); 324 1.1 christos AR_WRITE_BARRIER(sc); 325 1.1 christos DELAY(100); 326 1.1 christos } 327 1.1 christos else 328 1.1 christos #endif /* ATHN_USB */ 329 1.1 christos { 330 1.1 christos reg = AR_READ(sc, AR9285_AN_RF2G3); 331 1.1 christos reg = RW(reg, AR9285_AN_RF2G3_OB_0, ob [0]); 332 1.1 christos reg = RW(reg, AR9285_AN_RF2G3_OB_1, ob [1]); 333 1.1 christos reg = RW(reg, AR9285_AN_RF2G3_OB_2, ob [2]); 334 1.1 christos reg = RW(reg, AR9285_AN_RF2G3_OB_3, ob [3]); 335 1.1 christos reg = RW(reg, AR9285_AN_RF2G3_OB_4, ob [4]); 336 1.1 christos reg = RW(reg, AR9285_AN_RF2G3_DB1_0, db1[0]); 337 1.1 christos reg = RW(reg, AR9285_AN_RF2G3_DB1_1, db1[1]); 338 1.1 christos reg = RW(reg, AR9285_AN_RF2G3_DB1_2, db1[2]); 339 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G3, reg); 340 1.1 christos AR_WRITE_BARRIER(sc); 341 1.1 christos DELAY(100); 342 1.1 christos reg = AR_READ(sc, AR9285_AN_RF2G4); 343 1.1 christos reg = RW(reg, AR9285_AN_RF2G4_DB1_3, db1[3]); 344 1.1 christos reg = RW(reg, AR9285_AN_RF2G4_DB1_4, db1[4]); 345 1.1 christos reg = RW(reg, AR9285_AN_RF2G4_DB2_0, db2[0]); 346 1.1 christos reg = RW(reg, AR9285_AN_RF2G4_DB2_1, db2[1]); 347 1.1 christos reg = RW(reg, AR9285_AN_RF2G4_DB2_2, db2[2]); 348 1.1 christos reg = RW(reg, AR9285_AN_RF2G4_DB2_3, db2[3]); 349 1.1 christos reg = RW(reg, AR9285_AN_RF2G4_DB2_4, db2[4]); 350 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G4, reg); 351 1.1 christos AR_WRITE_BARRIER(sc); 352 1.1 christos DELAY(100); 353 1.1 christos } 354 1.1 christos 355 1.1 christos reg = AR_READ(sc, AR_PHY_SETTLING); 356 1.1 christos reg = RW(reg, AR_PHY_SETTLING_SWITCH, modal->switchSettling); 357 1.1 christos AR_WRITE(sc, AR_PHY_SETTLING, reg); 358 1.1 christos 359 1.1 christos reg = AR_READ(sc, AR_PHY_DESIRED_SZ); 360 1.1 christos reg = RW(reg, AR_PHY_DESIRED_SZ_ADC, modal->adcDesiredSize); 361 1.1 christos AR_WRITE(sc, AR_PHY_DESIRED_SZ, reg); 362 1.1 christos 363 1.1 christos reg = SM(AR_PHY_RF_CTL4_TX_END_XPAA_OFF, modal->txEndToXpaOff); 364 1.1 christos reg |= SM(AR_PHY_RF_CTL4_TX_END_XPAB_OFF, modal->txEndToXpaOff); 365 1.1 christos reg |= SM(AR_PHY_RF_CTL4_FRAME_XPAA_ON, modal->txFrameToXpaOn); 366 1.1 christos reg |= SM(AR_PHY_RF_CTL4_FRAME_XPAB_ON, modal->txFrameToXpaOn); 367 1.1 christos AR_WRITE(sc, AR_PHY_RF_CTL4, reg); 368 1.1 christos 369 1.1 christos reg = AR_READ(sc, AR_PHY_RF_CTL3); 370 1.1 christos reg = RW(reg, AR_PHY_TX_END_TO_A2_RX_ON, modal->txEndToRxOn); 371 1.1 christos AR_WRITE(sc, AR_PHY_RF_CTL3, reg); 372 1.1 christos 373 1.1 christos reg = AR_READ(sc, AR_PHY_CCA(0)); 374 1.1 christos reg = RW(reg, AR9280_PHY_CCA_THRESH62, modal->thresh62); 375 1.1 christos AR_WRITE(sc, AR_PHY_CCA(0), reg); 376 1.1 christos 377 1.1 christos reg = AR_READ(sc, AR_PHY_EXT_CCA0); 378 1.1 christos reg = RW(reg, AR_PHY_EXT_CCA0_THRESH62, modal->thresh62); 379 1.1 christos AR_WRITE(sc, AR_PHY_EXT_CCA0, reg); 380 1.1 christos 381 1.1 christos if (sc->sc_eep_rev >= AR_EEP_MINOR_VER_2) { 382 1.1 christos reg = AR_READ(sc, AR_PHY_RF_CTL2); 383 1.1 christos reg = RW(reg, AR_PHY_TX_END_PA_ON, 384 1.1 christos modal->txFrameToPaOn); 385 1.1 christos reg = RW(reg, AR_PHY_TX_END_DATA_START, 386 1.1 christos modal->txFrameToDataStart); 387 1.1 christos AR_WRITE(sc, AR_PHY_RF_CTL2, reg); 388 1.1 christos } 389 1.1 christos #ifndef IEEE80211_NO_HT 390 1.1 christos if (sc->sc_eep_rev >= AR_EEP_MINOR_VER_3 && extc != NULL) { 391 1.1 christos reg = AR_READ(sc, AR_PHY_SETTLING); 392 1.1 christos reg = RW(reg, AR_PHY_SETTLING_SWITCH, modal->swSettleHt40); 393 1.1 christos AR_WRITE(sc, AR_PHY_SETTLING, reg); 394 1.1 christos } 395 1.1 christos #endif 396 1.1 christos AR_WRITE_BARRIER(sc); 397 1.1 christos } 398 1.1 christos 399 1.1 christos PUBLIC void 400 1.1 christos ar9285_pa_calib(struct athn_softc *sc) 401 1.1 christos { 402 1.1 christos /* List of registers that need to be saved/restored. */ 403 1.1 christos static const uint16_t regs[] = { 404 1.1 christos AR9285_AN_TOP3, 405 1.1 christos AR9285_AN_RXTXBB1, 406 1.1 christos AR9285_AN_RF2G1, 407 1.1 christos AR9285_AN_RF2G2, 408 1.1 christos AR9285_AN_TOP2, 409 1.1 christos AR9285_AN_RF2G8, 410 1.1 christos AR9285_AN_RF2G7 411 1.1 christos }; 412 1.1 christos uint32_t svg[7], reg, ccomp_svg; 413 1.1 christos size_t i; 414 1.1 christos 415 1.1 christos /* No PA calibration needed for high power solutions. */ 416 1.1 christos if (AR_SREV_9285(sc) && 417 1.1 christos ((struct ar9285_base_eep_header *)sc->sc_eep)->txGainType == 418 1.1 christos AR_EEP_TXGAIN_HIGH_POWER) /* XXX AR9287? */ 419 1.1 christos return; 420 1.1 christos 421 1.1 christos /* Save registers. */ 422 1.1 christos for (i = 0; i < __arraycount(regs); i++) 423 1.1 christos svg[i] = AR_READ(sc, regs[i]); 424 1.1 christos 425 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G6, 1); 426 1.1 christos AR_SETBITS(sc, AR_PHY(2), 1 << 27); 427 1.1 christos 428 1.1 christos AR_SETBITS(sc, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC); 429 1.1 christos AR_SETBITS(sc, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1); 430 1.1 christos AR_SETBITS(sc, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I); 431 1.1 christos AR_SETBITS(sc, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF); 432 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL); 433 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB); 434 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL); 435 1.1 christos /* Power down PA drivers. */ 436 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1); 437 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV2); 438 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT); 439 1.1 christos 440 1.1 christos reg = AR_READ(sc, AR9285_AN_RF2G8); 441 1.1 christos reg = RW(reg, AR9285_AN_RF2G8_PADRVGN2TAB0, 7); 442 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G8, reg); 443 1.1 christos 444 1.1 christos reg = AR_READ(sc, AR9285_AN_RF2G7); 445 1.1 christos reg = RW(reg, AR9285_AN_RF2G7_PADRVGN2TAB0, 0); 446 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G7, reg); 447 1.1 christos 448 1.1 christos reg = AR_READ(sc, AR9285_AN_RF2G6); 449 1.1 christos /* Save compensation capacitor value. */ 450 1.1 christos ccomp_svg = MS(reg, AR9285_AN_RF2G6_CCOMP); 451 1.1 christos /* Program compensation capacitor for dynamic PA. */ 452 1.1 christos reg = RW(reg, AR9285_AN_RF2G6_CCOMP, 0xf); 453 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G6, reg); 454 1.1 christos 455 1.1 christos AR_WRITE(sc, AR9285_AN_TOP2, AR9285_AN_TOP2_DEFAULT); 456 1.1 christos AR_WRITE_BARRIER(sc); 457 1.1 christos DELAY(30); 458 1.1 christos 459 1.1 christos /* Clear offsets 6-1. */ 460 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS_6_1); 461 1.1 christos /* Clear offset 0. */ 462 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP); 463 1.1 christos /* Set offsets 6-1. */ 464 1.1 christos for (i = 6; i >= 1; i--) { 465 1.1 christos AR_SETBITS(sc, AR9285_AN_RF2G6, AR9285_AN_RF2G6_OFFS(i)); 466 1.1 christos AR_WRITE_BARRIER(sc); 467 1.1 christos DELAY(1); 468 1.1 christos if (AR_READ(sc, AR9285_AN_RF2G9) & AR9285_AN_RXTXBB1_SPARE9) { 469 1.1 christos AR_SETBITS(sc, AR9285_AN_RF2G6, 470 1.1 christos AR9285_AN_RF2G6_OFFS(i)); 471 1.1 christos } 472 1.1 christos else { 473 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G6, 474 1.1 christos AR9285_AN_RF2G6_OFFS(i)); 475 1.1 christos } 476 1.1 christos } 477 1.1 christos /* Set offset 0. */ 478 1.1 christos AR_SETBITS(sc, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP); 479 1.1 christos AR_WRITE_BARRIER(sc); 480 1.1 christos DELAY(1); 481 1.1 christos if (AR_READ(sc, AR9285_AN_RF2G9) & AR9285_AN_RXTXBB1_SPARE9) 482 1.1 christos AR_SETBITS(sc, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP); 483 1.1 christos else 484 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G3, AR9285_AN_RF2G3_PDVCCOMP); 485 1.1 christos 486 1.1 christos AR_WRITE_BARRIER(sc); 487 1.1 christos 488 1.1 christos AR_SETBITS(sc, AR9285_AN_RF2G6, 1); 489 1.1 christos AR_CLRBITS(sc, AR_PHY(2), 1 << 27); 490 1.1 christos 491 1.1 christos /* Restore registers. */ 492 1.1 christos for (i = 0; i < __arraycount(regs); i++) 493 1.1 christos AR_WRITE(sc, regs[i], svg[i]); 494 1.1 christos 495 1.1 christos /* Restore compensation capacitor value. */ 496 1.1 christos reg = AR_READ(sc, AR9285_AN_RF2G6); 497 1.1 christos reg = RW(reg, AR9285_AN_RF2G6_CCOMP, ccomp_svg); 498 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G6, reg); 499 1.1 christos AR_WRITE_BARRIER(sc); 500 1.1 christos } 501 1.1 christos 502 1.1 christos PUBLIC void 503 1.1 christos ar9271_pa_calib(struct athn_softc *sc) 504 1.1 christos { 505 1.1 christos #if NATHN_USB > 0 506 1.1 christos /* List of registers that need to be saved/restored. */ 507 1.1 christos static const uint16_t regs[] = { 508 1.1 christos AR9285_AN_TOP3, 509 1.1 christos AR9285_AN_RXTXBB1, 510 1.1 christos AR9285_AN_RF2G1, 511 1.1 christos AR9285_AN_RF2G2, 512 1.1 christos AR9285_AN_TOP2, 513 1.1 christos AR9285_AN_RF2G8, 514 1.1 christos AR9285_AN_RF2G7 515 1.1 christos }; 516 1.1 christos uint32_t svg[7], reg, rf2g3_svg; 517 1.1 christos size_t i; 518 1.1 christos 519 1.1 christos /* Save registers. */ 520 1.1 christos for (i = 0; i < __arraycount(regs); i++) 521 1.1 christos svg[i] = AR_READ(sc, regs[i]); 522 1.1 christos 523 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G6, 1); 524 1.1 christos AR_SETBITS(sc, AR_PHY(2), 1 << 27); 525 1.1 christos 526 1.1 christos AR_SETBITS(sc, AR9285_AN_TOP3, AR9285_AN_TOP3_PWDDAC); 527 1.1 christos AR_SETBITS(sc, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDRXTXBB1); 528 1.1 christos AR_SETBITS(sc, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDV2I); 529 1.1 christos AR_SETBITS(sc, AR9285_AN_RXTXBB1, AR9285_AN_RXTXBB1_PDDACIF); 530 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G2, AR9285_AN_RF2G2_OFFCAL); 531 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G7, AR9285_AN_RF2G7_PWDDB); 532 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G1, AR9285_AN_RF2G1_ENPACAL); 533 1.1 christos /* Power down PA drivers. */ 534 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV1); 535 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPADRV2); 536 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G1, AR9285_AN_RF2G1_PDPAOUT); 537 1.1 christos 538 1.1 christos reg = AR_READ(sc, AR9285_AN_RF2G8); 539 1.1 christos reg = RW(reg, AR9285_AN_RF2G8_PADRVGN2TAB0, 7); 540 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G8, reg); 541 1.1 christos 542 1.1 christos reg = AR_READ(sc, AR9285_AN_RF2G7); 543 1.1 christos reg = RW(reg, AR9285_AN_RF2G7_PADRVGN2TAB0, 0); 544 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G7, reg); 545 1.1 christos 546 1.1 christos /* Save compensation capacitor value. */ 547 1.1 christos reg = rf2g3_svg = AR_READ(sc, AR9285_AN_RF2G3); 548 1.1 christos /* Program compensation capacitor for dynamic PA. */ 549 1.1 christos reg = RW(reg, AR9271_AN_RF2G3_CCOMP, 0xfff); 550 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G3, reg); 551 1.1 christos 552 1.1 christos AR_WRITE(sc, AR9285_AN_TOP2, AR9285_AN_TOP2_DEFAULT); 553 1.1 christos AR_WRITE_BARRIER(sc); 554 1.1 christos DELAY(30); 555 1.1 christos 556 1.1 christos /* Clear offsets 6-0. */ 557 1.1 christos AR_CLRBITS(sc, AR9285_AN_RF2G6, AR9271_AN_RF2G6_OFFS_6_0); 558 1.1 christos /* Set offsets 6-1. */ 559 1.1 christos for (i = 6; i >= 1; i--) { 560 1.1 christos reg = AR_READ(sc, AR9285_AN_RF2G6); 561 1.1 christos reg |= AR9271_AN_RF2G6_OFFS(i); 562 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G6, reg); 563 1.1 christos AR_WRITE_BARRIER(sc); 564 1.1 christos DELAY(1); 565 1.1 christos if (!(AR_READ(sc, AR9285_AN_RF2G9) & AR9285_AN_RXTXBB1_SPARE9)) 566 1.1 christos reg &= ~AR9271_AN_RF2G6_OFFS(i); 567 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G6, reg); 568 1.1 christos } 569 1.1 christos AR_WRITE_BARRIER(sc); 570 1.1 christos 571 1.1 christos AR_SETBITS(sc, AR9285_AN_RF2G6, 1); 572 1.1 christos AR_CLRBITS(sc, AR_PHY(2), 1 << 27); 573 1.1 christos 574 1.1 christos /* Restore registers. */ 575 1.1 christos for (i = 0; i < __arraycount(regs); i++) 576 1.1 christos AR_WRITE(sc, regs[i], svg[i]); 577 1.1 christos 578 1.1 christos /* Restore compensation capacitor value. */ 579 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G3, rf2g3_svg); 580 1.1 christos AR_WRITE_BARRIER(sc); 581 1.1 christos #endif /* NATHN_USB */ 582 1.1 christos } 583 1.1 christos 584 1.1 christos /* 585 1.1 christos * Carrier Leakage Calibration. 586 1.1 christos */ 587 1.1 christos int 588 1.1 christos ar9285_cl_cal(struct athn_softc *sc, struct ieee80211_channel *c, 589 1.1 christos struct ieee80211_channel *extc) 590 1.1 christos { 591 1.1 christos int ntries; 592 1.1 christos 593 1.1 christos AR_SETBITS(sc, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE); 594 1.1 christos #ifndef IEEE80211_NO_HT 595 1.1 christos if (0 && extc == NULL) { /* XXX IS_CHAN_HT20!! */ 596 1.1 christos AR_SETBITS(sc, AR_PHY_CL_CAL_CTL, AR_PHY_PARALLEL_CAL_ENABLE); 597 1.1 christos AR_SETBITS(sc, AR_PHY_TURBO, AR_PHY_FC_DYN2040_EN); 598 1.1 christos AR_CLRBITS(sc, AR_PHY_AGC_CONTROL, 599 1.1 christos AR_PHY_AGC_CONTROL_FLTR_CAL); 600 1.1 christos AR_CLRBITS(sc, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_CAL_ENABLE); 601 1.1 christos AR_SETBITS(sc, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL); 602 1.1 christos for (ntries = 0; ntries < 10000; ntries++) { 603 1.1 christos if (!(AR_READ(sc, AR_PHY_AGC_CONTROL) & 604 1.1 christos AR_PHY_AGC_CONTROL_CAL)) 605 1.1 christos break; 606 1.1 christos DELAY(10); 607 1.1 christos } 608 1.1 christos if (ntries == 10000) 609 1.1 christos return ETIMEDOUT; 610 1.1 christos AR_CLRBITS(sc, AR_PHY_TURBO, AR_PHY_FC_DYN2040_EN); 611 1.1 christos AR_CLRBITS(sc, AR_PHY_CL_CAL_CTL, AR_PHY_PARALLEL_CAL_ENABLE); 612 1.1 christos AR_CLRBITS(sc, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE); 613 1.1 christos } 614 1.1 christos #endif 615 1.1 christos AR_CLRBITS(sc, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC); 616 1.1 christos AR_SETBITS(sc, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL); 617 1.1 christos AR_SETBITS(sc, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_CAL_ENABLE); 618 1.1 christos AR_SETBITS(sc, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL); 619 1.1 christos for (ntries = 0; ntries < 10000; ntries++) { 620 1.1 christos if (!(AR_READ(sc, AR_PHY_AGC_CONTROL) & 621 1.1 christos AR_PHY_AGC_CONTROL_CAL)) 622 1.1 christos break; 623 1.1 christos DELAY(10); 624 1.1 christos } 625 1.1 christos if (ntries == 10000) 626 1.1 christos return ETIMEDOUT; 627 1.1 christos AR_SETBITS(sc, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC); 628 1.1 christos AR_CLRBITS(sc, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE); 629 1.1 christos AR_CLRBITS(sc, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL); 630 1.1 christos AR_WRITE_BARRIER(sc); 631 1.1 christos return 0; 632 1.1 christos } 633 1.1 christos 634 1.1 christos PUBLIC void 635 1.1 christos ar9271_load_ani(struct athn_softc *sc) 636 1.1 christos { 637 1.1 christos 638 1.1 christos #if NATHN_USB > 0 639 1.1 christos /* Write ANI registers. */ 640 1.1 christos AR_WRITE(sc, AR_PHY_DESIRED_SZ, 0x6d4000e2); 641 1.1 christos AR_WRITE(sc, AR_PHY_AGC_CTL1, 0x3139605e); 642 1.1 christos AR_WRITE(sc, AR_PHY_FIND_SIG, 0x7ec84d2e); 643 1.1 christos AR_WRITE(sc, AR_PHY_SFCORR_LOW, 0x06903881); 644 1.1 christos AR_WRITE(sc, AR_PHY_SFCORR, 0x5ac640d0); 645 1.1 christos AR_WRITE(sc, AR_PHY_CCK_DETECT, 0x803e68c8); 646 1.1 christos AR_WRITE(sc, AR_PHY_TIMING5, 0xd00a8007); 647 1.1 christos AR_WRITE(sc, AR_PHY_SFCORR_EXT, 0x05eea6d4); 648 1.1 christos AR_WRITE_BARRIER(sc); 649 1.1 christos #endif /* NATHN_USB */ 650 1.1 christos } 651 1.1 christos 652 1.1 christos int 653 1.1 christos ar9285_init_calib(struct athn_softc *sc, struct ieee80211_channel *c, 654 1.1 christos struct ieee80211_channel *extc) 655 1.1 christos { 656 1.1 christos uint32_t reg, mask, clcgain, rf2g5_svg; 657 1.1 christos int i, maxgain, nclcs, thresh, error; 658 1.1 christos 659 1.1 christos /* Do carrier leakage calibration. */ 660 1.1 christos if ((error = ar9285_cl_cal(sc, c, extc)) != 0) 661 1.1 christos return error; 662 1.1 christos 663 1.1 christos /* Workaround for high temperature is not applicable on AR9271. */ 664 1.1 christos if (AR_SREV_9271(sc)) 665 1.1 christos return 0; 666 1.1 christos 667 1.1 christos mask = 0; 668 1.1 christos nclcs = 0; 669 1.1 christos reg = AR_READ(sc, AR_PHY_TX_PWRCTRL7); 670 1.1 christos maxgain = MS(reg, AR_PHY_TX_PWRCTRL_TX_GAIN_TAB_MAX); 671 1.1 christos for (i = 0; i <= maxgain; i++) { 672 1.1 christos reg = AR_READ(sc, AR_PHY_TX_GAIN_TBL(i)); 673 1.1 christos clcgain = MS(reg, AR_PHY_TX_GAIN_CLC); 674 1.1 christos /* NB: clcgain <= 0xf. */ 675 1.1 christos if (!(mask & (1 << clcgain))) { 676 1.1 christos mask |= 1 << clcgain; 677 1.1 christos nclcs++; 678 1.1 christos } 679 1.1 christos } 680 1.1 christos thresh = 0; 681 1.1 christos for (i = 0; i < nclcs; i++) { 682 1.1 christos reg = AR_READ(sc, AR_PHY_CLC_TBL(i)); 683 1.1 christos if (MS(reg, AR_PHY_CLC_I0) == 0) 684 1.1 christos thresh++; 685 1.1 christos if (MS(reg, AR_PHY_CLC_Q0) == 0) 686 1.1 christos thresh++; 687 1.1 christos } 688 1.1 christos if (thresh <= AR9285_CL_CAL_REDO_THRESH) 689 1.1 christos return 0; /* No need to redo. */ 690 1.1 christos 691 1.1 christos /* Threshold reached, redo carrier leakage calibration. */ 692 1.1 christos DPRINTFN(DBG_INIT, sc, "CLC threshold=%d\n", thresh); 693 1.1 christos rf2g5_svg = reg = AR_READ(sc, AR9285_AN_RF2G5); 694 1.1 christos if ((AR_READ(sc, AR_AN_SYNTH9) & 0x7) == 0x1) /* XE rev. */ 695 1.1 christos reg = RW(reg, AR9285_AN_RF2G5_IC50TX, 0x5); 696 1.1 christos else 697 1.1 christos reg = RW(reg, AR9285_AN_RF2G5_IC50TX, 0x4); 698 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G5, reg); 699 1.1 christos AR_WRITE_BARRIER(sc); 700 1.1 christos error = ar9285_cl_cal(sc, c, extc); 701 1.1 christos AR_WRITE(sc, AR9285_AN_RF2G5, rf2g5_svg); 702 1.1 christos AR_WRITE_BARRIER(sc); 703 1.1 christos return error; 704 1.1 christos } 705 1.1 christos 706 1.1 christos Static void 707 1.1 christos ar9285_get_pdadcs(struct athn_softc *sc, struct ieee80211_channel *c, 708 1.1 christos int nxpdgains, uint8_t overlap, uint8_t *boundaries, uint8_t *pdadcs) 709 1.1 christos { 710 1.1 christos const struct ar9285_eeprom *eep = sc->sc_eep; 711 1.1 christos const struct ar9285_cal_data_per_freq *pierdata; 712 1.1 christos const uint8_t *pierfreq; 713 1.1 christos struct athn_pier lopier, hipier; 714 1.1 christos uint8_t fbin; 715 1.1 christos int i, lo, hi, npiers; 716 1.1 christos 717 1.1 christos pierfreq = eep->calFreqPier2G; 718 1.1 christos pierdata = eep->calPierData2G; 719 1.1 christos npiers = AR9285_NUM_2G_CAL_PIERS; 720 1.1 christos 721 1.1 christos /* Find channel in ROM pier table. */ 722 1.1 christos fbin = athn_chan2fbin(c); 723 1.1 christos athn_get_pier_ival(fbin, pierfreq, npiers, &lo, &hi); 724 1.1 christos 725 1.1 christos lopier.fbin = pierfreq[lo]; 726 1.1 christos hipier.fbin = pierfreq[hi]; 727 1.1 christos for (i = 0; i < nxpdgains; i++) { 728 1.1 christos lopier.pwr[i] = pierdata[lo].pwrPdg[i]; 729 1.1 christos lopier.vpd[i] = pierdata[lo].vpdPdg[i]; 730 1.1 christos hipier.pwr[i] = pierdata[lo].pwrPdg[i]; 731 1.1 christos hipier.vpd[i] = pierdata[lo].vpdPdg[i]; 732 1.1 christos } 733 1.1 christos ar5008_get_pdadcs(sc, fbin, &lopier, &hipier, nxpdgains, 734 1.1 christos AR9285_PD_GAIN_ICEPTS, overlap, boundaries, pdadcs); 735 1.1 christos } 736 1.1 christos 737 1.1 christos Static void 738 1.1 christos ar9285_set_power_calib(struct athn_softc *sc, struct ieee80211_channel *c) 739 1.1 christos { 740 1.1 christos const struct ar9285_eeprom *eep = sc->sc_eep; 741 1.1 christos uint8_t boundaries[AR_PD_GAINS_IN_MASK]; 742 1.1 christos uint8_t pdadcs[AR_NUM_PDADC_VALUES]; 743 1.1 christos uint8_t xpdgains[AR9285_NUM_PD_GAINS]; 744 1.1 christos uint8_t overlap; 745 1.1 christos uint32_t reg; 746 1.1 christos int i, nxpdgains; 747 1.1 christos 748 1.1 christos if (sc->sc_eep_rev < AR_EEP_MINOR_VER_2) { 749 1.1 christos overlap = MS(AR_READ(sc, AR_PHY_TPCRG5), 750 1.1 christos AR_PHY_TPCRG5_PD_GAIN_OVERLAP); 751 1.1 christos } 752 1.1 christos else 753 1.1 christos overlap = eep->modalHeader.pdGainOverlap; 754 1.1 christos 755 1.1 christos nxpdgains = 0; 756 1.1 christos memset(xpdgains, 0, sizeof(xpdgains)); 757 1.1 christos for (i = AR9285_PD_GAINS_IN_MASK - 1; i >= 0; i--) { 758 1.1 christos if (nxpdgains >= AR9285_NUM_PD_GAINS) 759 1.1 christos break; 760 1.1 christos if (eep->modalHeader.xpdGain & (1 << i)) 761 1.1 christos xpdgains[nxpdgains++] = i; 762 1.1 christos } 763 1.1 christos reg = AR_READ(sc, AR_PHY_TPCRG1); 764 1.1 christos reg = RW(reg, AR_PHY_TPCRG1_NUM_PD_GAIN, nxpdgains - 1); 765 1.1 christos reg = RW(reg, AR_PHY_TPCRG1_PD_GAIN_1, xpdgains[0]); 766 1.1 christos reg = RW(reg, AR_PHY_TPCRG1_PD_GAIN_2, xpdgains[1]); 767 1.1 christos AR_WRITE(sc, AR_PHY_TPCRG1, reg); 768 1.1 christos 769 1.1 christos /* NB: No open loop power control for AR9285. */ 770 1.1 christos ar9285_get_pdadcs(sc, c, nxpdgains, overlap, boundaries, pdadcs); 771 1.1 christos 772 1.1 christos /* Write boundaries. */ 773 1.1 christos reg = SM(AR_PHY_TPCRG5_PD_GAIN_OVERLAP, overlap); 774 1.1 christos reg |= SM(AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1, boundaries[0]); 775 1.1 christos reg |= SM(AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2, boundaries[1]); 776 1.1 christos reg |= SM(AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3, boundaries[2]); 777 1.1 christos reg |= SM(AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4, boundaries[3]); 778 1.1 christos AR_WRITE(sc, AR_PHY_TPCRG5, reg); 779 1.1 christos 780 1.1 christos /* Write PDADC values. */ 781 1.1 christos for (i = 0; i < AR_NUM_PDADC_VALUES; i += 4) { 782 1.1 christos AR_WRITE(sc, AR_PHY_PDADC_TBL_BASE + i, 783 1.1 christos pdadcs[i + 0] << 0 | 784 1.1 christos pdadcs[i + 1] << 8 | 785 1.1 christos pdadcs[i + 2] << 16 | 786 1.4 msaitoh (uint32_t)pdadcs[i + 3] << 24); 787 1.1 christos } 788 1.1 christos AR_WRITE_BARRIER(sc); 789 1.1 christos } 790 1.1 christos 791 1.1 christos Static void 792 1.1 christos ar9285_set_txpower(struct athn_softc *sc, struct ieee80211_channel *c, 793 1.1 christos struct ieee80211_channel *extc) 794 1.1 christos { 795 1.1 christos const struct ar9285_eeprom *eep = sc->sc_eep; 796 1.3 christos #ifdef notyet 797 1.1 christos const struct ar9285_modal_eep_header *modal = &eep->modalHeader; 798 1.3 christos #endif 799 1.1 christos uint8_t tpow_cck[4], tpow_ofdm[4]; 800 1.1 christos #ifndef IEEE80211_NO_HT 801 1.1 christos uint8_t tpow_cck_ext[4], tpow_ofdm_ext[4]; 802 1.1 christos uint8_t tpow_ht20[8], tpow_ht40[8]; 803 1.1 christos uint8_t ht40inc; 804 1.1 christos #endif 805 1.3 christos int16_t power[ATHN_POWER_COUNT]; 806 1.1 christos int i; 807 1.1 christos 808 1.1 christos ar9285_set_power_calib(sc, c); 809 1.1 christos 810 1.3 christos #ifdef notyet 811 1.1 christos /* Compute transmit power reduction due to antenna gain. */ 812 1.3 christos uint16_t max_ant_gain = modal->antennaGain; 813 1.1 christos /* XXX */ 814 1.3 christos #endif 815 1.1 christos 816 1.1 christos /* Get CCK target powers. */ 817 1.1 christos ar5008_get_lg_tpow(sc, c, AR_CTL_11B, eep->calTargetPowerCck, 818 1.1 christos AR9285_NUM_2G_CCK_TARGET_POWERS, tpow_cck); 819 1.1 christos 820 1.1 christos /* Get OFDM target powers. */ 821 1.1 christos ar5008_get_lg_tpow(sc, c, AR_CTL_11G, eep->calTargetPower2G, 822 1.1 christos AR9285_NUM_2G_20_TARGET_POWERS, tpow_ofdm); 823 1.1 christos 824 1.1 christos #ifndef IEEE80211_NO_HT 825 1.1 christos /* Get HT-20 target powers. */ 826 1.1 christos ar5008_get_ht_tpow(sc, c, AR_CTL_2GHT20, eep->calTargetPower2GHT20, 827 1.1 christos AR9285_NUM_2G_20_TARGET_POWERS, tpow_ht20); 828 1.1 christos 829 1.1 christos if (extc != NULL) { 830 1.1 christos /* Get HT-40 target powers. */ 831 1.1 christos ar5008_get_ht_tpow(sc, c, AR_CTL_2GHT40, 832 1.1 christos eep->calTargetPower2GHT40, AR9285_NUM_2G_40_TARGET_POWERS, 833 1.1 christos tpow_ht40); 834 1.1 christos 835 1.1 christos /* Get secondary channel CCK target powers. */ 836 1.1 christos ar5008_get_lg_tpow(sc, extc, AR_CTL_11B, 837 1.1 christos eep->calTargetPowerCck, AR9285_NUM_2G_CCK_TARGET_POWERS, 838 1.1 christos tpow_cck_ext); 839 1.1 christos 840 1.1 christos /* Get secondary channel OFDM target powers. */ 841 1.1 christos ar5008_get_lg_tpow(sc, extc, AR_CTL_11G, 842 1.1 christos eep->calTargetPower2G, AR9285_NUM_2G_20_TARGET_POWERS, 843 1.1 christos tpow_ofdm_ext); 844 1.1 christos } 845 1.1 christos #endif 846 1.1 christos 847 1.1 christos memset(power, 0, sizeof(power)); 848 1.1 christos /* Shuffle target powers accross transmit rates. */ 849 1.1 christos power[ATHN_POWER_OFDM6 ] = 850 1.1 christos power[ATHN_POWER_OFDM9 ] = 851 1.1 christos power[ATHN_POWER_OFDM12 ] = 852 1.1 christos power[ATHN_POWER_OFDM18 ] = 853 1.1 christos power[ATHN_POWER_OFDM24 ] = tpow_ofdm[0]; 854 1.1 christos power[ATHN_POWER_OFDM36 ] = tpow_ofdm[1]; 855 1.1 christos power[ATHN_POWER_OFDM48 ] = tpow_ofdm[2]; 856 1.1 christos power[ATHN_POWER_OFDM54 ] = tpow_ofdm[3]; 857 1.1 christos power[ATHN_POWER_XR ] = tpow_ofdm[0]; 858 1.1 christos power[ATHN_POWER_CCK1_LP ] = tpow_cck[0]; 859 1.1 christos power[ATHN_POWER_CCK2_LP ] = 860 1.1 christos power[ATHN_POWER_CCK2_SP ] = tpow_cck[1]; 861 1.1 christos power[ATHN_POWER_CCK55_LP] = 862 1.1 christos power[ATHN_POWER_CCK55_SP] = tpow_cck[2]; 863 1.1 christos power[ATHN_POWER_CCK11_LP] = 864 1.1 christos power[ATHN_POWER_CCK11_SP] = tpow_cck[3]; 865 1.1 christos #ifndef IEEE80211_NO_HT 866 1.1 christos for (i = 0; i < __arraycount(tpow_ht20); i++) 867 1.1 christos power[ATHN_POWER_HT20(i)] = tpow_ht20[i]; 868 1.1 christos if (extc != NULL) { 869 1.1 christos /* Correct PAR difference between HT40 and HT20/Legacy. */ 870 1.1 christos if (sc->sc_eep_rev >= AR_EEP_MINOR_VER_2) 871 1.1 christos ht40inc = modal->ht40PowerIncForPdadc; 872 1.1 christos else 873 1.1 christos ht40inc = AR_HT40_POWER_INC_FOR_PDADC; 874 1.1 christos for (i = 0; i < __arraycount(tpow_ht40); i++) 875 1.1 christos power[ATHN_POWER_HT40(i)] = tpow_ht40[i] + ht40inc; 876 1.1 christos power[ATHN_POWER_OFDM_DUP] = tpow_ht40[0]; 877 1.1 christos power[ATHN_POWER_CCK_DUP ] = tpow_ht40[0]; 878 1.1 christos power[ATHN_POWER_OFDM_EXT] = tpow_ofdm_ext[0]; 879 1.1 christos power[ATHN_POWER_CCK_EXT ] = tpow_cck_ext[0]; 880 1.1 christos } 881 1.1 christos #endif 882 1.1 christos 883 1.1 christos for (i = 0; i < ATHN_POWER_COUNT; i++) { 884 1.1 christos power[i] -= AR_PWR_TABLE_OFFSET_DB * 2; /* In half dB. */ 885 1.1 christos if (power[i] > AR_MAX_RATE_POWER) 886 1.1 christos power[i] = AR_MAX_RATE_POWER; 887 1.1 christos } 888 1.1 christos 889 1.1 christos /* Commit transmit power values to hardware. */ 890 1.1 christos ar5008_write_txpower(sc, power); 891 1.1 christos } 892