eeprom_9287.c 35 KB

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