eeprom_def.c 43 KB

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