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 (common->bus_ops->ath_bus_type == ATH_USB)
  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_dbg(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_dbg(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_err(common, "Reading Magic # failed\n");
  65. return false;
  66. }
  67. ath_dbg(common, ATH_DBG_EEPROM,
  68. "Read Magic = 0x%04X\n", magic);
  69. if (magic != AR5416_EEPROM_MAGIC) {
  70. magic2 = swab16(magic);
  71. if (magic2 == AR5416_EEPROM_MAGIC) {
  72. need_swap = true;
  73. eepdata = (u16 *)(&ah->eeprom);
  74. for (addr = 0; addr < NUM_EEP_WORDS; addr++) {
  75. temp = swab16(*eepdata);
  76. *eepdata = temp;
  77. eepdata++;
  78. }
  79. } else {
  80. ath_err(common,
  81. "Invalid EEPROM Magic. Endianness mismatch.\n");
  82. return -EINVAL;
  83. }
  84. }
  85. }
  86. ath_dbg(common, ATH_DBG_EEPROM, "need_swap = %s.\n",
  87. need_swap ? "True" : "False");
  88. if (need_swap)
  89. el = swab16(ah->eeprom.map9287.baseEepHeader.length);
  90. else
  91. el = ah->eeprom.map9287.baseEepHeader.length;
  92. if (el > sizeof(struct ar9287_eeprom))
  93. el = sizeof(struct ar9287_eeprom) / sizeof(u16);
  94. else
  95. el = el / sizeof(u16);
  96. eepdata = (u16 *)(&ah->eeprom);
  97. for (i = 0; i < el; i++)
  98. sum ^= *eepdata++;
  99. if (need_swap) {
  100. word = swab16(eep->baseEepHeader.length);
  101. eep->baseEepHeader.length = word;
  102. word = swab16(eep->baseEepHeader.checksum);
  103. eep->baseEepHeader.checksum = word;
  104. word = swab16(eep->baseEepHeader.version);
  105. eep->baseEepHeader.version = word;
  106. word = swab16(eep->baseEepHeader.regDmn[0]);
  107. eep->baseEepHeader.regDmn[0] = word;
  108. word = swab16(eep->baseEepHeader.regDmn[1]);
  109. eep->baseEepHeader.regDmn[1] = word;
  110. word = swab16(eep->baseEepHeader.rfSilent);
  111. eep->baseEepHeader.rfSilent = word;
  112. word = swab16(eep->baseEepHeader.blueToothOptions);
  113. eep->baseEepHeader.blueToothOptions = word;
  114. word = swab16(eep->baseEepHeader.deviceCap);
  115. eep->baseEepHeader.deviceCap = word;
  116. integer = swab32(eep->modalHeader.antCtrlCommon);
  117. eep->modalHeader.antCtrlCommon = integer;
  118. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  119. integer = swab32(eep->modalHeader.antCtrlChain[i]);
  120. eep->modalHeader.antCtrlChain[i] = integer;
  121. }
  122. for (i = 0; i < AR9287_EEPROM_MODAL_SPURS; i++) {
  123. word = swab16(eep->modalHeader.spurChans[i].spurChan);
  124. eep->modalHeader.spurChans[i].spurChan = word;
  125. }
  126. }
  127. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR9287_EEP_VER
  128. || ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  129. ath_err(common, "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 EEP_MAC_LSW:
  147. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  148. case EEP_MAC_MID:
  149. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  150. case EEP_MAC_MSW:
  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,
  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. memset(&minPwrT4, 0, AR9287_NUM_PD_GAINS);
  216. ath9k_hw_get_channel_centers(ah, chan, &centers);
  217. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  218. if (bChans[numPiers] == AR9287_BCHAN_UNUSED)
  219. break;
  220. }
  221. match = ath9k_hw_get_lower_upper_index(
  222. (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
  223. bChans, numPiers, &idxL, &idxR);
  224. if (match) {
  225. for (i = 0; i < numXpdGains; i++) {
  226. minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
  227. maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
  228. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  229. pRawDataSet[idxL].pwrPdg[i],
  230. pRawDataSet[idxL].vpdPdg[i],
  231. AR9287_PD_GAIN_ICEPTS,
  232. vpdTableI[i]);
  233. }
  234. } else {
  235. for (i = 0; i < numXpdGains; i++) {
  236. pVpdL = pRawDataSet[idxL].vpdPdg[i];
  237. pPwrL = pRawDataSet[idxL].pwrPdg[i];
  238. pVpdR = pRawDataSet[idxR].vpdPdg[i];
  239. pPwrR = pRawDataSet[idxR].pwrPdg[i];
  240. minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
  241. maxPwrT4[i] = min(pPwrL[AR9287_PD_GAIN_ICEPTS - 1],
  242. pPwrR[AR9287_PD_GAIN_ICEPTS - 1]);
  243. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  244. pPwrL, pVpdL,
  245. AR9287_PD_GAIN_ICEPTS,
  246. vpdTableL[i]);
  247. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  248. pPwrR, pVpdR,
  249. AR9287_PD_GAIN_ICEPTS,
  250. vpdTableR[i]);
  251. for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
  252. vpdTableI[i][j] = (u8)(ath9k_hw_interpolate(
  253. (u16)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. 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_20_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. u16 numXpdGain, xpdMask;
  385. u16 xpdGainValues[AR9287_NUM_PD_GAINS] = {0, 0, 0, 0};
  386. u32 reg32, regOffset, regChainOffset, regval;
  387. int16_t modalIdx, diff = 0;
  388. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  389. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  390. xpdMask = pEepData->modalHeader.xpdGain;
  391. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  392. AR9287_EEP_MINOR_VER_2)
  393. pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
  394. else
  395. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  396. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  397. if (IS_CHAN_2GHZ(chan)) {
  398. pCalBChans = pEepData->calFreqPier2G;
  399. numPiers = AR9287_NUM_2G_CAL_PIERS;
  400. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  401. pRawDatasetOpenLoop =
  402. (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];
  403. ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
  404. }
  405. }
  406. numXpdGain = 0;
  407. /* Calculate the value of xpdgains from the xpdGain Mask */
  408. for (i = 1; i <= AR9287_PD_GAINS_IN_MASK; i++) {
  409. if ((xpdMask >> (AR9287_PD_GAINS_IN_MASK - i)) & 1) {
  410. if (numXpdGain >= AR9287_NUM_PD_GAINS)
  411. break;
  412. xpdGainValues[numXpdGain] =
  413. (u16)(AR9287_PD_GAINS_IN_MASK-i);
  414. numXpdGain++;
  415. }
  416. }
  417. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  418. (numXpdGain - 1) & 0x3);
  419. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  420. xpdGainValues[0]);
  421. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  422. xpdGainValues[1]);
  423. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  424. xpdGainValues[2]);
  425. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  426. regChainOffset = i * 0x1000;
  427. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  428. pRawDatasetOpenLoop =
  429. (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];
  430. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  431. int8_t txPower;
  432. ar9287_eeprom_get_tx_gain_index(ah, chan,
  433. pRawDatasetOpenLoop,
  434. pCalBChans, numPiers,
  435. &txPower);
  436. ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i);
  437. } else {
  438. pRawDataset =
  439. (struct cal_data_per_freq_ar9287 *)
  440. pEepData->calPierData2G[i];
  441. ath9k_hw_get_ar9287_gain_boundaries_pdadcs(ah, chan,
  442. pRawDataset,
  443. pCalBChans, numPiers,
  444. pdGainOverlap_t2,
  445. gainBoundaries,
  446. pdadcValues,
  447. numXpdGain);
  448. }
  449. if (i == 0) {
  450. if (!ath9k_hw_ar9287_get_eeprom(ah,
  451. EEP_OL_PWRCTRL)) {
  452. regval = SM(pdGainOverlap_t2,
  453. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
  454. | SM(gainBoundaries[0],
  455. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
  456. | SM(gainBoundaries[1],
  457. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
  458. | SM(gainBoundaries[2],
  459. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
  460. | SM(gainBoundaries[3],
  461. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4);
  462. REG_WRITE(ah,
  463. AR_PHY_TPCRG5 + regChainOffset,
  464. regval);
  465. }
  466. }
  467. if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB !=
  468. pEepData->baseEepHeader.pwrTableOffset) {
  469. diff = (u16)(pEepData->baseEepHeader.pwrTableOffset -
  470. (int32_t)AR9287_PWR_TABLE_OFFSET_DB);
  471. diff *= 2;
  472. for (j = 0; j < ((u16)AR9287_NUM_PDADC_VALUES-diff); j++)
  473. pdadcValues[j] = pdadcValues[j+diff];
  474. for (j = (u16)(AR9287_NUM_PDADC_VALUES-diff);
  475. j < AR9287_NUM_PDADC_VALUES; j++)
  476. pdadcValues[j] =
  477. pdadcValues[AR9287_NUM_PDADC_VALUES-diff];
  478. }
  479. if (!ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  480. regOffset = AR_PHY_BASE +
  481. (672 << 2) + regChainOffset;
  482. for (j = 0; j < 32; j++) {
  483. reg32 = ((pdadcValues[4*j + 0] & 0xFF) << 0)
  484. | ((pdadcValues[4*j + 1] & 0xFF) << 8)
  485. | ((pdadcValues[4*j + 2] & 0xFF) << 16)
  486. | ((pdadcValues[4*j + 3] & 0xFF) << 24);
  487. REG_WRITE(ah, regOffset, reg32);
  488. regOffset += 4;
  489. }
  490. }
  491. }
  492. }
  493. *pTxPowerIndexOffset = 0;
  494. }
  495. static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
  496. struct ath9k_channel *chan,
  497. int16_t *ratesArray,
  498. u16 cfgCtl,
  499. u16 AntennaReduction,
  500. u16 twiceMaxRegulatoryPower,
  501. u16 powerLimit)
  502. {
  503. #define CMP_CTL \
  504. (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  505. pEepData->ctlIndex[i])
  506. #define CMP_NO_CTL \
  507. (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
  508. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
  509. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
  510. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
  511. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  512. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  513. static const u16 tpScaleReductionTable[5] =
  514. { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
  515. int i;
  516. int16_t twiceLargestAntenna;
  517. struct cal_ctl_data_ar9287 *rep;
  518. struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
  519. targetPowerCck = {0, {0, 0, 0, 0} };
  520. struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
  521. targetPowerCckExt = {0, {0, 0, 0, 0} };
  522. struct cal_target_power_ht targetPowerHt20,
  523. targetPowerHt40 = {0, {0, 0, 0, 0} };
  524. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  525. static const u16 ctlModesFor11g[] = {
  526. CTL_11B, CTL_11G, CTL_2GHT20,
  527. CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
  528. };
  529. u16 numCtlModes = 0;
  530. const u16 *pCtlMode = NULL;
  531. u16 ctlMode, freq;
  532. struct chan_centers centers;
  533. int tx_chainmask;
  534. u16 twiceMinEdgePower;
  535. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  536. tx_chainmask = ah->txchainmask;
  537. ath9k_hw_get_channel_centers(ah, chan, &centers);
  538. /* Compute TxPower reduction due to Antenna Gain */
  539. twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
  540. pEepData->modalHeader.antennaGainCh[1]);
  541. twiceLargestAntenna = (int16_t)min((AntennaReduction) -
  542. twiceLargestAntenna, 0);
  543. /*
  544. * scaledPower is the minimum of the user input power level
  545. * and the regulatory allowed power level.
  546. */
  547. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  548. if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX)
  549. maxRegAllowedPower -=
  550. (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
  551. scaledPower = min(powerLimit, maxRegAllowedPower);
  552. /*
  553. * Reduce scaled Power by number of chains active
  554. * to get the per chain tx power level.
  555. */
  556. switch (ar5416_get_ntxchains(tx_chainmask)) {
  557. case 1:
  558. break;
  559. case 2:
  560. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  561. break;
  562. case 3:
  563. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  564. break;
  565. }
  566. scaledPower = max((u16)0, scaledPower);
  567. /*
  568. * Get TX power from EEPROM.
  569. */
  570. if (IS_CHAN_2GHZ(chan)) {
  571. /* CTL_11B, CTL_11G, CTL_2GHT20 */
  572. numCtlModes =
  573. ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
  574. pCtlMode = ctlModesFor11g;
  575. ath9k_hw_get_legacy_target_powers(ah, chan,
  576. pEepData->calTargetPowerCck,
  577. AR9287_NUM_2G_CCK_TARGET_POWERS,
  578. &targetPowerCck, 4, false);
  579. ath9k_hw_get_legacy_target_powers(ah, chan,
  580. pEepData->calTargetPower2G,
  581. AR9287_NUM_2G_20_TARGET_POWERS,
  582. &targetPowerOfdm, 4, false);
  583. ath9k_hw_get_target_powers(ah, chan,
  584. pEepData->calTargetPower2GHT20,
  585. AR9287_NUM_2G_20_TARGET_POWERS,
  586. &targetPowerHt20, 8, false);
  587. if (IS_CHAN_HT40(chan)) {
  588. /* All 2G CTLs */
  589. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  590. ath9k_hw_get_target_powers(ah, chan,
  591. pEepData->calTargetPower2GHT40,
  592. AR9287_NUM_2G_40_TARGET_POWERS,
  593. &targetPowerHt40, 8, true);
  594. ath9k_hw_get_legacy_target_powers(ah, chan,
  595. pEepData->calTargetPowerCck,
  596. AR9287_NUM_2G_CCK_TARGET_POWERS,
  597. &targetPowerCckExt, 4, true);
  598. ath9k_hw_get_legacy_target_powers(ah, chan,
  599. pEepData->calTargetPower2G,
  600. AR9287_NUM_2G_20_TARGET_POWERS,
  601. &targetPowerOfdmExt, 4, true);
  602. }
  603. }
  604. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  605. bool isHt40CtlMode =
  606. (pCtlMode[ctlMode] == CTL_2GHT40) ? true : false;
  607. if (isHt40CtlMode)
  608. freq = centers.synth_center;
  609. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  610. freq = centers.ext_center;
  611. else
  612. freq = centers.ctl_center;
  613. /* Walk through the CTL indices stored in EEPROM */
  614. for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  615. struct cal_ctl_edges *pRdEdgesPower;
  616. /*
  617. * Compare test group from regulatory channel list
  618. * with test mode from pCtlMode list
  619. */
  620. if (CMP_CTL || CMP_NO_CTL) {
  621. rep = &(pEepData->ctlData[i]);
  622. pRdEdgesPower =
  623. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1];
  624. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  625. pRdEdgesPower,
  626. IS_CHAN_2GHZ(chan),
  627. AR5416_NUM_BAND_EDGES);
  628. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  629. twiceMaxEdgePower = min(twiceMaxEdgePower,
  630. twiceMinEdgePower);
  631. } else {
  632. twiceMaxEdgePower = twiceMinEdgePower;
  633. break;
  634. }
  635. }
  636. }
  637. minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
  638. /* Apply ctl mode to correct target power set */
  639. switch (pCtlMode[ctlMode]) {
  640. case CTL_11B:
  641. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  642. targetPowerCck.tPow2x[i] =
  643. (u8)min((u16)targetPowerCck.tPow2x[i],
  644. minCtlPower);
  645. }
  646. break;
  647. case CTL_11A:
  648. case CTL_11G:
  649. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  650. targetPowerOfdm.tPow2x[i] =
  651. (u8)min((u16)targetPowerOfdm.tPow2x[i],
  652. minCtlPower);
  653. }
  654. break;
  655. case CTL_5GHT20:
  656. case CTL_2GHT20:
  657. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  658. targetPowerHt20.tPow2x[i] =
  659. (u8)min((u16)targetPowerHt20.tPow2x[i],
  660. minCtlPower);
  661. }
  662. break;
  663. case CTL_11B_EXT:
  664. targetPowerCckExt.tPow2x[0] =
  665. (u8)min((u16)targetPowerCckExt.tPow2x[0],
  666. minCtlPower);
  667. break;
  668. case CTL_11A_EXT:
  669. case CTL_11G_EXT:
  670. targetPowerOfdmExt.tPow2x[0] =
  671. (u8)min((u16)targetPowerOfdmExt.tPow2x[0],
  672. minCtlPower);
  673. break;
  674. case CTL_5GHT40:
  675. case CTL_2GHT40:
  676. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  677. targetPowerHt40.tPow2x[i] =
  678. (u8)min((u16)targetPowerHt40.tPow2x[i],
  679. minCtlPower);
  680. }
  681. break;
  682. default:
  683. break;
  684. }
  685. }
  686. /* Now set the rates array */
  687. ratesArray[rate6mb] =
  688. ratesArray[rate9mb] =
  689. ratesArray[rate12mb] =
  690. ratesArray[rate18mb] =
  691. ratesArray[rate24mb] = targetPowerOfdm.tPow2x[0];
  692. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  693. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  694. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  695. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  696. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  697. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  698. if (IS_CHAN_2GHZ(chan)) {
  699. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  700. ratesArray[rate2s] =
  701. ratesArray[rate2l] = targetPowerCck.tPow2x[1];
  702. ratesArray[rate5_5s] =
  703. ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
  704. ratesArray[rate11s] =
  705. ratesArray[rate11l] = targetPowerCck.tPow2x[3];
  706. }
  707. if (IS_CHAN_HT40(chan)) {
  708. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++)
  709. ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i];
  710. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  711. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  712. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  713. if (IS_CHAN_2GHZ(chan))
  714. ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
  715. }
  716. #undef CMP_CTL
  717. #undef CMP_NO_CTL
  718. #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
  719. #undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
  720. }
  721. static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
  722. struct ath9k_channel *chan, u16 cfgCtl,
  723. u8 twiceAntennaReduction,
  724. u8 twiceMaxRegulatoryPower,
  725. u8 powerLimit, bool test)
  726. {
  727. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  728. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  729. struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader;
  730. int16_t ratesArray[Ar5416RateSize];
  731. int16_t txPowerIndexOffset = 0;
  732. u8 ht40PowerIncForPdadc = 2;
  733. int i;
  734. memset(ratesArray, 0, sizeof(ratesArray));
  735. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  736. AR9287_EEP_MINOR_VER_2)
  737. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  738. ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
  739. &ratesArray[0], cfgCtl,
  740. twiceAntennaReduction,
  741. twiceMaxRegulatoryPower,
  742. powerLimit);
  743. ath9k_hw_set_ar9287_power_cal_table(ah, chan, &txPowerIndexOffset);
  744. regulatory->max_power_level = 0;
  745. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  746. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  747. if (ratesArray[i] > AR9287_MAX_RATE_POWER)
  748. ratesArray[i] = AR9287_MAX_RATE_POWER;
  749. if (ratesArray[i] > regulatory->max_power_level)
  750. regulatory->max_power_level = ratesArray[i];
  751. }
  752. if (test)
  753. return;
  754. if (IS_CHAN_2GHZ(chan))
  755. i = rate1l;
  756. else
  757. i = rate6mb;
  758. regulatory->max_power_level = ratesArray[i];
  759. if (AR_SREV_9280_20_OR_LATER(ah)) {
  760. for (i = 0; i < Ar5416RateSize; i++)
  761. ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
  762. }
  763. /* OFDM power per rate */
  764. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  765. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  766. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  767. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  768. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  769. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  770. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  771. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  772. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  773. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  774. /* CCK power per rate */
  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. /* HT20 power per rate */
  788. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  789. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  790. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  791. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  792. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  793. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  794. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  795. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  796. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  797. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  798. /* HT40 power per rate */
  799. if (IS_CHAN_HT40(chan)) {
  800. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  801. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  802. ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
  803. | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
  804. | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
  805. | ATH9K_POW_SM(ratesArray[rateHt40_0], 0));
  806. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  807. ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
  808. | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
  809. | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
  810. | ATH9K_POW_SM(ratesArray[rateHt40_4], 0));
  811. } else {
  812. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  813. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  814. ht40PowerIncForPdadc, 24)
  815. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  816. ht40PowerIncForPdadc, 16)
  817. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  818. ht40PowerIncForPdadc, 8)
  819. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  820. ht40PowerIncForPdadc, 0));
  821. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  822. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  823. ht40PowerIncForPdadc, 24)
  824. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  825. ht40PowerIncForPdadc, 16)
  826. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  827. ht40PowerIncForPdadc, 8)
  828. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  829. ht40PowerIncForPdadc, 0));
  830. }
  831. /* Dup/Ext power per rate */
  832. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  833. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  834. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  835. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  836. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  837. }
  838. }
  839. static void ath9k_hw_ar9287_set_addac(struct ath_hw *ah,
  840. struct ath9k_channel *chan)
  841. {
  842. }
  843. static void ath9k_hw_ar9287_set_board_values(struct ath_hw *ah,
  844. struct ath9k_channel *chan)
  845. {
  846. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  847. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  848. u16 antWrites[AR9287_ANT_16S];
  849. u32 regChainOffset, regval;
  850. u8 txRxAttenLocal;
  851. int i, j, offset_num;
  852. pModal = &eep->modalHeader;
  853. antWrites[0] = (u16)((pModal->antCtrlCommon >> 28) & 0xF);
  854. antWrites[1] = (u16)((pModal->antCtrlCommon >> 24) & 0xF);
  855. antWrites[2] = (u16)((pModal->antCtrlCommon >> 20) & 0xF);
  856. antWrites[3] = (u16)((pModal->antCtrlCommon >> 16) & 0xF);
  857. antWrites[4] = (u16)((pModal->antCtrlCommon >> 12) & 0xF);
  858. antWrites[5] = (u16)((pModal->antCtrlCommon >> 8) & 0xF);
  859. antWrites[6] = (u16)((pModal->antCtrlCommon >> 4) & 0xF);
  860. antWrites[7] = (u16)(pModal->antCtrlCommon & 0xF);
  861. offset_num = 8;
  862. for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) {
  863. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 28) & 0xf);
  864. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 10) & 0x3);
  865. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 8) & 0x3);
  866. antWrites[j++] = 0;
  867. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 6) & 0x3);
  868. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 4) & 0x3);
  869. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 2) & 0x3);
  870. antWrites[j++] = (u16)(pModal->antCtrlChain[i] & 0x3);
  871. }
  872. REG_WRITE(ah, AR_PHY_SWITCH_COM,
  873. ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
  874. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  875. regChainOffset = i * 0x1000;
  876. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  877. pModal->antCtrlChain[i]);
  878. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  879. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
  880. & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  881. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  882. SM(pModal->iqCalICh[i],
  883. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  884. SM(pModal->iqCalQCh[i],
  885. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  886. txRxAttenLocal = pModal->txRxAttenCh[i];
  887. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  888. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  889. pModal->bswMargin[i]);
  890. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  891. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  892. pModal->bswAtten[i]);
  893. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  894. AR9280_PHY_RXGAIN_TXRX_ATTEN,
  895. txRxAttenLocal);
  896. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  897. AR9280_PHY_RXGAIN_TXRX_MARGIN,
  898. pModal->rxTxMarginCh[i]);
  899. }
  900. if (IS_CHAN_HT40(chan))
  901. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  902. AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
  903. else
  904. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  905. AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
  906. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  907. AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
  908. REG_WRITE(ah, AR_PHY_RF_CTL4,
  909. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  910. | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  911. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  912. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  913. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
  914. AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
  915. REG_RMW_FIELD(ah, AR_PHY_CCA,
  916. AR9280_PHY_CCA_THRESH62, pModal->thresh62);
  917. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  918. AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
  919. regval = REG_READ(ah, AR9287_AN_RF2G3_CH0);
  920. regval &= ~(AR9287_AN_RF2G3_DB1 |
  921. AR9287_AN_RF2G3_DB2 |
  922. AR9287_AN_RF2G3_OB_CCK |
  923. AR9287_AN_RF2G3_OB_PSK |
  924. AR9287_AN_RF2G3_OB_QAM |
  925. AR9287_AN_RF2G3_OB_PAL_OFF);
  926. regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
  927. SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
  928. SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
  929. SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
  930. SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
  931. SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
  932. ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH0, regval);
  933. regval = REG_READ(ah, AR9287_AN_RF2G3_CH1);
  934. regval &= ~(AR9287_AN_RF2G3_DB1 |
  935. AR9287_AN_RF2G3_DB2 |
  936. AR9287_AN_RF2G3_OB_CCK |
  937. AR9287_AN_RF2G3_OB_PSK |
  938. AR9287_AN_RF2G3_OB_QAM |
  939. AR9287_AN_RF2G3_OB_PAL_OFF);
  940. regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
  941. SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
  942. SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
  943. SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
  944. SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
  945. SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
  946. ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH1, regval);
  947. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  948. AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
  949. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  950. AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
  951. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
  952. AR9287_AN_TOP2_XPABIAS_LVL,
  953. AR9287_AN_TOP2_XPABIAS_LVL_S,
  954. pModal->xpaBiasLvl);
  955. }
  956. static u8 ath9k_hw_ar9287_get_num_ant_config(struct ath_hw *ah,
  957. enum ath9k_hal_freq_band freq_band)
  958. {
  959. return 1;
  960. }
  961. static u32 ath9k_hw_ar9287_get_eeprom_antenna_cfg(struct ath_hw *ah,
  962. struct ath9k_channel *chan)
  963. {
  964. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  965. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  966. return pModal->antCtrlCommon;
  967. }
  968. static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
  969. u16 i, bool is2GHz)
  970. {
  971. #define EEP_MAP9287_SPURCHAN \
  972. (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan)
  973. struct ath_common *common = ath9k_hw_common(ah);
  974. u16 spur_val = AR_NO_SPUR;
  975. ath_dbg(common, ATH_DBG_ANI,
  976. "Getting spur idx:%d is2Ghz:%d val:%x\n",
  977. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  978. switch (ah->config.spurmode) {
  979. case SPUR_DISABLE:
  980. break;
  981. case SPUR_ENABLE_IOCTL:
  982. spur_val = ah->config.spurchans[i][is2GHz];
  983. ath_dbg(common, ATH_DBG_ANI,
  984. "Getting spur val from new loc. %d\n", spur_val);
  985. break;
  986. case SPUR_ENABLE_EEPROM:
  987. spur_val = EEP_MAP9287_SPURCHAN;
  988. break;
  989. }
  990. return spur_val;
  991. #undef EEP_MAP9287_SPURCHAN
  992. }
  993. const struct eeprom_ops eep_ar9287_ops = {
  994. .check_eeprom = ath9k_hw_ar9287_check_eeprom,
  995. .get_eeprom = ath9k_hw_ar9287_get_eeprom,
  996. .fill_eeprom = ath9k_hw_ar9287_fill_eeprom,
  997. .get_eeprom_ver = ath9k_hw_ar9287_get_eeprom_ver,
  998. .get_eeprom_rev = ath9k_hw_ar9287_get_eeprom_rev,
  999. .get_num_ant_config = ath9k_hw_ar9287_get_num_ant_config,
  1000. .get_eeprom_antenna_cfg = ath9k_hw_ar9287_get_eeprom_antenna_cfg,
  1001. .set_board_values = ath9k_hw_ar9287_set_board_values,
  1002. .set_addac = ath9k_hw_ar9287_set_addac,
  1003. .set_txpower = ath9k_hw_ar9287_set_txpower,
  1004. .get_spur_channel = ath9k_hw_ar9287_get_spur_channel
  1005. };