eeprom_def.c 40 KB

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