eeprom_def.c 38 KB

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