eeprom_def.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  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_err(ath9k_hw_common(ah),
  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_err(common, "Reading Magic # failed\n");
  104. return false;
  105. }
  106. if (!ath9k_hw_use_flash(ah)) {
  107. ath_dbg(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_err(common,
  122. "Invalid EEPROM Magic. Endianness mismatch.\n");
  123. return -EINVAL;
  124. }
  125. }
  126. }
  127. ath_dbg(common, ATH_DBG_EEPROM, "need_swap = %s.\n",
  128. need_swap ? "True" : "False");
  129. if (need_swap)
  130. el = swab16(ah->eeprom.def.baseEepHeader.length);
  131. else
  132. el = ah->eeprom.def.baseEepHeader.length;
  133. if (el > sizeof(struct ar5416_eeprom_def))
  134. el = sizeof(struct ar5416_eeprom_def) / sizeof(u16);
  135. else
  136. el = el / sizeof(u16);
  137. eepdata = (u16 *)(&ah->eeprom);
  138. for (i = 0; i < el; i++)
  139. sum ^= *eepdata++;
  140. if (need_swap) {
  141. u32 integer, j;
  142. u16 word;
  143. ath_dbg(common, ATH_DBG_EEPROM,
  144. "EEPROM Endianness is not native.. Changing.\n");
  145. word = swab16(eep->baseEepHeader.length);
  146. eep->baseEepHeader.length = word;
  147. word = swab16(eep->baseEepHeader.checksum);
  148. eep->baseEepHeader.checksum = word;
  149. word = swab16(eep->baseEepHeader.version);
  150. eep->baseEepHeader.version = word;
  151. word = swab16(eep->baseEepHeader.regDmn[0]);
  152. eep->baseEepHeader.regDmn[0] = word;
  153. word = swab16(eep->baseEepHeader.regDmn[1]);
  154. eep->baseEepHeader.regDmn[1] = word;
  155. word = swab16(eep->baseEepHeader.rfSilent);
  156. eep->baseEepHeader.rfSilent = word;
  157. word = swab16(eep->baseEepHeader.blueToothOptions);
  158. eep->baseEepHeader.blueToothOptions = word;
  159. word = swab16(eep->baseEepHeader.deviceCap);
  160. eep->baseEepHeader.deviceCap = word;
  161. for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
  162. struct modal_eep_header *pModal =
  163. &eep->modalHeader[j];
  164. integer = swab32(pModal->antCtrlCommon);
  165. pModal->antCtrlCommon = integer;
  166. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  167. integer = swab32(pModal->antCtrlChain[i]);
  168. pModal->antCtrlChain[i] = integer;
  169. }
  170. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  171. word = swab16(pModal->spurChans[i].spurChan);
  172. pModal->spurChans[i].spurChan = word;
  173. }
  174. }
  175. }
  176. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
  177. ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  178. ath_err(common, "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  179. sum, ah->eep_ops->get_eeprom_ver(ah));
  180. return -EINVAL;
  181. }
  182. /* Enable fixup for AR_AN_TOP2 if necessary */
  183. if (AR_SREV_9280_20_OR_LATER(ah) &&
  184. (eep->baseEepHeader.version & 0xff) > 0x0a &&
  185. eep->baseEepHeader.pwdclkind == 0)
  186. ah->need_an_top2_fixup = 1;
  187. if ((common->bus_ops->ath_bus_type == ATH_USB) &&
  188. (AR_SREV_9280(ah)))
  189. eep->modalHeader[0].xpaBiasLvl = 0;
  190. return 0;
  191. }
  192. static u32 ath9k_hw_def_get_eeprom(struct ath_hw *ah,
  193. enum eeprom_param param)
  194. {
  195. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  196. struct modal_eep_header *pModal = eep->modalHeader;
  197. struct base_eep_header *pBase = &eep->baseEepHeader;
  198. switch (param) {
  199. case EEP_NFTHRESH_5:
  200. return pModal[0].noiseFloorThreshCh[0];
  201. case EEP_NFTHRESH_2:
  202. return pModal[1].noiseFloorThreshCh[0];
  203. case EEP_MAC_LSW:
  204. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  205. case EEP_MAC_MID:
  206. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  207. case EEP_MAC_MSW:
  208. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  209. case EEP_REG_0:
  210. return pBase->regDmn[0];
  211. case EEP_REG_1:
  212. return pBase->regDmn[1];
  213. case EEP_OP_CAP:
  214. return pBase->deviceCap;
  215. case EEP_OP_MODE:
  216. return pBase->opCapFlags;
  217. case EEP_RF_SILENT:
  218. return pBase->rfSilent;
  219. case EEP_OB_5:
  220. return pModal[0].ob;
  221. case EEP_DB_5:
  222. return pModal[0].db;
  223. case EEP_OB_2:
  224. return pModal[1].ob;
  225. case EEP_DB_2:
  226. return pModal[1].db;
  227. case EEP_MINOR_REV:
  228. return AR5416_VER_MASK;
  229. case EEP_TX_MASK:
  230. return pBase->txMask;
  231. case EEP_RX_MASK:
  232. return pBase->rxMask;
  233. case EEP_FSTCLK_5G:
  234. return pBase->fastClk5g;
  235. case EEP_RXGAIN_TYPE:
  236. return pBase->rxGainType;
  237. case EEP_TXGAIN_TYPE:
  238. return pBase->txGainType;
  239. case EEP_OL_PWRCTRL:
  240. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  241. return pBase->openLoopPwrCntl ? true : false;
  242. else
  243. return false;
  244. case EEP_RC_CHAIN_MASK:
  245. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  246. return pBase->rcChainMask;
  247. else
  248. return 0;
  249. case EEP_DAC_HPWR_5G:
  250. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
  251. return pBase->dacHiPwrMode_5G;
  252. else
  253. return 0;
  254. case EEP_FRAC_N_5G:
  255. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
  256. return pBase->frac_n_5g;
  257. else
  258. return 0;
  259. case EEP_PWR_TABLE_OFFSET:
  260. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_21)
  261. return pBase->pwr_table_offset;
  262. else
  263. return AR5416_PWR_TABLE_OFFSET_DB;
  264. default:
  265. return 0;
  266. }
  267. }
  268. static void ath9k_hw_def_set_gain(struct ath_hw *ah,
  269. struct modal_eep_header *pModal,
  270. struct ar5416_eeprom_def *eep,
  271. u8 txRxAttenLocal, int regChainOffset, int i)
  272. {
  273. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
  274. txRxAttenLocal = pModal->txRxAttenCh[i];
  275. if (AR_SREV_9280_20_OR_LATER(ah)) {
  276. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  277. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  278. pModal->bswMargin[i]);
  279. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  280. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  281. pModal->bswAtten[i]);
  282. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  283. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  284. pModal->xatten2Margin[i]);
  285. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  286. AR_PHY_GAIN_2GHZ_XATTEN2_DB,
  287. pModal->xatten2Db[i]);
  288. } else {
  289. REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  290. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  291. ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
  292. | SM(pModal-> bswMargin[i],
  293. AR_PHY_GAIN_2GHZ_BSW_MARGIN));
  294. REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  295. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  296. ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
  297. | SM(pModal->bswAtten[i],
  298. AR_PHY_GAIN_2GHZ_BSW_ATTEN));
  299. }
  300. }
  301. if (AR_SREV_9280_20_OR_LATER(ah)) {
  302. REG_RMW_FIELD(ah,
  303. AR_PHY_RXGAIN + regChainOffset,
  304. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  305. REG_RMW_FIELD(ah,
  306. AR_PHY_RXGAIN + regChainOffset,
  307. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[i]);
  308. } else {
  309. REG_WRITE(ah,
  310. AR_PHY_RXGAIN + regChainOffset,
  311. (REG_READ(ah, AR_PHY_RXGAIN + regChainOffset) &
  312. ~AR_PHY_RXGAIN_TXRX_ATTEN)
  313. | SM(txRxAttenLocal, AR_PHY_RXGAIN_TXRX_ATTEN));
  314. REG_WRITE(ah,
  315. AR_PHY_GAIN_2GHZ + regChainOffset,
  316. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  317. ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
  318. SM(pModal->rxTxMarginCh[i], AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
  319. }
  320. }
  321. static void ath9k_hw_def_set_board_values(struct ath_hw *ah,
  322. struct ath9k_channel *chan)
  323. {
  324. struct modal_eep_header *pModal;
  325. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  326. int i, regChainOffset;
  327. u8 txRxAttenLocal;
  328. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  329. txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
  330. REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon & 0xffff);
  331. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  332. if (AR_SREV_9280(ah)) {
  333. if (i >= 2)
  334. break;
  335. }
  336. if (AR_SREV_5416_20_OR_LATER(ah) &&
  337. (ah->rxchainmask == 5 || ah->txchainmask == 5) && (i != 0))
  338. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  339. else
  340. regChainOffset = i * 0x1000;
  341. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  342. pModal->antCtrlChain[i]);
  343. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  344. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
  345. ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  346. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  347. SM(pModal->iqCalICh[i],
  348. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  349. SM(pModal->iqCalQCh[i],
  350. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  351. if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah))
  352. ath9k_hw_def_set_gain(ah, pModal, eep, txRxAttenLocal,
  353. regChainOffset, i);
  354. }
  355. if (AR_SREV_9280_20_OR_LATER(ah)) {
  356. if (IS_CHAN_2GHZ(chan)) {
  357. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  358. AR_AN_RF2G1_CH0_OB,
  359. AR_AN_RF2G1_CH0_OB_S,
  360. pModal->ob);
  361. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  362. AR_AN_RF2G1_CH0_DB,
  363. AR_AN_RF2G1_CH0_DB_S,
  364. pModal->db);
  365. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  366. AR_AN_RF2G1_CH1_OB,
  367. AR_AN_RF2G1_CH1_OB_S,
  368. pModal->ob_ch1);
  369. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  370. AR_AN_RF2G1_CH1_DB,
  371. AR_AN_RF2G1_CH1_DB_S,
  372. pModal->db_ch1);
  373. } else {
  374. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  375. AR_AN_RF5G1_CH0_OB5,
  376. AR_AN_RF5G1_CH0_OB5_S,
  377. pModal->ob);
  378. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  379. AR_AN_RF5G1_CH0_DB5,
  380. AR_AN_RF5G1_CH0_DB5_S,
  381. pModal->db);
  382. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  383. AR_AN_RF5G1_CH1_OB5,
  384. AR_AN_RF5G1_CH1_OB5_S,
  385. pModal->ob_ch1);
  386. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  387. AR_AN_RF5G1_CH1_DB5,
  388. AR_AN_RF5G1_CH1_DB5_S,
  389. pModal->db_ch1);
  390. }
  391. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  392. AR_AN_TOP2_XPABIAS_LVL,
  393. AR_AN_TOP2_XPABIAS_LVL_S,
  394. pModal->xpaBiasLvl);
  395. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  396. AR_AN_TOP2_LOCALBIAS,
  397. AR_AN_TOP2_LOCALBIAS_S,
  398. !!(pModal->lna_ctl &
  399. LNA_CTL_LOCAL_BIAS));
  400. REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
  401. !!(pModal->lna_ctl & LNA_CTL_FORCE_XPA));
  402. }
  403. REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
  404. pModal->switchSettling);
  405. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
  406. pModal->adcDesiredSize);
  407. if (!AR_SREV_9280_20_OR_LATER(ah))
  408. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  409. AR_PHY_DESIRED_SZ_PGA,
  410. pModal->pgaDesiredSize);
  411. REG_WRITE(ah, AR_PHY_RF_CTL4,
  412. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  413. | SM(pModal->txEndToXpaOff,
  414. AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  415. | SM(pModal->txFrameToXpaOn,
  416. AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  417. | SM(pModal->txFrameToXpaOn,
  418. AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  419. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  420. pModal->txEndToRxOn);
  421. if (AR_SREV_9280_20_OR_LATER(ah)) {
  422. REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
  423. pModal->thresh62);
  424. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  425. AR_PHY_EXT_CCA0_THRESH62,
  426. pModal->thresh62);
  427. } else {
  428. REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
  429. pModal->thresh62);
  430. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  431. AR_PHY_EXT_CCA_THRESH62,
  432. pModal->thresh62);
  433. }
  434. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
  435. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  436. AR_PHY_TX_END_DATA_START,
  437. pModal->txFrameToDataStart);
  438. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
  439. pModal->txFrameToPaOn);
  440. }
  441. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
  442. if (IS_CHAN_HT40(chan))
  443. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  444. AR_PHY_SETTLING_SWITCH,
  445. pModal->swSettleHt40);
  446. }
  447. if (AR_SREV_9280_20_OR_LATER(ah) &&
  448. AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  449. REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL,
  450. AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK,
  451. pModal->miscBits);
  452. if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) {
  453. if (IS_CHAN_2GHZ(chan))
  454. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
  455. eep->baseEepHeader.dacLpMode);
  456. else if (eep->baseEepHeader.dacHiPwrMode_5G)
  457. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, 0);
  458. else
  459. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
  460. eep->baseEepHeader.dacLpMode);
  461. udelay(100);
  462. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, AR_PHY_FRAME_CTL_TX_CLIP,
  463. pModal->miscBits >> 2);
  464. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL9,
  465. AR_PHY_TX_DESIRED_SCALE_CCK,
  466. eep->baseEepHeader.desiredScaleCCK);
  467. }
  468. }
  469. static void ath9k_hw_def_set_addac(struct ath_hw *ah,
  470. struct ath9k_channel *chan)
  471. {
  472. #define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt])
  473. struct modal_eep_header *pModal;
  474. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  475. u8 biaslevel;
  476. if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
  477. return;
  478. if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
  479. return;
  480. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  481. if (pModal->xpaBiasLvl != 0xff) {
  482. biaslevel = pModal->xpaBiasLvl;
  483. } else {
  484. u16 resetFreqBin, freqBin, freqCount = 0;
  485. struct chan_centers centers;
  486. ath9k_hw_get_channel_centers(ah, chan, &centers);
  487. resetFreqBin = FREQ2FBIN(centers.synth_center,
  488. IS_CHAN_2GHZ(chan));
  489. freqBin = XPA_LVL_FREQ(0) & 0xff;
  490. biaslevel = (u8) (XPA_LVL_FREQ(0) >> 14);
  491. freqCount++;
  492. while (freqCount < 3) {
  493. if (XPA_LVL_FREQ(freqCount) == 0x0)
  494. break;
  495. freqBin = XPA_LVL_FREQ(freqCount) & 0xff;
  496. if (resetFreqBin >= freqBin)
  497. biaslevel = (u8)(XPA_LVL_FREQ(freqCount) >> 14);
  498. else
  499. break;
  500. freqCount++;
  501. }
  502. }
  503. if (IS_CHAN_2GHZ(chan)) {
  504. INI_RA(&ah->iniAddac, 7, 1) = (INI_RA(&ah->iniAddac,
  505. 7, 1) & (~0x18)) | biaslevel << 3;
  506. } else {
  507. INI_RA(&ah->iniAddac, 6, 1) = (INI_RA(&ah->iniAddac,
  508. 6, 1) & (~0xc0)) | biaslevel << 6;
  509. }
  510. #undef XPA_LVL_FREQ
  511. }
  512. static int16_t ath9k_change_gain_boundary_setting(struct ath_hw *ah,
  513. u16 *gb,
  514. u16 numXpdGain,
  515. u16 pdGainOverlap_t2,
  516. int8_t pwr_table_offset,
  517. int16_t *diff)
  518. {
  519. u16 k;
  520. /* Prior to writing the boundaries or the pdadc vs. power table
  521. * into the chip registers the default starting point on the pdadc
  522. * vs. power table needs to be checked and the curve boundaries
  523. * adjusted accordingly
  524. */
  525. if (AR_SREV_9280_20_OR_LATER(ah)) {
  526. u16 gb_limit;
  527. if (AR5416_PWR_TABLE_OFFSET_DB != pwr_table_offset) {
  528. /* get the difference in dB */
  529. *diff = (u16)(pwr_table_offset - AR5416_PWR_TABLE_OFFSET_DB);
  530. /* get the number of half dB steps */
  531. *diff *= 2;
  532. /* change the original gain boundary settings
  533. * by the number of half dB steps
  534. */
  535. for (k = 0; k < numXpdGain; k++)
  536. gb[k] = (u16)(gb[k] - *diff);
  537. }
  538. /* Because of a hardware limitation, ensure the gain boundary
  539. * is not larger than (63 - overlap)
  540. */
  541. gb_limit = (u16)(MAX_RATE_POWER - pdGainOverlap_t2);
  542. for (k = 0; k < numXpdGain; k++)
  543. gb[k] = (u16)min(gb_limit, gb[k]);
  544. }
  545. return *diff;
  546. }
  547. static void ath9k_adjust_pdadc_values(struct ath_hw *ah,
  548. int8_t pwr_table_offset,
  549. int16_t diff,
  550. u8 *pdadcValues)
  551. {
  552. #define NUM_PDADC(diff) (AR5416_NUM_PDADC_VALUES - diff)
  553. u16 k;
  554. /* If this is a board that has a pwrTableOffset that differs from
  555. * the default AR5416_PWR_TABLE_OFFSET_DB then the start of the
  556. * pdadc vs pwr table needs to be adjusted prior to writing to the
  557. * chip.
  558. */
  559. if (AR_SREV_9280_20_OR_LATER(ah)) {
  560. if (AR5416_PWR_TABLE_OFFSET_DB != pwr_table_offset) {
  561. /* shift the table to start at the new offset */
  562. for (k = 0; k < (u16)NUM_PDADC(diff); k++ ) {
  563. pdadcValues[k] = pdadcValues[k + diff];
  564. }
  565. /* fill the back of the table */
  566. for (k = (u16)NUM_PDADC(diff); k < NUM_PDADC(0); k++) {
  567. pdadcValues[k] = pdadcValues[NUM_PDADC(diff)];
  568. }
  569. }
  570. }
  571. #undef NUM_PDADC
  572. }
  573. static void ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
  574. struct ath9k_channel *chan,
  575. int16_t *pTxPowerIndexOffset)
  576. {
  577. #define SM_PD_GAIN(x) SM(0x38, AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##x)
  578. #define SM_PDGAIN_B(x, y) \
  579. SM((gainBoundaries[x]), AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##y)
  580. struct ath_common *common = ath9k_hw_common(ah);
  581. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  582. struct cal_data_per_freq *pRawDataset;
  583. u8 *pCalBChans = NULL;
  584. u16 pdGainOverlap_t2;
  585. static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
  586. u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
  587. u16 numPiers, i, j;
  588. int16_t diff = 0;
  589. u16 numXpdGain, xpdMask;
  590. u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
  591. u32 reg32, regOffset, regChainOffset;
  592. int16_t modalIdx;
  593. int8_t pwr_table_offset;
  594. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  595. xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
  596. pwr_table_offset = ah->eep_ops->get_eeprom(ah, EEP_PWR_TABLE_OFFSET);
  597. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  598. AR5416_EEP_MINOR_VER_2) {
  599. pdGainOverlap_t2 =
  600. pEepData->modalHeader[modalIdx].pdGainOverlap;
  601. } else {
  602. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  603. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  604. }
  605. if (IS_CHAN_2GHZ(chan)) {
  606. pCalBChans = pEepData->calFreqPier2G;
  607. numPiers = AR5416_NUM_2G_CAL_PIERS;
  608. } else {
  609. pCalBChans = pEepData->calFreqPier5G;
  610. numPiers = AR5416_NUM_5G_CAL_PIERS;
  611. }
  612. if (OLC_FOR_AR9280_20_LATER && IS_CHAN_2GHZ(chan)) {
  613. pRawDataset = pEepData->calPierData2G[0];
  614. ah->initPDADC = ((struct calDataPerFreqOpLoop *)
  615. pRawDataset)->vpdPdg[0][0];
  616. }
  617. numXpdGain = 0;
  618. for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
  619. if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
  620. if (numXpdGain >= AR5416_NUM_PD_GAINS)
  621. break;
  622. xpdGainValues[numXpdGain] =
  623. (u16)(AR5416_PD_GAINS_IN_MASK - i);
  624. numXpdGain++;
  625. }
  626. }
  627. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  628. (numXpdGain - 1) & 0x3);
  629. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  630. xpdGainValues[0]);
  631. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  632. xpdGainValues[1]);
  633. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  634. xpdGainValues[2]);
  635. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  636. if (AR_SREV_5416_20_OR_LATER(ah) &&
  637. (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
  638. (i != 0)) {
  639. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  640. } else
  641. regChainOffset = i * 0x1000;
  642. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  643. if (IS_CHAN_2GHZ(chan))
  644. pRawDataset = pEepData->calPierData2G[i];
  645. else
  646. pRawDataset = pEepData->calPierData5G[i];
  647. if (OLC_FOR_AR9280_20_LATER) {
  648. u8 pcdacIdx;
  649. u8 txPower;
  650. ath9k_get_txgain_index(ah, chan,
  651. (struct calDataPerFreqOpLoop *)pRawDataset,
  652. pCalBChans, numPiers, &txPower, &pcdacIdx);
  653. ath9k_olc_get_pdadcs(ah, pcdacIdx,
  654. txPower/2, pdadcValues);
  655. } else {
  656. ath9k_hw_get_gain_boundaries_pdadcs(ah,
  657. chan, pRawDataset,
  658. pCalBChans, numPiers,
  659. pdGainOverlap_t2,
  660. gainBoundaries,
  661. pdadcValues,
  662. numXpdGain);
  663. }
  664. diff = ath9k_change_gain_boundary_setting(ah,
  665. gainBoundaries,
  666. numXpdGain,
  667. pdGainOverlap_t2,
  668. pwr_table_offset,
  669. &diff);
  670. if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
  671. if (OLC_FOR_AR9280_20_LATER) {
  672. REG_WRITE(ah,
  673. AR_PHY_TPCRG5 + regChainOffset,
  674. SM(0x6,
  675. AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
  676. SM_PD_GAIN(1) | SM_PD_GAIN(2) |
  677. SM_PD_GAIN(3) | SM_PD_GAIN(4));
  678. } else {
  679. REG_WRITE(ah,
  680. AR_PHY_TPCRG5 + regChainOffset,
  681. SM(pdGainOverlap_t2,
  682. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)|
  683. SM_PDGAIN_B(0, 1) |
  684. SM_PDGAIN_B(1, 2) |
  685. SM_PDGAIN_B(2, 3) |
  686. SM_PDGAIN_B(3, 4));
  687. }
  688. }
  689. ath9k_adjust_pdadc_values(ah, pwr_table_offset,
  690. diff, pdadcValues);
  691. regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
  692. for (j = 0; j < 32; j++) {
  693. reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
  694. ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
  695. ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
  696. ((pdadcValues[4 * j + 3] & 0xFF) << 24);
  697. REG_WRITE(ah, regOffset, reg32);
  698. ath_dbg(common, ATH_DBG_EEPROM,
  699. "PDADC (%d,%4x): %4.4x %8.8x\n",
  700. i, regChainOffset, regOffset,
  701. reg32);
  702. ath_dbg(common, ATH_DBG_EEPROM,
  703. "PDADC: Chain %d | PDADC %3d "
  704. "Value %3d | PDADC %3d Value %3d | "
  705. "PDADC %3d Value %3d | PDADC %3d "
  706. "Value %3d |\n",
  707. i, 4 * j, pdadcValues[4 * j],
  708. 4 * j + 1, pdadcValues[4 * j + 1],
  709. 4 * j + 2, pdadcValues[4 * j + 2],
  710. 4 * j + 3, pdadcValues[4 * j + 3]);
  711. regOffset += 4;
  712. }
  713. }
  714. }
  715. *pTxPowerIndexOffset = 0;
  716. #undef SM_PD_GAIN
  717. #undef SM_PDGAIN_B
  718. }
  719. static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
  720. struct ath9k_channel *chan,
  721. int16_t *ratesArray,
  722. u16 cfgCtl,
  723. u16 AntennaReduction,
  724. u16 twiceMaxRegulatoryPower,
  725. u16 powerLimit)
  726. {
  727. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */
  728. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 9 /* 10*log10(3)*2 */
  729. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  730. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  731. u16 twiceMaxEdgePower = MAX_RATE_POWER;
  732. static const u16 tpScaleReductionTable[5] =
  733. { 0, 3, 6, 9, MAX_RATE_POWER };
  734. int i;
  735. int16_t twiceLargestAntenna;
  736. struct cal_ctl_data *rep;
  737. struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
  738. 0, { 0, 0, 0, 0}
  739. };
  740. struct cal_target_power_leg targetPowerOfdmExt = {
  741. 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
  742. 0, { 0, 0, 0, 0 }
  743. };
  744. struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
  745. 0, {0, 0, 0, 0}
  746. };
  747. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  748. static const u16 ctlModesFor11a[] = {
  749. CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40
  750. };
  751. static const u16 ctlModesFor11g[] = {
  752. CTL_11B, CTL_11G, CTL_2GHT20,
  753. CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
  754. };
  755. u16 numCtlModes;
  756. const u16 *pCtlMode;
  757. u16 ctlMode, freq;
  758. struct chan_centers centers;
  759. int tx_chainmask;
  760. u16 twiceMinEdgePower;
  761. tx_chainmask = ah->txchainmask;
  762. ath9k_hw_get_channel_centers(ah, chan, &centers);
  763. twiceLargestAntenna = max(
  764. pEepData->modalHeader
  765. [IS_CHAN_2GHZ(chan)].antennaGainCh[0],
  766. pEepData->modalHeader
  767. [IS_CHAN_2GHZ(chan)].antennaGainCh[1]);
  768. twiceLargestAntenna = max((u8)twiceLargestAntenna,
  769. pEepData->modalHeader
  770. [IS_CHAN_2GHZ(chan)].antennaGainCh[2]);
  771. twiceLargestAntenna = (int16_t)min(AntennaReduction -
  772. twiceLargestAntenna, 0);
  773. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  774. if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX) {
  775. maxRegAllowedPower -=
  776. (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
  777. }
  778. scaledPower = min(powerLimit, maxRegAllowedPower);
  779. switch (ar5416_get_ntxchains(tx_chainmask)) {
  780. case 1:
  781. break;
  782. case 2:
  783. if (scaledPower > REDUCE_SCALED_POWER_BY_TWO_CHAIN)
  784. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  785. else
  786. scaledPower = 0;
  787. break;
  788. case 3:
  789. if (scaledPower > REDUCE_SCALED_POWER_BY_THREE_CHAIN)
  790. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  791. else
  792. scaledPower = 0;
  793. break;
  794. }
  795. if (IS_CHAN_2GHZ(chan)) {
  796. numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
  797. SUB_NUM_CTL_MODES_AT_2G_40;
  798. pCtlMode = ctlModesFor11g;
  799. ath9k_hw_get_legacy_target_powers(ah, chan,
  800. pEepData->calTargetPowerCck,
  801. AR5416_NUM_2G_CCK_TARGET_POWERS,
  802. &targetPowerCck, 4, false);
  803. ath9k_hw_get_legacy_target_powers(ah, chan,
  804. pEepData->calTargetPower2G,
  805. AR5416_NUM_2G_20_TARGET_POWERS,
  806. &targetPowerOfdm, 4, false);
  807. ath9k_hw_get_target_powers(ah, chan,
  808. pEepData->calTargetPower2GHT20,
  809. AR5416_NUM_2G_20_TARGET_POWERS,
  810. &targetPowerHt20, 8, false);
  811. if (IS_CHAN_HT40(chan)) {
  812. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  813. ath9k_hw_get_target_powers(ah, chan,
  814. pEepData->calTargetPower2GHT40,
  815. AR5416_NUM_2G_40_TARGET_POWERS,
  816. &targetPowerHt40, 8, true);
  817. ath9k_hw_get_legacy_target_powers(ah, chan,
  818. pEepData->calTargetPowerCck,
  819. AR5416_NUM_2G_CCK_TARGET_POWERS,
  820. &targetPowerCckExt, 4, true);
  821. ath9k_hw_get_legacy_target_powers(ah, chan,
  822. pEepData->calTargetPower2G,
  823. AR5416_NUM_2G_20_TARGET_POWERS,
  824. &targetPowerOfdmExt, 4, true);
  825. }
  826. } else {
  827. numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
  828. SUB_NUM_CTL_MODES_AT_5G_40;
  829. pCtlMode = ctlModesFor11a;
  830. ath9k_hw_get_legacy_target_powers(ah, chan,
  831. pEepData->calTargetPower5G,
  832. AR5416_NUM_5G_20_TARGET_POWERS,
  833. &targetPowerOfdm, 4, false);
  834. ath9k_hw_get_target_powers(ah, chan,
  835. pEepData->calTargetPower5GHT20,
  836. AR5416_NUM_5G_20_TARGET_POWERS,
  837. &targetPowerHt20, 8, false);
  838. if (IS_CHAN_HT40(chan)) {
  839. numCtlModes = ARRAY_SIZE(ctlModesFor11a);
  840. ath9k_hw_get_target_powers(ah, chan,
  841. pEepData->calTargetPower5GHT40,
  842. AR5416_NUM_5G_40_TARGET_POWERS,
  843. &targetPowerHt40, 8, true);
  844. ath9k_hw_get_legacy_target_powers(ah, chan,
  845. pEepData->calTargetPower5G,
  846. AR5416_NUM_5G_20_TARGET_POWERS,
  847. &targetPowerOfdmExt, 4, true);
  848. }
  849. }
  850. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  851. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  852. (pCtlMode[ctlMode] == CTL_2GHT40);
  853. if (isHt40CtlMode)
  854. freq = centers.synth_center;
  855. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  856. freq = centers.ext_center;
  857. else
  858. freq = centers.ctl_center;
  859. if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
  860. ah->eep_ops->get_eeprom_rev(ah) <= 2)
  861. twiceMaxEdgePower = MAX_RATE_POWER;
  862. for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  863. if ((((cfgCtl & ~CTL_MODE_M) |
  864. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  865. pEepData->ctlIndex[i]) ||
  866. (((cfgCtl & ~CTL_MODE_M) |
  867. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  868. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
  869. rep = &(pEepData->ctlData[i]);
  870. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  871. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
  872. IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
  873. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  874. twiceMaxEdgePower = min(twiceMaxEdgePower,
  875. twiceMinEdgePower);
  876. } else {
  877. twiceMaxEdgePower = twiceMinEdgePower;
  878. break;
  879. }
  880. }
  881. }
  882. minCtlPower = min(twiceMaxEdgePower, scaledPower);
  883. switch (pCtlMode[ctlMode]) {
  884. case CTL_11B:
  885. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  886. targetPowerCck.tPow2x[i] =
  887. min((u16)targetPowerCck.tPow2x[i],
  888. minCtlPower);
  889. }
  890. break;
  891. case CTL_11A:
  892. case CTL_11G:
  893. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  894. targetPowerOfdm.tPow2x[i] =
  895. min((u16)targetPowerOfdm.tPow2x[i],
  896. minCtlPower);
  897. }
  898. break;
  899. case CTL_5GHT20:
  900. case CTL_2GHT20:
  901. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  902. targetPowerHt20.tPow2x[i] =
  903. min((u16)targetPowerHt20.tPow2x[i],
  904. minCtlPower);
  905. }
  906. break;
  907. case CTL_11B_EXT:
  908. targetPowerCckExt.tPow2x[0] = min((u16)
  909. targetPowerCckExt.tPow2x[0],
  910. minCtlPower);
  911. break;
  912. case CTL_11A_EXT:
  913. case CTL_11G_EXT:
  914. targetPowerOfdmExt.tPow2x[0] = min((u16)
  915. targetPowerOfdmExt.tPow2x[0],
  916. minCtlPower);
  917. break;
  918. case CTL_5GHT40:
  919. case CTL_2GHT40:
  920. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  921. targetPowerHt40.tPow2x[i] =
  922. min((u16)targetPowerHt40.tPow2x[i],
  923. minCtlPower);
  924. }
  925. break;
  926. default:
  927. break;
  928. }
  929. }
  930. ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
  931. ratesArray[rate18mb] = ratesArray[rate24mb] =
  932. targetPowerOfdm.tPow2x[0];
  933. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  934. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  935. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  936. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  937. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  938. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  939. if (IS_CHAN_2GHZ(chan)) {
  940. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  941. ratesArray[rate2s] = ratesArray[rate2l] =
  942. targetPowerCck.tPow2x[1];
  943. ratesArray[rate5_5s] = ratesArray[rate5_5l] =
  944. targetPowerCck.tPow2x[2];
  945. ratesArray[rate11s] = ratesArray[rate11l] =
  946. targetPowerCck.tPow2x[3];
  947. }
  948. if (IS_CHAN_HT40(chan)) {
  949. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  950. ratesArray[rateHt40_0 + i] =
  951. targetPowerHt40.tPow2x[i];
  952. }
  953. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  954. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  955. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  956. if (IS_CHAN_2GHZ(chan)) {
  957. ratesArray[rateExtCck] =
  958. targetPowerCckExt.tPow2x[0];
  959. }
  960. }
  961. }
  962. static void ath9k_hw_def_set_txpower(struct ath_hw *ah,
  963. struct ath9k_channel *chan,
  964. u16 cfgCtl,
  965. u8 twiceAntennaReduction,
  966. u8 twiceMaxRegulatoryPower,
  967. u8 powerLimit, bool test)
  968. {
  969. #define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
  970. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  971. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  972. struct modal_eep_header *pModal =
  973. &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
  974. int16_t ratesArray[Ar5416RateSize];
  975. int16_t txPowerIndexOffset = 0;
  976. u8 ht40PowerIncForPdadc = 2;
  977. int i, cck_ofdm_delta = 0;
  978. memset(ratesArray, 0, sizeof(ratesArray));
  979. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  980. AR5416_EEP_MINOR_VER_2) {
  981. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  982. }
  983. ath9k_hw_set_def_power_per_rate_table(ah, chan,
  984. &ratesArray[0], cfgCtl,
  985. twiceAntennaReduction,
  986. twiceMaxRegulatoryPower,
  987. powerLimit);
  988. ath9k_hw_set_def_power_cal_table(ah, chan, &txPowerIndexOffset);
  989. regulatory->max_power_level = 0;
  990. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  991. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  992. if (ratesArray[i] > MAX_RATE_POWER)
  993. ratesArray[i] = MAX_RATE_POWER;
  994. if (ratesArray[i] > regulatory->max_power_level)
  995. regulatory->max_power_level = ratesArray[i];
  996. }
  997. if (!test) {
  998. i = rate6mb;
  999. if (IS_CHAN_HT40(chan))
  1000. i = rateHt40_0;
  1001. else if (IS_CHAN_HT20(chan))
  1002. i = rateHt20_0;
  1003. regulatory->max_power_level = ratesArray[i];
  1004. }
  1005. switch(ar5416_get_ntxchains(ah->txchainmask)) {
  1006. case 1:
  1007. break;
  1008. case 2:
  1009. regulatory->max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
  1010. break;
  1011. case 3:
  1012. regulatory->max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
  1013. break;
  1014. default:
  1015. ath_dbg(ath9k_hw_common(ah), ATH_DBG_EEPROM,
  1016. "Invalid chainmask configuration\n");
  1017. break;
  1018. }
  1019. if (test)
  1020. return;
  1021. if (AR_SREV_9280_20_OR_LATER(ah)) {
  1022. for (i = 0; i < Ar5416RateSize; i++) {
  1023. int8_t pwr_table_offset;
  1024. pwr_table_offset = ah->eep_ops->get_eeprom(ah,
  1025. EEP_PWR_TABLE_OFFSET);
  1026. ratesArray[i] -= pwr_table_offset * 2;
  1027. }
  1028. }
  1029. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  1030. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  1031. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  1032. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  1033. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  1034. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  1035. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  1036. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  1037. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  1038. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  1039. if (IS_CHAN_2GHZ(chan)) {
  1040. if (OLC_FOR_AR9280_20_LATER) {
  1041. cck_ofdm_delta = 2;
  1042. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  1043. ATH9K_POW_SM(RT_AR_DELTA(rate2s), 24)
  1044. | ATH9K_POW_SM(RT_AR_DELTA(rate2l), 16)
  1045. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  1046. | ATH9K_POW_SM(RT_AR_DELTA(rate1l), 0));
  1047. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  1048. ATH9K_POW_SM(RT_AR_DELTA(rate11s), 24)
  1049. | ATH9K_POW_SM(RT_AR_DELTA(rate11l), 16)
  1050. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5s), 8)
  1051. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5l), 0));
  1052. } else {
  1053. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  1054. ATH9K_POW_SM(ratesArray[rate2s], 24)
  1055. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  1056. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  1057. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  1058. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  1059. ATH9K_POW_SM(ratesArray[rate11s], 24)
  1060. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  1061. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  1062. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  1063. }
  1064. }
  1065. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  1066. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  1067. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  1068. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  1069. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  1070. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  1071. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  1072. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  1073. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  1074. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  1075. if (IS_CHAN_HT40(chan)) {
  1076. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  1077. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  1078. ht40PowerIncForPdadc, 24)
  1079. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  1080. ht40PowerIncForPdadc, 16)
  1081. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  1082. ht40PowerIncForPdadc, 8)
  1083. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  1084. ht40PowerIncForPdadc, 0));
  1085. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  1086. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  1087. ht40PowerIncForPdadc, 24)
  1088. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  1089. ht40PowerIncForPdadc, 16)
  1090. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  1091. ht40PowerIncForPdadc, 8)
  1092. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  1093. ht40PowerIncForPdadc, 0));
  1094. if (OLC_FOR_AR9280_20_LATER) {
  1095. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  1096. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  1097. | ATH9K_POW_SM(RT_AR_DELTA(rateExtCck), 16)
  1098. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  1099. | ATH9K_POW_SM(RT_AR_DELTA(rateDupCck), 0));
  1100. } else {
  1101. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  1102. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  1103. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  1104. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  1105. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  1106. }
  1107. }
  1108. REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
  1109. ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
  1110. | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
  1111. }
  1112. static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
  1113. {
  1114. #define EEP_DEF_SPURCHAN \
  1115. (ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan)
  1116. struct ath_common *common = ath9k_hw_common(ah);
  1117. u16 spur_val = AR_NO_SPUR;
  1118. ath_dbg(common, ATH_DBG_ANI,
  1119. "Getting spur idx:%d is2Ghz:%d val:%x\n",
  1120. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  1121. switch (ah->config.spurmode) {
  1122. case SPUR_DISABLE:
  1123. break;
  1124. case SPUR_ENABLE_IOCTL:
  1125. spur_val = ah->config.spurchans[i][is2GHz];
  1126. ath_dbg(common, ATH_DBG_ANI,
  1127. "Getting spur val from new loc. %d\n", spur_val);
  1128. break;
  1129. case SPUR_ENABLE_EEPROM:
  1130. spur_val = EEP_DEF_SPURCHAN;
  1131. break;
  1132. }
  1133. return spur_val;
  1134. #undef EEP_DEF_SPURCHAN
  1135. }
  1136. const struct eeprom_ops eep_def_ops = {
  1137. .check_eeprom = ath9k_hw_def_check_eeprom,
  1138. .get_eeprom = ath9k_hw_def_get_eeprom,
  1139. .fill_eeprom = ath9k_hw_def_fill_eeprom,
  1140. .get_eeprom_ver = ath9k_hw_def_get_eeprom_ver,
  1141. .get_eeprom_rev = ath9k_hw_def_get_eeprom_rev,
  1142. .set_board_values = ath9k_hw_def_set_board_values,
  1143. .set_addac = ath9k_hw_def_set_addac,
  1144. .set_txpower = ath9k_hw_def_set_txpower,
  1145. .get_spur_channel = ath9k_hw_def_get_spur_channel
  1146. };