eeprom_def.c 42 KB

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