eeprom_def.c 39 KB

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