eeprom.c 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786
  1. /*
  2. * Copyright (c) 2008-2009 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "ath9k.h"
  17. static void ath9k_hw_analog_shift_rmw(struct ath_hw *ah,
  18. u32 reg, u32 mask,
  19. u32 shift, u32 val)
  20. {
  21. u32 regVal;
  22. regVal = REG_READ(ah, reg) & ~mask;
  23. regVal |= (val << shift) & mask;
  24. REG_WRITE(ah, reg, regVal);
  25. if (ah->config.analog_shiftreg)
  26. udelay(100);
  27. return;
  28. }
  29. static inline u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz)
  30. {
  31. if (fbin == AR5416_BCHAN_UNUSED)
  32. return fbin;
  33. return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
  34. }
  35. static inline int16_t ath9k_hw_interpolate(u16 target,
  36. u16 srcLeft, u16 srcRight,
  37. int16_t targetLeft,
  38. int16_t targetRight)
  39. {
  40. int16_t rv;
  41. if (srcRight == srcLeft) {
  42. rv = targetLeft;
  43. } else {
  44. rv = (int16_t) (((target - srcLeft) * targetRight +
  45. (srcRight - target) * targetLeft) /
  46. (srcRight - srcLeft));
  47. }
  48. return rv;
  49. }
  50. static inline bool ath9k_hw_get_lower_upper_index(u8 target, u8 *pList,
  51. u16 listSize, u16 *indexL,
  52. u16 *indexR)
  53. {
  54. u16 i;
  55. if (target <= pList[0]) {
  56. *indexL = *indexR = 0;
  57. return true;
  58. }
  59. if (target >= pList[listSize - 1]) {
  60. *indexL = *indexR = (u16) (listSize - 1);
  61. return true;
  62. }
  63. for (i = 0; i < listSize - 1; i++) {
  64. if (pList[i] == target) {
  65. *indexL = *indexR = i;
  66. return true;
  67. }
  68. if (target < pList[i + 1]) {
  69. *indexL = i;
  70. *indexR = (u16) (i + 1);
  71. return false;
  72. }
  73. }
  74. return false;
  75. }
  76. static inline bool ath9k_hw_nvram_read(struct ath_hw *ah, u32 off, u16 *data)
  77. {
  78. struct ath_softc *sc = ah->ah_sc;
  79. return sc->bus_ops->eeprom_read(ah, off, data);
  80. }
  81. static inline bool ath9k_hw_fill_vpd_table(u8 pwrMin, u8 pwrMax, u8 *pPwrList,
  82. u8 *pVpdList, u16 numIntercepts,
  83. u8 *pRetVpdList)
  84. {
  85. u16 i, k;
  86. u8 currPwr = pwrMin;
  87. u16 idxL = 0, idxR = 0;
  88. for (i = 0; i <= (pwrMax - pwrMin) / 2; i++) {
  89. ath9k_hw_get_lower_upper_index(currPwr, pPwrList,
  90. numIntercepts, &(idxL),
  91. &(idxR));
  92. if (idxR < 1)
  93. idxR = 1;
  94. if (idxL == numIntercepts - 1)
  95. idxL = (u16) (numIntercepts - 2);
  96. if (pPwrList[idxL] == pPwrList[idxR])
  97. k = pVpdList[idxL];
  98. else
  99. k = (u16)(((currPwr - pPwrList[idxL]) * pVpdList[idxR] +
  100. (pPwrList[idxR] - currPwr) * pVpdList[idxL]) /
  101. (pPwrList[idxR] - pPwrList[idxL]));
  102. pRetVpdList[i] = (u8) k;
  103. currPwr += 2;
  104. }
  105. return true;
  106. }
  107. static void ath9k_hw_get_legacy_target_powers(struct ath_hw *ah,
  108. struct ath9k_channel *chan,
  109. struct cal_target_power_leg *powInfo,
  110. u16 numChannels,
  111. struct cal_target_power_leg *pNewPower,
  112. u16 numRates, bool isExtTarget)
  113. {
  114. struct chan_centers centers;
  115. u16 clo, chi;
  116. int i;
  117. int matchIndex = -1, lowIndex = -1;
  118. u16 freq;
  119. ath9k_hw_get_channel_centers(ah, chan, &centers);
  120. freq = (isExtTarget) ? centers.ext_center : centers.ctl_center;
  121. if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel,
  122. IS_CHAN_2GHZ(chan))) {
  123. matchIndex = 0;
  124. } else {
  125. for (i = 0; (i < numChannels) &&
  126. (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  127. if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
  128. IS_CHAN_2GHZ(chan))) {
  129. matchIndex = i;
  130. break;
  131. } else if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
  132. IS_CHAN_2GHZ(chan))) &&
  133. (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
  134. IS_CHAN_2GHZ(chan)))) {
  135. lowIndex = i - 1;
  136. break;
  137. }
  138. }
  139. if ((matchIndex == -1) && (lowIndex == -1))
  140. matchIndex = i - 1;
  141. }
  142. if (matchIndex != -1) {
  143. *pNewPower = powInfo[matchIndex];
  144. } else {
  145. clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
  146. IS_CHAN_2GHZ(chan));
  147. chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
  148. IS_CHAN_2GHZ(chan));
  149. for (i = 0; i < numRates; i++) {
  150. pNewPower->tPow2x[i] =
  151. (u8)ath9k_hw_interpolate(freq, clo, chi,
  152. powInfo[lowIndex].tPow2x[i],
  153. powInfo[lowIndex + 1].tPow2x[i]);
  154. }
  155. }
  156. }
  157. static void ath9k_get_txgain_index(struct ath_hw *ah,
  158. struct ath9k_channel *chan,
  159. struct calDataPerFreqOpLoop *rawDatasetOpLoop,
  160. u8 *calChans, u16 availPiers, u8 *pwr, u8 *pcdacIdx)
  161. {
  162. u8 pcdac, i = 0;
  163. u16 idxL = 0, idxR = 0, numPiers;
  164. bool match;
  165. struct chan_centers centers;
  166. ath9k_hw_get_channel_centers(ah, chan, &centers);
  167. for (numPiers = 0; numPiers < availPiers; numPiers++)
  168. if (calChans[numPiers] == AR5416_BCHAN_UNUSED)
  169. break;
  170. match = ath9k_hw_get_lower_upper_index(
  171. (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
  172. calChans, numPiers, &idxL, &idxR);
  173. if (match) {
  174. pcdac = rawDatasetOpLoop[idxL].pcdac[0][0];
  175. *pwr = rawDatasetOpLoop[idxL].pwrPdg[0][0];
  176. } else {
  177. pcdac = rawDatasetOpLoop[idxR].pcdac[0][0];
  178. *pwr = (rawDatasetOpLoop[idxL].pwrPdg[0][0] +
  179. rawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
  180. }
  181. while (pcdac > ah->originalGain[i] &&
  182. i < (AR9280_TX_GAIN_TABLE_SIZE - 1))
  183. i++;
  184. *pcdacIdx = i;
  185. return;
  186. }
  187. static void ath9k_olc_get_pdadcs(struct ath_hw *ah,
  188. u32 initTxGain,
  189. int txPower,
  190. u8 *pPDADCValues)
  191. {
  192. u32 i;
  193. u32 offset;
  194. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_0,
  195. AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3);
  196. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_1,
  197. AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3);
  198. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL7,
  199. AR_PHY_TX_PWRCTRL_INIT_TX_GAIN, initTxGain);
  200. offset = txPower;
  201. for (i = 0; i < AR5416_NUM_PDADC_VALUES; i++)
  202. if (i < offset)
  203. pPDADCValues[i] = 0x0;
  204. else
  205. pPDADCValues[i] = 0xFF;
  206. }
  207. static void ath9k_hw_get_target_powers(struct ath_hw *ah,
  208. struct ath9k_channel *chan,
  209. struct cal_target_power_ht *powInfo,
  210. u16 numChannels,
  211. struct cal_target_power_ht *pNewPower,
  212. u16 numRates, bool isHt40Target)
  213. {
  214. struct chan_centers centers;
  215. u16 clo, chi;
  216. int i;
  217. int matchIndex = -1, lowIndex = -1;
  218. u16 freq;
  219. ath9k_hw_get_channel_centers(ah, chan, &centers);
  220. freq = isHt40Target ? centers.synth_center : centers.ctl_center;
  221. if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) {
  222. matchIndex = 0;
  223. } else {
  224. for (i = 0; (i < numChannels) &&
  225. (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  226. if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
  227. IS_CHAN_2GHZ(chan))) {
  228. matchIndex = i;
  229. break;
  230. } else
  231. if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
  232. IS_CHAN_2GHZ(chan))) &&
  233. (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
  234. IS_CHAN_2GHZ(chan)))) {
  235. lowIndex = i - 1;
  236. break;
  237. }
  238. }
  239. if ((matchIndex == -1) && (lowIndex == -1))
  240. matchIndex = i - 1;
  241. }
  242. if (matchIndex != -1) {
  243. *pNewPower = powInfo[matchIndex];
  244. } else {
  245. clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
  246. IS_CHAN_2GHZ(chan));
  247. chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
  248. IS_CHAN_2GHZ(chan));
  249. for (i = 0; i < numRates; i++) {
  250. pNewPower->tPow2x[i] = (u8)ath9k_hw_interpolate(freq,
  251. clo, chi,
  252. powInfo[lowIndex].tPow2x[i],
  253. powInfo[lowIndex + 1].tPow2x[i]);
  254. }
  255. }
  256. }
  257. static u16 ath9k_hw_get_max_edge_power(u16 freq,
  258. struct cal_ctl_edges *pRdEdgesPower,
  259. bool is2GHz, int num_band_edges)
  260. {
  261. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  262. int i;
  263. for (i = 0; (i < num_band_edges) &&
  264. (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  265. if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) {
  266. twiceMaxEdgePower = pRdEdgesPower[i].tPower;
  267. break;
  268. } else if ((i > 0) &&
  269. (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel,
  270. is2GHz))) {
  271. if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel,
  272. is2GHz) < freq &&
  273. pRdEdgesPower[i - 1].flag) {
  274. twiceMaxEdgePower =
  275. pRdEdgesPower[i - 1].tPower;
  276. }
  277. break;
  278. }
  279. }
  280. return twiceMaxEdgePower;
  281. }
  282. /****************************************/
  283. /* EEPROM Operations for 4K sized cards */
  284. /****************************************/
  285. static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah)
  286. {
  287. return ((ah->eeprom.map4k.baseEepHeader.version >> 12) & 0xF);
  288. }
  289. static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah)
  290. {
  291. return ((ah->eeprom.map4k.baseEepHeader.version) & 0xFFF);
  292. }
  293. static bool ath9k_hw_4k_fill_eeprom(struct ath_hw *ah)
  294. {
  295. #define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
  296. u16 *eep_data = (u16 *)&ah->eeprom.map4k;
  297. int addr, eep_start_loc = 0;
  298. eep_start_loc = 64;
  299. if (!ath9k_hw_use_flash(ah)) {
  300. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  301. "Reading from EEPROM, not flash\n");
  302. }
  303. for (addr = 0; addr < SIZE_EEPROM_4K; addr++) {
  304. if (!ath9k_hw_nvram_read(ah, addr + eep_start_loc, eep_data)) {
  305. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  306. "Unable to read eeprom region \n");
  307. return false;
  308. }
  309. eep_data++;
  310. }
  311. return true;
  312. #undef SIZE_EEPROM_4K
  313. }
  314. static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah)
  315. {
  316. #define EEPROM_4K_SIZE (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
  317. struct ar5416_eeprom_4k *eep =
  318. (struct ar5416_eeprom_4k *) &ah->eeprom.map4k;
  319. u16 *eepdata, temp, magic, magic2;
  320. u32 sum = 0, el;
  321. bool need_swap = false;
  322. int i, addr;
  323. if (!ath9k_hw_use_flash(ah)) {
  324. if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET,
  325. &magic)) {
  326. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  327. "Reading Magic # failed\n");
  328. return false;
  329. }
  330. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  331. "Read Magic = 0x%04X\n", magic);
  332. if (magic != AR5416_EEPROM_MAGIC) {
  333. magic2 = swab16(magic);
  334. if (magic2 == AR5416_EEPROM_MAGIC) {
  335. need_swap = true;
  336. eepdata = (u16 *) (&ah->eeprom);
  337. for (addr = 0; addr < EEPROM_4K_SIZE; addr++) {
  338. temp = swab16(*eepdata);
  339. *eepdata = temp;
  340. eepdata++;
  341. }
  342. } else {
  343. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  344. "Invalid EEPROM Magic. "
  345. "endianness mismatch.\n");
  346. return -EINVAL;
  347. }
  348. }
  349. }
  350. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
  351. need_swap ? "True" : "False");
  352. if (need_swap)
  353. el = swab16(ah->eeprom.map4k.baseEepHeader.length);
  354. else
  355. el = ah->eeprom.map4k.baseEepHeader.length;
  356. if (el > sizeof(struct ar5416_eeprom_4k))
  357. el = sizeof(struct ar5416_eeprom_4k) / sizeof(u16);
  358. else
  359. el = el / sizeof(u16);
  360. eepdata = (u16 *)(&ah->eeprom);
  361. for (i = 0; i < el; i++)
  362. sum ^= *eepdata++;
  363. if (need_swap) {
  364. u32 integer;
  365. u16 word;
  366. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  367. "EEPROM Endianness is not native.. Changing\n");
  368. word = swab16(eep->baseEepHeader.length);
  369. eep->baseEepHeader.length = word;
  370. word = swab16(eep->baseEepHeader.checksum);
  371. eep->baseEepHeader.checksum = word;
  372. word = swab16(eep->baseEepHeader.version);
  373. eep->baseEepHeader.version = word;
  374. word = swab16(eep->baseEepHeader.regDmn[0]);
  375. eep->baseEepHeader.regDmn[0] = word;
  376. word = swab16(eep->baseEepHeader.regDmn[1]);
  377. eep->baseEepHeader.regDmn[1] = word;
  378. word = swab16(eep->baseEepHeader.rfSilent);
  379. eep->baseEepHeader.rfSilent = word;
  380. word = swab16(eep->baseEepHeader.blueToothOptions);
  381. eep->baseEepHeader.blueToothOptions = word;
  382. word = swab16(eep->baseEepHeader.deviceCap);
  383. eep->baseEepHeader.deviceCap = word;
  384. integer = swab32(eep->modalHeader.antCtrlCommon);
  385. eep->modalHeader.antCtrlCommon = integer;
  386. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  387. integer = swab32(eep->modalHeader.antCtrlChain[i]);
  388. eep->modalHeader.antCtrlChain[i] = integer;
  389. }
  390. for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
  391. word = swab16(eep->modalHeader.spurChans[i].spurChan);
  392. eep->modalHeader.spurChans[i].spurChan = word;
  393. }
  394. }
  395. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
  396. ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  397. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  398. "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  399. sum, ah->eep_ops->get_eeprom_ver(ah));
  400. return -EINVAL;
  401. }
  402. return 0;
  403. #undef EEPROM_4K_SIZE
  404. }
  405. static u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah,
  406. enum eeprom_param param)
  407. {
  408. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  409. struct modal_eep_4k_header *pModal = &eep->modalHeader;
  410. struct base_eep_header_4k *pBase = &eep->baseEepHeader;
  411. switch (param) {
  412. case EEP_NFTHRESH_2:
  413. return pModal->noiseFloorThreshCh[0];
  414. case AR_EEPROM_MAC(0):
  415. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  416. case AR_EEPROM_MAC(1):
  417. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  418. case AR_EEPROM_MAC(2):
  419. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  420. case EEP_REG_0:
  421. return pBase->regDmn[0];
  422. case EEP_REG_1:
  423. return pBase->regDmn[1];
  424. case EEP_OP_CAP:
  425. return pBase->deviceCap;
  426. case EEP_OP_MODE:
  427. return pBase->opCapFlags;
  428. case EEP_RF_SILENT:
  429. return pBase->rfSilent;
  430. case EEP_OB_2:
  431. return pModal->ob_01;
  432. case EEP_DB_2:
  433. return pModal->db1_01;
  434. case EEP_MINOR_REV:
  435. return pBase->version & AR5416_EEP_VER_MINOR_MASK;
  436. case EEP_TX_MASK:
  437. return pBase->txMask;
  438. case EEP_RX_MASK:
  439. return pBase->rxMask;
  440. case EEP_FRAC_N_5G:
  441. return 0;
  442. default:
  443. return 0;
  444. }
  445. }
  446. static void ath9k_hw_get_4k_gain_boundaries_pdadcs(struct ath_hw *ah,
  447. struct ath9k_channel *chan,
  448. struct cal_data_per_freq_4k *pRawDataSet,
  449. u8 *bChans, u16 availPiers,
  450. u16 tPdGainOverlap, int16_t *pMinCalPower,
  451. u16 *pPdGainBoundaries, u8 *pPDADCValues,
  452. u16 numXpdGains)
  453. {
  454. #define TMP_VAL_VPD_TABLE \
  455. ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep));
  456. int i, j, k;
  457. int16_t ss;
  458. u16 idxL = 0, idxR = 0, numPiers;
  459. static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS]
  460. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  461. static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS]
  462. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  463. static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS]
  464. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  465. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  466. u8 minPwrT4[AR5416_EEP4K_NUM_PD_GAINS];
  467. u8 maxPwrT4[AR5416_EEP4K_NUM_PD_GAINS];
  468. int16_t vpdStep;
  469. int16_t tmpVal;
  470. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  471. bool match;
  472. int16_t minDelta = 0;
  473. struct chan_centers centers;
  474. #define PD_GAIN_BOUNDARY_DEFAULT 58;
  475. ath9k_hw_get_channel_centers(ah, chan, &centers);
  476. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  477. if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
  478. break;
  479. }
  480. match = ath9k_hw_get_lower_upper_index(
  481. (u8)FREQ2FBIN(centers.synth_center,
  482. IS_CHAN_2GHZ(chan)), bChans, numPiers,
  483. &idxL, &idxR);
  484. if (match) {
  485. for (i = 0; i < numXpdGains; i++) {
  486. minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
  487. maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
  488. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  489. pRawDataSet[idxL].pwrPdg[i],
  490. pRawDataSet[idxL].vpdPdg[i],
  491. AR5416_EEP4K_PD_GAIN_ICEPTS,
  492. vpdTableI[i]);
  493. }
  494. } else {
  495. for (i = 0; i < numXpdGains; i++) {
  496. pVpdL = pRawDataSet[idxL].vpdPdg[i];
  497. pPwrL = pRawDataSet[idxL].pwrPdg[i];
  498. pVpdR = pRawDataSet[idxR].vpdPdg[i];
  499. pPwrR = pRawDataSet[idxR].pwrPdg[i];
  500. minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
  501. maxPwrT4[i] =
  502. min(pPwrL[AR5416_EEP4K_PD_GAIN_ICEPTS - 1],
  503. pPwrR[AR5416_EEP4K_PD_GAIN_ICEPTS - 1]);
  504. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  505. pPwrL, pVpdL,
  506. AR5416_EEP4K_PD_GAIN_ICEPTS,
  507. vpdTableL[i]);
  508. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  509. pPwrR, pVpdR,
  510. AR5416_EEP4K_PD_GAIN_ICEPTS,
  511. vpdTableR[i]);
  512. for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
  513. vpdTableI[i][j] =
  514. (u8)(ath9k_hw_interpolate((u16)
  515. FREQ2FBIN(centers.
  516. synth_center,
  517. IS_CHAN_2GHZ
  518. (chan)),
  519. bChans[idxL], bChans[idxR],
  520. vpdTableL[i][j], vpdTableR[i][j]));
  521. }
  522. }
  523. }
  524. *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
  525. k = 0;
  526. for (i = 0; i < numXpdGains; i++) {
  527. if (i == (numXpdGains - 1))
  528. pPdGainBoundaries[i] =
  529. (u16)(maxPwrT4[i] / 2);
  530. else
  531. pPdGainBoundaries[i] =
  532. (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
  533. pPdGainBoundaries[i] =
  534. min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
  535. if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
  536. minDelta = pPdGainBoundaries[0] - 23;
  537. pPdGainBoundaries[0] = 23;
  538. } else {
  539. minDelta = 0;
  540. }
  541. if (i == 0) {
  542. if (AR_SREV_9280_10_OR_LATER(ah))
  543. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  544. else
  545. ss = 0;
  546. } else {
  547. ss = (int16_t)((pPdGainBoundaries[i - 1] -
  548. (minPwrT4[i] / 2)) -
  549. tPdGainOverlap + 1 + minDelta);
  550. }
  551. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  552. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  553. while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  554. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  555. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  556. ss++;
  557. }
  558. sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  559. tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
  560. (minPwrT4[i] / 2));
  561. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  562. tgtIndex : sizeCurrVpdTable;
  563. while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1)))
  564. pPDADCValues[k++] = vpdTableI[i][ss++];
  565. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  566. vpdTableI[i][sizeCurrVpdTable - 2]);
  567. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  568. if (tgtIndex >= maxIndex) {
  569. while ((ss <= tgtIndex) &&
  570. (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  571. tmpVal = (int16_t) TMP_VAL_VPD_TABLE;
  572. pPDADCValues[k++] = (u8)((tmpVal > 255) ?
  573. 255 : tmpVal);
  574. ss++;
  575. }
  576. }
  577. }
  578. while (i < AR5416_EEP4K_PD_GAINS_IN_MASK) {
  579. pPdGainBoundaries[i] = PD_GAIN_BOUNDARY_DEFAULT;
  580. i++;
  581. }
  582. while (k < AR5416_NUM_PDADC_VALUES) {
  583. pPDADCValues[k] = pPDADCValues[k - 1];
  584. k++;
  585. }
  586. return;
  587. #undef TMP_VAL_VPD_TABLE
  588. }
  589. static void ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah,
  590. struct ath9k_channel *chan,
  591. int16_t *pTxPowerIndexOffset)
  592. {
  593. struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
  594. struct cal_data_per_freq_4k *pRawDataset;
  595. u8 *pCalBChans = NULL;
  596. u16 pdGainOverlap_t2;
  597. static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
  598. u16 gainBoundaries[AR5416_EEP4K_PD_GAINS_IN_MASK];
  599. u16 numPiers, i, j;
  600. int16_t tMinCalPower;
  601. u16 numXpdGain, xpdMask;
  602. u16 xpdGainValues[AR5416_EEP4K_NUM_PD_GAINS] = { 0, 0 };
  603. u32 reg32, regOffset, regChainOffset;
  604. xpdMask = pEepData->modalHeader.xpdGain;
  605. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  606. AR5416_EEP_MINOR_VER_2) {
  607. pdGainOverlap_t2 =
  608. pEepData->modalHeader.pdGainOverlap;
  609. } else {
  610. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  611. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  612. }
  613. pCalBChans = pEepData->calFreqPier2G;
  614. numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS;
  615. numXpdGain = 0;
  616. for (i = 1; i <= AR5416_EEP4K_PD_GAINS_IN_MASK; i++) {
  617. if ((xpdMask >> (AR5416_EEP4K_PD_GAINS_IN_MASK - i)) & 1) {
  618. if (numXpdGain >= AR5416_EEP4K_NUM_PD_GAINS)
  619. break;
  620. xpdGainValues[numXpdGain] =
  621. (u16)(AR5416_EEP4K_PD_GAINS_IN_MASK - i);
  622. numXpdGain++;
  623. }
  624. }
  625. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  626. (numXpdGain - 1) & 0x3);
  627. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  628. xpdGainValues[0]);
  629. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  630. xpdGainValues[1]);
  631. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, 0);
  632. for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
  633. if (AR_SREV_5416_20_OR_LATER(ah) &&
  634. (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
  635. (i != 0)) {
  636. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  637. } else
  638. regChainOffset = i * 0x1000;
  639. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  640. pRawDataset = pEepData->calPierData2G[i];
  641. ath9k_hw_get_4k_gain_boundaries_pdadcs(ah, chan,
  642. pRawDataset, pCalBChans,
  643. numPiers, pdGainOverlap_t2,
  644. &tMinCalPower, gainBoundaries,
  645. pdadcValues, numXpdGain);
  646. if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
  647. REG_WRITE(ah, AR_PHY_TPCRG5 + regChainOffset,
  648. SM(pdGainOverlap_t2,
  649. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
  650. | SM(gainBoundaries[0],
  651. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
  652. | SM(gainBoundaries[1],
  653. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
  654. | SM(gainBoundaries[2],
  655. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
  656. | SM(gainBoundaries[3],
  657. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
  658. }
  659. regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
  660. for (j = 0; j < 32; j++) {
  661. reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
  662. ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
  663. ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
  664. ((pdadcValues[4 * j + 3] & 0xFF) << 24);
  665. REG_WRITE(ah, regOffset, reg32);
  666. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  667. "PDADC (%d,%4x): %4.4x %8.8x\n",
  668. i, regChainOffset, regOffset,
  669. reg32);
  670. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  671. "PDADC: Chain %d | "
  672. "PDADC %3d Value %3d | "
  673. "PDADC %3d Value %3d | "
  674. "PDADC %3d Value %3d | "
  675. "PDADC %3d Value %3d |\n",
  676. i, 4 * j, pdadcValues[4 * j],
  677. 4 * j + 1, pdadcValues[4 * j + 1],
  678. 4 * j + 2, pdadcValues[4 * j + 2],
  679. 4 * j + 3,
  680. pdadcValues[4 * j + 3]);
  681. regOffset += 4;
  682. }
  683. }
  684. }
  685. *pTxPowerIndexOffset = 0;
  686. }
  687. static void ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
  688. struct ath9k_channel *chan,
  689. int16_t *ratesArray,
  690. u16 cfgCtl,
  691. u16 AntennaReduction,
  692. u16 twiceMaxRegulatoryPower,
  693. u16 powerLimit)
  694. {
  695. struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
  696. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  697. static const u16 tpScaleReductionTable[5] =
  698. { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
  699. int i;
  700. int16_t twiceLargestAntenna;
  701. struct cal_ctl_data_4k *rep;
  702. struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
  703. 0, { 0, 0, 0, 0}
  704. };
  705. struct cal_target_power_leg targetPowerOfdmExt = {
  706. 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
  707. 0, { 0, 0, 0, 0 }
  708. };
  709. struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
  710. 0, {0, 0, 0, 0}
  711. };
  712. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  713. u16 ctlModesFor11g[] =
  714. { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
  715. CTL_2GHT40
  716. };
  717. u16 numCtlModes, *pCtlMode, ctlMode, freq;
  718. struct chan_centers centers;
  719. int tx_chainmask;
  720. u16 twiceMinEdgePower;
  721. tx_chainmask = ah->txchainmask;
  722. ath9k_hw_get_channel_centers(ah, chan, &centers);
  723. twiceLargestAntenna = pEepData->modalHeader.antennaGainCh[0];
  724. twiceLargestAntenna = (int16_t)min(AntennaReduction -
  725. twiceLargestAntenna, 0);
  726. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  727. if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) {
  728. maxRegAllowedPower -=
  729. (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2);
  730. }
  731. scaledPower = min(powerLimit, maxRegAllowedPower);
  732. scaledPower = max((u16)0, scaledPower);
  733. numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
  734. pCtlMode = ctlModesFor11g;
  735. ath9k_hw_get_legacy_target_powers(ah, chan,
  736. pEepData->calTargetPowerCck,
  737. AR5416_NUM_2G_CCK_TARGET_POWERS,
  738. &targetPowerCck, 4, false);
  739. ath9k_hw_get_legacy_target_powers(ah, chan,
  740. pEepData->calTargetPower2G,
  741. AR5416_NUM_2G_20_TARGET_POWERS,
  742. &targetPowerOfdm, 4, false);
  743. ath9k_hw_get_target_powers(ah, chan,
  744. pEepData->calTargetPower2GHT20,
  745. AR5416_NUM_2G_20_TARGET_POWERS,
  746. &targetPowerHt20, 8, false);
  747. if (IS_CHAN_HT40(chan)) {
  748. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  749. ath9k_hw_get_target_powers(ah, chan,
  750. pEepData->calTargetPower2GHT40,
  751. AR5416_NUM_2G_40_TARGET_POWERS,
  752. &targetPowerHt40, 8, true);
  753. ath9k_hw_get_legacy_target_powers(ah, chan,
  754. pEepData->calTargetPowerCck,
  755. AR5416_NUM_2G_CCK_TARGET_POWERS,
  756. &targetPowerCckExt, 4, true);
  757. ath9k_hw_get_legacy_target_powers(ah, chan,
  758. pEepData->calTargetPower2G,
  759. AR5416_NUM_2G_20_TARGET_POWERS,
  760. &targetPowerOfdmExt, 4, true);
  761. }
  762. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  763. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  764. (pCtlMode[ctlMode] == CTL_2GHT40);
  765. if (isHt40CtlMode)
  766. freq = centers.synth_center;
  767. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  768. freq = centers.ext_center;
  769. else
  770. freq = centers.ctl_center;
  771. if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
  772. ah->eep_ops->get_eeprom_rev(ah) <= 2)
  773. twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  774. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  775. "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
  776. "EXT_ADDITIVE %d\n",
  777. ctlMode, numCtlModes, isHt40CtlMode,
  778. (pCtlMode[ctlMode] & EXT_ADDITIVE));
  779. for (i = 0; (i < AR5416_NUM_CTLS) &&
  780. pEepData->ctlIndex[i]; i++) {
  781. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  782. " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
  783. "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
  784. "chan %d\n",
  785. i, cfgCtl, pCtlMode[ctlMode],
  786. pEepData->ctlIndex[i], chan->channel);
  787. if ((((cfgCtl & ~CTL_MODE_M) |
  788. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  789. pEepData->ctlIndex[i]) ||
  790. (((cfgCtl & ~CTL_MODE_M) |
  791. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  792. ((pEepData->ctlIndex[i] & CTL_MODE_M) |
  793. SD_NO_CTL))) {
  794. rep = &(pEepData->ctlData[i]);
  795. twiceMinEdgePower =
  796. ath9k_hw_get_max_edge_power(freq,
  797. rep->ctlEdges[ar5416_get_ntxchains
  798. (tx_chainmask) - 1],
  799. IS_CHAN_2GHZ(chan),
  800. AR5416_EEP4K_NUM_BAND_EDGES);
  801. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  802. " MATCH-EE_IDX %d: ch %d is2 %d "
  803. "2xMinEdge %d chainmask %d chains %d\n",
  804. i, freq, IS_CHAN_2GHZ(chan),
  805. twiceMinEdgePower, tx_chainmask,
  806. ar5416_get_ntxchains
  807. (tx_chainmask));
  808. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  809. twiceMaxEdgePower =
  810. min(twiceMaxEdgePower,
  811. twiceMinEdgePower);
  812. } else {
  813. twiceMaxEdgePower = twiceMinEdgePower;
  814. break;
  815. }
  816. }
  817. }
  818. minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
  819. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  820. " SEL-Min ctlMode %d pCtlMode %d "
  821. "2xMaxEdge %d sP %d minCtlPwr %d\n",
  822. ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
  823. scaledPower, minCtlPower);
  824. switch (pCtlMode[ctlMode]) {
  825. case CTL_11B:
  826. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x);
  827. i++) {
  828. targetPowerCck.tPow2x[i] =
  829. min((u16)targetPowerCck.tPow2x[i],
  830. minCtlPower);
  831. }
  832. break;
  833. case CTL_11G:
  834. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x);
  835. i++) {
  836. targetPowerOfdm.tPow2x[i] =
  837. min((u16)targetPowerOfdm.tPow2x[i],
  838. minCtlPower);
  839. }
  840. break;
  841. case CTL_2GHT20:
  842. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x);
  843. i++) {
  844. targetPowerHt20.tPow2x[i] =
  845. min((u16)targetPowerHt20.tPow2x[i],
  846. minCtlPower);
  847. }
  848. break;
  849. case CTL_11B_EXT:
  850. targetPowerCckExt.tPow2x[0] = min((u16)
  851. targetPowerCckExt.tPow2x[0],
  852. minCtlPower);
  853. break;
  854. case CTL_11G_EXT:
  855. targetPowerOfdmExt.tPow2x[0] = min((u16)
  856. targetPowerOfdmExt.tPow2x[0],
  857. minCtlPower);
  858. break;
  859. case CTL_2GHT40:
  860. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x);
  861. i++) {
  862. targetPowerHt40.tPow2x[i] =
  863. min((u16)targetPowerHt40.tPow2x[i],
  864. minCtlPower);
  865. }
  866. break;
  867. default:
  868. break;
  869. }
  870. }
  871. ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
  872. ratesArray[rate18mb] = ratesArray[rate24mb] =
  873. targetPowerOfdm.tPow2x[0];
  874. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  875. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  876. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  877. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  878. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  879. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  880. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  881. ratesArray[rate2s] = ratesArray[rate2l] = targetPowerCck.tPow2x[1];
  882. ratesArray[rate5_5s] = ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
  883. ratesArray[rate11s] = ratesArray[rate11l] = targetPowerCck.tPow2x[3];
  884. if (IS_CHAN_HT40(chan)) {
  885. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  886. ratesArray[rateHt40_0 + i] =
  887. targetPowerHt40.tPow2x[i];
  888. }
  889. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  890. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  891. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  892. ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
  893. }
  894. }
  895. static void ath9k_hw_4k_set_txpower(struct ath_hw *ah,
  896. struct ath9k_channel *chan,
  897. u16 cfgCtl,
  898. u8 twiceAntennaReduction,
  899. u8 twiceMaxRegulatoryPower,
  900. u8 powerLimit)
  901. {
  902. struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
  903. struct modal_eep_4k_header *pModal = &pEepData->modalHeader;
  904. int16_t ratesArray[Ar5416RateSize];
  905. int16_t txPowerIndexOffset = 0;
  906. u8 ht40PowerIncForPdadc = 2;
  907. int i;
  908. memset(ratesArray, 0, sizeof(ratesArray));
  909. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  910. AR5416_EEP_MINOR_VER_2) {
  911. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  912. }
  913. ath9k_hw_set_4k_power_per_rate_table(ah, chan,
  914. &ratesArray[0], cfgCtl,
  915. twiceAntennaReduction,
  916. twiceMaxRegulatoryPower,
  917. powerLimit);
  918. ath9k_hw_set_4k_power_cal_table(ah, chan, &txPowerIndexOffset);
  919. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  920. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  921. if (ratesArray[i] > AR5416_MAX_RATE_POWER)
  922. ratesArray[i] = AR5416_MAX_RATE_POWER;
  923. }
  924. if (AR_SREV_9280_10_OR_LATER(ah)) {
  925. for (i = 0; i < Ar5416RateSize; i++)
  926. ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
  927. }
  928. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  929. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  930. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  931. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  932. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  933. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  934. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  935. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  936. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  937. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  938. if (IS_CHAN_2GHZ(chan)) {
  939. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  940. ATH9K_POW_SM(ratesArray[rate2s], 24)
  941. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  942. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  943. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  944. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  945. ATH9K_POW_SM(ratesArray[rate11s], 24)
  946. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  947. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  948. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  949. }
  950. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  951. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  952. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  953. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  954. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  955. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  956. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  957. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  958. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  959. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  960. if (IS_CHAN_HT40(chan)) {
  961. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  962. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  963. ht40PowerIncForPdadc, 24)
  964. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  965. ht40PowerIncForPdadc, 16)
  966. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  967. ht40PowerIncForPdadc, 8)
  968. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  969. ht40PowerIncForPdadc, 0));
  970. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  971. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  972. ht40PowerIncForPdadc, 24)
  973. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  974. ht40PowerIncForPdadc, 16)
  975. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  976. ht40PowerIncForPdadc, 8)
  977. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  978. ht40PowerIncForPdadc, 0));
  979. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  980. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  981. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  982. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  983. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  984. }
  985. i = rate6mb;
  986. if (IS_CHAN_HT40(chan))
  987. i = rateHt40_0;
  988. else if (IS_CHAN_HT20(chan))
  989. i = rateHt20_0;
  990. if (AR_SREV_9280_10_OR_LATER(ah))
  991. ah->regulatory.max_power_level =
  992. ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
  993. else
  994. ah->regulatory.max_power_level = ratesArray[i];
  995. }
  996. static void ath9k_hw_4k_set_addac(struct ath_hw *ah,
  997. struct ath9k_channel *chan)
  998. {
  999. struct modal_eep_4k_header *pModal;
  1000. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  1001. u8 biaslevel;
  1002. if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
  1003. return;
  1004. if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
  1005. return;
  1006. pModal = &eep->modalHeader;
  1007. if (pModal->xpaBiasLvl != 0xff) {
  1008. biaslevel = pModal->xpaBiasLvl;
  1009. INI_RA(&ah->iniAddac, 7, 1) =
  1010. (INI_RA(&ah->iniAddac, 7, 1) & (~0x18)) | biaslevel << 3;
  1011. }
  1012. }
  1013. static void ath9k_hw_4k_set_gain(struct ath_hw *ah,
  1014. struct modal_eep_4k_header *pModal,
  1015. struct ar5416_eeprom_4k *eep,
  1016. u8 txRxAttenLocal, int regChainOffset)
  1017. {
  1018. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  1019. pModal->antCtrlChain[0]);
  1020. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  1021. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
  1022. ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  1023. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  1024. SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  1025. SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  1026. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1027. AR5416_EEP_MINOR_VER_3) {
  1028. txRxAttenLocal = pModal->txRxAttenCh[0];
  1029. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1030. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]);
  1031. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1032. AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
  1033. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1034. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  1035. pModal->xatten2Margin[0]);
  1036. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1037. AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]);
  1038. }
  1039. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  1040. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  1041. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  1042. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
  1043. if (AR_SREV_9285_11(ah))
  1044. REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14));
  1045. }
  1046. static void ath9k_hw_4k_set_board_values(struct ath_hw *ah,
  1047. struct ath9k_channel *chan)
  1048. {
  1049. struct modal_eep_4k_header *pModal;
  1050. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  1051. u8 txRxAttenLocal;
  1052. u8 ob[5], db1[5], db2[5];
  1053. u8 ant_div_control1, ant_div_control2;
  1054. u32 regVal;
  1055. pModal = &eep->modalHeader;
  1056. txRxAttenLocal = 23;
  1057. REG_WRITE(ah, AR_PHY_SWITCH_COM,
  1058. ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
  1059. /* Single chain for 4K EEPROM*/
  1060. ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal, 0);
  1061. /* Initialize Ant Diversity settings from EEPROM */
  1062. if (pModal->version == 3) {
  1063. ant_div_control1 = ((pModal->ob_234 >> 12) & 0xf);
  1064. ant_div_control2 = ((pModal->db1_234 >> 12) & 0xf);
  1065. regVal = REG_READ(ah, 0x99ac);
  1066. regVal &= (~(0x7f000000));
  1067. regVal |= ((ant_div_control1 & 0x1) << 24);
  1068. regVal |= (((ant_div_control1 >> 1) & 0x1) << 29);
  1069. regVal |= (((ant_div_control1 >> 2) & 0x1) << 30);
  1070. regVal |= ((ant_div_control2 & 0x3) << 25);
  1071. regVal |= (((ant_div_control2 >> 2) & 0x3) << 27);
  1072. REG_WRITE(ah, 0x99ac, regVal);
  1073. regVal = REG_READ(ah, 0x99ac);
  1074. regVal = REG_READ(ah, 0xa208);
  1075. regVal &= (~(0x1 << 13));
  1076. regVal |= (((ant_div_control1 >> 3) & 0x1) << 13);
  1077. REG_WRITE(ah, 0xa208, regVal);
  1078. regVal = REG_READ(ah, 0xa208);
  1079. }
  1080. if (pModal->version >= 2) {
  1081. ob[0] = (pModal->ob_01 & 0xf);
  1082. ob[1] = (pModal->ob_01 >> 4) & 0xf;
  1083. ob[2] = (pModal->ob_234 & 0xf);
  1084. ob[3] = ((pModal->ob_234 >> 4) & 0xf);
  1085. ob[4] = ((pModal->ob_234 >> 8) & 0xf);
  1086. db1[0] = (pModal->db1_01 & 0xf);
  1087. db1[1] = ((pModal->db1_01 >> 4) & 0xf);
  1088. db1[2] = (pModal->db1_234 & 0xf);
  1089. db1[3] = ((pModal->db1_234 >> 4) & 0xf);
  1090. db1[4] = ((pModal->db1_234 >> 8) & 0xf);
  1091. db2[0] = (pModal->db2_01 & 0xf);
  1092. db2[1] = ((pModal->db2_01 >> 4) & 0xf);
  1093. db2[2] = (pModal->db2_234 & 0xf);
  1094. db2[3] = ((pModal->db2_234 >> 4) & 0xf);
  1095. db2[4] = ((pModal->db2_234 >> 8) & 0xf);
  1096. } else if (pModal->version == 1) {
  1097. ob[0] = (pModal->ob_01 & 0xf);
  1098. ob[1] = ob[2] = ob[3] = ob[4] = (pModal->ob_01 >> 4) & 0xf;
  1099. db1[0] = (pModal->db1_01 & 0xf);
  1100. db1[1] = db1[2] = db1[3] =
  1101. db1[4] = ((pModal->db1_01 >> 4) & 0xf);
  1102. db2[0] = (pModal->db2_01 & 0xf);
  1103. db2[1] = db2[2] = db2[3] =
  1104. db2[4] = ((pModal->db2_01 >> 4) & 0xf);
  1105. } else {
  1106. int i;
  1107. for (i = 0; i < 5; i++) {
  1108. ob[i] = pModal->ob_01;
  1109. db1[i] = pModal->db1_01;
  1110. db2[i] = pModal->db1_01;
  1111. }
  1112. }
  1113. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1114. AR9285_AN_RF2G3_OB_0, AR9285_AN_RF2G3_OB_0_S, ob[0]);
  1115. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1116. AR9285_AN_RF2G3_OB_1, AR9285_AN_RF2G3_OB_1_S, ob[1]);
  1117. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1118. AR9285_AN_RF2G3_OB_2, AR9285_AN_RF2G3_OB_2_S, ob[2]);
  1119. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1120. AR9285_AN_RF2G3_OB_3, AR9285_AN_RF2G3_OB_3_S, ob[3]);
  1121. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1122. AR9285_AN_RF2G3_OB_4, AR9285_AN_RF2G3_OB_4_S, ob[4]);
  1123. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1124. AR9285_AN_RF2G3_DB1_0, AR9285_AN_RF2G3_DB1_0_S, db1[0]);
  1125. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1126. AR9285_AN_RF2G3_DB1_1, AR9285_AN_RF2G3_DB1_1_S, db1[1]);
  1127. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1128. AR9285_AN_RF2G3_DB1_2, AR9285_AN_RF2G3_DB1_2_S, db1[2]);
  1129. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1130. AR9285_AN_RF2G4_DB1_3, AR9285_AN_RF2G4_DB1_3_S, db1[3]);
  1131. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1132. AR9285_AN_RF2G4_DB1_4, AR9285_AN_RF2G4_DB1_4_S, db1[4]);
  1133. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1134. AR9285_AN_RF2G4_DB2_0, AR9285_AN_RF2G4_DB2_0_S, db2[0]);
  1135. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1136. AR9285_AN_RF2G4_DB2_1, AR9285_AN_RF2G4_DB2_1_S, db2[1]);
  1137. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1138. AR9285_AN_RF2G4_DB2_2, AR9285_AN_RF2G4_DB2_2_S, db2[2]);
  1139. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1140. AR9285_AN_RF2G4_DB2_3, AR9285_AN_RF2G4_DB2_3_S, db2[3]);
  1141. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1142. AR9285_AN_RF2G4_DB2_4, AR9285_AN_RF2G4_DB2_4_S, db2[4]);
  1143. if (AR_SREV_9285_11(ah))
  1144. REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT);
  1145. REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
  1146. pModal->switchSettling);
  1147. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
  1148. pModal->adcDesiredSize);
  1149. REG_WRITE(ah, AR_PHY_RF_CTL4,
  1150. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
  1151. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
  1152. SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
  1153. SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  1154. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  1155. pModal->txEndToRxOn);
  1156. REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
  1157. pModal->thresh62);
  1158. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
  1159. pModal->thresh62);
  1160. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1161. AR5416_EEP_MINOR_VER_2) {
  1162. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
  1163. pModal->txFrameToDataStart);
  1164. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
  1165. pModal->txFrameToPaOn);
  1166. }
  1167. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1168. AR5416_EEP_MINOR_VER_3) {
  1169. if (IS_CHAN_HT40(chan))
  1170. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  1171. AR_PHY_SETTLING_SWITCH,
  1172. pModal->swSettleHt40);
  1173. }
  1174. }
  1175. static u16 ath9k_hw_4k_get_eeprom_antenna_cfg(struct ath_hw *ah,
  1176. struct ath9k_channel *chan)
  1177. {
  1178. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  1179. struct modal_eep_4k_header *pModal = &eep->modalHeader;
  1180. return pModal->antCtrlCommon & 0xFFFF;
  1181. }
  1182. static u8 ath9k_hw_4k_get_num_ant_config(struct ath_hw *ah,
  1183. enum ieee80211_band freq_band)
  1184. {
  1185. return 1;
  1186. }
  1187. static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
  1188. {
  1189. #define EEP_MAP4K_SPURCHAN \
  1190. (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan)
  1191. u16 spur_val = AR_NO_SPUR;
  1192. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  1193. "Getting spur idx %d is2Ghz. %d val %x\n",
  1194. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  1195. switch (ah->config.spurmode) {
  1196. case SPUR_DISABLE:
  1197. break;
  1198. case SPUR_ENABLE_IOCTL:
  1199. spur_val = ah->config.spurchans[i][is2GHz];
  1200. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  1201. "Getting spur val from new loc. %d\n", spur_val);
  1202. break;
  1203. case SPUR_ENABLE_EEPROM:
  1204. spur_val = EEP_MAP4K_SPURCHAN;
  1205. break;
  1206. }
  1207. return spur_val;
  1208. #undef EEP_MAP4K_SPURCHAN
  1209. }
  1210. static struct eeprom_ops eep_4k_ops = {
  1211. .check_eeprom = ath9k_hw_4k_check_eeprom,
  1212. .get_eeprom = ath9k_hw_4k_get_eeprom,
  1213. .fill_eeprom = ath9k_hw_4k_fill_eeprom,
  1214. .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver,
  1215. .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev,
  1216. .get_num_ant_config = ath9k_hw_4k_get_num_ant_config,
  1217. .get_eeprom_antenna_cfg = ath9k_hw_4k_get_eeprom_antenna_cfg,
  1218. .set_board_values = ath9k_hw_4k_set_board_values,
  1219. .set_addac = ath9k_hw_4k_set_addac,
  1220. .set_txpower = ath9k_hw_4k_set_txpower,
  1221. .get_spur_channel = ath9k_hw_4k_get_spur_channel
  1222. };
  1223. /************************************************/
  1224. /* EEPROM Operations for non-4K (Default) cards */
  1225. /************************************************/
  1226. static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
  1227. {
  1228. return ((ah->eeprom.def.baseEepHeader.version >> 12) & 0xF);
  1229. }
  1230. static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
  1231. {
  1232. return ((ah->eeprom.def.baseEepHeader.version) & 0xFFF);
  1233. }
  1234. static bool ath9k_hw_def_fill_eeprom(struct ath_hw *ah)
  1235. {
  1236. #define SIZE_EEPROM_DEF (sizeof(struct ar5416_eeprom_def) / sizeof(u16))
  1237. u16 *eep_data = (u16 *)&ah->eeprom.def;
  1238. int addr, ar5416_eep_start_loc = 0x100;
  1239. for (addr = 0; addr < SIZE_EEPROM_DEF; addr++) {
  1240. if (!ath9k_hw_nvram_read(ah, addr + ar5416_eep_start_loc,
  1241. eep_data)) {
  1242. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  1243. "Unable to read eeprom region\n");
  1244. return false;
  1245. }
  1246. eep_data++;
  1247. }
  1248. return true;
  1249. #undef SIZE_EEPROM_DEF
  1250. }
  1251. static int ath9k_hw_def_check_eeprom(struct ath_hw *ah)
  1252. {
  1253. struct ar5416_eeprom_def *eep =
  1254. (struct ar5416_eeprom_def *) &ah->eeprom.def;
  1255. u16 *eepdata, temp, magic, magic2;
  1256. u32 sum = 0, el;
  1257. bool need_swap = false;
  1258. int i, addr, size;
  1259. if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
  1260. DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Reading Magic # failed\n");
  1261. return false;
  1262. }
  1263. if (!ath9k_hw_use_flash(ah)) {
  1264. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1265. "Read Magic = 0x%04X\n", magic);
  1266. if (magic != AR5416_EEPROM_MAGIC) {
  1267. magic2 = swab16(magic);
  1268. if (magic2 == AR5416_EEPROM_MAGIC) {
  1269. size = sizeof(struct ar5416_eeprom_def);
  1270. need_swap = true;
  1271. eepdata = (u16 *) (&ah->eeprom);
  1272. for (addr = 0; addr < size / sizeof(u16); addr++) {
  1273. temp = swab16(*eepdata);
  1274. *eepdata = temp;
  1275. eepdata++;
  1276. }
  1277. } else {
  1278. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  1279. "Invalid EEPROM Magic. "
  1280. "Endianness mismatch.\n");
  1281. return -EINVAL;
  1282. }
  1283. }
  1284. }
  1285. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
  1286. need_swap ? "True" : "False");
  1287. if (need_swap)
  1288. el = swab16(ah->eeprom.def.baseEepHeader.length);
  1289. else
  1290. el = ah->eeprom.def.baseEepHeader.length;
  1291. if (el > sizeof(struct ar5416_eeprom_def))
  1292. el = sizeof(struct ar5416_eeprom_def) / sizeof(u16);
  1293. else
  1294. el = el / sizeof(u16);
  1295. eepdata = (u16 *)(&ah->eeprom);
  1296. for (i = 0; i < el; i++)
  1297. sum ^= *eepdata++;
  1298. if (need_swap) {
  1299. u32 integer, j;
  1300. u16 word;
  1301. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1302. "EEPROM Endianness is not native.. Changing.\n");
  1303. word = swab16(eep->baseEepHeader.length);
  1304. eep->baseEepHeader.length = word;
  1305. word = swab16(eep->baseEepHeader.checksum);
  1306. eep->baseEepHeader.checksum = word;
  1307. word = swab16(eep->baseEepHeader.version);
  1308. eep->baseEepHeader.version = word;
  1309. word = swab16(eep->baseEepHeader.regDmn[0]);
  1310. eep->baseEepHeader.regDmn[0] = word;
  1311. word = swab16(eep->baseEepHeader.regDmn[1]);
  1312. eep->baseEepHeader.regDmn[1] = word;
  1313. word = swab16(eep->baseEepHeader.rfSilent);
  1314. eep->baseEepHeader.rfSilent = word;
  1315. word = swab16(eep->baseEepHeader.blueToothOptions);
  1316. eep->baseEepHeader.blueToothOptions = word;
  1317. word = swab16(eep->baseEepHeader.deviceCap);
  1318. eep->baseEepHeader.deviceCap = word;
  1319. for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
  1320. struct modal_eep_header *pModal =
  1321. &eep->modalHeader[j];
  1322. integer = swab32(pModal->antCtrlCommon);
  1323. pModal->antCtrlCommon = integer;
  1324. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  1325. integer = swab32(pModal->antCtrlChain[i]);
  1326. pModal->antCtrlChain[i] = integer;
  1327. }
  1328. for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
  1329. word = swab16(pModal->spurChans[i].spurChan);
  1330. pModal->spurChans[i].spurChan = word;
  1331. }
  1332. }
  1333. }
  1334. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
  1335. ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  1336. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  1337. "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  1338. sum, ah->eep_ops->get_eeprom_ver(ah));
  1339. return -EINVAL;
  1340. }
  1341. return 0;
  1342. }
  1343. static u32 ath9k_hw_def_get_eeprom(struct ath_hw *ah,
  1344. enum eeprom_param param)
  1345. {
  1346. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  1347. struct modal_eep_header *pModal = eep->modalHeader;
  1348. struct base_eep_header *pBase = &eep->baseEepHeader;
  1349. switch (param) {
  1350. case EEP_NFTHRESH_5:
  1351. return pModal[0].noiseFloorThreshCh[0];
  1352. case EEP_NFTHRESH_2:
  1353. return pModal[1].noiseFloorThreshCh[0];
  1354. case AR_EEPROM_MAC(0):
  1355. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  1356. case AR_EEPROM_MAC(1):
  1357. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  1358. case AR_EEPROM_MAC(2):
  1359. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  1360. case EEP_REG_0:
  1361. return pBase->regDmn[0];
  1362. case EEP_REG_1:
  1363. return pBase->regDmn[1];
  1364. case EEP_OP_CAP:
  1365. return pBase->deviceCap;
  1366. case EEP_OP_MODE:
  1367. return pBase->opCapFlags;
  1368. case EEP_RF_SILENT:
  1369. return pBase->rfSilent;
  1370. case EEP_OB_5:
  1371. return pModal[0].ob;
  1372. case EEP_DB_5:
  1373. return pModal[0].db;
  1374. case EEP_OB_2:
  1375. return pModal[1].ob;
  1376. case EEP_DB_2:
  1377. return pModal[1].db;
  1378. case EEP_MINOR_REV:
  1379. return AR5416_VER_MASK;
  1380. case EEP_TX_MASK:
  1381. return pBase->txMask;
  1382. case EEP_RX_MASK:
  1383. return pBase->rxMask;
  1384. case EEP_RXGAIN_TYPE:
  1385. return pBase->rxGainType;
  1386. case EEP_TXGAIN_TYPE:
  1387. return pBase->txGainType;
  1388. case EEP_OL_PWRCTRL:
  1389. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  1390. return pBase->openLoopPwrCntl ? true : false;
  1391. else
  1392. return false;
  1393. case EEP_RC_CHAIN_MASK:
  1394. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  1395. return pBase->rcChainMask;
  1396. else
  1397. return 0;
  1398. case EEP_DAC_HPWR_5G:
  1399. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
  1400. return pBase->dacHiPwrMode_5G;
  1401. else
  1402. return 0;
  1403. case EEP_FRAC_N_5G:
  1404. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
  1405. return pBase->frac_n_5g;
  1406. else
  1407. return 0;
  1408. default:
  1409. return 0;
  1410. }
  1411. }
  1412. static void ath9k_hw_def_set_gain(struct ath_hw *ah,
  1413. struct modal_eep_header *pModal,
  1414. struct ar5416_eeprom_def *eep,
  1415. u8 txRxAttenLocal, int regChainOffset, int i)
  1416. {
  1417. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
  1418. txRxAttenLocal = pModal->txRxAttenCh[i];
  1419. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1420. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1421. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  1422. pModal->bswMargin[i]);
  1423. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1424. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  1425. pModal->bswAtten[i]);
  1426. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1427. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  1428. pModal->xatten2Margin[i]);
  1429. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1430. AR_PHY_GAIN_2GHZ_XATTEN2_DB,
  1431. pModal->xatten2Db[i]);
  1432. } else {
  1433. REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1434. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  1435. ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
  1436. | SM(pModal-> bswMargin[i],
  1437. AR_PHY_GAIN_2GHZ_BSW_MARGIN));
  1438. REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1439. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  1440. ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
  1441. | SM(pModal->bswAtten[i],
  1442. AR_PHY_GAIN_2GHZ_BSW_ATTEN));
  1443. }
  1444. }
  1445. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1446. REG_RMW_FIELD(ah,
  1447. AR_PHY_RXGAIN + regChainOffset,
  1448. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  1449. REG_RMW_FIELD(ah,
  1450. AR_PHY_RXGAIN + regChainOffset,
  1451. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[i]);
  1452. } else {
  1453. REG_WRITE(ah,
  1454. AR_PHY_RXGAIN + regChainOffset,
  1455. (REG_READ(ah, AR_PHY_RXGAIN + regChainOffset) &
  1456. ~AR_PHY_RXGAIN_TXRX_ATTEN)
  1457. | SM(txRxAttenLocal, AR_PHY_RXGAIN_TXRX_ATTEN));
  1458. REG_WRITE(ah,
  1459. AR_PHY_GAIN_2GHZ + regChainOffset,
  1460. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  1461. ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
  1462. SM(pModal->rxTxMarginCh[i], AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
  1463. }
  1464. }
  1465. static void ath9k_hw_def_set_board_values(struct ath_hw *ah,
  1466. struct ath9k_channel *chan)
  1467. {
  1468. struct modal_eep_header *pModal;
  1469. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  1470. int i, regChainOffset;
  1471. u8 txRxAttenLocal;
  1472. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  1473. txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
  1474. REG_WRITE(ah, AR_PHY_SWITCH_COM,
  1475. ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
  1476. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  1477. if (AR_SREV_9280(ah)) {
  1478. if (i >= 2)
  1479. break;
  1480. }
  1481. if (AR_SREV_5416_20_OR_LATER(ah) &&
  1482. (ah->rxchainmask == 5 || ah->txchainmask == 5) && (i != 0))
  1483. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  1484. else
  1485. regChainOffset = i * 0x1000;
  1486. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  1487. pModal->antCtrlChain[i]);
  1488. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  1489. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
  1490. ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  1491. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  1492. SM(pModal->iqCalICh[i],
  1493. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  1494. SM(pModal->iqCalQCh[i],
  1495. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  1496. if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah))
  1497. ath9k_hw_def_set_gain(ah, pModal, eep, txRxAttenLocal,
  1498. regChainOffset, i);
  1499. }
  1500. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1501. if (IS_CHAN_2GHZ(chan)) {
  1502. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  1503. AR_AN_RF2G1_CH0_OB,
  1504. AR_AN_RF2G1_CH0_OB_S,
  1505. pModal->ob);
  1506. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  1507. AR_AN_RF2G1_CH0_DB,
  1508. AR_AN_RF2G1_CH0_DB_S,
  1509. pModal->db);
  1510. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  1511. AR_AN_RF2G1_CH1_OB,
  1512. AR_AN_RF2G1_CH1_OB_S,
  1513. pModal->ob_ch1);
  1514. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  1515. AR_AN_RF2G1_CH1_DB,
  1516. AR_AN_RF2G1_CH1_DB_S,
  1517. pModal->db_ch1);
  1518. } else {
  1519. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  1520. AR_AN_RF5G1_CH0_OB5,
  1521. AR_AN_RF5G1_CH0_OB5_S,
  1522. pModal->ob);
  1523. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  1524. AR_AN_RF5G1_CH0_DB5,
  1525. AR_AN_RF5G1_CH0_DB5_S,
  1526. pModal->db);
  1527. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  1528. AR_AN_RF5G1_CH1_OB5,
  1529. AR_AN_RF5G1_CH1_OB5_S,
  1530. pModal->ob_ch1);
  1531. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  1532. AR_AN_RF5G1_CH1_DB5,
  1533. AR_AN_RF5G1_CH1_DB5_S,
  1534. pModal->db_ch1);
  1535. }
  1536. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  1537. AR_AN_TOP2_XPABIAS_LVL,
  1538. AR_AN_TOP2_XPABIAS_LVL_S,
  1539. pModal->xpaBiasLvl);
  1540. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  1541. AR_AN_TOP2_LOCALBIAS,
  1542. AR_AN_TOP2_LOCALBIAS_S,
  1543. pModal->local_bias);
  1544. REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
  1545. pModal->force_xpaon);
  1546. }
  1547. REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
  1548. pModal->switchSettling);
  1549. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
  1550. pModal->adcDesiredSize);
  1551. if (!AR_SREV_9280_10_OR_LATER(ah))
  1552. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  1553. AR_PHY_DESIRED_SZ_PGA,
  1554. pModal->pgaDesiredSize);
  1555. REG_WRITE(ah, AR_PHY_RF_CTL4,
  1556. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  1557. | SM(pModal->txEndToXpaOff,
  1558. AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  1559. | SM(pModal->txFrameToXpaOn,
  1560. AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  1561. | SM(pModal->txFrameToXpaOn,
  1562. AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  1563. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  1564. pModal->txEndToRxOn);
  1565. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1566. REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
  1567. pModal->thresh62);
  1568. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  1569. AR_PHY_EXT_CCA0_THRESH62,
  1570. pModal->thresh62);
  1571. } else {
  1572. REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
  1573. pModal->thresh62);
  1574. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  1575. AR_PHY_EXT_CCA_THRESH62,
  1576. pModal->thresh62);
  1577. }
  1578. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
  1579. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  1580. AR_PHY_TX_END_DATA_START,
  1581. pModal->txFrameToDataStart);
  1582. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
  1583. pModal->txFrameToPaOn);
  1584. }
  1585. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
  1586. if (IS_CHAN_HT40(chan))
  1587. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  1588. AR_PHY_SETTLING_SWITCH,
  1589. pModal->swSettleHt40);
  1590. }
  1591. if (AR_SREV_9280_20_OR_LATER(ah) &&
  1592. AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  1593. REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL,
  1594. AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK,
  1595. pModal->miscBits);
  1596. if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) {
  1597. if (IS_CHAN_2GHZ(chan))
  1598. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
  1599. eep->baseEepHeader.dacLpMode);
  1600. else if (eep->baseEepHeader.dacHiPwrMode_5G)
  1601. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, 0);
  1602. else
  1603. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
  1604. eep->baseEepHeader.dacLpMode);
  1605. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, AR_PHY_FRAME_CTL_TX_CLIP,
  1606. pModal->miscBits >> 2);
  1607. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL9,
  1608. AR_PHY_TX_DESIRED_SCALE_CCK,
  1609. eep->baseEepHeader.desiredScaleCCK);
  1610. }
  1611. }
  1612. static void ath9k_hw_def_set_addac(struct ath_hw *ah,
  1613. struct ath9k_channel *chan)
  1614. {
  1615. #define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt])
  1616. struct modal_eep_header *pModal;
  1617. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  1618. u8 biaslevel;
  1619. if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
  1620. return;
  1621. if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
  1622. return;
  1623. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  1624. if (pModal->xpaBiasLvl != 0xff) {
  1625. biaslevel = pModal->xpaBiasLvl;
  1626. } else {
  1627. u16 resetFreqBin, freqBin, freqCount = 0;
  1628. struct chan_centers centers;
  1629. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1630. resetFreqBin = FREQ2FBIN(centers.synth_center,
  1631. IS_CHAN_2GHZ(chan));
  1632. freqBin = XPA_LVL_FREQ(0) & 0xff;
  1633. biaslevel = (u8) (XPA_LVL_FREQ(0) >> 14);
  1634. freqCount++;
  1635. while (freqCount < 3) {
  1636. if (XPA_LVL_FREQ(freqCount) == 0x0)
  1637. break;
  1638. freqBin = XPA_LVL_FREQ(freqCount) & 0xff;
  1639. if (resetFreqBin >= freqBin)
  1640. biaslevel = (u8)(XPA_LVL_FREQ(freqCount) >> 14);
  1641. else
  1642. break;
  1643. freqCount++;
  1644. }
  1645. }
  1646. if (IS_CHAN_2GHZ(chan)) {
  1647. INI_RA(&ah->iniAddac, 7, 1) = (INI_RA(&ah->iniAddac,
  1648. 7, 1) & (~0x18)) | biaslevel << 3;
  1649. } else {
  1650. INI_RA(&ah->iniAddac, 6, 1) = (INI_RA(&ah->iniAddac,
  1651. 6, 1) & (~0xc0)) | biaslevel << 6;
  1652. }
  1653. #undef XPA_LVL_FREQ
  1654. }
  1655. static void ath9k_hw_get_def_gain_boundaries_pdadcs(struct ath_hw *ah,
  1656. struct ath9k_channel *chan,
  1657. struct cal_data_per_freq *pRawDataSet,
  1658. u8 *bChans, u16 availPiers,
  1659. u16 tPdGainOverlap, int16_t *pMinCalPower,
  1660. u16 *pPdGainBoundaries, u8 *pPDADCValues,
  1661. u16 numXpdGains)
  1662. {
  1663. int i, j, k;
  1664. int16_t ss;
  1665. u16 idxL = 0, idxR = 0, numPiers;
  1666. static u8 vpdTableL[AR5416_NUM_PD_GAINS]
  1667. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  1668. static u8 vpdTableR[AR5416_NUM_PD_GAINS]
  1669. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  1670. static u8 vpdTableI[AR5416_NUM_PD_GAINS]
  1671. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  1672. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  1673. u8 minPwrT4[AR5416_NUM_PD_GAINS];
  1674. u8 maxPwrT4[AR5416_NUM_PD_GAINS];
  1675. int16_t vpdStep;
  1676. int16_t tmpVal;
  1677. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  1678. bool match;
  1679. int16_t minDelta = 0;
  1680. struct chan_centers centers;
  1681. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1682. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  1683. if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
  1684. break;
  1685. }
  1686. match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center,
  1687. IS_CHAN_2GHZ(chan)),
  1688. bChans, numPiers, &idxL, &idxR);
  1689. if (match) {
  1690. for (i = 0; i < numXpdGains; i++) {
  1691. minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
  1692. maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
  1693. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  1694. pRawDataSet[idxL].pwrPdg[i],
  1695. pRawDataSet[idxL].vpdPdg[i],
  1696. AR5416_PD_GAIN_ICEPTS,
  1697. vpdTableI[i]);
  1698. }
  1699. } else {
  1700. for (i = 0; i < numXpdGains; i++) {
  1701. pVpdL = pRawDataSet[idxL].vpdPdg[i];
  1702. pPwrL = pRawDataSet[idxL].pwrPdg[i];
  1703. pVpdR = pRawDataSet[idxR].vpdPdg[i];
  1704. pPwrR = pRawDataSet[idxR].pwrPdg[i];
  1705. minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
  1706. maxPwrT4[i] =
  1707. min(pPwrL[AR5416_PD_GAIN_ICEPTS - 1],
  1708. pPwrR[AR5416_PD_GAIN_ICEPTS - 1]);
  1709. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  1710. pPwrL, pVpdL,
  1711. AR5416_PD_GAIN_ICEPTS,
  1712. vpdTableL[i]);
  1713. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  1714. pPwrR, pVpdR,
  1715. AR5416_PD_GAIN_ICEPTS,
  1716. vpdTableR[i]);
  1717. for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
  1718. vpdTableI[i][j] =
  1719. (u8)(ath9k_hw_interpolate((u16)
  1720. FREQ2FBIN(centers.
  1721. synth_center,
  1722. IS_CHAN_2GHZ
  1723. (chan)),
  1724. bChans[idxL], bChans[idxR],
  1725. vpdTableL[i][j], vpdTableR[i][j]));
  1726. }
  1727. }
  1728. }
  1729. *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
  1730. k = 0;
  1731. for (i = 0; i < numXpdGains; i++) {
  1732. if (i == (numXpdGains - 1))
  1733. pPdGainBoundaries[i] =
  1734. (u16)(maxPwrT4[i] / 2);
  1735. else
  1736. pPdGainBoundaries[i] =
  1737. (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
  1738. pPdGainBoundaries[i] =
  1739. min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
  1740. if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
  1741. minDelta = pPdGainBoundaries[0] - 23;
  1742. pPdGainBoundaries[0] = 23;
  1743. } else {
  1744. minDelta = 0;
  1745. }
  1746. if (i == 0) {
  1747. if (AR_SREV_9280_10_OR_LATER(ah))
  1748. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  1749. else
  1750. ss = 0;
  1751. } else {
  1752. ss = (int16_t)((pPdGainBoundaries[i - 1] -
  1753. (minPwrT4[i] / 2)) -
  1754. tPdGainOverlap + 1 + minDelta);
  1755. }
  1756. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  1757. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  1758. while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  1759. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  1760. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  1761. ss++;
  1762. }
  1763. sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  1764. tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
  1765. (minPwrT4[i] / 2));
  1766. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  1767. tgtIndex : sizeCurrVpdTable;
  1768. while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  1769. pPDADCValues[k++] = vpdTableI[i][ss++];
  1770. }
  1771. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  1772. vpdTableI[i][sizeCurrVpdTable - 2]);
  1773. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  1774. if (tgtIndex > maxIndex) {
  1775. while ((ss <= tgtIndex) &&
  1776. (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  1777. tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] +
  1778. (ss - maxIndex + 1) * vpdStep));
  1779. pPDADCValues[k++] = (u8)((tmpVal > 255) ?
  1780. 255 : tmpVal);
  1781. ss++;
  1782. }
  1783. }
  1784. }
  1785. while (i < AR5416_PD_GAINS_IN_MASK) {
  1786. pPdGainBoundaries[i] = pPdGainBoundaries[i - 1];
  1787. i++;
  1788. }
  1789. while (k < AR5416_NUM_PDADC_VALUES) {
  1790. pPDADCValues[k] = pPDADCValues[k - 1];
  1791. k++;
  1792. }
  1793. return;
  1794. }
  1795. static void ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
  1796. struct ath9k_channel *chan,
  1797. int16_t *pTxPowerIndexOffset)
  1798. {
  1799. #define SM_PD_GAIN(x) SM(0x38, AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##x)
  1800. #define SM_PDGAIN_B(x, y) \
  1801. SM((gainBoundaries[x]), AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##y)
  1802. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  1803. struct cal_data_per_freq *pRawDataset;
  1804. u8 *pCalBChans = NULL;
  1805. u16 pdGainOverlap_t2;
  1806. static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
  1807. u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
  1808. u16 numPiers, i, j;
  1809. int16_t tMinCalPower;
  1810. u16 numXpdGain, xpdMask;
  1811. u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
  1812. u32 reg32, regOffset, regChainOffset;
  1813. int16_t modalIdx;
  1814. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  1815. xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
  1816. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1817. AR5416_EEP_MINOR_VER_2) {
  1818. pdGainOverlap_t2 =
  1819. pEepData->modalHeader[modalIdx].pdGainOverlap;
  1820. } else {
  1821. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  1822. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  1823. }
  1824. if (IS_CHAN_2GHZ(chan)) {
  1825. pCalBChans = pEepData->calFreqPier2G;
  1826. numPiers = AR5416_NUM_2G_CAL_PIERS;
  1827. } else {
  1828. pCalBChans = pEepData->calFreqPier5G;
  1829. numPiers = AR5416_NUM_5G_CAL_PIERS;
  1830. }
  1831. if (OLC_FOR_AR9280_20_LATER && IS_CHAN_2GHZ(chan)) {
  1832. pRawDataset = pEepData->calPierData2G[0];
  1833. ah->initPDADC = ((struct calDataPerFreqOpLoop *)
  1834. pRawDataset)->vpdPdg[0][0];
  1835. }
  1836. numXpdGain = 0;
  1837. for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
  1838. if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
  1839. if (numXpdGain >= AR5416_NUM_PD_GAINS)
  1840. break;
  1841. xpdGainValues[numXpdGain] =
  1842. (u16)(AR5416_PD_GAINS_IN_MASK - i);
  1843. numXpdGain++;
  1844. }
  1845. }
  1846. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  1847. (numXpdGain - 1) & 0x3);
  1848. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  1849. xpdGainValues[0]);
  1850. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  1851. xpdGainValues[1]);
  1852. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  1853. xpdGainValues[2]);
  1854. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  1855. if (AR_SREV_5416_20_OR_LATER(ah) &&
  1856. (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
  1857. (i != 0)) {
  1858. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  1859. } else
  1860. regChainOffset = i * 0x1000;
  1861. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  1862. if (IS_CHAN_2GHZ(chan))
  1863. pRawDataset = pEepData->calPierData2G[i];
  1864. else
  1865. pRawDataset = pEepData->calPierData5G[i];
  1866. if (OLC_FOR_AR9280_20_LATER) {
  1867. u8 pcdacIdx;
  1868. u8 txPower;
  1869. ath9k_get_txgain_index(ah, chan,
  1870. (struct calDataPerFreqOpLoop *)pRawDataset,
  1871. pCalBChans, numPiers, &txPower, &pcdacIdx);
  1872. ath9k_olc_get_pdadcs(ah, pcdacIdx,
  1873. txPower/2, pdadcValues);
  1874. } else {
  1875. ath9k_hw_get_def_gain_boundaries_pdadcs(ah,
  1876. chan, pRawDataset,
  1877. pCalBChans, numPiers,
  1878. pdGainOverlap_t2,
  1879. &tMinCalPower,
  1880. gainBoundaries,
  1881. pdadcValues,
  1882. numXpdGain);
  1883. }
  1884. if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
  1885. if (OLC_FOR_AR9280_20_LATER) {
  1886. REG_WRITE(ah,
  1887. AR_PHY_TPCRG5 + regChainOffset,
  1888. SM(0x6,
  1889. AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
  1890. SM_PD_GAIN(1) | SM_PD_GAIN(2) |
  1891. SM_PD_GAIN(3) | SM_PD_GAIN(4));
  1892. } else {
  1893. REG_WRITE(ah,
  1894. AR_PHY_TPCRG5 + regChainOffset,
  1895. SM(pdGainOverlap_t2,
  1896. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)|
  1897. SM_PDGAIN_B(0, 1) |
  1898. SM_PDGAIN_B(1, 2) |
  1899. SM_PDGAIN_B(2, 3) |
  1900. SM_PDGAIN_B(3, 4));
  1901. }
  1902. }
  1903. regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
  1904. for (j = 0; j < 32; j++) {
  1905. reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
  1906. ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
  1907. ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
  1908. ((pdadcValues[4 * j + 3] & 0xFF) << 24);
  1909. REG_WRITE(ah, regOffset, reg32);
  1910. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1911. "PDADC (%d,%4x): %4.4x %8.8x\n",
  1912. i, regChainOffset, regOffset,
  1913. reg32);
  1914. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1915. "PDADC: Chain %d | PDADC %3d "
  1916. "Value %3d | PDADC %3d Value %3d | "
  1917. "PDADC %3d Value %3d | PDADC %3d "
  1918. "Value %3d |\n",
  1919. i, 4 * j, pdadcValues[4 * j],
  1920. 4 * j + 1, pdadcValues[4 * j + 1],
  1921. 4 * j + 2, pdadcValues[4 * j + 2],
  1922. 4 * j + 3,
  1923. pdadcValues[4 * j + 3]);
  1924. regOffset += 4;
  1925. }
  1926. }
  1927. }
  1928. *pTxPowerIndexOffset = 0;
  1929. #undef SM_PD_GAIN
  1930. #undef SM_PDGAIN_B
  1931. }
  1932. static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
  1933. struct ath9k_channel *chan,
  1934. int16_t *ratesArray,
  1935. u16 cfgCtl,
  1936. u16 AntennaReduction,
  1937. u16 twiceMaxRegulatoryPower,
  1938. u16 powerLimit)
  1939. {
  1940. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */
  1941. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */
  1942. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  1943. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  1944. static const u16 tpScaleReductionTable[5] =
  1945. { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
  1946. int i;
  1947. int16_t twiceLargestAntenna;
  1948. struct cal_ctl_data *rep;
  1949. struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
  1950. 0, { 0, 0, 0, 0}
  1951. };
  1952. struct cal_target_power_leg targetPowerOfdmExt = {
  1953. 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
  1954. 0, { 0, 0, 0, 0 }
  1955. };
  1956. struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
  1957. 0, {0, 0, 0, 0}
  1958. };
  1959. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  1960. u16 ctlModesFor11a[] =
  1961. { CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40 };
  1962. u16 ctlModesFor11g[] =
  1963. { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
  1964. CTL_2GHT40
  1965. };
  1966. u16 numCtlModes, *pCtlMode, ctlMode, freq;
  1967. struct chan_centers centers;
  1968. int tx_chainmask;
  1969. u16 twiceMinEdgePower;
  1970. tx_chainmask = ah->txchainmask;
  1971. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1972. twiceLargestAntenna = max(
  1973. pEepData->modalHeader
  1974. [IS_CHAN_2GHZ(chan)].antennaGainCh[0],
  1975. pEepData->modalHeader
  1976. [IS_CHAN_2GHZ(chan)].antennaGainCh[1]);
  1977. twiceLargestAntenna = max((u8)twiceLargestAntenna,
  1978. pEepData->modalHeader
  1979. [IS_CHAN_2GHZ(chan)].antennaGainCh[2]);
  1980. twiceLargestAntenna = (int16_t)min(AntennaReduction -
  1981. twiceLargestAntenna, 0);
  1982. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  1983. if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) {
  1984. maxRegAllowedPower -=
  1985. (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2);
  1986. }
  1987. scaledPower = min(powerLimit, maxRegAllowedPower);
  1988. switch (ar5416_get_ntxchains(tx_chainmask)) {
  1989. case 1:
  1990. break;
  1991. case 2:
  1992. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  1993. break;
  1994. case 3:
  1995. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  1996. break;
  1997. }
  1998. scaledPower = max((u16)0, scaledPower);
  1999. if (IS_CHAN_2GHZ(chan)) {
  2000. numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
  2001. SUB_NUM_CTL_MODES_AT_2G_40;
  2002. pCtlMode = ctlModesFor11g;
  2003. ath9k_hw_get_legacy_target_powers(ah, chan,
  2004. pEepData->calTargetPowerCck,
  2005. AR5416_NUM_2G_CCK_TARGET_POWERS,
  2006. &targetPowerCck, 4, false);
  2007. ath9k_hw_get_legacy_target_powers(ah, chan,
  2008. pEepData->calTargetPower2G,
  2009. AR5416_NUM_2G_20_TARGET_POWERS,
  2010. &targetPowerOfdm, 4, false);
  2011. ath9k_hw_get_target_powers(ah, chan,
  2012. pEepData->calTargetPower2GHT20,
  2013. AR5416_NUM_2G_20_TARGET_POWERS,
  2014. &targetPowerHt20, 8, false);
  2015. if (IS_CHAN_HT40(chan)) {
  2016. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  2017. ath9k_hw_get_target_powers(ah, chan,
  2018. pEepData->calTargetPower2GHT40,
  2019. AR5416_NUM_2G_40_TARGET_POWERS,
  2020. &targetPowerHt40, 8, true);
  2021. ath9k_hw_get_legacy_target_powers(ah, chan,
  2022. pEepData->calTargetPowerCck,
  2023. AR5416_NUM_2G_CCK_TARGET_POWERS,
  2024. &targetPowerCckExt, 4, true);
  2025. ath9k_hw_get_legacy_target_powers(ah, chan,
  2026. pEepData->calTargetPower2G,
  2027. AR5416_NUM_2G_20_TARGET_POWERS,
  2028. &targetPowerOfdmExt, 4, true);
  2029. }
  2030. } else {
  2031. numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
  2032. SUB_NUM_CTL_MODES_AT_5G_40;
  2033. pCtlMode = ctlModesFor11a;
  2034. ath9k_hw_get_legacy_target_powers(ah, chan,
  2035. pEepData->calTargetPower5G,
  2036. AR5416_NUM_5G_20_TARGET_POWERS,
  2037. &targetPowerOfdm, 4, false);
  2038. ath9k_hw_get_target_powers(ah, chan,
  2039. pEepData->calTargetPower5GHT20,
  2040. AR5416_NUM_5G_20_TARGET_POWERS,
  2041. &targetPowerHt20, 8, false);
  2042. if (IS_CHAN_HT40(chan)) {
  2043. numCtlModes = ARRAY_SIZE(ctlModesFor11a);
  2044. ath9k_hw_get_target_powers(ah, chan,
  2045. pEepData->calTargetPower5GHT40,
  2046. AR5416_NUM_5G_40_TARGET_POWERS,
  2047. &targetPowerHt40, 8, true);
  2048. ath9k_hw_get_legacy_target_powers(ah, chan,
  2049. pEepData->calTargetPower5G,
  2050. AR5416_NUM_5G_20_TARGET_POWERS,
  2051. &targetPowerOfdmExt, 4, true);
  2052. }
  2053. }
  2054. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  2055. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  2056. (pCtlMode[ctlMode] == CTL_2GHT40);
  2057. if (isHt40CtlMode)
  2058. freq = centers.synth_center;
  2059. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  2060. freq = centers.ext_center;
  2061. else
  2062. freq = centers.ctl_center;
  2063. if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
  2064. ah->eep_ops->get_eeprom_rev(ah) <= 2)
  2065. twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  2066. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2067. "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
  2068. "EXT_ADDITIVE %d\n",
  2069. ctlMode, numCtlModes, isHt40CtlMode,
  2070. (pCtlMode[ctlMode] & EXT_ADDITIVE));
  2071. for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  2072. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2073. " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
  2074. "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
  2075. "chan %d\n",
  2076. i, cfgCtl, pCtlMode[ctlMode],
  2077. pEepData->ctlIndex[i], chan->channel);
  2078. if ((((cfgCtl & ~CTL_MODE_M) |
  2079. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  2080. pEepData->ctlIndex[i]) ||
  2081. (((cfgCtl & ~CTL_MODE_M) |
  2082. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  2083. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
  2084. rep = &(pEepData->ctlData[i]);
  2085. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  2086. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
  2087. IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
  2088. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2089. " MATCH-EE_IDX %d: ch %d is2 %d "
  2090. "2xMinEdge %d chainmask %d chains %d\n",
  2091. i, freq, IS_CHAN_2GHZ(chan),
  2092. twiceMinEdgePower, tx_chainmask,
  2093. ar5416_get_ntxchains
  2094. (tx_chainmask));
  2095. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  2096. twiceMaxEdgePower = min(twiceMaxEdgePower,
  2097. twiceMinEdgePower);
  2098. } else {
  2099. twiceMaxEdgePower = twiceMinEdgePower;
  2100. break;
  2101. }
  2102. }
  2103. }
  2104. minCtlPower = min(twiceMaxEdgePower, scaledPower);
  2105. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2106. " SEL-Min ctlMode %d pCtlMode %d "
  2107. "2xMaxEdge %d sP %d minCtlPwr %d\n",
  2108. ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
  2109. scaledPower, minCtlPower);
  2110. switch (pCtlMode[ctlMode]) {
  2111. case CTL_11B:
  2112. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  2113. targetPowerCck.tPow2x[i] =
  2114. min((u16)targetPowerCck.tPow2x[i],
  2115. minCtlPower);
  2116. }
  2117. break;
  2118. case CTL_11A:
  2119. case CTL_11G:
  2120. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  2121. targetPowerOfdm.tPow2x[i] =
  2122. min((u16)targetPowerOfdm.tPow2x[i],
  2123. minCtlPower);
  2124. }
  2125. break;
  2126. case CTL_5GHT20:
  2127. case CTL_2GHT20:
  2128. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  2129. targetPowerHt20.tPow2x[i] =
  2130. min((u16)targetPowerHt20.tPow2x[i],
  2131. minCtlPower);
  2132. }
  2133. break;
  2134. case CTL_11B_EXT:
  2135. targetPowerCckExt.tPow2x[0] = min((u16)
  2136. targetPowerCckExt.tPow2x[0],
  2137. minCtlPower);
  2138. break;
  2139. case CTL_11A_EXT:
  2140. case CTL_11G_EXT:
  2141. targetPowerOfdmExt.tPow2x[0] = min((u16)
  2142. targetPowerOfdmExt.tPow2x[0],
  2143. minCtlPower);
  2144. break;
  2145. case CTL_5GHT40:
  2146. case CTL_2GHT40:
  2147. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  2148. targetPowerHt40.tPow2x[i] =
  2149. min((u16)targetPowerHt40.tPow2x[i],
  2150. minCtlPower);
  2151. }
  2152. break;
  2153. default:
  2154. break;
  2155. }
  2156. }
  2157. ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
  2158. ratesArray[rate18mb] = ratesArray[rate24mb] =
  2159. targetPowerOfdm.tPow2x[0];
  2160. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  2161. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  2162. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  2163. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  2164. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  2165. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  2166. if (IS_CHAN_2GHZ(chan)) {
  2167. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  2168. ratesArray[rate2s] = ratesArray[rate2l] =
  2169. targetPowerCck.tPow2x[1];
  2170. ratesArray[rate5_5s] = ratesArray[rate5_5l] =
  2171. targetPowerCck.tPow2x[2];
  2172. ;
  2173. ratesArray[rate11s] = ratesArray[rate11l] =
  2174. targetPowerCck.tPow2x[3];
  2175. ;
  2176. }
  2177. if (IS_CHAN_HT40(chan)) {
  2178. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  2179. ratesArray[rateHt40_0 + i] =
  2180. targetPowerHt40.tPow2x[i];
  2181. }
  2182. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  2183. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  2184. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  2185. if (IS_CHAN_2GHZ(chan)) {
  2186. ratesArray[rateExtCck] =
  2187. targetPowerCckExt.tPow2x[0];
  2188. }
  2189. }
  2190. }
  2191. static void ath9k_hw_def_set_txpower(struct ath_hw *ah,
  2192. struct ath9k_channel *chan,
  2193. u16 cfgCtl,
  2194. u8 twiceAntennaReduction,
  2195. u8 twiceMaxRegulatoryPower,
  2196. u8 powerLimit)
  2197. {
  2198. #define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
  2199. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  2200. struct modal_eep_header *pModal =
  2201. &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
  2202. int16_t ratesArray[Ar5416RateSize];
  2203. int16_t txPowerIndexOffset = 0;
  2204. u8 ht40PowerIncForPdadc = 2;
  2205. int i, cck_ofdm_delta = 0;
  2206. memset(ratesArray, 0, sizeof(ratesArray));
  2207. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  2208. AR5416_EEP_MINOR_VER_2) {
  2209. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  2210. }
  2211. ath9k_hw_set_def_power_per_rate_table(ah, chan,
  2212. &ratesArray[0], cfgCtl,
  2213. twiceAntennaReduction,
  2214. twiceMaxRegulatoryPower,
  2215. powerLimit);
  2216. ath9k_hw_set_def_power_cal_table(ah, chan, &txPowerIndexOffset);
  2217. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  2218. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  2219. if (ratesArray[i] > AR5416_MAX_RATE_POWER)
  2220. ratesArray[i] = AR5416_MAX_RATE_POWER;
  2221. }
  2222. if (AR_SREV_9280_10_OR_LATER(ah)) {
  2223. for (i = 0; i < Ar5416RateSize; i++)
  2224. ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
  2225. }
  2226. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  2227. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  2228. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  2229. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  2230. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  2231. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  2232. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  2233. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  2234. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  2235. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  2236. if (IS_CHAN_2GHZ(chan)) {
  2237. if (OLC_FOR_AR9280_20_LATER) {
  2238. cck_ofdm_delta = 2;
  2239. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  2240. ATH9K_POW_SM(RT_AR_DELTA(rate2s), 24)
  2241. | ATH9K_POW_SM(RT_AR_DELTA(rate2l), 16)
  2242. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  2243. | ATH9K_POW_SM(RT_AR_DELTA(rate1l), 0));
  2244. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  2245. ATH9K_POW_SM(RT_AR_DELTA(rate11s), 24)
  2246. | ATH9K_POW_SM(RT_AR_DELTA(rate11l), 16)
  2247. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5s), 8)
  2248. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5l), 0));
  2249. } else {
  2250. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  2251. ATH9K_POW_SM(ratesArray[rate2s], 24)
  2252. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  2253. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  2254. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  2255. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  2256. ATH9K_POW_SM(ratesArray[rate11s], 24)
  2257. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  2258. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  2259. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  2260. }
  2261. }
  2262. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  2263. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  2264. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  2265. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  2266. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  2267. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  2268. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  2269. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  2270. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  2271. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  2272. if (IS_CHAN_HT40(chan)) {
  2273. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  2274. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  2275. ht40PowerIncForPdadc, 24)
  2276. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  2277. ht40PowerIncForPdadc, 16)
  2278. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  2279. ht40PowerIncForPdadc, 8)
  2280. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  2281. ht40PowerIncForPdadc, 0));
  2282. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  2283. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  2284. ht40PowerIncForPdadc, 24)
  2285. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  2286. ht40PowerIncForPdadc, 16)
  2287. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  2288. ht40PowerIncForPdadc, 8)
  2289. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  2290. ht40PowerIncForPdadc, 0));
  2291. if (OLC_FOR_AR9280_20_LATER) {
  2292. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  2293. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  2294. | ATH9K_POW_SM(RT_AR_DELTA(rateExtCck), 16)
  2295. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  2296. | ATH9K_POW_SM(RT_AR_DELTA(rateDupCck), 0));
  2297. } else {
  2298. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  2299. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  2300. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  2301. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  2302. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  2303. }
  2304. }
  2305. REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
  2306. ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
  2307. | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
  2308. i = rate6mb;
  2309. if (IS_CHAN_HT40(chan))
  2310. i = rateHt40_0;
  2311. else if (IS_CHAN_HT20(chan))
  2312. i = rateHt20_0;
  2313. if (AR_SREV_9280_10_OR_LATER(ah))
  2314. ah->regulatory.max_power_level =
  2315. ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
  2316. else
  2317. ah->regulatory.max_power_level = ratesArray[i];
  2318. switch(ar5416_get_ntxchains(ah->txchainmask)) {
  2319. case 1:
  2320. break;
  2321. case 2:
  2322. ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
  2323. break;
  2324. case 3:
  2325. ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
  2326. break;
  2327. default:
  2328. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2329. "Invalid chainmask configuration\n");
  2330. break;
  2331. }
  2332. }
  2333. static u8 ath9k_hw_def_get_num_ant_config(struct ath_hw *ah,
  2334. enum ieee80211_band freq_band)
  2335. {
  2336. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  2337. struct modal_eep_header *pModal =
  2338. &(eep->modalHeader[ATH9K_HAL_FREQ_BAND_2GHZ == freq_band]);
  2339. struct base_eep_header *pBase = &eep->baseEepHeader;
  2340. u8 num_ant_config;
  2341. num_ant_config = 1;
  2342. if (pBase->version >= 0x0E0D)
  2343. if (pModal->useAnt1)
  2344. num_ant_config += 1;
  2345. return num_ant_config;
  2346. }
  2347. static u16 ath9k_hw_def_get_eeprom_antenna_cfg(struct ath_hw *ah,
  2348. struct ath9k_channel *chan)
  2349. {
  2350. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  2351. struct modal_eep_header *pModal =
  2352. &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  2353. return pModal->antCtrlCommon & 0xFFFF;
  2354. }
  2355. static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
  2356. {
  2357. #define EEP_DEF_SPURCHAN \
  2358. (ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan)
  2359. u16 spur_val = AR_NO_SPUR;
  2360. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  2361. "Getting spur idx %d is2Ghz. %d val %x\n",
  2362. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  2363. switch (ah->config.spurmode) {
  2364. case SPUR_DISABLE:
  2365. break;
  2366. case SPUR_ENABLE_IOCTL:
  2367. spur_val = ah->config.spurchans[i][is2GHz];
  2368. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  2369. "Getting spur val from new loc. %d\n", spur_val);
  2370. break;
  2371. case SPUR_ENABLE_EEPROM:
  2372. spur_val = EEP_DEF_SPURCHAN;
  2373. break;
  2374. }
  2375. return spur_val;
  2376. #undef EEP_DEF_SPURCHAN
  2377. }
  2378. static struct eeprom_ops eep_def_ops = {
  2379. .check_eeprom = ath9k_hw_def_check_eeprom,
  2380. .get_eeprom = ath9k_hw_def_get_eeprom,
  2381. .fill_eeprom = ath9k_hw_def_fill_eeprom,
  2382. .get_eeprom_ver = ath9k_hw_def_get_eeprom_ver,
  2383. .get_eeprom_rev = ath9k_hw_def_get_eeprom_rev,
  2384. .get_num_ant_config = ath9k_hw_def_get_num_ant_config,
  2385. .get_eeprom_antenna_cfg = ath9k_hw_def_get_eeprom_antenna_cfg,
  2386. .set_board_values = ath9k_hw_def_set_board_values,
  2387. .set_addac = ath9k_hw_def_set_addac,
  2388. .set_txpower = ath9k_hw_def_set_txpower,
  2389. .get_spur_channel = ath9k_hw_def_get_spur_channel
  2390. };
  2391. int ath9k_hw_eeprom_attach(struct ath_hw *ah)
  2392. {
  2393. int status;
  2394. if (AR_SREV_9285(ah)) {
  2395. ah->eep_map = EEP_MAP_4KBITS;
  2396. ah->eep_ops = &eep_4k_ops;
  2397. } else {
  2398. ah->eep_map = EEP_MAP_DEFAULT;
  2399. ah->eep_ops = &eep_def_ops;
  2400. }
  2401. if (!ah->eep_ops->fill_eeprom(ah))
  2402. return -EIO;
  2403. status = ah->eep_ops->check_eeprom(ah);
  2404. return status;
  2405. }