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