eeprom_def.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  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;
  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. twiceMaxEdgePower = MAX_RATE_POWER;
  984. for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  985. if ((((cfgCtl & ~CTL_MODE_M) |
  986. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  987. pEepData->ctlIndex[i]) ||
  988. (((cfgCtl & ~CTL_MODE_M) |
  989. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  990. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
  991. rep = &(pEepData->ctlData[i]);
  992. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  993. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
  994. IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
  995. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  996. twiceMaxEdgePower = min(twiceMaxEdgePower,
  997. twiceMinEdgePower);
  998. } else {
  999. twiceMaxEdgePower = twiceMinEdgePower;
  1000. break;
  1001. }
  1002. }
  1003. }
  1004. minCtlPower = min(twiceMaxEdgePower, scaledPower);
  1005. switch (pCtlMode[ctlMode]) {
  1006. case CTL_11B:
  1007. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  1008. targetPowerCck.tPow2x[i] =
  1009. min((u16)targetPowerCck.tPow2x[i],
  1010. minCtlPower);
  1011. }
  1012. break;
  1013. case CTL_11A:
  1014. case CTL_11G:
  1015. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  1016. targetPowerOfdm.tPow2x[i] =
  1017. min((u16)targetPowerOfdm.tPow2x[i],
  1018. minCtlPower);
  1019. }
  1020. break;
  1021. case CTL_5GHT20:
  1022. case CTL_2GHT20:
  1023. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  1024. targetPowerHt20.tPow2x[i] =
  1025. min((u16)targetPowerHt20.tPow2x[i],
  1026. minCtlPower);
  1027. }
  1028. break;
  1029. case CTL_11B_EXT:
  1030. targetPowerCckExt.tPow2x[0] = min((u16)
  1031. targetPowerCckExt.tPow2x[0],
  1032. minCtlPower);
  1033. break;
  1034. case CTL_11A_EXT:
  1035. case CTL_11G_EXT:
  1036. targetPowerOfdmExt.tPow2x[0] = min((u16)
  1037. targetPowerOfdmExt.tPow2x[0],
  1038. minCtlPower);
  1039. break;
  1040. case CTL_5GHT40:
  1041. case CTL_2GHT40:
  1042. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  1043. targetPowerHt40.tPow2x[i] =
  1044. min((u16)targetPowerHt40.tPow2x[i],
  1045. minCtlPower);
  1046. }
  1047. break;
  1048. default:
  1049. break;
  1050. }
  1051. }
  1052. ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
  1053. ratesArray[rate18mb] = ratesArray[rate24mb] =
  1054. targetPowerOfdm.tPow2x[0];
  1055. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  1056. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  1057. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  1058. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  1059. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  1060. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  1061. if (IS_CHAN_2GHZ(chan)) {
  1062. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  1063. ratesArray[rate2s] = ratesArray[rate2l] =
  1064. targetPowerCck.tPow2x[1];
  1065. ratesArray[rate5_5s] = ratesArray[rate5_5l] =
  1066. targetPowerCck.tPow2x[2];
  1067. ratesArray[rate11s] = ratesArray[rate11l] =
  1068. targetPowerCck.tPow2x[3];
  1069. }
  1070. if (IS_CHAN_HT40(chan)) {
  1071. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  1072. ratesArray[rateHt40_0 + i] =
  1073. targetPowerHt40.tPow2x[i];
  1074. }
  1075. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  1076. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  1077. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  1078. if (IS_CHAN_2GHZ(chan)) {
  1079. ratesArray[rateExtCck] =
  1080. targetPowerCckExt.tPow2x[0];
  1081. }
  1082. }
  1083. }
  1084. static void ath9k_hw_def_set_txpower(struct ath_hw *ah,
  1085. struct ath9k_channel *chan,
  1086. u16 cfgCtl,
  1087. u8 twiceAntennaReduction,
  1088. u8 powerLimit, bool test)
  1089. {
  1090. #define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
  1091. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1092. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  1093. struct modal_eep_header *pModal =
  1094. &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
  1095. int16_t ratesArray[Ar5416RateSize];
  1096. u8 ht40PowerIncForPdadc = 2;
  1097. int i, cck_ofdm_delta = 0;
  1098. memset(ratesArray, 0, sizeof(ratesArray));
  1099. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1100. AR5416_EEP_MINOR_VER_2) {
  1101. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  1102. }
  1103. ath9k_hw_set_def_power_per_rate_table(ah, chan,
  1104. &ratesArray[0], cfgCtl,
  1105. twiceAntennaReduction,
  1106. powerLimit);
  1107. ath9k_hw_set_def_power_cal_table(ah, chan);
  1108. regulatory->max_power_level = 0;
  1109. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  1110. if (ratesArray[i] > MAX_RATE_POWER)
  1111. ratesArray[i] = MAX_RATE_POWER;
  1112. if (ratesArray[i] > regulatory->max_power_level)
  1113. regulatory->max_power_level = ratesArray[i];
  1114. }
  1115. switch(ar5416_get_ntxchains(ah->txchainmask)) {
  1116. case 1:
  1117. break;
  1118. case 2:
  1119. regulatory->max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
  1120. break;
  1121. case 3:
  1122. regulatory->max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
  1123. break;
  1124. default:
  1125. ath_dbg(ath9k_hw_common(ah), ATH_DBG_EEPROM,
  1126. "Invalid chainmask configuration\n");
  1127. break;
  1128. }
  1129. if (test)
  1130. return;
  1131. if (AR_SREV_9280_20_OR_LATER(ah)) {
  1132. for (i = 0; i < Ar5416RateSize; i++) {
  1133. int8_t pwr_table_offset;
  1134. pwr_table_offset = ah->eep_ops->get_eeprom(ah,
  1135. EEP_PWR_TABLE_OFFSET);
  1136. ratesArray[i] -= pwr_table_offset * 2;
  1137. }
  1138. }
  1139. ENABLE_REGWRITE_BUFFER(ah);
  1140. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  1141. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  1142. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  1143. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  1144. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  1145. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  1146. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  1147. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  1148. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  1149. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  1150. if (IS_CHAN_2GHZ(chan)) {
  1151. if (OLC_FOR_AR9280_20_LATER) {
  1152. cck_ofdm_delta = 2;
  1153. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  1154. ATH9K_POW_SM(RT_AR_DELTA(rate2s), 24)
  1155. | ATH9K_POW_SM(RT_AR_DELTA(rate2l), 16)
  1156. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  1157. | ATH9K_POW_SM(RT_AR_DELTA(rate1l), 0));
  1158. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  1159. ATH9K_POW_SM(RT_AR_DELTA(rate11s), 24)
  1160. | ATH9K_POW_SM(RT_AR_DELTA(rate11l), 16)
  1161. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5s), 8)
  1162. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5l), 0));
  1163. } else {
  1164. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  1165. ATH9K_POW_SM(ratesArray[rate2s], 24)
  1166. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  1167. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  1168. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  1169. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  1170. ATH9K_POW_SM(ratesArray[rate11s], 24)
  1171. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  1172. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  1173. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  1174. }
  1175. }
  1176. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  1177. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  1178. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  1179. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  1180. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  1181. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  1182. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  1183. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  1184. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  1185. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  1186. if (IS_CHAN_HT40(chan)) {
  1187. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  1188. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  1189. ht40PowerIncForPdadc, 24)
  1190. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  1191. ht40PowerIncForPdadc, 16)
  1192. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  1193. ht40PowerIncForPdadc, 8)
  1194. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  1195. ht40PowerIncForPdadc, 0));
  1196. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  1197. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  1198. ht40PowerIncForPdadc, 24)
  1199. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  1200. ht40PowerIncForPdadc, 16)
  1201. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  1202. ht40PowerIncForPdadc, 8)
  1203. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  1204. ht40PowerIncForPdadc, 0));
  1205. if (OLC_FOR_AR9280_20_LATER) {
  1206. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  1207. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  1208. | ATH9K_POW_SM(RT_AR_DELTA(rateExtCck), 16)
  1209. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  1210. | ATH9K_POW_SM(RT_AR_DELTA(rateDupCck), 0));
  1211. } else {
  1212. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  1213. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  1214. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  1215. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  1216. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  1217. }
  1218. }
  1219. REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
  1220. ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
  1221. | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
  1222. REGWRITE_BUFFER_FLUSH(ah);
  1223. }
  1224. static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
  1225. {
  1226. #define EEP_DEF_SPURCHAN \
  1227. (ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan)
  1228. struct ath_common *common = ath9k_hw_common(ah);
  1229. u16 spur_val = AR_NO_SPUR;
  1230. ath_dbg(common, ATH_DBG_ANI,
  1231. "Getting spur idx:%d is2Ghz:%d val:%x\n",
  1232. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  1233. switch (ah->config.spurmode) {
  1234. case SPUR_DISABLE:
  1235. break;
  1236. case SPUR_ENABLE_IOCTL:
  1237. spur_val = ah->config.spurchans[i][is2GHz];
  1238. ath_dbg(common, ATH_DBG_ANI,
  1239. "Getting spur val from new loc. %d\n", spur_val);
  1240. break;
  1241. case SPUR_ENABLE_EEPROM:
  1242. spur_val = EEP_DEF_SPURCHAN;
  1243. break;
  1244. }
  1245. return spur_val;
  1246. #undef EEP_DEF_SPURCHAN
  1247. }
  1248. const struct eeprom_ops eep_def_ops = {
  1249. .check_eeprom = ath9k_hw_def_check_eeprom,
  1250. .get_eeprom = ath9k_hw_def_get_eeprom,
  1251. .fill_eeprom = ath9k_hw_def_fill_eeprom,
  1252. .dump_eeprom = ath9k_hw_def_dump_eeprom,
  1253. .get_eeprom_ver = ath9k_hw_def_get_eeprom_ver,
  1254. .get_eeprom_rev = ath9k_hw_def_get_eeprom_rev,
  1255. .set_board_values = ath9k_hw_def_set_board_values,
  1256. .set_addac = ath9k_hw_def_set_addac,
  1257. .set_txpower = ath9k_hw_def_set_txpower,
  1258. .get_spur_channel = ath9k_hw_def_get_spur_channel
  1259. };