eeprom_4k.c 33 KB

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