eeprom_def.c 38 KB

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