eeprom_def.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434
  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. int band = 0;
  344. switch (param) {
  345. case EEP_NFTHRESH_5:
  346. return pModal[0].noiseFloorThreshCh[0];
  347. case EEP_NFTHRESH_2:
  348. return pModal[1].noiseFloorThreshCh[0];
  349. case EEP_MAC_LSW:
  350. return get_unaligned_be16(pBase->macAddr);
  351. case EEP_MAC_MID:
  352. return get_unaligned_be16(pBase->macAddr + 2);
  353. case EEP_MAC_MSW:
  354. return get_unaligned_be16(pBase->macAddr + 4);
  355. case EEP_REG_0:
  356. return pBase->regDmn[0];
  357. case EEP_OP_CAP:
  358. return pBase->deviceCap;
  359. case EEP_OP_MODE:
  360. return pBase->opCapFlags;
  361. case EEP_RF_SILENT:
  362. return pBase->rfSilent;
  363. case EEP_OB_5:
  364. return pModal[0].ob;
  365. case EEP_DB_5:
  366. return pModal[0].db;
  367. case EEP_OB_2:
  368. return pModal[1].ob;
  369. case EEP_DB_2:
  370. return pModal[1].db;
  371. case EEP_MINOR_REV:
  372. return AR5416_VER_MASK;
  373. case EEP_TX_MASK:
  374. return pBase->txMask;
  375. case EEP_RX_MASK:
  376. return pBase->rxMask;
  377. case EEP_FSTCLK_5G:
  378. return pBase->fastClk5g;
  379. case EEP_RXGAIN_TYPE:
  380. return pBase->rxGainType;
  381. case EEP_TXGAIN_TYPE:
  382. return pBase->txGainType;
  383. case EEP_OL_PWRCTRL:
  384. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  385. return pBase->openLoopPwrCntl ? true : false;
  386. else
  387. return false;
  388. case EEP_RC_CHAIN_MASK:
  389. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  390. return pBase->rcChainMask;
  391. else
  392. return 0;
  393. case EEP_DAC_HPWR_5G:
  394. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
  395. return pBase->dacHiPwrMode_5G;
  396. else
  397. return 0;
  398. case EEP_FRAC_N_5G:
  399. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
  400. return pBase->frac_n_5g;
  401. else
  402. return 0;
  403. case EEP_PWR_TABLE_OFFSET:
  404. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_21)
  405. return pBase->pwr_table_offset;
  406. else
  407. return AR5416_PWR_TABLE_OFFSET_DB;
  408. case EEP_ANTENNA_GAIN_2G:
  409. band = 1;
  410. /* fall through */
  411. case EEP_ANTENNA_GAIN_5G:
  412. return max_t(u8, max_t(u8,
  413. pModal[band].antennaGainCh[0],
  414. pModal[band].antennaGainCh[1]),
  415. pModal[band].antennaGainCh[2]);
  416. default:
  417. return 0;
  418. }
  419. }
  420. static void ath9k_hw_def_set_gain(struct ath_hw *ah,
  421. struct modal_eep_header *pModal,
  422. struct ar5416_eeprom_def *eep,
  423. u8 txRxAttenLocal, int regChainOffset, int i)
  424. {
  425. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
  426. txRxAttenLocal = pModal->txRxAttenCh[i];
  427. if (AR_SREV_9280_20_OR_LATER(ah)) {
  428. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  429. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  430. pModal->bswMargin[i]);
  431. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  432. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  433. pModal->bswAtten[i]);
  434. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  435. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  436. pModal->xatten2Margin[i]);
  437. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  438. AR_PHY_GAIN_2GHZ_XATTEN2_DB,
  439. pModal->xatten2Db[i]);
  440. } else {
  441. REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  442. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  443. ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
  444. | SM(pModal-> bswMargin[i],
  445. AR_PHY_GAIN_2GHZ_BSW_MARGIN));
  446. REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  447. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  448. ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
  449. | SM(pModal->bswAtten[i],
  450. AR_PHY_GAIN_2GHZ_BSW_ATTEN));
  451. }
  452. }
  453. if (AR_SREV_9280_20_OR_LATER(ah)) {
  454. REG_RMW_FIELD(ah,
  455. AR_PHY_RXGAIN + regChainOffset,
  456. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  457. REG_RMW_FIELD(ah,
  458. AR_PHY_RXGAIN + regChainOffset,
  459. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[i]);
  460. } else {
  461. REG_WRITE(ah,
  462. AR_PHY_RXGAIN + regChainOffset,
  463. (REG_READ(ah, AR_PHY_RXGAIN + regChainOffset) &
  464. ~AR_PHY_RXGAIN_TXRX_ATTEN)
  465. | SM(txRxAttenLocal, AR_PHY_RXGAIN_TXRX_ATTEN));
  466. REG_WRITE(ah,
  467. AR_PHY_GAIN_2GHZ + regChainOffset,
  468. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  469. ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
  470. SM(pModal->rxTxMarginCh[i], AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
  471. }
  472. }
  473. static void ath9k_hw_def_set_board_values(struct ath_hw *ah,
  474. struct ath9k_channel *chan)
  475. {
  476. struct modal_eep_header *pModal;
  477. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  478. int i, regChainOffset;
  479. u8 txRxAttenLocal;
  480. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  481. txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
  482. REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon & 0xffff);
  483. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  484. if (AR_SREV_9280(ah)) {
  485. if (i >= 2)
  486. break;
  487. }
  488. if ((ah->rxchainmask == 5 || ah->txchainmask == 5) && (i != 0))
  489. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  490. else
  491. regChainOffset = i * 0x1000;
  492. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  493. pModal->antCtrlChain[i]);
  494. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  495. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
  496. ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  497. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  498. SM(pModal->iqCalICh[i],
  499. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  500. SM(pModal->iqCalQCh[i],
  501. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  502. ath9k_hw_def_set_gain(ah, pModal, eep, txRxAttenLocal,
  503. regChainOffset, i);
  504. }
  505. if (AR_SREV_9280_20_OR_LATER(ah)) {
  506. if (IS_CHAN_2GHZ(chan)) {
  507. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  508. AR_AN_RF2G1_CH0_OB,
  509. AR_AN_RF2G1_CH0_OB_S,
  510. pModal->ob);
  511. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  512. AR_AN_RF2G1_CH0_DB,
  513. AR_AN_RF2G1_CH0_DB_S,
  514. pModal->db);
  515. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  516. AR_AN_RF2G1_CH1_OB,
  517. AR_AN_RF2G1_CH1_OB_S,
  518. pModal->ob_ch1);
  519. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  520. AR_AN_RF2G1_CH1_DB,
  521. AR_AN_RF2G1_CH1_DB_S,
  522. pModal->db_ch1);
  523. } else {
  524. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  525. AR_AN_RF5G1_CH0_OB5,
  526. AR_AN_RF5G1_CH0_OB5_S,
  527. pModal->ob);
  528. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  529. AR_AN_RF5G1_CH0_DB5,
  530. AR_AN_RF5G1_CH0_DB5_S,
  531. pModal->db);
  532. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  533. AR_AN_RF5G1_CH1_OB5,
  534. AR_AN_RF5G1_CH1_OB5_S,
  535. pModal->ob_ch1);
  536. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  537. AR_AN_RF5G1_CH1_DB5,
  538. AR_AN_RF5G1_CH1_DB5_S,
  539. pModal->db_ch1);
  540. }
  541. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  542. AR_AN_TOP2_XPABIAS_LVL,
  543. AR_AN_TOP2_XPABIAS_LVL_S,
  544. pModal->xpaBiasLvl);
  545. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  546. AR_AN_TOP2_LOCALBIAS,
  547. AR_AN_TOP2_LOCALBIAS_S,
  548. !!(pModal->lna_ctl &
  549. LNA_CTL_LOCAL_BIAS));
  550. REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
  551. !!(pModal->lna_ctl & LNA_CTL_FORCE_XPA));
  552. }
  553. REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
  554. pModal->switchSettling);
  555. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
  556. pModal->adcDesiredSize);
  557. if (!AR_SREV_9280_20_OR_LATER(ah))
  558. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  559. AR_PHY_DESIRED_SZ_PGA,
  560. pModal->pgaDesiredSize);
  561. REG_WRITE(ah, AR_PHY_RF_CTL4,
  562. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  563. | SM(pModal->txEndToXpaOff,
  564. AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  565. | SM(pModal->txFrameToXpaOn,
  566. AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  567. | SM(pModal->txFrameToXpaOn,
  568. AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  569. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  570. pModal->txEndToRxOn);
  571. if (AR_SREV_9280_20_OR_LATER(ah)) {
  572. REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
  573. pModal->thresh62);
  574. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  575. AR_PHY_EXT_CCA0_THRESH62,
  576. pModal->thresh62);
  577. } else {
  578. REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
  579. pModal->thresh62);
  580. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  581. AR_PHY_EXT_CCA_THRESH62,
  582. pModal->thresh62);
  583. }
  584. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
  585. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  586. AR_PHY_TX_END_DATA_START,
  587. pModal->txFrameToDataStart);
  588. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
  589. pModal->txFrameToPaOn);
  590. }
  591. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
  592. if (IS_CHAN_HT40(chan))
  593. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  594. AR_PHY_SETTLING_SWITCH,
  595. pModal->swSettleHt40);
  596. }
  597. if (AR_SREV_9280_20_OR_LATER(ah) &&
  598. AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  599. REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL,
  600. AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK,
  601. pModal->miscBits);
  602. if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) {
  603. if (IS_CHAN_2GHZ(chan))
  604. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
  605. eep->baseEepHeader.dacLpMode);
  606. else if (eep->baseEepHeader.dacHiPwrMode_5G)
  607. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, 0);
  608. else
  609. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
  610. eep->baseEepHeader.dacLpMode);
  611. udelay(100);
  612. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, AR_PHY_FRAME_CTL_TX_CLIP,
  613. pModal->miscBits >> 2);
  614. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL9,
  615. AR_PHY_TX_DESIRED_SCALE_CCK,
  616. eep->baseEepHeader.desiredScaleCCK);
  617. }
  618. }
  619. static void ath9k_hw_def_set_addac(struct ath_hw *ah,
  620. struct ath9k_channel *chan)
  621. {
  622. #define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt])
  623. struct modal_eep_header *pModal;
  624. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  625. u8 biaslevel;
  626. if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
  627. return;
  628. if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
  629. return;
  630. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  631. if (pModal->xpaBiasLvl != 0xff) {
  632. biaslevel = pModal->xpaBiasLvl;
  633. } else {
  634. u16 resetFreqBin, freqBin, freqCount = 0;
  635. struct chan_centers centers;
  636. ath9k_hw_get_channel_centers(ah, chan, &centers);
  637. resetFreqBin = FREQ2FBIN(centers.synth_center,
  638. IS_CHAN_2GHZ(chan));
  639. freqBin = XPA_LVL_FREQ(0) & 0xff;
  640. biaslevel = (u8) (XPA_LVL_FREQ(0) >> 14);
  641. freqCount++;
  642. while (freqCount < 3) {
  643. if (XPA_LVL_FREQ(freqCount) == 0x0)
  644. break;
  645. freqBin = XPA_LVL_FREQ(freqCount) & 0xff;
  646. if (resetFreqBin >= freqBin)
  647. biaslevel = (u8)(XPA_LVL_FREQ(freqCount) >> 14);
  648. else
  649. break;
  650. freqCount++;
  651. }
  652. }
  653. if (IS_CHAN_2GHZ(chan)) {
  654. INI_RA(&ah->iniAddac, 7, 1) = (INI_RA(&ah->iniAddac,
  655. 7, 1) & (~0x18)) | biaslevel << 3;
  656. } else {
  657. INI_RA(&ah->iniAddac, 6, 1) = (INI_RA(&ah->iniAddac,
  658. 6, 1) & (~0xc0)) | biaslevel << 6;
  659. }
  660. #undef XPA_LVL_FREQ
  661. }
  662. static int16_t ath9k_change_gain_boundary_setting(struct ath_hw *ah,
  663. u16 *gb,
  664. u16 numXpdGain,
  665. u16 pdGainOverlap_t2,
  666. int8_t pwr_table_offset,
  667. int16_t *diff)
  668. {
  669. u16 k;
  670. /* Prior to writing the boundaries or the pdadc vs. power table
  671. * into the chip registers the default starting point on the pdadc
  672. * vs. power table needs to be checked and the curve boundaries
  673. * adjusted accordingly
  674. */
  675. if (AR_SREV_9280_20_OR_LATER(ah)) {
  676. u16 gb_limit;
  677. if (AR5416_PWR_TABLE_OFFSET_DB != pwr_table_offset) {
  678. /* get the difference in dB */
  679. *diff = (u16)(pwr_table_offset - AR5416_PWR_TABLE_OFFSET_DB);
  680. /* get the number of half dB steps */
  681. *diff *= 2;
  682. /* change the original gain boundary settings
  683. * by the number of half dB steps
  684. */
  685. for (k = 0; k < numXpdGain; k++)
  686. gb[k] = (u16)(gb[k] - *diff);
  687. }
  688. /* Because of a hardware limitation, ensure the gain boundary
  689. * is not larger than (63 - overlap)
  690. */
  691. gb_limit = (u16)(MAX_RATE_POWER - pdGainOverlap_t2);
  692. for (k = 0; k < numXpdGain; k++)
  693. gb[k] = (u16)min(gb_limit, gb[k]);
  694. }
  695. return *diff;
  696. }
  697. static void ath9k_adjust_pdadc_values(struct ath_hw *ah,
  698. int8_t pwr_table_offset,
  699. int16_t diff,
  700. u8 *pdadcValues)
  701. {
  702. #define NUM_PDADC(diff) (AR5416_NUM_PDADC_VALUES - diff)
  703. u16 k;
  704. /* If this is a board that has a pwrTableOffset that differs from
  705. * the default AR5416_PWR_TABLE_OFFSET_DB then the start of the
  706. * pdadc vs pwr table needs to be adjusted prior to writing to the
  707. * chip.
  708. */
  709. if (AR_SREV_9280_20_OR_LATER(ah)) {
  710. if (AR5416_PWR_TABLE_OFFSET_DB != pwr_table_offset) {
  711. /* shift the table to start at the new offset */
  712. for (k = 0; k < (u16)NUM_PDADC(diff); k++ ) {
  713. pdadcValues[k] = pdadcValues[k + diff];
  714. }
  715. /* fill the back of the table */
  716. for (k = (u16)NUM_PDADC(diff); k < NUM_PDADC(0); k++) {
  717. pdadcValues[k] = pdadcValues[NUM_PDADC(diff)];
  718. }
  719. }
  720. }
  721. #undef NUM_PDADC
  722. }
  723. static void ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
  724. struct ath9k_channel *chan)
  725. {
  726. #define SM_PD_GAIN(x) SM(0x38, AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##x)
  727. #define SM_PDGAIN_B(x, y) \
  728. SM((gainBoundaries[x]), AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##y)
  729. struct ath_common *common = ath9k_hw_common(ah);
  730. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  731. struct cal_data_per_freq *pRawDataset;
  732. u8 *pCalBChans = NULL;
  733. u16 pdGainOverlap_t2;
  734. static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
  735. u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
  736. u16 numPiers, i, j;
  737. int16_t diff = 0;
  738. u16 numXpdGain, xpdMask;
  739. u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
  740. u32 reg32, regOffset, regChainOffset;
  741. int16_t modalIdx;
  742. int8_t pwr_table_offset;
  743. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  744. xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
  745. pwr_table_offset = ah->eep_ops->get_eeprom(ah, EEP_PWR_TABLE_OFFSET);
  746. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  747. AR5416_EEP_MINOR_VER_2) {
  748. pdGainOverlap_t2 =
  749. pEepData->modalHeader[modalIdx].pdGainOverlap;
  750. } else {
  751. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  752. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  753. }
  754. if (IS_CHAN_2GHZ(chan)) {
  755. pCalBChans = pEepData->calFreqPier2G;
  756. numPiers = AR5416_NUM_2G_CAL_PIERS;
  757. } else {
  758. pCalBChans = pEepData->calFreqPier5G;
  759. numPiers = AR5416_NUM_5G_CAL_PIERS;
  760. }
  761. if (OLC_FOR_AR9280_20_LATER && IS_CHAN_2GHZ(chan)) {
  762. pRawDataset = pEepData->calPierData2G[0];
  763. ah->initPDADC = ((struct calDataPerFreqOpLoop *)
  764. pRawDataset)->vpdPdg[0][0];
  765. }
  766. numXpdGain = 0;
  767. for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
  768. if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
  769. if (numXpdGain >= AR5416_NUM_PD_GAINS)
  770. break;
  771. xpdGainValues[numXpdGain] =
  772. (u16)(AR5416_PD_GAINS_IN_MASK - i);
  773. numXpdGain++;
  774. }
  775. }
  776. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  777. (numXpdGain - 1) & 0x3);
  778. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  779. xpdGainValues[0]);
  780. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  781. xpdGainValues[1]);
  782. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  783. xpdGainValues[2]);
  784. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  785. if ((ah->rxchainmask == 5 || ah->txchainmask == 5) &&
  786. (i != 0)) {
  787. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  788. } else
  789. regChainOffset = i * 0x1000;
  790. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  791. if (IS_CHAN_2GHZ(chan))
  792. pRawDataset = pEepData->calPierData2G[i];
  793. else
  794. pRawDataset = pEepData->calPierData5G[i];
  795. if (OLC_FOR_AR9280_20_LATER) {
  796. u8 pcdacIdx;
  797. u8 txPower;
  798. ath9k_get_txgain_index(ah, chan,
  799. (struct calDataPerFreqOpLoop *)pRawDataset,
  800. pCalBChans, numPiers, &txPower, &pcdacIdx);
  801. ath9k_olc_get_pdadcs(ah, pcdacIdx,
  802. txPower/2, pdadcValues);
  803. } else {
  804. ath9k_hw_get_gain_boundaries_pdadcs(ah,
  805. chan, pRawDataset,
  806. pCalBChans, numPiers,
  807. pdGainOverlap_t2,
  808. gainBoundaries,
  809. pdadcValues,
  810. numXpdGain);
  811. }
  812. diff = ath9k_change_gain_boundary_setting(ah,
  813. gainBoundaries,
  814. numXpdGain,
  815. pdGainOverlap_t2,
  816. pwr_table_offset,
  817. &diff);
  818. ENABLE_REGWRITE_BUFFER(ah);
  819. if (OLC_FOR_AR9280_20_LATER) {
  820. REG_WRITE(ah,
  821. AR_PHY_TPCRG5 + regChainOffset,
  822. SM(0x6,
  823. AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
  824. SM_PD_GAIN(1) | SM_PD_GAIN(2) |
  825. SM_PD_GAIN(3) | SM_PD_GAIN(4));
  826. } else {
  827. REG_WRITE(ah,
  828. AR_PHY_TPCRG5 + regChainOffset,
  829. SM(pdGainOverlap_t2,
  830. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)|
  831. SM_PDGAIN_B(0, 1) |
  832. SM_PDGAIN_B(1, 2) |
  833. SM_PDGAIN_B(2, 3) |
  834. SM_PDGAIN_B(3, 4));
  835. }
  836. ath9k_adjust_pdadc_values(ah, pwr_table_offset,
  837. diff, pdadcValues);
  838. regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
  839. for (j = 0; j < 32; j++) {
  840. reg32 = get_unaligned_le32(&pdadcValues[4 * j]);
  841. REG_WRITE(ah, regOffset, reg32);
  842. ath_dbg(common, ATH_DBG_EEPROM,
  843. "PDADC (%d,%4x): %4.4x %8.8x\n",
  844. i, regChainOffset, regOffset,
  845. reg32);
  846. ath_dbg(common, ATH_DBG_EEPROM,
  847. "PDADC: Chain %d | PDADC %3d "
  848. "Value %3d | PDADC %3d Value %3d | "
  849. "PDADC %3d Value %3d | PDADC %3d "
  850. "Value %3d |\n",
  851. i, 4 * j, pdadcValues[4 * j],
  852. 4 * j + 1, pdadcValues[4 * j + 1],
  853. 4 * j + 2, pdadcValues[4 * j + 2],
  854. 4 * j + 3, pdadcValues[4 * j + 3]);
  855. regOffset += 4;
  856. }
  857. REGWRITE_BUFFER_FLUSH(ah);
  858. }
  859. }
  860. #undef SM_PD_GAIN
  861. #undef SM_PDGAIN_B
  862. }
  863. static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
  864. struct ath9k_channel *chan,
  865. int16_t *ratesArray,
  866. u16 cfgCtl,
  867. u16 antenna_reduction,
  868. u16 powerLimit)
  869. {
  870. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */
  871. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 9 /* 10*log10(3)*2 */
  872. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  873. u16 twiceMaxEdgePower = MAX_RATE_POWER;
  874. int i;
  875. struct cal_ctl_data *rep;
  876. struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
  877. 0, { 0, 0, 0, 0}
  878. };
  879. struct cal_target_power_leg targetPowerOfdmExt = {
  880. 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
  881. 0, { 0, 0, 0, 0 }
  882. };
  883. struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
  884. 0, {0, 0, 0, 0}
  885. };
  886. u16 scaledPower = 0, minCtlPower;
  887. static const u16 ctlModesFor11a[] = {
  888. CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40
  889. };
  890. static const u16 ctlModesFor11g[] = {
  891. CTL_11B, CTL_11G, CTL_2GHT20,
  892. CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
  893. };
  894. u16 numCtlModes;
  895. const u16 *pCtlMode;
  896. u16 ctlMode, freq;
  897. struct chan_centers centers;
  898. int tx_chainmask;
  899. u16 twiceMinEdgePower;
  900. tx_chainmask = ah->txchainmask;
  901. ath9k_hw_get_channel_centers(ah, chan, &centers);
  902. scaledPower = powerLimit - antenna_reduction;
  903. switch (ar5416_get_ntxchains(tx_chainmask)) {
  904. case 1:
  905. break;
  906. case 2:
  907. if (scaledPower > REDUCE_SCALED_POWER_BY_TWO_CHAIN)
  908. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  909. else
  910. scaledPower = 0;
  911. break;
  912. case 3:
  913. if (scaledPower > REDUCE_SCALED_POWER_BY_THREE_CHAIN)
  914. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  915. else
  916. scaledPower = 0;
  917. break;
  918. }
  919. if (IS_CHAN_2GHZ(chan)) {
  920. numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
  921. SUB_NUM_CTL_MODES_AT_2G_40;
  922. pCtlMode = ctlModesFor11g;
  923. ath9k_hw_get_legacy_target_powers(ah, chan,
  924. pEepData->calTargetPowerCck,
  925. AR5416_NUM_2G_CCK_TARGET_POWERS,
  926. &targetPowerCck, 4, false);
  927. ath9k_hw_get_legacy_target_powers(ah, chan,
  928. pEepData->calTargetPower2G,
  929. AR5416_NUM_2G_20_TARGET_POWERS,
  930. &targetPowerOfdm, 4, false);
  931. ath9k_hw_get_target_powers(ah, chan,
  932. pEepData->calTargetPower2GHT20,
  933. AR5416_NUM_2G_20_TARGET_POWERS,
  934. &targetPowerHt20, 8, false);
  935. if (IS_CHAN_HT40(chan)) {
  936. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  937. ath9k_hw_get_target_powers(ah, chan,
  938. pEepData->calTargetPower2GHT40,
  939. AR5416_NUM_2G_40_TARGET_POWERS,
  940. &targetPowerHt40, 8, true);
  941. ath9k_hw_get_legacy_target_powers(ah, chan,
  942. pEepData->calTargetPowerCck,
  943. AR5416_NUM_2G_CCK_TARGET_POWERS,
  944. &targetPowerCckExt, 4, true);
  945. ath9k_hw_get_legacy_target_powers(ah, chan,
  946. pEepData->calTargetPower2G,
  947. AR5416_NUM_2G_20_TARGET_POWERS,
  948. &targetPowerOfdmExt, 4, true);
  949. }
  950. } else {
  951. numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
  952. SUB_NUM_CTL_MODES_AT_5G_40;
  953. pCtlMode = ctlModesFor11a;
  954. ath9k_hw_get_legacy_target_powers(ah, chan,
  955. pEepData->calTargetPower5G,
  956. AR5416_NUM_5G_20_TARGET_POWERS,
  957. &targetPowerOfdm, 4, false);
  958. ath9k_hw_get_target_powers(ah, chan,
  959. pEepData->calTargetPower5GHT20,
  960. AR5416_NUM_5G_20_TARGET_POWERS,
  961. &targetPowerHt20, 8, false);
  962. if (IS_CHAN_HT40(chan)) {
  963. numCtlModes = ARRAY_SIZE(ctlModesFor11a);
  964. ath9k_hw_get_target_powers(ah, chan,
  965. pEepData->calTargetPower5GHT40,
  966. AR5416_NUM_5G_40_TARGET_POWERS,
  967. &targetPowerHt40, 8, true);
  968. ath9k_hw_get_legacy_target_powers(ah, chan,
  969. pEepData->calTargetPower5G,
  970. AR5416_NUM_5G_20_TARGET_POWERS,
  971. &targetPowerOfdmExt, 4, true);
  972. }
  973. }
  974. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  975. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  976. (pCtlMode[ctlMode] == CTL_2GHT40);
  977. if (isHt40CtlMode)
  978. freq = centers.synth_center;
  979. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  980. freq = centers.ext_center;
  981. else
  982. freq = centers.ctl_center;
  983. if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
  984. ah->eep_ops->get_eeprom_rev(ah) <= 2)
  985. twiceMaxEdgePower = MAX_RATE_POWER;
  986. for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  987. if ((((cfgCtl & ~CTL_MODE_M) |
  988. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  989. pEepData->ctlIndex[i]) ||
  990. (((cfgCtl & ~CTL_MODE_M) |
  991. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  992. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
  993. rep = &(pEepData->ctlData[i]);
  994. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  995. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
  996. IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
  997. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  998. twiceMaxEdgePower = min(twiceMaxEdgePower,
  999. twiceMinEdgePower);
  1000. } else {
  1001. twiceMaxEdgePower = twiceMinEdgePower;
  1002. break;
  1003. }
  1004. }
  1005. }
  1006. minCtlPower = min(twiceMaxEdgePower, scaledPower);
  1007. switch (pCtlMode[ctlMode]) {
  1008. case CTL_11B:
  1009. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  1010. targetPowerCck.tPow2x[i] =
  1011. min((u16)targetPowerCck.tPow2x[i],
  1012. minCtlPower);
  1013. }
  1014. break;
  1015. case CTL_11A:
  1016. case CTL_11G:
  1017. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  1018. targetPowerOfdm.tPow2x[i] =
  1019. min((u16)targetPowerOfdm.tPow2x[i],
  1020. minCtlPower);
  1021. }
  1022. break;
  1023. case CTL_5GHT20:
  1024. case CTL_2GHT20:
  1025. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  1026. targetPowerHt20.tPow2x[i] =
  1027. min((u16)targetPowerHt20.tPow2x[i],
  1028. minCtlPower);
  1029. }
  1030. break;
  1031. case CTL_11B_EXT:
  1032. targetPowerCckExt.tPow2x[0] = min((u16)
  1033. targetPowerCckExt.tPow2x[0],
  1034. minCtlPower);
  1035. break;
  1036. case CTL_11A_EXT:
  1037. case CTL_11G_EXT:
  1038. targetPowerOfdmExt.tPow2x[0] = min((u16)
  1039. targetPowerOfdmExt.tPow2x[0],
  1040. minCtlPower);
  1041. break;
  1042. case CTL_5GHT40:
  1043. case CTL_2GHT40:
  1044. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  1045. targetPowerHt40.tPow2x[i] =
  1046. min((u16)targetPowerHt40.tPow2x[i],
  1047. minCtlPower);
  1048. }
  1049. break;
  1050. default:
  1051. break;
  1052. }
  1053. }
  1054. ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
  1055. ratesArray[rate18mb] = ratesArray[rate24mb] =
  1056. targetPowerOfdm.tPow2x[0];
  1057. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  1058. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  1059. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  1060. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  1061. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  1062. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  1063. if (IS_CHAN_2GHZ(chan)) {
  1064. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  1065. ratesArray[rate2s] = ratesArray[rate2l] =
  1066. targetPowerCck.tPow2x[1];
  1067. ratesArray[rate5_5s] = ratesArray[rate5_5l] =
  1068. targetPowerCck.tPow2x[2];
  1069. ratesArray[rate11s] = ratesArray[rate11l] =
  1070. targetPowerCck.tPow2x[3];
  1071. }
  1072. if (IS_CHAN_HT40(chan)) {
  1073. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  1074. ratesArray[rateHt40_0 + i] =
  1075. targetPowerHt40.tPow2x[i];
  1076. }
  1077. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  1078. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  1079. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  1080. if (IS_CHAN_2GHZ(chan)) {
  1081. ratesArray[rateExtCck] =
  1082. targetPowerCckExt.tPow2x[0];
  1083. }
  1084. }
  1085. }
  1086. static void ath9k_hw_def_set_txpower(struct ath_hw *ah,
  1087. struct ath9k_channel *chan,
  1088. u16 cfgCtl,
  1089. u8 twiceAntennaReduction,
  1090. u8 powerLimit, bool test)
  1091. {
  1092. #define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
  1093. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1094. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  1095. struct modal_eep_header *pModal =
  1096. &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
  1097. int16_t ratesArray[Ar5416RateSize];
  1098. u8 ht40PowerIncForPdadc = 2;
  1099. int i, cck_ofdm_delta = 0;
  1100. memset(ratesArray, 0, sizeof(ratesArray));
  1101. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1102. AR5416_EEP_MINOR_VER_2) {
  1103. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  1104. }
  1105. ath9k_hw_set_def_power_per_rate_table(ah, chan,
  1106. &ratesArray[0], cfgCtl,
  1107. twiceAntennaReduction,
  1108. powerLimit);
  1109. ath9k_hw_set_def_power_cal_table(ah, chan);
  1110. regulatory->max_power_level = 0;
  1111. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  1112. if (ratesArray[i] > MAX_RATE_POWER)
  1113. ratesArray[i] = MAX_RATE_POWER;
  1114. if (ratesArray[i] > regulatory->max_power_level)
  1115. regulatory->max_power_level = ratesArray[i];
  1116. }
  1117. switch(ar5416_get_ntxchains(ah->txchainmask)) {
  1118. case 1:
  1119. break;
  1120. case 2:
  1121. regulatory->max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
  1122. break;
  1123. case 3:
  1124. regulatory->max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
  1125. break;
  1126. default:
  1127. ath_dbg(ath9k_hw_common(ah), ATH_DBG_EEPROM,
  1128. "Invalid chainmask configuration\n");
  1129. break;
  1130. }
  1131. if (test)
  1132. return;
  1133. if (AR_SREV_9280_20_OR_LATER(ah)) {
  1134. for (i = 0; i < Ar5416RateSize; i++) {
  1135. int8_t pwr_table_offset;
  1136. pwr_table_offset = ah->eep_ops->get_eeprom(ah,
  1137. EEP_PWR_TABLE_OFFSET);
  1138. ratesArray[i] -= pwr_table_offset * 2;
  1139. }
  1140. }
  1141. ENABLE_REGWRITE_BUFFER(ah);
  1142. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  1143. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  1144. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  1145. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  1146. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  1147. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  1148. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  1149. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  1150. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  1151. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  1152. if (IS_CHAN_2GHZ(chan)) {
  1153. if (OLC_FOR_AR9280_20_LATER) {
  1154. cck_ofdm_delta = 2;
  1155. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  1156. ATH9K_POW_SM(RT_AR_DELTA(rate2s), 24)
  1157. | ATH9K_POW_SM(RT_AR_DELTA(rate2l), 16)
  1158. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  1159. | ATH9K_POW_SM(RT_AR_DELTA(rate1l), 0));
  1160. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  1161. ATH9K_POW_SM(RT_AR_DELTA(rate11s), 24)
  1162. | ATH9K_POW_SM(RT_AR_DELTA(rate11l), 16)
  1163. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5s), 8)
  1164. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5l), 0));
  1165. } else {
  1166. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  1167. ATH9K_POW_SM(ratesArray[rate2s], 24)
  1168. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  1169. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  1170. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  1171. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  1172. ATH9K_POW_SM(ratesArray[rate11s], 24)
  1173. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  1174. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  1175. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  1176. }
  1177. }
  1178. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  1179. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  1180. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  1181. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  1182. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  1183. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  1184. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  1185. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  1186. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  1187. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  1188. if (IS_CHAN_HT40(chan)) {
  1189. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  1190. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  1191. ht40PowerIncForPdadc, 24)
  1192. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  1193. ht40PowerIncForPdadc, 16)
  1194. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  1195. ht40PowerIncForPdadc, 8)
  1196. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  1197. ht40PowerIncForPdadc, 0));
  1198. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  1199. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  1200. ht40PowerIncForPdadc, 24)
  1201. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  1202. ht40PowerIncForPdadc, 16)
  1203. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  1204. ht40PowerIncForPdadc, 8)
  1205. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  1206. ht40PowerIncForPdadc, 0));
  1207. if (OLC_FOR_AR9280_20_LATER) {
  1208. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  1209. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  1210. | ATH9K_POW_SM(RT_AR_DELTA(rateExtCck), 16)
  1211. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  1212. | ATH9K_POW_SM(RT_AR_DELTA(rateDupCck), 0));
  1213. } else {
  1214. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  1215. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  1216. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  1217. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  1218. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  1219. }
  1220. }
  1221. REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
  1222. ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
  1223. | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
  1224. REGWRITE_BUFFER_FLUSH(ah);
  1225. }
  1226. static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
  1227. {
  1228. #define EEP_DEF_SPURCHAN \
  1229. (ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan)
  1230. struct ath_common *common = ath9k_hw_common(ah);
  1231. u16 spur_val = AR_NO_SPUR;
  1232. ath_dbg(common, ATH_DBG_ANI,
  1233. "Getting spur idx:%d is2Ghz:%d val:%x\n",
  1234. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  1235. switch (ah->config.spurmode) {
  1236. case SPUR_DISABLE:
  1237. break;
  1238. case SPUR_ENABLE_IOCTL:
  1239. spur_val = ah->config.spurchans[i][is2GHz];
  1240. ath_dbg(common, ATH_DBG_ANI,
  1241. "Getting spur val from new loc. %d\n", spur_val);
  1242. break;
  1243. case SPUR_ENABLE_EEPROM:
  1244. spur_val = EEP_DEF_SPURCHAN;
  1245. break;
  1246. }
  1247. return spur_val;
  1248. #undef EEP_DEF_SPURCHAN
  1249. }
  1250. const struct eeprom_ops eep_def_ops = {
  1251. .check_eeprom = ath9k_hw_def_check_eeprom,
  1252. .get_eeprom = ath9k_hw_def_get_eeprom,
  1253. .fill_eeprom = ath9k_hw_def_fill_eeprom,
  1254. .dump_eeprom = ath9k_hw_def_dump_eeprom,
  1255. .get_eeprom_ver = ath9k_hw_def_get_eeprom_ver,
  1256. .get_eeprom_rev = ath9k_hw_def_get_eeprom_rev,
  1257. .set_board_values = ath9k_hw_def_set_board_values,
  1258. .set_addac = ath9k_hw_def_set_addac,
  1259. .set_txpower = ath9k_hw_def_set_txpower,
  1260. .get_spur_channel = ath9k_hw_def_get_spur_channel
  1261. };