eeprom_9287.c 30 KB

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