eeprom_4k.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  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 int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah)
  19. {
  20. return ((ah->eeprom.map4k.baseEepHeader.version >> 12) & 0xF);
  21. }
  22. static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah)
  23. {
  24. return ((ah->eeprom.map4k.baseEepHeader.version) & 0xFFF);
  25. }
  26. #define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
  27. static bool __ath9k_hw_4k_fill_eeprom(struct ath_hw *ah)
  28. {
  29. struct ath_common *common = ath9k_hw_common(ah);
  30. u16 *eep_data = (u16 *)&ah->eeprom.map4k;
  31. int addr, eep_start_loc = 64;
  32. for (addr = 0; addr < SIZE_EEPROM_4K; addr++) {
  33. if (!ath9k_hw_nvram_read(common, addr + eep_start_loc, eep_data)) {
  34. ath_dbg(common, ATH_DBG_EEPROM,
  35. "Unable to read eeprom region\n");
  36. return false;
  37. }
  38. eep_data++;
  39. }
  40. return true;
  41. }
  42. static bool __ath9k_hw_usb_4k_fill_eeprom(struct ath_hw *ah)
  43. {
  44. u16 *eep_data = (u16 *)&ah->eeprom.map4k;
  45. ath9k_hw_usb_gen_fill_eeprom(ah, eep_data, 64, SIZE_EEPROM_4K);
  46. return true;
  47. }
  48. static bool ath9k_hw_4k_fill_eeprom(struct ath_hw *ah)
  49. {
  50. struct ath_common *common = ath9k_hw_common(ah);
  51. if (!ath9k_hw_use_flash(ah)) {
  52. ath_dbg(common, ATH_DBG_EEPROM,
  53. "Reading from EEPROM, not flash\n");
  54. }
  55. if (common->bus_ops->ath_bus_type == ATH_USB)
  56. return __ath9k_hw_usb_4k_fill_eeprom(ah);
  57. else
  58. return __ath9k_hw_4k_fill_eeprom(ah);
  59. }
  60. #undef SIZE_EEPROM_4K
  61. static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah)
  62. {
  63. #define EEPROM_4K_SIZE (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
  64. struct ath_common *common = ath9k_hw_common(ah);
  65. struct ar5416_eeprom_4k *eep =
  66. (struct ar5416_eeprom_4k *) &ah->eeprom.map4k;
  67. u16 *eepdata, temp, magic, magic2;
  68. u32 sum = 0, el;
  69. bool need_swap = false;
  70. int i, addr;
  71. if (!ath9k_hw_use_flash(ah)) {
  72. if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET,
  73. &magic)) {
  74. ath_err(common, "Reading Magic # failed\n");
  75. return false;
  76. }
  77. ath_dbg(common, ATH_DBG_EEPROM,
  78. "Read Magic = 0x%04X\n", magic);
  79. if (magic != AR5416_EEPROM_MAGIC) {
  80. magic2 = swab16(magic);
  81. if (magic2 == AR5416_EEPROM_MAGIC) {
  82. need_swap = true;
  83. eepdata = (u16 *) (&ah->eeprom);
  84. for (addr = 0; addr < EEPROM_4K_SIZE; addr++) {
  85. temp = swab16(*eepdata);
  86. *eepdata = temp;
  87. eepdata++;
  88. }
  89. } else {
  90. ath_err(common,
  91. "Invalid EEPROM Magic. Endianness mismatch.\n");
  92. return -EINVAL;
  93. }
  94. }
  95. }
  96. ath_dbg(common, ATH_DBG_EEPROM, "need_swap = %s.\n",
  97. need_swap ? "True" : "False");
  98. if (need_swap)
  99. el = swab16(ah->eeprom.map4k.baseEepHeader.length);
  100. else
  101. el = ah->eeprom.map4k.baseEepHeader.length;
  102. if (el > sizeof(struct ar5416_eeprom_4k))
  103. el = sizeof(struct ar5416_eeprom_4k) / sizeof(u16);
  104. else
  105. el = el / sizeof(u16);
  106. eepdata = (u16 *)(&ah->eeprom);
  107. for (i = 0; i < el; i++)
  108. sum ^= *eepdata++;
  109. if (need_swap) {
  110. u32 integer;
  111. u16 word;
  112. ath_dbg(common, ATH_DBG_EEPROM,
  113. "EEPROM Endianness is not native.. Changing\n");
  114. word = swab16(eep->baseEepHeader.length);
  115. eep->baseEepHeader.length = word;
  116. word = swab16(eep->baseEepHeader.checksum);
  117. eep->baseEepHeader.checksum = word;
  118. word = swab16(eep->baseEepHeader.version);
  119. eep->baseEepHeader.version = word;
  120. word = swab16(eep->baseEepHeader.regDmn[0]);
  121. eep->baseEepHeader.regDmn[0] = word;
  122. word = swab16(eep->baseEepHeader.regDmn[1]);
  123. eep->baseEepHeader.regDmn[1] = word;
  124. word = swab16(eep->baseEepHeader.rfSilent);
  125. eep->baseEepHeader.rfSilent = word;
  126. word = swab16(eep->baseEepHeader.blueToothOptions);
  127. eep->baseEepHeader.blueToothOptions = word;
  128. word = swab16(eep->baseEepHeader.deviceCap);
  129. eep->baseEepHeader.deviceCap = word;
  130. integer = swab32(eep->modalHeader.antCtrlCommon);
  131. eep->modalHeader.antCtrlCommon = integer;
  132. for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
  133. integer = swab32(eep->modalHeader.antCtrlChain[i]);
  134. eep->modalHeader.antCtrlChain[i] = integer;
  135. }
  136. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  137. word = swab16(eep->modalHeader.spurChans[i].spurChan);
  138. eep->modalHeader.spurChans[i].spurChan = word;
  139. }
  140. }
  141. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
  142. ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  143. ath_err(common, "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  144. sum, ah->eep_ops->get_eeprom_ver(ah));
  145. return -EINVAL;
  146. }
  147. return 0;
  148. #undef EEPROM_4K_SIZE
  149. }
  150. static u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah,
  151. enum eeprom_param param)
  152. {
  153. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  154. struct modal_eep_4k_header *pModal = &eep->modalHeader;
  155. struct base_eep_header_4k *pBase = &eep->baseEepHeader;
  156. u16 ver_minor;
  157. ver_minor = pBase->version & AR5416_EEP_VER_MINOR_MASK;
  158. switch (param) {
  159. case EEP_NFTHRESH_2:
  160. return pModal->noiseFloorThreshCh[0];
  161. case EEP_MAC_LSW:
  162. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  163. case EEP_MAC_MID:
  164. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  165. case EEP_MAC_MSW:
  166. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  167. case EEP_REG_0:
  168. return pBase->regDmn[0];
  169. case EEP_REG_1:
  170. return pBase->regDmn[1];
  171. case EEP_OP_CAP:
  172. return pBase->deviceCap;
  173. case EEP_OP_MODE:
  174. return pBase->opCapFlags;
  175. case EEP_RF_SILENT:
  176. return pBase->rfSilent;
  177. case EEP_OB_2:
  178. return pModal->ob_0;
  179. case EEP_DB_2:
  180. return pModal->db1_1;
  181. case EEP_MINOR_REV:
  182. return ver_minor;
  183. case EEP_TX_MASK:
  184. return pBase->txMask;
  185. case EEP_RX_MASK:
  186. return pBase->rxMask;
  187. case EEP_FRAC_N_5G:
  188. return 0;
  189. case EEP_PWR_TABLE_OFFSET:
  190. return AR5416_PWR_TABLE_OFFSET_DB;
  191. case EEP_MODAL_VER:
  192. return pModal->version;
  193. case EEP_ANT_DIV_CTL1:
  194. return pModal->antdiv_ctl1;
  195. case EEP_TXGAIN_TYPE:
  196. if (ver_minor >= AR5416_EEP_MINOR_VER_19)
  197. return pBase->txGainType;
  198. else
  199. return AR5416_EEP_TXGAIN_ORIGINAL;
  200. default:
  201. return 0;
  202. }
  203. }
  204. static void ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah,
  205. struct ath9k_channel *chan,
  206. int16_t *pTxPowerIndexOffset)
  207. {
  208. struct ath_common *common = ath9k_hw_common(ah);
  209. struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
  210. struct cal_data_per_freq_4k *pRawDataset;
  211. u8 *pCalBChans = NULL;
  212. u16 pdGainOverlap_t2;
  213. static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
  214. u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
  215. u16 numPiers, i, j;
  216. u16 numXpdGain, xpdMask;
  217. u16 xpdGainValues[AR5416_EEP4K_NUM_PD_GAINS] = { 0, 0 };
  218. u32 reg32, regOffset, regChainOffset;
  219. xpdMask = pEepData->modalHeader.xpdGain;
  220. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  221. AR5416_EEP_MINOR_VER_2) {
  222. pdGainOverlap_t2 =
  223. pEepData->modalHeader.pdGainOverlap;
  224. } else {
  225. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  226. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  227. }
  228. pCalBChans = pEepData->calFreqPier2G;
  229. numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS;
  230. numXpdGain = 0;
  231. for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
  232. if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
  233. if (numXpdGain >= AR5416_EEP4K_NUM_PD_GAINS)
  234. break;
  235. xpdGainValues[numXpdGain] =
  236. (u16)(AR5416_PD_GAINS_IN_MASK - i);
  237. numXpdGain++;
  238. }
  239. }
  240. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  241. (numXpdGain - 1) & 0x3);
  242. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  243. xpdGainValues[0]);
  244. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  245. xpdGainValues[1]);
  246. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, 0);
  247. for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
  248. if (AR_SREV_5416_20_OR_LATER(ah) &&
  249. (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
  250. (i != 0)) {
  251. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  252. } else
  253. regChainOffset = i * 0x1000;
  254. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  255. pRawDataset = pEepData->calPierData2G[i];
  256. ath9k_hw_get_gain_boundaries_pdadcs(ah, chan,
  257. pRawDataset, pCalBChans,
  258. numPiers, pdGainOverlap_t2,
  259. gainBoundaries,
  260. pdadcValues, numXpdGain);
  261. ENABLE_REGWRITE_BUFFER(ah);
  262. if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
  263. REG_WRITE(ah, AR_PHY_TPCRG5 + regChainOffset,
  264. SM(pdGainOverlap_t2,
  265. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
  266. | SM(gainBoundaries[0],
  267. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
  268. | SM(gainBoundaries[1],
  269. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
  270. | SM(gainBoundaries[2],
  271. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
  272. | SM(gainBoundaries[3],
  273. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
  274. }
  275. regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
  276. for (j = 0; j < 32; j++) {
  277. reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
  278. ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
  279. ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
  280. ((pdadcValues[4 * j + 3] & 0xFF) << 24);
  281. REG_WRITE(ah, regOffset, reg32);
  282. ath_dbg(common, ATH_DBG_EEPROM,
  283. "PDADC (%d,%4x): %4.4x %8.8x\n",
  284. i, regChainOffset, regOffset,
  285. reg32);
  286. ath_dbg(common, ATH_DBG_EEPROM,
  287. "PDADC: Chain %d | "
  288. "PDADC %3d Value %3d | "
  289. "PDADC %3d Value %3d | "
  290. "PDADC %3d Value %3d | "
  291. "PDADC %3d Value %3d |\n",
  292. i, 4 * j, pdadcValues[4 * j],
  293. 4 * j + 1, pdadcValues[4 * j + 1],
  294. 4 * j + 2, pdadcValues[4 * j + 2],
  295. 4 * j + 3, pdadcValues[4 * j + 3]);
  296. regOffset += 4;
  297. }
  298. REGWRITE_BUFFER_FLUSH(ah);
  299. }
  300. }
  301. *pTxPowerIndexOffset = 0;
  302. }
  303. static void ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
  304. struct ath9k_channel *chan,
  305. int16_t *ratesArray,
  306. u16 cfgCtl,
  307. u16 AntennaReduction,
  308. u16 twiceMaxRegulatoryPower,
  309. u16 powerLimit)
  310. {
  311. #define CMP_TEST_GRP \
  312. (((cfgCtl & ~CTL_MODE_M)| (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  313. pEepData->ctlIndex[i]) \
  314. || (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  315. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
  316. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  317. int i;
  318. int16_t twiceLargestAntenna;
  319. u16 twiceMinEdgePower;
  320. u16 twiceMaxEdgePower = MAX_RATE_POWER;
  321. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  322. u16 numCtlModes;
  323. const u16 *pCtlMode;
  324. u16 ctlMode, freq;
  325. struct chan_centers centers;
  326. struct cal_ctl_data_4k *rep;
  327. struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
  328. static const u16 tpScaleReductionTable[5] =
  329. { 0, 3, 6, 9, MAX_RATE_POWER };
  330. struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
  331. 0, { 0, 0, 0, 0}
  332. };
  333. struct cal_target_power_leg targetPowerOfdmExt = {
  334. 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
  335. 0, { 0, 0, 0, 0 }
  336. };
  337. struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
  338. 0, {0, 0, 0, 0}
  339. };
  340. static const u16 ctlModesFor11g[] = {
  341. CTL_11B, CTL_11G, CTL_2GHT20,
  342. CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
  343. };
  344. ath9k_hw_get_channel_centers(ah, chan, &centers);
  345. twiceLargestAntenna = pEepData->modalHeader.antennaGainCh[0];
  346. twiceLargestAntenna = (int16_t)min(AntennaReduction -
  347. twiceLargestAntenna, 0);
  348. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  349. if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX) {
  350. maxRegAllowedPower -=
  351. (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
  352. }
  353. scaledPower = min(powerLimit, maxRegAllowedPower);
  354. scaledPower = max((u16)0, scaledPower);
  355. numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
  356. pCtlMode = ctlModesFor11g;
  357. ath9k_hw_get_legacy_target_powers(ah, chan,
  358. pEepData->calTargetPowerCck,
  359. AR5416_NUM_2G_CCK_TARGET_POWERS,
  360. &targetPowerCck, 4, false);
  361. ath9k_hw_get_legacy_target_powers(ah, chan,
  362. pEepData->calTargetPower2G,
  363. AR5416_NUM_2G_20_TARGET_POWERS,
  364. &targetPowerOfdm, 4, false);
  365. ath9k_hw_get_target_powers(ah, chan,
  366. pEepData->calTargetPower2GHT20,
  367. AR5416_NUM_2G_20_TARGET_POWERS,
  368. &targetPowerHt20, 8, false);
  369. if (IS_CHAN_HT40(chan)) {
  370. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  371. ath9k_hw_get_target_powers(ah, chan,
  372. pEepData->calTargetPower2GHT40,
  373. AR5416_NUM_2G_40_TARGET_POWERS,
  374. &targetPowerHt40, 8, true);
  375. ath9k_hw_get_legacy_target_powers(ah, chan,
  376. pEepData->calTargetPowerCck,
  377. AR5416_NUM_2G_CCK_TARGET_POWERS,
  378. &targetPowerCckExt, 4, true);
  379. ath9k_hw_get_legacy_target_powers(ah, chan,
  380. pEepData->calTargetPower2G,
  381. AR5416_NUM_2G_20_TARGET_POWERS,
  382. &targetPowerOfdmExt, 4, true);
  383. }
  384. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  385. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  386. (pCtlMode[ctlMode] == CTL_2GHT40);
  387. if (isHt40CtlMode)
  388. freq = centers.synth_center;
  389. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  390. freq = centers.ext_center;
  391. else
  392. freq = centers.ctl_center;
  393. if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
  394. ah->eep_ops->get_eeprom_rev(ah) <= 2)
  395. twiceMaxEdgePower = MAX_RATE_POWER;
  396. for (i = 0; (i < AR5416_EEP4K_NUM_CTLS) &&
  397. pEepData->ctlIndex[i]; i++) {
  398. if (CMP_TEST_GRP) {
  399. rep = &(pEepData->ctlData[i]);
  400. twiceMinEdgePower = ath9k_hw_get_max_edge_power(
  401. freq,
  402. rep->ctlEdges[
  403. ar5416_get_ntxchains(ah->txchainmask) - 1],
  404. IS_CHAN_2GHZ(chan),
  405. AR5416_EEP4K_NUM_BAND_EDGES);
  406. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  407. twiceMaxEdgePower =
  408. min(twiceMaxEdgePower,
  409. twiceMinEdgePower);
  410. } else {
  411. twiceMaxEdgePower = twiceMinEdgePower;
  412. break;
  413. }
  414. }
  415. }
  416. minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
  417. switch (pCtlMode[ctlMode]) {
  418. case CTL_11B:
  419. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  420. targetPowerCck.tPow2x[i] =
  421. min((u16)targetPowerCck.tPow2x[i],
  422. minCtlPower);
  423. }
  424. break;
  425. case CTL_11G:
  426. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  427. targetPowerOfdm.tPow2x[i] =
  428. min((u16)targetPowerOfdm.tPow2x[i],
  429. minCtlPower);
  430. }
  431. break;
  432. case CTL_2GHT20:
  433. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  434. targetPowerHt20.tPow2x[i] =
  435. min((u16)targetPowerHt20.tPow2x[i],
  436. minCtlPower);
  437. }
  438. break;
  439. case CTL_11B_EXT:
  440. targetPowerCckExt.tPow2x[0] =
  441. min((u16)targetPowerCckExt.tPow2x[0],
  442. minCtlPower);
  443. break;
  444. case CTL_11G_EXT:
  445. targetPowerOfdmExt.tPow2x[0] =
  446. min((u16)targetPowerOfdmExt.tPow2x[0],
  447. minCtlPower);
  448. break;
  449. case CTL_2GHT40:
  450. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  451. targetPowerHt40.tPow2x[i] =
  452. min((u16)targetPowerHt40.tPow2x[i],
  453. minCtlPower);
  454. }
  455. break;
  456. default:
  457. break;
  458. }
  459. }
  460. ratesArray[rate6mb] =
  461. ratesArray[rate9mb] =
  462. ratesArray[rate12mb] =
  463. ratesArray[rate18mb] =
  464. ratesArray[rate24mb] =
  465. targetPowerOfdm.tPow2x[0];
  466. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  467. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  468. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  469. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  470. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  471. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  472. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  473. ratesArray[rate2s] = ratesArray[rate2l] = targetPowerCck.tPow2x[1];
  474. ratesArray[rate5_5s] = ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
  475. ratesArray[rate11s] = ratesArray[rate11l] = targetPowerCck.tPow2x[3];
  476. if (IS_CHAN_HT40(chan)) {
  477. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  478. ratesArray[rateHt40_0 + i] =
  479. targetPowerHt40.tPow2x[i];
  480. }
  481. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  482. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  483. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  484. ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
  485. }
  486. #undef CMP_TEST_GRP
  487. }
  488. static void ath9k_hw_4k_set_txpower(struct ath_hw *ah,
  489. struct ath9k_channel *chan,
  490. u16 cfgCtl,
  491. u8 twiceAntennaReduction,
  492. u8 twiceMaxRegulatoryPower,
  493. u8 powerLimit, bool test)
  494. {
  495. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  496. struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
  497. struct modal_eep_4k_header *pModal = &pEepData->modalHeader;
  498. int16_t ratesArray[Ar5416RateSize];
  499. int16_t txPowerIndexOffset = 0;
  500. u8 ht40PowerIncForPdadc = 2;
  501. int i;
  502. memset(ratesArray, 0, sizeof(ratesArray));
  503. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  504. AR5416_EEP_MINOR_VER_2) {
  505. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  506. }
  507. ath9k_hw_set_4k_power_per_rate_table(ah, chan,
  508. &ratesArray[0], cfgCtl,
  509. twiceAntennaReduction,
  510. twiceMaxRegulatoryPower,
  511. powerLimit);
  512. ath9k_hw_set_4k_power_cal_table(ah, chan, &txPowerIndexOffset);
  513. regulatory->max_power_level = 0;
  514. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  515. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  516. if (ratesArray[i] > MAX_RATE_POWER)
  517. ratesArray[i] = MAX_RATE_POWER;
  518. if (ratesArray[i] > regulatory->max_power_level)
  519. regulatory->max_power_level = ratesArray[i];
  520. }
  521. if (test)
  522. return;
  523. /* Update regulatory */
  524. i = rate6mb;
  525. if (IS_CHAN_HT40(chan))
  526. i = rateHt40_0;
  527. else if (IS_CHAN_HT20(chan))
  528. i = rateHt20_0;
  529. regulatory->max_power_level = ratesArray[i];
  530. if (AR_SREV_9280_20_OR_LATER(ah)) {
  531. for (i = 0; i < Ar5416RateSize; i++)
  532. ratesArray[i] -= AR5416_PWR_TABLE_OFFSET_DB * 2;
  533. }
  534. ENABLE_REGWRITE_BUFFER(ah);
  535. /* OFDM power per rate */
  536. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  537. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  538. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  539. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  540. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  541. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  542. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  543. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  544. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  545. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  546. /* CCK power per rate */
  547. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  548. ATH9K_POW_SM(ratesArray[rate2s], 24)
  549. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  550. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  551. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  552. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  553. ATH9K_POW_SM(ratesArray[rate11s], 24)
  554. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  555. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  556. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  557. /* HT20 power per rate */
  558. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  559. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  560. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  561. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  562. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  563. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  564. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  565. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  566. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  567. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  568. /* HT40 power per rate */
  569. if (IS_CHAN_HT40(chan)) {
  570. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  571. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  572. ht40PowerIncForPdadc, 24)
  573. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  574. ht40PowerIncForPdadc, 16)
  575. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  576. ht40PowerIncForPdadc, 8)
  577. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  578. ht40PowerIncForPdadc, 0));
  579. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  580. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  581. ht40PowerIncForPdadc, 24)
  582. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  583. ht40PowerIncForPdadc, 16)
  584. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  585. ht40PowerIncForPdadc, 8)
  586. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  587. ht40PowerIncForPdadc, 0));
  588. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  589. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  590. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  591. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  592. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  593. }
  594. REGWRITE_BUFFER_FLUSH(ah);
  595. }
  596. static void ath9k_hw_4k_set_addac(struct ath_hw *ah,
  597. struct ath9k_channel *chan)
  598. {
  599. struct modal_eep_4k_header *pModal;
  600. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  601. u8 biaslevel;
  602. if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
  603. return;
  604. if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
  605. return;
  606. pModal = &eep->modalHeader;
  607. if (pModal->xpaBiasLvl != 0xff) {
  608. biaslevel = pModal->xpaBiasLvl;
  609. INI_RA(&ah->iniAddac, 7, 1) =
  610. (INI_RA(&ah->iniAddac, 7, 1) & (~0x18)) | biaslevel << 3;
  611. }
  612. }
  613. static void ath9k_hw_4k_set_gain(struct ath_hw *ah,
  614. struct modal_eep_4k_header *pModal,
  615. struct ar5416_eeprom_4k *eep,
  616. u8 txRxAttenLocal)
  617. {
  618. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0,
  619. pModal->antCtrlChain[0]);
  620. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0),
  621. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) &
  622. ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  623. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  624. SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  625. SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  626. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  627. AR5416_EEP_MINOR_VER_3) {
  628. txRxAttenLocal = pModal->txRxAttenCh[0];
  629. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
  630. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]);
  631. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
  632. AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
  633. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
  634. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  635. pModal->xatten2Margin[0]);
  636. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
  637. AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]);
  638. /* Set the block 1 value to block 0 value */
  639. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
  640. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  641. pModal->bswMargin[0]);
  642. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
  643. AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
  644. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
  645. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  646. pModal->xatten2Margin[0]);
  647. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
  648. AR_PHY_GAIN_2GHZ_XATTEN2_DB,
  649. pModal->xatten2Db[0]);
  650. }
  651. REG_RMW_FIELD(ah, AR_PHY_RXGAIN,
  652. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  653. REG_RMW_FIELD(ah, AR_PHY_RXGAIN,
  654. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
  655. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000,
  656. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  657. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000,
  658. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
  659. }
  660. /*
  661. * Read EEPROM header info and program the device for correct operation
  662. * given the channel value.
  663. */
  664. static void ath9k_hw_4k_set_board_values(struct ath_hw *ah,
  665. struct ath9k_channel *chan)
  666. {
  667. struct modal_eep_4k_header *pModal;
  668. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  669. struct base_eep_header_4k *pBase = &eep->baseEepHeader;
  670. u8 txRxAttenLocal;
  671. u8 ob[5], db1[5], db2[5];
  672. u8 ant_div_control1, ant_div_control2;
  673. u32 regVal;
  674. pModal = &eep->modalHeader;
  675. txRxAttenLocal = 23;
  676. REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
  677. /* Single chain for 4K EEPROM*/
  678. ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal);
  679. /* Initialize Ant Diversity settings from EEPROM */
  680. if (pModal->version >= 3) {
  681. ant_div_control1 = pModal->antdiv_ctl1;
  682. ant_div_control2 = pModal->antdiv_ctl2;
  683. regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
  684. regVal &= (~(AR_PHY_9285_ANT_DIV_CTL_ALL));
  685. regVal |= SM(ant_div_control1,
  686. AR_PHY_9285_ANT_DIV_CTL);
  687. regVal |= SM(ant_div_control2,
  688. AR_PHY_9285_ANT_DIV_ALT_LNACONF);
  689. regVal |= SM((ant_div_control2 >> 2),
  690. AR_PHY_9285_ANT_DIV_MAIN_LNACONF);
  691. regVal |= SM((ant_div_control1 >> 1),
  692. AR_PHY_9285_ANT_DIV_ALT_GAINTB);
  693. regVal |= SM((ant_div_control1 >> 2),
  694. AR_PHY_9285_ANT_DIV_MAIN_GAINTB);
  695. REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regVal);
  696. regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
  697. regVal = REG_READ(ah, AR_PHY_CCK_DETECT);
  698. regVal &= (~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
  699. regVal |= SM((ant_div_control1 >> 3),
  700. AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
  701. REG_WRITE(ah, AR_PHY_CCK_DETECT, regVal);
  702. regVal = REG_READ(ah, AR_PHY_CCK_DETECT);
  703. }
  704. if (pModal->version >= 2) {
  705. ob[0] = pModal->ob_0;
  706. ob[1] = pModal->ob_1;
  707. ob[2] = pModal->ob_2;
  708. ob[3] = pModal->ob_3;
  709. ob[4] = pModal->ob_4;
  710. db1[0] = pModal->db1_0;
  711. db1[1] = pModal->db1_1;
  712. db1[2] = pModal->db1_2;
  713. db1[3] = pModal->db1_3;
  714. db1[4] = pModal->db1_4;
  715. db2[0] = pModal->db2_0;
  716. db2[1] = pModal->db2_1;
  717. db2[2] = pModal->db2_2;
  718. db2[3] = pModal->db2_3;
  719. db2[4] = pModal->db2_4;
  720. } else if (pModal->version == 1) {
  721. ob[0] = pModal->ob_0;
  722. ob[1] = ob[2] = ob[3] = ob[4] = pModal->ob_1;
  723. db1[0] = pModal->db1_0;
  724. db1[1] = db1[2] = db1[3] = db1[4] = pModal->db1_1;
  725. db2[0] = pModal->db2_0;
  726. db2[1] = db2[2] = db2[3] = db2[4] = pModal->db2_1;
  727. } else {
  728. int i;
  729. for (i = 0; i < 5; i++) {
  730. ob[i] = pModal->ob_0;
  731. db1[i] = pModal->db1_0;
  732. db2[i] = pModal->db1_0;
  733. }
  734. }
  735. if (AR_SREV_9271(ah)) {
  736. ath9k_hw_analog_shift_rmw(ah,
  737. AR9285_AN_RF2G3,
  738. AR9271_AN_RF2G3_OB_cck,
  739. AR9271_AN_RF2G3_OB_cck_S,
  740. ob[0]);
  741. ath9k_hw_analog_shift_rmw(ah,
  742. AR9285_AN_RF2G3,
  743. AR9271_AN_RF2G3_OB_psk,
  744. AR9271_AN_RF2G3_OB_psk_S,
  745. ob[1]);
  746. ath9k_hw_analog_shift_rmw(ah,
  747. AR9285_AN_RF2G3,
  748. AR9271_AN_RF2G3_OB_qam,
  749. AR9271_AN_RF2G3_OB_qam_S,
  750. ob[2]);
  751. ath9k_hw_analog_shift_rmw(ah,
  752. AR9285_AN_RF2G3,
  753. AR9271_AN_RF2G3_DB_1,
  754. AR9271_AN_RF2G3_DB_1_S,
  755. db1[0]);
  756. ath9k_hw_analog_shift_rmw(ah,
  757. AR9285_AN_RF2G4,
  758. AR9271_AN_RF2G4_DB_2,
  759. AR9271_AN_RF2G4_DB_2_S,
  760. db2[0]);
  761. } else {
  762. ath9k_hw_analog_shift_rmw(ah,
  763. AR9285_AN_RF2G3,
  764. AR9285_AN_RF2G3_OB_0,
  765. AR9285_AN_RF2G3_OB_0_S,
  766. ob[0]);
  767. ath9k_hw_analog_shift_rmw(ah,
  768. AR9285_AN_RF2G3,
  769. AR9285_AN_RF2G3_OB_1,
  770. AR9285_AN_RF2G3_OB_1_S,
  771. ob[1]);
  772. ath9k_hw_analog_shift_rmw(ah,
  773. AR9285_AN_RF2G3,
  774. AR9285_AN_RF2G3_OB_2,
  775. AR9285_AN_RF2G3_OB_2_S,
  776. ob[2]);
  777. ath9k_hw_analog_shift_rmw(ah,
  778. AR9285_AN_RF2G3,
  779. AR9285_AN_RF2G3_OB_3,
  780. AR9285_AN_RF2G3_OB_3_S,
  781. ob[3]);
  782. ath9k_hw_analog_shift_rmw(ah,
  783. AR9285_AN_RF2G3,
  784. AR9285_AN_RF2G3_OB_4,
  785. AR9285_AN_RF2G3_OB_4_S,
  786. ob[4]);
  787. ath9k_hw_analog_shift_rmw(ah,
  788. AR9285_AN_RF2G3,
  789. AR9285_AN_RF2G3_DB1_0,
  790. AR9285_AN_RF2G3_DB1_0_S,
  791. db1[0]);
  792. ath9k_hw_analog_shift_rmw(ah,
  793. AR9285_AN_RF2G3,
  794. AR9285_AN_RF2G3_DB1_1,
  795. AR9285_AN_RF2G3_DB1_1_S,
  796. db1[1]);
  797. ath9k_hw_analog_shift_rmw(ah,
  798. AR9285_AN_RF2G3,
  799. AR9285_AN_RF2G3_DB1_2,
  800. AR9285_AN_RF2G3_DB1_2_S,
  801. db1[2]);
  802. ath9k_hw_analog_shift_rmw(ah,
  803. AR9285_AN_RF2G4,
  804. AR9285_AN_RF2G4_DB1_3,
  805. AR9285_AN_RF2G4_DB1_3_S,
  806. db1[3]);
  807. ath9k_hw_analog_shift_rmw(ah,
  808. AR9285_AN_RF2G4,
  809. AR9285_AN_RF2G4_DB1_4,
  810. AR9285_AN_RF2G4_DB1_4_S, db1[4]);
  811. ath9k_hw_analog_shift_rmw(ah,
  812. AR9285_AN_RF2G4,
  813. AR9285_AN_RF2G4_DB2_0,
  814. AR9285_AN_RF2G4_DB2_0_S,
  815. db2[0]);
  816. ath9k_hw_analog_shift_rmw(ah,
  817. AR9285_AN_RF2G4,
  818. AR9285_AN_RF2G4_DB2_1,
  819. AR9285_AN_RF2G4_DB2_1_S,
  820. db2[1]);
  821. ath9k_hw_analog_shift_rmw(ah,
  822. AR9285_AN_RF2G4,
  823. AR9285_AN_RF2G4_DB2_2,
  824. AR9285_AN_RF2G4_DB2_2_S,
  825. db2[2]);
  826. ath9k_hw_analog_shift_rmw(ah,
  827. AR9285_AN_RF2G4,
  828. AR9285_AN_RF2G4_DB2_3,
  829. AR9285_AN_RF2G4_DB2_3_S,
  830. db2[3]);
  831. ath9k_hw_analog_shift_rmw(ah,
  832. AR9285_AN_RF2G4,
  833. AR9285_AN_RF2G4_DB2_4,
  834. AR9285_AN_RF2G4_DB2_4_S,
  835. db2[4]);
  836. }
  837. REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
  838. pModal->switchSettling);
  839. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
  840. pModal->adcDesiredSize);
  841. REG_WRITE(ah, AR_PHY_RF_CTL4,
  842. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
  843. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
  844. SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
  845. SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  846. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  847. pModal->txEndToRxOn);
  848. if (AR_SREV_9271_10(ah))
  849. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  850. pModal->txEndToRxOn);
  851. REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
  852. pModal->thresh62);
  853. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
  854. pModal->thresh62);
  855. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  856. AR5416_EEP_MINOR_VER_2) {
  857. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
  858. pModal->txFrameToDataStart);
  859. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
  860. pModal->txFrameToPaOn);
  861. }
  862. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  863. AR5416_EEP_MINOR_VER_3) {
  864. if (IS_CHAN_HT40(chan))
  865. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  866. AR_PHY_SETTLING_SWITCH,
  867. pModal->swSettleHt40);
  868. }
  869. if (AR_SREV_9271(ah) || AR_SREV_9285(ah)) {
  870. u8 bb_desired_scale = (pModal->bb_scale_smrt_antenna &
  871. EEP_4K_BB_DESIRED_SCALE_MASK);
  872. if ((pBase->txGainType == 0) && (bb_desired_scale != 0)) {
  873. u32 pwrctrl, mask, clr;
  874. mask = BIT(0)|BIT(5)|BIT(10)|BIT(15)|BIT(20)|BIT(25);
  875. pwrctrl = mask * bb_desired_scale;
  876. clr = mask * 0x1f;
  877. REG_RMW(ah, AR_PHY_TX_PWRCTRL8, pwrctrl, clr);
  878. REG_RMW(ah, AR_PHY_TX_PWRCTRL10, pwrctrl, clr);
  879. REG_RMW(ah, AR_PHY_CH0_TX_PWRCTRL12, pwrctrl, clr);
  880. mask = BIT(0)|BIT(5)|BIT(15);
  881. pwrctrl = mask * bb_desired_scale;
  882. clr = mask * 0x1f;
  883. REG_RMW(ah, AR_PHY_TX_PWRCTRL9, pwrctrl, clr);
  884. mask = BIT(0)|BIT(5);
  885. pwrctrl = mask * bb_desired_scale;
  886. clr = mask * 0x1f;
  887. REG_RMW(ah, AR_PHY_CH0_TX_PWRCTRL11, pwrctrl, clr);
  888. REG_RMW(ah, AR_PHY_CH0_TX_PWRCTRL13, pwrctrl, clr);
  889. }
  890. }
  891. }
  892. static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
  893. {
  894. #define EEP_MAP4K_SPURCHAN \
  895. (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan)
  896. struct ath_common *common = ath9k_hw_common(ah);
  897. u16 spur_val = AR_NO_SPUR;
  898. ath_dbg(common, ATH_DBG_ANI,
  899. "Getting spur idx:%d is2Ghz:%d val:%x\n",
  900. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  901. switch (ah->config.spurmode) {
  902. case SPUR_DISABLE:
  903. break;
  904. case SPUR_ENABLE_IOCTL:
  905. spur_val = ah->config.spurchans[i][is2GHz];
  906. ath_dbg(common, ATH_DBG_ANI,
  907. "Getting spur val from new loc. %d\n", spur_val);
  908. break;
  909. case SPUR_ENABLE_EEPROM:
  910. spur_val = EEP_MAP4K_SPURCHAN;
  911. break;
  912. }
  913. return spur_val;
  914. #undef EEP_MAP4K_SPURCHAN
  915. }
  916. const struct eeprom_ops eep_4k_ops = {
  917. .check_eeprom = ath9k_hw_4k_check_eeprom,
  918. .get_eeprom = ath9k_hw_4k_get_eeprom,
  919. .fill_eeprom = ath9k_hw_4k_fill_eeprom,
  920. .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver,
  921. .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev,
  922. .set_board_values = ath9k_hw_4k_set_board_values,
  923. .set_addac = ath9k_hw_4k_set_addac,
  924. .set_txpower = ath9k_hw_4k_set_txpower,
  925. .get_spur_channel = ath9k_hw_4k_get_spur_channel
  926. };