eeprom_9287.c 34 KB

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