eeprom_def.c 38 KB

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