eeprom_def.c 40 KB

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