eeprom_4k.c 33 KB

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