eeprom_9287.c 35 KB

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