eeprom_9287.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. /*
  2. * Copyright (c) 2008-2009 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 "hw.h"
  17. #include "ar9002_phy.h"
  18. #define NUM_EEP_WORDS (sizeof(struct ar9287_eeprom) / sizeof(u16))
  19. static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah)
  20. {
  21. return (ah->eeprom.map9287.baseEepHeader.version >> 12) & 0xF;
  22. }
  23. static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah)
  24. {
  25. return (ah->eeprom.map9287.baseEepHeader.version) & 0xFFF;
  26. }
  27. static bool ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah)
  28. {
  29. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  30. struct ath_common *common = ath9k_hw_common(ah);
  31. u16 *eep_data;
  32. int addr, eep_start_loc = AR9287_EEP_START_LOC;
  33. eep_data = (u16 *)eep;
  34. if (!ath9k_hw_use_flash(ah)) {
  35. ath_print(common, ATH_DBG_EEPROM,
  36. "Reading from EEPROM, not flash\n");
  37. }
  38. for (addr = 0; addr < NUM_EEP_WORDS; addr++) {
  39. if (!ath9k_hw_nvram_read(common, addr + eep_start_loc,
  40. eep_data)) {
  41. ath_print(common, ATH_DBG_EEPROM,
  42. "Unable to read eeprom region\n");
  43. return false;
  44. }
  45. eep_data++;
  46. }
  47. return true;
  48. }
  49. static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah)
  50. {
  51. u32 sum = 0, el, integer;
  52. u16 temp, word, magic, magic2, *eepdata;
  53. int i, addr;
  54. bool need_swap = false;
  55. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  56. struct ath_common *common = ath9k_hw_common(ah);
  57. if (!ath9k_hw_use_flash(ah)) {
  58. if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET,
  59. &magic)) {
  60. ath_print(common, ATH_DBG_FATAL,
  61. "Reading Magic # failed\n");
  62. return false;
  63. }
  64. ath_print(common, ATH_DBG_EEPROM,
  65. "Read Magic = 0x%04X\n", magic);
  66. if (magic != AR5416_EEPROM_MAGIC) {
  67. magic2 = swab16(magic);
  68. if (magic2 == AR5416_EEPROM_MAGIC) {
  69. need_swap = true;
  70. eepdata = (u16 *)(&ah->eeprom);
  71. for (addr = 0; addr < NUM_EEP_WORDS; addr++) {
  72. temp = swab16(*eepdata);
  73. *eepdata = temp;
  74. eepdata++;
  75. }
  76. } else {
  77. ath_print(common, ATH_DBG_FATAL,
  78. "Invalid EEPROM Magic. "
  79. "Endianness mismatch.\n");
  80. return -EINVAL;
  81. }
  82. }
  83. }
  84. ath_print(common, ATH_DBG_EEPROM, "need_swap = %s.\n",
  85. need_swap ? "True" : "False");
  86. if (need_swap)
  87. el = swab16(ah->eeprom.map9287.baseEepHeader.length);
  88. else
  89. el = ah->eeprom.map9287.baseEepHeader.length;
  90. if (el > sizeof(struct ar9287_eeprom))
  91. el = sizeof(struct ar9287_eeprom) / sizeof(u16);
  92. else
  93. el = el / sizeof(u16);
  94. eepdata = (u16 *)(&ah->eeprom);
  95. for (i = 0; i < el; i++)
  96. sum ^= *eepdata++;
  97. if (need_swap) {
  98. word = swab16(eep->baseEepHeader.length);
  99. eep->baseEepHeader.length = word;
  100. word = swab16(eep->baseEepHeader.checksum);
  101. eep->baseEepHeader.checksum = word;
  102. word = swab16(eep->baseEepHeader.version);
  103. eep->baseEepHeader.version = word;
  104. word = swab16(eep->baseEepHeader.regDmn[0]);
  105. eep->baseEepHeader.regDmn[0] = word;
  106. word = swab16(eep->baseEepHeader.regDmn[1]);
  107. eep->baseEepHeader.regDmn[1] = word;
  108. word = swab16(eep->baseEepHeader.rfSilent);
  109. eep->baseEepHeader.rfSilent = word;
  110. word = swab16(eep->baseEepHeader.blueToothOptions);
  111. eep->baseEepHeader.blueToothOptions = word;
  112. word = swab16(eep->baseEepHeader.deviceCap);
  113. eep->baseEepHeader.deviceCap = word;
  114. integer = swab32(eep->modalHeader.antCtrlCommon);
  115. eep->modalHeader.antCtrlCommon = integer;
  116. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  117. integer = swab32(eep->modalHeader.antCtrlChain[i]);
  118. eep->modalHeader.antCtrlChain[i] = integer;
  119. }
  120. for (i = 0; i < AR9287_EEPROM_MODAL_SPURS; i++) {
  121. word = swab16(eep->modalHeader.spurChans[i].spurChan);
  122. eep->modalHeader.spurChans[i].spurChan = word;
  123. }
  124. }
  125. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR9287_EEP_VER
  126. || ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  127. ath_print(common, ATH_DBG_FATAL,
  128. "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  129. sum, ah->eep_ops->get_eeprom_ver(ah));
  130. return -EINVAL;
  131. }
  132. return 0;
  133. }
  134. static u32 ath9k_hw_ar9287_get_eeprom(struct ath_hw *ah,
  135. enum eeprom_param param)
  136. {
  137. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  138. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  139. struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
  140. u16 ver_minor;
  141. ver_minor = pBase->version & AR9287_EEP_VER_MINOR_MASK;
  142. switch (param) {
  143. case EEP_NFTHRESH_2:
  144. return pModal->noiseFloorThreshCh[0];
  145. case EEP_MAC_LSW:
  146. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  147. case EEP_MAC_MID:
  148. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  149. case EEP_MAC_MSW:
  150. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  151. case EEP_REG_0:
  152. return pBase->regDmn[0];
  153. case EEP_REG_1:
  154. return pBase->regDmn[1];
  155. case EEP_OP_CAP:
  156. return pBase->deviceCap;
  157. case EEP_OP_MODE:
  158. return pBase->opCapFlags;
  159. case EEP_RF_SILENT:
  160. return pBase->rfSilent;
  161. case EEP_MINOR_REV:
  162. return ver_minor;
  163. case EEP_TX_MASK:
  164. return pBase->txMask;
  165. case EEP_RX_MASK:
  166. return pBase->rxMask;
  167. case EEP_DEV_TYPE:
  168. return pBase->deviceType;
  169. case EEP_OL_PWRCTRL:
  170. return pBase->openLoopPwrCntl;
  171. case EEP_TEMPSENSE_SLOPE:
  172. if (ver_minor >= AR9287_EEP_MINOR_VER_2)
  173. return pBase->tempSensSlope;
  174. else
  175. return 0;
  176. case EEP_TEMPSENSE_SLOPE_PAL_ON:
  177. if (ver_minor >= AR9287_EEP_MINOR_VER_3)
  178. return pBase->tempSensSlopePalOn;
  179. else
  180. return 0;
  181. default:
  182. return 0;
  183. }
  184. }
  185. static void ath9k_hw_get_ar9287_gain_boundaries_pdadcs(struct ath_hw *ah,
  186. struct ath9k_channel *chan,
  187. struct cal_data_per_freq_ar9287 *pRawDataSet,
  188. u8 *bChans, u16 availPiers,
  189. u16 tPdGainOverlap,
  190. u16 *pPdGainBoundaries,
  191. u8 *pPDADCValues,
  192. u16 numXpdGains)
  193. {
  194. #define TMP_VAL_VPD_TABLE \
  195. ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep));
  196. int i, j, k;
  197. int16_t ss;
  198. u16 idxL = 0, idxR = 0, numPiers;
  199. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  200. u8 minPwrT4[AR9287_NUM_PD_GAINS];
  201. u8 maxPwrT4[AR9287_NUM_PD_GAINS];
  202. int16_t vpdStep;
  203. int16_t tmpVal;
  204. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  205. bool match;
  206. int16_t minDelta = 0;
  207. struct chan_centers centers;
  208. static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS]
  209. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  210. static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS]
  211. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  212. static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS]
  213. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  214. memset(&minPwrT4, 0, AR9287_NUM_PD_GAINS);
  215. ath9k_hw_get_channel_centers(ah, chan, &centers);
  216. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  217. if (bChans[numPiers] == AR9287_BCHAN_UNUSED)
  218. break;
  219. }
  220. match = ath9k_hw_get_lower_upper_index(
  221. (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
  222. bChans, numPiers, &idxL, &idxR);
  223. if (match) {
  224. for (i = 0; i < numXpdGains; i++) {
  225. minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
  226. maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
  227. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  228. pRawDataSet[idxL].pwrPdg[i],
  229. pRawDataSet[idxL].vpdPdg[i],
  230. AR9287_PD_GAIN_ICEPTS,
  231. vpdTableI[i]);
  232. }
  233. } else {
  234. for (i = 0; i < numXpdGains; i++) {
  235. pVpdL = pRawDataSet[idxL].vpdPdg[i];
  236. pPwrL = pRawDataSet[idxL].pwrPdg[i];
  237. pVpdR = pRawDataSet[idxR].vpdPdg[i];
  238. pPwrR = pRawDataSet[idxR].pwrPdg[i];
  239. minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
  240. maxPwrT4[i] = min(pPwrL[AR9287_PD_GAIN_ICEPTS - 1],
  241. pPwrR[AR9287_PD_GAIN_ICEPTS - 1]);
  242. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  243. pPwrL, pVpdL,
  244. AR9287_PD_GAIN_ICEPTS,
  245. vpdTableL[i]);
  246. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  247. pPwrR, pVpdR,
  248. AR9287_PD_GAIN_ICEPTS,
  249. vpdTableR[i]);
  250. for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
  251. vpdTableI[i][j] = (u8)(ath9k_hw_interpolate(
  252. (u16)FREQ2FBIN(centers. synth_center,
  253. IS_CHAN_2GHZ(chan)),
  254. bChans[idxL], bChans[idxR],
  255. vpdTableL[i][j], vpdTableR[i][j]));
  256. }
  257. }
  258. }
  259. k = 0;
  260. for (i = 0; i < numXpdGains; i++) {
  261. if (i == (numXpdGains - 1))
  262. pPdGainBoundaries[i] =
  263. (u16)(maxPwrT4[i] / 2);
  264. else
  265. pPdGainBoundaries[i] =
  266. (u16)((maxPwrT4[i] + minPwrT4[i+1]) / 4);
  267. pPdGainBoundaries[i] = min((u16)AR5416_MAX_RATE_POWER,
  268. pPdGainBoundaries[i]);
  269. minDelta = 0;
  270. if (i == 0) {
  271. if (AR_SREV_9280_10_OR_LATER(ah))
  272. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  273. else
  274. ss = 0;
  275. } else {
  276. ss = (int16_t)((pPdGainBoundaries[i-1] -
  277. (minPwrT4[i] / 2)) -
  278. tPdGainOverlap + 1 + minDelta);
  279. }
  280. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  281. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  282. while ((ss < 0) && (k < (AR9287_NUM_PDADC_VALUES - 1))) {
  283. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  284. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  285. ss++;
  286. }
  287. sizeCurrVpdTable = (u8)((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  288. tgtIndex = (u8)(pPdGainBoundaries[i] +
  289. tPdGainOverlap - (minPwrT4[i] / 2));
  290. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  291. tgtIndex : sizeCurrVpdTable;
  292. while ((ss < maxIndex) && (k < (AR9287_NUM_PDADC_VALUES - 1)))
  293. pPDADCValues[k++] = vpdTableI[i][ss++];
  294. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  295. vpdTableI[i][sizeCurrVpdTable - 2]);
  296. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  297. if (tgtIndex > maxIndex) {
  298. while ((ss <= tgtIndex) &&
  299. (k < (AR9287_NUM_PDADC_VALUES - 1))) {
  300. tmpVal = (int16_t) TMP_VAL_VPD_TABLE;
  301. pPDADCValues[k++] =
  302. (u8)((tmpVal > 255) ? 255 : tmpVal);
  303. ss++;
  304. }
  305. }
  306. }
  307. while (i < AR9287_PD_GAINS_IN_MASK) {
  308. pPdGainBoundaries[i] = pPdGainBoundaries[i-1];
  309. i++;
  310. }
  311. while (k < AR9287_NUM_PDADC_VALUES) {
  312. pPDADCValues[k] = pPDADCValues[k-1];
  313. k++;
  314. }
  315. #undef TMP_VAL_VPD_TABLE
  316. }
  317. static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah,
  318. struct ath9k_channel *chan,
  319. struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop,
  320. u8 *pCalChans, u16 availPiers, int8_t *pPwr)
  321. {
  322. u16 idxL = 0, idxR = 0, numPiers;
  323. bool match;
  324. struct chan_centers centers;
  325. ath9k_hw_get_channel_centers(ah, chan, &centers);
  326. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  327. if (pCalChans[numPiers] == AR9287_BCHAN_UNUSED)
  328. break;
  329. }
  330. match = ath9k_hw_get_lower_upper_index(
  331. (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
  332. pCalChans, numPiers, &idxL, &idxR);
  333. if (match) {
  334. *pPwr = (int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0];
  335. } else {
  336. *pPwr = ((int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0] +
  337. (int8_t) pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
  338. }
  339. }
  340. static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah,
  341. int32_t txPower, u16 chain)
  342. {
  343. u32 tmpVal;
  344. u32 a;
  345. /* Enable OLPC for chain 0 */
  346. tmpVal = REG_READ(ah, 0xa270);
  347. tmpVal = tmpVal & 0xFCFFFFFF;
  348. tmpVal = tmpVal | (0x3 << 24);
  349. REG_WRITE(ah, 0xa270, tmpVal);
  350. /* Enable OLPC for chain 1 */
  351. tmpVal = REG_READ(ah, 0xb270);
  352. tmpVal = tmpVal & 0xFCFFFFFF;
  353. tmpVal = tmpVal | (0x3 << 24);
  354. REG_WRITE(ah, 0xb270, tmpVal);
  355. /* Write the OLPC ref power for chain 0 */
  356. if (chain == 0) {
  357. tmpVal = REG_READ(ah, 0xa398);
  358. tmpVal = tmpVal & 0xff00ffff;
  359. a = (txPower)&0xff;
  360. tmpVal = tmpVal | (a << 16);
  361. REG_WRITE(ah, 0xa398, tmpVal);
  362. }
  363. /* Write the OLPC ref power for chain 1 */
  364. if (chain == 1) {
  365. tmpVal = REG_READ(ah, 0xb398);
  366. tmpVal = tmpVal & 0xff00ffff;
  367. a = (txPower)&0xff;
  368. tmpVal = tmpVal | (a << 16);
  369. REG_WRITE(ah, 0xb398, tmpVal);
  370. }
  371. }
  372. static void ath9k_hw_set_ar9287_power_cal_table(struct ath_hw *ah,
  373. struct ath9k_channel *chan,
  374. int16_t *pTxPowerIndexOffset)
  375. {
  376. struct cal_data_per_freq_ar9287 *pRawDataset;
  377. struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
  378. u8 *pCalBChans = NULL;
  379. u16 pdGainOverlap_t2;
  380. u8 pdadcValues[AR9287_NUM_PDADC_VALUES];
  381. u16 gainBoundaries[AR9287_PD_GAINS_IN_MASK];
  382. u16 numPiers = 0, i, j;
  383. u16 numXpdGain, xpdMask;
  384. u16 xpdGainValues[AR9287_NUM_PD_GAINS] = {0, 0, 0, 0};
  385. u32 reg32, regOffset, regChainOffset, regval;
  386. int16_t modalIdx, diff = 0;
  387. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  388. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  389. xpdMask = pEepData->modalHeader.xpdGain;
  390. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  391. AR9287_EEP_MINOR_VER_2)
  392. pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
  393. else
  394. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  395. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  396. if (IS_CHAN_2GHZ(chan)) {
  397. pCalBChans = pEepData->calFreqPier2G;
  398. numPiers = AR9287_NUM_2G_CAL_PIERS;
  399. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  400. pRawDatasetOpenLoop =
  401. (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];
  402. ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
  403. }
  404. }
  405. numXpdGain = 0;
  406. /* Calculate the value of xpdgains from the xpdGain Mask */
  407. for (i = 1; i <= AR9287_PD_GAINS_IN_MASK; i++) {
  408. if ((xpdMask >> (AR9287_PD_GAINS_IN_MASK - i)) & 1) {
  409. if (numXpdGain >= AR9287_NUM_PD_GAINS)
  410. break;
  411. xpdGainValues[numXpdGain] =
  412. (u16)(AR9287_PD_GAINS_IN_MASK-i);
  413. numXpdGain++;
  414. }
  415. }
  416. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  417. (numXpdGain - 1) & 0x3);
  418. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  419. xpdGainValues[0]);
  420. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  421. xpdGainValues[1]);
  422. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  423. xpdGainValues[2]);
  424. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  425. regChainOffset = i * 0x1000;
  426. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  427. pRawDatasetOpenLoop =
  428. (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];
  429. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  430. int8_t txPower;
  431. ar9287_eeprom_get_tx_gain_index(ah, chan,
  432. pRawDatasetOpenLoop,
  433. pCalBChans, numPiers,
  434. &txPower);
  435. ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i);
  436. } else {
  437. pRawDataset =
  438. (struct cal_data_per_freq_ar9287 *)
  439. pEepData->calPierData2G[i];
  440. ath9k_hw_get_ar9287_gain_boundaries_pdadcs(ah, chan,
  441. pRawDataset,
  442. pCalBChans, numPiers,
  443. pdGainOverlap_t2,
  444. gainBoundaries,
  445. pdadcValues,
  446. numXpdGain);
  447. }
  448. if (i == 0) {
  449. if (!ath9k_hw_ar9287_get_eeprom(ah,
  450. EEP_OL_PWRCTRL)) {
  451. regval = SM(pdGainOverlap_t2,
  452. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
  453. | SM(gainBoundaries[0],
  454. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
  455. | SM(gainBoundaries[1],
  456. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
  457. | SM(gainBoundaries[2],
  458. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
  459. | SM(gainBoundaries[3],
  460. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4);
  461. REG_WRITE(ah,
  462. AR_PHY_TPCRG5 + regChainOffset,
  463. regval);
  464. }
  465. }
  466. if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB !=
  467. pEepData->baseEepHeader.pwrTableOffset) {
  468. diff = (u16)(pEepData->baseEepHeader.pwrTableOffset -
  469. (int32_t)AR9287_PWR_TABLE_OFFSET_DB);
  470. diff *= 2;
  471. for (j = 0; j < ((u16)AR9287_NUM_PDADC_VALUES-diff); j++)
  472. pdadcValues[j] = pdadcValues[j+diff];
  473. for (j = (u16)(AR9287_NUM_PDADC_VALUES-diff);
  474. j < AR9287_NUM_PDADC_VALUES; j++)
  475. pdadcValues[j] =
  476. pdadcValues[AR9287_NUM_PDADC_VALUES-diff];
  477. }
  478. if (!ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  479. regOffset = AR_PHY_BASE +
  480. (672 << 2) + regChainOffset;
  481. for (j = 0; j < 32; j++) {
  482. reg32 = ((pdadcValues[4*j + 0] & 0xFF) << 0)
  483. | ((pdadcValues[4*j + 1] & 0xFF) << 8)
  484. | ((pdadcValues[4*j + 2] & 0xFF) << 16)
  485. | ((pdadcValues[4*j + 3] & 0xFF) << 24);
  486. REG_WRITE(ah, regOffset, reg32);
  487. regOffset += 4;
  488. }
  489. }
  490. }
  491. }
  492. *pTxPowerIndexOffset = 0;
  493. }
  494. static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
  495. struct ath9k_channel *chan,
  496. int16_t *ratesArray,
  497. u16 cfgCtl,
  498. u16 AntennaReduction,
  499. u16 twiceMaxRegulatoryPower,
  500. u16 powerLimit)
  501. {
  502. #define CMP_CTL \
  503. (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  504. pEepData->ctlIndex[i])
  505. #define CMP_NO_CTL \
  506. (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  507. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
  508. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
  509. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
  510. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  511. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  512. static const u16 tpScaleReductionTable[5] =
  513. { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
  514. int i;
  515. int16_t twiceLargestAntenna;
  516. struct cal_ctl_data_ar9287 *rep;
  517. struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
  518. targetPowerCck = {0, {0, 0, 0, 0} };
  519. struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
  520. targetPowerCckExt = {0, {0, 0, 0, 0} };
  521. struct cal_target_power_ht targetPowerHt20,
  522. targetPowerHt40 = {0, {0, 0, 0, 0} };
  523. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  524. u16 ctlModesFor11g[] = {CTL_11B,
  525. CTL_11G,
  526. CTL_2GHT20,
  527. CTL_11B_EXT,
  528. CTL_11G_EXT,
  529. CTL_2GHT40};
  530. u16 numCtlModes = 0, *pCtlMode = NULL, ctlMode, freq;
  531. struct chan_centers centers;
  532. int tx_chainmask;
  533. u16 twiceMinEdgePower;
  534. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  535. tx_chainmask = ah->txchainmask;
  536. ath9k_hw_get_channel_centers(ah, chan, &centers);
  537. /* Compute TxPower reduction due to Antenna Gain */
  538. twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
  539. pEepData->modalHeader.antennaGainCh[1]);
  540. twiceLargestAntenna = (int16_t)min((AntennaReduction) -
  541. twiceLargestAntenna, 0);
  542. /*
  543. * scaledPower is the minimum of the user input power level
  544. * and the regulatory allowed power level.
  545. */
  546. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  547. if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX)
  548. maxRegAllowedPower -=
  549. (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
  550. scaledPower = min(powerLimit, maxRegAllowedPower);
  551. /*
  552. * Reduce scaled Power by number of chains active
  553. * to get the per chain tx power level.
  554. */
  555. switch (ar5416_get_ntxchains(tx_chainmask)) {
  556. case 1:
  557. break;
  558. case 2:
  559. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  560. break;
  561. case 3:
  562. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  563. break;
  564. }
  565. scaledPower = max((u16)0, scaledPower);
  566. /*
  567. * Get TX power from EEPROM.
  568. */
  569. if (IS_CHAN_2GHZ(chan)) {
  570. /* CTL_11B, CTL_11G, CTL_2GHT20 */
  571. numCtlModes =
  572. ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
  573. pCtlMode = ctlModesFor11g;
  574. ath9k_hw_get_legacy_target_powers(ah, chan,
  575. pEepData->calTargetPowerCck,
  576. AR9287_NUM_2G_CCK_TARGET_POWERS,
  577. &targetPowerCck, 4, false);
  578. ath9k_hw_get_legacy_target_powers(ah, chan,
  579. pEepData->calTargetPower2G,
  580. AR9287_NUM_2G_20_TARGET_POWERS,
  581. &targetPowerOfdm, 4, false);
  582. ath9k_hw_get_target_powers(ah, chan,
  583. pEepData->calTargetPower2GHT20,
  584. AR9287_NUM_2G_20_TARGET_POWERS,
  585. &targetPowerHt20, 8, false);
  586. if (IS_CHAN_HT40(chan)) {
  587. /* All 2G CTLs */
  588. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  589. ath9k_hw_get_target_powers(ah, chan,
  590. pEepData->calTargetPower2GHT40,
  591. AR9287_NUM_2G_40_TARGET_POWERS,
  592. &targetPowerHt40, 8, true);
  593. ath9k_hw_get_legacy_target_powers(ah, chan,
  594. pEepData->calTargetPowerCck,
  595. AR9287_NUM_2G_CCK_TARGET_POWERS,
  596. &targetPowerCckExt, 4, true);
  597. ath9k_hw_get_legacy_target_powers(ah, chan,
  598. pEepData->calTargetPower2G,
  599. AR9287_NUM_2G_20_TARGET_POWERS,
  600. &targetPowerOfdmExt, 4, true);
  601. }
  602. }
  603. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  604. bool isHt40CtlMode =
  605. (pCtlMode[ctlMode] == CTL_2GHT40) ? true : false;
  606. if (isHt40CtlMode)
  607. freq = centers.synth_center;
  608. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  609. freq = centers.ext_center;
  610. else
  611. freq = centers.ctl_center;
  612. /* Walk through the CTL indices stored in EEPROM */
  613. for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  614. struct cal_ctl_edges *pRdEdgesPower;
  615. /*
  616. * Compare test group from regulatory channel list
  617. * with test mode from pCtlMode list
  618. */
  619. if (CMP_CTL || CMP_NO_CTL) {
  620. rep = &(pEepData->ctlData[i]);
  621. pRdEdgesPower =
  622. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1];
  623. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  624. pRdEdgesPower,
  625. IS_CHAN_2GHZ(chan),
  626. AR5416_NUM_BAND_EDGES);
  627. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  628. twiceMaxEdgePower = min(twiceMaxEdgePower,
  629. twiceMinEdgePower);
  630. } else {
  631. twiceMaxEdgePower = twiceMinEdgePower;
  632. break;
  633. }
  634. }
  635. }
  636. minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
  637. /* Apply ctl mode to correct target power set */
  638. switch (pCtlMode[ctlMode]) {
  639. case CTL_11B:
  640. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  641. targetPowerCck.tPow2x[i] =
  642. (u8)min((u16)targetPowerCck.tPow2x[i],
  643. minCtlPower);
  644. }
  645. break;
  646. case CTL_11A:
  647. case CTL_11G:
  648. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  649. targetPowerOfdm.tPow2x[i] =
  650. (u8)min((u16)targetPowerOfdm.tPow2x[i],
  651. minCtlPower);
  652. }
  653. break;
  654. case CTL_5GHT20:
  655. case CTL_2GHT20:
  656. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  657. targetPowerHt20.tPow2x[i] =
  658. (u8)min((u16)targetPowerHt20.tPow2x[i],
  659. minCtlPower);
  660. }
  661. break;
  662. case CTL_11B_EXT:
  663. targetPowerCckExt.tPow2x[0] =
  664. (u8)min((u16)targetPowerCckExt.tPow2x[0],
  665. minCtlPower);
  666. break;
  667. case CTL_11A_EXT:
  668. case CTL_11G_EXT:
  669. targetPowerOfdmExt.tPow2x[0] =
  670. (u8)min((u16)targetPowerOfdmExt.tPow2x[0],
  671. minCtlPower);
  672. break;
  673. case CTL_5GHT40:
  674. case CTL_2GHT40:
  675. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  676. targetPowerHt40.tPow2x[i] =
  677. (u8)min((u16)targetPowerHt40.tPow2x[i],
  678. minCtlPower);
  679. }
  680. break;
  681. default:
  682. break;
  683. }
  684. }
  685. /* Now set the rates array */
  686. ratesArray[rate6mb] =
  687. ratesArray[rate9mb] =
  688. ratesArray[rate12mb] =
  689. ratesArray[rate18mb] =
  690. ratesArray[rate24mb] = targetPowerOfdm.tPow2x[0];
  691. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  692. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  693. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  694. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  695. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  696. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  697. if (IS_CHAN_2GHZ(chan)) {
  698. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  699. ratesArray[rate2s] =
  700. ratesArray[rate2l] = targetPowerCck.tPow2x[1];
  701. ratesArray[rate5_5s] =
  702. ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
  703. ratesArray[rate11s] =
  704. ratesArray[rate11l] = targetPowerCck.tPow2x[3];
  705. }
  706. if (IS_CHAN_HT40(chan)) {
  707. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++)
  708. ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i];
  709. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  710. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  711. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  712. if (IS_CHAN_2GHZ(chan))
  713. ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
  714. }
  715. #undef CMP_CTL
  716. #undef CMP_NO_CTL
  717. #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
  718. #undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
  719. }
  720. static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
  721. struct ath9k_channel *chan, u16 cfgCtl,
  722. u8 twiceAntennaReduction,
  723. u8 twiceMaxRegulatoryPower,
  724. u8 powerLimit)
  725. {
  726. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  727. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  728. struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader;
  729. int16_t ratesArray[Ar5416RateSize];
  730. int16_t txPowerIndexOffset = 0;
  731. u8 ht40PowerIncForPdadc = 2;
  732. int i;
  733. memset(ratesArray, 0, sizeof(ratesArray));
  734. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  735. AR9287_EEP_MINOR_VER_2)
  736. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  737. ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
  738. &ratesArray[0], cfgCtl,
  739. twiceAntennaReduction,
  740. twiceMaxRegulatoryPower,
  741. powerLimit);
  742. ath9k_hw_set_ar9287_power_cal_table(ah, chan, &txPowerIndexOffset);
  743. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  744. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  745. if (ratesArray[i] > AR9287_MAX_RATE_POWER)
  746. ratesArray[i] = AR9287_MAX_RATE_POWER;
  747. }
  748. if (AR_SREV_9280_10_OR_LATER(ah)) {
  749. for (i = 0; i < Ar5416RateSize; i++)
  750. ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
  751. }
  752. /* OFDM power per rate */
  753. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  754. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  755. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  756. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  757. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  758. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  759. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  760. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  761. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  762. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  763. /* CCK power per rate */
  764. if (IS_CHAN_2GHZ(chan)) {
  765. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  766. ATH9K_POW_SM(ratesArray[rate2s], 24)
  767. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  768. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  769. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  770. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  771. ATH9K_POW_SM(ratesArray[rate11s], 24)
  772. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  773. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  774. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  775. }
  776. /* HT20 power per rate */
  777. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  778. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  779. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  780. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  781. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  782. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  783. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  784. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  785. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  786. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  787. /* HT40 power per rate */
  788. if (IS_CHAN_HT40(chan)) {
  789. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  790. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  791. ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
  792. | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
  793. | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
  794. | ATH9K_POW_SM(ratesArray[rateHt40_0], 0));
  795. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  796. ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
  797. | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
  798. | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
  799. | ATH9K_POW_SM(ratesArray[rateHt40_4], 0));
  800. } else {
  801. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  802. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  803. ht40PowerIncForPdadc, 24)
  804. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  805. ht40PowerIncForPdadc, 16)
  806. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  807. ht40PowerIncForPdadc, 8)
  808. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  809. ht40PowerIncForPdadc, 0));
  810. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  811. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  812. ht40PowerIncForPdadc, 24)
  813. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  814. ht40PowerIncForPdadc, 16)
  815. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  816. ht40PowerIncForPdadc, 8)
  817. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  818. ht40PowerIncForPdadc, 0));
  819. }
  820. /* Dup/Ext power per rate */
  821. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  822. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  823. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  824. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  825. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  826. }
  827. if (IS_CHAN_2GHZ(chan))
  828. i = rate1l;
  829. else
  830. i = rate6mb;
  831. if (AR_SREV_9280_10_OR_LATER(ah))
  832. regulatory->max_power_level =
  833. ratesArray[i] + AR9287_PWR_TABLE_OFFSET_DB * 2;
  834. else
  835. regulatory->max_power_level = ratesArray[i];
  836. }
  837. static void ath9k_hw_ar9287_set_addac(struct ath_hw *ah,
  838. struct ath9k_channel *chan)
  839. {
  840. }
  841. static void ath9k_hw_ar9287_set_board_values(struct ath_hw *ah,
  842. struct ath9k_channel *chan)
  843. {
  844. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  845. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  846. u16 antWrites[AR9287_ANT_16S];
  847. u32 regChainOffset, regval;
  848. u8 txRxAttenLocal;
  849. int i, j, offset_num;
  850. pModal = &eep->modalHeader;
  851. antWrites[0] = (u16)((pModal->antCtrlCommon >> 28) & 0xF);
  852. antWrites[1] = (u16)((pModal->antCtrlCommon >> 24) & 0xF);
  853. antWrites[2] = (u16)((pModal->antCtrlCommon >> 20) & 0xF);
  854. antWrites[3] = (u16)((pModal->antCtrlCommon >> 16) & 0xF);
  855. antWrites[4] = (u16)((pModal->antCtrlCommon >> 12) & 0xF);
  856. antWrites[5] = (u16)((pModal->antCtrlCommon >> 8) & 0xF);
  857. antWrites[6] = (u16)((pModal->antCtrlCommon >> 4) & 0xF);
  858. antWrites[7] = (u16)(pModal->antCtrlCommon & 0xF);
  859. offset_num = 8;
  860. for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) {
  861. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 28) & 0xf);
  862. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 10) & 0x3);
  863. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 8) & 0x3);
  864. antWrites[j++] = 0;
  865. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 6) & 0x3);
  866. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 4) & 0x3);
  867. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 2) & 0x3);
  868. antWrites[j++] = (u16)(pModal->antCtrlChain[i] & 0x3);
  869. }
  870. REG_WRITE(ah, AR_PHY_SWITCH_COM,
  871. ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
  872. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  873. regChainOffset = i * 0x1000;
  874. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  875. pModal->antCtrlChain[i]);
  876. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  877. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
  878. & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  879. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  880. SM(pModal->iqCalICh[i],
  881. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  882. SM(pModal->iqCalQCh[i],
  883. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  884. txRxAttenLocal = pModal->txRxAttenCh[i];
  885. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  886. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  887. pModal->bswMargin[i]);
  888. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  889. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  890. pModal->bswAtten[i]);
  891. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  892. AR9280_PHY_RXGAIN_TXRX_ATTEN,
  893. txRxAttenLocal);
  894. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  895. AR9280_PHY_RXGAIN_TXRX_MARGIN,
  896. pModal->rxTxMarginCh[i]);
  897. }
  898. if (IS_CHAN_HT40(chan))
  899. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  900. AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
  901. else
  902. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  903. AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
  904. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  905. AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
  906. REG_WRITE(ah, AR_PHY_RF_CTL4,
  907. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  908. | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  909. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  910. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  911. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
  912. AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
  913. REG_RMW_FIELD(ah, AR_PHY_CCA,
  914. AR9280_PHY_CCA_THRESH62, pModal->thresh62);
  915. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  916. AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
  917. regval = REG_READ(ah, AR9287_AN_RF2G3_CH0);
  918. regval &= ~(AR9287_AN_RF2G3_DB1 |
  919. AR9287_AN_RF2G3_DB2 |
  920. AR9287_AN_RF2G3_OB_CCK |
  921. AR9287_AN_RF2G3_OB_PSK |
  922. AR9287_AN_RF2G3_OB_QAM |
  923. AR9287_AN_RF2G3_OB_PAL_OFF);
  924. regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
  925. SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
  926. SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
  927. SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
  928. SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
  929. SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
  930. ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH0, regval);
  931. regval = REG_READ(ah, AR9287_AN_RF2G3_CH1);
  932. regval &= ~(AR9287_AN_RF2G3_DB1 |
  933. AR9287_AN_RF2G3_DB2 |
  934. AR9287_AN_RF2G3_OB_CCK |
  935. AR9287_AN_RF2G3_OB_PSK |
  936. AR9287_AN_RF2G3_OB_QAM |
  937. AR9287_AN_RF2G3_OB_PAL_OFF);
  938. regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
  939. SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
  940. SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
  941. SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
  942. SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
  943. SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
  944. ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH1, regval);
  945. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  946. AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
  947. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  948. AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
  949. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
  950. AR9287_AN_TOP2_XPABIAS_LVL,
  951. AR9287_AN_TOP2_XPABIAS_LVL_S,
  952. pModal->xpaBiasLvl);
  953. }
  954. static u8 ath9k_hw_ar9287_get_num_ant_config(struct ath_hw *ah,
  955. enum ieee80211_band freq_band)
  956. {
  957. return 1;
  958. }
  959. static u32 ath9k_hw_ar9287_get_eeprom_antenna_cfg(struct ath_hw *ah,
  960. struct ath9k_channel *chan)
  961. {
  962. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  963. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  964. return pModal->antCtrlCommon;
  965. }
  966. static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
  967. u16 i, bool is2GHz)
  968. {
  969. #define EEP_MAP9287_SPURCHAN \
  970. (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan)
  971. struct ath_common *common = ath9k_hw_common(ah);
  972. u16 spur_val = AR_NO_SPUR;
  973. ath_print(common, ATH_DBG_ANI,
  974. "Getting spur idx %d is2Ghz. %d val %x\n",
  975. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  976. switch (ah->config.spurmode) {
  977. case SPUR_DISABLE:
  978. break;
  979. case SPUR_ENABLE_IOCTL:
  980. spur_val = ah->config.spurchans[i][is2GHz];
  981. ath_print(common, ATH_DBG_ANI,
  982. "Getting spur val from new loc. %d\n", spur_val);
  983. break;
  984. case SPUR_ENABLE_EEPROM:
  985. spur_val = EEP_MAP9287_SPURCHAN;
  986. break;
  987. }
  988. return spur_val;
  989. #undef EEP_MAP9287_SPURCHAN
  990. }
  991. const struct eeprom_ops eep_ar9287_ops = {
  992. .check_eeprom = ath9k_hw_ar9287_check_eeprom,
  993. .get_eeprom = ath9k_hw_ar9287_get_eeprom,
  994. .fill_eeprom = ath9k_hw_ar9287_fill_eeprom,
  995. .get_eeprom_ver = ath9k_hw_ar9287_get_eeprom_ver,
  996. .get_eeprom_rev = ath9k_hw_ar9287_get_eeprom_rev,
  997. .get_num_ant_config = ath9k_hw_ar9287_get_num_ant_config,
  998. .get_eeprom_antenna_cfg = ath9k_hw_ar9287_get_eeprom_antenna_cfg,
  999. .set_board_values = ath9k_hw_ar9287_set_board_values,
  1000. .set_addac = ath9k_hw_ar9287_set_addac,
  1001. .set_txpower = ath9k_hw_ar9287_set_txpower,
  1002. .get_spur_channel = ath9k_hw_ar9287_get_spur_channel
  1003. };