eeprom_4k.c 29 KB

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