eeprom_def.c 39 KB

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