You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ath9k_eeprom_4k.c 31KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
  5. * Original from Linux kernel 3.0.1
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include <ipxe/io.h>
  20. #include "hw.h"
  21. #include "ar9002_phy.h"
  22. static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah)
  23. {
  24. return ((ah->eeprom.map4k.baseEepHeader.version >> 12) & 0xF);
  25. }
  26. static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah)
  27. {
  28. return ((ah->eeprom.map4k.baseEepHeader.version) & 0xFFF);
  29. }
  30. #define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
  31. static int __ath9k_hw_4k_fill_eeprom(struct ath_hw *ah)
  32. {
  33. struct ath_common *common = ath9k_hw_common(ah);
  34. u16 *eep_data = (u16 *)&ah->eeprom.map4k;
  35. unsigned int addr;
  36. int eep_start_loc = 64;
  37. for (addr = 0; addr < SIZE_EEPROM_4K; addr++) {
  38. if (!ath9k_hw_nvram_read(common, addr + eep_start_loc, eep_data)) {
  39. DBG("ath9k: "
  40. "Unable to read eeprom region\n");
  41. return 0;
  42. }
  43. eep_data++;
  44. }
  45. return 1;
  46. }
  47. static int __ath9k_hw_usb_4k_fill_eeprom(struct ath_hw *ah)
  48. {
  49. u16 *eep_data = (u16 *)&ah->eeprom.map4k;
  50. ath9k_hw_usb_gen_fill_eeprom(ah, eep_data, 64, SIZE_EEPROM_4K);
  51. return 1;
  52. }
  53. static int ath9k_hw_4k_fill_eeprom(struct ath_hw *ah)
  54. {
  55. struct ath_common *common = ath9k_hw_common(ah);
  56. if (!ath9k_hw_use_flash(ah)) {
  57. DBG2("ath9k: "
  58. "Reading from EEPROM, not flash\n");
  59. }
  60. if (common->bus_ops->ath_bus_type == ATH_USB)
  61. return __ath9k_hw_usb_4k_fill_eeprom(ah);
  62. else
  63. return __ath9k_hw_4k_fill_eeprom(ah);
  64. }
  65. #undef SIZE_EEPROM_4K
  66. static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah)
  67. {
  68. #define EEPROM_4K_SIZE (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
  69. struct ath_common *common = ath9k_hw_common(ah);
  70. struct ar5416_eeprom_4k *eep =
  71. (struct ar5416_eeprom_4k *) &ah->eeprom.map4k;
  72. u16 *eepdata, temp, magic, magic2;
  73. u32 sum = 0, el;
  74. int need_swap = 0;
  75. unsigned int i, addr;
  76. if (!ath9k_hw_use_flash(ah)) {
  77. if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET,
  78. &magic)) {
  79. DBG("ath9k: Reading Magic # failed\n");
  80. return 0;
  81. }
  82. DBG2("ath9k: "
  83. "Read Magic = 0x%04X\n", magic);
  84. if (magic != AR5416_EEPROM_MAGIC) {
  85. magic2 = swab16(magic);
  86. if (magic2 == AR5416_EEPROM_MAGIC) {
  87. need_swap = 1;
  88. eepdata = (u16 *) (&ah->eeprom);
  89. for (addr = 0; addr < EEPROM_4K_SIZE; addr++) {
  90. temp = swab16(*eepdata);
  91. *eepdata = temp;
  92. eepdata++;
  93. }
  94. } else {
  95. DBG("ath9k: "
  96. "Invalid EEPROM Magic. Endianness mismatch.\n");
  97. return -EINVAL;
  98. }
  99. }
  100. }
  101. DBG2("ath9k: need_swap = %s.\n",
  102. need_swap ? "True" : "False");
  103. if (need_swap)
  104. el = swab16(ah->eeprom.map4k.baseEepHeader.length);
  105. else
  106. el = ah->eeprom.map4k.baseEepHeader.length;
  107. if (el > sizeof(struct ar5416_eeprom_4k))
  108. el = sizeof(struct ar5416_eeprom_4k) / sizeof(u16);
  109. else
  110. el = el / sizeof(u16);
  111. eepdata = (u16 *)(&ah->eeprom);
  112. for (i = 0; i < el; i++)
  113. sum ^= *eepdata++;
  114. if (need_swap) {
  115. u32 integer;
  116. u16 word;
  117. DBG("ath9k: "
  118. "EEPROM Endianness is not native.. Changing\n");
  119. word = swab16(eep->baseEepHeader.length);
  120. eep->baseEepHeader.length = word;
  121. word = swab16(eep->baseEepHeader.checksum);
  122. eep->baseEepHeader.checksum = word;
  123. word = swab16(eep->baseEepHeader.version);
  124. eep->baseEepHeader.version = word;
  125. word = swab16(eep->baseEepHeader.regDmn[0]);
  126. eep->baseEepHeader.regDmn[0] = word;
  127. word = swab16(eep->baseEepHeader.regDmn[1]);
  128. eep->baseEepHeader.regDmn[1] = word;
  129. word = swab16(eep->baseEepHeader.rfSilent);
  130. eep->baseEepHeader.rfSilent = word;
  131. word = swab16(eep->baseEepHeader.blueToothOptions);
  132. eep->baseEepHeader.blueToothOptions = word;
  133. word = swab16(eep->baseEepHeader.deviceCap);
  134. eep->baseEepHeader.deviceCap = word;
  135. integer = swab32(eep->modalHeader.antCtrlCommon);
  136. eep->modalHeader.antCtrlCommon = integer;
  137. for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
  138. integer = swab32(eep->modalHeader.antCtrlChain[i]);
  139. eep->modalHeader.antCtrlChain[i] = integer;
  140. }
  141. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  142. word = swab16(eep->modalHeader.spurChans[i].spurChan);
  143. eep->modalHeader.spurChans[i].spurChan = word;
  144. }
  145. }
  146. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
  147. ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  148. DBG("ath9k: Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  149. sum, ah->eep_ops->get_eeprom_ver(ah));
  150. return -EINVAL;
  151. }
  152. return 0;
  153. #undef EEPROM_4K_SIZE
  154. }
  155. static u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah,
  156. enum eeprom_param param)
  157. {
  158. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  159. struct modal_eep_4k_header *pModal = &eep->modalHeader;
  160. struct base_eep_header_4k *pBase = &eep->baseEepHeader;
  161. u16 ver_minor;
  162. ver_minor = pBase->version & AR5416_EEP_VER_MINOR_MASK;
  163. switch (param) {
  164. case EEP_NFTHRESH_2:
  165. return pModal->noiseFloorThreshCh[0];
  166. case EEP_MAC_LSW:
  167. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  168. case EEP_MAC_MID:
  169. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  170. case EEP_MAC_MSW:
  171. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  172. case EEP_REG_0:
  173. return pBase->regDmn[0];
  174. case EEP_REG_1:
  175. return pBase->regDmn[1];
  176. case EEP_OP_CAP:
  177. return pBase->deviceCap;
  178. case EEP_OP_MODE:
  179. return pBase->opCapFlags;
  180. case EEP_RF_SILENT:
  181. return pBase->rfSilent;
  182. case EEP_OB_2:
  183. return pModal->ob_0;
  184. case EEP_DB_2:
  185. return pModal->db1_1;
  186. case EEP_MINOR_REV:
  187. return ver_minor;
  188. case EEP_TX_MASK:
  189. return pBase->txMask;
  190. case EEP_RX_MASK:
  191. return pBase->rxMask;
  192. case EEP_FRAC_N_5G:
  193. return 0;
  194. case EEP_PWR_TABLE_OFFSET:
  195. return AR5416_PWR_TABLE_OFFSET_DB;
  196. case EEP_MODAL_VER:
  197. return pModal->version;
  198. case EEP_ANT_DIV_CTL1:
  199. return pModal->antdiv_ctl1;
  200. case EEP_TXGAIN_TYPE:
  201. if (ver_minor >= AR5416_EEP_MINOR_VER_19)
  202. return pBase->txGainType;
  203. else
  204. return AR5416_EEP_TXGAIN_ORIGINAL;
  205. default:
  206. return 0;
  207. }
  208. }
  209. static void ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah,
  210. struct ath9k_channel *chan,
  211. int16_t *pTxPowerIndexOffset)
  212. {
  213. struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
  214. struct cal_data_per_freq_4k *pRawDataset;
  215. u8 *pCalBChans = NULL;
  216. u16 pdGainOverlap_t2;
  217. static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
  218. u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
  219. u16 numPiers, i, j;
  220. u16 numXpdGain, xpdMask;
  221. u16 xpdGainValues[AR5416_EEP4K_NUM_PD_GAINS] = { 0, 0 };
  222. u32 reg32, regOffset, regChainOffset;
  223. xpdMask = pEepData->modalHeader.xpdGain;
  224. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  225. AR5416_EEP_MINOR_VER_2) {
  226. pdGainOverlap_t2 =
  227. pEepData->modalHeader.pdGainOverlap;
  228. } else {
  229. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  230. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  231. }
  232. pCalBChans = pEepData->calFreqPier2G;
  233. numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS;
  234. numXpdGain = 0;
  235. for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
  236. if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
  237. if (numXpdGain >= AR5416_EEP4K_NUM_PD_GAINS)
  238. break;
  239. xpdGainValues[numXpdGain] =
  240. (u16)(AR5416_PD_GAINS_IN_MASK - i);
  241. numXpdGain++;
  242. }
  243. }
  244. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  245. (numXpdGain - 1) & 0x3);
  246. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  247. xpdGainValues[0]);
  248. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  249. xpdGainValues[1]);
  250. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, 0);
  251. for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
  252. if (AR_SREV_5416_20_OR_LATER(ah) &&
  253. (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
  254. (i != 0)) {
  255. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  256. } else
  257. regChainOffset = i * 0x1000;
  258. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  259. pRawDataset = pEepData->calPierData2G[i];
  260. ath9k_hw_get_gain_boundaries_pdadcs(ah, chan,
  261. pRawDataset, pCalBChans,
  262. numPiers, pdGainOverlap_t2,
  263. gainBoundaries,
  264. pdadcValues, numXpdGain);
  265. ENABLE_REGWRITE_BUFFER(ah);
  266. if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
  267. REG_WRITE(ah, AR_PHY_TPCRG5 + regChainOffset,
  268. SM(pdGainOverlap_t2,
  269. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
  270. | SM(gainBoundaries[0],
  271. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
  272. | SM(gainBoundaries[1],
  273. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
  274. | SM(gainBoundaries[2],
  275. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
  276. | SM(gainBoundaries[3],
  277. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
  278. }
  279. regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
  280. for (j = 0; j < 32; j++) {
  281. reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
  282. ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
  283. ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
  284. ((pdadcValues[4 * j + 3] & 0xFF) << 24);
  285. REG_WRITE(ah, regOffset, reg32);
  286. DBG2("ath9k: "
  287. "PDADC (%d,%4x): %4.4x %8.8x\n",
  288. i, regChainOffset, regOffset,
  289. reg32);
  290. DBG2("ath9k: "
  291. "PDADC: Chain %d | "
  292. "PDADC %3d Value %3d | "
  293. "PDADC %3d Value %3d | "
  294. "PDADC %3d Value %3d | "
  295. "PDADC %3d Value %3d |\n",
  296. i, 4 * j, pdadcValues[4 * j],
  297. 4 * j + 1, pdadcValues[4 * j + 1],
  298. 4 * j + 2, pdadcValues[4 * j + 2],
  299. 4 * j + 3, pdadcValues[4 * j + 3]);
  300. regOffset += 4;
  301. }
  302. REGWRITE_BUFFER_FLUSH(ah);
  303. }
  304. }
  305. *pTxPowerIndexOffset = 0;
  306. }
  307. static void ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
  308. struct ath9k_channel *chan,
  309. int16_t *ratesArray,
  310. u16 cfgCtl,
  311. u16 AntennaReduction,
  312. u16 twiceMaxRegulatoryPower,
  313. u16 powerLimit)
  314. {
  315. #define CMP_TEST_GRP \
  316. (((cfgCtl & ~CTL_MODE_M)| (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  317. pEepData->ctlIndex[i]) \
  318. || (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  319. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
  320. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  321. unsigned int i;
  322. int16_t twiceLargestAntenna;
  323. u16 twiceMinEdgePower;
  324. u16 twiceMaxEdgePower = MAX_RATE_POWER;
  325. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  326. u16 numCtlModes;
  327. const u16 *pCtlMode;
  328. u16 ctlMode, freq;
  329. struct chan_centers centers;
  330. struct cal_ctl_data_4k *rep;
  331. struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
  332. static const u16 tpScaleReductionTable[5] =
  333. { 0, 3, 6, 9, MAX_RATE_POWER };
  334. struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
  335. 0, { 0, 0, 0, 0}
  336. };
  337. struct cal_target_power_leg targetPowerOfdmExt = {
  338. 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
  339. 0, { 0, 0, 0, 0 }
  340. };
  341. struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
  342. 0, {0, 0, 0, 0}
  343. };
  344. static const u16 ctlModesFor11g[] = {
  345. CTL_11B, CTL_11G, CTL_2GHT20,
  346. CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
  347. };
  348. ath9k_hw_get_channel_centers(ah, chan, &centers);
  349. twiceLargestAntenna = pEepData->modalHeader.antennaGainCh[0];
  350. twiceLargestAntenna = (int16_t)min(AntennaReduction -
  351. twiceLargestAntenna, 0);
  352. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  353. if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX) {
  354. maxRegAllowedPower -=
  355. (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
  356. }
  357. scaledPower = min(powerLimit, maxRegAllowedPower);
  358. scaledPower = max((u16)0, scaledPower);
  359. numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
  360. pCtlMode = ctlModesFor11g;
  361. ath9k_hw_get_legacy_target_powers(ah, chan,
  362. pEepData->calTargetPowerCck,
  363. AR5416_NUM_2G_CCK_TARGET_POWERS,
  364. &targetPowerCck, 4, 0);
  365. ath9k_hw_get_legacy_target_powers(ah, chan,
  366. pEepData->calTargetPower2G,
  367. AR5416_NUM_2G_20_TARGET_POWERS,
  368. &targetPowerOfdm, 4, 0);
  369. ath9k_hw_get_target_powers(ah, chan,
  370. pEepData->calTargetPower2GHT20,
  371. AR5416_NUM_2G_20_TARGET_POWERS,
  372. &targetPowerHt20, 8, 0);
  373. if (IS_CHAN_HT40(chan)) {
  374. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  375. ath9k_hw_get_target_powers(ah, chan,
  376. pEepData->calTargetPower2GHT40,
  377. AR5416_NUM_2G_40_TARGET_POWERS,
  378. &targetPowerHt40, 8, 1);
  379. ath9k_hw_get_legacy_target_powers(ah, chan,
  380. pEepData->calTargetPowerCck,
  381. AR5416_NUM_2G_CCK_TARGET_POWERS,
  382. &targetPowerCckExt, 4, 1);
  383. ath9k_hw_get_legacy_target_powers(ah, chan,
  384. pEepData->calTargetPower2G,
  385. AR5416_NUM_2G_20_TARGET_POWERS,
  386. &targetPowerOfdmExt, 4, 1);
  387. }
  388. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  389. int isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  390. (pCtlMode[ctlMode] == CTL_2GHT40);
  391. if (isHt40CtlMode)
  392. freq = centers.synth_center;
  393. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  394. freq = centers.ext_center;
  395. else
  396. freq = centers.ctl_center;
  397. if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
  398. ah->eep_ops->get_eeprom_rev(ah) <= 2)
  399. twiceMaxEdgePower = MAX_RATE_POWER;
  400. for (i = 0; (i < AR5416_EEP4K_NUM_CTLS) &&
  401. pEepData->ctlIndex[i]; i++) {
  402. if (CMP_TEST_GRP) {
  403. rep = &(pEepData->ctlData[i]);
  404. twiceMinEdgePower = ath9k_hw_get_max_edge_power(
  405. freq,
  406. rep->ctlEdges[
  407. ar5416_get_ntxchains(ah->txchainmask) - 1],
  408. IS_CHAN_2GHZ(chan),
  409. AR5416_EEP4K_NUM_BAND_EDGES);
  410. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  411. twiceMaxEdgePower =
  412. min(twiceMaxEdgePower,
  413. twiceMinEdgePower);
  414. } else {
  415. twiceMaxEdgePower = twiceMinEdgePower;
  416. break;
  417. }
  418. }
  419. }
  420. minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
  421. switch (pCtlMode[ctlMode]) {
  422. case CTL_11B:
  423. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  424. targetPowerCck.tPow2x[i] =
  425. min((u16)targetPowerCck.tPow2x[i],
  426. minCtlPower);
  427. }
  428. break;
  429. case CTL_11G:
  430. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  431. targetPowerOfdm.tPow2x[i] =
  432. min((u16)targetPowerOfdm.tPow2x[i],
  433. minCtlPower);
  434. }
  435. break;
  436. case CTL_2GHT20:
  437. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  438. targetPowerHt20.tPow2x[i] =
  439. min((u16)targetPowerHt20.tPow2x[i],
  440. minCtlPower);
  441. }
  442. break;
  443. case CTL_11B_EXT:
  444. targetPowerCckExt.tPow2x[0] =
  445. min((u16)targetPowerCckExt.tPow2x[0],
  446. minCtlPower);
  447. break;
  448. case CTL_11G_EXT:
  449. targetPowerOfdmExt.tPow2x[0] =
  450. min((u16)targetPowerOfdmExt.tPow2x[0],
  451. minCtlPower);
  452. break;
  453. case CTL_2GHT40:
  454. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  455. targetPowerHt40.tPow2x[i] =
  456. min((u16)targetPowerHt40.tPow2x[i],
  457. minCtlPower);
  458. }
  459. break;
  460. default:
  461. break;
  462. }
  463. }
  464. ratesArray[rate6mb] =
  465. ratesArray[rate9mb] =
  466. ratesArray[rate12mb] =
  467. ratesArray[rate18mb] =
  468. ratesArray[rate24mb] =
  469. targetPowerOfdm.tPow2x[0];
  470. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  471. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  472. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  473. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  474. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  475. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  476. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  477. ratesArray[rate2s] = ratesArray[rate2l] = targetPowerCck.tPow2x[1];
  478. ratesArray[rate5_5s] = ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
  479. ratesArray[rate11s] = ratesArray[rate11l] = targetPowerCck.tPow2x[3];
  480. if (IS_CHAN_HT40(chan)) {
  481. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  482. ratesArray[rateHt40_0 + i] =
  483. targetPowerHt40.tPow2x[i];
  484. }
  485. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  486. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  487. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  488. ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
  489. }
  490. #undef CMP_TEST_GRP
  491. }
  492. static void ath9k_hw_4k_set_txpower(struct ath_hw *ah,
  493. struct ath9k_channel *chan,
  494. u16 cfgCtl,
  495. u8 twiceAntennaReduction,
  496. u8 twiceMaxRegulatoryPower,
  497. u8 powerLimit, int test)
  498. {
  499. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  500. struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
  501. struct modal_eep_4k_header *pModal = &pEepData->modalHeader;
  502. int16_t ratesArray[Ar5416RateSize];
  503. int16_t txPowerIndexOffset = 0;
  504. u8 ht40PowerIncForPdadc = 2;
  505. unsigned int i;
  506. memset(ratesArray, 0, sizeof(ratesArray));
  507. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  508. AR5416_EEP_MINOR_VER_2) {
  509. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  510. }
  511. ath9k_hw_set_4k_power_per_rate_table(ah, chan,
  512. &ratesArray[0], cfgCtl,
  513. twiceAntennaReduction,
  514. twiceMaxRegulatoryPower,
  515. powerLimit);
  516. ath9k_hw_set_4k_power_cal_table(ah, chan, &txPowerIndexOffset);
  517. regulatory->max_power_level = 0;
  518. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  519. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  520. if (ratesArray[i] > MAX_RATE_POWER)
  521. ratesArray[i] = MAX_RATE_POWER;
  522. if (ratesArray[i] > regulatory->max_power_level)
  523. regulatory->max_power_level = ratesArray[i];
  524. }
  525. if (test)
  526. return;
  527. /* Update regulatory */
  528. i = rate6mb;
  529. if (IS_CHAN_HT40(chan))
  530. i = rateHt40_0;
  531. else if (IS_CHAN_HT20(chan))
  532. i = rateHt20_0;
  533. regulatory->max_power_level = ratesArray[i];
  534. if (AR_SREV_9280_20_OR_LATER(ah)) {
  535. for (i = 0; i < Ar5416RateSize; i++)
  536. ratesArray[i] -= AR5416_PWR_TABLE_OFFSET_DB * 2;
  537. }
  538. ENABLE_REGWRITE_BUFFER(ah);
  539. /* OFDM power per rate */
  540. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  541. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  542. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  543. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  544. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  545. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  546. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  547. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  548. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  549. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  550. /* CCK power per rate */
  551. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  552. ATH9K_POW_SM(ratesArray[rate2s], 24)
  553. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  554. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  555. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  556. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  557. ATH9K_POW_SM(ratesArray[rate11s], 24)
  558. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  559. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  560. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  561. /* HT20 power per rate */
  562. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  563. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  564. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  565. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  566. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  567. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  568. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  569. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  570. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  571. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  572. /* HT40 power per rate */
  573. if (IS_CHAN_HT40(chan)) {
  574. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  575. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  576. ht40PowerIncForPdadc, 24)
  577. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  578. ht40PowerIncForPdadc, 16)
  579. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  580. ht40PowerIncForPdadc, 8)
  581. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  582. ht40PowerIncForPdadc, 0));
  583. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  584. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  585. ht40PowerIncForPdadc, 24)
  586. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  587. ht40PowerIncForPdadc, 16)
  588. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  589. ht40PowerIncForPdadc, 8)
  590. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  591. ht40PowerIncForPdadc, 0));
  592. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  593. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  594. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  595. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  596. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  597. }
  598. REGWRITE_BUFFER_FLUSH(ah);
  599. }
  600. static void ath9k_hw_4k_set_addac(struct ath_hw *ah,
  601. struct ath9k_channel *chan __unused)
  602. {
  603. struct modal_eep_4k_header *pModal;
  604. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  605. u8 biaslevel;
  606. if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
  607. return;
  608. if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
  609. return;
  610. pModal = &eep->modalHeader;
  611. if (pModal->xpaBiasLvl != 0xff) {
  612. biaslevel = pModal->xpaBiasLvl;
  613. INI_RA(&ah->iniAddac, 7, 1) =
  614. (INI_RA(&ah->iniAddac, 7, 1) & (~0x18)) | biaslevel << 3;
  615. }
  616. }
  617. static void ath9k_hw_4k_set_gain(struct ath_hw *ah,
  618. struct modal_eep_4k_header *pModal,
  619. struct ar5416_eeprom_4k *eep,
  620. u8 txRxAttenLocal)
  621. {
  622. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0,
  623. pModal->antCtrlChain[0]);
  624. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0),
  625. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) &
  626. ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  627. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  628. SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  629. SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  630. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  631. AR5416_EEP_MINOR_VER_3) {
  632. txRxAttenLocal = pModal->txRxAttenCh[0];
  633. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
  634. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]);
  635. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
  636. AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
  637. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
  638. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  639. pModal->xatten2Margin[0]);
  640. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
  641. AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]);
  642. /* Set the block 1 value to block 0 value */
  643. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
  644. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  645. pModal->bswMargin[0]);
  646. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
  647. AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
  648. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
  649. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  650. pModal->xatten2Margin[0]);
  651. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
  652. AR_PHY_GAIN_2GHZ_XATTEN2_DB,
  653. pModal->xatten2Db[0]);
  654. }
  655. REG_RMW_FIELD(ah, AR_PHY_RXGAIN,
  656. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  657. REG_RMW_FIELD(ah, AR_PHY_RXGAIN,
  658. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
  659. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000,
  660. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  661. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000,
  662. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
  663. }
  664. /*
  665. * Read EEPROM header info and program the device for correct operation
  666. * given the channel value.
  667. */
  668. static void ath9k_hw_4k_set_board_values(struct ath_hw *ah,
  669. struct ath9k_channel *chan)
  670. {
  671. struct modal_eep_4k_header *pModal;
  672. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  673. struct base_eep_header_4k *pBase = &eep->baseEepHeader;
  674. u8 txRxAttenLocal;
  675. u8 ob[5], db1[5], db2[5];
  676. u8 ant_div_control1, ant_div_control2;
  677. u32 regVal;
  678. pModal = &eep->modalHeader;
  679. txRxAttenLocal = 23;
  680. REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
  681. /* Single chain for 4K EEPROM*/
  682. ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal);
  683. /* Initialize Ant Diversity settings from EEPROM */
  684. if (pModal->version >= 3) {
  685. ant_div_control1 = pModal->antdiv_ctl1;
  686. ant_div_control2 = pModal->antdiv_ctl2;
  687. regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
  688. regVal &= (~(AR_PHY_9285_ANT_DIV_CTL_ALL));
  689. regVal |= SM(ant_div_control1,
  690. AR_PHY_9285_ANT_DIV_CTL);
  691. regVal |= SM(ant_div_control2,
  692. AR_PHY_9285_ANT_DIV_ALT_LNACONF);
  693. regVal |= SM((ant_div_control2 >> 2),
  694. AR_PHY_9285_ANT_DIV_MAIN_LNACONF);
  695. regVal |= SM((ant_div_control1 >> 1),
  696. AR_PHY_9285_ANT_DIV_ALT_GAINTB);
  697. regVal |= SM((ant_div_control1 >> 2),
  698. AR_PHY_9285_ANT_DIV_MAIN_GAINTB);
  699. REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regVal);
  700. regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
  701. regVal = REG_READ(ah, AR_PHY_CCK_DETECT);
  702. regVal &= (~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
  703. regVal |= SM((ant_div_control1 >> 3),
  704. AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
  705. REG_WRITE(ah, AR_PHY_CCK_DETECT, regVal);
  706. regVal = REG_READ(ah, AR_PHY_CCK_DETECT);
  707. }
  708. if (pModal->version >= 2) {
  709. ob[0] = pModal->ob_0;
  710. ob[1] = pModal->ob_1;
  711. ob[2] = pModal->ob_2;
  712. ob[3] = pModal->ob_3;
  713. ob[4] = pModal->ob_4;
  714. db1[0] = pModal->db1_0;
  715. db1[1] = pModal->db1_1;
  716. db1[2] = pModal->db1_2;
  717. db1[3] = pModal->db1_3;
  718. db1[4] = pModal->db1_4;
  719. db2[0] = pModal->db2_0;
  720. db2[1] = pModal->db2_1;
  721. db2[2] = pModal->db2_2;
  722. db2[3] = pModal->db2_3;
  723. db2[4] = pModal->db2_4;
  724. } else if (pModal->version == 1) {
  725. ob[0] = pModal->ob_0;
  726. ob[1] = ob[2] = ob[3] = ob[4] = pModal->ob_1;
  727. db1[0] = pModal->db1_0;
  728. db1[1] = db1[2] = db1[3] = db1[4] = pModal->db1_1;
  729. db2[0] = pModal->db2_0;
  730. db2[1] = db2[2] = db2[3] = db2[4] = pModal->db2_1;
  731. } else {
  732. int i;
  733. for (i = 0; i < 5; i++) {
  734. ob[i] = pModal->ob_0;
  735. db1[i] = pModal->db1_0;
  736. db2[i] = pModal->db1_0;
  737. }
  738. }
  739. if (AR_SREV_9271(ah)) {
  740. ath9k_hw_analog_shift_rmw(ah,
  741. AR9285_AN_RF2G3,
  742. AR9271_AN_RF2G3_OB_cck,
  743. AR9271_AN_RF2G3_OB_cck_S,
  744. ob[0]);
  745. ath9k_hw_analog_shift_rmw(ah,
  746. AR9285_AN_RF2G3,
  747. AR9271_AN_RF2G3_OB_psk,
  748. AR9271_AN_RF2G3_OB_psk_S,
  749. ob[1]);
  750. ath9k_hw_analog_shift_rmw(ah,
  751. AR9285_AN_RF2G3,
  752. AR9271_AN_RF2G3_OB_qam,
  753. AR9271_AN_RF2G3_OB_qam_S,
  754. ob[2]);
  755. ath9k_hw_analog_shift_rmw(ah,
  756. AR9285_AN_RF2G3,
  757. AR9271_AN_RF2G3_DB_1,
  758. AR9271_AN_RF2G3_DB_1_S,
  759. db1[0]);
  760. ath9k_hw_analog_shift_rmw(ah,
  761. AR9285_AN_RF2G4,
  762. AR9271_AN_RF2G4_DB_2,
  763. AR9271_AN_RF2G4_DB_2_S,
  764. db2[0]);
  765. } else {
  766. ath9k_hw_analog_shift_rmw(ah,
  767. AR9285_AN_RF2G3,
  768. AR9285_AN_RF2G3_OB_0,
  769. AR9285_AN_RF2G3_OB_0_S,
  770. ob[0]);
  771. ath9k_hw_analog_shift_rmw(ah,
  772. AR9285_AN_RF2G3,
  773. AR9285_AN_RF2G3_OB_1,
  774. AR9285_AN_RF2G3_OB_1_S,
  775. ob[1]);
  776. ath9k_hw_analog_shift_rmw(ah,
  777. AR9285_AN_RF2G3,
  778. AR9285_AN_RF2G3_OB_2,
  779. AR9285_AN_RF2G3_OB_2_S,
  780. ob[2]);
  781. ath9k_hw_analog_shift_rmw(ah,
  782. AR9285_AN_RF2G3,
  783. AR9285_AN_RF2G3_OB_3,
  784. AR9285_AN_RF2G3_OB_3_S,
  785. ob[3]);
  786. ath9k_hw_analog_shift_rmw(ah,
  787. AR9285_AN_RF2G3,
  788. AR9285_AN_RF2G3_OB_4,
  789. AR9285_AN_RF2G3_OB_4_S,
  790. ob[4]);
  791. ath9k_hw_analog_shift_rmw(ah,
  792. AR9285_AN_RF2G3,
  793. AR9285_AN_RF2G3_DB1_0,
  794. AR9285_AN_RF2G3_DB1_0_S,
  795. db1[0]);
  796. ath9k_hw_analog_shift_rmw(ah,
  797. AR9285_AN_RF2G3,
  798. AR9285_AN_RF2G3_DB1_1,
  799. AR9285_AN_RF2G3_DB1_1_S,
  800. db1[1]);
  801. ath9k_hw_analog_shift_rmw(ah,
  802. AR9285_AN_RF2G3,
  803. AR9285_AN_RF2G3_DB1_2,
  804. AR9285_AN_RF2G3_DB1_2_S,
  805. db1[2]);
  806. ath9k_hw_analog_shift_rmw(ah,
  807. AR9285_AN_RF2G4,
  808. AR9285_AN_RF2G4_DB1_3,
  809. AR9285_AN_RF2G4_DB1_3_S,
  810. db1[3]);
  811. ath9k_hw_analog_shift_rmw(ah,
  812. AR9285_AN_RF2G4,
  813. AR9285_AN_RF2G4_DB1_4,
  814. AR9285_AN_RF2G4_DB1_4_S, db1[4]);
  815. ath9k_hw_analog_shift_rmw(ah,
  816. AR9285_AN_RF2G4,
  817. AR9285_AN_RF2G4_DB2_0,
  818. AR9285_AN_RF2G4_DB2_0_S,
  819. db2[0]);
  820. ath9k_hw_analog_shift_rmw(ah,
  821. AR9285_AN_RF2G4,
  822. AR9285_AN_RF2G4_DB2_1,
  823. AR9285_AN_RF2G4_DB2_1_S,
  824. db2[1]);
  825. ath9k_hw_analog_shift_rmw(ah,
  826. AR9285_AN_RF2G4,
  827. AR9285_AN_RF2G4_DB2_2,
  828. AR9285_AN_RF2G4_DB2_2_S,
  829. db2[2]);
  830. ath9k_hw_analog_shift_rmw(ah,
  831. AR9285_AN_RF2G4,
  832. AR9285_AN_RF2G4_DB2_3,
  833. AR9285_AN_RF2G4_DB2_3_S,
  834. db2[3]);
  835. ath9k_hw_analog_shift_rmw(ah,
  836. AR9285_AN_RF2G4,
  837. AR9285_AN_RF2G4_DB2_4,
  838. AR9285_AN_RF2G4_DB2_4_S,
  839. db2[4]);
  840. }
  841. REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
  842. pModal->switchSettling);
  843. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
  844. pModal->adcDesiredSize);
  845. REG_WRITE(ah, AR_PHY_RF_CTL4,
  846. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
  847. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
  848. SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
  849. SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  850. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  851. pModal->txEndToRxOn);
  852. if (AR_SREV_9271_10(ah))
  853. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  854. pModal->txEndToRxOn);
  855. REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
  856. pModal->thresh62);
  857. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
  858. pModal->thresh62);
  859. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  860. AR5416_EEP_MINOR_VER_2) {
  861. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
  862. pModal->txFrameToDataStart);
  863. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
  864. pModal->txFrameToPaOn);
  865. }
  866. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  867. AR5416_EEP_MINOR_VER_3) {
  868. if (IS_CHAN_HT40(chan))
  869. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  870. AR_PHY_SETTLING_SWITCH,
  871. pModal->swSettleHt40);
  872. }
  873. if (AR_SREV_9271(ah) || AR_SREV_9285(ah)) {
  874. u8 bb_desired_scale = (pModal->bb_scale_smrt_antenna &
  875. EEP_4K_BB_DESIRED_SCALE_MASK);
  876. if ((pBase->txGainType == 0) && (bb_desired_scale != 0)) {
  877. u32 pwrctrl, mask, clr;
  878. mask = BIT(0)|BIT(5)|BIT(10)|BIT(15)|BIT(20)|BIT(25);
  879. pwrctrl = mask * bb_desired_scale;
  880. clr = mask * 0x1f;
  881. REG_RMW(ah, AR_PHY_TX_PWRCTRL8, pwrctrl, clr);
  882. REG_RMW(ah, AR_PHY_TX_PWRCTRL10, pwrctrl, clr);
  883. REG_RMW(ah, AR_PHY_CH0_TX_PWRCTRL12, pwrctrl, clr);
  884. mask = BIT(0)|BIT(5)|BIT(15);
  885. pwrctrl = mask * bb_desired_scale;
  886. clr = mask * 0x1f;
  887. REG_RMW(ah, AR_PHY_TX_PWRCTRL9, pwrctrl, clr);
  888. mask = BIT(0)|BIT(5);
  889. pwrctrl = mask * bb_desired_scale;
  890. clr = mask * 0x1f;
  891. REG_RMW(ah, AR_PHY_CH0_TX_PWRCTRL11, pwrctrl, clr);
  892. REG_RMW(ah, AR_PHY_CH0_TX_PWRCTRL13, pwrctrl, clr);
  893. }
  894. }
  895. }
  896. static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, int is2GHz)
  897. {
  898. #define EEP_MAP4K_SPURCHAN \
  899. (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan)
  900. u16 spur_val = AR_NO_SPUR;
  901. DBG2("ath9k: "
  902. "Getting spur idx:%d is2Ghz:%d val:%x\n",
  903. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  904. switch (ah->config.spurmode) {
  905. case SPUR_DISABLE:
  906. break;
  907. case SPUR_ENABLE_IOCTL:
  908. spur_val = ah->config.spurchans[i][is2GHz];
  909. DBG2("ath9k: "
  910. "Getting spur val from new loc. %d\n", spur_val);
  911. break;
  912. case SPUR_ENABLE_EEPROM:
  913. spur_val = EEP_MAP4K_SPURCHAN;
  914. break;
  915. }
  916. return spur_val;
  917. #undef EEP_MAP4K_SPURCHAN
  918. }
  919. const struct eeprom_ops eep_4k_ops = {
  920. .check_eeprom = ath9k_hw_4k_check_eeprom,
  921. .get_eeprom = ath9k_hw_4k_get_eeprom,
  922. .fill_eeprom = ath9k_hw_4k_fill_eeprom,
  923. .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver,
  924. .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev,
  925. .set_board_values = ath9k_hw_4k_set_board_values,
  926. .set_addac = ath9k_hw_4k_set_addac,
  927. .set_txpower = ath9k_hw_4k_set_txpower,
  928. .get_spur_channel = ath9k_hw_4k_get_spur_channel
  929. };