eeprom_9287.c 31 KB

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