eeprom_def.c 42 KB

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