eeprom_9287.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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. #define NUM_EEP_WORDS (sizeof(struct ar9287_eeprom) / sizeof(u16))
  19. static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah)
  20. {
  21. return (ah->eeprom.map9287.baseEepHeader.version >> 12) & 0xF;
  22. }
  23. static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah)
  24. {
  25. return (ah->eeprom.map9287.baseEepHeader.version) & 0xFFF;
  26. }
  27. static bool ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah)
  28. {
  29. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  30. struct ath_common *common = ath9k_hw_common(ah);
  31. u16 *eep_data;
  32. int addr, eep_start_loc;
  33. eep_data = (u16 *)eep;
  34. if (common->bus_ops->ath_bus_type == ATH_USB)
  35. eep_start_loc = AR9287_HTC_EEP_START_LOC;
  36. else
  37. eep_start_loc = AR9287_EEP_START_LOC;
  38. if (!ath9k_hw_use_flash(ah)) {
  39. ath_dbg(common, ATH_DBG_EEPROM,
  40. "Reading from EEPROM, not flash\n");
  41. }
  42. for (addr = 0; addr < NUM_EEP_WORDS; addr++) {
  43. if (!ath9k_hw_nvram_read(common, addr + eep_start_loc,
  44. eep_data)) {
  45. ath_dbg(common, ATH_DBG_EEPROM,
  46. "Unable to read eeprom region\n");
  47. return false;
  48. }
  49. eep_data++;
  50. }
  51. return true;
  52. }
  53. static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah)
  54. {
  55. u32 sum = 0, el, integer;
  56. u16 temp, word, magic, magic2, *eepdata;
  57. int i, addr;
  58. bool need_swap = false;
  59. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  60. struct ath_common *common = ath9k_hw_common(ah);
  61. if (!ath9k_hw_use_flash(ah)) {
  62. if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET,
  63. &magic)) {
  64. ath_err(common, "Reading Magic # failed\n");
  65. return false;
  66. }
  67. ath_dbg(common, ATH_DBG_EEPROM,
  68. "Read Magic = 0x%04X\n", magic);
  69. if (magic != AR5416_EEPROM_MAGIC) {
  70. magic2 = swab16(magic);
  71. if (magic2 == AR5416_EEPROM_MAGIC) {
  72. need_swap = true;
  73. eepdata = (u16 *)(&ah->eeprom);
  74. for (addr = 0; addr < NUM_EEP_WORDS; addr++) {
  75. temp = swab16(*eepdata);
  76. *eepdata = temp;
  77. eepdata++;
  78. }
  79. } else {
  80. ath_err(common,
  81. "Invalid EEPROM Magic. Endianness mismatch.\n");
  82. return -EINVAL;
  83. }
  84. }
  85. }
  86. ath_dbg(common, ATH_DBG_EEPROM, "need_swap = %s.\n",
  87. need_swap ? "True" : "False");
  88. if (need_swap)
  89. el = swab16(ah->eeprom.map9287.baseEepHeader.length);
  90. else
  91. el = ah->eeprom.map9287.baseEepHeader.length;
  92. if (el > sizeof(struct ar9287_eeprom))
  93. el = sizeof(struct ar9287_eeprom) / sizeof(u16);
  94. else
  95. el = el / sizeof(u16);
  96. eepdata = (u16 *)(&ah->eeprom);
  97. for (i = 0; i < el; i++)
  98. sum ^= *eepdata++;
  99. if (need_swap) {
  100. word = swab16(eep->baseEepHeader.length);
  101. eep->baseEepHeader.length = word;
  102. word = swab16(eep->baseEepHeader.checksum);
  103. eep->baseEepHeader.checksum = word;
  104. word = swab16(eep->baseEepHeader.version);
  105. eep->baseEepHeader.version = word;
  106. word = swab16(eep->baseEepHeader.regDmn[0]);
  107. eep->baseEepHeader.regDmn[0] = word;
  108. word = swab16(eep->baseEepHeader.regDmn[1]);
  109. eep->baseEepHeader.regDmn[1] = word;
  110. word = swab16(eep->baseEepHeader.rfSilent);
  111. eep->baseEepHeader.rfSilent = word;
  112. word = swab16(eep->baseEepHeader.blueToothOptions);
  113. eep->baseEepHeader.blueToothOptions = word;
  114. word = swab16(eep->baseEepHeader.deviceCap);
  115. eep->baseEepHeader.deviceCap = word;
  116. integer = swab32(eep->modalHeader.antCtrlCommon);
  117. eep->modalHeader.antCtrlCommon = integer;
  118. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  119. integer = swab32(eep->modalHeader.antCtrlChain[i]);
  120. eep->modalHeader.antCtrlChain[i] = integer;
  121. }
  122. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  123. word = swab16(eep->modalHeader.spurChans[i].spurChan);
  124. eep->modalHeader.spurChans[i].spurChan = word;
  125. }
  126. }
  127. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR9287_EEP_VER
  128. || ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  129. ath_err(common, "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  130. sum, ah->eep_ops->get_eeprom_ver(ah));
  131. return -EINVAL;
  132. }
  133. return 0;
  134. }
  135. static u32 ath9k_hw_ar9287_get_eeprom(struct ath_hw *ah,
  136. enum eeprom_param param)
  137. {
  138. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  139. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  140. struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
  141. u16 ver_minor;
  142. ver_minor = pBase->version & AR9287_EEP_VER_MINOR_MASK;
  143. switch (param) {
  144. case EEP_NFTHRESH_2:
  145. return pModal->noiseFloorThreshCh[0];
  146. case EEP_MAC_LSW:
  147. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  148. case EEP_MAC_MID:
  149. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  150. case EEP_MAC_MSW:
  151. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  152. case EEP_REG_0:
  153. return pBase->regDmn[0];
  154. case EEP_REG_1:
  155. return pBase->regDmn[1];
  156. case EEP_OP_CAP:
  157. return pBase->deviceCap;
  158. case EEP_OP_MODE:
  159. return pBase->opCapFlags;
  160. case EEP_RF_SILENT:
  161. return pBase->rfSilent;
  162. case EEP_MINOR_REV:
  163. return ver_minor;
  164. case EEP_TX_MASK:
  165. return pBase->txMask;
  166. case EEP_RX_MASK:
  167. return pBase->rxMask;
  168. case EEP_DEV_TYPE:
  169. return pBase->deviceType;
  170. case EEP_OL_PWRCTRL:
  171. return pBase->openLoopPwrCntl;
  172. case EEP_TEMPSENSE_SLOPE:
  173. if (ver_minor >= AR9287_EEP_MINOR_VER_2)
  174. return pBase->tempSensSlope;
  175. else
  176. return 0;
  177. case EEP_TEMPSENSE_SLOPE_PAL_ON:
  178. if (ver_minor >= AR9287_EEP_MINOR_VER_3)
  179. return pBase->tempSensSlopePalOn;
  180. else
  181. return 0;
  182. default:
  183. return 0;
  184. }
  185. }
  186. static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah,
  187. struct ath9k_channel *chan,
  188. struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop,
  189. u8 *pCalChans, u16 availPiers, int8_t *pPwr)
  190. {
  191. u16 idxL = 0, idxR = 0, numPiers;
  192. bool match;
  193. struct chan_centers centers;
  194. ath9k_hw_get_channel_centers(ah, chan, &centers);
  195. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  196. if (pCalChans[numPiers] == AR5416_BCHAN_UNUSED)
  197. break;
  198. }
  199. match = ath9k_hw_get_lower_upper_index(
  200. (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
  201. pCalChans, numPiers, &idxL, &idxR);
  202. if (match) {
  203. *pPwr = (int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0];
  204. } else {
  205. *pPwr = ((int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0] +
  206. (int8_t) pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
  207. }
  208. }
  209. static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah,
  210. int32_t txPower, u16 chain)
  211. {
  212. u32 tmpVal;
  213. u32 a;
  214. /* Enable OLPC for chain 0 */
  215. tmpVal = REG_READ(ah, 0xa270);
  216. tmpVal = tmpVal & 0xFCFFFFFF;
  217. tmpVal = tmpVal | (0x3 << 24);
  218. REG_WRITE(ah, 0xa270, tmpVal);
  219. /* Enable OLPC for chain 1 */
  220. tmpVal = REG_READ(ah, 0xb270);
  221. tmpVal = tmpVal & 0xFCFFFFFF;
  222. tmpVal = tmpVal | (0x3 << 24);
  223. REG_WRITE(ah, 0xb270, tmpVal);
  224. /* Write the OLPC ref power for chain 0 */
  225. if (chain == 0) {
  226. tmpVal = REG_READ(ah, 0xa398);
  227. tmpVal = tmpVal & 0xff00ffff;
  228. a = (txPower)&0xff;
  229. tmpVal = tmpVal | (a << 16);
  230. REG_WRITE(ah, 0xa398, tmpVal);
  231. }
  232. /* Write the OLPC ref power for chain 1 */
  233. if (chain == 1) {
  234. tmpVal = REG_READ(ah, 0xb398);
  235. tmpVal = tmpVal & 0xff00ffff;
  236. a = (txPower)&0xff;
  237. tmpVal = tmpVal | (a << 16);
  238. REG_WRITE(ah, 0xb398, tmpVal);
  239. }
  240. }
  241. static void ath9k_hw_set_ar9287_power_cal_table(struct ath_hw *ah,
  242. struct ath9k_channel *chan,
  243. int16_t *pTxPowerIndexOffset)
  244. {
  245. struct cal_data_per_freq_ar9287 *pRawDataset;
  246. struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
  247. u8 *pCalBChans = NULL;
  248. u16 pdGainOverlap_t2;
  249. u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
  250. u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
  251. u16 numPiers = 0, i, j;
  252. u16 numXpdGain, xpdMask;
  253. u16 xpdGainValues[AR5416_NUM_PD_GAINS] = {0, 0, 0, 0};
  254. u32 reg32, regOffset, regChainOffset, regval;
  255. int16_t modalIdx, diff = 0;
  256. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  257. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  258. xpdMask = pEepData->modalHeader.xpdGain;
  259. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  260. AR9287_EEP_MINOR_VER_2)
  261. pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
  262. else
  263. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  264. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  265. if (IS_CHAN_2GHZ(chan)) {
  266. pCalBChans = pEepData->calFreqPier2G;
  267. numPiers = AR9287_NUM_2G_CAL_PIERS;
  268. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  269. pRawDatasetOpenLoop =
  270. (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];
  271. ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
  272. }
  273. }
  274. numXpdGain = 0;
  275. /* Calculate the value of xpdgains from the xpdGain Mask */
  276. for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
  277. if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
  278. if (numXpdGain >= AR5416_NUM_PD_GAINS)
  279. break;
  280. xpdGainValues[numXpdGain] =
  281. (u16)(AR5416_PD_GAINS_IN_MASK-i);
  282. numXpdGain++;
  283. }
  284. }
  285. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  286. (numXpdGain - 1) & 0x3);
  287. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  288. xpdGainValues[0]);
  289. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  290. xpdGainValues[1]);
  291. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  292. xpdGainValues[2]);
  293. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  294. regChainOffset = i * 0x1000;
  295. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  296. pRawDatasetOpenLoop =
  297. (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];
  298. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  299. int8_t txPower;
  300. ar9287_eeprom_get_tx_gain_index(ah, chan,
  301. pRawDatasetOpenLoop,
  302. pCalBChans, numPiers,
  303. &txPower);
  304. ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i);
  305. } else {
  306. pRawDataset =
  307. (struct cal_data_per_freq_ar9287 *)
  308. pEepData->calPierData2G[i];
  309. ath9k_hw_get_gain_boundaries_pdadcs(ah, chan,
  310. pRawDataset,
  311. pCalBChans, numPiers,
  312. pdGainOverlap_t2,
  313. gainBoundaries,
  314. pdadcValues,
  315. numXpdGain);
  316. }
  317. if (i == 0) {
  318. if (!ath9k_hw_ar9287_get_eeprom(ah,
  319. EEP_OL_PWRCTRL)) {
  320. regval = SM(pdGainOverlap_t2,
  321. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
  322. | SM(gainBoundaries[0],
  323. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
  324. | SM(gainBoundaries[1],
  325. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
  326. | SM(gainBoundaries[2],
  327. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
  328. | SM(gainBoundaries[3],
  329. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4);
  330. REG_WRITE(ah,
  331. AR_PHY_TPCRG5 + regChainOffset,
  332. regval);
  333. }
  334. }
  335. if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB !=
  336. pEepData->baseEepHeader.pwrTableOffset) {
  337. diff = (u16)(pEepData->baseEepHeader.pwrTableOffset -
  338. (int32_t)AR9287_PWR_TABLE_OFFSET_DB);
  339. diff *= 2;
  340. for (j = 0; j < ((u16)AR5416_NUM_PDADC_VALUES-diff); j++)
  341. pdadcValues[j] = pdadcValues[j+diff];
  342. for (j = (u16)(AR5416_NUM_PDADC_VALUES-diff);
  343. j < AR5416_NUM_PDADC_VALUES; j++)
  344. pdadcValues[j] =
  345. pdadcValues[AR5416_NUM_PDADC_VALUES-diff];
  346. }
  347. if (!ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  348. regOffset = AR_PHY_BASE +
  349. (672 << 2) + regChainOffset;
  350. for (j = 0; j < 32; j++) {
  351. reg32 = ((pdadcValues[4*j + 0] & 0xFF) << 0)
  352. | ((pdadcValues[4*j + 1] & 0xFF) << 8)
  353. | ((pdadcValues[4*j + 2] & 0xFF) << 16)
  354. | ((pdadcValues[4*j + 3] & 0xFF) << 24);
  355. REG_WRITE(ah, regOffset, reg32);
  356. regOffset += 4;
  357. }
  358. }
  359. }
  360. }
  361. *pTxPowerIndexOffset = 0;
  362. }
  363. static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
  364. struct ath9k_channel *chan,
  365. int16_t *ratesArray,
  366. u16 cfgCtl,
  367. u16 AntennaReduction,
  368. u16 twiceMaxRegulatoryPower,
  369. u16 powerLimit)
  370. {
  371. #define CMP_CTL \
  372. (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  373. pEepData->ctlIndex[i])
  374. #define CMP_NO_CTL \
  375. (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  376. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
  377. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
  378. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
  379. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  380. u16 twiceMaxEdgePower = MAX_RATE_POWER;
  381. static const u16 tpScaleReductionTable[5] =
  382. { 0, 3, 6, 9, MAX_RATE_POWER };
  383. int i;
  384. int16_t twiceLargestAntenna;
  385. struct cal_ctl_data_ar9287 *rep;
  386. struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
  387. targetPowerCck = {0, {0, 0, 0, 0} };
  388. struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
  389. targetPowerCckExt = {0, {0, 0, 0, 0} };
  390. struct cal_target_power_ht targetPowerHt20,
  391. targetPowerHt40 = {0, {0, 0, 0, 0} };
  392. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  393. static const u16 ctlModesFor11g[] = {
  394. CTL_11B, CTL_11G, CTL_2GHT20,
  395. CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
  396. };
  397. u16 numCtlModes = 0;
  398. const u16 *pCtlMode = NULL;
  399. u16 ctlMode, freq;
  400. struct chan_centers centers;
  401. int tx_chainmask;
  402. u16 twiceMinEdgePower;
  403. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  404. tx_chainmask = ah->txchainmask;
  405. ath9k_hw_get_channel_centers(ah, chan, &centers);
  406. /* Compute TxPower reduction due to Antenna Gain */
  407. twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
  408. pEepData->modalHeader.antennaGainCh[1]);
  409. twiceLargestAntenna = (int16_t)min((AntennaReduction) -
  410. twiceLargestAntenna, 0);
  411. /*
  412. * scaledPower is the minimum of the user input power level
  413. * and the regulatory allowed power level.
  414. */
  415. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  416. if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX)
  417. maxRegAllowedPower -=
  418. (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
  419. scaledPower = min(powerLimit, maxRegAllowedPower);
  420. /*
  421. * Reduce scaled Power by number of chains active
  422. * to get the per chain tx power level.
  423. */
  424. switch (ar5416_get_ntxchains(tx_chainmask)) {
  425. case 1:
  426. break;
  427. case 2:
  428. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  429. break;
  430. case 3:
  431. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  432. break;
  433. }
  434. scaledPower = max((u16)0, scaledPower);
  435. /*
  436. * Get TX power from EEPROM.
  437. */
  438. if (IS_CHAN_2GHZ(chan)) {
  439. /* CTL_11B, CTL_11G, CTL_2GHT20 */
  440. numCtlModes =
  441. ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
  442. pCtlMode = ctlModesFor11g;
  443. ath9k_hw_get_legacy_target_powers(ah, chan,
  444. pEepData->calTargetPowerCck,
  445. AR9287_NUM_2G_CCK_TARGET_POWERS,
  446. &targetPowerCck, 4, false);
  447. ath9k_hw_get_legacy_target_powers(ah, chan,
  448. pEepData->calTargetPower2G,
  449. AR9287_NUM_2G_20_TARGET_POWERS,
  450. &targetPowerOfdm, 4, false);
  451. ath9k_hw_get_target_powers(ah, chan,
  452. pEepData->calTargetPower2GHT20,
  453. AR9287_NUM_2G_20_TARGET_POWERS,
  454. &targetPowerHt20, 8, false);
  455. if (IS_CHAN_HT40(chan)) {
  456. /* All 2G CTLs */
  457. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  458. ath9k_hw_get_target_powers(ah, chan,
  459. pEepData->calTargetPower2GHT40,
  460. AR9287_NUM_2G_40_TARGET_POWERS,
  461. &targetPowerHt40, 8, true);
  462. ath9k_hw_get_legacy_target_powers(ah, chan,
  463. pEepData->calTargetPowerCck,
  464. AR9287_NUM_2G_CCK_TARGET_POWERS,
  465. &targetPowerCckExt, 4, true);
  466. ath9k_hw_get_legacy_target_powers(ah, chan,
  467. pEepData->calTargetPower2G,
  468. AR9287_NUM_2G_20_TARGET_POWERS,
  469. &targetPowerOfdmExt, 4, true);
  470. }
  471. }
  472. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  473. bool isHt40CtlMode =
  474. (pCtlMode[ctlMode] == CTL_2GHT40) ? true : false;
  475. if (isHt40CtlMode)
  476. freq = centers.synth_center;
  477. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  478. freq = centers.ext_center;
  479. else
  480. freq = centers.ctl_center;
  481. /* Walk through the CTL indices stored in EEPROM */
  482. for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  483. struct cal_ctl_edges *pRdEdgesPower;
  484. /*
  485. * Compare test group from regulatory channel list
  486. * with test mode from pCtlMode list
  487. */
  488. if (CMP_CTL || CMP_NO_CTL) {
  489. rep = &(pEepData->ctlData[i]);
  490. pRdEdgesPower =
  491. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1];
  492. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  493. pRdEdgesPower,
  494. IS_CHAN_2GHZ(chan),
  495. AR5416_NUM_BAND_EDGES);
  496. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  497. twiceMaxEdgePower = min(twiceMaxEdgePower,
  498. twiceMinEdgePower);
  499. } else {
  500. twiceMaxEdgePower = twiceMinEdgePower;
  501. break;
  502. }
  503. }
  504. }
  505. minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
  506. /* Apply ctl mode to correct target power set */
  507. switch (pCtlMode[ctlMode]) {
  508. case CTL_11B:
  509. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  510. targetPowerCck.tPow2x[i] =
  511. (u8)min((u16)targetPowerCck.tPow2x[i],
  512. minCtlPower);
  513. }
  514. break;
  515. case CTL_11A:
  516. case CTL_11G:
  517. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  518. targetPowerOfdm.tPow2x[i] =
  519. (u8)min((u16)targetPowerOfdm.tPow2x[i],
  520. minCtlPower);
  521. }
  522. break;
  523. case CTL_5GHT20:
  524. case CTL_2GHT20:
  525. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  526. targetPowerHt20.tPow2x[i] =
  527. (u8)min((u16)targetPowerHt20.tPow2x[i],
  528. minCtlPower);
  529. }
  530. break;
  531. case CTL_11B_EXT:
  532. targetPowerCckExt.tPow2x[0] =
  533. (u8)min((u16)targetPowerCckExt.tPow2x[0],
  534. minCtlPower);
  535. break;
  536. case CTL_11A_EXT:
  537. case CTL_11G_EXT:
  538. targetPowerOfdmExt.tPow2x[0] =
  539. (u8)min((u16)targetPowerOfdmExt.tPow2x[0],
  540. minCtlPower);
  541. break;
  542. case CTL_5GHT40:
  543. case CTL_2GHT40:
  544. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  545. targetPowerHt40.tPow2x[i] =
  546. (u8)min((u16)targetPowerHt40.tPow2x[i],
  547. minCtlPower);
  548. }
  549. break;
  550. default:
  551. break;
  552. }
  553. }
  554. /* Now set the rates array */
  555. ratesArray[rate6mb] =
  556. ratesArray[rate9mb] =
  557. ratesArray[rate12mb] =
  558. ratesArray[rate18mb] =
  559. ratesArray[rate24mb] = targetPowerOfdm.tPow2x[0];
  560. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  561. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  562. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  563. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  564. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  565. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  566. if (IS_CHAN_2GHZ(chan)) {
  567. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  568. ratesArray[rate2s] =
  569. ratesArray[rate2l] = targetPowerCck.tPow2x[1];
  570. ratesArray[rate5_5s] =
  571. ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
  572. ratesArray[rate11s] =
  573. ratesArray[rate11l] = targetPowerCck.tPow2x[3];
  574. }
  575. if (IS_CHAN_HT40(chan)) {
  576. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++)
  577. ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i];
  578. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  579. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  580. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  581. if (IS_CHAN_2GHZ(chan))
  582. ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
  583. }
  584. #undef CMP_CTL
  585. #undef CMP_NO_CTL
  586. #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
  587. #undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
  588. }
  589. static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
  590. struct ath9k_channel *chan, u16 cfgCtl,
  591. u8 twiceAntennaReduction,
  592. u8 twiceMaxRegulatoryPower,
  593. u8 powerLimit, bool test)
  594. {
  595. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  596. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  597. struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader;
  598. int16_t ratesArray[Ar5416RateSize];
  599. int16_t txPowerIndexOffset = 0;
  600. u8 ht40PowerIncForPdadc = 2;
  601. int i;
  602. memset(ratesArray, 0, sizeof(ratesArray));
  603. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  604. AR9287_EEP_MINOR_VER_2)
  605. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  606. ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
  607. &ratesArray[0], cfgCtl,
  608. twiceAntennaReduction,
  609. twiceMaxRegulatoryPower,
  610. powerLimit);
  611. ath9k_hw_set_ar9287_power_cal_table(ah, chan, &txPowerIndexOffset);
  612. regulatory->max_power_level = 0;
  613. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  614. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  615. if (ratesArray[i] > MAX_RATE_POWER)
  616. ratesArray[i] = MAX_RATE_POWER;
  617. if (ratesArray[i] > regulatory->max_power_level)
  618. regulatory->max_power_level = ratesArray[i];
  619. }
  620. if (test)
  621. return;
  622. if (IS_CHAN_2GHZ(chan))
  623. i = rate1l;
  624. else
  625. i = rate6mb;
  626. regulatory->max_power_level = ratesArray[i];
  627. if (AR_SREV_9280_20_OR_LATER(ah)) {
  628. for (i = 0; i < Ar5416RateSize; i++)
  629. ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
  630. }
  631. /* OFDM power per rate */
  632. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  633. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  634. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  635. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  636. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  637. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  638. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  639. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  640. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  641. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  642. /* CCK power per rate */
  643. if (IS_CHAN_2GHZ(chan)) {
  644. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  645. ATH9K_POW_SM(ratesArray[rate2s], 24)
  646. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  647. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  648. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  649. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  650. ATH9K_POW_SM(ratesArray[rate11s], 24)
  651. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  652. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  653. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  654. }
  655. /* HT20 power per rate */
  656. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  657. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  658. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  659. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  660. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  661. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  662. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  663. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  664. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  665. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  666. /* HT40 power per rate */
  667. if (IS_CHAN_HT40(chan)) {
  668. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  669. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  670. ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
  671. | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
  672. | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
  673. | ATH9K_POW_SM(ratesArray[rateHt40_0], 0));
  674. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  675. ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
  676. | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
  677. | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
  678. | ATH9K_POW_SM(ratesArray[rateHt40_4], 0));
  679. } else {
  680. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  681. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  682. ht40PowerIncForPdadc, 24)
  683. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  684. ht40PowerIncForPdadc, 16)
  685. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  686. ht40PowerIncForPdadc, 8)
  687. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  688. ht40PowerIncForPdadc, 0));
  689. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  690. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  691. ht40PowerIncForPdadc, 24)
  692. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  693. ht40PowerIncForPdadc, 16)
  694. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  695. ht40PowerIncForPdadc, 8)
  696. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  697. ht40PowerIncForPdadc, 0));
  698. }
  699. /* Dup/Ext power per rate */
  700. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  701. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  702. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  703. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  704. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  705. }
  706. }
  707. static void ath9k_hw_ar9287_set_addac(struct ath_hw *ah,
  708. struct ath9k_channel *chan)
  709. {
  710. }
  711. static void ath9k_hw_ar9287_set_board_values(struct ath_hw *ah,
  712. struct ath9k_channel *chan)
  713. {
  714. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  715. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  716. u16 antWrites[AR9287_ANT_16S];
  717. u32 regChainOffset, regval;
  718. u8 txRxAttenLocal;
  719. int i, j, offset_num;
  720. pModal = &eep->modalHeader;
  721. antWrites[0] = (u16)((pModal->antCtrlCommon >> 28) & 0xF);
  722. antWrites[1] = (u16)((pModal->antCtrlCommon >> 24) & 0xF);
  723. antWrites[2] = (u16)((pModal->antCtrlCommon >> 20) & 0xF);
  724. antWrites[3] = (u16)((pModal->antCtrlCommon >> 16) & 0xF);
  725. antWrites[4] = (u16)((pModal->antCtrlCommon >> 12) & 0xF);
  726. antWrites[5] = (u16)((pModal->antCtrlCommon >> 8) & 0xF);
  727. antWrites[6] = (u16)((pModal->antCtrlCommon >> 4) & 0xF);
  728. antWrites[7] = (u16)(pModal->antCtrlCommon & 0xF);
  729. offset_num = 8;
  730. for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) {
  731. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 28) & 0xf);
  732. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 10) & 0x3);
  733. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 8) & 0x3);
  734. antWrites[j++] = 0;
  735. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 6) & 0x3);
  736. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 4) & 0x3);
  737. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 2) & 0x3);
  738. antWrites[j++] = (u16)(pModal->antCtrlChain[i] & 0x3);
  739. }
  740. REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
  741. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  742. regChainOffset = i * 0x1000;
  743. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  744. pModal->antCtrlChain[i]);
  745. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  746. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
  747. & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  748. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  749. SM(pModal->iqCalICh[i],
  750. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  751. SM(pModal->iqCalQCh[i],
  752. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  753. txRxAttenLocal = pModal->txRxAttenCh[i];
  754. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  755. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  756. pModal->bswMargin[i]);
  757. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  758. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  759. pModal->bswAtten[i]);
  760. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  761. AR9280_PHY_RXGAIN_TXRX_ATTEN,
  762. txRxAttenLocal);
  763. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  764. AR9280_PHY_RXGAIN_TXRX_MARGIN,
  765. pModal->rxTxMarginCh[i]);
  766. }
  767. if (IS_CHAN_HT40(chan))
  768. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  769. AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
  770. else
  771. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  772. AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
  773. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  774. AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
  775. REG_WRITE(ah, AR_PHY_RF_CTL4,
  776. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  777. | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  778. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  779. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  780. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
  781. AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
  782. REG_RMW_FIELD(ah, AR_PHY_CCA,
  783. AR9280_PHY_CCA_THRESH62, pModal->thresh62);
  784. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  785. AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
  786. regval = REG_READ(ah, AR9287_AN_RF2G3_CH0);
  787. regval &= ~(AR9287_AN_RF2G3_DB1 |
  788. AR9287_AN_RF2G3_DB2 |
  789. AR9287_AN_RF2G3_OB_CCK |
  790. AR9287_AN_RF2G3_OB_PSK |
  791. AR9287_AN_RF2G3_OB_QAM |
  792. AR9287_AN_RF2G3_OB_PAL_OFF);
  793. regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
  794. SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
  795. SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
  796. SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
  797. SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
  798. SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
  799. ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH0, regval);
  800. regval = REG_READ(ah, AR9287_AN_RF2G3_CH1);
  801. regval &= ~(AR9287_AN_RF2G3_DB1 |
  802. AR9287_AN_RF2G3_DB2 |
  803. AR9287_AN_RF2G3_OB_CCK |
  804. AR9287_AN_RF2G3_OB_PSK |
  805. AR9287_AN_RF2G3_OB_QAM |
  806. AR9287_AN_RF2G3_OB_PAL_OFF);
  807. regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
  808. SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
  809. SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
  810. SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
  811. SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
  812. SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
  813. ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH1, regval);
  814. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  815. AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
  816. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  817. AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
  818. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
  819. AR9287_AN_TOP2_XPABIAS_LVL,
  820. AR9287_AN_TOP2_XPABIAS_LVL_S,
  821. pModal->xpaBiasLvl);
  822. }
  823. static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
  824. u16 i, bool is2GHz)
  825. {
  826. #define EEP_MAP9287_SPURCHAN \
  827. (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan)
  828. struct ath_common *common = ath9k_hw_common(ah);
  829. u16 spur_val = AR_NO_SPUR;
  830. ath_dbg(common, ATH_DBG_ANI,
  831. "Getting spur idx:%d is2Ghz:%d val:%x\n",
  832. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  833. switch (ah->config.spurmode) {
  834. case SPUR_DISABLE:
  835. break;
  836. case SPUR_ENABLE_IOCTL:
  837. spur_val = ah->config.spurchans[i][is2GHz];
  838. ath_dbg(common, ATH_DBG_ANI,
  839. "Getting spur val from new loc. %d\n", spur_val);
  840. break;
  841. case SPUR_ENABLE_EEPROM:
  842. spur_val = EEP_MAP9287_SPURCHAN;
  843. break;
  844. }
  845. return spur_val;
  846. #undef EEP_MAP9287_SPURCHAN
  847. }
  848. const struct eeprom_ops eep_ar9287_ops = {
  849. .check_eeprom = ath9k_hw_ar9287_check_eeprom,
  850. .get_eeprom = ath9k_hw_ar9287_get_eeprom,
  851. .fill_eeprom = ath9k_hw_ar9287_fill_eeprom,
  852. .get_eeprom_ver = ath9k_hw_ar9287_get_eeprom_ver,
  853. .get_eeprom_rev = ath9k_hw_ar9287_get_eeprom_rev,
  854. .set_board_values = ath9k_hw_ar9287_set_board_values,
  855. .set_addac = ath9k_hw_ar9287_set_addac,
  856. .set_txpower = ath9k_hw_ar9287_set_txpower,
  857. .get_spur_channel = ath9k_hw_ar9287_get_spur_channel
  858. };