eeprom.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  1. /*
  2. * Copyright (c) 2008 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 "core.h"
  17. #include "hw.h"
  18. #include "reg.h"
  19. #include "phy.h"
  20. static void ath9k_hw_analog_shift_rmw(struct ath_hal *ah,
  21. u32 reg, u32 mask,
  22. u32 shift, u32 val)
  23. {
  24. u32 regVal;
  25. regVal = REG_READ(ah, reg) & ~mask;
  26. regVal |= (val << shift) & mask;
  27. REG_WRITE(ah, reg, regVal);
  28. if (ah->ah_config.analog_shiftreg)
  29. udelay(100);
  30. return;
  31. }
  32. static inline u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz)
  33. {
  34. if (fbin == AR5416_BCHAN_UNUSED)
  35. return fbin;
  36. return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
  37. }
  38. static inline int16_t ath9k_hw_interpolate(u16 target,
  39. u16 srcLeft, u16 srcRight,
  40. int16_t targetLeft,
  41. int16_t targetRight)
  42. {
  43. int16_t rv;
  44. if (srcRight == srcLeft) {
  45. rv = targetLeft;
  46. } else {
  47. rv = (int16_t) (((target - srcLeft) * targetRight +
  48. (srcRight - target) * targetLeft) /
  49. (srcRight - srcLeft));
  50. }
  51. return rv;
  52. }
  53. static inline bool ath9k_hw_get_lower_upper_index(u8 target, u8 *pList,
  54. u16 listSize, u16 *indexL,
  55. u16 *indexR)
  56. {
  57. u16 i;
  58. if (target <= pList[0]) {
  59. *indexL = *indexR = 0;
  60. return true;
  61. }
  62. if (target >= pList[listSize - 1]) {
  63. *indexL = *indexR = (u16) (listSize - 1);
  64. return true;
  65. }
  66. for (i = 0; i < listSize - 1; i++) {
  67. if (pList[i] == target) {
  68. *indexL = *indexR = i;
  69. return true;
  70. }
  71. if (target < pList[i + 1]) {
  72. *indexL = i;
  73. *indexR = (u16) (i + 1);
  74. return false;
  75. }
  76. }
  77. return false;
  78. }
  79. static bool ath9k_hw_eeprom_read(struct ath_hal *ah, u32 off, u16 *data)
  80. {
  81. (void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
  82. if (!ath9k_hw_wait(ah,
  83. AR_EEPROM_STATUS_DATA,
  84. AR_EEPROM_STATUS_DATA_BUSY |
  85. AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0)) {
  86. return false;
  87. }
  88. *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
  89. AR_EEPROM_STATUS_DATA_VAL);
  90. return true;
  91. }
  92. static int ath9k_hw_flash_map(struct ath_hal *ah)
  93. {
  94. struct ath_hal_5416 *ahp = AH5416(ah);
  95. ahp->ah_cal_mem = ioremap(AR5416_EEPROM_START_ADDR, AR5416_EEPROM_MAX);
  96. if (!ahp->ah_cal_mem) {
  97. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  98. "cannot remap eeprom region \n");
  99. return -EIO;
  100. }
  101. return 0;
  102. }
  103. static bool ath9k_hw_flash_read(struct ath_hal *ah, u32 off, u16 *data)
  104. {
  105. struct ath_hal_5416 *ahp = AH5416(ah);
  106. *data = ioread16(ahp->ah_cal_mem + off);
  107. return true;
  108. }
  109. static inline bool ath9k_hw_nvram_read(struct ath_hal *ah, u32 off, u16 *data)
  110. {
  111. if (ath9k_hw_use_flash(ah))
  112. return ath9k_hw_flash_read(ah, off, data);
  113. else
  114. return ath9k_hw_eeprom_read(ah, off, data);
  115. }
  116. static bool ath9k_hw_fill_eeprom(struct ath_hal *ah)
  117. {
  118. struct ath_hal_5416 *ahp = AH5416(ah);
  119. struct ar5416_eeprom *eep = &ahp->ah_eeprom;
  120. u16 *eep_data;
  121. int addr, ar5416_eep_start_loc = 0;
  122. if (!ath9k_hw_use_flash(ah)) {
  123. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  124. "Reading from EEPROM, not flash\n");
  125. ar5416_eep_start_loc = 256;
  126. }
  127. if (AR_SREV_9100(ah))
  128. ar5416_eep_start_loc = 256;
  129. eep_data = (u16 *)eep;
  130. for (addr = 0; addr < sizeof(struct ar5416_eeprom) / sizeof(u16); addr++) {
  131. if (!ath9k_hw_nvram_read(ah, addr + ar5416_eep_start_loc,
  132. eep_data)) {
  133. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  134. "Unable to read eeprom region \n");
  135. return false;
  136. }
  137. eep_data++;
  138. }
  139. return true;
  140. }
  141. static int ath9k_hw_check_eeprom(struct ath_hal *ah)
  142. {
  143. struct ath_hal_5416 *ahp = AH5416(ah);
  144. struct ar5416_eeprom *eep =
  145. (struct ar5416_eeprom *) &ahp->ah_eeprom;
  146. u16 *eepdata, temp, magic, magic2;
  147. u32 sum = 0, el;
  148. bool need_swap = false;
  149. int i, addr, size;
  150. if (!ath9k_hw_use_flash(ah)) {
  151. if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET,
  152. &magic)) {
  153. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  154. "Reading Magic # failed\n");
  155. return false;
  156. }
  157. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "Read Magic = 0x%04X\n", magic);
  158. if (magic != AR5416_EEPROM_MAGIC) {
  159. magic2 = swab16(magic);
  160. if (magic2 == AR5416_EEPROM_MAGIC) {
  161. size = sizeof(struct ar5416_eeprom);
  162. need_swap = true;
  163. eepdata = (u16 *) (&ahp->ah_eeprom);
  164. for (addr = 0; addr < size / sizeof(u16); addr++) {
  165. temp = swab16(*eepdata);
  166. *eepdata = temp;
  167. eepdata++;
  168. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  169. "0x%04X ", *eepdata);
  170. if (((addr + 1) % 6) == 0)
  171. DPRINTF(ah->ah_sc,
  172. ATH_DBG_EEPROM, "\n");
  173. }
  174. } else {
  175. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  176. "Invalid EEPROM Magic. "
  177. "endianness mismatch.\n");
  178. return -EINVAL;
  179. }
  180. }
  181. }
  182. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
  183. need_swap ? "True" : "False");
  184. if (need_swap)
  185. el = swab16(ahp->ah_eeprom.baseEepHeader.length);
  186. else
  187. el = ahp->ah_eeprom.baseEepHeader.length;
  188. if (el > sizeof(struct ar5416_eeprom))
  189. el = sizeof(struct ar5416_eeprom) / sizeof(u16);
  190. else
  191. el = el / sizeof(u16);
  192. eepdata = (u16 *)(&ahp->ah_eeprom);
  193. for (i = 0; i < el; i++)
  194. sum ^= *eepdata++;
  195. if (need_swap) {
  196. u32 integer, j;
  197. u16 word;
  198. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  199. "EEPROM Endianness is not native.. Changing \n");
  200. word = swab16(eep->baseEepHeader.length);
  201. eep->baseEepHeader.length = word;
  202. word = swab16(eep->baseEepHeader.checksum);
  203. eep->baseEepHeader.checksum = word;
  204. word = swab16(eep->baseEepHeader.version);
  205. eep->baseEepHeader.version = word;
  206. word = swab16(eep->baseEepHeader.regDmn[0]);
  207. eep->baseEepHeader.regDmn[0] = word;
  208. word = swab16(eep->baseEepHeader.regDmn[1]);
  209. eep->baseEepHeader.regDmn[1] = word;
  210. word = swab16(eep->baseEepHeader.rfSilent);
  211. eep->baseEepHeader.rfSilent = word;
  212. word = swab16(eep->baseEepHeader.blueToothOptions);
  213. eep->baseEepHeader.blueToothOptions = word;
  214. word = swab16(eep->baseEepHeader.deviceCap);
  215. eep->baseEepHeader.deviceCap = word;
  216. for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
  217. struct modal_eep_header *pModal =
  218. &eep->modalHeader[j];
  219. integer = swab32(pModal->antCtrlCommon);
  220. pModal->antCtrlCommon = integer;
  221. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  222. integer = swab32(pModal->antCtrlChain[i]);
  223. pModal->antCtrlChain[i] = integer;
  224. }
  225. for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
  226. word = swab16(pModal->spurChans[i].spurChan);
  227. pModal->spurChans[i].spurChan = word;
  228. }
  229. }
  230. }
  231. if (sum != 0xffff || ar5416_get_eep_ver(ahp) != AR5416_EEP_VER ||
  232. ar5416_get_eep_rev(ahp) < AR5416_EEP_NO_BACK_VER) {
  233. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  234. "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  235. sum, ar5416_get_eep_ver(ahp));
  236. return -EINVAL;
  237. }
  238. return 0;
  239. }
  240. static inline bool ath9k_hw_fill_vpd_table(u8 pwrMin, u8 pwrMax, u8 *pPwrList,
  241. u8 *pVpdList, u16 numIntercepts,
  242. u8 *pRetVpdList)
  243. {
  244. u16 i, k;
  245. u8 currPwr = pwrMin;
  246. u16 idxL = 0, idxR = 0;
  247. for (i = 0; i <= (pwrMax - pwrMin) / 2; i++) {
  248. ath9k_hw_get_lower_upper_index(currPwr, pPwrList,
  249. numIntercepts, &(idxL),
  250. &(idxR));
  251. if (idxR < 1)
  252. idxR = 1;
  253. if (idxL == numIntercepts - 1)
  254. idxL = (u16) (numIntercepts - 2);
  255. if (pPwrList[idxL] == pPwrList[idxR])
  256. k = pVpdList[idxL];
  257. else
  258. k = (u16)(((currPwr - pPwrList[idxL]) * pVpdList[idxR] +
  259. (pPwrList[idxR] - currPwr) * pVpdList[idxL]) /
  260. (pPwrList[idxR] - pPwrList[idxL]));
  261. pRetVpdList[i] = (u8) k;
  262. currPwr += 2;
  263. }
  264. return true;
  265. }
  266. static void ath9k_hw_get_gain_boundaries_pdadcs(struct ath_hal *ah,
  267. struct ath9k_channel *chan,
  268. struct cal_data_per_freq *pRawDataSet,
  269. u8 *bChans, u16 availPiers,
  270. u16 tPdGainOverlap, int16_t *pMinCalPower,
  271. u16 *pPdGainBoundaries, u8 *pPDADCValues,
  272. u16 numXpdGains)
  273. {
  274. int i, j, k;
  275. int16_t ss;
  276. u16 idxL = 0, idxR = 0, numPiers;
  277. static u8 vpdTableL[AR5416_NUM_PD_GAINS]
  278. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  279. static u8 vpdTableR[AR5416_NUM_PD_GAINS]
  280. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  281. static u8 vpdTableI[AR5416_NUM_PD_GAINS]
  282. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  283. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  284. u8 minPwrT4[AR5416_NUM_PD_GAINS];
  285. u8 maxPwrT4[AR5416_NUM_PD_GAINS];
  286. int16_t vpdStep;
  287. int16_t tmpVal;
  288. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  289. bool match;
  290. int16_t minDelta = 0;
  291. struct chan_centers centers;
  292. ath9k_hw_get_channel_centers(ah, chan, &centers);
  293. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  294. if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
  295. break;
  296. }
  297. match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center,
  298. IS_CHAN_2GHZ(chan)),
  299. bChans, numPiers, &idxL, &idxR);
  300. if (match) {
  301. for (i = 0; i < numXpdGains; i++) {
  302. minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
  303. maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
  304. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  305. pRawDataSet[idxL].pwrPdg[i],
  306. pRawDataSet[idxL].vpdPdg[i],
  307. AR5416_PD_GAIN_ICEPTS,
  308. vpdTableI[i]);
  309. }
  310. } else {
  311. for (i = 0; i < numXpdGains; i++) {
  312. pVpdL = pRawDataSet[idxL].vpdPdg[i];
  313. pPwrL = pRawDataSet[idxL].pwrPdg[i];
  314. pVpdR = pRawDataSet[idxR].vpdPdg[i];
  315. pPwrR = pRawDataSet[idxR].pwrPdg[i];
  316. minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
  317. maxPwrT4[i] =
  318. min(pPwrL[AR5416_PD_GAIN_ICEPTS - 1],
  319. pPwrR[AR5416_PD_GAIN_ICEPTS - 1]);
  320. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  321. pPwrL, pVpdL,
  322. AR5416_PD_GAIN_ICEPTS,
  323. vpdTableL[i]);
  324. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  325. pPwrR, pVpdR,
  326. AR5416_PD_GAIN_ICEPTS,
  327. vpdTableR[i]);
  328. for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
  329. vpdTableI[i][j] =
  330. (u8)(ath9k_hw_interpolate((u16)
  331. FREQ2FBIN(centers.
  332. synth_center,
  333. IS_CHAN_2GHZ
  334. (chan)),
  335. bChans[idxL], bChans[idxR],
  336. vpdTableL[i][j], vpdTableR[i][j]));
  337. }
  338. }
  339. }
  340. *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
  341. k = 0;
  342. for (i = 0; i < numXpdGains; i++) {
  343. if (i == (numXpdGains - 1))
  344. pPdGainBoundaries[i] =
  345. (u16)(maxPwrT4[i] / 2);
  346. else
  347. pPdGainBoundaries[i] =
  348. (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
  349. pPdGainBoundaries[i] =
  350. min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
  351. if ((i == 0) && !AR_SREV_5416_V20_OR_LATER(ah)) {
  352. minDelta = pPdGainBoundaries[0] - 23;
  353. pPdGainBoundaries[0] = 23;
  354. } else {
  355. minDelta = 0;
  356. }
  357. if (i == 0) {
  358. if (AR_SREV_9280_10_OR_LATER(ah))
  359. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  360. else
  361. ss = 0;
  362. } else {
  363. ss = (int16_t)((pPdGainBoundaries[i - 1] -
  364. (minPwrT4[i] / 2)) -
  365. tPdGainOverlap + 1 + minDelta);
  366. }
  367. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  368. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  369. while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  370. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  371. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  372. ss++;
  373. }
  374. sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  375. tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
  376. (minPwrT4[i] / 2));
  377. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  378. tgtIndex : sizeCurrVpdTable;
  379. while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  380. pPDADCValues[k++] = vpdTableI[i][ss++];
  381. }
  382. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  383. vpdTableI[i][sizeCurrVpdTable - 2]);
  384. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  385. if (tgtIndex > maxIndex) {
  386. while ((ss <= tgtIndex) &&
  387. (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  388. tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] +
  389. (ss - maxIndex + 1) * vpdStep));
  390. pPDADCValues[k++] = (u8)((tmpVal > 255) ?
  391. 255 : tmpVal);
  392. ss++;
  393. }
  394. }
  395. }
  396. while (i < AR5416_PD_GAINS_IN_MASK) {
  397. pPdGainBoundaries[i] = pPdGainBoundaries[i - 1];
  398. i++;
  399. }
  400. while (k < AR5416_NUM_PDADC_VALUES) {
  401. pPDADCValues[k] = pPDADCValues[k - 1];
  402. k++;
  403. }
  404. return;
  405. }
  406. static void ath9k_hw_get_legacy_target_powers(struct ath_hal *ah,
  407. struct ath9k_channel *chan,
  408. struct cal_target_power_leg *powInfo,
  409. u16 numChannels,
  410. struct cal_target_power_leg *pNewPower,
  411. u16 numRates, bool isExtTarget)
  412. {
  413. struct chan_centers centers;
  414. u16 clo, chi;
  415. int i;
  416. int matchIndex = -1, lowIndex = -1;
  417. u16 freq;
  418. ath9k_hw_get_channel_centers(ah, chan, &centers);
  419. freq = (isExtTarget) ? centers.ext_center : centers.ctl_center;
  420. if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel,
  421. IS_CHAN_2GHZ(chan))) {
  422. matchIndex = 0;
  423. } else {
  424. for (i = 0; (i < numChannels) &&
  425. (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  426. if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
  427. IS_CHAN_2GHZ(chan))) {
  428. matchIndex = i;
  429. break;
  430. } else if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
  431. IS_CHAN_2GHZ(chan))) &&
  432. (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
  433. IS_CHAN_2GHZ(chan)))) {
  434. lowIndex = i - 1;
  435. break;
  436. }
  437. }
  438. if ((matchIndex == -1) && (lowIndex == -1))
  439. matchIndex = i - 1;
  440. }
  441. if (matchIndex != -1) {
  442. *pNewPower = powInfo[matchIndex];
  443. } else {
  444. clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
  445. IS_CHAN_2GHZ(chan));
  446. chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
  447. IS_CHAN_2GHZ(chan));
  448. for (i = 0; i < numRates; i++) {
  449. pNewPower->tPow2x[i] =
  450. (u8)ath9k_hw_interpolate(freq, clo, chi,
  451. powInfo[lowIndex].tPow2x[i],
  452. powInfo[lowIndex + 1].tPow2x[i]);
  453. }
  454. }
  455. }
  456. static void ath9k_hw_get_target_powers(struct ath_hal *ah,
  457. struct ath9k_channel *chan,
  458. struct cal_target_power_ht *powInfo,
  459. u16 numChannels,
  460. struct cal_target_power_ht *pNewPower,
  461. u16 numRates, bool isHt40Target)
  462. {
  463. struct chan_centers centers;
  464. u16 clo, chi;
  465. int i;
  466. int matchIndex = -1, lowIndex = -1;
  467. u16 freq;
  468. ath9k_hw_get_channel_centers(ah, chan, &centers);
  469. freq = isHt40Target ? centers.synth_center : centers.ctl_center;
  470. if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) {
  471. matchIndex = 0;
  472. } else {
  473. for (i = 0; (i < numChannels) &&
  474. (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  475. if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
  476. IS_CHAN_2GHZ(chan))) {
  477. matchIndex = i;
  478. break;
  479. } else
  480. if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
  481. IS_CHAN_2GHZ(chan))) &&
  482. (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
  483. IS_CHAN_2GHZ(chan)))) {
  484. lowIndex = i - 1;
  485. break;
  486. }
  487. }
  488. if ((matchIndex == -1) && (lowIndex == -1))
  489. matchIndex = i - 1;
  490. }
  491. if (matchIndex != -1) {
  492. *pNewPower = powInfo[matchIndex];
  493. } else {
  494. clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
  495. IS_CHAN_2GHZ(chan));
  496. chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
  497. IS_CHAN_2GHZ(chan));
  498. for (i = 0; i < numRates; i++) {
  499. pNewPower->tPow2x[i] = (u8)ath9k_hw_interpolate(freq,
  500. clo, chi,
  501. powInfo[lowIndex].tPow2x[i],
  502. powInfo[lowIndex + 1].tPow2x[i]);
  503. }
  504. }
  505. }
  506. static u16 ath9k_hw_get_max_edge_power(u16 freq,
  507. struct cal_ctl_edges *pRdEdgesPower,
  508. bool is2GHz)
  509. {
  510. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  511. int i;
  512. for (i = 0; (i < AR5416_NUM_BAND_EDGES) &&
  513. (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  514. if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) {
  515. twiceMaxEdgePower = pRdEdgesPower[i].tPower;
  516. break;
  517. } else if ((i > 0) &&
  518. (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel,
  519. is2GHz))) {
  520. if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel,
  521. is2GHz) < freq &&
  522. pRdEdgesPower[i - 1].flag) {
  523. twiceMaxEdgePower =
  524. pRdEdgesPower[i - 1].tPower;
  525. }
  526. break;
  527. }
  528. }
  529. return twiceMaxEdgePower;
  530. }
  531. int ath9k_hw_set_txpower(struct ath_hal *ah,
  532. struct ath9k_channel *chan,
  533. u16 cfgCtl,
  534. u8 twiceAntennaReduction,
  535. u8 twiceMaxRegulatoryPower,
  536. u8 powerLimit)
  537. {
  538. struct ath_hal_5416 *ahp = AH5416(ah);
  539. struct ar5416_eeprom *pEepData = &ahp->ah_eeprom;
  540. struct modal_eep_header *pModal =
  541. &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
  542. int16_t ratesArray[Ar5416RateSize];
  543. int16_t txPowerIndexOffset = 0;
  544. u8 ht40PowerIncForPdadc = 2;
  545. int i;
  546. memset(ratesArray, 0, sizeof(ratesArray));
  547. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  548. AR5416_EEP_MINOR_VER_2) {
  549. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  550. }
  551. if (!ath9k_hw_set_power_per_rate_table(ah, chan,
  552. &ratesArray[0], cfgCtl,
  553. twiceAntennaReduction,
  554. twiceMaxRegulatoryPower,
  555. powerLimit)) {
  556. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  557. "ath9k_hw_set_txpower: unable to set "
  558. "tx power per rate table\n");
  559. return -EIO;
  560. }
  561. if (!ath9k_hw_set_power_cal_table(ah, chan, &txPowerIndexOffset)) {
  562. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  563. "ath9k_hw_set_txpower: unable to set power table\n");
  564. return -EIO;
  565. }
  566. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  567. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  568. if (ratesArray[i] > AR5416_MAX_RATE_POWER)
  569. ratesArray[i] = AR5416_MAX_RATE_POWER;
  570. }
  571. if (AR_SREV_9280_10_OR_LATER(ah)) {
  572. for (i = 0; i < Ar5416RateSize; i++)
  573. ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
  574. }
  575. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  576. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  577. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  578. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  579. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  580. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  581. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  582. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  583. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  584. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  585. if (IS_CHAN_2GHZ(chan)) {
  586. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  587. ATH9K_POW_SM(ratesArray[rate2s], 24)
  588. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  589. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  590. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  591. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  592. ATH9K_POW_SM(ratesArray[rate11s], 24)
  593. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  594. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  595. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  596. }
  597. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  598. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  599. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  600. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  601. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  602. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  603. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  604. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  605. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  606. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  607. if (IS_CHAN_HT40(chan)) {
  608. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  609. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  610. ht40PowerIncForPdadc, 24)
  611. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  612. ht40PowerIncForPdadc, 16)
  613. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  614. ht40PowerIncForPdadc, 8)
  615. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  616. ht40PowerIncForPdadc, 0));
  617. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  618. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  619. ht40PowerIncForPdadc, 24)
  620. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  621. ht40PowerIncForPdadc, 16)
  622. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  623. ht40PowerIncForPdadc, 8)
  624. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  625. ht40PowerIncForPdadc, 0));
  626. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  627. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  628. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  629. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  630. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  631. }
  632. REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
  633. ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
  634. | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
  635. i = rate6mb;
  636. if (IS_CHAN_HT40(chan))
  637. i = rateHt40_0;
  638. else if (IS_CHAN_HT20(chan))
  639. i = rateHt20_0;
  640. if (AR_SREV_9280_10_OR_LATER(ah))
  641. ah->ah_maxPowerLevel =
  642. ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
  643. else
  644. ah->ah_maxPowerLevel = ratesArray[i];
  645. return 0;
  646. }
  647. void ath9k_hw_set_addac(struct ath_hal *ah, struct ath9k_channel *chan)
  648. {
  649. struct modal_eep_header *pModal;
  650. struct ath_hal_5416 *ahp = AH5416(ah);
  651. struct ar5416_eeprom *eep = &ahp->ah_eeprom;
  652. u8 biaslevel;
  653. if (ah->ah_macVersion != AR_SREV_VERSION_9160)
  654. return;
  655. if (ar5416_get_eep_rev(ahp) < AR5416_EEP_MINOR_VER_7)
  656. return;
  657. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  658. if (pModal->xpaBiasLvl != 0xff) {
  659. biaslevel = pModal->xpaBiasLvl;
  660. } else {
  661. u16 resetFreqBin, freqBin, freqCount = 0;
  662. struct chan_centers centers;
  663. ath9k_hw_get_channel_centers(ah, chan, &centers);
  664. resetFreqBin = FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan));
  665. freqBin = pModal->xpaBiasLvlFreq[0] & 0xff;
  666. biaslevel = (u8) (pModal->xpaBiasLvlFreq[0] >> 14);
  667. freqCount++;
  668. while (freqCount < 3) {
  669. if (pModal->xpaBiasLvlFreq[freqCount] == 0x0)
  670. break;
  671. freqBin = pModal->xpaBiasLvlFreq[freqCount] & 0xff;
  672. if (resetFreqBin >= freqBin) {
  673. biaslevel = (u8)(pModal->xpaBiasLvlFreq[freqCount] >> 14);
  674. } else {
  675. break;
  676. }
  677. freqCount++;
  678. }
  679. }
  680. if (IS_CHAN_2GHZ(chan)) {
  681. INI_RA(&ahp->ah_iniAddac, 7, 1) =
  682. (INI_RA(&ahp->ah_iniAddac, 7, 1) & (~0x18)) | biaslevel << 3;
  683. } else {
  684. INI_RA(&ahp->ah_iniAddac, 6, 1) =
  685. (INI_RA(&ahp->ah_iniAddac, 6, 1) & (~0xc0)) | biaslevel << 6;
  686. }
  687. }
  688. bool ath9k_hw_set_power_per_rate_table(struct ath_hal *ah,
  689. struct ath9k_channel *chan,
  690. int16_t *ratesArray,
  691. u16 cfgCtl,
  692. u8 AntennaReduction,
  693. u8 twiceMaxRegulatoryPower,
  694. u8 powerLimit)
  695. {
  696. struct ath_hal_5416 *ahp = AH5416(ah);
  697. struct ar5416_eeprom *pEepData = &ahp->ah_eeprom;
  698. u8 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  699. static const u16 tpScaleReductionTable[5] =
  700. { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
  701. int i;
  702. int8_t twiceLargestAntenna;
  703. struct cal_ctl_data *rep;
  704. struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
  705. 0, { 0, 0, 0, 0}
  706. };
  707. struct cal_target_power_leg targetPowerOfdmExt = {
  708. 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
  709. 0, { 0, 0, 0, 0 }
  710. };
  711. struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
  712. 0, {0, 0, 0, 0}
  713. };
  714. u8 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  715. u16 ctlModesFor11a[] =
  716. { CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40 };
  717. u16 ctlModesFor11g[] =
  718. { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
  719. CTL_2GHT40
  720. };
  721. u16 numCtlModes, *pCtlMode, ctlMode, freq;
  722. struct chan_centers centers;
  723. int tx_chainmask;
  724. u8 twiceMinEdgePower;
  725. tx_chainmask = ahp->ah_txchainmask;
  726. ath9k_hw_get_channel_centers(ah, chan, &centers);
  727. twiceLargestAntenna = max(
  728. pEepData->modalHeader
  729. [IS_CHAN_2GHZ(chan)].antennaGainCh[0],
  730. pEepData->modalHeader
  731. [IS_CHAN_2GHZ(chan)].antennaGainCh[1]);
  732. twiceLargestAntenna = max((u8)twiceLargestAntenna,
  733. pEepData->modalHeader
  734. [IS_CHAN_2GHZ(chan)].antennaGainCh[2]);
  735. twiceLargestAntenna = (int8_t)min(AntennaReduction - twiceLargestAntenna, 0);
  736. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  737. if (ah->ah_tpScale != ATH9K_TP_SCALE_MAX) {
  738. maxRegAllowedPower -=
  739. (tpScaleReductionTable[(ah->ah_tpScale)] * 2);
  740. }
  741. scaledPower = min(powerLimit, maxRegAllowedPower);
  742. switch (ar5416_get_ntxchains(tx_chainmask)) {
  743. case 1:
  744. break;
  745. case 2:
  746. scaledPower -=
  747. pEepData->modalHeader[IS_CHAN_2GHZ(chan)].pwrDecreaseFor2Chain;
  748. break;
  749. case 3:
  750. scaledPower -=
  751. pEepData->modalHeader[IS_CHAN_2GHZ(chan)].pwrDecreaseFor3Chain;
  752. break;
  753. }
  754. scaledPower = max(0, (int32_t) scaledPower);
  755. if (IS_CHAN_2GHZ(chan)) {
  756. numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
  757. SUB_NUM_CTL_MODES_AT_2G_40;
  758. pCtlMode = ctlModesFor11g;
  759. ath9k_hw_get_legacy_target_powers(ah, chan,
  760. pEepData->calTargetPowerCck,
  761. AR5416_NUM_2G_CCK_TARGET_POWERS,
  762. &targetPowerCck, 4, false);
  763. ath9k_hw_get_legacy_target_powers(ah, chan,
  764. pEepData->calTargetPower2G,
  765. AR5416_NUM_2G_20_TARGET_POWERS,
  766. &targetPowerOfdm, 4, false);
  767. ath9k_hw_get_target_powers(ah, chan,
  768. pEepData->calTargetPower2GHT20,
  769. AR5416_NUM_2G_20_TARGET_POWERS,
  770. &targetPowerHt20, 8, false);
  771. if (IS_CHAN_HT40(chan)) {
  772. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  773. ath9k_hw_get_target_powers(ah, chan,
  774. pEepData->calTargetPower2GHT40,
  775. AR5416_NUM_2G_40_TARGET_POWERS,
  776. &targetPowerHt40, 8, true);
  777. ath9k_hw_get_legacy_target_powers(ah, chan,
  778. pEepData->calTargetPowerCck,
  779. AR5416_NUM_2G_CCK_TARGET_POWERS,
  780. &targetPowerCckExt, 4, true);
  781. ath9k_hw_get_legacy_target_powers(ah, chan,
  782. pEepData->calTargetPower2G,
  783. AR5416_NUM_2G_20_TARGET_POWERS,
  784. &targetPowerOfdmExt, 4, true);
  785. }
  786. } else {
  787. numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
  788. SUB_NUM_CTL_MODES_AT_5G_40;
  789. pCtlMode = ctlModesFor11a;
  790. ath9k_hw_get_legacy_target_powers(ah, chan,
  791. pEepData->calTargetPower5G,
  792. AR5416_NUM_5G_20_TARGET_POWERS,
  793. &targetPowerOfdm, 4, false);
  794. ath9k_hw_get_target_powers(ah, chan,
  795. pEepData->calTargetPower5GHT20,
  796. AR5416_NUM_5G_20_TARGET_POWERS,
  797. &targetPowerHt20, 8, false);
  798. if (IS_CHAN_HT40(chan)) {
  799. numCtlModes = ARRAY_SIZE(ctlModesFor11a);
  800. ath9k_hw_get_target_powers(ah, chan,
  801. pEepData->calTargetPower5GHT40,
  802. AR5416_NUM_5G_40_TARGET_POWERS,
  803. &targetPowerHt40, 8, true);
  804. ath9k_hw_get_legacy_target_powers(ah, chan,
  805. pEepData->calTargetPower5G,
  806. AR5416_NUM_5G_20_TARGET_POWERS,
  807. &targetPowerOfdmExt, 4, true);
  808. }
  809. }
  810. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  811. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  812. (pCtlMode[ctlMode] == CTL_2GHT40);
  813. if (isHt40CtlMode)
  814. freq = centers.synth_center;
  815. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  816. freq = centers.ext_center;
  817. else
  818. freq = centers.ctl_center;
  819. if (ar5416_get_eep_ver(ahp) == 14 && ar5416_get_eep_rev(ahp) <= 2)
  820. twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  821. DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
  822. "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
  823. "EXT_ADDITIVE %d\n",
  824. ctlMode, numCtlModes, isHt40CtlMode,
  825. (pCtlMode[ctlMode] & EXT_ADDITIVE));
  826. for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  827. DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
  828. " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
  829. "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
  830. "chan %d\n",
  831. i, cfgCtl, pCtlMode[ctlMode],
  832. pEepData->ctlIndex[i], chan->channel);
  833. if ((((cfgCtl & ~CTL_MODE_M) |
  834. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  835. pEepData->ctlIndex[i]) ||
  836. (((cfgCtl & ~CTL_MODE_M) |
  837. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  838. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
  839. rep = &(pEepData->ctlData[i]);
  840. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  841. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
  842. IS_CHAN_2GHZ(chan));
  843. DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
  844. " MATCH-EE_IDX %d: ch %d is2 %d "
  845. "2xMinEdge %d chainmask %d chains %d\n",
  846. i, freq, IS_CHAN_2GHZ(chan),
  847. twiceMinEdgePower, tx_chainmask,
  848. ar5416_get_ntxchains
  849. (tx_chainmask));
  850. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  851. twiceMaxEdgePower = min(twiceMaxEdgePower,
  852. twiceMinEdgePower);
  853. } else {
  854. twiceMaxEdgePower = twiceMinEdgePower;
  855. break;
  856. }
  857. }
  858. }
  859. minCtlPower = min(twiceMaxEdgePower, scaledPower);
  860. DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
  861. " SEL-Min ctlMode %d pCtlMode %d "
  862. "2xMaxEdge %d sP %d minCtlPwr %d\n",
  863. ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
  864. scaledPower, minCtlPower);
  865. switch (pCtlMode[ctlMode]) {
  866. case CTL_11B:
  867. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  868. targetPowerCck.tPow2x[i] =
  869. min(targetPowerCck.tPow2x[i],
  870. minCtlPower);
  871. }
  872. break;
  873. case CTL_11A:
  874. case CTL_11G:
  875. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  876. targetPowerOfdm.tPow2x[i] =
  877. min(targetPowerOfdm.tPow2x[i],
  878. minCtlPower);
  879. }
  880. break;
  881. case CTL_5GHT20:
  882. case CTL_2GHT20:
  883. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  884. targetPowerHt20.tPow2x[i] =
  885. min(targetPowerHt20.tPow2x[i],
  886. minCtlPower);
  887. }
  888. break;
  889. case CTL_11B_EXT:
  890. targetPowerCckExt.tPow2x[0] =
  891. min(targetPowerCckExt.tPow2x[0], minCtlPower);
  892. break;
  893. case CTL_11A_EXT:
  894. case CTL_11G_EXT:
  895. targetPowerOfdmExt.tPow2x[0] =
  896. min(targetPowerOfdmExt.tPow2x[0], minCtlPower);
  897. break;
  898. case CTL_5GHT40:
  899. case CTL_2GHT40:
  900. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  901. targetPowerHt40.tPow2x[i] =
  902. min(targetPowerHt40.tPow2x[i],
  903. minCtlPower);
  904. }
  905. break;
  906. default:
  907. break;
  908. }
  909. }
  910. ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
  911. ratesArray[rate18mb] = ratesArray[rate24mb] =
  912. targetPowerOfdm.tPow2x[0];
  913. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  914. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  915. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  916. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  917. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  918. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  919. if (IS_CHAN_2GHZ(chan)) {
  920. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  921. ratesArray[rate2s] = ratesArray[rate2l] =
  922. targetPowerCck.tPow2x[1];
  923. ratesArray[rate5_5s] = ratesArray[rate5_5l] =
  924. targetPowerCck.tPow2x[2];
  925. ;
  926. ratesArray[rate11s] = ratesArray[rate11l] =
  927. targetPowerCck.tPow2x[3];
  928. ;
  929. }
  930. if (IS_CHAN_HT40(chan)) {
  931. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  932. ratesArray[rateHt40_0 + i] =
  933. targetPowerHt40.tPow2x[i];
  934. }
  935. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  936. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  937. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  938. if (IS_CHAN_2GHZ(chan)) {
  939. ratesArray[rateExtCck] =
  940. targetPowerCckExt.tPow2x[0];
  941. }
  942. }
  943. return true;
  944. }
  945. bool ath9k_hw_set_power_cal_table(struct ath_hal *ah,
  946. struct ath9k_channel *chan,
  947. int16_t *pTxPowerIndexOffset)
  948. {
  949. struct ath_hal_5416 *ahp = AH5416(ah);
  950. struct ar5416_eeprom *pEepData = &ahp->ah_eeprom;
  951. struct cal_data_per_freq *pRawDataset;
  952. u8 *pCalBChans = NULL;
  953. u16 pdGainOverlap_t2;
  954. static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
  955. u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
  956. u16 numPiers, i, j;
  957. int16_t tMinCalPower;
  958. u16 numXpdGain, xpdMask;
  959. u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
  960. u32 reg32, regOffset, regChainOffset;
  961. int16_t modalIdx;
  962. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  963. xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
  964. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  965. AR5416_EEP_MINOR_VER_2) {
  966. pdGainOverlap_t2 =
  967. pEepData->modalHeader[modalIdx].pdGainOverlap;
  968. } else {
  969. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  970. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  971. }
  972. if (IS_CHAN_2GHZ(chan)) {
  973. pCalBChans = pEepData->calFreqPier2G;
  974. numPiers = AR5416_NUM_2G_CAL_PIERS;
  975. } else {
  976. pCalBChans = pEepData->calFreqPier5G;
  977. numPiers = AR5416_NUM_5G_CAL_PIERS;
  978. }
  979. numXpdGain = 0;
  980. for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
  981. if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
  982. if (numXpdGain >= AR5416_NUM_PD_GAINS)
  983. break;
  984. xpdGainValues[numXpdGain] =
  985. (u16)(AR5416_PD_GAINS_IN_MASK - i);
  986. numXpdGain++;
  987. }
  988. }
  989. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  990. (numXpdGain - 1) & 0x3);
  991. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  992. xpdGainValues[0]);
  993. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  994. xpdGainValues[1]);
  995. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  996. xpdGainValues[2]);
  997. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  998. if (AR_SREV_5416_V20_OR_LATER(ah) &&
  999. (ahp->ah_rxchainmask == 5 || ahp->ah_txchainmask == 5) &&
  1000. (i != 0)) {
  1001. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  1002. } else
  1003. regChainOffset = i * 0x1000;
  1004. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  1005. if (IS_CHAN_2GHZ(chan))
  1006. pRawDataset = pEepData->calPierData2G[i];
  1007. else
  1008. pRawDataset = pEepData->calPierData5G[i];
  1009. ath9k_hw_get_gain_boundaries_pdadcs(ah, chan,
  1010. pRawDataset, pCalBChans,
  1011. numPiers, pdGainOverlap_t2,
  1012. &tMinCalPower, gainBoundaries,
  1013. pdadcValues, numXpdGain);
  1014. if ((i == 0) || AR_SREV_5416_V20_OR_LATER(ah)) {
  1015. REG_WRITE(ah,
  1016. AR_PHY_TPCRG5 + regChainOffset,
  1017. SM(pdGainOverlap_t2,
  1018. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
  1019. | SM(gainBoundaries[0],
  1020. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
  1021. | SM(gainBoundaries[1],
  1022. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
  1023. | SM(gainBoundaries[2],
  1024. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
  1025. | SM(gainBoundaries[3],
  1026. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
  1027. }
  1028. regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
  1029. for (j = 0; j < 32; j++) {
  1030. reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
  1031. ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
  1032. ((pdadcValues[4 * j + 2] & 0xFF) << 16) |
  1033. ((pdadcValues[4 * j + 3] & 0xFF) << 24);
  1034. REG_WRITE(ah, regOffset, reg32);
  1035. DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
  1036. "PDADC (%d,%4x): %4.4x %8.8x\n",
  1037. i, regChainOffset, regOffset,
  1038. reg32);
  1039. DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
  1040. "PDADC: Chain %d | PDADC %3d Value %3d | "
  1041. "PDADC %3d Value %3d | PDADC %3d Value %3d | "
  1042. "PDADC %3d Value %3d |\n",
  1043. i, 4 * j, pdadcValues[4 * j],
  1044. 4 * j + 1, pdadcValues[4 * j + 1],
  1045. 4 * j + 2, pdadcValues[4 * j + 2],
  1046. 4 * j + 3,
  1047. pdadcValues[4 * j + 3]);
  1048. regOffset += 4;
  1049. }
  1050. }
  1051. }
  1052. *pTxPowerIndexOffset = 0;
  1053. return true;
  1054. }
  1055. /* XXX: Clean me up, make me more legible */
  1056. bool ath9k_hw_eeprom_set_board_values(struct ath_hal *ah,
  1057. struct ath9k_channel *chan)
  1058. {
  1059. struct modal_eep_header *pModal;
  1060. struct ath_hal_5416 *ahp = AH5416(ah);
  1061. struct ar5416_eeprom *eep = &ahp->ah_eeprom;
  1062. int i, regChainOffset;
  1063. u8 txRxAttenLocal;
  1064. u16 ant_config;
  1065. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  1066. txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
  1067. ath9k_hw_get_eeprom_antenna_cfg(ah, chan, 0, &ant_config);
  1068. REG_WRITE(ah, AR_PHY_SWITCH_COM, ant_config);
  1069. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  1070. if (AR_SREV_9280(ah)) {
  1071. if (i >= 2)
  1072. break;
  1073. }
  1074. if (AR_SREV_5416_V20_OR_LATER(ah) &&
  1075. (ahp->ah_rxchainmask == 5 || ahp->ah_txchainmask == 5)
  1076. && (i != 0))
  1077. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  1078. else
  1079. regChainOffset = i * 0x1000;
  1080. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  1081. pModal->antCtrlChain[i]);
  1082. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  1083. (REG_READ(ah,
  1084. AR_PHY_TIMING_CTRL4(0) +
  1085. regChainOffset) &
  1086. ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  1087. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  1088. SM(pModal->iqCalICh[i],
  1089. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  1090. SM(pModal->iqCalQCh[i],
  1091. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  1092. if ((i == 0) || AR_SREV_5416_V20_OR_LATER(ah)) {
  1093. if ((eep->baseEepHeader.version &
  1094. AR5416_EEP_VER_MINOR_MASK) >=
  1095. AR5416_EEP_MINOR_VER_3) {
  1096. txRxAttenLocal = pModal->txRxAttenCh[i];
  1097. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1098. REG_RMW_FIELD(ah,
  1099. AR_PHY_GAIN_2GHZ +
  1100. regChainOffset,
  1101. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  1102. pModal->
  1103. bswMargin[i]);
  1104. REG_RMW_FIELD(ah,
  1105. AR_PHY_GAIN_2GHZ +
  1106. regChainOffset,
  1107. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  1108. pModal->
  1109. bswAtten[i]);
  1110. REG_RMW_FIELD(ah,
  1111. AR_PHY_GAIN_2GHZ +
  1112. regChainOffset,
  1113. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  1114. pModal->
  1115. xatten2Margin[i]);
  1116. REG_RMW_FIELD(ah,
  1117. AR_PHY_GAIN_2GHZ +
  1118. regChainOffset,
  1119. AR_PHY_GAIN_2GHZ_XATTEN2_DB,
  1120. pModal->
  1121. xatten2Db[i]);
  1122. } else {
  1123. REG_WRITE(ah,
  1124. AR_PHY_GAIN_2GHZ +
  1125. regChainOffset,
  1126. (REG_READ(ah,
  1127. AR_PHY_GAIN_2GHZ +
  1128. regChainOffset) &
  1129. ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
  1130. | SM(pModal->
  1131. bswMargin[i],
  1132. AR_PHY_GAIN_2GHZ_BSW_MARGIN));
  1133. REG_WRITE(ah,
  1134. AR_PHY_GAIN_2GHZ +
  1135. regChainOffset,
  1136. (REG_READ(ah,
  1137. AR_PHY_GAIN_2GHZ +
  1138. regChainOffset) &
  1139. ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
  1140. | SM(pModal->bswAtten[i],
  1141. AR_PHY_GAIN_2GHZ_BSW_ATTEN));
  1142. }
  1143. }
  1144. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1145. REG_RMW_FIELD(ah,
  1146. AR_PHY_RXGAIN +
  1147. regChainOffset,
  1148. AR9280_PHY_RXGAIN_TXRX_ATTEN,
  1149. txRxAttenLocal);
  1150. REG_RMW_FIELD(ah,
  1151. AR_PHY_RXGAIN +
  1152. regChainOffset,
  1153. AR9280_PHY_RXGAIN_TXRX_MARGIN,
  1154. pModal->rxTxMarginCh[i]);
  1155. } else {
  1156. REG_WRITE(ah,
  1157. AR_PHY_RXGAIN + regChainOffset,
  1158. (REG_READ(ah,
  1159. AR_PHY_RXGAIN +
  1160. regChainOffset) &
  1161. ~AR_PHY_RXGAIN_TXRX_ATTEN) |
  1162. SM(txRxAttenLocal,
  1163. AR_PHY_RXGAIN_TXRX_ATTEN));
  1164. REG_WRITE(ah,
  1165. AR_PHY_GAIN_2GHZ +
  1166. regChainOffset,
  1167. (REG_READ(ah,
  1168. AR_PHY_GAIN_2GHZ +
  1169. regChainOffset) &
  1170. ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
  1171. SM(pModal->rxTxMarginCh[i],
  1172. AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
  1173. }
  1174. }
  1175. }
  1176. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1177. if (IS_CHAN_2GHZ(chan)) {
  1178. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  1179. AR_AN_RF2G1_CH0_OB,
  1180. AR_AN_RF2G1_CH0_OB_S,
  1181. pModal->ob);
  1182. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  1183. AR_AN_RF2G1_CH0_DB,
  1184. AR_AN_RF2G1_CH0_DB_S,
  1185. pModal->db);
  1186. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  1187. AR_AN_RF2G1_CH1_OB,
  1188. AR_AN_RF2G1_CH1_OB_S,
  1189. pModal->ob_ch1);
  1190. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  1191. AR_AN_RF2G1_CH1_DB,
  1192. AR_AN_RF2G1_CH1_DB_S,
  1193. pModal->db_ch1);
  1194. } else {
  1195. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  1196. AR_AN_RF5G1_CH0_OB5,
  1197. AR_AN_RF5G1_CH0_OB5_S,
  1198. pModal->ob);
  1199. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  1200. AR_AN_RF5G1_CH0_DB5,
  1201. AR_AN_RF5G1_CH0_DB5_S,
  1202. pModal->db);
  1203. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  1204. AR_AN_RF5G1_CH1_OB5,
  1205. AR_AN_RF5G1_CH1_OB5_S,
  1206. pModal->ob_ch1);
  1207. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  1208. AR_AN_RF5G1_CH1_DB5,
  1209. AR_AN_RF5G1_CH1_DB5_S,
  1210. pModal->db_ch1);
  1211. }
  1212. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  1213. AR_AN_TOP2_XPABIAS_LVL,
  1214. AR_AN_TOP2_XPABIAS_LVL_S,
  1215. pModal->xpaBiasLvl);
  1216. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  1217. AR_AN_TOP2_LOCALBIAS,
  1218. AR_AN_TOP2_LOCALBIAS_S,
  1219. pModal->local_bias);
  1220. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "ForceXPAon: %d\n",
  1221. pModal->force_xpaon);
  1222. REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
  1223. pModal->force_xpaon);
  1224. }
  1225. REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
  1226. pModal->switchSettling);
  1227. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
  1228. pModal->adcDesiredSize);
  1229. if (!AR_SREV_9280_10_OR_LATER(ah))
  1230. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  1231. AR_PHY_DESIRED_SZ_PGA,
  1232. pModal->pgaDesiredSize);
  1233. REG_WRITE(ah, AR_PHY_RF_CTL4,
  1234. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  1235. | SM(pModal->txEndToXpaOff,
  1236. AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  1237. | SM(pModal->txFrameToXpaOn,
  1238. AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  1239. | SM(pModal->txFrameToXpaOn,
  1240. AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  1241. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  1242. pModal->txEndToRxOn);
  1243. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1244. REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
  1245. pModal->thresh62);
  1246. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  1247. AR_PHY_EXT_CCA0_THRESH62,
  1248. pModal->thresh62);
  1249. } else {
  1250. REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
  1251. pModal->thresh62);
  1252. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  1253. AR_PHY_EXT_CCA_THRESH62,
  1254. pModal->thresh62);
  1255. }
  1256. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1257. AR5416_EEP_MINOR_VER_2) {
  1258. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  1259. AR_PHY_TX_END_DATA_START,
  1260. pModal->txFrameToDataStart);
  1261. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
  1262. pModal->txFrameToPaOn);
  1263. }
  1264. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1265. AR5416_EEP_MINOR_VER_3) {
  1266. if (IS_CHAN_HT40(chan))
  1267. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  1268. AR_PHY_SETTLING_SWITCH,
  1269. pModal->swSettleHt40);
  1270. }
  1271. return true;
  1272. }
  1273. int ath9k_hw_get_eeprom_antenna_cfg(struct ath_hal *ah,
  1274. struct ath9k_channel *chan,
  1275. u8 index, u16 *config)
  1276. {
  1277. struct ath_hal_5416 *ahp = AH5416(ah);
  1278. struct ar5416_eeprom *eep = &ahp->ah_eeprom;
  1279. struct modal_eep_header *pModal =
  1280. &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  1281. struct base_eep_header *pBase = &eep->baseEepHeader;
  1282. switch (index) {
  1283. case 0:
  1284. *config = pModal->antCtrlCommon & 0xFFFF;
  1285. return 0;
  1286. case 1:
  1287. if (pBase->version >= 0x0E0D) {
  1288. if (pModal->useAnt1) {
  1289. *config =
  1290. ((pModal->antCtrlCommon & 0xFFFF0000) >> 16);
  1291. return 0;
  1292. }
  1293. }
  1294. break;
  1295. default:
  1296. break;
  1297. }
  1298. return -EINVAL;
  1299. }
  1300. u8 ath9k_hw_get_num_ant_config(struct ath_hal *ah,
  1301. enum ieee80211_band freq_band)
  1302. {
  1303. struct ath_hal_5416 *ahp = AH5416(ah);
  1304. struct ar5416_eeprom *eep = &ahp->ah_eeprom;
  1305. struct modal_eep_header *pModal =
  1306. &(eep->modalHeader[IEEE80211_BAND_5GHZ == freq_band]);
  1307. struct base_eep_header *pBase = &eep->baseEepHeader;
  1308. u8 num_ant_config;
  1309. num_ant_config = 1;
  1310. if (pBase->version >= 0x0E0D)
  1311. if (pModal->useAnt1)
  1312. num_ant_config += 1;
  1313. return num_ant_config;
  1314. }
  1315. u16 ath9k_hw_eeprom_get_spur_chan(struct ath_hal *ah, u16 i, bool is2GHz)
  1316. {
  1317. struct ath_hal_5416 *ahp = AH5416(ah);
  1318. struct ar5416_eeprom *eep =
  1319. (struct ar5416_eeprom *) &ahp->ah_eeprom;
  1320. u16 spur_val = AR_NO_SPUR;
  1321. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  1322. "Getting spur idx %d is2Ghz. %d val %x\n",
  1323. i, is2GHz, ah->ah_config.spurchans[i][is2GHz]);
  1324. switch (ah->ah_config.spurmode) {
  1325. case SPUR_DISABLE:
  1326. break;
  1327. case SPUR_ENABLE_IOCTL:
  1328. spur_val = ah->ah_config.spurchans[i][is2GHz];
  1329. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  1330. "Getting spur val from new loc. %d\n", spur_val);
  1331. break;
  1332. case SPUR_ENABLE_EEPROM:
  1333. spur_val = eep->modalHeader[is2GHz].spurChans[i].spurChan;
  1334. break;
  1335. }
  1336. return spur_val;
  1337. }
  1338. u32 ath9k_hw_get_eeprom(struct ath_hal *ah,
  1339. enum eeprom_param param)
  1340. {
  1341. struct ath_hal_5416 *ahp = AH5416(ah);
  1342. struct ar5416_eeprom *eep = &ahp->ah_eeprom;
  1343. struct modal_eep_header *pModal = eep->modalHeader;
  1344. struct base_eep_header *pBase = &eep->baseEepHeader;
  1345. switch (param) {
  1346. case EEP_NFTHRESH_5:
  1347. return pModal[0].noiseFloorThreshCh[0];
  1348. case EEP_NFTHRESH_2:
  1349. return pModal[1].noiseFloorThreshCh[0];
  1350. case AR_EEPROM_MAC(0):
  1351. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  1352. case AR_EEPROM_MAC(1):
  1353. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  1354. case AR_EEPROM_MAC(2):
  1355. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  1356. case EEP_REG_0:
  1357. return pBase->regDmn[0];
  1358. case EEP_REG_1:
  1359. return pBase->regDmn[1];
  1360. case EEP_OP_CAP:
  1361. return pBase->deviceCap;
  1362. case EEP_OP_MODE:
  1363. return pBase->opCapFlags;
  1364. case EEP_RF_SILENT:
  1365. return pBase->rfSilent;
  1366. case EEP_OB_5:
  1367. return pModal[0].ob;
  1368. case EEP_DB_5:
  1369. return pModal[0].db;
  1370. case EEP_OB_2:
  1371. return pModal[1].ob;
  1372. case EEP_DB_2:
  1373. return pModal[1].db;
  1374. case EEP_MINOR_REV:
  1375. return pBase->version & AR5416_EEP_VER_MINOR_MASK;
  1376. case EEP_TX_MASK:
  1377. return pBase->txMask;
  1378. case EEP_RX_MASK:
  1379. return pBase->rxMask;
  1380. case EEP_RXGAIN_TYPE:
  1381. return pBase->rxGainType;
  1382. case EEP_TXGAIN_TYPE:
  1383. return pBase->txGainType;
  1384. default:
  1385. return 0;
  1386. }
  1387. }
  1388. int ath9k_hw_eeprom_attach(struct ath_hal *ah)
  1389. {
  1390. int status;
  1391. if (ath9k_hw_use_flash(ah))
  1392. ath9k_hw_flash_map(ah);
  1393. if (!ath9k_hw_fill_eeprom(ah))
  1394. return -EIO;
  1395. status = ath9k_hw_check_eeprom(ah);
  1396. return status;
  1397. }