eeprom_def.c 40 KB

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