eeprom_9287.c 34 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. #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. int16_t *pMinCalPower,
  191. u16 *pPdGainBoundaries,
  192. u8 *pPDADCValues,
  193. u16 numXpdGains)
  194. {
  195. #define TMP_VAL_VPD_TABLE \
  196. ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep));
  197. int i, j, k;
  198. int16_t ss;
  199. u16 idxL = 0, idxR = 0, numPiers;
  200. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  201. u8 minPwrT4[AR9287_NUM_PD_GAINS];
  202. u8 maxPwrT4[AR9287_NUM_PD_GAINS];
  203. int16_t vpdStep;
  204. int16_t tmpVal;
  205. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  206. bool match;
  207. int16_t minDelta = 0;
  208. struct chan_centers centers;
  209. static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS]
  210. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  211. static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS]
  212. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  213. static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS]
  214. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  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. *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
  260. k = 0;
  261. for (i = 0; i < numXpdGains; i++) {
  262. if (i == (numXpdGains - 1))
  263. pPdGainBoundaries[i] =
  264. (u16)(maxPwrT4[i] / 2);
  265. else
  266. pPdGainBoundaries[i] =
  267. (u16)((maxPwrT4[i] + minPwrT4[i+1]) / 4);
  268. pPdGainBoundaries[i] = min((u16)AR5416_MAX_RATE_POWER,
  269. pPdGainBoundaries[i]);
  270. minDelta = 0;
  271. if (i == 0) {
  272. if (AR_SREV_9280_10_OR_LATER(ah))
  273. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  274. else
  275. ss = 0;
  276. } else {
  277. ss = (int16_t)((pPdGainBoundaries[i-1] -
  278. (minPwrT4[i] / 2)) -
  279. tPdGainOverlap + 1 + minDelta);
  280. }
  281. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  282. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  283. while ((ss < 0) && (k < (AR9287_NUM_PDADC_VALUES - 1))) {
  284. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  285. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  286. ss++;
  287. }
  288. sizeCurrVpdTable = (u8)((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  289. tgtIndex = (u8)(pPdGainBoundaries[i] +
  290. tPdGainOverlap - (minPwrT4[i] / 2));
  291. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  292. tgtIndex : sizeCurrVpdTable;
  293. while ((ss < maxIndex) && (k < (AR9287_NUM_PDADC_VALUES - 1)))
  294. pPDADCValues[k++] = vpdTableI[i][ss++];
  295. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  296. vpdTableI[i][sizeCurrVpdTable - 2]);
  297. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  298. if (tgtIndex > maxIndex) {
  299. while ((ss <= tgtIndex) &&
  300. (k < (AR9287_NUM_PDADC_VALUES - 1))) {
  301. tmpVal = (int16_t) TMP_VAL_VPD_TABLE;
  302. pPDADCValues[k++] =
  303. (u8)((tmpVal > 255) ? 255 : tmpVal);
  304. ss++;
  305. }
  306. }
  307. }
  308. while (i < AR9287_PD_GAINS_IN_MASK) {
  309. pPdGainBoundaries[i] = pPdGainBoundaries[i-1];
  310. i++;
  311. }
  312. while (k < AR9287_NUM_PDADC_VALUES) {
  313. pPDADCValues[k] = pPDADCValues[k-1];
  314. k++;
  315. }
  316. #undef TMP_VAL_VPD_TABLE
  317. }
  318. static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah,
  319. struct ath9k_channel *chan,
  320. struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop,
  321. u8 *pCalChans, u16 availPiers, int8_t *pPwr)
  322. {
  323. u16 idxL = 0, idxR = 0, numPiers;
  324. bool match;
  325. struct chan_centers centers;
  326. ath9k_hw_get_channel_centers(ah, chan, &centers);
  327. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  328. if (pCalChans[numPiers] == AR9287_BCHAN_UNUSED)
  329. break;
  330. }
  331. match = ath9k_hw_get_lower_upper_index(
  332. (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
  333. pCalChans, numPiers, &idxL, &idxR);
  334. if (match) {
  335. *pPwr = (int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0];
  336. } else {
  337. *pPwr = ((int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0] +
  338. (int8_t) pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
  339. }
  340. }
  341. static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah,
  342. int32_t txPower, u16 chain)
  343. {
  344. u32 tmpVal;
  345. u32 a;
  346. /* Enable OLPC for chain 0 */
  347. tmpVal = REG_READ(ah, 0xa270);
  348. tmpVal = tmpVal & 0xFCFFFFFF;
  349. tmpVal = tmpVal | (0x3 << 24);
  350. REG_WRITE(ah, 0xa270, tmpVal);
  351. /* Enable OLPC for chain 1 */
  352. tmpVal = REG_READ(ah, 0xb270);
  353. tmpVal = tmpVal & 0xFCFFFFFF;
  354. tmpVal = tmpVal | (0x3 << 24);
  355. REG_WRITE(ah, 0xb270, tmpVal);
  356. /* Write the OLPC ref power for chain 0 */
  357. if (chain == 0) {
  358. tmpVal = REG_READ(ah, 0xa398);
  359. tmpVal = tmpVal & 0xff00ffff;
  360. a = (txPower)&0xff;
  361. tmpVal = tmpVal | (a << 16);
  362. REG_WRITE(ah, 0xa398, tmpVal);
  363. }
  364. /* Write the OLPC ref power for chain 1 */
  365. if (chain == 1) {
  366. tmpVal = REG_READ(ah, 0xb398);
  367. tmpVal = tmpVal & 0xff00ffff;
  368. a = (txPower)&0xff;
  369. tmpVal = tmpVal | (a << 16);
  370. REG_WRITE(ah, 0xb398, tmpVal);
  371. }
  372. }
  373. static void ath9k_hw_set_ar9287_power_cal_table(struct ath_hw *ah,
  374. struct ath9k_channel *chan,
  375. int16_t *pTxPowerIndexOffset)
  376. {
  377. struct cal_data_per_freq_ar9287 *pRawDataset;
  378. struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
  379. u8 *pCalBChans = NULL;
  380. u16 pdGainOverlap_t2;
  381. u8 pdadcValues[AR9287_NUM_PDADC_VALUES];
  382. u16 gainBoundaries[AR9287_PD_GAINS_IN_MASK];
  383. u16 numPiers = 0, i, j;
  384. int16_t tMinCalPower;
  385. u16 numXpdGain, xpdMask;
  386. u16 xpdGainValues[AR9287_NUM_PD_GAINS] = {0, 0, 0, 0};
  387. u32 reg32, regOffset, regChainOffset, regval;
  388. int16_t modalIdx, diff = 0;
  389. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  390. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  391. xpdMask = pEepData->modalHeader.xpdGain;
  392. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  393. AR9287_EEP_MINOR_VER_2)
  394. pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
  395. else
  396. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  397. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  398. if (IS_CHAN_2GHZ(chan)) {
  399. pCalBChans = pEepData->calFreqPier2G;
  400. numPiers = AR9287_NUM_2G_CAL_PIERS;
  401. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  402. pRawDatasetOpenLoop =
  403. (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];
  404. ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
  405. }
  406. }
  407. numXpdGain = 0;
  408. /* Calculate the value of xpdgains from the xpdGain Mask */
  409. for (i = 1; i <= AR9287_PD_GAINS_IN_MASK; i++) {
  410. if ((xpdMask >> (AR9287_PD_GAINS_IN_MASK - i)) & 1) {
  411. if (numXpdGain >= AR9287_NUM_PD_GAINS)
  412. break;
  413. xpdGainValues[numXpdGain] =
  414. (u16)(AR9287_PD_GAINS_IN_MASK-i);
  415. numXpdGain++;
  416. }
  417. }
  418. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  419. (numXpdGain - 1) & 0x3);
  420. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  421. xpdGainValues[0]);
  422. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  423. xpdGainValues[1]);
  424. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  425. xpdGainValues[2]);
  426. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  427. regChainOffset = i * 0x1000;
  428. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  429. pRawDatasetOpenLoop =
  430. (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];
  431. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  432. int8_t txPower;
  433. ar9287_eeprom_get_tx_gain_index(ah, chan,
  434. pRawDatasetOpenLoop,
  435. pCalBChans, numPiers,
  436. &txPower);
  437. ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i);
  438. } else {
  439. pRawDataset =
  440. (struct cal_data_per_freq_ar9287 *)
  441. pEepData->calPierData2G[i];
  442. ath9k_hw_get_ar9287_gain_boundaries_pdadcs(ah, chan,
  443. pRawDataset,
  444. pCalBChans, numPiers,
  445. pdGainOverlap_t2,
  446. &tMinCalPower,
  447. gainBoundaries,
  448. pdadcValues,
  449. numXpdGain);
  450. }
  451. if (i == 0) {
  452. if (!ath9k_hw_ar9287_get_eeprom(ah,
  453. EEP_OL_PWRCTRL)) {
  454. regval = SM(pdGainOverlap_t2,
  455. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
  456. | SM(gainBoundaries[0],
  457. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
  458. | SM(gainBoundaries[1],
  459. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
  460. | SM(gainBoundaries[2],
  461. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
  462. | SM(gainBoundaries[3],
  463. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4);
  464. REG_WRITE(ah,
  465. AR_PHY_TPCRG5 + regChainOffset,
  466. regval);
  467. }
  468. }
  469. if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB !=
  470. pEepData->baseEepHeader.pwrTableOffset) {
  471. diff = (u16)(pEepData->baseEepHeader.pwrTableOffset -
  472. (int32_t)AR9287_PWR_TABLE_OFFSET_DB);
  473. diff *= 2;
  474. for (j = 0; j < ((u16)AR9287_NUM_PDADC_VALUES-diff); j++)
  475. pdadcValues[j] = pdadcValues[j+diff];
  476. for (j = (u16)(AR9287_NUM_PDADC_VALUES-diff);
  477. j < AR9287_NUM_PDADC_VALUES; j++)
  478. pdadcValues[j] =
  479. pdadcValues[AR9287_NUM_PDADC_VALUES-diff];
  480. }
  481. if (!ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  482. regOffset = AR_PHY_BASE +
  483. (672 << 2) + regChainOffset;
  484. for (j = 0; j < 32; j++) {
  485. reg32 = ((pdadcValues[4*j + 0] & 0xFF) << 0)
  486. | ((pdadcValues[4*j + 1] & 0xFF) << 8)
  487. | ((pdadcValues[4*j + 2] & 0xFF) << 16)
  488. | ((pdadcValues[4*j + 3] & 0xFF) << 24);
  489. REG_WRITE(ah, regOffset, reg32);
  490. regOffset += 4;
  491. }
  492. }
  493. }
  494. }
  495. *pTxPowerIndexOffset = 0;
  496. }
  497. static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
  498. struct ath9k_channel *chan,
  499. int16_t *ratesArray,
  500. u16 cfgCtl,
  501. u16 AntennaReduction,
  502. u16 twiceMaxRegulatoryPower,
  503. u16 powerLimit)
  504. {
  505. #define CMP_CTL \
  506. (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  507. pEepData->ctlIndex[i])
  508. #define CMP_NO_CTL \
  509. (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  510. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
  511. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
  512. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
  513. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  514. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  515. static const u16 tpScaleReductionTable[5] =
  516. { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
  517. int i;
  518. int16_t twiceLargestAntenna;
  519. struct cal_ctl_data_ar9287 *rep;
  520. struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
  521. targetPowerCck = {0, {0, 0, 0, 0} };
  522. struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
  523. targetPowerCckExt = {0, {0, 0, 0, 0} };
  524. struct cal_target_power_ht targetPowerHt20,
  525. targetPowerHt40 = {0, {0, 0, 0, 0} };
  526. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  527. u16 ctlModesFor11g[] = {CTL_11B,
  528. CTL_11G,
  529. CTL_2GHT20,
  530. CTL_11B_EXT,
  531. CTL_11G_EXT,
  532. CTL_2GHT40};
  533. u16 numCtlModes = 0, *pCtlMode = NULL, ctlMode, freq;
  534. struct chan_centers centers;
  535. int tx_chainmask;
  536. u16 twiceMinEdgePower;
  537. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  538. tx_chainmask = ah->txchainmask;
  539. ath9k_hw_get_channel_centers(ah, chan, &centers);
  540. /* Compute TxPower reduction due to Antenna Gain */
  541. twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
  542. pEepData->modalHeader.antennaGainCh[1]);
  543. twiceLargestAntenna = (int16_t)min((AntennaReduction) -
  544. twiceLargestAntenna, 0);
  545. /*
  546. * scaledPower is the minimum of the user input power level
  547. * and the regulatory allowed power level.
  548. */
  549. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  550. if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX)
  551. maxRegAllowedPower -=
  552. (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
  553. scaledPower = min(powerLimit, maxRegAllowedPower);
  554. /*
  555. * Reduce scaled Power by number of chains active
  556. * to get the per chain tx power level.
  557. */
  558. switch (ar5416_get_ntxchains(tx_chainmask)) {
  559. case 1:
  560. break;
  561. case 2:
  562. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  563. break;
  564. case 3:
  565. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  566. break;
  567. }
  568. scaledPower = max((u16)0, scaledPower);
  569. /*
  570. * Get TX power from EEPROM.
  571. */
  572. if (IS_CHAN_2GHZ(chan)) {
  573. /* CTL_11B, CTL_11G, CTL_2GHT20 */
  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. /* All 2G CTLs */
  591. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  592. ath9k_hw_get_target_powers(ah, chan,
  593. pEepData->calTargetPower2GHT40,
  594. AR9287_NUM_2G_40_TARGET_POWERS,
  595. &targetPowerHt40, 8, true);
  596. ath9k_hw_get_legacy_target_powers(ah, chan,
  597. pEepData->calTargetPowerCck,
  598. AR9287_NUM_2G_CCK_TARGET_POWERS,
  599. &targetPowerCckExt, 4, true);
  600. ath9k_hw_get_legacy_target_powers(ah, chan,
  601. pEepData->calTargetPower2G,
  602. AR9287_NUM_2G_20_TARGET_POWERS,
  603. &targetPowerOfdmExt, 4, true);
  604. }
  605. }
  606. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  607. bool isHt40CtlMode =
  608. (pCtlMode[ctlMode] == CTL_2GHT40) ? true : false;
  609. if (isHt40CtlMode)
  610. freq = centers.synth_center;
  611. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  612. freq = centers.ext_center;
  613. else
  614. freq = centers.ctl_center;
  615. /* Walk through the CTL indices stored in EEPROM */
  616. for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  617. struct cal_ctl_edges *pRdEdgesPower;
  618. /*
  619. * Compare test group from regulatory channel list
  620. * with test mode from pCtlMode list
  621. */
  622. if (CMP_CTL || CMP_NO_CTL) {
  623. rep = &(pEepData->ctlData[i]);
  624. pRdEdgesPower =
  625. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1];
  626. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  627. pRdEdgesPower,
  628. IS_CHAN_2GHZ(chan),
  629. AR5416_NUM_BAND_EDGES);
  630. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  631. twiceMaxEdgePower = min(twiceMaxEdgePower,
  632. twiceMinEdgePower);
  633. } else {
  634. twiceMaxEdgePower = twiceMinEdgePower;
  635. break;
  636. }
  637. }
  638. }
  639. minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
  640. /* Apply ctl mode to correct target power set */
  641. switch (pCtlMode[ctlMode]) {
  642. case CTL_11B:
  643. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  644. targetPowerCck.tPow2x[i] =
  645. (u8)min((u16)targetPowerCck.tPow2x[i],
  646. minCtlPower);
  647. }
  648. break;
  649. case CTL_11A:
  650. case CTL_11G:
  651. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  652. targetPowerOfdm.tPow2x[i] =
  653. (u8)min((u16)targetPowerOfdm.tPow2x[i],
  654. minCtlPower);
  655. }
  656. break;
  657. case CTL_5GHT20:
  658. case CTL_2GHT20:
  659. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  660. targetPowerHt20.tPow2x[i] =
  661. (u8)min((u16)targetPowerHt20.tPow2x[i],
  662. minCtlPower);
  663. }
  664. break;
  665. case CTL_11B_EXT:
  666. targetPowerCckExt.tPow2x[0] =
  667. (u8)min((u16)targetPowerCckExt.tPow2x[0],
  668. minCtlPower);
  669. break;
  670. case CTL_11A_EXT:
  671. case CTL_11G_EXT:
  672. targetPowerOfdmExt.tPow2x[0] =
  673. (u8)min((u16)targetPowerOfdmExt.tPow2x[0],
  674. minCtlPower);
  675. break;
  676. case CTL_5GHT40:
  677. case CTL_2GHT40:
  678. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  679. targetPowerHt40.tPow2x[i] =
  680. (u8)min((u16)targetPowerHt40.tPow2x[i],
  681. minCtlPower);
  682. }
  683. break;
  684. default:
  685. break;
  686. }
  687. }
  688. /* Now set the rates array */
  689. ratesArray[rate6mb] =
  690. ratesArray[rate9mb] =
  691. ratesArray[rate12mb] =
  692. ratesArray[rate18mb] =
  693. ratesArray[rate24mb] = targetPowerOfdm.tPow2x[0];
  694. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  695. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  696. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  697. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  698. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  699. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  700. if (IS_CHAN_2GHZ(chan)) {
  701. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  702. ratesArray[rate2s] =
  703. ratesArray[rate2l] = targetPowerCck.tPow2x[1];
  704. ratesArray[rate5_5s] =
  705. ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
  706. ratesArray[rate11s] =
  707. ratesArray[rate11l] = targetPowerCck.tPow2x[3];
  708. }
  709. if (IS_CHAN_HT40(chan)) {
  710. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++)
  711. ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i];
  712. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  713. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  714. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  715. if (IS_CHAN_2GHZ(chan))
  716. ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
  717. }
  718. #undef CMP_CTL
  719. #undef CMP_NO_CTL
  720. #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
  721. #undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
  722. }
  723. static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
  724. struct ath9k_channel *chan, u16 cfgCtl,
  725. u8 twiceAntennaReduction,
  726. u8 twiceMaxRegulatoryPower,
  727. u8 powerLimit)
  728. {
  729. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  730. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  731. struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader;
  732. int16_t ratesArray[Ar5416RateSize];
  733. int16_t txPowerIndexOffset = 0;
  734. u8 ht40PowerIncForPdadc = 2;
  735. int i;
  736. memset(ratesArray, 0, sizeof(ratesArray));
  737. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  738. AR9287_EEP_MINOR_VER_2)
  739. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  740. ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
  741. &ratesArray[0], cfgCtl,
  742. twiceAntennaReduction,
  743. twiceMaxRegulatoryPower,
  744. powerLimit);
  745. ath9k_hw_set_ar9287_power_cal_table(ah, chan, &txPowerIndexOffset);
  746. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  747. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  748. if (ratesArray[i] > AR9287_MAX_RATE_POWER)
  749. ratesArray[i] = AR9287_MAX_RATE_POWER;
  750. }
  751. if (AR_SREV_9280_10_OR_LATER(ah)) {
  752. for (i = 0; i < Ar5416RateSize; i++)
  753. ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
  754. }
  755. /* OFDM power per rate */
  756. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  757. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  758. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  759. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  760. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  761. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  762. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  763. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  764. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  765. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  766. /* CCK power per rate */
  767. if (IS_CHAN_2GHZ(chan)) {
  768. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  769. ATH9K_POW_SM(ratesArray[rate2s], 24)
  770. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  771. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  772. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  773. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  774. ATH9K_POW_SM(ratesArray[rate11s], 24)
  775. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  776. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  777. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  778. }
  779. /* HT20 power per rate */
  780. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  781. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  782. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  783. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  784. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  785. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  786. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  787. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  788. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  789. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  790. /* HT40 power per rate */
  791. if (IS_CHAN_HT40(chan)) {
  792. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  793. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  794. ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
  795. | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
  796. | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
  797. | ATH9K_POW_SM(ratesArray[rateHt40_0], 0));
  798. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  799. ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
  800. | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
  801. | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
  802. | ATH9K_POW_SM(ratesArray[rateHt40_4], 0));
  803. } else {
  804. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  805. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  806. ht40PowerIncForPdadc, 24)
  807. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  808. ht40PowerIncForPdadc, 16)
  809. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  810. ht40PowerIncForPdadc, 8)
  811. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  812. ht40PowerIncForPdadc, 0));
  813. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  814. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  815. ht40PowerIncForPdadc, 24)
  816. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  817. ht40PowerIncForPdadc, 16)
  818. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  819. ht40PowerIncForPdadc, 8)
  820. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  821. ht40PowerIncForPdadc, 0));
  822. }
  823. /* Dup/Ext power per rate */
  824. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  825. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  826. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  827. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  828. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  829. }
  830. if (IS_CHAN_2GHZ(chan))
  831. i = rate1l;
  832. else
  833. i = rate6mb;
  834. if (AR_SREV_9280_10_OR_LATER(ah))
  835. regulatory->max_power_level =
  836. ratesArray[i] + AR9287_PWR_TABLE_OFFSET_DB * 2;
  837. else
  838. regulatory->max_power_level = ratesArray[i];
  839. }
  840. static void ath9k_hw_ar9287_set_addac(struct ath_hw *ah,
  841. struct ath9k_channel *chan)
  842. {
  843. }
  844. static void ath9k_hw_ar9287_set_board_values(struct ath_hw *ah,
  845. struct ath9k_channel *chan)
  846. {
  847. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  848. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  849. u16 antWrites[AR9287_ANT_16S];
  850. u32 regChainOffset, regval;
  851. u8 txRxAttenLocal;
  852. int i, j, offset_num;
  853. pModal = &eep->modalHeader;
  854. antWrites[0] = (u16)((pModal->antCtrlCommon >> 28) & 0xF);
  855. antWrites[1] = (u16)((pModal->antCtrlCommon >> 24) & 0xF);
  856. antWrites[2] = (u16)((pModal->antCtrlCommon >> 20) & 0xF);
  857. antWrites[3] = (u16)((pModal->antCtrlCommon >> 16) & 0xF);
  858. antWrites[4] = (u16)((pModal->antCtrlCommon >> 12) & 0xF);
  859. antWrites[5] = (u16)((pModal->antCtrlCommon >> 8) & 0xF);
  860. antWrites[6] = (u16)((pModal->antCtrlCommon >> 4) & 0xF);
  861. antWrites[7] = (u16)(pModal->antCtrlCommon & 0xF);
  862. offset_num = 8;
  863. for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) {
  864. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 28) & 0xf);
  865. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 10) & 0x3);
  866. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 8) & 0x3);
  867. antWrites[j++] = 0;
  868. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 6) & 0x3);
  869. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 4) & 0x3);
  870. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 2) & 0x3);
  871. antWrites[j++] = (u16)(pModal->antCtrlChain[i] & 0x3);
  872. }
  873. REG_WRITE(ah, AR_PHY_SWITCH_COM,
  874. ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
  875. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  876. regChainOffset = i * 0x1000;
  877. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  878. pModal->antCtrlChain[i]);
  879. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  880. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
  881. & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  882. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  883. SM(pModal->iqCalICh[i],
  884. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  885. SM(pModal->iqCalQCh[i],
  886. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  887. txRxAttenLocal = pModal->txRxAttenCh[i];
  888. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  889. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  890. pModal->bswMargin[i]);
  891. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  892. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  893. pModal->bswAtten[i]);
  894. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  895. AR9280_PHY_RXGAIN_TXRX_ATTEN,
  896. txRxAttenLocal);
  897. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  898. AR9280_PHY_RXGAIN_TXRX_MARGIN,
  899. pModal->rxTxMarginCh[i]);
  900. }
  901. if (IS_CHAN_HT40(chan))
  902. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  903. AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
  904. else
  905. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  906. AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
  907. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  908. AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
  909. REG_WRITE(ah, AR_PHY_RF_CTL4,
  910. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  911. | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  912. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  913. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  914. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
  915. AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
  916. REG_RMW_FIELD(ah, AR_PHY_CCA,
  917. AR9280_PHY_CCA_THRESH62, pModal->thresh62);
  918. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  919. AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
  920. regval = REG_READ(ah, AR9287_AN_RF2G3_CH0);
  921. regval &= ~(AR9287_AN_RF2G3_DB1 |
  922. AR9287_AN_RF2G3_DB2 |
  923. AR9287_AN_RF2G3_OB_CCK |
  924. AR9287_AN_RF2G3_OB_PSK |
  925. AR9287_AN_RF2G3_OB_QAM |
  926. AR9287_AN_RF2G3_OB_PAL_OFF);
  927. regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
  928. SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
  929. SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
  930. SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
  931. SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
  932. SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
  933. ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH0, regval);
  934. regval = REG_READ(ah, AR9287_AN_RF2G3_CH1);
  935. regval &= ~(AR9287_AN_RF2G3_DB1 |
  936. AR9287_AN_RF2G3_DB2 |
  937. AR9287_AN_RF2G3_OB_CCK |
  938. AR9287_AN_RF2G3_OB_PSK |
  939. AR9287_AN_RF2G3_OB_QAM |
  940. AR9287_AN_RF2G3_OB_PAL_OFF);
  941. regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
  942. SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
  943. SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
  944. SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
  945. SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
  946. SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
  947. ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH1, regval);
  948. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  949. AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
  950. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  951. AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
  952. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
  953. AR9287_AN_TOP2_XPABIAS_LVL,
  954. AR9287_AN_TOP2_XPABIAS_LVL_S,
  955. pModal->xpaBiasLvl);
  956. }
  957. static u8 ath9k_hw_ar9287_get_num_ant_config(struct ath_hw *ah,
  958. enum ieee80211_band freq_band)
  959. {
  960. return 1;
  961. }
  962. static u16 ath9k_hw_ar9287_get_eeprom_antenna_cfg(struct ath_hw *ah,
  963. struct ath9k_channel *chan)
  964. {
  965. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  966. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  967. return pModal->antCtrlCommon & 0xFFFF;
  968. }
  969. static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
  970. u16 i, bool is2GHz)
  971. {
  972. #define EEP_MAP9287_SPURCHAN \
  973. (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan)
  974. struct ath_common *common = ath9k_hw_common(ah);
  975. u16 spur_val = AR_NO_SPUR;
  976. ath_print(common, ATH_DBG_ANI,
  977. "Getting spur idx %d is2Ghz. %d val %x\n",
  978. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  979. switch (ah->config.spurmode) {
  980. case SPUR_DISABLE:
  981. break;
  982. case SPUR_ENABLE_IOCTL:
  983. spur_val = ah->config.spurchans[i][is2GHz];
  984. ath_print(common, ATH_DBG_ANI,
  985. "Getting spur val from new loc. %d\n", spur_val);
  986. break;
  987. case SPUR_ENABLE_EEPROM:
  988. spur_val = EEP_MAP9287_SPURCHAN;
  989. break;
  990. }
  991. return spur_val;
  992. #undef EEP_MAP9287_SPURCHAN
  993. }
  994. const struct eeprom_ops eep_ar9287_ops = {
  995. .check_eeprom = ath9k_hw_ar9287_check_eeprom,
  996. .get_eeprom = ath9k_hw_ar9287_get_eeprom,
  997. .fill_eeprom = ath9k_hw_ar9287_fill_eeprom,
  998. .get_eeprom_ver = ath9k_hw_ar9287_get_eeprom_ver,
  999. .get_eeprom_rev = ath9k_hw_ar9287_get_eeprom_rev,
  1000. .get_num_ant_config = ath9k_hw_ar9287_get_num_ant_config,
  1001. .get_eeprom_antenna_cfg = ath9k_hw_ar9287_get_eeprom_antenna_cfg,
  1002. .set_board_values = ath9k_hw_ar9287_set_board_values,
  1003. .set_addac = ath9k_hw_ar9287_set_addac,
  1004. .set_txpower = ath9k_hw_ar9287_set_txpower,
  1005. .get_spur_channel = ath9k_hw_ar9287_get_spur_channel
  1006. };