eeprom_def.c 38 KB

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