eeprom_def.c 37 KB

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