eeprom_9287.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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. ENABLE_REGWRITE_BUFFER(ah);
  330. if (i == 0) {
  331. if (!ath9k_hw_ar9287_get_eeprom(ah,
  332. EEP_OL_PWRCTRL)) {
  333. regval = SM(pdGainOverlap_t2,
  334. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
  335. | SM(gainBoundaries[0],
  336. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
  337. | SM(gainBoundaries[1],
  338. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
  339. | SM(gainBoundaries[2],
  340. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
  341. | SM(gainBoundaries[3],
  342. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4);
  343. REG_WRITE(ah,
  344. AR_PHY_TPCRG5 + regChainOffset,
  345. regval);
  346. }
  347. }
  348. if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB !=
  349. pEepData->baseEepHeader.pwrTableOffset) {
  350. diff = (u16)(pEepData->baseEepHeader.pwrTableOffset -
  351. (int32_t)AR9287_PWR_TABLE_OFFSET_DB);
  352. diff *= 2;
  353. for (j = 0; j < ((u16)AR5416_NUM_PDADC_VALUES-diff); j++)
  354. pdadcValues[j] = pdadcValues[j+diff];
  355. for (j = (u16)(AR5416_NUM_PDADC_VALUES-diff);
  356. j < AR5416_NUM_PDADC_VALUES; j++)
  357. pdadcValues[j] =
  358. pdadcValues[AR5416_NUM_PDADC_VALUES-diff];
  359. }
  360. if (!ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  361. regOffset = AR_PHY_BASE +
  362. (672 << 2) + regChainOffset;
  363. for (j = 0; j < 32; j++) {
  364. reg32 = ((pdadcValues[4*j + 0] & 0xFF) << 0)
  365. | ((pdadcValues[4*j + 1] & 0xFF) << 8)
  366. | ((pdadcValues[4*j + 2] & 0xFF) << 16)
  367. | ((pdadcValues[4*j + 3] & 0xFF) << 24);
  368. REG_WRITE(ah, regOffset, reg32);
  369. regOffset += 4;
  370. }
  371. }
  372. REGWRITE_BUFFER_FLUSH(ah);
  373. }
  374. }
  375. *pTxPowerIndexOffset = 0;
  376. }
  377. static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
  378. struct ath9k_channel *chan,
  379. int16_t *ratesArray,
  380. u16 cfgCtl,
  381. u16 AntennaReduction,
  382. u16 twiceMaxRegulatoryPower,
  383. u16 powerLimit)
  384. {
  385. #define CMP_CTL \
  386. (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  387. pEepData->ctlIndex[i])
  388. #define CMP_NO_CTL \
  389. (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  390. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
  391. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
  392. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
  393. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  394. u16 twiceMaxEdgePower = MAX_RATE_POWER;
  395. static const u16 tpScaleReductionTable[5] =
  396. { 0, 3, 6, 9, MAX_RATE_POWER };
  397. int i;
  398. int16_t twiceLargestAntenna;
  399. struct cal_ctl_data_ar9287 *rep;
  400. struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
  401. targetPowerCck = {0, {0, 0, 0, 0} };
  402. struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
  403. targetPowerCckExt = {0, {0, 0, 0, 0} };
  404. struct cal_target_power_ht targetPowerHt20,
  405. targetPowerHt40 = {0, {0, 0, 0, 0} };
  406. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  407. static const u16 ctlModesFor11g[] = {
  408. CTL_11B, CTL_11G, CTL_2GHT20,
  409. CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
  410. };
  411. u16 numCtlModes = 0;
  412. const u16 *pCtlMode = NULL;
  413. u16 ctlMode, freq;
  414. struct chan_centers centers;
  415. int tx_chainmask;
  416. u16 twiceMinEdgePower;
  417. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  418. tx_chainmask = ah->txchainmask;
  419. ath9k_hw_get_channel_centers(ah, chan, &centers);
  420. /* Compute TxPower reduction due to Antenna Gain */
  421. twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
  422. pEepData->modalHeader.antennaGainCh[1]);
  423. twiceLargestAntenna = (int16_t)min((AntennaReduction) -
  424. twiceLargestAntenna, 0);
  425. /*
  426. * scaledPower is the minimum of the user input power level
  427. * and the regulatory allowed power level.
  428. */
  429. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  430. if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX)
  431. maxRegAllowedPower -=
  432. (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
  433. scaledPower = min(powerLimit, maxRegAllowedPower);
  434. /*
  435. * Reduce scaled Power by number of chains active
  436. * to get the per chain tx power level.
  437. */
  438. switch (ar5416_get_ntxchains(tx_chainmask)) {
  439. case 1:
  440. break;
  441. case 2:
  442. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  443. break;
  444. case 3:
  445. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  446. break;
  447. }
  448. scaledPower = max((u16)0, scaledPower);
  449. /*
  450. * Get TX power from EEPROM.
  451. */
  452. if (IS_CHAN_2GHZ(chan)) {
  453. /* CTL_11B, CTL_11G, CTL_2GHT20 */
  454. numCtlModes =
  455. ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
  456. pCtlMode = ctlModesFor11g;
  457. ath9k_hw_get_legacy_target_powers(ah, chan,
  458. pEepData->calTargetPowerCck,
  459. AR9287_NUM_2G_CCK_TARGET_POWERS,
  460. &targetPowerCck, 4, false);
  461. ath9k_hw_get_legacy_target_powers(ah, chan,
  462. pEepData->calTargetPower2G,
  463. AR9287_NUM_2G_20_TARGET_POWERS,
  464. &targetPowerOfdm, 4, false);
  465. ath9k_hw_get_target_powers(ah, chan,
  466. pEepData->calTargetPower2GHT20,
  467. AR9287_NUM_2G_20_TARGET_POWERS,
  468. &targetPowerHt20, 8, false);
  469. if (IS_CHAN_HT40(chan)) {
  470. /* All 2G CTLs */
  471. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  472. ath9k_hw_get_target_powers(ah, chan,
  473. pEepData->calTargetPower2GHT40,
  474. AR9287_NUM_2G_40_TARGET_POWERS,
  475. &targetPowerHt40, 8, true);
  476. ath9k_hw_get_legacy_target_powers(ah, chan,
  477. pEepData->calTargetPowerCck,
  478. AR9287_NUM_2G_CCK_TARGET_POWERS,
  479. &targetPowerCckExt, 4, true);
  480. ath9k_hw_get_legacy_target_powers(ah, chan,
  481. pEepData->calTargetPower2G,
  482. AR9287_NUM_2G_20_TARGET_POWERS,
  483. &targetPowerOfdmExt, 4, true);
  484. }
  485. }
  486. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  487. bool isHt40CtlMode =
  488. (pCtlMode[ctlMode] == CTL_2GHT40) ? true : false;
  489. if (isHt40CtlMode)
  490. freq = centers.synth_center;
  491. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  492. freq = centers.ext_center;
  493. else
  494. freq = centers.ctl_center;
  495. /* Walk through the CTL indices stored in EEPROM */
  496. for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  497. struct cal_ctl_edges *pRdEdgesPower;
  498. /*
  499. * Compare test group from regulatory channel list
  500. * with test mode from pCtlMode list
  501. */
  502. if (CMP_CTL || CMP_NO_CTL) {
  503. rep = &(pEepData->ctlData[i]);
  504. pRdEdgesPower =
  505. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1];
  506. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  507. pRdEdgesPower,
  508. IS_CHAN_2GHZ(chan),
  509. AR5416_NUM_BAND_EDGES);
  510. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  511. twiceMaxEdgePower = min(twiceMaxEdgePower,
  512. twiceMinEdgePower);
  513. } else {
  514. twiceMaxEdgePower = twiceMinEdgePower;
  515. break;
  516. }
  517. }
  518. }
  519. minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
  520. /* Apply ctl mode to correct target power set */
  521. switch (pCtlMode[ctlMode]) {
  522. case CTL_11B:
  523. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  524. targetPowerCck.tPow2x[i] =
  525. (u8)min((u16)targetPowerCck.tPow2x[i],
  526. minCtlPower);
  527. }
  528. break;
  529. case CTL_11A:
  530. case CTL_11G:
  531. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  532. targetPowerOfdm.tPow2x[i] =
  533. (u8)min((u16)targetPowerOfdm.tPow2x[i],
  534. minCtlPower);
  535. }
  536. break;
  537. case CTL_5GHT20:
  538. case CTL_2GHT20:
  539. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  540. targetPowerHt20.tPow2x[i] =
  541. (u8)min((u16)targetPowerHt20.tPow2x[i],
  542. minCtlPower);
  543. }
  544. break;
  545. case CTL_11B_EXT:
  546. targetPowerCckExt.tPow2x[0] =
  547. (u8)min((u16)targetPowerCckExt.tPow2x[0],
  548. minCtlPower);
  549. break;
  550. case CTL_11A_EXT:
  551. case CTL_11G_EXT:
  552. targetPowerOfdmExt.tPow2x[0] =
  553. (u8)min((u16)targetPowerOfdmExt.tPow2x[0],
  554. minCtlPower);
  555. break;
  556. case CTL_5GHT40:
  557. case CTL_2GHT40:
  558. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  559. targetPowerHt40.tPow2x[i] =
  560. (u8)min((u16)targetPowerHt40.tPow2x[i],
  561. minCtlPower);
  562. }
  563. break;
  564. default:
  565. break;
  566. }
  567. }
  568. /* Now set the rates array */
  569. ratesArray[rate6mb] =
  570. ratesArray[rate9mb] =
  571. ratesArray[rate12mb] =
  572. ratesArray[rate18mb] =
  573. ratesArray[rate24mb] = targetPowerOfdm.tPow2x[0];
  574. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  575. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  576. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  577. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  578. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  579. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  580. if (IS_CHAN_2GHZ(chan)) {
  581. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  582. ratesArray[rate2s] =
  583. ratesArray[rate2l] = targetPowerCck.tPow2x[1];
  584. ratesArray[rate5_5s] =
  585. ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
  586. ratesArray[rate11s] =
  587. ratesArray[rate11l] = targetPowerCck.tPow2x[3];
  588. }
  589. if (IS_CHAN_HT40(chan)) {
  590. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++)
  591. ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i];
  592. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  593. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  594. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  595. if (IS_CHAN_2GHZ(chan))
  596. ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
  597. }
  598. #undef CMP_CTL
  599. #undef CMP_NO_CTL
  600. #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
  601. #undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
  602. }
  603. static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
  604. struct ath9k_channel *chan, u16 cfgCtl,
  605. u8 twiceAntennaReduction,
  606. u8 twiceMaxRegulatoryPower,
  607. u8 powerLimit, bool test)
  608. {
  609. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  610. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  611. struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader;
  612. int16_t ratesArray[Ar5416RateSize];
  613. int16_t txPowerIndexOffset = 0;
  614. u8 ht40PowerIncForPdadc = 2;
  615. int i;
  616. memset(ratesArray, 0, sizeof(ratesArray));
  617. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  618. AR9287_EEP_MINOR_VER_2)
  619. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  620. ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
  621. &ratesArray[0], cfgCtl,
  622. twiceAntennaReduction,
  623. twiceMaxRegulatoryPower,
  624. powerLimit);
  625. ath9k_hw_set_ar9287_power_cal_table(ah, chan, &txPowerIndexOffset);
  626. regulatory->max_power_level = 0;
  627. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  628. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  629. if (ratesArray[i] > MAX_RATE_POWER)
  630. ratesArray[i] = MAX_RATE_POWER;
  631. if (ratesArray[i] > regulatory->max_power_level)
  632. regulatory->max_power_level = ratesArray[i];
  633. }
  634. if (test)
  635. return;
  636. if (IS_CHAN_2GHZ(chan))
  637. i = rate1l;
  638. else
  639. i = rate6mb;
  640. regulatory->max_power_level = ratesArray[i];
  641. if (AR_SREV_9280_20_OR_LATER(ah)) {
  642. for (i = 0; i < Ar5416RateSize; i++)
  643. ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
  644. }
  645. ENABLE_REGWRITE_BUFFER(ah);
  646. /* OFDM power per rate */
  647. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  648. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  649. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  650. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  651. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  652. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  653. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  654. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  655. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  656. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  657. /* CCK power per rate */
  658. if (IS_CHAN_2GHZ(chan)) {
  659. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  660. ATH9K_POW_SM(ratesArray[rate2s], 24)
  661. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  662. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  663. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  664. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  665. ATH9K_POW_SM(ratesArray[rate11s], 24)
  666. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  667. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  668. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  669. }
  670. /* HT20 power per rate */
  671. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  672. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  673. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  674. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  675. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  676. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  677. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  678. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  679. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  680. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  681. /* HT40 power per rate */
  682. if (IS_CHAN_HT40(chan)) {
  683. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  684. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  685. ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
  686. | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
  687. | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
  688. | ATH9K_POW_SM(ratesArray[rateHt40_0], 0));
  689. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  690. ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
  691. | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
  692. | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
  693. | ATH9K_POW_SM(ratesArray[rateHt40_4], 0));
  694. } else {
  695. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  696. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  697. ht40PowerIncForPdadc, 24)
  698. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  699. ht40PowerIncForPdadc, 16)
  700. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  701. ht40PowerIncForPdadc, 8)
  702. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  703. ht40PowerIncForPdadc, 0));
  704. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  705. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  706. ht40PowerIncForPdadc, 24)
  707. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  708. ht40PowerIncForPdadc, 16)
  709. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  710. ht40PowerIncForPdadc, 8)
  711. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  712. ht40PowerIncForPdadc, 0));
  713. }
  714. /* Dup/Ext power per rate */
  715. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  716. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  717. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  718. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  719. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  720. }
  721. REGWRITE_BUFFER_FLUSH(ah);
  722. }
  723. static void ath9k_hw_ar9287_set_addac(struct ath_hw *ah,
  724. struct ath9k_channel *chan)
  725. {
  726. }
  727. static void ath9k_hw_ar9287_set_board_values(struct ath_hw *ah,
  728. struct ath9k_channel *chan)
  729. {
  730. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  731. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  732. u16 antWrites[AR9287_ANT_16S];
  733. u32 regChainOffset, regval;
  734. u8 txRxAttenLocal;
  735. int i, j, offset_num;
  736. pModal = &eep->modalHeader;
  737. antWrites[0] = (u16)((pModal->antCtrlCommon >> 28) & 0xF);
  738. antWrites[1] = (u16)((pModal->antCtrlCommon >> 24) & 0xF);
  739. antWrites[2] = (u16)((pModal->antCtrlCommon >> 20) & 0xF);
  740. antWrites[3] = (u16)((pModal->antCtrlCommon >> 16) & 0xF);
  741. antWrites[4] = (u16)((pModal->antCtrlCommon >> 12) & 0xF);
  742. antWrites[5] = (u16)((pModal->antCtrlCommon >> 8) & 0xF);
  743. antWrites[6] = (u16)((pModal->antCtrlCommon >> 4) & 0xF);
  744. antWrites[7] = (u16)(pModal->antCtrlCommon & 0xF);
  745. offset_num = 8;
  746. for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) {
  747. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 28) & 0xf);
  748. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 10) & 0x3);
  749. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 8) & 0x3);
  750. antWrites[j++] = 0;
  751. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 6) & 0x3);
  752. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 4) & 0x3);
  753. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 2) & 0x3);
  754. antWrites[j++] = (u16)(pModal->antCtrlChain[i] & 0x3);
  755. }
  756. REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
  757. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  758. regChainOffset = i * 0x1000;
  759. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  760. pModal->antCtrlChain[i]);
  761. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  762. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
  763. & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  764. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  765. SM(pModal->iqCalICh[i],
  766. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  767. SM(pModal->iqCalQCh[i],
  768. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  769. txRxAttenLocal = pModal->txRxAttenCh[i];
  770. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  771. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  772. pModal->bswMargin[i]);
  773. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  774. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  775. pModal->bswAtten[i]);
  776. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  777. AR9280_PHY_RXGAIN_TXRX_ATTEN,
  778. txRxAttenLocal);
  779. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  780. AR9280_PHY_RXGAIN_TXRX_MARGIN,
  781. pModal->rxTxMarginCh[i]);
  782. }
  783. if (IS_CHAN_HT40(chan))
  784. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  785. AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
  786. else
  787. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  788. AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
  789. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  790. AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
  791. REG_WRITE(ah, AR_PHY_RF_CTL4,
  792. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  793. | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  794. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  795. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  796. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
  797. AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
  798. REG_RMW_FIELD(ah, AR_PHY_CCA,
  799. AR9280_PHY_CCA_THRESH62, pModal->thresh62);
  800. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  801. AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
  802. regval = REG_READ(ah, AR9287_AN_RF2G3_CH0);
  803. regval &= ~(AR9287_AN_RF2G3_DB1 |
  804. AR9287_AN_RF2G3_DB2 |
  805. AR9287_AN_RF2G3_OB_CCK |
  806. AR9287_AN_RF2G3_OB_PSK |
  807. AR9287_AN_RF2G3_OB_QAM |
  808. AR9287_AN_RF2G3_OB_PAL_OFF);
  809. regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
  810. SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
  811. SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
  812. SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
  813. SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
  814. SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
  815. ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH0, regval);
  816. regval = REG_READ(ah, AR9287_AN_RF2G3_CH1);
  817. regval &= ~(AR9287_AN_RF2G3_DB1 |
  818. AR9287_AN_RF2G3_DB2 |
  819. AR9287_AN_RF2G3_OB_CCK |
  820. AR9287_AN_RF2G3_OB_PSK |
  821. AR9287_AN_RF2G3_OB_QAM |
  822. AR9287_AN_RF2G3_OB_PAL_OFF);
  823. regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
  824. SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
  825. SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
  826. SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
  827. SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
  828. SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
  829. ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH1, regval);
  830. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  831. AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
  832. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  833. AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
  834. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
  835. AR9287_AN_TOP2_XPABIAS_LVL,
  836. AR9287_AN_TOP2_XPABIAS_LVL_S,
  837. pModal->xpaBiasLvl);
  838. }
  839. static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
  840. u16 i, bool is2GHz)
  841. {
  842. #define EEP_MAP9287_SPURCHAN \
  843. (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan)
  844. struct ath_common *common = ath9k_hw_common(ah);
  845. u16 spur_val = AR_NO_SPUR;
  846. ath_dbg(common, ATH_DBG_ANI,
  847. "Getting spur idx:%d is2Ghz:%d val:%x\n",
  848. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  849. switch (ah->config.spurmode) {
  850. case SPUR_DISABLE:
  851. break;
  852. case SPUR_ENABLE_IOCTL:
  853. spur_val = ah->config.spurchans[i][is2GHz];
  854. ath_dbg(common, ATH_DBG_ANI,
  855. "Getting spur val from new loc. %d\n", spur_val);
  856. break;
  857. case SPUR_ENABLE_EEPROM:
  858. spur_val = EEP_MAP9287_SPURCHAN;
  859. break;
  860. }
  861. return spur_val;
  862. #undef EEP_MAP9287_SPURCHAN
  863. }
  864. const struct eeprom_ops eep_ar9287_ops = {
  865. .check_eeprom = ath9k_hw_ar9287_check_eeprom,
  866. .get_eeprom = ath9k_hw_ar9287_get_eeprom,
  867. .fill_eeprom = ath9k_hw_ar9287_fill_eeprom,
  868. .get_eeprom_ver = ath9k_hw_ar9287_get_eeprom_ver,
  869. .get_eeprom_rev = ath9k_hw_ar9287_get_eeprom_rev,
  870. .set_board_values = ath9k_hw_ar9287_set_board_values,
  871. .set_addac = ath9k_hw_ar9287_set_addac,
  872. .set_txpower = ath9k_hw_ar9287_set_txpower,
  873. .get_spur_channel = ath9k_hw_ar9287_get_spur_channel
  874. };