eeprom_4k.c 33 KB

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