eeprom_def.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  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. static void ath9k_get_txgain_index(struct ath_hw *ah,
  20. struct ath9k_channel *chan,
  21. struct calDataPerFreqOpLoop *rawDatasetOpLoop,
  22. u8 *calChans, u16 availPiers, u8 *pwr, u8 *pcdacIdx)
  23. {
  24. u8 pcdac, i = 0;
  25. u16 idxL = 0, idxR = 0, numPiers;
  26. bool match;
  27. struct chan_centers centers;
  28. ath9k_hw_get_channel_centers(ah, chan, &centers);
  29. for (numPiers = 0; numPiers < availPiers; numPiers++)
  30. if (calChans[numPiers] == AR5416_BCHAN_UNUSED)
  31. break;
  32. match = ath9k_hw_get_lower_upper_index(
  33. (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
  34. calChans, numPiers, &idxL, &idxR);
  35. if (match) {
  36. pcdac = rawDatasetOpLoop[idxL].pcdac[0][0];
  37. *pwr = rawDatasetOpLoop[idxL].pwrPdg[0][0];
  38. } else {
  39. pcdac = rawDatasetOpLoop[idxR].pcdac[0][0];
  40. *pwr = (rawDatasetOpLoop[idxL].pwrPdg[0][0] +
  41. rawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
  42. }
  43. while (pcdac > ah->originalGain[i] &&
  44. i < (AR9280_TX_GAIN_TABLE_SIZE - 1))
  45. i++;
  46. *pcdacIdx = i;
  47. }
  48. static void ath9k_olc_get_pdadcs(struct ath_hw *ah,
  49. u32 initTxGain,
  50. int txPower,
  51. u8 *pPDADCValues)
  52. {
  53. u32 i;
  54. u32 offset;
  55. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_0,
  56. AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3);
  57. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_1,
  58. AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3);
  59. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL7,
  60. AR_PHY_TX_PWRCTRL_INIT_TX_GAIN, initTxGain);
  61. offset = txPower;
  62. for (i = 0; i < AR5416_NUM_PDADC_VALUES; i++)
  63. if (i < offset)
  64. pPDADCValues[i] = 0x0;
  65. else
  66. pPDADCValues[i] = 0xFF;
  67. }
  68. static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
  69. {
  70. return ((ah->eeprom.def.baseEepHeader.version >> 12) & 0xF);
  71. }
  72. static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
  73. {
  74. return ((ah->eeprom.def.baseEepHeader.version) & 0xFFF);
  75. }
  76. #define SIZE_EEPROM_DEF (sizeof(struct ar5416_eeprom_def) / sizeof(u16))
  77. static bool __ath9k_hw_def_fill_eeprom(struct ath_hw *ah)
  78. {
  79. u16 *eep_data = (u16 *)&ah->eeprom.def;
  80. int addr, ar5416_eep_start_loc = 0x100;
  81. for (addr = 0; addr < SIZE_EEPROM_DEF; addr++) {
  82. if (!ath9k_hw_nvram_read(ah, addr + ar5416_eep_start_loc,
  83. eep_data))
  84. return false;
  85. eep_data++;
  86. }
  87. return true;
  88. }
  89. static bool __ath9k_hw_usb_def_fill_eeprom(struct ath_hw *ah)
  90. {
  91. u16 *eep_data = (u16 *)&ah->eeprom.def;
  92. ath9k_hw_usb_gen_fill_eeprom(ah, eep_data,
  93. 0x100, SIZE_EEPROM_DEF);
  94. return true;
  95. }
  96. static bool ath9k_hw_def_fill_eeprom(struct ath_hw *ah)
  97. {
  98. struct ath_common *common = ath9k_hw_common(ah);
  99. if (!ath9k_hw_use_flash(ah)) {
  100. ath_dbg(common, EEPROM, "Reading from EEPROM, not flash\n");
  101. }
  102. if (common->bus_ops->ath_bus_type == ATH_USB)
  103. return __ath9k_hw_usb_def_fill_eeprom(ah);
  104. else
  105. return __ath9k_hw_def_fill_eeprom(ah);
  106. }
  107. #undef SIZE_EEPROM_DEF
  108. #if defined(CONFIG_ATH9K_DEBUGFS) || defined(CONFIG_ATH9K_HTC_DEBUGFS)
  109. static u32 ath9k_def_dump_modal_eeprom(char *buf, u32 len, u32 size,
  110. struct modal_eep_header *modal_hdr)
  111. {
  112. PR_EEP("Chain0 Ant. Control", modal_hdr->antCtrlChain[0]);
  113. PR_EEP("Chain1 Ant. Control", modal_hdr->antCtrlChain[1]);
  114. PR_EEP("Chain2 Ant. Control", modal_hdr->antCtrlChain[2]);
  115. PR_EEP("Ant. Common Control", modal_hdr->antCtrlCommon);
  116. PR_EEP("Chain0 Ant. Gain", modal_hdr->antennaGainCh[0]);
  117. PR_EEP("Chain1 Ant. Gain", modal_hdr->antennaGainCh[1]);
  118. PR_EEP("Chain2 Ant. Gain", modal_hdr->antennaGainCh[2]);
  119. PR_EEP("Switch Settle", modal_hdr->switchSettling);
  120. PR_EEP("Chain0 TxRxAtten", modal_hdr->txRxAttenCh[0]);
  121. PR_EEP("Chain1 TxRxAtten", modal_hdr->txRxAttenCh[1]);
  122. PR_EEP("Chain2 TxRxAtten", modal_hdr->txRxAttenCh[2]);
  123. PR_EEP("Chain0 RxTxMargin", modal_hdr->rxTxMarginCh[0]);
  124. PR_EEP("Chain1 RxTxMargin", modal_hdr->rxTxMarginCh[1]);
  125. PR_EEP("Chain2 RxTxMargin", modal_hdr->rxTxMarginCh[2]);
  126. PR_EEP("ADC Desired size", modal_hdr->adcDesiredSize);
  127. PR_EEP("PGA Desired size", modal_hdr->pgaDesiredSize);
  128. PR_EEP("Chain0 xlna Gain", modal_hdr->xlnaGainCh[0]);
  129. PR_EEP("Chain1 xlna Gain", modal_hdr->xlnaGainCh[1]);
  130. PR_EEP("Chain2 xlna Gain", modal_hdr->xlnaGainCh[2]);
  131. PR_EEP("txEndToXpaOff", modal_hdr->txEndToXpaOff);
  132. PR_EEP("txEndToRxOn", modal_hdr->txEndToRxOn);
  133. PR_EEP("txFrameToXpaOn", modal_hdr->txFrameToXpaOn);
  134. PR_EEP("CCA Threshold)", modal_hdr->thresh62);
  135. PR_EEP("Chain0 NF Threshold", modal_hdr->noiseFloorThreshCh[0]);
  136. PR_EEP("Chain1 NF Threshold", modal_hdr->noiseFloorThreshCh[1]);
  137. PR_EEP("Chain2 NF Threshold", modal_hdr->noiseFloorThreshCh[2]);
  138. PR_EEP("xpdGain", modal_hdr->xpdGain);
  139. PR_EEP("External PD", modal_hdr->xpd);
  140. PR_EEP("Chain0 I Coefficient", modal_hdr->iqCalICh[0]);
  141. PR_EEP("Chain1 I Coefficient", modal_hdr->iqCalICh[1]);
  142. PR_EEP("Chain2 I Coefficient", modal_hdr->iqCalICh[2]);
  143. PR_EEP("Chain0 Q Coefficient", modal_hdr->iqCalQCh[0]);
  144. PR_EEP("Chain1 Q Coefficient", modal_hdr->iqCalQCh[1]);
  145. PR_EEP("Chain2 Q Coefficient", modal_hdr->iqCalQCh[2]);
  146. PR_EEP("pdGainOverlap", modal_hdr->pdGainOverlap);
  147. PR_EEP("Chain0 OutputBias", modal_hdr->ob);
  148. PR_EEP("Chain0 DriverBias", modal_hdr->db);
  149. PR_EEP("xPA Bias Level", modal_hdr->xpaBiasLvl);
  150. PR_EEP("2chain pwr decrease", modal_hdr->pwrDecreaseFor2Chain);
  151. PR_EEP("3chain pwr decrease", modal_hdr->pwrDecreaseFor3Chain);
  152. PR_EEP("txFrameToDataStart", modal_hdr->txFrameToDataStart);
  153. PR_EEP("txFrameToPaOn", modal_hdr->txFrameToPaOn);
  154. PR_EEP("HT40 Power Inc.", modal_hdr->ht40PowerIncForPdadc);
  155. PR_EEP("Chain0 bswAtten", modal_hdr->bswAtten[0]);
  156. PR_EEP("Chain1 bswAtten", modal_hdr->bswAtten[1]);
  157. PR_EEP("Chain2 bswAtten", modal_hdr->bswAtten[2]);
  158. PR_EEP("Chain0 bswMargin", modal_hdr->bswMargin[0]);
  159. PR_EEP("Chain1 bswMargin", modal_hdr->bswMargin[1]);
  160. PR_EEP("Chain2 bswMargin", modal_hdr->bswMargin[2]);
  161. PR_EEP("HT40 Switch Settle", modal_hdr->swSettleHt40);
  162. PR_EEP("Chain0 xatten2Db", modal_hdr->xatten2Db[0]);
  163. PR_EEP("Chain1 xatten2Db", modal_hdr->xatten2Db[1]);
  164. PR_EEP("Chain2 xatten2Db", modal_hdr->xatten2Db[2]);
  165. PR_EEP("Chain0 xatten2Margin", modal_hdr->xatten2Margin[0]);
  166. PR_EEP("Chain1 xatten2Margin", modal_hdr->xatten2Margin[1]);
  167. PR_EEP("Chain2 xatten2Margin", modal_hdr->xatten2Margin[2]);
  168. PR_EEP("Chain1 OutputBias", modal_hdr->ob_ch1);
  169. PR_EEP("Chain1 DriverBias", modal_hdr->db_ch1);
  170. PR_EEP("LNA Control", modal_hdr->lna_ctl);
  171. PR_EEP("XPA Bias Freq0", modal_hdr->xpaBiasLvlFreq[0]);
  172. PR_EEP("XPA Bias Freq1", modal_hdr->xpaBiasLvlFreq[1]);
  173. PR_EEP("XPA Bias Freq2", modal_hdr->xpaBiasLvlFreq[2]);
  174. return len;
  175. }
  176. static u32 ath9k_hw_def_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
  177. u8 *buf, u32 len, u32 size)
  178. {
  179. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  180. struct base_eep_header *pBase = &eep->baseEepHeader;
  181. if (!dump_base_hdr) {
  182. len += scnprintf(buf + len, size - len,
  183. "%20s :\n", "2GHz modal Header");
  184. len = ath9k_def_dump_modal_eeprom(buf, len, size,
  185. &eep->modalHeader[0]);
  186. len += scnprintf(buf + len, size - len,
  187. "%20s :\n", "5GHz modal Header");
  188. len = ath9k_def_dump_modal_eeprom(buf, len, size,
  189. &eep->modalHeader[1]);
  190. goto out;
  191. }
  192. PR_EEP("Major Version", pBase->version >> 12);
  193. PR_EEP("Minor Version", pBase->version & 0xFFF);
  194. PR_EEP("Checksum", pBase->checksum);
  195. PR_EEP("Length", pBase->length);
  196. PR_EEP("RegDomain1", pBase->regDmn[0]);
  197. PR_EEP("RegDomain2", pBase->regDmn[1]);
  198. PR_EEP("TX Mask", pBase->txMask);
  199. PR_EEP("RX Mask", pBase->rxMask);
  200. PR_EEP("Allow 5GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11A));
  201. PR_EEP("Allow 2GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11G));
  202. PR_EEP("Disable 2GHz HT20", !!(pBase->opCapFlags &
  203. AR5416_OPFLAGS_N_2G_HT20));
  204. PR_EEP("Disable 2GHz HT40", !!(pBase->opCapFlags &
  205. AR5416_OPFLAGS_N_2G_HT40));
  206. PR_EEP("Disable 5Ghz HT20", !!(pBase->opCapFlags &
  207. AR5416_OPFLAGS_N_5G_HT20));
  208. PR_EEP("Disable 5Ghz HT40", !!(pBase->opCapFlags &
  209. AR5416_OPFLAGS_N_5G_HT40));
  210. PR_EEP("Big Endian", !!(pBase->eepMisc & 0x01));
  211. PR_EEP("Cal Bin Major Ver", (pBase->binBuildNumber >> 24) & 0xFF);
  212. PR_EEP("Cal Bin Minor Ver", (pBase->binBuildNumber >> 16) & 0xFF);
  213. PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF);
  214. PR_EEP("OpenLoop Power Ctrl", pBase->openLoopPwrCntl);
  215. len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
  216. pBase->macAddr);
  217. out:
  218. if (len > size)
  219. len = size;
  220. return len;
  221. }
  222. #else
  223. static u32 ath9k_hw_def_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
  224. u8 *buf, u32 len, u32 size)
  225. {
  226. return 0;
  227. }
  228. #endif
  229. static int ath9k_hw_def_check_eeprom(struct ath_hw *ah)
  230. {
  231. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  232. struct ath_common *common = ath9k_hw_common(ah);
  233. u16 *eepdata, temp, magic;
  234. u32 sum = 0, el;
  235. bool need_swap = false;
  236. int i, addr, size;
  237. if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
  238. ath_err(common, "Reading Magic # failed\n");
  239. return false;
  240. }
  241. if (swab16(magic) == AR5416_EEPROM_MAGIC &&
  242. !(ah->ah_flags & AH_NO_EEP_SWAP)) {
  243. size = sizeof(struct ar5416_eeprom_def);
  244. need_swap = true;
  245. eepdata = (u16 *) (&ah->eeprom);
  246. for (addr = 0; addr < size / sizeof(u16); addr++) {
  247. temp = swab16(*eepdata);
  248. *eepdata = temp;
  249. eepdata++;
  250. }
  251. }
  252. ath_dbg(common, EEPROM, "need_swap = %s\n",
  253. need_swap ? "True" : "False");
  254. if (need_swap)
  255. el = swab16(ah->eeprom.def.baseEepHeader.length);
  256. else
  257. el = ah->eeprom.def.baseEepHeader.length;
  258. if (el > sizeof(struct ar5416_eeprom_def))
  259. el = sizeof(struct ar5416_eeprom_def) / sizeof(u16);
  260. else
  261. el = el / sizeof(u16);
  262. eepdata = (u16 *)(&ah->eeprom);
  263. for (i = 0; i < el; i++)
  264. sum ^= *eepdata++;
  265. if (need_swap) {
  266. u32 integer, j;
  267. u16 word;
  268. ath_dbg(common, EEPROM,
  269. "EEPROM Endianness is not native.. Changing.\n");
  270. word = swab16(eep->baseEepHeader.length);
  271. eep->baseEepHeader.length = word;
  272. word = swab16(eep->baseEepHeader.checksum);
  273. eep->baseEepHeader.checksum = word;
  274. word = swab16(eep->baseEepHeader.version);
  275. eep->baseEepHeader.version = word;
  276. word = swab16(eep->baseEepHeader.regDmn[0]);
  277. eep->baseEepHeader.regDmn[0] = word;
  278. word = swab16(eep->baseEepHeader.regDmn[1]);
  279. eep->baseEepHeader.regDmn[1] = word;
  280. word = swab16(eep->baseEepHeader.rfSilent);
  281. eep->baseEepHeader.rfSilent = word;
  282. word = swab16(eep->baseEepHeader.blueToothOptions);
  283. eep->baseEepHeader.blueToothOptions = word;
  284. word = swab16(eep->baseEepHeader.deviceCap);
  285. eep->baseEepHeader.deviceCap = word;
  286. for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
  287. struct modal_eep_header *pModal =
  288. &eep->modalHeader[j];
  289. integer = swab32(pModal->antCtrlCommon);
  290. pModal->antCtrlCommon = integer;
  291. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  292. integer = swab32(pModal->antCtrlChain[i]);
  293. pModal->antCtrlChain[i] = integer;
  294. }
  295. for (i = 0; i < 3; i++) {
  296. word = swab16(pModal->xpaBiasLvlFreq[i]);
  297. pModal->xpaBiasLvlFreq[i] = word;
  298. }
  299. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  300. word = swab16(pModal->spurChans[i].spurChan);
  301. pModal->spurChans[i].spurChan = word;
  302. }
  303. }
  304. }
  305. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
  306. ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  307. ath_err(common, "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  308. sum, ah->eep_ops->get_eeprom_ver(ah));
  309. return -EINVAL;
  310. }
  311. /* Enable fixup for AR_AN_TOP2 if necessary */
  312. if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
  313. ((eep->baseEepHeader.version & 0xff) > 0x0a) &&
  314. (eep->baseEepHeader.pwdclkind == 0))
  315. ah->need_an_top2_fixup = true;
  316. if ((common->bus_ops->ath_bus_type == ATH_USB) &&
  317. (AR_SREV_9280(ah)))
  318. eep->modalHeader[0].xpaBiasLvl = 0;
  319. return 0;
  320. }
  321. static u32 ath9k_hw_def_get_eeprom(struct ath_hw *ah,
  322. enum eeprom_param param)
  323. {
  324. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  325. struct modal_eep_header *pModal = eep->modalHeader;
  326. struct base_eep_header *pBase = &eep->baseEepHeader;
  327. int band = 0;
  328. switch (param) {
  329. case EEP_NFTHRESH_5:
  330. return pModal[0].noiseFloorThreshCh[0];
  331. case EEP_NFTHRESH_2:
  332. return pModal[1].noiseFloorThreshCh[0];
  333. case EEP_MAC_LSW:
  334. return get_unaligned_be16(pBase->macAddr);
  335. case EEP_MAC_MID:
  336. return get_unaligned_be16(pBase->macAddr + 2);
  337. case EEP_MAC_MSW:
  338. return get_unaligned_be16(pBase->macAddr + 4);
  339. case EEP_REG_0:
  340. return pBase->regDmn[0];
  341. case EEP_OP_CAP:
  342. return pBase->deviceCap;
  343. case EEP_OP_MODE:
  344. return pBase->opCapFlags;
  345. case EEP_RF_SILENT:
  346. return pBase->rfSilent;
  347. case EEP_OB_5:
  348. return pModal[0].ob;
  349. case EEP_DB_5:
  350. return pModal[0].db;
  351. case EEP_OB_2:
  352. return pModal[1].ob;
  353. case EEP_DB_2:
  354. return pModal[1].db;
  355. case EEP_MINOR_REV:
  356. return AR5416_VER_MASK;
  357. case EEP_TX_MASK:
  358. return pBase->txMask;
  359. case EEP_RX_MASK:
  360. return pBase->rxMask;
  361. case EEP_FSTCLK_5G:
  362. return pBase->fastClk5g;
  363. case EEP_RXGAIN_TYPE:
  364. return pBase->rxGainType;
  365. case EEP_TXGAIN_TYPE:
  366. return pBase->txGainType;
  367. case EEP_OL_PWRCTRL:
  368. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  369. return pBase->openLoopPwrCntl ? true : false;
  370. else
  371. return false;
  372. case EEP_RC_CHAIN_MASK:
  373. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  374. return pBase->rcChainMask;
  375. else
  376. return 0;
  377. case EEP_DAC_HPWR_5G:
  378. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
  379. return pBase->dacHiPwrMode_5G;
  380. else
  381. return 0;
  382. case EEP_FRAC_N_5G:
  383. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
  384. return pBase->frac_n_5g;
  385. else
  386. return 0;
  387. case EEP_PWR_TABLE_OFFSET:
  388. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_21)
  389. return pBase->pwr_table_offset;
  390. else
  391. return AR5416_PWR_TABLE_OFFSET_DB;
  392. case EEP_ANTENNA_GAIN_2G:
  393. band = 1;
  394. /* fall through */
  395. case EEP_ANTENNA_GAIN_5G:
  396. return max_t(u8, max_t(u8,
  397. pModal[band].antennaGainCh[0],
  398. pModal[band].antennaGainCh[1]),
  399. pModal[band].antennaGainCh[2]);
  400. default:
  401. return 0;
  402. }
  403. }
  404. static void ath9k_hw_def_set_gain(struct ath_hw *ah,
  405. struct modal_eep_header *pModal,
  406. struct ar5416_eeprom_def *eep,
  407. u8 txRxAttenLocal, int regChainOffset, int i)
  408. {
  409. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
  410. txRxAttenLocal = pModal->txRxAttenCh[i];
  411. if (AR_SREV_9280_20_OR_LATER(ah)) {
  412. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  413. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  414. pModal->bswMargin[i]);
  415. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  416. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  417. pModal->bswAtten[i]);
  418. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  419. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  420. pModal->xatten2Margin[i]);
  421. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  422. AR_PHY_GAIN_2GHZ_XATTEN2_DB,
  423. pModal->xatten2Db[i]);
  424. } else {
  425. REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  426. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  427. ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
  428. | SM(pModal-> bswMargin[i],
  429. AR_PHY_GAIN_2GHZ_BSW_MARGIN));
  430. REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  431. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  432. ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
  433. | SM(pModal->bswAtten[i],
  434. AR_PHY_GAIN_2GHZ_BSW_ATTEN));
  435. }
  436. }
  437. if (AR_SREV_9280_20_OR_LATER(ah)) {
  438. REG_RMW_FIELD(ah,
  439. AR_PHY_RXGAIN + regChainOffset,
  440. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  441. REG_RMW_FIELD(ah,
  442. AR_PHY_RXGAIN + regChainOffset,
  443. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[i]);
  444. } else {
  445. REG_WRITE(ah,
  446. AR_PHY_RXGAIN + regChainOffset,
  447. (REG_READ(ah, AR_PHY_RXGAIN + regChainOffset) &
  448. ~AR_PHY_RXGAIN_TXRX_ATTEN)
  449. | SM(txRxAttenLocal, AR_PHY_RXGAIN_TXRX_ATTEN));
  450. REG_WRITE(ah,
  451. AR_PHY_GAIN_2GHZ + regChainOffset,
  452. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  453. ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
  454. SM(pModal->rxTxMarginCh[i], AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
  455. }
  456. }
  457. static void ath9k_hw_def_set_board_values(struct ath_hw *ah,
  458. struct ath9k_channel *chan)
  459. {
  460. struct modal_eep_header *pModal;
  461. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  462. int i, regChainOffset;
  463. u8 txRxAttenLocal;
  464. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  465. txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
  466. REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon & 0xffff);
  467. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  468. if (AR_SREV_9280(ah)) {
  469. if (i >= 2)
  470. break;
  471. }
  472. if ((ah->rxchainmask == 5 || ah->txchainmask == 5) && (i != 0))
  473. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  474. else
  475. regChainOffset = i * 0x1000;
  476. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  477. pModal->antCtrlChain[i]);
  478. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  479. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
  480. ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  481. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  482. SM(pModal->iqCalICh[i],
  483. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  484. SM(pModal->iqCalQCh[i],
  485. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  486. ath9k_hw_def_set_gain(ah, pModal, eep, txRxAttenLocal,
  487. regChainOffset, i);
  488. }
  489. if (AR_SREV_9280_20_OR_LATER(ah)) {
  490. if (IS_CHAN_2GHZ(chan)) {
  491. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  492. AR_AN_RF2G1_CH0_OB,
  493. AR_AN_RF2G1_CH0_OB_S,
  494. pModal->ob);
  495. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  496. AR_AN_RF2G1_CH0_DB,
  497. AR_AN_RF2G1_CH0_DB_S,
  498. pModal->db);
  499. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  500. AR_AN_RF2G1_CH1_OB,
  501. AR_AN_RF2G1_CH1_OB_S,
  502. pModal->ob_ch1);
  503. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  504. AR_AN_RF2G1_CH1_DB,
  505. AR_AN_RF2G1_CH1_DB_S,
  506. pModal->db_ch1);
  507. } else {
  508. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  509. AR_AN_RF5G1_CH0_OB5,
  510. AR_AN_RF5G1_CH0_OB5_S,
  511. pModal->ob);
  512. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  513. AR_AN_RF5G1_CH0_DB5,
  514. AR_AN_RF5G1_CH0_DB5_S,
  515. pModal->db);
  516. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  517. AR_AN_RF5G1_CH1_OB5,
  518. AR_AN_RF5G1_CH1_OB5_S,
  519. pModal->ob_ch1);
  520. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  521. AR_AN_RF5G1_CH1_DB5,
  522. AR_AN_RF5G1_CH1_DB5_S,
  523. pModal->db_ch1);
  524. }
  525. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  526. AR_AN_TOP2_XPABIAS_LVL,
  527. AR_AN_TOP2_XPABIAS_LVL_S,
  528. pModal->xpaBiasLvl);
  529. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  530. AR_AN_TOP2_LOCALBIAS,
  531. AR_AN_TOP2_LOCALBIAS_S,
  532. !!(pModal->lna_ctl &
  533. LNA_CTL_LOCAL_BIAS));
  534. REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
  535. !!(pModal->lna_ctl & LNA_CTL_FORCE_XPA));
  536. }
  537. REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
  538. pModal->switchSettling);
  539. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
  540. pModal->adcDesiredSize);
  541. if (!AR_SREV_9280_20_OR_LATER(ah))
  542. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  543. AR_PHY_DESIRED_SZ_PGA,
  544. pModal->pgaDesiredSize);
  545. REG_WRITE(ah, AR_PHY_RF_CTL4,
  546. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  547. | SM(pModal->txEndToXpaOff,
  548. AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  549. | SM(pModal->txFrameToXpaOn,
  550. AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  551. | SM(pModal->txFrameToXpaOn,
  552. AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  553. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  554. pModal->txEndToRxOn);
  555. if (AR_SREV_9280_20_OR_LATER(ah)) {
  556. REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
  557. pModal->thresh62);
  558. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  559. AR_PHY_EXT_CCA0_THRESH62,
  560. pModal->thresh62);
  561. } else {
  562. REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
  563. pModal->thresh62);
  564. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  565. AR_PHY_EXT_CCA_THRESH62,
  566. pModal->thresh62);
  567. }
  568. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
  569. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  570. AR_PHY_TX_END_DATA_START,
  571. pModal->txFrameToDataStart);
  572. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
  573. pModal->txFrameToPaOn);
  574. }
  575. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
  576. if (IS_CHAN_HT40(chan))
  577. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  578. AR_PHY_SETTLING_SWITCH,
  579. pModal->swSettleHt40);
  580. }
  581. if (AR_SREV_9280_20_OR_LATER(ah) &&
  582. AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  583. REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL,
  584. AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK,
  585. pModal->miscBits);
  586. if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) {
  587. if (IS_CHAN_2GHZ(chan))
  588. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
  589. eep->baseEepHeader.dacLpMode);
  590. else if (eep->baseEepHeader.dacHiPwrMode_5G)
  591. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, 0);
  592. else
  593. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
  594. eep->baseEepHeader.dacLpMode);
  595. udelay(100);
  596. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, AR_PHY_FRAME_CTL_TX_CLIP,
  597. pModal->miscBits >> 2);
  598. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL9,
  599. AR_PHY_TX_DESIRED_SCALE_CCK,
  600. eep->baseEepHeader.desiredScaleCCK);
  601. }
  602. }
  603. static void ath9k_hw_def_set_addac(struct ath_hw *ah,
  604. struct ath9k_channel *chan)
  605. {
  606. #define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt])
  607. struct modal_eep_header *pModal;
  608. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  609. u8 biaslevel;
  610. if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
  611. return;
  612. if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
  613. return;
  614. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  615. if (pModal->xpaBiasLvl != 0xff) {
  616. biaslevel = pModal->xpaBiasLvl;
  617. } else {
  618. u16 resetFreqBin, freqBin, freqCount = 0;
  619. struct chan_centers centers;
  620. ath9k_hw_get_channel_centers(ah, chan, &centers);
  621. resetFreqBin = FREQ2FBIN(centers.synth_center,
  622. IS_CHAN_2GHZ(chan));
  623. freqBin = XPA_LVL_FREQ(0) & 0xff;
  624. biaslevel = (u8) (XPA_LVL_FREQ(0) >> 14);
  625. freqCount++;
  626. while (freqCount < 3) {
  627. if (XPA_LVL_FREQ(freqCount) == 0x0)
  628. break;
  629. freqBin = XPA_LVL_FREQ(freqCount) & 0xff;
  630. if (resetFreqBin >= freqBin)
  631. biaslevel = (u8)(XPA_LVL_FREQ(freqCount) >> 14);
  632. else
  633. break;
  634. freqCount++;
  635. }
  636. }
  637. if (IS_CHAN_2GHZ(chan)) {
  638. INI_RA(&ah->iniAddac, 7, 1) = (INI_RA(&ah->iniAddac,
  639. 7, 1) & (~0x18)) | biaslevel << 3;
  640. } else {
  641. INI_RA(&ah->iniAddac, 6, 1) = (INI_RA(&ah->iniAddac,
  642. 6, 1) & (~0xc0)) | biaslevel << 6;
  643. }
  644. #undef XPA_LVL_FREQ
  645. }
  646. static int16_t ath9k_change_gain_boundary_setting(struct ath_hw *ah,
  647. u16 *gb,
  648. u16 numXpdGain,
  649. u16 pdGainOverlap_t2,
  650. int8_t pwr_table_offset,
  651. int16_t *diff)
  652. {
  653. u16 k;
  654. /* Prior to writing the boundaries or the pdadc vs. power table
  655. * into the chip registers the default starting point on the pdadc
  656. * vs. power table needs to be checked and the curve boundaries
  657. * adjusted accordingly
  658. */
  659. if (AR_SREV_9280_20_OR_LATER(ah)) {
  660. u16 gb_limit;
  661. if (AR5416_PWR_TABLE_OFFSET_DB != pwr_table_offset) {
  662. /* get the difference in dB */
  663. *diff = (u16)(pwr_table_offset - AR5416_PWR_TABLE_OFFSET_DB);
  664. /* get the number of half dB steps */
  665. *diff *= 2;
  666. /* change the original gain boundary settings
  667. * by the number of half dB steps
  668. */
  669. for (k = 0; k < numXpdGain; k++)
  670. gb[k] = (u16)(gb[k] - *diff);
  671. }
  672. /* Because of a hardware limitation, ensure the gain boundary
  673. * is not larger than (63 - overlap)
  674. */
  675. gb_limit = (u16)(MAX_RATE_POWER - pdGainOverlap_t2);
  676. for (k = 0; k < numXpdGain; k++)
  677. gb[k] = (u16)min(gb_limit, gb[k]);
  678. }
  679. return *diff;
  680. }
  681. static void ath9k_adjust_pdadc_values(struct ath_hw *ah,
  682. int8_t pwr_table_offset,
  683. int16_t diff,
  684. u8 *pdadcValues)
  685. {
  686. #define NUM_PDADC(diff) (AR5416_NUM_PDADC_VALUES - diff)
  687. u16 k;
  688. /* If this is a board that has a pwrTableOffset that differs from
  689. * the default AR5416_PWR_TABLE_OFFSET_DB then the start of the
  690. * pdadc vs pwr table needs to be adjusted prior to writing to the
  691. * chip.
  692. */
  693. if (AR_SREV_9280_20_OR_LATER(ah)) {
  694. if (AR5416_PWR_TABLE_OFFSET_DB != pwr_table_offset) {
  695. /* shift the table to start at the new offset */
  696. for (k = 0; k < (u16)NUM_PDADC(diff); k++ ) {
  697. pdadcValues[k] = pdadcValues[k + diff];
  698. }
  699. /* fill the back of the table */
  700. for (k = (u16)NUM_PDADC(diff); k < NUM_PDADC(0); k++) {
  701. pdadcValues[k] = pdadcValues[NUM_PDADC(diff)];
  702. }
  703. }
  704. }
  705. #undef NUM_PDADC
  706. }
  707. static void ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
  708. struct ath9k_channel *chan)
  709. {
  710. #define SM_PD_GAIN(x) SM(0x38, AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##x)
  711. #define SM_PDGAIN_B(x, y) \
  712. SM((gainBoundaries[x]), AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##y)
  713. struct ath_common *common = ath9k_hw_common(ah);
  714. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  715. struct cal_data_per_freq *pRawDataset;
  716. u8 *pCalBChans = NULL;
  717. u16 pdGainOverlap_t2;
  718. static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
  719. u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
  720. u16 numPiers, i, j;
  721. int16_t diff = 0;
  722. u16 numXpdGain, xpdMask;
  723. u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
  724. u32 reg32, regOffset, regChainOffset;
  725. int16_t modalIdx;
  726. int8_t pwr_table_offset;
  727. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  728. xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
  729. pwr_table_offset = ah->eep_ops->get_eeprom(ah, EEP_PWR_TABLE_OFFSET);
  730. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  731. AR5416_EEP_MINOR_VER_2) {
  732. pdGainOverlap_t2 =
  733. pEepData->modalHeader[modalIdx].pdGainOverlap;
  734. } else {
  735. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  736. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  737. }
  738. if (IS_CHAN_2GHZ(chan)) {
  739. pCalBChans = pEepData->calFreqPier2G;
  740. numPiers = AR5416_NUM_2G_CAL_PIERS;
  741. } else {
  742. pCalBChans = pEepData->calFreqPier5G;
  743. numPiers = AR5416_NUM_5G_CAL_PIERS;
  744. }
  745. if (OLC_FOR_AR9280_20_LATER && IS_CHAN_2GHZ(chan)) {
  746. pRawDataset = pEepData->calPierData2G[0];
  747. ah->initPDADC = ((struct calDataPerFreqOpLoop *)
  748. pRawDataset)->vpdPdg[0][0];
  749. }
  750. numXpdGain = 0;
  751. for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
  752. if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
  753. if (numXpdGain >= AR5416_NUM_PD_GAINS)
  754. break;
  755. xpdGainValues[numXpdGain] =
  756. (u16)(AR5416_PD_GAINS_IN_MASK - i);
  757. numXpdGain++;
  758. }
  759. }
  760. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  761. (numXpdGain - 1) & 0x3);
  762. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  763. xpdGainValues[0]);
  764. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  765. xpdGainValues[1]);
  766. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  767. xpdGainValues[2]);
  768. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  769. if ((ah->rxchainmask == 5 || ah->txchainmask == 5) &&
  770. (i != 0)) {
  771. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  772. } else
  773. regChainOffset = i * 0x1000;
  774. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  775. if (IS_CHAN_2GHZ(chan))
  776. pRawDataset = pEepData->calPierData2G[i];
  777. else
  778. pRawDataset = pEepData->calPierData5G[i];
  779. if (OLC_FOR_AR9280_20_LATER) {
  780. u8 pcdacIdx;
  781. u8 txPower;
  782. ath9k_get_txgain_index(ah, chan,
  783. (struct calDataPerFreqOpLoop *)pRawDataset,
  784. pCalBChans, numPiers, &txPower, &pcdacIdx);
  785. ath9k_olc_get_pdadcs(ah, pcdacIdx,
  786. txPower/2, pdadcValues);
  787. } else {
  788. ath9k_hw_get_gain_boundaries_pdadcs(ah,
  789. chan, pRawDataset,
  790. pCalBChans, numPiers,
  791. pdGainOverlap_t2,
  792. gainBoundaries,
  793. pdadcValues,
  794. numXpdGain);
  795. }
  796. diff = ath9k_change_gain_boundary_setting(ah,
  797. gainBoundaries,
  798. numXpdGain,
  799. pdGainOverlap_t2,
  800. pwr_table_offset,
  801. &diff);
  802. ENABLE_REGWRITE_BUFFER(ah);
  803. if (OLC_FOR_AR9280_20_LATER) {
  804. REG_WRITE(ah,
  805. AR_PHY_TPCRG5 + regChainOffset,
  806. SM(0x6,
  807. AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
  808. SM_PD_GAIN(1) | SM_PD_GAIN(2) |
  809. SM_PD_GAIN(3) | SM_PD_GAIN(4));
  810. } else {
  811. REG_WRITE(ah,
  812. AR_PHY_TPCRG5 + regChainOffset,
  813. SM(pdGainOverlap_t2,
  814. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)|
  815. SM_PDGAIN_B(0, 1) |
  816. SM_PDGAIN_B(1, 2) |
  817. SM_PDGAIN_B(2, 3) |
  818. SM_PDGAIN_B(3, 4));
  819. }
  820. ath9k_adjust_pdadc_values(ah, pwr_table_offset,
  821. diff, pdadcValues);
  822. regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
  823. for (j = 0; j < 32; j++) {
  824. reg32 = get_unaligned_le32(&pdadcValues[4 * j]);
  825. REG_WRITE(ah, regOffset, reg32);
  826. ath_dbg(common, EEPROM,
  827. "PDADC (%d,%4x): %4.4x %8.8x\n",
  828. i, regChainOffset, regOffset,
  829. reg32);
  830. ath_dbg(common, EEPROM,
  831. "PDADC: Chain %d | PDADC %3d Value %3d | PDADC %3d Value %3d | PDADC %3d Value %3d | PDADC %3d Value %3d |\n",
  832. i, 4 * j, pdadcValues[4 * j],
  833. 4 * j + 1, pdadcValues[4 * j + 1],
  834. 4 * j + 2, pdadcValues[4 * j + 2],
  835. 4 * j + 3, pdadcValues[4 * j + 3]);
  836. regOffset += 4;
  837. }
  838. REGWRITE_BUFFER_FLUSH(ah);
  839. }
  840. }
  841. #undef SM_PD_GAIN
  842. #undef SM_PDGAIN_B
  843. }
  844. static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
  845. struct ath9k_channel *chan,
  846. int16_t *ratesArray,
  847. u16 cfgCtl,
  848. u16 antenna_reduction,
  849. u16 powerLimit)
  850. {
  851. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  852. u16 twiceMaxEdgePower;
  853. int i;
  854. struct cal_ctl_data *rep;
  855. struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
  856. 0, { 0, 0, 0, 0}
  857. };
  858. struct cal_target_power_leg targetPowerOfdmExt = {
  859. 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
  860. 0, { 0, 0, 0, 0 }
  861. };
  862. struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
  863. 0, {0, 0, 0, 0}
  864. };
  865. u16 scaledPower = 0, minCtlPower;
  866. static const u16 ctlModesFor11a[] = {
  867. CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40
  868. };
  869. static const u16 ctlModesFor11g[] = {
  870. CTL_11B, CTL_11G, CTL_2GHT20,
  871. CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
  872. };
  873. u16 numCtlModes;
  874. const u16 *pCtlMode;
  875. u16 ctlMode, freq;
  876. struct chan_centers centers;
  877. int tx_chainmask;
  878. u16 twiceMinEdgePower;
  879. tx_chainmask = ah->txchainmask;
  880. ath9k_hw_get_channel_centers(ah, chan, &centers);
  881. scaledPower = ath9k_hw_get_scaled_power(ah, powerLimit,
  882. antenna_reduction);
  883. if (IS_CHAN_2GHZ(chan)) {
  884. numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
  885. SUB_NUM_CTL_MODES_AT_2G_40;
  886. pCtlMode = ctlModesFor11g;
  887. ath9k_hw_get_legacy_target_powers(ah, chan,
  888. pEepData->calTargetPowerCck,
  889. AR5416_NUM_2G_CCK_TARGET_POWERS,
  890. &targetPowerCck, 4, false);
  891. ath9k_hw_get_legacy_target_powers(ah, chan,
  892. pEepData->calTargetPower2G,
  893. AR5416_NUM_2G_20_TARGET_POWERS,
  894. &targetPowerOfdm, 4, false);
  895. ath9k_hw_get_target_powers(ah, chan,
  896. pEepData->calTargetPower2GHT20,
  897. AR5416_NUM_2G_20_TARGET_POWERS,
  898. &targetPowerHt20, 8, false);
  899. if (IS_CHAN_HT40(chan)) {
  900. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  901. ath9k_hw_get_target_powers(ah, chan,
  902. pEepData->calTargetPower2GHT40,
  903. AR5416_NUM_2G_40_TARGET_POWERS,
  904. &targetPowerHt40, 8, true);
  905. ath9k_hw_get_legacy_target_powers(ah, chan,
  906. pEepData->calTargetPowerCck,
  907. AR5416_NUM_2G_CCK_TARGET_POWERS,
  908. &targetPowerCckExt, 4, true);
  909. ath9k_hw_get_legacy_target_powers(ah, chan,
  910. pEepData->calTargetPower2G,
  911. AR5416_NUM_2G_20_TARGET_POWERS,
  912. &targetPowerOfdmExt, 4, true);
  913. }
  914. } else {
  915. numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
  916. SUB_NUM_CTL_MODES_AT_5G_40;
  917. pCtlMode = ctlModesFor11a;
  918. ath9k_hw_get_legacy_target_powers(ah, chan,
  919. pEepData->calTargetPower5G,
  920. AR5416_NUM_5G_20_TARGET_POWERS,
  921. &targetPowerOfdm, 4, false);
  922. ath9k_hw_get_target_powers(ah, chan,
  923. pEepData->calTargetPower5GHT20,
  924. AR5416_NUM_5G_20_TARGET_POWERS,
  925. &targetPowerHt20, 8, false);
  926. if (IS_CHAN_HT40(chan)) {
  927. numCtlModes = ARRAY_SIZE(ctlModesFor11a);
  928. ath9k_hw_get_target_powers(ah, chan,
  929. pEepData->calTargetPower5GHT40,
  930. AR5416_NUM_5G_40_TARGET_POWERS,
  931. &targetPowerHt40, 8, true);
  932. ath9k_hw_get_legacy_target_powers(ah, chan,
  933. pEepData->calTargetPower5G,
  934. AR5416_NUM_5G_20_TARGET_POWERS,
  935. &targetPowerOfdmExt, 4, true);
  936. }
  937. }
  938. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  939. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  940. (pCtlMode[ctlMode] == CTL_2GHT40);
  941. if (isHt40CtlMode)
  942. freq = centers.synth_center;
  943. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  944. freq = centers.ext_center;
  945. else
  946. freq = centers.ctl_center;
  947. twiceMaxEdgePower = MAX_RATE_POWER;
  948. for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  949. if ((((cfgCtl & ~CTL_MODE_M) |
  950. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  951. pEepData->ctlIndex[i]) ||
  952. (((cfgCtl & ~CTL_MODE_M) |
  953. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  954. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
  955. rep = &(pEepData->ctlData[i]);
  956. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  957. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
  958. IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
  959. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  960. twiceMaxEdgePower = min(twiceMaxEdgePower,
  961. twiceMinEdgePower);
  962. } else {
  963. twiceMaxEdgePower = twiceMinEdgePower;
  964. break;
  965. }
  966. }
  967. }
  968. minCtlPower = min(twiceMaxEdgePower, scaledPower);
  969. switch (pCtlMode[ctlMode]) {
  970. case CTL_11B:
  971. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  972. targetPowerCck.tPow2x[i] =
  973. min((u16)targetPowerCck.tPow2x[i],
  974. minCtlPower);
  975. }
  976. break;
  977. case CTL_11A:
  978. case CTL_11G:
  979. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  980. targetPowerOfdm.tPow2x[i] =
  981. min((u16)targetPowerOfdm.tPow2x[i],
  982. minCtlPower);
  983. }
  984. break;
  985. case CTL_5GHT20:
  986. case CTL_2GHT20:
  987. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  988. targetPowerHt20.tPow2x[i] =
  989. min((u16)targetPowerHt20.tPow2x[i],
  990. minCtlPower);
  991. }
  992. break;
  993. case CTL_11B_EXT:
  994. targetPowerCckExt.tPow2x[0] = min((u16)
  995. targetPowerCckExt.tPow2x[0],
  996. minCtlPower);
  997. break;
  998. case CTL_11A_EXT:
  999. case CTL_11G_EXT:
  1000. targetPowerOfdmExt.tPow2x[0] = min((u16)
  1001. targetPowerOfdmExt.tPow2x[0],
  1002. minCtlPower);
  1003. break;
  1004. case CTL_5GHT40:
  1005. case CTL_2GHT40:
  1006. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  1007. targetPowerHt40.tPow2x[i] =
  1008. min((u16)targetPowerHt40.tPow2x[i],
  1009. minCtlPower);
  1010. }
  1011. break;
  1012. default:
  1013. break;
  1014. }
  1015. }
  1016. ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
  1017. ratesArray[rate18mb] = ratesArray[rate24mb] =
  1018. targetPowerOfdm.tPow2x[0];
  1019. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  1020. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  1021. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  1022. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  1023. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  1024. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  1025. if (IS_CHAN_2GHZ(chan)) {
  1026. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  1027. ratesArray[rate2s] = ratesArray[rate2l] =
  1028. targetPowerCck.tPow2x[1];
  1029. ratesArray[rate5_5s] = ratesArray[rate5_5l] =
  1030. targetPowerCck.tPow2x[2];
  1031. ratesArray[rate11s] = ratesArray[rate11l] =
  1032. targetPowerCck.tPow2x[3];
  1033. }
  1034. if (IS_CHAN_HT40(chan)) {
  1035. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  1036. ratesArray[rateHt40_0 + i] =
  1037. targetPowerHt40.tPow2x[i];
  1038. }
  1039. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  1040. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  1041. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  1042. if (IS_CHAN_2GHZ(chan)) {
  1043. ratesArray[rateExtCck] =
  1044. targetPowerCckExt.tPow2x[0];
  1045. }
  1046. }
  1047. }
  1048. static void ath9k_hw_def_set_txpower(struct ath_hw *ah,
  1049. struct ath9k_channel *chan,
  1050. u16 cfgCtl,
  1051. u8 twiceAntennaReduction,
  1052. u8 powerLimit, bool test)
  1053. {
  1054. #define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
  1055. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1056. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  1057. struct modal_eep_header *pModal =
  1058. &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
  1059. int16_t ratesArray[Ar5416RateSize];
  1060. u8 ht40PowerIncForPdadc = 2;
  1061. int i, cck_ofdm_delta = 0;
  1062. memset(ratesArray, 0, sizeof(ratesArray));
  1063. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1064. AR5416_EEP_MINOR_VER_2) {
  1065. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  1066. }
  1067. ath9k_hw_set_def_power_per_rate_table(ah, chan,
  1068. &ratesArray[0], cfgCtl,
  1069. twiceAntennaReduction,
  1070. powerLimit);
  1071. ath9k_hw_set_def_power_cal_table(ah, chan);
  1072. regulatory->max_power_level = 0;
  1073. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  1074. if (ratesArray[i] > MAX_RATE_POWER)
  1075. ratesArray[i] = MAX_RATE_POWER;
  1076. if (ratesArray[i] > regulatory->max_power_level)
  1077. regulatory->max_power_level = ratesArray[i];
  1078. }
  1079. ath9k_hw_update_regulatory_maxpower(ah);
  1080. if (test)
  1081. return;
  1082. if (AR_SREV_9280_20_OR_LATER(ah)) {
  1083. for (i = 0; i < Ar5416RateSize; i++) {
  1084. int8_t pwr_table_offset;
  1085. pwr_table_offset = ah->eep_ops->get_eeprom(ah,
  1086. EEP_PWR_TABLE_OFFSET);
  1087. ratesArray[i] -= pwr_table_offset * 2;
  1088. }
  1089. }
  1090. ENABLE_REGWRITE_BUFFER(ah);
  1091. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  1092. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  1093. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  1094. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  1095. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  1096. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  1097. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  1098. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  1099. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  1100. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  1101. if (IS_CHAN_2GHZ(chan)) {
  1102. if (OLC_FOR_AR9280_20_LATER) {
  1103. cck_ofdm_delta = 2;
  1104. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  1105. ATH9K_POW_SM(RT_AR_DELTA(rate2s), 24)
  1106. | ATH9K_POW_SM(RT_AR_DELTA(rate2l), 16)
  1107. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  1108. | ATH9K_POW_SM(RT_AR_DELTA(rate1l), 0));
  1109. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  1110. ATH9K_POW_SM(RT_AR_DELTA(rate11s), 24)
  1111. | ATH9K_POW_SM(RT_AR_DELTA(rate11l), 16)
  1112. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5s), 8)
  1113. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5l), 0));
  1114. } else {
  1115. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  1116. ATH9K_POW_SM(ratesArray[rate2s], 24)
  1117. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  1118. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  1119. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  1120. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  1121. ATH9K_POW_SM(ratesArray[rate11s], 24)
  1122. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  1123. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  1124. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  1125. }
  1126. }
  1127. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  1128. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  1129. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  1130. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  1131. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  1132. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  1133. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  1134. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  1135. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  1136. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  1137. if (IS_CHAN_HT40(chan)) {
  1138. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  1139. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  1140. ht40PowerIncForPdadc, 24)
  1141. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  1142. ht40PowerIncForPdadc, 16)
  1143. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  1144. ht40PowerIncForPdadc, 8)
  1145. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  1146. ht40PowerIncForPdadc, 0));
  1147. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  1148. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  1149. ht40PowerIncForPdadc, 24)
  1150. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  1151. ht40PowerIncForPdadc, 16)
  1152. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  1153. ht40PowerIncForPdadc, 8)
  1154. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  1155. ht40PowerIncForPdadc, 0));
  1156. if (OLC_FOR_AR9280_20_LATER) {
  1157. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  1158. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  1159. | ATH9K_POW_SM(RT_AR_DELTA(rateExtCck), 16)
  1160. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  1161. | ATH9K_POW_SM(RT_AR_DELTA(rateDupCck), 0));
  1162. } else {
  1163. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  1164. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  1165. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  1166. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  1167. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  1168. }
  1169. }
  1170. REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
  1171. ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
  1172. | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
  1173. REGWRITE_BUFFER_FLUSH(ah);
  1174. }
  1175. static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
  1176. {
  1177. return ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan;
  1178. }
  1179. const struct eeprom_ops eep_def_ops = {
  1180. .check_eeprom = ath9k_hw_def_check_eeprom,
  1181. .get_eeprom = ath9k_hw_def_get_eeprom,
  1182. .fill_eeprom = ath9k_hw_def_fill_eeprom,
  1183. .dump_eeprom = ath9k_hw_def_dump_eeprom,
  1184. .get_eeprom_ver = ath9k_hw_def_get_eeprom_ver,
  1185. .get_eeprom_rev = ath9k_hw_def_get_eeprom_rev,
  1186. .set_board_values = ath9k_hw_def_set_board_values,
  1187. .set_addac = ath9k_hw_def_set_addac,
  1188. .set_txpower = ath9k_hw_def_set_txpower,
  1189. .get_spur_channel = ath9k_hw_def_get_spur_channel
  1190. };