eeprom_4k.c 34 KB

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