eeprom_def.c 42 KB

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