eeprom_4k.c 33 KB

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