eeprom_9287.c 34 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. #define NUM_EEP_WORDS (sizeof(struct ar9287_eeprom) / sizeof(u16))
  19. static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah)
  20. {
  21. return (ah->eeprom.map9287.baseEepHeader.version >> 12) & 0xF;
  22. }
  23. static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah)
  24. {
  25. return (ah->eeprom.map9287.baseEepHeader.version) & 0xFFF;
  26. }
  27. static bool ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah)
  28. {
  29. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  30. struct ath_common *common = ath9k_hw_common(ah);
  31. u16 *eep_data;
  32. int addr, eep_start_loc = AR9287_EEP_START_LOC;
  33. eep_data = (u16 *)eep;
  34. if (!ath9k_hw_use_flash(ah)) {
  35. ath_print(common, ATH_DBG_EEPROM,
  36. "Reading from EEPROM, not flash\n");
  37. }
  38. for (addr = 0; addr < NUM_EEP_WORDS; addr++) {
  39. if (!ath9k_hw_nvram_read(common, addr + eep_start_loc,
  40. eep_data)) {
  41. ath_print(common, ATH_DBG_EEPROM,
  42. "Unable to read eeprom region\n");
  43. return false;
  44. }
  45. eep_data++;
  46. }
  47. return true;
  48. }
  49. static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah)
  50. {
  51. u32 sum = 0, el, integer;
  52. u16 temp, word, magic, magic2, *eepdata;
  53. int i, addr;
  54. bool need_swap = false;
  55. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  56. struct ath_common *common = ath9k_hw_common(ah);
  57. if (!ath9k_hw_use_flash(ah)) {
  58. if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET,
  59. &magic)) {
  60. ath_print(common, ATH_DBG_FATAL,
  61. "Reading Magic # failed\n");
  62. return false;
  63. }
  64. ath_print(common, ATH_DBG_EEPROM,
  65. "Read Magic = 0x%04X\n", magic);
  66. if (magic != AR5416_EEPROM_MAGIC) {
  67. magic2 = swab16(magic);
  68. if (magic2 == AR5416_EEPROM_MAGIC) {
  69. need_swap = true;
  70. eepdata = (u16 *)(&ah->eeprom);
  71. for (addr = 0; addr < NUM_EEP_WORDS; addr++) {
  72. temp = swab16(*eepdata);
  73. *eepdata = temp;
  74. eepdata++;
  75. }
  76. } else {
  77. ath_print(common, ATH_DBG_FATAL,
  78. "Invalid EEPROM Magic. "
  79. "Endianness mismatch.\n");
  80. return -EINVAL;
  81. }
  82. }
  83. }
  84. ath_print(common, ATH_DBG_EEPROM, "need_swap = %s.\n",
  85. need_swap ? "True" : "False");
  86. if (need_swap)
  87. el = swab16(ah->eeprom.map9287.baseEepHeader.length);
  88. else
  89. el = ah->eeprom.map9287.baseEepHeader.length;
  90. if (el > sizeof(struct ar9287_eeprom))
  91. el = sizeof(struct ar9287_eeprom) / sizeof(u16);
  92. else
  93. el = el / sizeof(u16);
  94. eepdata = (u16 *)(&ah->eeprom);
  95. for (i = 0; i < el; i++)
  96. sum ^= *eepdata++;
  97. if (need_swap) {
  98. word = swab16(eep->baseEepHeader.length);
  99. eep->baseEepHeader.length = word;
  100. word = swab16(eep->baseEepHeader.checksum);
  101. eep->baseEepHeader.checksum = word;
  102. word = swab16(eep->baseEepHeader.version);
  103. eep->baseEepHeader.version = word;
  104. word = swab16(eep->baseEepHeader.regDmn[0]);
  105. eep->baseEepHeader.regDmn[0] = word;
  106. word = swab16(eep->baseEepHeader.regDmn[1]);
  107. eep->baseEepHeader.regDmn[1] = word;
  108. word = swab16(eep->baseEepHeader.rfSilent);
  109. eep->baseEepHeader.rfSilent = word;
  110. word = swab16(eep->baseEepHeader.blueToothOptions);
  111. eep->baseEepHeader.blueToothOptions = word;
  112. word = swab16(eep->baseEepHeader.deviceCap);
  113. eep->baseEepHeader.deviceCap = word;
  114. integer = swab32(eep->modalHeader.antCtrlCommon);
  115. eep->modalHeader.antCtrlCommon = integer;
  116. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  117. integer = swab32(eep->modalHeader.antCtrlChain[i]);
  118. eep->modalHeader.antCtrlChain[i] = integer;
  119. }
  120. for (i = 0; i < AR9287_EEPROM_MODAL_SPURS; i++) {
  121. word = swab16(eep->modalHeader.spurChans[i].spurChan);
  122. eep->modalHeader.spurChans[i].spurChan = word;
  123. }
  124. }
  125. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR9287_EEP_VER
  126. || ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  127. ath_print(common, ATH_DBG_FATAL,
  128. "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  129. sum, ah->eep_ops->get_eeprom_ver(ah));
  130. return -EINVAL;
  131. }
  132. return 0;
  133. }
  134. static u32 ath9k_hw_ar9287_get_eeprom(struct ath_hw *ah,
  135. enum eeprom_param param)
  136. {
  137. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  138. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  139. struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
  140. u16 ver_minor;
  141. ver_minor = pBase->version & AR9287_EEP_VER_MINOR_MASK;
  142. switch (param) {
  143. case EEP_NFTHRESH_2:
  144. return pModal->noiseFloorThreshCh[0];
  145. case EEP_MAC_LSW:
  146. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  147. case EEP_MAC_MID:
  148. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  149. case EEP_MAC_MSW:
  150. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  151. case EEP_REG_0:
  152. return pBase->regDmn[0];
  153. case EEP_REG_1:
  154. return pBase->regDmn[1];
  155. case EEP_OP_CAP:
  156. return pBase->deviceCap;
  157. case EEP_OP_MODE:
  158. return pBase->opCapFlags;
  159. case EEP_RF_SILENT:
  160. return pBase->rfSilent;
  161. case EEP_MINOR_REV:
  162. return ver_minor;
  163. case EEP_TX_MASK:
  164. return pBase->txMask;
  165. case EEP_RX_MASK:
  166. return pBase->rxMask;
  167. case EEP_DEV_TYPE:
  168. return pBase->deviceType;
  169. case EEP_OL_PWRCTRL:
  170. return pBase->openLoopPwrCntl;
  171. case EEP_TEMPSENSE_SLOPE:
  172. if (ver_minor >= AR9287_EEP_MINOR_VER_2)
  173. return pBase->tempSensSlope;
  174. else
  175. return 0;
  176. case EEP_TEMPSENSE_SLOPE_PAL_ON:
  177. if (ver_minor >= AR9287_EEP_MINOR_VER_3)
  178. return pBase->tempSensSlopePalOn;
  179. else
  180. return 0;
  181. default:
  182. return 0;
  183. }
  184. }
  185. static void ath9k_hw_get_ar9287_gain_boundaries_pdadcs(struct ath_hw *ah,
  186. struct ath9k_channel *chan,
  187. struct cal_data_per_freq_ar9287 *pRawDataSet,
  188. u8 *bChans, u16 availPiers,
  189. u16 tPdGainOverlap,
  190. int16_t *pMinCalPower,
  191. u16 *pPdGainBoundaries,
  192. u8 *pPDADCValues,
  193. u16 numXpdGains)
  194. {
  195. #define TMP_VAL_VPD_TABLE \
  196. ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep));
  197. int i, j, k;
  198. int16_t ss;
  199. u16 idxL = 0, idxR = 0, numPiers;
  200. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  201. u8 minPwrT4[AR9287_NUM_PD_GAINS];
  202. u8 maxPwrT4[AR9287_NUM_PD_GAINS];
  203. int16_t vpdStep;
  204. int16_t tmpVal;
  205. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  206. bool match;
  207. int16_t minDelta = 0;
  208. struct chan_centers centers;
  209. static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS]
  210. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  211. static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS]
  212. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  213. static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS]
  214. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  215. 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. *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
  261. k = 0;
  262. for (i = 0; i < numXpdGains; i++) {
  263. if (i == (numXpdGains - 1))
  264. pPdGainBoundaries[i] =
  265. (u16)(maxPwrT4[i] / 2);
  266. else
  267. pPdGainBoundaries[i] =
  268. (u16)((maxPwrT4[i] + minPwrT4[i+1]) / 4);
  269. pPdGainBoundaries[i] = min((u16)AR5416_MAX_RATE_POWER,
  270. pPdGainBoundaries[i]);
  271. minDelta = 0;
  272. if (i == 0) {
  273. if (AR_SREV_9280_10_OR_LATER(ah))
  274. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  275. else
  276. ss = 0;
  277. } else {
  278. ss = (int16_t)((pPdGainBoundaries[i-1] -
  279. (minPwrT4[i] / 2)) -
  280. tPdGainOverlap + 1 + minDelta);
  281. }
  282. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  283. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  284. while ((ss < 0) && (k < (AR9287_NUM_PDADC_VALUES - 1))) {
  285. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  286. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  287. ss++;
  288. }
  289. sizeCurrVpdTable = (u8)((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  290. tgtIndex = (u8)(pPdGainBoundaries[i] +
  291. tPdGainOverlap - (minPwrT4[i] / 2));
  292. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  293. tgtIndex : sizeCurrVpdTable;
  294. while ((ss < maxIndex) && (k < (AR9287_NUM_PDADC_VALUES - 1)))
  295. pPDADCValues[k++] = vpdTableI[i][ss++];
  296. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  297. vpdTableI[i][sizeCurrVpdTable - 2]);
  298. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  299. if (tgtIndex > maxIndex) {
  300. while ((ss <= tgtIndex) &&
  301. (k < (AR9287_NUM_PDADC_VALUES - 1))) {
  302. tmpVal = (int16_t) TMP_VAL_VPD_TABLE;
  303. pPDADCValues[k++] =
  304. (u8)((tmpVal > 255) ? 255 : tmpVal);
  305. ss++;
  306. }
  307. }
  308. }
  309. while (i < AR9287_PD_GAINS_IN_MASK) {
  310. pPdGainBoundaries[i] = pPdGainBoundaries[i-1];
  311. i++;
  312. }
  313. while (k < AR9287_NUM_PDADC_VALUES) {
  314. pPDADCValues[k] = pPDADCValues[k-1];
  315. k++;
  316. }
  317. #undef TMP_VAL_VPD_TABLE
  318. }
  319. static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah,
  320. struct ath9k_channel *chan,
  321. struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop,
  322. u8 *pCalChans, u16 availPiers, int8_t *pPwr)
  323. {
  324. u16 idxL = 0, idxR = 0, numPiers;
  325. bool match;
  326. struct chan_centers centers;
  327. ath9k_hw_get_channel_centers(ah, chan, &centers);
  328. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  329. if (pCalChans[numPiers] == AR9287_BCHAN_UNUSED)
  330. break;
  331. }
  332. match = ath9k_hw_get_lower_upper_index(
  333. (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
  334. pCalChans, numPiers, &idxL, &idxR);
  335. if (match) {
  336. *pPwr = (int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0];
  337. } else {
  338. *pPwr = ((int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0] +
  339. (int8_t) pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
  340. }
  341. }
  342. static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah,
  343. int32_t txPower, u16 chain)
  344. {
  345. u32 tmpVal;
  346. u32 a;
  347. /* Enable OLPC for chain 0 */
  348. tmpVal = REG_READ(ah, 0xa270);
  349. tmpVal = tmpVal & 0xFCFFFFFF;
  350. tmpVal = tmpVal | (0x3 << 24);
  351. REG_WRITE(ah, 0xa270, tmpVal);
  352. /* Enable OLPC for chain 1 */
  353. tmpVal = REG_READ(ah, 0xb270);
  354. tmpVal = tmpVal & 0xFCFFFFFF;
  355. tmpVal = tmpVal | (0x3 << 24);
  356. REG_WRITE(ah, 0xb270, tmpVal);
  357. /* Write the OLPC ref power for chain 0 */
  358. if (chain == 0) {
  359. tmpVal = REG_READ(ah, 0xa398);
  360. tmpVal = tmpVal & 0xff00ffff;
  361. a = (txPower)&0xff;
  362. tmpVal = tmpVal | (a << 16);
  363. REG_WRITE(ah, 0xa398, tmpVal);
  364. }
  365. /* Write the OLPC ref power for chain 1 */
  366. if (chain == 1) {
  367. tmpVal = REG_READ(ah, 0xb398);
  368. tmpVal = tmpVal & 0xff00ffff;
  369. a = (txPower)&0xff;
  370. tmpVal = tmpVal | (a << 16);
  371. REG_WRITE(ah, 0xb398, tmpVal);
  372. }
  373. }
  374. static void ath9k_hw_set_ar9287_power_cal_table(struct ath_hw *ah,
  375. struct ath9k_channel *chan,
  376. int16_t *pTxPowerIndexOffset)
  377. {
  378. struct cal_data_per_freq_ar9287 *pRawDataset;
  379. struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
  380. u8 *pCalBChans = NULL;
  381. u16 pdGainOverlap_t2;
  382. u8 pdadcValues[AR9287_NUM_PDADC_VALUES];
  383. u16 gainBoundaries[AR9287_PD_GAINS_IN_MASK];
  384. u16 numPiers = 0, i, j;
  385. int16_t tMinCalPower;
  386. u16 numXpdGain, xpdMask;
  387. u16 xpdGainValues[AR9287_NUM_PD_GAINS] = {0, 0, 0, 0};
  388. u32 reg32, regOffset, regChainOffset, regval;
  389. int16_t modalIdx, diff = 0;
  390. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  391. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  392. xpdMask = pEepData->modalHeader.xpdGain;
  393. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  394. AR9287_EEP_MINOR_VER_2)
  395. pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
  396. else
  397. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  398. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  399. if (IS_CHAN_2GHZ(chan)) {
  400. pCalBChans = pEepData->calFreqPier2G;
  401. numPiers = AR9287_NUM_2G_CAL_PIERS;
  402. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  403. pRawDatasetOpenLoop =
  404. (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];
  405. ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
  406. }
  407. }
  408. numXpdGain = 0;
  409. /* Calculate the value of xpdgains from the xpdGain Mask */
  410. for (i = 1; i <= AR9287_PD_GAINS_IN_MASK; i++) {
  411. if ((xpdMask >> (AR9287_PD_GAINS_IN_MASK - i)) & 1) {
  412. if (numXpdGain >= AR9287_NUM_PD_GAINS)
  413. break;
  414. xpdGainValues[numXpdGain] =
  415. (u16)(AR9287_PD_GAINS_IN_MASK-i);
  416. numXpdGain++;
  417. }
  418. }
  419. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  420. (numXpdGain - 1) & 0x3);
  421. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  422. xpdGainValues[0]);
  423. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  424. xpdGainValues[1]);
  425. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  426. xpdGainValues[2]);
  427. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  428. regChainOffset = i * 0x1000;
  429. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  430. pRawDatasetOpenLoop =
  431. (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];
  432. if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  433. int8_t txPower;
  434. ar9287_eeprom_get_tx_gain_index(ah, chan,
  435. pRawDatasetOpenLoop,
  436. pCalBChans, numPiers,
  437. &txPower);
  438. ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i);
  439. } else {
  440. pRawDataset =
  441. (struct cal_data_per_freq_ar9287 *)
  442. pEepData->calPierData2G[i];
  443. ath9k_hw_get_ar9287_gain_boundaries_pdadcs(ah, chan,
  444. pRawDataset,
  445. pCalBChans, numPiers,
  446. pdGainOverlap_t2,
  447. &tMinCalPower,
  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_10_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_10_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 ieee80211_band freq_band)
  960. {
  961. return 1;
  962. }
  963. static u16 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 & 0xFFFF;
  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. };