eeprom_def.c 41 KB

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