eeprom.c 43 KB

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