eeprom_def.c 42 KB

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