eeprom_9287.c 32 KB

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