eeprom_def.c 42 KB

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