eeprom.c 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070
  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 void 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. }
  106. static void ath9k_hw_get_legacy_target_powers(struct ath_hw *ah,
  107. struct ath9k_channel *chan,
  108. struct cal_target_power_leg *powInfo,
  109. u16 numChannels,
  110. struct cal_target_power_leg *pNewPower,
  111. u16 numRates, bool isExtTarget)
  112. {
  113. struct chan_centers centers;
  114. u16 clo, chi;
  115. int i;
  116. int matchIndex = -1, lowIndex = -1;
  117. u16 freq;
  118. ath9k_hw_get_channel_centers(ah, chan, &centers);
  119. freq = (isExtTarget) ? centers.ext_center : centers.ctl_center;
  120. if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel,
  121. IS_CHAN_2GHZ(chan))) {
  122. matchIndex = 0;
  123. } else {
  124. for (i = 0; (i < numChannels) &&
  125. (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  126. if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
  127. IS_CHAN_2GHZ(chan))) {
  128. matchIndex = i;
  129. break;
  130. } else if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
  131. IS_CHAN_2GHZ(chan))) &&
  132. (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
  133. IS_CHAN_2GHZ(chan)))) {
  134. lowIndex = i - 1;
  135. break;
  136. }
  137. }
  138. if ((matchIndex == -1) && (lowIndex == -1))
  139. matchIndex = i - 1;
  140. }
  141. if (matchIndex != -1) {
  142. *pNewPower = powInfo[matchIndex];
  143. } else {
  144. clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
  145. IS_CHAN_2GHZ(chan));
  146. chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
  147. IS_CHAN_2GHZ(chan));
  148. for (i = 0; i < numRates; i++) {
  149. pNewPower->tPow2x[i] =
  150. (u8)ath9k_hw_interpolate(freq, clo, chi,
  151. powInfo[lowIndex].tPow2x[i],
  152. powInfo[lowIndex + 1].tPow2x[i]);
  153. }
  154. }
  155. }
  156. static void ath9k_get_txgain_index(struct ath_hw *ah,
  157. struct ath9k_channel *chan,
  158. struct calDataPerFreqOpLoop *rawDatasetOpLoop,
  159. u8 *calChans, u16 availPiers, u8 *pwr, u8 *pcdacIdx)
  160. {
  161. u8 pcdac, i = 0;
  162. u16 idxL = 0, idxR = 0, numPiers;
  163. bool match;
  164. struct chan_centers centers;
  165. ath9k_hw_get_channel_centers(ah, chan, &centers);
  166. for (numPiers = 0; numPiers < availPiers; numPiers++)
  167. if (calChans[numPiers] == AR5416_BCHAN_UNUSED)
  168. break;
  169. match = ath9k_hw_get_lower_upper_index(
  170. (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
  171. calChans, numPiers, &idxL, &idxR);
  172. if (match) {
  173. pcdac = rawDatasetOpLoop[idxL].pcdac[0][0];
  174. *pwr = rawDatasetOpLoop[idxL].pwrPdg[0][0];
  175. } else {
  176. pcdac = rawDatasetOpLoop[idxR].pcdac[0][0];
  177. *pwr = (rawDatasetOpLoop[idxL].pwrPdg[0][0] +
  178. rawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
  179. }
  180. while (pcdac > ah->originalGain[i] &&
  181. i < (AR9280_TX_GAIN_TABLE_SIZE - 1))
  182. i++;
  183. *pcdacIdx = i;
  184. return;
  185. }
  186. static void ath9k_olc_get_pdadcs(struct ath_hw *ah,
  187. u32 initTxGain,
  188. int txPower,
  189. u8 *pPDADCValues)
  190. {
  191. u32 i;
  192. u32 offset;
  193. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_0,
  194. AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3);
  195. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_1,
  196. AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3);
  197. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL7,
  198. AR_PHY_TX_PWRCTRL_INIT_TX_GAIN, initTxGain);
  199. offset = txPower;
  200. for (i = 0; i < AR5416_NUM_PDADC_VALUES; i++)
  201. if (i < offset)
  202. pPDADCValues[i] = 0x0;
  203. else
  204. pPDADCValues[i] = 0xFF;
  205. }
  206. static void ath9k_hw_get_target_powers(struct ath_hw *ah,
  207. struct ath9k_channel *chan,
  208. struct cal_target_power_ht *powInfo,
  209. u16 numChannels,
  210. struct cal_target_power_ht *pNewPower,
  211. u16 numRates, bool isHt40Target)
  212. {
  213. struct chan_centers centers;
  214. u16 clo, chi;
  215. int i;
  216. int matchIndex = -1, lowIndex = -1;
  217. u16 freq;
  218. ath9k_hw_get_channel_centers(ah, chan, &centers);
  219. freq = isHt40Target ? centers.synth_center : centers.ctl_center;
  220. if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) {
  221. matchIndex = 0;
  222. } else {
  223. for (i = 0; (i < numChannels) &&
  224. (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  225. if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
  226. IS_CHAN_2GHZ(chan))) {
  227. matchIndex = i;
  228. break;
  229. } else
  230. if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
  231. IS_CHAN_2GHZ(chan))) &&
  232. (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
  233. IS_CHAN_2GHZ(chan)))) {
  234. lowIndex = i - 1;
  235. break;
  236. }
  237. }
  238. if ((matchIndex == -1) && (lowIndex == -1))
  239. matchIndex = i - 1;
  240. }
  241. if (matchIndex != -1) {
  242. *pNewPower = powInfo[matchIndex];
  243. } else {
  244. clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
  245. IS_CHAN_2GHZ(chan));
  246. chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
  247. IS_CHAN_2GHZ(chan));
  248. for (i = 0; i < numRates; i++) {
  249. pNewPower->tPow2x[i] = (u8)ath9k_hw_interpolate(freq,
  250. clo, chi,
  251. powInfo[lowIndex].tPow2x[i],
  252. powInfo[lowIndex + 1].tPow2x[i]);
  253. }
  254. }
  255. }
  256. static u16 ath9k_hw_get_max_edge_power(u16 freq,
  257. struct cal_ctl_edges *pRdEdgesPower,
  258. bool is2GHz, int num_band_edges)
  259. {
  260. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  261. int i;
  262. for (i = 0; (i < num_band_edges) &&
  263. (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
  264. if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) {
  265. twiceMaxEdgePower = pRdEdgesPower[i].tPower;
  266. break;
  267. } else if ((i > 0) &&
  268. (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel,
  269. is2GHz))) {
  270. if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel,
  271. is2GHz) < freq &&
  272. pRdEdgesPower[i - 1].flag) {
  273. twiceMaxEdgePower =
  274. pRdEdgesPower[i - 1].tPower;
  275. }
  276. break;
  277. }
  278. }
  279. return twiceMaxEdgePower;
  280. }
  281. /****************************************/
  282. /* EEPROM Operations for 4K sized cards */
  283. /****************************************/
  284. static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah)
  285. {
  286. return ((ah->eeprom.map4k.baseEepHeader.version >> 12) & 0xF);
  287. }
  288. static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah)
  289. {
  290. return ((ah->eeprom.map4k.baseEepHeader.version) & 0xFFF);
  291. }
  292. static bool ath9k_hw_4k_fill_eeprom(struct ath_hw *ah)
  293. {
  294. #define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
  295. u16 *eep_data = (u16 *)&ah->eeprom.map4k;
  296. int addr, eep_start_loc = 0;
  297. eep_start_loc = 64;
  298. if (!ath9k_hw_use_flash(ah)) {
  299. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  300. "Reading from EEPROM, not flash\n");
  301. }
  302. for (addr = 0; addr < SIZE_EEPROM_4K; addr++) {
  303. if (!ath9k_hw_nvram_read(ah, addr + eep_start_loc, eep_data)) {
  304. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  305. "Unable to read eeprom region \n");
  306. return false;
  307. }
  308. eep_data++;
  309. }
  310. return true;
  311. #undef SIZE_EEPROM_4K
  312. }
  313. static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah)
  314. {
  315. #define EEPROM_4K_SIZE (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
  316. struct ar5416_eeprom_4k *eep =
  317. (struct ar5416_eeprom_4k *) &ah->eeprom.map4k;
  318. u16 *eepdata, temp, magic, magic2;
  319. u32 sum = 0, el;
  320. bool need_swap = false;
  321. int i, addr;
  322. if (!ath9k_hw_use_flash(ah)) {
  323. if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET,
  324. &magic)) {
  325. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  326. "Reading Magic # failed\n");
  327. return false;
  328. }
  329. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  330. "Read Magic = 0x%04X\n", magic);
  331. if (magic != AR5416_EEPROM_MAGIC) {
  332. magic2 = swab16(magic);
  333. if (magic2 == AR5416_EEPROM_MAGIC) {
  334. need_swap = true;
  335. eepdata = (u16 *) (&ah->eeprom);
  336. for (addr = 0; addr < EEPROM_4K_SIZE; addr++) {
  337. temp = swab16(*eepdata);
  338. *eepdata = temp;
  339. eepdata++;
  340. }
  341. } else {
  342. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  343. "Invalid EEPROM Magic. "
  344. "endianness mismatch.\n");
  345. return -EINVAL;
  346. }
  347. }
  348. }
  349. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
  350. need_swap ? "True" : "False");
  351. if (need_swap)
  352. el = swab16(ah->eeprom.map4k.baseEepHeader.length);
  353. else
  354. el = ah->eeprom.map4k.baseEepHeader.length;
  355. if (el > sizeof(struct ar5416_eeprom_4k))
  356. el = sizeof(struct ar5416_eeprom_4k) / sizeof(u16);
  357. else
  358. el = el / sizeof(u16);
  359. eepdata = (u16 *)(&ah->eeprom);
  360. for (i = 0; i < el; i++)
  361. sum ^= *eepdata++;
  362. if (need_swap) {
  363. u32 integer;
  364. u16 word;
  365. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  366. "EEPROM Endianness is not native.. Changing\n");
  367. word = swab16(eep->baseEepHeader.length);
  368. eep->baseEepHeader.length = word;
  369. word = swab16(eep->baseEepHeader.checksum);
  370. eep->baseEepHeader.checksum = word;
  371. word = swab16(eep->baseEepHeader.version);
  372. eep->baseEepHeader.version = word;
  373. word = swab16(eep->baseEepHeader.regDmn[0]);
  374. eep->baseEepHeader.regDmn[0] = word;
  375. word = swab16(eep->baseEepHeader.regDmn[1]);
  376. eep->baseEepHeader.regDmn[1] = word;
  377. word = swab16(eep->baseEepHeader.rfSilent);
  378. eep->baseEepHeader.rfSilent = word;
  379. word = swab16(eep->baseEepHeader.blueToothOptions);
  380. eep->baseEepHeader.blueToothOptions = word;
  381. word = swab16(eep->baseEepHeader.deviceCap);
  382. eep->baseEepHeader.deviceCap = word;
  383. integer = swab32(eep->modalHeader.antCtrlCommon);
  384. eep->modalHeader.antCtrlCommon = integer;
  385. for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
  386. integer = swab32(eep->modalHeader.antCtrlChain[i]);
  387. eep->modalHeader.antCtrlChain[i] = integer;
  388. }
  389. for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
  390. word = swab16(eep->modalHeader.spurChans[i].spurChan);
  391. eep->modalHeader.spurChans[i].spurChan = word;
  392. }
  393. }
  394. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
  395. ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  396. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  397. "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  398. sum, ah->eep_ops->get_eeprom_ver(ah));
  399. return -EINVAL;
  400. }
  401. return 0;
  402. #undef EEPROM_4K_SIZE
  403. }
  404. static u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah,
  405. enum eeprom_param param)
  406. {
  407. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  408. struct modal_eep_4k_header *pModal = &eep->modalHeader;
  409. struct base_eep_header_4k *pBase = &eep->baseEepHeader;
  410. switch (param) {
  411. case EEP_NFTHRESH_2:
  412. return pModal->noiseFloorThreshCh[0];
  413. case AR_EEPROM_MAC(0):
  414. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  415. case AR_EEPROM_MAC(1):
  416. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  417. case AR_EEPROM_MAC(2):
  418. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  419. case EEP_REG_0:
  420. return pBase->regDmn[0];
  421. case EEP_REG_1:
  422. return pBase->regDmn[1];
  423. case EEP_OP_CAP:
  424. return pBase->deviceCap;
  425. case EEP_OP_MODE:
  426. return pBase->opCapFlags;
  427. case EEP_RF_SILENT:
  428. return pBase->rfSilent;
  429. case EEP_OB_2:
  430. return pModal->ob_01;
  431. case EEP_DB_2:
  432. return pModal->db1_01;
  433. case EEP_MINOR_REV:
  434. return pBase->version & AR5416_EEP_VER_MINOR_MASK;
  435. case EEP_TX_MASK:
  436. return pBase->txMask;
  437. case EEP_RX_MASK:
  438. return pBase->rxMask;
  439. case EEP_FRAC_N_5G:
  440. return 0;
  441. default:
  442. return 0;
  443. }
  444. }
  445. static void ath9k_hw_get_4k_gain_boundaries_pdadcs(struct ath_hw *ah,
  446. struct ath9k_channel *chan,
  447. struct cal_data_per_freq_4k *pRawDataSet,
  448. u8 *bChans, u16 availPiers,
  449. u16 tPdGainOverlap, int16_t *pMinCalPower,
  450. u16 *pPdGainBoundaries, u8 *pPDADCValues,
  451. u16 numXpdGains)
  452. {
  453. #define TMP_VAL_VPD_TABLE \
  454. ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep));
  455. int i, j, k;
  456. int16_t ss;
  457. u16 idxL = 0, idxR = 0, numPiers;
  458. static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS]
  459. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  460. static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS]
  461. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  462. static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS]
  463. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  464. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  465. u8 minPwrT4[AR5416_EEP4K_NUM_PD_GAINS];
  466. u8 maxPwrT4[AR5416_EEP4K_NUM_PD_GAINS];
  467. int16_t vpdStep;
  468. int16_t tmpVal;
  469. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  470. bool match;
  471. int16_t minDelta = 0;
  472. struct chan_centers centers;
  473. #define PD_GAIN_BOUNDARY_DEFAULT 58;
  474. ath9k_hw_get_channel_centers(ah, chan, &centers);
  475. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  476. if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
  477. break;
  478. }
  479. match = ath9k_hw_get_lower_upper_index(
  480. (u8)FREQ2FBIN(centers.synth_center,
  481. IS_CHAN_2GHZ(chan)), bChans, numPiers,
  482. &idxL, &idxR);
  483. if (match) {
  484. for (i = 0; i < numXpdGains; i++) {
  485. minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
  486. maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
  487. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  488. pRawDataSet[idxL].pwrPdg[i],
  489. pRawDataSet[idxL].vpdPdg[i],
  490. AR5416_EEP4K_PD_GAIN_ICEPTS,
  491. vpdTableI[i]);
  492. }
  493. } else {
  494. for (i = 0; i < numXpdGains; i++) {
  495. pVpdL = pRawDataSet[idxL].vpdPdg[i];
  496. pPwrL = pRawDataSet[idxL].pwrPdg[i];
  497. pVpdR = pRawDataSet[idxR].vpdPdg[i];
  498. pPwrR = pRawDataSet[idxR].pwrPdg[i];
  499. minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
  500. maxPwrT4[i] =
  501. min(pPwrL[AR5416_EEP4K_PD_GAIN_ICEPTS - 1],
  502. pPwrR[AR5416_EEP4K_PD_GAIN_ICEPTS - 1]);
  503. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  504. pPwrL, pVpdL,
  505. AR5416_EEP4K_PD_GAIN_ICEPTS,
  506. vpdTableL[i]);
  507. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  508. pPwrR, pVpdR,
  509. AR5416_EEP4K_PD_GAIN_ICEPTS,
  510. vpdTableR[i]);
  511. for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
  512. vpdTableI[i][j] =
  513. (u8)(ath9k_hw_interpolate((u16)
  514. FREQ2FBIN(centers.
  515. synth_center,
  516. IS_CHAN_2GHZ
  517. (chan)),
  518. bChans[idxL], bChans[idxR],
  519. vpdTableL[i][j], vpdTableR[i][j]));
  520. }
  521. }
  522. }
  523. *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
  524. k = 0;
  525. for (i = 0; i < numXpdGains; i++) {
  526. if (i == (numXpdGains - 1))
  527. pPdGainBoundaries[i] =
  528. (u16)(maxPwrT4[i] / 2);
  529. else
  530. pPdGainBoundaries[i] =
  531. (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
  532. pPdGainBoundaries[i] =
  533. min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
  534. if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
  535. minDelta = pPdGainBoundaries[0] - 23;
  536. pPdGainBoundaries[0] = 23;
  537. } else {
  538. minDelta = 0;
  539. }
  540. if (i == 0) {
  541. if (AR_SREV_9280_10_OR_LATER(ah))
  542. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  543. else
  544. ss = 0;
  545. } else {
  546. ss = (int16_t)((pPdGainBoundaries[i - 1] -
  547. (minPwrT4[i] / 2)) -
  548. tPdGainOverlap + 1 + minDelta);
  549. }
  550. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  551. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  552. while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  553. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  554. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  555. ss++;
  556. }
  557. sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  558. tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
  559. (minPwrT4[i] / 2));
  560. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  561. tgtIndex : sizeCurrVpdTable;
  562. while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1)))
  563. pPDADCValues[k++] = vpdTableI[i][ss++];
  564. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  565. vpdTableI[i][sizeCurrVpdTable - 2]);
  566. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  567. if (tgtIndex >= maxIndex) {
  568. while ((ss <= tgtIndex) &&
  569. (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  570. tmpVal = (int16_t) TMP_VAL_VPD_TABLE;
  571. pPDADCValues[k++] = (u8)((tmpVal > 255) ?
  572. 255 : tmpVal);
  573. ss++;
  574. }
  575. }
  576. }
  577. while (i < AR5416_EEP4K_PD_GAINS_IN_MASK) {
  578. pPdGainBoundaries[i] = PD_GAIN_BOUNDARY_DEFAULT;
  579. i++;
  580. }
  581. while (k < AR5416_NUM_PDADC_VALUES) {
  582. pPDADCValues[k] = pPDADCValues[k - 1];
  583. k++;
  584. }
  585. return;
  586. #undef TMP_VAL_VPD_TABLE
  587. }
  588. static void ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah,
  589. struct ath9k_channel *chan,
  590. int16_t *pTxPowerIndexOffset)
  591. {
  592. struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
  593. struct cal_data_per_freq_4k *pRawDataset;
  594. u8 *pCalBChans = NULL;
  595. u16 pdGainOverlap_t2;
  596. static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
  597. u16 gainBoundaries[AR5416_EEP4K_PD_GAINS_IN_MASK];
  598. u16 numPiers, i, j;
  599. int16_t tMinCalPower;
  600. u16 numXpdGain, xpdMask;
  601. u16 xpdGainValues[AR5416_EEP4K_NUM_PD_GAINS] = { 0, 0 };
  602. u32 reg32, regOffset, regChainOffset;
  603. xpdMask = pEepData->modalHeader.xpdGain;
  604. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  605. AR5416_EEP_MINOR_VER_2) {
  606. pdGainOverlap_t2 =
  607. pEepData->modalHeader.pdGainOverlap;
  608. } else {
  609. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  610. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  611. }
  612. pCalBChans = pEepData->calFreqPier2G;
  613. numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS;
  614. numXpdGain = 0;
  615. for (i = 1; i <= AR5416_EEP4K_PD_GAINS_IN_MASK; i++) {
  616. if ((xpdMask >> (AR5416_EEP4K_PD_GAINS_IN_MASK - i)) & 1) {
  617. if (numXpdGain >= AR5416_EEP4K_NUM_PD_GAINS)
  618. break;
  619. xpdGainValues[numXpdGain] =
  620. (u16)(AR5416_EEP4K_PD_GAINS_IN_MASK - i);
  621. numXpdGain++;
  622. }
  623. }
  624. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  625. (numXpdGain - 1) & 0x3);
  626. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  627. xpdGainValues[0]);
  628. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  629. xpdGainValues[1]);
  630. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, 0);
  631. for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
  632. if (AR_SREV_5416_20_OR_LATER(ah) &&
  633. (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
  634. (i != 0)) {
  635. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  636. } else
  637. regChainOffset = i * 0x1000;
  638. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  639. pRawDataset = pEepData->calPierData2G[i];
  640. ath9k_hw_get_4k_gain_boundaries_pdadcs(ah, chan,
  641. pRawDataset, pCalBChans,
  642. numPiers, pdGainOverlap_t2,
  643. &tMinCalPower, gainBoundaries,
  644. pdadcValues, numXpdGain);
  645. if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
  646. REG_WRITE(ah, AR_PHY_TPCRG5 + regChainOffset,
  647. SM(pdGainOverlap_t2,
  648. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
  649. | SM(gainBoundaries[0],
  650. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
  651. | SM(gainBoundaries[1],
  652. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
  653. | SM(gainBoundaries[2],
  654. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
  655. | SM(gainBoundaries[3],
  656. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
  657. }
  658. regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
  659. for (j = 0; j < 32; j++) {
  660. reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
  661. ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
  662. ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
  663. ((pdadcValues[4 * j + 3] & 0xFF) << 24);
  664. REG_WRITE(ah, regOffset, reg32);
  665. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  666. "PDADC (%d,%4x): %4.4x %8.8x\n",
  667. i, regChainOffset, regOffset,
  668. reg32);
  669. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  670. "PDADC: Chain %d | "
  671. "PDADC %3d Value %3d | "
  672. "PDADC %3d Value %3d | "
  673. "PDADC %3d Value %3d | "
  674. "PDADC %3d Value %3d |\n",
  675. i, 4 * j, pdadcValues[4 * j],
  676. 4 * j + 1, pdadcValues[4 * j + 1],
  677. 4 * j + 2, pdadcValues[4 * j + 2],
  678. 4 * j + 3,
  679. pdadcValues[4 * j + 3]);
  680. regOffset += 4;
  681. }
  682. }
  683. }
  684. *pTxPowerIndexOffset = 0;
  685. }
  686. static void ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
  687. struct ath9k_channel *chan,
  688. int16_t *ratesArray,
  689. u16 cfgCtl,
  690. u16 AntennaReduction,
  691. u16 twiceMaxRegulatoryPower,
  692. u16 powerLimit)
  693. {
  694. struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
  695. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  696. static const u16 tpScaleReductionTable[5] =
  697. { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
  698. int i;
  699. int16_t twiceLargestAntenna;
  700. struct cal_ctl_data_4k *rep;
  701. struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
  702. 0, { 0, 0, 0, 0}
  703. };
  704. struct cal_target_power_leg targetPowerOfdmExt = {
  705. 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
  706. 0, { 0, 0, 0, 0 }
  707. };
  708. struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
  709. 0, {0, 0, 0, 0}
  710. };
  711. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  712. u16 ctlModesFor11g[] =
  713. { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
  714. CTL_2GHT40
  715. };
  716. u16 numCtlModes, *pCtlMode, ctlMode, freq;
  717. struct chan_centers centers;
  718. int tx_chainmask;
  719. u16 twiceMinEdgePower;
  720. tx_chainmask = ah->txchainmask;
  721. ath9k_hw_get_channel_centers(ah, chan, &centers);
  722. twiceLargestAntenna = pEepData->modalHeader.antennaGainCh[0];
  723. twiceLargestAntenna = (int16_t)min(AntennaReduction -
  724. twiceLargestAntenna, 0);
  725. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  726. if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) {
  727. maxRegAllowedPower -=
  728. (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2);
  729. }
  730. scaledPower = min(powerLimit, maxRegAllowedPower);
  731. scaledPower = max((u16)0, scaledPower);
  732. numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
  733. pCtlMode = ctlModesFor11g;
  734. ath9k_hw_get_legacy_target_powers(ah, chan,
  735. pEepData->calTargetPowerCck,
  736. AR5416_NUM_2G_CCK_TARGET_POWERS,
  737. &targetPowerCck, 4, false);
  738. ath9k_hw_get_legacy_target_powers(ah, chan,
  739. pEepData->calTargetPower2G,
  740. AR5416_NUM_2G_20_TARGET_POWERS,
  741. &targetPowerOfdm, 4, false);
  742. ath9k_hw_get_target_powers(ah, chan,
  743. pEepData->calTargetPower2GHT20,
  744. AR5416_NUM_2G_20_TARGET_POWERS,
  745. &targetPowerHt20, 8, false);
  746. if (IS_CHAN_HT40(chan)) {
  747. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  748. ath9k_hw_get_target_powers(ah, chan,
  749. pEepData->calTargetPower2GHT40,
  750. AR5416_NUM_2G_40_TARGET_POWERS,
  751. &targetPowerHt40, 8, true);
  752. ath9k_hw_get_legacy_target_powers(ah, chan,
  753. pEepData->calTargetPowerCck,
  754. AR5416_NUM_2G_CCK_TARGET_POWERS,
  755. &targetPowerCckExt, 4, true);
  756. ath9k_hw_get_legacy_target_powers(ah, chan,
  757. pEepData->calTargetPower2G,
  758. AR5416_NUM_2G_20_TARGET_POWERS,
  759. &targetPowerOfdmExt, 4, true);
  760. }
  761. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  762. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  763. (pCtlMode[ctlMode] == CTL_2GHT40);
  764. if (isHt40CtlMode)
  765. freq = centers.synth_center;
  766. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  767. freq = centers.ext_center;
  768. else
  769. freq = centers.ctl_center;
  770. if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
  771. ah->eep_ops->get_eeprom_rev(ah) <= 2)
  772. twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  773. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  774. "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
  775. "EXT_ADDITIVE %d\n",
  776. ctlMode, numCtlModes, isHt40CtlMode,
  777. (pCtlMode[ctlMode] & EXT_ADDITIVE));
  778. for (i = 0; (i < AR5416_EEP4K_NUM_CTLS) &&
  779. pEepData->ctlIndex[i]; i++) {
  780. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  781. " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
  782. "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
  783. "chan %d\n",
  784. i, cfgCtl, pCtlMode[ctlMode],
  785. pEepData->ctlIndex[i], chan->channel);
  786. if ((((cfgCtl & ~CTL_MODE_M) |
  787. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  788. pEepData->ctlIndex[i]) ||
  789. (((cfgCtl & ~CTL_MODE_M) |
  790. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  791. ((pEepData->ctlIndex[i] & CTL_MODE_M) |
  792. SD_NO_CTL))) {
  793. rep = &(pEepData->ctlData[i]);
  794. twiceMinEdgePower =
  795. ath9k_hw_get_max_edge_power(freq,
  796. rep->ctlEdges[ar5416_get_ntxchains
  797. (tx_chainmask) - 1],
  798. IS_CHAN_2GHZ(chan),
  799. AR5416_EEP4K_NUM_BAND_EDGES);
  800. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  801. " MATCH-EE_IDX %d: ch %d is2 %d "
  802. "2xMinEdge %d chainmask %d chains %d\n",
  803. i, freq, IS_CHAN_2GHZ(chan),
  804. twiceMinEdgePower, tx_chainmask,
  805. ar5416_get_ntxchains
  806. (tx_chainmask));
  807. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  808. twiceMaxEdgePower =
  809. min(twiceMaxEdgePower,
  810. twiceMinEdgePower);
  811. } else {
  812. twiceMaxEdgePower = twiceMinEdgePower;
  813. break;
  814. }
  815. }
  816. }
  817. minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
  818. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  819. " SEL-Min ctlMode %d pCtlMode %d "
  820. "2xMaxEdge %d sP %d minCtlPwr %d\n",
  821. ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
  822. scaledPower, minCtlPower);
  823. switch (pCtlMode[ctlMode]) {
  824. case CTL_11B:
  825. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x);
  826. i++) {
  827. targetPowerCck.tPow2x[i] =
  828. min((u16)targetPowerCck.tPow2x[i],
  829. minCtlPower);
  830. }
  831. break;
  832. case CTL_11G:
  833. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x);
  834. i++) {
  835. targetPowerOfdm.tPow2x[i] =
  836. min((u16)targetPowerOfdm.tPow2x[i],
  837. minCtlPower);
  838. }
  839. break;
  840. case CTL_2GHT20:
  841. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x);
  842. i++) {
  843. targetPowerHt20.tPow2x[i] =
  844. min((u16)targetPowerHt20.tPow2x[i],
  845. minCtlPower);
  846. }
  847. break;
  848. case CTL_11B_EXT:
  849. targetPowerCckExt.tPow2x[0] = min((u16)
  850. targetPowerCckExt.tPow2x[0],
  851. minCtlPower);
  852. break;
  853. case CTL_11G_EXT:
  854. targetPowerOfdmExt.tPow2x[0] = min((u16)
  855. targetPowerOfdmExt.tPow2x[0],
  856. minCtlPower);
  857. break;
  858. case CTL_2GHT40:
  859. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x);
  860. i++) {
  861. targetPowerHt40.tPow2x[i] =
  862. min((u16)targetPowerHt40.tPow2x[i],
  863. minCtlPower);
  864. }
  865. break;
  866. default:
  867. break;
  868. }
  869. }
  870. ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
  871. ratesArray[rate18mb] = ratesArray[rate24mb] =
  872. targetPowerOfdm.tPow2x[0];
  873. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  874. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  875. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  876. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  877. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  878. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  879. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  880. ratesArray[rate2s] = ratesArray[rate2l] = targetPowerCck.tPow2x[1];
  881. ratesArray[rate5_5s] = ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
  882. ratesArray[rate11s] = ratesArray[rate11l] = targetPowerCck.tPow2x[3];
  883. if (IS_CHAN_HT40(chan)) {
  884. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  885. ratesArray[rateHt40_0 + i] =
  886. targetPowerHt40.tPow2x[i];
  887. }
  888. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  889. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  890. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  891. ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
  892. }
  893. }
  894. static void ath9k_hw_4k_set_txpower(struct ath_hw *ah,
  895. struct ath9k_channel *chan,
  896. u16 cfgCtl,
  897. u8 twiceAntennaReduction,
  898. u8 twiceMaxRegulatoryPower,
  899. u8 powerLimit)
  900. {
  901. struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
  902. struct modal_eep_4k_header *pModal = &pEepData->modalHeader;
  903. int16_t ratesArray[Ar5416RateSize];
  904. int16_t txPowerIndexOffset = 0;
  905. u8 ht40PowerIncForPdadc = 2;
  906. int i;
  907. memset(ratesArray, 0, sizeof(ratesArray));
  908. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  909. AR5416_EEP_MINOR_VER_2) {
  910. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  911. }
  912. ath9k_hw_set_4k_power_per_rate_table(ah, chan,
  913. &ratesArray[0], cfgCtl,
  914. twiceAntennaReduction,
  915. twiceMaxRegulatoryPower,
  916. powerLimit);
  917. ath9k_hw_set_4k_power_cal_table(ah, chan, &txPowerIndexOffset);
  918. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  919. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  920. if (ratesArray[i] > AR5416_MAX_RATE_POWER)
  921. ratesArray[i] = AR5416_MAX_RATE_POWER;
  922. }
  923. if (AR_SREV_9280_10_OR_LATER(ah)) {
  924. for (i = 0; i < Ar5416RateSize; i++)
  925. ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
  926. }
  927. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  928. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  929. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  930. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  931. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  932. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  933. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  934. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  935. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  936. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  937. if (IS_CHAN_2GHZ(chan)) {
  938. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  939. ATH9K_POW_SM(ratesArray[rate2s], 24)
  940. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  941. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  942. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  943. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  944. ATH9K_POW_SM(ratesArray[rate11s], 24)
  945. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  946. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  947. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  948. }
  949. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  950. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  951. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  952. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  953. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  954. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  955. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  956. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  957. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  958. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  959. if (IS_CHAN_HT40(chan)) {
  960. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  961. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  962. ht40PowerIncForPdadc, 24)
  963. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  964. ht40PowerIncForPdadc, 16)
  965. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  966. ht40PowerIncForPdadc, 8)
  967. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  968. ht40PowerIncForPdadc, 0));
  969. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  970. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  971. ht40PowerIncForPdadc, 24)
  972. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  973. ht40PowerIncForPdadc, 16)
  974. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  975. ht40PowerIncForPdadc, 8)
  976. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  977. ht40PowerIncForPdadc, 0));
  978. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  979. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  980. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  981. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  982. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  983. }
  984. i = rate6mb;
  985. if (IS_CHAN_HT40(chan))
  986. i = rateHt40_0;
  987. else if (IS_CHAN_HT20(chan))
  988. i = rateHt20_0;
  989. if (AR_SREV_9280_10_OR_LATER(ah))
  990. ah->regulatory.max_power_level =
  991. ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
  992. else
  993. ah->regulatory.max_power_level = ratesArray[i];
  994. }
  995. static void ath9k_hw_4k_set_addac(struct ath_hw *ah,
  996. struct ath9k_channel *chan)
  997. {
  998. struct modal_eep_4k_header *pModal;
  999. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  1000. u8 biaslevel;
  1001. if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
  1002. return;
  1003. if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
  1004. return;
  1005. pModal = &eep->modalHeader;
  1006. if (pModal->xpaBiasLvl != 0xff) {
  1007. biaslevel = pModal->xpaBiasLvl;
  1008. INI_RA(&ah->iniAddac, 7, 1) =
  1009. (INI_RA(&ah->iniAddac, 7, 1) & (~0x18)) | biaslevel << 3;
  1010. }
  1011. }
  1012. static void ath9k_hw_4k_set_gain(struct ath_hw *ah,
  1013. struct modal_eep_4k_header *pModal,
  1014. struct ar5416_eeprom_4k *eep,
  1015. u8 txRxAttenLocal, int regChainOffset)
  1016. {
  1017. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  1018. pModal->antCtrlChain[0]);
  1019. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  1020. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
  1021. ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  1022. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  1023. SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  1024. SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  1025. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1026. AR5416_EEP_MINOR_VER_3) {
  1027. txRxAttenLocal = pModal->txRxAttenCh[0];
  1028. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1029. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]);
  1030. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1031. AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
  1032. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1033. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  1034. pModal->xatten2Margin[0]);
  1035. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1036. AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]);
  1037. /* Set the block 1 value to block 0 value */
  1038. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
  1039. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  1040. pModal->bswMargin[0]);
  1041. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
  1042. AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
  1043. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
  1044. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  1045. pModal->xatten2Margin[0]);
  1046. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
  1047. AR_PHY_GAIN_2GHZ_XATTEN2_DB,
  1048. pModal->xatten2Db[0]);
  1049. }
  1050. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  1051. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  1052. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  1053. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
  1054. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000,
  1055. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  1056. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000,
  1057. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
  1058. if (AR_SREV_9285_11(ah))
  1059. REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14));
  1060. }
  1061. /*
  1062. * Read EEPROM header info and program the device for correct operation
  1063. * given the channel value.
  1064. */
  1065. static void ath9k_hw_4k_set_board_values(struct ath_hw *ah,
  1066. struct ath9k_channel *chan)
  1067. {
  1068. struct modal_eep_4k_header *pModal;
  1069. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  1070. u8 txRxAttenLocal;
  1071. u8 ob[5], db1[5], db2[5];
  1072. u8 ant_div_control1, ant_div_control2;
  1073. u32 regVal;
  1074. pModal = &eep->modalHeader;
  1075. txRxAttenLocal = 23;
  1076. REG_WRITE(ah, AR_PHY_SWITCH_COM,
  1077. ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
  1078. /* Single chain for 4K EEPROM*/
  1079. ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal, 0);
  1080. /* Initialize Ant Diversity settings from EEPROM */
  1081. if (pModal->version >= 3) {
  1082. ant_div_control1 = ((pModal->ob_234 >> 12) & 0xf);
  1083. ant_div_control2 = ((pModal->db1_234 >> 12) & 0xf);
  1084. regVal = REG_READ(ah, 0x99ac);
  1085. regVal &= (~(0x7f000000));
  1086. regVal |= ((ant_div_control1 & 0x1) << 24);
  1087. regVal |= (((ant_div_control1 >> 1) & 0x1) << 29);
  1088. regVal |= (((ant_div_control1 >> 2) & 0x1) << 30);
  1089. regVal |= ((ant_div_control2 & 0x3) << 25);
  1090. regVal |= (((ant_div_control2 >> 2) & 0x3) << 27);
  1091. REG_WRITE(ah, 0x99ac, regVal);
  1092. regVal = REG_READ(ah, 0x99ac);
  1093. regVal = REG_READ(ah, 0xa208);
  1094. regVal &= (~(0x1 << 13));
  1095. regVal |= (((ant_div_control1 >> 3) & 0x1) << 13);
  1096. REG_WRITE(ah, 0xa208, regVal);
  1097. regVal = REG_READ(ah, 0xa208);
  1098. }
  1099. if (pModal->version >= 2) {
  1100. ob[0] = (pModal->ob_01 & 0xf);
  1101. ob[1] = (pModal->ob_01 >> 4) & 0xf;
  1102. ob[2] = (pModal->ob_234 & 0xf);
  1103. ob[3] = ((pModal->ob_234 >> 4) & 0xf);
  1104. ob[4] = ((pModal->ob_234 >> 8) & 0xf);
  1105. db1[0] = (pModal->db1_01 & 0xf);
  1106. db1[1] = ((pModal->db1_01 >> 4) & 0xf);
  1107. db1[2] = (pModal->db1_234 & 0xf);
  1108. db1[3] = ((pModal->db1_234 >> 4) & 0xf);
  1109. db1[4] = ((pModal->db1_234 >> 8) & 0xf);
  1110. db2[0] = (pModal->db2_01 & 0xf);
  1111. db2[1] = ((pModal->db2_01 >> 4) & 0xf);
  1112. db2[2] = (pModal->db2_234 & 0xf);
  1113. db2[3] = ((pModal->db2_234 >> 4) & 0xf);
  1114. db2[4] = ((pModal->db2_234 >> 8) & 0xf);
  1115. } else if (pModal->version == 1) {
  1116. ob[0] = (pModal->ob_01 & 0xf);
  1117. ob[1] = ob[2] = ob[3] = ob[4] = (pModal->ob_01 >> 4) & 0xf;
  1118. db1[0] = (pModal->db1_01 & 0xf);
  1119. db1[1] = db1[2] = db1[3] =
  1120. db1[4] = ((pModal->db1_01 >> 4) & 0xf);
  1121. db2[0] = (pModal->db2_01 & 0xf);
  1122. db2[1] = db2[2] = db2[3] =
  1123. db2[4] = ((pModal->db2_01 >> 4) & 0xf);
  1124. } else {
  1125. int i;
  1126. for (i = 0; i < 5; i++) {
  1127. ob[i] = pModal->ob_01;
  1128. db1[i] = pModal->db1_01;
  1129. db2[i] = pModal->db1_01;
  1130. }
  1131. }
  1132. if (AR_SREV_9271(ah)) {
  1133. ath9k_hw_analog_shift_rmw(ah,
  1134. AR9285_AN_RF2G3,
  1135. AR9271_AN_RF2G3_OB_cck,
  1136. AR9271_AN_RF2G3_OB_cck_S,
  1137. ob[0]);
  1138. ath9k_hw_analog_shift_rmw(ah,
  1139. AR9285_AN_RF2G3,
  1140. AR9271_AN_RF2G3_OB_psk,
  1141. AR9271_AN_RF2G3_OB_psk_S,
  1142. ob[1]);
  1143. ath9k_hw_analog_shift_rmw(ah,
  1144. AR9285_AN_RF2G3,
  1145. AR9271_AN_RF2G3_OB_qam,
  1146. AR9271_AN_RF2G3_OB_qam_S,
  1147. ob[2]);
  1148. ath9k_hw_analog_shift_rmw(ah,
  1149. AR9285_AN_RF2G3,
  1150. AR9271_AN_RF2G3_DB_1,
  1151. AR9271_AN_RF2G3_DB_1_S,
  1152. db1[0]);
  1153. ath9k_hw_analog_shift_rmw(ah,
  1154. AR9285_AN_RF2G4,
  1155. AR9271_AN_RF2G4_DB_2,
  1156. AR9271_AN_RF2G4_DB_2_S,
  1157. db2[0]);
  1158. } else {
  1159. ath9k_hw_analog_shift_rmw(ah,
  1160. AR9285_AN_RF2G3,
  1161. AR9285_AN_RF2G3_OB_0,
  1162. AR9285_AN_RF2G3_OB_0_S,
  1163. ob[0]);
  1164. ath9k_hw_analog_shift_rmw(ah,
  1165. AR9285_AN_RF2G3,
  1166. AR9285_AN_RF2G3_OB_1,
  1167. AR9285_AN_RF2G3_OB_1_S,
  1168. ob[1]);
  1169. ath9k_hw_analog_shift_rmw(ah,
  1170. AR9285_AN_RF2G3,
  1171. AR9285_AN_RF2G3_OB_2,
  1172. AR9285_AN_RF2G3_OB_2_S,
  1173. ob[2]);
  1174. ath9k_hw_analog_shift_rmw(ah,
  1175. AR9285_AN_RF2G3,
  1176. AR9285_AN_RF2G3_OB_3,
  1177. AR9285_AN_RF2G3_OB_3_S,
  1178. ob[3]);
  1179. ath9k_hw_analog_shift_rmw(ah,
  1180. AR9285_AN_RF2G3,
  1181. AR9285_AN_RF2G3_OB_4,
  1182. AR9285_AN_RF2G3_OB_4_S,
  1183. ob[4]);
  1184. ath9k_hw_analog_shift_rmw(ah,
  1185. AR9285_AN_RF2G3,
  1186. AR9285_AN_RF2G3_DB1_0,
  1187. AR9285_AN_RF2G3_DB1_0_S,
  1188. db1[0]);
  1189. ath9k_hw_analog_shift_rmw(ah,
  1190. AR9285_AN_RF2G3,
  1191. AR9285_AN_RF2G3_DB1_1,
  1192. AR9285_AN_RF2G3_DB1_1_S,
  1193. db1[1]);
  1194. ath9k_hw_analog_shift_rmw(ah,
  1195. AR9285_AN_RF2G3,
  1196. AR9285_AN_RF2G3_DB1_2,
  1197. AR9285_AN_RF2G3_DB1_2_S,
  1198. db1[2]);
  1199. ath9k_hw_analog_shift_rmw(ah,
  1200. AR9285_AN_RF2G4,
  1201. AR9285_AN_RF2G4_DB1_3,
  1202. AR9285_AN_RF2G4_DB1_3_S,
  1203. db1[3]);
  1204. ath9k_hw_analog_shift_rmw(ah,
  1205. AR9285_AN_RF2G4,
  1206. AR9285_AN_RF2G4_DB1_4,
  1207. AR9285_AN_RF2G4_DB1_4_S, db1[4]);
  1208. ath9k_hw_analog_shift_rmw(ah,
  1209. AR9285_AN_RF2G4,
  1210. AR9285_AN_RF2G4_DB2_0,
  1211. AR9285_AN_RF2G4_DB2_0_S,
  1212. db2[0]);
  1213. ath9k_hw_analog_shift_rmw(ah,
  1214. AR9285_AN_RF2G4,
  1215. AR9285_AN_RF2G4_DB2_1,
  1216. AR9285_AN_RF2G4_DB2_1_S,
  1217. db2[1]);
  1218. ath9k_hw_analog_shift_rmw(ah,
  1219. AR9285_AN_RF2G4,
  1220. AR9285_AN_RF2G4_DB2_2,
  1221. AR9285_AN_RF2G4_DB2_2_S,
  1222. db2[2]);
  1223. ath9k_hw_analog_shift_rmw(ah,
  1224. AR9285_AN_RF2G4,
  1225. AR9285_AN_RF2G4_DB2_3,
  1226. AR9285_AN_RF2G4_DB2_3_S,
  1227. db2[3]);
  1228. ath9k_hw_analog_shift_rmw(ah,
  1229. AR9285_AN_RF2G4,
  1230. AR9285_AN_RF2G4_DB2_4,
  1231. AR9285_AN_RF2G4_DB2_4_S,
  1232. db2[4]);
  1233. }
  1234. if (AR_SREV_9285_11(ah))
  1235. REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT);
  1236. REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
  1237. pModal->switchSettling);
  1238. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
  1239. pModal->adcDesiredSize);
  1240. REG_WRITE(ah, AR_PHY_RF_CTL4,
  1241. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
  1242. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
  1243. SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
  1244. SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  1245. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  1246. pModal->txEndToRxOn);
  1247. REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
  1248. pModal->thresh62);
  1249. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
  1250. pModal->thresh62);
  1251. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1252. AR5416_EEP_MINOR_VER_2) {
  1253. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
  1254. pModal->txFrameToDataStart);
  1255. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
  1256. pModal->txFrameToPaOn);
  1257. }
  1258. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1259. AR5416_EEP_MINOR_VER_3) {
  1260. if (IS_CHAN_HT40(chan))
  1261. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  1262. AR_PHY_SETTLING_SWITCH,
  1263. pModal->swSettleHt40);
  1264. }
  1265. }
  1266. static u16 ath9k_hw_4k_get_eeprom_antenna_cfg(struct ath_hw *ah,
  1267. struct ath9k_channel *chan)
  1268. {
  1269. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  1270. struct modal_eep_4k_header *pModal = &eep->modalHeader;
  1271. return pModal->antCtrlCommon & 0xFFFF;
  1272. }
  1273. static u8 ath9k_hw_4k_get_num_ant_config(struct ath_hw *ah,
  1274. enum ieee80211_band freq_band)
  1275. {
  1276. return 1;
  1277. }
  1278. static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
  1279. {
  1280. #define EEP_MAP4K_SPURCHAN \
  1281. (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan)
  1282. u16 spur_val = AR_NO_SPUR;
  1283. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  1284. "Getting spur idx %d is2Ghz. %d val %x\n",
  1285. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  1286. switch (ah->config.spurmode) {
  1287. case SPUR_DISABLE:
  1288. break;
  1289. case SPUR_ENABLE_IOCTL:
  1290. spur_val = ah->config.spurchans[i][is2GHz];
  1291. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  1292. "Getting spur val from new loc. %d\n", spur_val);
  1293. break;
  1294. case SPUR_ENABLE_EEPROM:
  1295. spur_val = EEP_MAP4K_SPURCHAN;
  1296. break;
  1297. }
  1298. return spur_val;
  1299. #undef EEP_MAP4K_SPURCHAN
  1300. }
  1301. static struct eeprom_ops eep_4k_ops = {
  1302. .check_eeprom = ath9k_hw_4k_check_eeprom,
  1303. .get_eeprom = ath9k_hw_4k_get_eeprom,
  1304. .fill_eeprom = ath9k_hw_4k_fill_eeprom,
  1305. .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver,
  1306. .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev,
  1307. .get_num_ant_config = ath9k_hw_4k_get_num_ant_config,
  1308. .get_eeprom_antenna_cfg = ath9k_hw_4k_get_eeprom_antenna_cfg,
  1309. .set_board_values = ath9k_hw_4k_set_board_values,
  1310. .set_addac = ath9k_hw_4k_set_addac,
  1311. .set_txpower = ath9k_hw_4k_set_txpower,
  1312. .get_spur_channel = ath9k_hw_4k_get_spur_channel
  1313. };
  1314. /************************************************/
  1315. /* EEPROM Operations for non-4K (Default) cards */
  1316. /************************************************/
  1317. static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
  1318. {
  1319. return ((ah->eeprom.def.baseEepHeader.version >> 12) & 0xF);
  1320. }
  1321. static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
  1322. {
  1323. return ((ah->eeprom.def.baseEepHeader.version) & 0xFFF);
  1324. }
  1325. static bool ath9k_hw_def_fill_eeprom(struct ath_hw *ah)
  1326. {
  1327. #define SIZE_EEPROM_DEF (sizeof(struct ar5416_eeprom_def) / sizeof(u16))
  1328. u16 *eep_data = (u16 *)&ah->eeprom.def;
  1329. int addr, ar5416_eep_start_loc = 0x100;
  1330. for (addr = 0; addr < SIZE_EEPROM_DEF; addr++) {
  1331. if (!ath9k_hw_nvram_read(ah, addr + ar5416_eep_start_loc,
  1332. eep_data)) {
  1333. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  1334. "Unable to read eeprom region\n");
  1335. return false;
  1336. }
  1337. eep_data++;
  1338. }
  1339. return true;
  1340. #undef SIZE_EEPROM_DEF
  1341. }
  1342. static int ath9k_hw_def_check_eeprom(struct ath_hw *ah)
  1343. {
  1344. struct ar5416_eeprom_def *eep =
  1345. (struct ar5416_eeprom_def *) &ah->eeprom.def;
  1346. u16 *eepdata, temp, magic, magic2;
  1347. u32 sum = 0, el;
  1348. bool need_swap = false;
  1349. int i, addr, size;
  1350. if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
  1351. DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Reading Magic # failed\n");
  1352. return false;
  1353. }
  1354. if (!ath9k_hw_use_flash(ah)) {
  1355. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1356. "Read Magic = 0x%04X\n", magic);
  1357. if (magic != AR5416_EEPROM_MAGIC) {
  1358. magic2 = swab16(magic);
  1359. if (magic2 == AR5416_EEPROM_MAGIC) {
  1360. size = sizeof(struct ar5416_eeprom_def);
  1361. need_swap = true;
  1362. eepdata = (u16 *) (&ah->eeprom);
  1363. for (addr = 0; addr < size / sizeof(u16); addr++) {
  1364. temp = swab16(*eepdata);
  1365. *eepdata = temp;
  1366. eepdata++;
  1367. }
  1368. } else {
  1369. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  1370. "Invalid EEPROM Magic. "
  1371. "Endianness mismatch.\n");
  1372. return -EINVAL;
  1373. }
  1374. }
  1375. }
  1376. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
  1377. need_swap ? "True" : "False");
  1378. if (need_swap)
  1379. el = swab16(ah->eeprom.def.baseEepHeader.length);
  1380. else
  1381. el = ah->eeprom.def.baseEepHeader.length;
  1382. if (el > sizeof(struct ar5416_eeprom_def))
  1383. el = sizeof(struct ar5416_eeprom_def) / sizeof(u16);
  1384. else
  1385. el = el / sizeof(u16);
  1386. eepdata = (u16 *)(&ah->eeprom);
  1387. for (i = 0; i < el; i++)
  1388. sum ^= *eepdata++;
  1389. if (need_swap) {
  1390. u32 integer, j;
  1391. u16 word;
  1392. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1393. "EEPROM Endianness is not native.. Changing.\n");
  1394. word = swab16(eep->baseEepHeader.length);
  1395. eep->baseEepHeader.length = word;
  1396. word = swab16(eep->baseEepHeader.checksum);
  1397. eep->baseEepHeader.checksum = word;
  1398. word = swab16(eep->baseEepHeader.version);
  1399. eep->baseEepHeader.version = word;
  1400. word = swab16(eep->baseEepHeader.regDmn[0]);
  1401. eep->baseEepHeader.regDmn[0] = word;
  1402. word = swab16(eep->baseEepHeader.regDmn[1]);
  1403. eep->baseEepHeader.regDmn[1] = word;
  1404. word = swab16(eep->baseEepHeader.rfSilent);
  1405. eep->baseEepHeader.rfSilent = word;
  1406. word = swab16(eep->baseEepHeader.blueToothOptions);
  1407. eep->baseEepHeader.blueToothOptions = word;
  1408. word = swab16(eep->baseEepHeader.deviceCap);
  1409. eep->baseEepHeader.deviceCap = word;
  1410. for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
  1411. struct modal_eep_header *pModal =
  1412. &eep->modalHeader[j];
  1413. integer = swab32(pModal->antCtrlCommon);
  1414. pModal->antCtrlCommon = integer;
  1415. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  1416. integer = swab32(pModal->antCtrlChain[i]);
  1417. pModal->antCtrlChain[i] = integer;
  1418. }
  1419. for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
  1420. word = swab16(pModal->spurChans[i].spurChan);
  1421. pModal->spurChans[i].spurChan = word;
  1422. }
  1423. }
  1424. }
  1425. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
  1426. ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  1427. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  1428. "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  1429. sum, ah->eep_ops->get_eeprom_ver(ah));
  1430. return -EINVAL;
  1431. }
  1432. return 0;
  1433. }
  1434. static u32 ath9k_hw_def_get_eeprom(struct ath_hw *ah,
  1435. enum eeprom_param param)
  1436. {
  1437. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  1438. struct modal_eep_header *pModal = eep->modalHeader;
  1439. struct base_eep_header *pBase = &eep->baseEepHeader;
  1440. switch (param) {
  1441. case EEP_NFTHRESH_5:
  1442. return pModal[0].noiseFloorThreshCh[0];
  1443. case EEP_NFTHRESH_2:
  1444. return pModal[1].noiseFloorThreshCh[0];
  1445. case AR_EEPROM_MAC(0):
  1446. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  1447. case AR_EEPROM_MAC(1):
  1448. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  1449. case AR_EEPROM_MAC(2):
  1450. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  1451. case EEP_REG_0:
  1452. return pBase->regDmn[0];
  1453. case EEP_REG_1:
  1454. return pBase->regDmn[1];
  1455. case EEP_OP_CAP:
  1456. return pBase->deviceCap;
  1457. case EEP_OP_MODE:
  1458. return pBase->opCapFlags;
  1459. case EEP_RF_SILENT:
  1460. return pBase->rfSilent;
  1461. case EEP_OB_5:
  1462. return pModal[0].ob;
  1463. case EEP_DB_5:
  1464. return pModal[0].db;
  1465. case EEP_OB_2:
  1466. return pModal[1].ob;
  1467. case EEP_DB_2:
  1468. return pModal[1].db;
  1469. case EEP_MINOR_REV:
  1470. return AR5416_VER_MASK;
  1471. case EEP_TX_MASK:
  1472. return pBase->txMask;
  1473. case EEP_RX_MASK:
  1474. return pBase->rxMask;
  1475. case EEP_RXGAIN_TYPE:
  1476. return pBase->rxGainType;
  1477. case EEP_TXGAIN_TYPE:
  1478. return pBase->txGainType;
  1479. case EEP_OL_PWRCTRL:
  1480. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  1481. return pBase->openLoopPwrCntl ? true : false;
  1482. else
  1483. return false;
  1484. case EEP_RC_CHAIN_MASK:
  1485. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  1486. return pBase->rcChainMask;
  1487. else
  1488. return 0;
  1489. case EEP_DAC_HPWR_5G:
  1490. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
  1491. return pBase->dacHiPwrMode_5G;
  1492. else
  1493. return 0;
  1494. case EEP_FRAC_N_5G:
  1495. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
  1496. return pBase->frac_n_5g;
  1497. else
  1498. return 0;
  1499. default:
  1500. return 0;
  1501. }
  1502. }
  1503. static void ath9k_hw_def_set_gain(struct ath_hw *ah,
  1504. struct modal_eep_header *pModal,
  1505. struct ar5416_eeprom_def *eep,
  1506. u8 txRxAttenLocal, int regChainOffset, int i)
  1507. {
  1508. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
  1509. txRxAttenLocal = pModal->txRxAttenCh[i];
  1510. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1511. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1512. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  1513. pModal->bswMargin[i]);
  1514. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1515. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  1516. pModal->bswAtten[i]);
  1517. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1518. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  1519. pModal->xatten2Margin[i]);
  1520. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1521. AR_PHY_GAIN_2GHZ_XATTEN2_DB,
  1522. pModal->xatten2Db[i]);
  1523. } else {
  1524. REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1525. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  1526. ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
  1527. | SM(pModal-> bswMargin[i],
  1528. AR_PHY_GAIN_2GHZ_BSW_MARGIN));
  1529. REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1530. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  1531. ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
  1532. | SM(pModal->bswAtten[i],
  1533. AR_PHY_GAIN_2GHZ_BSW_ATTEN));
  1534. }
  1535. }
  1536. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1537. REG_RMW_FIELD(ah,
  1538. AR_PHY_RXGAIN + regChainOffset,
  1539. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  1540. REG_RMW_FIELD(ah,
  1541. AR_PHY_RXGAIN + regChainOffset,
  1542. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[i]);
  1543. } else {
  1544. REG_WRITE(ah,
  1545. AR_PHY_RXGAIN + regChainOffset,
  1546. (REG_READ(ah, AR_PHY_RXGAIN + regChainOffset) &
  1547. ~AR_PHY_RXGAIN_TXRX_ATTEN)
  1548. | SM(txRxAttenLocal, AR_PHY_RXGAIN_TXRX_ATTEN));
  1549. REG_WRITE(ah,
  1550. AR_PHY_GAIN_2GHZ + regChainOffset,
  1551. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  1552. ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
  1553. SM(pModal->rxTxMarginCh[i], AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
  1554. }
  1555. }
  1556. static void ath9k_hw_def_set_board_values(struct ath_hw *ah,
  1557. struct ath9k_channel *chan)
  1558. {
  1559. struct modal_eep_header *pModal;
  1560. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  1561. int i, regChainOffset;
  1562. u8 txRxAttenLocal;
  1563. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  1564. txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
  1565. REG_WRITE(ah, AR_PHY_SWITCH_COM,
  1566. ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
  1567. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  1568. if (AR_SREV_9280(ah)) {
  1569. if (i >= 2)
  1570. break;
  1571. }
  1572. if (AR_SREV_5416_20_OR_LATER(ah) &&
  1573. (ah->rxchainmask == 5 || ah->txchainmask == 5) && (i != 0))
  1574. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  1575. else
  1576. regChainOffset = i * 0x1000;
  1577. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  1578. pModal->antCtrlChain[i]);
  1579. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  1580. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
  1581. ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  1582. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  1583. SM(pModal->iqCalICh[i],
  1584. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  1585. SM(pModal->iqCalQCh[i],
  1586. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  1587. if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah))
  1588. ath9k_hw_def_set_gain(ah, pModal, eep, txRxAttenLocal,
  1589. regChainOffset, i);
  1590. }
  1591. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1592. if (IS_CHAN_2GHZ(chan)) {
  1593. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  1594. AR_AN_RF2G1_CH0_OB,
  1595. AR_AN_RF2G1_CH0_OB_S,
  1596. pModal->ob);
  1597. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  1598. AR_AN_RF2G1_CH0_DB,
  1599. AR_AN_RF2G1_CH0_DB_S,
  1600. pModal->db);
  1601. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  1602. AR_AN_RF2G1_CH1_OB,
  1603. AR_AN_RF2G1_CH1_OB_S,
  1604. pModal->ob_ch1);
  1605. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  1606. AR_AN_RF2G1_CH1_DB,
  1607. AR_AN_RF2G1_CH1_DB_S,
  1608. pModal->db_ch1);
  1609. } else {
  1610. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  1611. AR_AN_RF5G1_CH0_OB5,
  1612. AR_AN_RF5G1_CH0_OB5_S,
  1613. pModal->ob);
  1614. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  1615. AR_AN_RF5G1_CH0_DB5,
  1616. AR_AN_RF5G1_CH0_DB5_S,
  1617. pModal->db);
  1618. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  1619. AR_AN_RF5G1_CH1_OB5,
  1620. AR_AN_RF5G1_CH1_OB5_S,
  1621. pModal->ob_ch1);
  1622. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  1623. AR_AN_RF5G1_CH1_DB5,
  1624. AR_AN_RF5G1_CH1_DB5_S,
  1625. pModal->db_ch1);
  1626. }
  1627. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  1628. AR_AN_TOP2_XPABIAS_LVL,
  1629. AR_AN_TOP2_XPABIAS_LVL_S,
  1630. pModal->xpaBiasLvl);
  1631. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  1632. AR_AN_TOP2_LOCALBIAS,
  1633. AR_AN_TOP2_LOCALBIAS_S,
  1634. pModal->local_bias);
  1635. REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
  1636. pModal->force_xpaon);
  1637. }
  1638. REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
  1639. pModal->switchSettling);
  1640. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
  1641. pModal->adcDesiredSize);
  1642. if (!AR_SREV_9280_10_OR_LATER(ah))
  1643. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  1644. AR_PHY_DESIRED_SZ_PGA,
  1645. pModal->pgaDesiredSize);
  1646. REG_WRITE(ah, AR_PHY_RF_CTL4,
  1647. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  1648. | SM(pModal->txEndToXpaOff,
  1649. AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  1650. | SM(pModal->txFrameToXpaOn,
  1651. AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  1652. | SM(pModal->txFrameToXpaOn,
  1653. AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  1654. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  1655. pModal->txEndToRxOn);
  1656. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1657. REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
  1658. pModal->thresh62);
  1659. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  1660. AR_PHY_EXT_CCA0_THRESH62,
  1661. pModal->thresh62);
  1662. } else {
  1663. REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
  1664. pModal->thresh62);
  1665. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  1666. AR_PHY_EXT_CCA_THRESH62,
  1667. pModal->thresh62);
  1668. }
  1669. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
  1670. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  1671. AR_PHY_TX_END_DATA_START,
  1672. pModal->txFrameToDataStart);
  1673. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
  1674. pModal->txFrameToPaOn);
  1675. }
  1676. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
  1677. if (IS_CHAN_HT40(chan))
  1678. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  1679. AR_PHY_SETTLING_SWITCH,
  1680. pModal->swSettleHt40);
  1681. }
  1682. if (AR_SREV_9280_20_OR_LATER(ah) &&
  1683. AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  1684. REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL,
  1685. AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK,
  1686. pModal->miscBits);
  1687. if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) {
  1688. if (IS_CHAN_2GHZ(chan))
  1689. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
  1690. eep->baseEepHeader.dacLpMode);
  1691. else if (eep->baseEepHeader.dacHiPwrMode_5G)
  1692. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, 0);
  1693. else
  1694. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
  1695. eep->baseEepHeader.dacLpMode);
  1696. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, AR_PHY_FRAME_CTL_TX_CLIP,
  1697. pModal->miscBits >> 2);
  1698. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL9,
  1699. AR_PHY_TX_DESIRED_SCALE_CCK,
  1700. eep->baseEepHeader.desiredScaleCCK);
  1701. }
  1702. }
  1703. static void ath9k_hw_def_set_addac(struct ath_hw *ah,
  1704. struct ath9k_channel *chan)
  1705. {
  1706. #define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt])
  1707. struct modal_eep_header *pModal;
  1708. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  1709. u8 biaslevel;
  1710. if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
  1711. return;
  1712. if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
  1713. return;
  1714. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  1715. if (pModal->xpaBiasLvl != 0xff) {
  1716. biaslevel = pModal->xpaBiasLvl;
  1717. } else {
  1718. u16 resetFreqBin, freqBin, freqCount = 0;
  1719. struct chan_centers centers;
  1720. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1721. resetFreqBin = FREQ2FBIN(centers.synth_center,
  1722. IS_CHAN_2GHZ(chan));
  1723. freqBin = XPA_LVL_FREQ(0) & 0xff;
  1724. biaslevel = (u8) (XPA_LVL_FREQ(0) >> 14);
  1725. freqCount++;
  1726. while (freqCount < 3) {
  1727. if (XPA_LVL_FREQ(freqCount) == 0x0)
  1728. break;
  1729. freqBin = XPA_LVL_FREQ(freqCount) & 0xff;
  1730. if (resetFreqBin >= freqBin)
  1731. biaslevel = (u8)(XPA_LVL_FREQ(freqCount) >> 14);
  1732. else
  1733. break;
  1734. freqCount++;
  1735. }
  1736. }
  1737. if (IS_CHAN_2GHZ(chan)) {
  1738. INI_RA(&ah->iniAddac, 7, 1) = (INI_RA(&ah->iniAddac,
  1739. 7, 1) & (~0x18)) | biaslevel << 3;
  1740. } else {
  1741. INI_RA(&ah->iniAddac, 6, 1) = (INI_RA(&ah->iniAddac,
  1742. 6, 1) & (~0xc0)) | biaslevel << 6;
  1743. }
  1744. #undef XPA_LVL_FREQ
  1745. }
  1746. static void ath9k_hw_get_def_gain_boundaries_pdadcs(struct ath_hw *ah,
  1747. struct ath9k_channel *chan,
  1748. struct cal_data_per_freq *pRawDataSet,
  1749. u8 *bChans, u16 availPiers,
  1750. u16 tPdGainOverlap, int16_t *pMinCalPower,
  1751. u16 *pPdGainBoundaries, u8 *pPDADCValues,
  1752. u16 numXpdGains)
  1753. {
  1754. int i, j, k;
  1755. int16_t ss;
  1756. u16 idxL = 0, idxR = 0, numPiers;
  1757. static u8 vpdTableL[AR5416_NUM_PD_GAINS]
  1758. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  1759. static u8 vpdTableR[AR5416_NUM_PD_GAINS]
  1760. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  1761. static u8 vpdTableI[AR5416_NUM_PD_GAINS]
  1762. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  1763. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  1764. u8 minPwrT4[AR5416_NUM_PD_GAINS];
  1765. u8 maxPwrT4[AR5416_NUM_PD_GAINS];
  1766. int16_t vpdStep;
  1767. int16_t tmpVal;
  1768. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  1769. bool match;
  1770. int16_t minDelta = 0;
  1771. struct chan_centers centers;
  1772. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1773. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  1774. if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
  1775. break;
  1776. }
  1777. match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center,
  1778. IS_CHAN_2GHZ(chan)),
  1779. bChans, numPiers, &idxL, &idxR);
  1780. if (match) {
  1781. for (i = 0; i < numXpdGains; i++) {
  1782. minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
  1783. maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
  1784. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  1785. pRawDataSet[idxL].pwrPdg[i],
  1786. pRawDataSet[idxL].vpdPdg[i],
  1787. AR5416_PD_GAIN_ICEPTS,
  1788. vpdTableI[i]);
  1789. }
  1790. } else {
  1791. for (i = 0; i < numXpdGains; i++) {
  1792. pVpdL = pRawDataSet[idxL].vpdPdg[i];
  1793. pPwrL = pRawDataSet[idxL].pwrPdg[i];
  1794. pVpdR = pRawDataSet[idxR].vpdPdg[i];
  1795. pPwrR = pRawDataSet[idxR].pwrPdg[i];
  1796. minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
  1797. maxPwrT4[i] =
  1798. min(pPwrL[AR5416_PD_GAIN_ICEPTS - 1],
  1799. pPwrR[AR5416_PD_GAIN_ICEPTS - 1]);
  1800. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  1801. pPwrL, pVpdL,
  1802. AR5416_PD_GAIN_ICEPTS,
  1803. vpdTableL[i]);
  1804. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  1805. pPwrR, pVpdR,
  1806. AR5416_PD_GAIN_ICEPTS,
  1807. vpdTableR[i]);
  1808. for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
  1809. vpdTableI[i][j] =
  1810. (u8)(ath9k_hw_interpolate((u16)
  1811. FREQ2FBIN(centers.
  1812. synth_center,
  1813. IS_CHAN_2GHZ
  1814. (chan)),
  1815. bChans[idxL], bChans[idxR],
  1816. vpdTableL[i][j], vpdTableR[i][j]));
  1817. }
  1818. }
  1819. }
  1820. *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
  1821. k = 0;
  1822. for (i = 0; i < numXpdGains; i++) {
  1823. if (i == (numXpdGains - 1))
  1824. pPdGainBoundaries[i] =
  1825. (u16)(maxPwrT4[i] / 2);
  1826. else
  1827. pPdGainBoundaries[i] =
  1828. (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
  1829. pPdGainBoundaries[i] =
  1830. min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
  1831. if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
  1832. minDelta = pPdGainBoundaries[0] - 23;
  1833. pPdGainBoundaries[0] = 23;
  1834. } else {
  1835. minDelta = 0;
  1836. }
  1837. if (i == 0) {
  1838. if (AR_SREV_9280_10_OR_LATER(ah))
  1839. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  1840. else
  1841. ss = 0;
  1842. } else {
  1843. ss = (int16_t)((pPdGainBoundaries[i - 1] -
  1844. (minPwrT4[i] / 2)) -
  1845. tPdGainOverlap + 1 + minDelta);
  1846. }
  1847. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  1848. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  1849. while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  1850. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  1851. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  1852. ss++;
  1853. }
  1854. sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  1855. tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
  1856. (minPwrT4[i] / 2));
  1857. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  1858. tgtIndex : sizeCurrVpdTable;
  1859. while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  1860. pPDADCValues[k++] = vpdTableI[i][ss++];
  1861. }
  1862. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  1863. vpdTableI[i][sizeCurrVpdTable - 2]);
  1864. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  1865. if (tgtIndex > maxIndex) {
  1866. while ((ss <= tgtIndex) &&
  1867. (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  1868. tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] +
  1869. (ss - maxIndex + 1) * vpdStep));
  1870. pPDADCValues[k++] = (u8)((tmpVal > 255) ?
  1871. 255 : tmpVal);
  1872. ss++;
  1873. }
  1874. }
  1875. }
  1876. while (i < AR5416_PD_GAINS_IN_MASK) {
  1877. pPdGainBoundaries[i] = pPdGainBoundaries[i - 1];
  1878. i++;
  1879. }
  1880. while (k < AR5416_NUM_PDADC_VALUES) {
  1881. pPDADCValues[k] = pPDADCValues[k - 1];
  1882. k++;
  1883. }
  1884. return;
  1885. }
  1886. static void ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
  1887. struct ath9k_channel *chan,
  1888. int16_t *pTxPowerIndexOffset)
  1889. {
  1890. #define SM_PD_GAIN(x) SM(0x38, AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##x)
  1891. #define SM_PDGAIN_B(x, y) \
  1892. SM((gainBoundaries[x]), AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##y)
  1893. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  1894. struct cal_data_per_freq *pRawDataset;
  1895. u8 *pCalBChans = NULL;
  1896. u16 pdGainOverlap_t2;
  1897. static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
  1898. u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
  1899. u16 numPiers, i, j;
  1900. int16_t tMinCalPower;
  1901. u16 numXpdGain, xpdMask;
  1902. u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
  1903. u32 reg32, regOffset, regChainOffset;
  1904. int16_t modalIdx;
  1905. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  1906. xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
  1907. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1908. AR5416_EEP_MINOR_VER_2) {
  1909. pdGainOverlap_t2 =
  1910. pEepData->modalHeader[modalIdx].pdGainOverlap;
  1911. } else {
  1912. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  1913. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  1914. }
  1915. if (IS_CHAN_2GHZ(chan)) {
  1916. pCalBChans = pEepData->calFreqPier2G;
  1917. numPiers = AR5416_NUM_2G_CAL_PIERS;
  1918. } else {
  1919. pCalBChans = pEepData->calFreqPier5G;
  1920. numPiers = AR5416_NUM_5G_CAL_PIERS;
  1921. }
  1922. if (OLC_FOR_AR9280_20_LATER && IS_CHAN_2GHZ(chan)) {
  1923. pRawDataset = pEepData->calPierData2G[0];
  1924. ah->initPDADC = ((struct calDataPerFreqOpLoop *)
  1925. pRawDataset)->vpdPdg[0][0];
  1926. }
  1927. numXpdGain = 0;
  1928. for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
  1929. if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
  1930. if (numXpdGain >= AR5416_NUM_PD_GAINS)
  1931. break;
  1932. xpdGainValues[numXpdGain] =
  1933. (u16)(AR5416_PD_GAINS_IN_MASK - i);
  1934. numXpdGain++;
  1935. }
  1936. }
  1937. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  1938. (numXpdGain - 1) & 0x3);
  1939. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  1940. xpdGainValues[0]);
  1941. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  1942. xpdGainValues[1]);
  1943. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  1944. xpdGainValues[2]);
  1945. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  1946. if (AR_SREV_5416_20_OR_LATER(ah) &&
  1947. (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
  1948. (i != 0)) {
  1949. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  1950. } else
  1951. regChainOffset = i * 0x1000;
  1952. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  1953. if (IS_CHAN_2GHZ(chan))
  1954. pRawDataset = pEepData->calPierData2G[i];
  1955. else
  1956. pRawDataset = pEepData->calPierData5G[i];
  1957. if (OLC_FOR_AR9280_20_LATER) {
  1958. u8 pcdacIdx;
  1959. u8 txPower;
  1960. ath9k_get_txgain_index(ah, chan,
  1961. (struct calDataPerFreqOpLoop *)pRawDataset,
  1962. pCalBChans, numPiers, &txPower, &pcdacIdx);
  1963. ath9k_olc_get_pdadcs(ah, pcdacIdx,
  1964. txPower/2, pdadcValues);
  1965. } else {
  1966. ath9k_hw_get_def_gain_boundaries_pdadcs(ah,
  1967. chan, pRawDataset,
  1968. pCalBChans, numPiers,
  1969. pdGainOverlap_t2,
  1970. &tMinCalPower,
  1971. gainBoundaries,
  1972. pdadcValues,
  1973. numXpdGain);
  1974. }
  1975. if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
  1976. if (OLC_FOR_AR9280_20_LATER) {
  1977. REG_WRITE(ah,
  1978. AR_PHY_TPCRG5 + regChainOffset,
  1979. SM(0x6,
  1980. AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
  1981. SM_PD_GAIN(1) | SM_PD_GAIN(2) |
  1982. SM_PD_GAIN(3) | SM_PD_GAIN(4));
  1983. } else {
  1984. REG_WRITE(ah,
  1985. AR_PHY_TPCRG5 + regChainOffset,
  1986. SM(pdGainOverlap_t2,
  1987. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)|
  1988. SM_PDGAIN_B(0, 1) |
  1989. SM_PDGAIN_B(1, 2) |
  1990. SM_PDGAIN_B(2, 3) |
  1991. SM_PDGAIN_B(3, 4));
  1992. }
  1993. }
  1994. regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
  1995. for (j = 0; j < 32; j++) {
  1996. reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
  1997. ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
  1998. ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
  1999. ((pdadcValues[4 * j + 3] & 0xFF) << 24);
  2000. REG_WRITE(ah, regOffset, reg32);
  2001. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2002. "PDADC (%d,%4x): %4.4x %8.8x\n",
  2003. i, regChainOffset, regOffset,
  2004. reg32);
  2005. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2006. "PDADC: Chain %d | PDADC %3d "
  2007. "Value %3d | PDADC %3d Value %3d | "
  2008. "PDADC %3d Value %3d | PDADC %3d "
  2009. "Value %3d |\n",
  2010. i, 4 * j, pdadcValues[4 * j],
  2011. 4 * j + 1, pdadcValues[4 * j + 1],
  2012. 4 * j + 2, pdadcValues[4 * j + 2],
  2013. 4 * j + 3,
  2014. pdadcValues[4 * j + 3]);
  2015. regOffset += 4;
  2016. }
  2017. }
  2018. }
  2019. *pTxPowerIndexOffset = 0;
  2020. #undef SM_PD_GAIN
  2021. #undef SM_PDGAIN_B
  2022. }
  2023. static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
  2024. struct ath9k_channel *chan,
  2025. int16_t *ratesArray,
  2026. u16 cfgCtl,
  2027. u16 AntennaReduction,
  2028. u16 twiceMaxRegulatoryPower,
  2029. u16 powerLimit)
  2030. {
  2031. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */
  2032. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */
  2033. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  2034. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  2035. static const u16 tpScaleReductionTable[5] =
  2036. { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
  2037. int i;
  2038. int16_t twiceLargestAntenna;
  2039. struct cal_ctl_data *rep;
  2040. struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
  2041. 0, { 0, 0, 0, 0}
  2042. };
  2043. struct cal_target_power_leg targetPowerOfdmExt = {
  2044. 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
  2045. 0, { 0, 0, 0, 0 }
  2046. };
  2047. struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
  2048. 0, {0, 0, 0, 0}
  2049. };
  2050. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  2051. u16 ctlModesFor11a[] =
  2052. { CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40 };
  2053. u16 ctlModesFor11g[] =
  2054. { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
  2055. CTL_2GHT40
  2056. };
  2057. u16 numCtlModes, *pCtlMode, ctlMode, freq;
  2058. struct chan_centers centers;
  2059. int tx_chainmask;
  2060. u16 twiceMinEdgePower;
  2061. tx_chainmask = ah->txchainmask;
  2062. ath9k_hw_get_channel_centers(ah, chan, &centers);
  2063. twiceLargestAntenna = max(
  2064. pEepData->modalHeader
  2065. [IS_CHAN_2GHZ(chan)].antennaGainCh[0],
  2066. pEepData->modalHeader
  2067. [IS_CHAN_2GHZ(chan)].antennaGainCh[1]);
  2068. twiceLargestAntenna = max((u8)twiceLargestAntenna,
  2069. pEepData->modalHeader
  2070. [IS_CHAN_2GHZ(chan)].antennaGainCh[2]);
  2071. twiceLargestAntenna = (int16_t)min(AntennaReduction -
  2072. twiceLargestAntenna, 0);
  2073. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  2074. if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) {
  2075. maxRegAllowedPower -=
  2076. (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2);
  2077. }
  2078. scaledPower = min(powerLimit, maxRegAllowedPower);
  2079. switch (ar5416_get_ntxchains(tx_chainmask)) {
  2080. case 1:
  2081. break;
  2082. case 2:
  2083. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  2084. break;
  2085. case 3:
  2086. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  2087. break;
  2088. }
  2089. scaledPower = max((u16)0, scaledPower);
  2090. if (IS_CHAN_2GHZ(chan)) {
  2091. numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
  2092. SUB_NUM_CTL_MODES_AT_2G_40;
  2093. pCtlMode = ctlModesFor11g;
  2094. ath9k_hw_get_legacy_target_powers(ah, chan,
  2095. pEepData->calTargetPowerCck,
  2096. AR5416_NUM_2G_CCK_TARGET_POWERS,
  2097. &targetPowerCck, 4, false);
  2098. ath9k_hw_get_legacy_target_powers(ah, chan,
  2099. pEepData->calTargetPower2G,
  2100. AR5416_NUM_2G_20_TARGET_POWERS,
  2101. &targetPowerOfdm, 4, false);
  2102. ath9k_hw_get_target_powers(ah, chan,
  2103. pEepData->calTargetPower2GHT20,
  2104. AR5416_NUM_2G_20_TARGET_POWERS,
  2105. &targetPowerHt20, 8, false);
  2106. if (IS_CHAN_HT40(chan)) {
  2107. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  2108. ath9k_hw_get_target_powers(ah, chan,
  2109. pEepData->calTargetPower2GHT40,
  2110. AR5416_NUM_2G_40_TARGET_POWERS,
  2111. &targetPowerHt40, 8, true);
  2112. ath9k_hw_get_legacy_target_powers(ah, chan,
  2113. pEepData->calTargetPowerCck,
  2114. AR5416_NUM_2G_CCK_TARGET_POWERS,
  2115. &targetPowerCckExt, 4, true);
  2116. ath9k_hw_get_legacy_target_powers(ah, chan,
  2117. pEepData->calTargetPower2G,
  2118. AR5416_NUM_2G_20_TARGET_POWERS,
  2119. &targetPowerOfdmExt, 4, true);
  2120. }
  2121. } else {
  2122. numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
  2123. SUB_NUM_CTL_MODES_AT_5G_40;
  2124. pCtlMode = ctlModesFor11a;
  2125. ath9k_hw_get_legacy_target_powers(ah, chan,
  2126. pEepData->calTargetPower5G,
  2127. AR5416_NUM_5G_20_TARGET_POWERS,
  2128. &targetPowerOfdm, 4, false);
  2129. ath9k_hw_get_target_powers(ah, chan,
  2130. pEepData->calTargetPower5GHT20,
  2131. AR5416_NUM_5G_20_TARGET_POWERS,
  2132. &targetPowerHt20, 8, false);
  2133. if (IS_CHAN_HT40(chan)) {
  2134. numCtlModes = ARRAY_SIZE(ctlModesFor11a);
  2135. ath9k_hw_get_target_powers(ah, chan,
  2136. pEepData->calTargetPower5GHT40,
  2137. AR5416_NUM_5G_40_TARGET_POWERS,
  2138. &targetPowerHt40, 8, true);
  2139. ath9k_hw_get_legacy_target_powers(ah, chan,
  2140. pEepData->calTargetPower5G,
  2141. AR5416_NUM_5G_20_TARGET_POWERS,
  2142. &targetPowerOfdmExt, 4, true);
  2143. }
  2144. }
  2145. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  2146. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  2147. (pCtlMode[ctlMode] == CTL_2GHT40);
  2148. if (isHt40CtlMode)
  2149. freq = centers.synth_center;
  2150. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  2151. freq = centers.ext_center;
  2152. else
  2153. freq = centers.ctl_center;
  2154. if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
  2155. ah->eep_ops->get_eeprom_rev(ah) <= 2)
  2156. twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  2157. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2158. "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
  2159. "EXT_ADDITIVE %d\n",
  2160. ctlMode, numCtlModes, isHt40CtlMode,
  2161. (pCtlMode[ctlMode] & EXT_ADDITIVE));
  2162. for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  2163. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2164. " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
  2165. "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
  2166. "chan %d\n",
  2167. i, cfgCtl, pCtlMode[ctlMode],
  2168. pEepData->ctlIndex[i], chan->channel);
  2169. if ((((cfgCtl & ~CTL_MODE_M) |
  2170. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  2171. pEepData->ctlIndex[i]) ||
  2172. (((cfgCtl & ~CTL_MODE_M) |
  2173. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  2174. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
  2175. rep = &(pEepData->ctlData[i]);
  2176. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  2177. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
  2178. IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
  2179. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2180. " MATCH-EE_IDX %d: ch %d is2 %d "
  2181. "2xMinEdge %d chainmask %d chains %d\n",
  2182. i, freq, IS_CHAN_2GHZ(chan),
  2183. twiceMinEdgePower, tx_chainmask,
  2184. ar5416_get_ntxchains
  2185. (tx_chainmask));
  2186. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  2187. twiceMaxEdgePower = min(twiceMaxEdgePower,
  2188. twiceMinEdgePower);
  2189. } else {
  2190. twiceMaxEdgePower = twiceMinEdgePower;
  2191. break;
  2192. }
  2193. }
  2194. }
  2195. minCtlPower = min(twiceMaxEdgePower, scaledPower);
  2196. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2197. " SEL-Min ctlMode %d pCtlMode %d "
  2198. "2xMaxEdge %d sP %d minCtlPwr %d\n",
  2199. ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
  2200. scaledPower, minCtlPower);
  2201. switch (pCtlMode[ctlMode]) {
  2202. case CTL_11B:
  2203. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  2204. targetPowerCck.tPow2x[i] =
  2205. min((u16)targetPowerCck.tPow2x[i],
  2206. minCtlPower);
  2207. }
  2208. break;
  2209. case CTL_11A:
  2210. case CTL_11G:
  2211. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  2212. targetPowerOfdm.tPow2x[i] =
  2213. min((u16)targetPowerOfdm.tPow2x[i],
  2214. minCtlPower);
  2215. }
  2216. break;
  2217. case CTL_5GHT20:
  2218. case CTL_2GHT20:
  2219. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  2220. targetPowerHt20.tPow2x[i] =
  2221. min((u16)targetPowerHt20.tPow2x[i],
  2222. minCtlPower);
  2223. }
  2224. break;
  2225. case CTL_11B_EXT:
  2226. targetPowerCckExt.tPow2x[0] = min((u16)
  2227. targetPowerCckExt.tPow2x[0],
  2228. minCtlPower);
  2229. break;
  2230. case CTL_11A_EXT:
  2231. case CTL_11G_EXT:
  2232. targetPowerOfdmExt.tPow2x[0] = min((u16)
  2233. targetPowerOfdmExt.tPow2x[0],
  2234. minCtlPower);
  2235. break;
  2236. case CTL_5GHT40:
  2237. case CTL_2GHT40:
  2238. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  2239. targetPowerHt40.tPow2x[i] =
  2240. min((u16)targetPowerHt40.tPow2x[i],
  2241. minCtlPower);
  2242. }
  2243. break;
  2244. default:
  2245. break;
  2246. }
  2247. }
  2248. ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
  2249. ratesArray[rate18mb] = ratesArray[rate24mb] =
  2250. targetPowerOfdm.tPow2x[0];
  2251. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  2252. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  2253. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  2254. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  2255. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  2256. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  2257. if (IS_CHAN_2GHZ(chan)) {
  2258. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  2259. ratesArray[rate2s] = ratesArray[rate2l] =
  2260. targetPowerCck.tPow2x[1];
  2261. ratesArray[rate5_5s] = ratesArray[rate5_5l] =
  2262. targetPowerCck.tPow2x[2];
  2263. ratesArray[rate11s] = ratesArray[rate11l] =
  2264. targetPowerCck.tPow2x[3];
  2265. }
  2266. if (IS_CHAN_HT40(chan)) {
  2267. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  2268. ratesArray[rateHt40_0 + i] =
  2269. targetPowerHt40.tPow2x[i];
  2270. }
  2271. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  2272. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  2273. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  2274. if (IS_CHAN_2GHZ(chan)) {
  2275. ratesArray[rateExtCck] =
  2276. targetPowerCckExt.tPow2x[0];
  2277. }
  2278. }
  2279. }
  2280. static void ath9k_hw_def_set_txpower(struct ath_hw *ah,
  2281. struct ath9k_channel *chan,
  2282. u16 cfgCtl,
  2283. u8 twiceAntennaReduction,
  2284. u8 twiceMaxRegulatoryPower,
  2285. u8 powerLimit)
  2286. {
  2287. #define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
  2288. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  2289. struct modal_eep_header *pModal =
  2290. &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
  2291. int16_t ratesArray[Ar5416RateSize];
  2292. int16_t txPowerIndexOffset = 0;
  2293. u8 ht40PowerIncForPdadc = 2;
  2294. int i, cck_ofdm_delta = 0;
  2295. memset(ratesArray, 0, sizeof(ratesArray));
  2296. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  2297. AR5416_EEP_MINOR_VER_2) {
  2298. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  2299. }
  2300. ath9k_hw_set_def_power_per_rate_table(ah, chan,
  2301. &ratesArray[0], cfgCtl,
  2302. twiceAntennaReduction,
  2303. twiceMaxRegulatoryPower,
  2304. powerLimit);
  2305. ath9k_hw_set_def_power_cal_table(ah, chan, &txPowerIndexOffset);
  2306. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  2307. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  2308. if (ratesArray[i] > AR5416_MAX_RATE_POWER)
  2309. ratesArray[i] = AR5416_MAX_RATE_POWER;
  2310. }
  2311. if (AR_SREV_9280_10_OR_LATER(ah)) {
  2312. for (i = 0; i < Ar5416RateSize; i++)
  2313. ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
  2314. }
  2315. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  2316. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  2317. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  2318. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  2319. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  2320. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  2321. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  2322. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  2323. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  2324. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  2325. if (IS_CHAN_2GHZ(chan)) {
  2326. if (OLC_FOR_AR9280_20_LATER) {
  2327. cck_ofdm_delta = 2;
  2328. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  2329. ATH9K_POW_SM(RT_AR_DELTA(rate2s), 24)
  2330. | ATH9K_POW_SM(RT_AR_DELTA(rate2l), 16)
  2331. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  2332. | ATH9K_POW_SM(RT_AR_DELTA(rate1l), 0));
  2333. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  2334. ATH9K_POW_SM(RT_AR_DELTA(rate11s), 24)
  2335. | ATH9K_POW_SM(RT_AR_DELTA(rate11l), 16)
  2336. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5s), 8)
  2337. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5l), 0));
  2338. } else {
  2339. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  2340. ATH9K_POW_SM(ratesArray[rate2s], 24)
  2341. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  2342. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  2343. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  2344. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  2345. ATH9K_POW_SM(ratesArray[rate11s], 24)
  2346. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  2347. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  2348. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  2349. }
  2350. }
  2351. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  2352. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  2353. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  2354. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  2355. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  2356. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  2357. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  2358. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  2359. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  2360. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  2361. if (IS_CHAN_HT40(chan)) {
  2362. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  2363. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  2364. ht40PowerIncForPdadc, 24)
  2365. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  2366. ht40PowerIncForPdadc, 16)
  2367. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  2368. ht40PowerIncForPdadc, 8)
  2369. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  2370. ht40PowerIncForPdadc, 0));
  2371. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  2372. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  2373. ht40PowerIncForPdadc, 24)
  2374. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  2375. ht40PowerIncForPdadc, 16)
  2376. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  2377. ht40PowerIncForPdadc, 8)
  2378. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  2379. ht40PowerIncForPdadc, 0));
  2380. if (OLC_FOR_AR9280_20_LATER) {
  2381. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  2382. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  2383. | ATH9K_POW_SM(RT_AR_DELTA(rateExtCck), 16)
  2384. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  2385. | ATH9K_POW_SM(RT_AR_DELTA(rateDupCck), 0));
  2386. } else {
  2387. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  2388. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  2389. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  2390. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  2391. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  2392. }
  2393. }
  2394. REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
  2395. ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
  2396. | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
  2397. i = rate6mb;
  2398. if (IS_CHAN_HT40(chan))
  2399. i = rateHt40_0;
  2400. else if (IS_CHAN_HT20(chan))
  2401. i = rateHt20_0;
  2402. if (AR_SREV_9280_10_OR_LATER(ah))
  2403. ah->regulatory.max_power_level =
  2404. ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
  2405. else
  2406. ah->regulatory.max_power_level = ratesArray[i];
  2407. switch(ar5416_get_ntxchains(ah->txchainmask)) {
  2408. case 1:
  2409. break;
  2410. case 2:
  2411. ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
  2412. break;
  2413. case 3:
  2414. ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
  2415. break;
  2416. default:
  2417. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2418. "Invalid chainmask configuration\n");
  2419. break;
  2420. }
  2421. }
  2422. static u8 ath9k_hw_def_get_num_ant_config(struct ath_hw *ah,
  2423. enum ieee80211_band freq_band)
  2424. {
  2425. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  2426. struct modal_eep_header *pModal =
  2427. &(eep->modalHeader[ATH9K_HAL_FREQ_BAND_2GHZ == freq_band]);
  2428. struct base_eep_header *pBase = &eep->baseEepHeader;
  2429. u8 num_ant_config;
  2430. num_ant_config = 1;
  2431. if (pBase->version >= 0x0E0D)
  2432. if (pModal->useAnt1)
  2433. num_ant_config += 1;
  2434. return num_ant_config;
  2435. }
  2436. static u16 ath9k_hw_def_get_eeprom_antenna_cfg(struct ath_hw *ah,
  2437. struct ath9k_channel *chan)
  2438. {
  2439. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  2440. struct modal_eep_header *pModal =
  2441. &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  2442. return pModal->antCtrlCommon & 0xFFFF;
  2443. }
  2444. static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
  2445. {
  2446. #define EEP_DEF_SPURCHAN \
  2447. (ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan)
  2448. u16 spur_val = AR_NO_SPUR;
  2449. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  2450. "Getting spur idx %d is2Ghz. %d val %x\n",
  2451. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  2452. switch (ah->config.spurmode) {
  2453. case SPUR_DISABLE:
  2454. break;
  2455. case SPUR_ENABLE_IOCTL:
  2456. spur_val = ah->config.spurchans[i][is2GHz];
  2457. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  2458. "Getting spur val from new loc. %d\n", spur_val);
  2459. break;
  2460. case SPUR_ENABLE_EEPROM:
  2461. spur_val = EEP_DEF_SPURCHAN;
  2462. break;
  2463. }
  2464. return spur_val;
  2465. #undef EEP_DEF_SPURCHAN
  2466. }
  2467. static struct eeprom_ops eep_def_ops = {
  2468. .check_eeprom = ath9k_hw_def_check_eeprom,
  2469. .get_eeprom = ath9k_hw_def_get_eeprom,
  2470. .fill_eeprom = ath9k_hw_def_fill_eeprom,
  2471. .get_eeprom_ver = ath9k_hw_def_get_eeprom_ver,
  2472. .get_eeprom_rev = ath9k_hw_def_get_eeprom_rev,
  2473. .get_num_ant_config = ath9k_hw_def_get_num_ant_config,
  2474. .get_eeprom_antenna_cfg = ath9k_hw_def_get_eeprom_antenna_cfg,
  2475. .set_board_values = ath9k_hw_def_set_board_values,
  2476. .set_addac = ath9k_hw_def_set_addac,
  2477. .set_txpower = ath9k_hw_def_set_txpower,
  2478. .get_spur_channel = ath9k_hw_def_get_spur_channel
  2479. };
  2480. static int ath9k_hw_AR9287_get_eeprom_ver(struct ath_hw *ah)
  2481. {
  2482. return (ah->eeprom.map9287.baseEepHeader.version >> 12) & 0xF;
  2483. }
  2484. static int ath9k_hw_AR9287_get_eeprom_rev(struct ath_hw *ah)
  2485. {
  2486. return (ah->eeprom.map9287.baseEepHeader.version) & 0xFFF;
  2487. }
  2488. static bool ath9k_hw_AR9287_fill_eeprom(struct ath_hw *ah)
  2489. {
  2490. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  2491. u16 *eep_data;
  2492. int addr, eep_start_loc = AR9287_EEP_START_LOC;
  2493. eep_data = (u16 *)eep;
  2494. if (!ath9k_hw_use_flash(ah)) {
  2495. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2496. "Reading from EEPROM, not flash\n");
  2497. }
  2498. for (addr = 0; addr < sizeof(struct ar9287_eeprom) / sizeof(u16);
  2499. addr++) {
  2500. if (!ath9k_hw_nvram_read(ah, addr + eep_start_loc, eep_data)) {
  2501. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2502. "Unable to read eeprom region \n");
  2503. return false;
  2504. }
  2505. eep_data++;
  2506. }
  2507. return true;
  2508. }
  2509. static int ath9k_hw_AR9287_check_eeprom(struct ath_hw *ah)
  2510. {
  2511. u32 sum = 0, el, integer;
  2512. u16 temp, word, magic, magic2, *eepdata;
  2513. int i, addr;
  2514. bool need_swap = false;
  2515. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  2516. if (!ath9k_hw_use_flash(ah)) {
  2517. if (!ath9k_hw_nvram_read
  2518. (ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
  2519. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  2520. "Reading Magic # failed\n");
  2521. return false;
  2522. }
  2523. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2524. "Read Magic = 0x%04X\n", magic);
  2525. if (magic != AR5416_EEPROM_MAGIC) {
  2526. magic2 = swab16(magic);
  2527. if (magic2 == AR5416_EEPROM_MAGIC) {
  2528. need_swap = true;
  2529. eepdata = (u16 *)(&ah->eeprom);
  2530. for (addr = 0;
  2531. addr < sizeof(struct ar9287_eeprom) / sizeof(u16);
  2532. addr++) {
  2533. temp = swab16(*eepdata);
  2534. *eepdata = temp;
  2535. eepdata++;
  2536. }
  2537. } else {
  2538. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  2539. "Invalid EEPROM Magic. "
  2540. "endianness mismatch.\n");
  2541. return -EINVAL; }
  2542. }
  2543. }
  2544. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n", need_swap ?
  2545. "True" : "False");
  2546. if (need_swap)
  2547. el = swab16(ah->eeprom.map9287.baseEepHeader.length);
  2548. else
  2549. el = ah->eeprom.map9287.baseEepHeader.length;
  2550. if (el > sizeof(struct ar9287_eeprom))
  2551. el = sizeof(struct ar9287_eeprom) / sizeof(u16);
  2552. else
  2553. el = el / sizeof(u16);
  2554. eepdata = (u16 *)(&ah->eeprom);
  2555. for (i = 0; i < el; i++)
  2556. sum ^= *eepdata++;
  2557. if (need_swap) {
  2558. word = swab16(eep->baseEepHeader.length);
  2559. eep->baseEepHeader.length = word;
  2560. word = swab16(eep->baseEepHeader.checksum);
  2561. eep->baseEepHeader.checksum = word;
  2562. word = swab16(eep->baseEepHeader.version);
  2563. eep->baseEepHeader.version = word;
  2564. word = swab16(eep->baseEepHeader.regDmn[0]);
  2565. eep->baseEepHeader.regDmn[0] = word;
  2566. word = swab16(eep->baseEepHeader.regDmn[1]);
  2567. eep->baseEepHeader.regDmn[1] = word;
  2568. word = swab16(eep->baseEepHeader.rfSilent);
  2569. eep->baseEepHeader.rfSilent = word;
  2570. word = swab16(eep->baseEepHeader.blueToothOptions);
  2571. eep->baseEepHeader.blueToothOptions = word;
  2572. word = swab16(eep->baseEepHeader.deviceCap);
  2573. eep->baseEepHeader.deviceCap = word;
  2574. integer = swab32(eep->modalHeader.antCtrlCommon);
  2575. eep->modalHeader.antCtrlCommon = integer;
  2576. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  2577. integer = swab32(eep->modalHeader.antCtrlChain[i]);
  2578. eep->modalHeader.antCtrlChain[i] = integer;
  2579. }
  2580. for (i = 0; i < AR9287_EEPROM_MODAL_SPURS; i++) {
  2581. word = swab16(eep->modalHeader.spurChans[i].spurChan);
  2582. eep->modalHeader.spurChans[i].spurChan = word;
  2583. }
  2584. }
  2585. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR9287_EEP_VER
  2586. || ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  2587. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  2588. "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  2589. sum, ah->eep_ops->get_eeprom_ver(ah));
  2590. return -EINVAL;
  2591. }
  2592. return 0;
  2593. }
  2594. static u32 ath9k_hw_AR9287_get_eeprom(struct ath_hw *ah,
  2595. enum eeprom_param param)
  2596. {
  2597. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  2598. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  2599. struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
  2600. u16 ver_minor;
  2601. ver_minor = pBase->version & AR9287_EEP_VER_MINOR_MASK;
  2602. switch (param) {
  2603. case EEP_NFTHRESH_2:
  2604. return pModal->noiseFloorThreshCh[0];
  2605. case AR_EEPROM_MAC(0):
  2606. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  2607. case AR_EEPROM_MAC(1):
  2608. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  2609. case AR_EEPROM_MAC(2):
  2610. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  2611. case EEP_REG_0:
  2612. return pBase->regDmn[0];
  2613. case EEP_REG_1:
  2614. return pBase->regDmn[1];
  2615. case EEP_OP_CAP:
  2616. return pBase->deviceCap;
  2617. case EEP_OP_MODE:
  2618. return pBase->opCapFlags;
  2619. case EEP_RF_SILENT:
  2620. return pBase->rfSilent;
  2621. case EEP_MINOR_REV:
  2622. return ver_minor;
  2623. case EEP_TX_MASK:
  2624. return pBase->txMask;
  2625. case EEP_RX_MASK:
  2626. return pBase->rxMask;
  2627. case EEP_DEV_TYPE:
  2628. return pBase->deviceType;
  2629. case EEP_OL_PWRCTRL:
  2630. return pBase->openLoopPwrCntl;
  2631. case EEP_TEMPSENSE_SLOPE:
  2632. if (ver_minor >= AR9287_EEP_MINOR_VER_2)
  2633. return pBase->tempSensSlope;
  2634. else
  2635. return 0;
  2636. case EEP_TEMPSENSE_SLOPE_PAL_ON:
  2637. if (ver_minor >= AR9287_EEP_MINOR_VER_3)
  2638. return pBase->tempSensSlopePalOn;
  2639. else
  2640. return 0;
  2641. default:
  2642. return 0;
  2643. }
  2644. }
  2645. static void ath9k_hw_get_AR9287_gain_boundaries_pdadcs(struct ath_hw *ah,
  2646. struct ath9k_channel *chan,
  2647. struct cal_data_per_freq_ar9287 *pRawDataSet,
  2648. u8 *bChans, u16 availPiers,
  2649. u16 tPdGainOverlap, int16_t *pMinCalPower,
  2650. u16 *pPdGainBoundaries, u8 *pPDADCValues,
  2651. u16 numXpdGains)
  2652. {
  2653. #define TMP_VAL_VPD_TABLE \
  2654. ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep));
  2655. int i, j, k;
  2656. int16_t ss;
  2657. u16 idxL = 0, idxR = 0, numPiers;
  2658. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  2659. u8 minPwrT4[AR9287_NUM_PD_GAINS];
  2660. u8 maxPwrT4[AR9287_NUM_PD_GAINS];
  2661. int16_t vpdStep;
  2662. int16_t tmpVal;
  2663. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  2664. bool match;
  2665. int16_t minDelta = 0;
  2666. struct chan_centers centers;
  2667. static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS]
  2668. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  2669. static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS]
  2670. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  2671. static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS]
  2672. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  2673. ath9k_hw_get_channel_centers(ah, chan, &centers);
  2674. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  2675. if (bChans[numPiers] == AR9287_BCHAN_UNUSED)
  2676. break;
  2677. }
  2678. match = ath9k_hw_get_lower_upper_index(
  2679. (u8)FREQ2FBIN(centers.synth_center,
  2680. IS_CHAN_2GHZ(chan)), bChans, numPiers,
  2681. &idxL, &idxR);
  2682. if (match) {
  2683. for (i = 0; i < numXpdGains; i++) {
  2684. minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
  2685. maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
  2686. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  2687. pRawDataSet[idxL].pwrPdg[i],
  2688. pRawDataSet[idxL].vpdPdg[i],
  2689. AR9287_PD_GAIN_ICEPTS, vpdTableI[i]);
  2690. }
  2691. } else {
  2692. for (i = 0; i < numXpdGains; i++) {
  2693. pVpdL = pRawDataSet[idxL].vpdPdg[i];
  2694. pPwrL = pRawDataSet[idxL].pwrPdg[i];
  2695. pVpdR = pRawDataSet[idxR].vpdPdg[i];
  2696. pPwrR = pRawDataSet[idxR].pwrPdg[i];
  2697. minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
  2698. maxPwrT4[i] =
  2699. min(pPwrL[AR9287_PD_GAIN_ICEPTS - 1],
  2700. pPwrR[AR9287_PD_GAIN_ICEPTS - 1]);
  2701. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  2702. pPwrL, pVpdL,
  2703. AR9287_PD_GAIN_ICEPTS,
  2704. vpdTableL[i]);
  2705. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  2706. pPwrR, pVpdR,
  2707. AR9287_PD_GAIN_ICEPTS,
  2708. vpdTableR[i]);
  2709. for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
  2710. vpdTableI[i][j] =
  2711. (u8)(ath9k_hw_interpolate((u16)
  2712. FREQ2FBIN(centers. synth_center,
  2713. IS_CHAN_2GHZ(chan)),
  2714. bChans[idxL], bChans[idxR],
  2715. vpdTableL[i][j], vpdTableR[i][j]));
  2716. }
  2717. }
  2718. }
  2719. *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
  2720. k = 0;
  2721. for (i = 0; i < numXpdGains; i++) {
  2722. if (i == (numXpdGains - 1))
  2723. pPdGainBoundaries[i] = (u16)(maxPwrT4[i] / 2);
  2724. else
  2725. pPdGainBoundaries[i] = (u16)((maxPwrT4[i] +
  2726. minPwrT4[i+1]) / 4);
  2727. pPdGainBoundaries[i] = min((u16)AR5416_MAX_RATE_POWER,
  2728. pPdGainBoundaries[i]);
  2729. if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
  2730. minDelta = pPdGainBoundaries[0] - 23;
  2731. pPdGainBoundaries[0] = 23;
  2732. } else
  2733. minDelta = 0;
  2734. if (i == 0) {
  2735. if (AR_SREV_9280_10_OR_LATER(ah))
  2736. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  2737. else
  2738. ss = 0;
  2739. } else
  2740. ss = (int16_t)((pPdGainBoundaries[i-1] -
  2741. (minPwrT4[i] / 2)) -
  2742. tPdGainOverlap + 1 + minDelta);
  2743. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  2744. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  2745. while ((ss < 0) && (k < (AR9287_NUM_PDADC_VALUES - 1))) {
  2746. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  2747. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  2748. ss++;
  2749. }
  2750. sizeCurrVpdTable = (u8)((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  2751. tgtIndex = (u8)(pPdGainBoundaries[i] +
  2752. tPdGainOverlap - (minPwrT4[i] / 2));
  2753. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  2754. tgtIndex : sizeCurrVpdTable;
  2755. while ((ss < maxIndex) && (k < (AR9287_NUM_PDADC_VALUES - 1)))
  2756. pPDADCValues[k++] = vpdTableI[i][ss++];
  2757. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  2758. vpdTableI[i][sizeCurrVpdTable - 2]);
  2759. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  2760. if (tgtIndex > maxIndex) {
  2761. while ((ss <= tgtIndex) &&
  2762. (k < (AR9287_NUM_PDADC_VALUES - 1))) {
  2763. tmpVal = (int16_t) TMP_VAL_VPD_TABLE;
  2764. pPDADCValues[k++] = (u8)((tmpVal > 255) ?
  2765. 255 : tmpVal);
  2766. ss++;
  2767. }
  2768. }
  2769. }
  2770. while (i < AR9287_PD_GAINS_IN_MASK) {
  2771. pPdGainBoundaries[i] = pPdGainBoundaries[i-1];
  2772. i++;
  2773. }
  2774. while (k < AR9287_NUM_PDADC_VALUES) {
  2775. pPDADCValues[k] = pPDADCValues[k-1];
  2776. k++;
  2777. }
  2778. #undef TMP_VAL_VPD_TABLE
  2779. }
  2780. static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah,
  2781. struct ath9k_channel *chan,
  2782. struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop,
  2783. u8 *pCalChans, u16 availPiers,
  2784. int8_t *pPwr)
  2785. {
  2786. u8 pcdac, i = 0;
  2787. u16 idxL = 0, idxR = 0, numPiers;
  2788. bool match;
  2789. struct chan_centers centers;
  2790. ath9k_hw_get_channel_centers(ah, chan, &centers);
  2791. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  2792. if (pCalChans[numPiers] == AR9287_BCHAN_UNUSED)
  2793. break;
  2794. }
  2795. match = ath9k_hw_get_lower_upper_index(
  2796. (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
  2797. pCalChans, numPiers,
  2798. &idxL, &idxR);
  2799. if (match) {
  2800. pcdac = pRawDatasetOpLoop[idxL].pcdac[0][0];
  2801. *pPwr = pRawDatasetOpLoop[idxL].pwrPdg[0][0];
  2802. } else {
  2803. pcdac = pRawDatasetOpLoop[idxR].pcdac[0][0];
  2804. *pPwr = (pRawDatasetOpLoop[idxL].pwrPdg[0][0] +
  2805. pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
  2806. }
  2807. while ((pcdac > ah->originalGain[i]) &&
  2808. (i < (AR9280_TX_GAIN_TABLE_SIZE - 1)))
  2809. i++;
  2810. }
  2811. static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah,
  2812. int32_t txPower, u16 chain)
  2813. {
  2814. u32 tmpVal;
  2815. u32 a;
  2816. tmpVal = REG_READ(ah, 0xa270);
  2817. tmpVal = tmpVal & 0xFCFFFFFF;
  2818. tmpVal = tmpVal | (0x3 << 24);
  2819. REG_WRITE(ah, 0xa270, tmpVal);
  2820. tmpVal = REG_READ(ah, 0xb270);
  2821. tmpVal = tmpVal & 0xFCFFFFFF;
  2822. tmpVal = tmpVal | (0x3 << 24);
  2823. REG_WRITE(ah, 0xb270, tmpVal);
  2824. if (chain == 0) {
  2825. tmpVal = REG_READ(ah, 0xa398);
  2826. tmpVal = tmpVal & 0xff00ffff;
  2827. a = (txPower)&0xff;
  2828. tmpVal = tmpVal | (a << 16);
  2829. REG_WRITE(ah, 0xa398, tmpVal);
  2830. }
  2831. if (chain == 1) {
  2832. tmpVal = REG_READ(ah, 0xb398);
  2833. tmpVal = tmpVal & 0xff00ffff;
  2834. a = (txPower)&0xff;
  2835. tmpVal = tmpVal | (a << 16);
  2836. REG_WRITE(ah, 0xb398, tmpVal);
  2837. }
  2838. }
  2839. static void ath9k_hw_set_AR9287_power_cal_table(struct ath_hw *ah,
  2840. struct ath9k_channel *chan,
  2841. int16_t *pTxPowerIndexOffset)
  2842. {
  2843. struct cal_data_per_freq_ar9287 *pRawDataset;
  2844. struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
  2845. u8 *pCalBChans = NULL;
  2846. u16 pdGainOverlap_t2;
  2847. u8 pdadcValues[AR9287_NUM_PDADC_VALUES];
  2848. u16 gainBoundaries[AR9287_PD_GAINS_IN_MASK];
  2849. u16 numPiers = 0, i, j;
  2850. int16_t tMinCalPower;
  2851. u16 numXpdGain, xpdMask;
  2852. u16 xpdGainValues[AR9287_NUM_PD_GAINS] = {0, 0, 0, 0};
  2853. u32 reg32, regOffset, regChainOffset;
  2854. int16_t modalIdx, diff = 0;
  2855. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  2856. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  2857. xpdMask = pEepData->modalHeader.xpdGain;
  2858. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  2859. AR9287_EEP_MINOR_VER_2)
  2860. pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
  2861. else
  2862. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  2863. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  2864. if (IS_CHAN_2GHZ(chan)) {
  2865. pCalBChans = pEepData->calFreqPier2G;
  2866. numPiers = AR9287_NUM_2G_CAL_PIERS;
  2867. if (ath9k_hw_AR9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  2868. pRawDatasetOpenLoop =
  2869. (struct cal_data_op_loop_ar9287 *)
  2870. pEepData->calPierData2G[0];
  2871. ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
  2872. }
  2873. }
  2874. numXpdGain = 0;
  2875. for (i = 1; i <= AR9287_PD_GAINS_IN_MASK; i++) {
  2876. if ((xpdMask >> (AR9287_PD_GAINS_IN_MASK - i)) & 1) {
  2877. if (numXpdGain >= AR9287_NUM_PD_GAINS)
  2878. break;
  2879. xpdGainValues[numXpdGain] =
  2880. (u16)(AR9287_PD_GAINS_IN_MASK-i);
  2881. numXpdGain++;
  2882. }
  2883. }
  2884. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  2885. (numXpdGain - 1) & 0x3);
  2886. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  2887. xpdGainValues[0]);
  2888. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  2889. xpdGainValues[1]);
  2890. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  2891. xpdGainValues[2]);
  2892. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  2893. regChainOffset = i * 0x1000;
  2894. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  2895. pRawDatasetOpenLoop = (struct cal_data_op_loop_ar9287 *)
  2896. pEepData->calPierData2G[i];
  2897. if (ath9k_hw_AR9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  2898. int8_t txPower;
  2899. ar9287_eeprom_get_tx_gain_index(ah, chan,
  2900. pRawDatasetOpenLoop,
  2901. pCalBChans, numPiers,
  2902. &txPower);
  2903. ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i);
  2904. } else {
  2905. pRawDataset =
  2906. (struct cal_data_per_freq_ar9287 *)
  2907. pEepData->calPierData2G[i];
  2908. ath9k_hw_get_AR9287_gain_boundaries_pdadcs(
  2909. ah, chan, pRawDataset,
  2910. pCalBChans, numPiers,
  2911. pdGainOverlap_t2,
  2912. &tMinCalPower, gainBoundaries,
  2913. pdadcValues, numXpdGain);
  2914. }
  2915. if (i == 0) {
  2916. if (!ath9k_hw_AR9287_get_eeprom(
  2917. ah, EEP_OL_PWRCTRL)) {
  2918. REG_WRITE(ah, AR_PHY_TPCRG5 +
  2919. regChainOffset,
  2920. SM(pdGainOverlap_t2,
  2921. AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
  2922. SM(gainBoundaries[0],
  2923. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
  2924. | SM(gainBoundaries[1],
  2925. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
  2926. | SM(gainBoundaries[2],
  2927. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
  2928. | SM(gainBoundaries[3],
  2929. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
  2930. }
  2931. }
  2932. if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB !=
  2933. pEepData->baseEepHeader.pwrTableOffset) {
  2934. diff = (u16)
  2935. (pEepData->baseEepHeader.pwrTableOffset
  2936. - (int32_t)AR9287_PWR_TABLE_OFFSET_DB);
  2937. diff *= 2;
  2938. for (j = 0;
  2939. j < ((u16)AR9287_NUM_PDADC_VALUES-diff);
  2940. j++)
  2941. pdadcValues[j] = pdadcValues[j+diff];
  2942. for (j = (u16)(AR9287_NUM_PDADC_VALUES-diff);
  2943. j < AR9287_NUM_PDADC_VALUES; j++)
  2944. pdadcValues[j] =
  2945. pdadcValues[
  2946. AR9287_NUM_PDADC_VALUES-diff];
  2947. }
  2948. if (!ath9k_hw_AR9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  2949. regOffset = AR_PHY_BASE + (672 << 2) +
  2950. regChainOffset;
  2951. for (j = 0; j < 32; j++) {
  2952. reg32 = ((pdadcValues[4*j + 0]
  2953. & 0xFF) << 0) |
  2954. ((pdadcValues[4*j + 1]
  2955. & 0xFF) << 8) |
  2956. ((pdadcValues[4*j + 2]
  2957. & 0xFF) << 16) |
  2958. ((pdadcValues[4*j + 3]
  2959. & 0xFF) << 24) ;
  2960. REG_WRITE(ah, regOffset, reg32);
  2961. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2962. "PDADC (%d,%4x): %4.4x %8.8x\n",
  2963. i, regChainOffset, regOffset,
  2964. reg32);
  2965. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2966. "PDADC: Chain %d | "
  2967. "PDADC %3d Value %3d | "
  2968. "PDADC %3d Value %3d | "
  2969. "PDADC %3d Value %3d | "
  2970. "PDADC %3d Value %3d |\n",
  2971. i, 4 * j, pdadcValues[4 * j],
  2972. 4 * j + 1,
  2973. pdadcValues[4 * j + 1],
  2974. 4 * j + 2,
  2975. pdadcValues[4 * j + 2],
  2976. 4 * j + 3,
  2977. pdadcValues[4 * j + 3]);
  2978. regOffset += 4;
  2979. }
  2980. }
  2981. }
  2982. }
  2983. *pTxPowerIndexOffset = 0;
  2984. }
  2985. static void ath9k_hw_set_AR9287_power_per_rate_table(struct ath_hw *ah,
  2986. struct ath9k_channel *chan, int16_t *ratesArray, u16 cfgCtl,
  2987. u16 AntennaReduction, u16 twiceMaxRegulatoryPower,
  2988. u16 powerLimit)
  2989. {
  2990. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
  2991. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
  2992. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  2993. static const u16 tpScaleReductionTable[5] =
  2994. { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
  2995. int i;
  2996. int16_t twiceLargestAntenna;
  2997. struct cal_ctl_data_ar9287 *rep;
  2998. struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
  2999. targetPowerCck = {0, {0, 0, 0, 0} };
  3000. struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
  3001. targetPowerCckExt = {0, {0, 0, 0, 0} };
  3002. struct cal_target_power_ht targetPowerHt20,
  3003. targetPowerHt40 = {0, {0, 0, 0, 0} };
  3004. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  3005. u16 ctlModesFor11g[] =
  3006. {CTL_11B, CTL_11G, CTL_2GHT20,
  3007. CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40};
  3008. u16 numCtlModes = 0, *pCtlMode = NULL, ctlMode, freq;
  3009. struct chan_centers centers;
  3010. int tx_chainmask;
  3011. u16 twiceMinEdgePower;
  3012. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  3013. tx_chainmask = ah->txchainmask;
  3014. ath9k_hw_get_channel_centers(ah, chan, &centers);
  3015. twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
  3016. pEepData->modalHeader.antennaGainCh[1]);
  3017. twiceLargestAntenna = (int16_t)min((AntennaReduction) -
  3018. twiceLargestAntenna, 0);
  3019. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  3020. if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX)
  3021. maxRegAllowedPower -=
  3022. (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2);
  3023. scaledPower = min(powerLimit, maxRegAllowedPower);
  3024. switch (ar5416_get_ntxchains(tx_chainmask)) {
  3025. case 1:
  3026. break;
  3027. case 2:
  3028. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  3029. break;
  3030. case 3:
  3031. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  3032. break;
  3033. }
  3034. scaledPower = max((u16)0, scaledPower);
  3035. if (IS_CHAN_2GHZ(chan)) {
  3036. numCtlModes =
  3037. ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
  3038. pCtlMode = ctlModesFor11g;
  3039. ath9k_hw_get_legacy_target_powers(ah, chan,
  3040. pEepData->calTargetPowerCck,
  3041. AR9287_NUM_2G_CCK_TARGET_POWERS,
  3042. &targetPowerCck, 4, false);
  3043. ath9k_hw_get_legacy_target_powers(ah, chan,
  3044. pEepData->calTargetPower2G,
  3045. AR9287_NUM_2G_20_TARGET_POWERS,
  3046. &targetPowerOfdm, 4, false);
  3047. ath9k_hw_get_target_powers(ah, chan,
  3048. pEepData->calTargetPower2GHT20,
  3049. AR9287_NUM_2G_20_TARGET_POWERS,
  3050. &targetPowerHt20, 8, false);
  3051. if (IS_CHAN_HT40(chan)) {
  3052. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  3053. ath9k_hw_get_target_powers(ah, chan,
  3054. pEepData->calTargetPower2GHT40,
  3055. AR9287_NUM_2G_40_TARGET_POWERS,
  3056. &targetPowerHt40, 8, true);
  3057. ath9k_hw_get_legacy_target_powers(ah, chan,
  3058. pEepData->calTargetPowerCck,
  3059. AR9287_NUM_2G_CCK_TARGET_POWERS,
  3060. &targetPowerCckExt, 4, true);
  3061. ath9k_hw_get_legacy_target_powers(ah, chan,
  3062. pEepData->calTargetPower2G,
  3063. AR9287_NUM_2G_20_TARGET_POWERS,
  3064. &targetPowerOfdmExt, 4, true);
  3065. }
  3066. }
  3067. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  3068. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  3069. (pCtlMode[ctlMode] == CTL_2GHT40);
  3070. if (isHt40CtlMode)
  3071. freq = centers.synth_center;
  3072. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  3073. freq = centers.ext_center;
  3074. else
  3075. freq = centers.ctl_center;
  3076. if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
  3077. ah->eep_ops->get_eeprom_rev(ah) <= 2)
  3078. twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  3079. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  3080. "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d,"
  3081. "EXT_ADDITIVE %d\n", ctlMode, numCtlModes,
  3082. isHt40CtlMode, (pCtlMode[ctlMode] & EXT_ADDITIVE));
  3083. for (i = 0; (i < AR9287_NUM_CTLS)
  3084. && pEepData->ctlIndex[i]; i++) {
  3085. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  3086. "LOOP-Ctlidx %d: cfgCtl 0x%2.2x"
  3087. "pCtlMode 0x%2.2x ctlIndex 0x%2.2x"
  3088. "chan %d chanctl=xxxx\n",
  3089. i, cfgCtl, pCtlMode[ctlMode],
  3090. pEepData->ctlIndex[i], chan->channel);
  3091. if ((((cfgCtl & ~CTL_MODE_M) |
  3092. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  3093. pEepData->ctlIndex[i]) ||
  3094. (((cfgCtl & ~CTL_MODE_M) |
  3095. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  3096. ((pEepData->ctlIndex[i] &
  3097. CTL_MODE_M) | SD_NO_CTL))) {
  3098. rep = &(pEepData->ctlData[i]);
  3099. twiceMinEdgePower = ath9k_hw_get_max_edge_power(
  3100. freq,
  3101. rep->ctlEdges[ar5416_get_ntxchains(
  3102. tx_chainmask) - 1],
  3103. IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
  3104. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  3105. "MATCH-EE_IDX %d: ch %d is2 %d"
  3106. "2xMinEdge %d chainmask %d chains %d\n",
  3107. i, freq, IS_CHAN_2GHZ(chan),
  3108. twiceMinEdgePower, tx_chainmask,
  3109. ar5416_get_ntxchains(tx_chainmask));
  3110. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL)
  3111. twiceMaxEdgePower = min(
  3112. twiceMaxEdgePower,
  3113. twiceMinEdgePower);
  3114. else {
  3115. twiceMaxEdgePower = twiceMinEdgePower;
  3116. break;
  3117. }
  3118. }
  3119. }
  3120. minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
  3121. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  3122. "SEL-Min ctlMode %d pCtlMode %d 2xMaxEdge %d"
  3123. "sP %d minCtlPwr %d\n",
  3124. ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
  3125. scaledPower, minCtlPower);
  3126. switch (pCtlMode[ctlMode]) {
  3127. case CTL_11B:
  3128. for (i = 0;
  3129. i < ARRAY_SIZE(targetPowerCck.tPow2x);
  3130. i++) {
  3131. targetPowerCck.tPow2x[i] = (u8)min(
  3132. (u16)targetPowerCck.tPow2x[i],
  3133. minCtlPower);
  3134. }
  3135. break;
  3136. case CTL_11A:
  3137. case CTL_11G:
  3138. for (i = 0;
  3139. i < ARRAY_SIZE(targetPowerOfdm.tPow2x);
  3140. i++) {
  3141. targetPowerOfdm.tPow2x[i] = (u8)min(
  3142. (u16)targetPowerOfdm.tPow2x[i],
  3143. minCtlPower);
  3144. }
  3145. break;
  3146. case CTL_5GHT20:
  3147. case CTL_2GHT20:
  3148. for (i = 0;
  3149. i < ARRAY_SIZE(targetPowerHt20.tPow2x);
  3150. i++) {
  3151. targetPowerHt20.tPow2x[i] = (u8)min(
  3152. (u16)targetPowerHt20.tPow2x[i],
  3153. minCtlPower);
  3154. }
  3155. break;
  3156. case CTL_11B_EXT:
  3157. targetPowerCckExt.tPow2x[0] = (u8)min(
  3158. (u16)targetPowerCckExt.tPow2x[0],
  3159. minCtlPower);
  3160. break;
  3161. case CTL_11A_EXT:
  3162. case CTL_11G_EXT:
  3163. targetPowerOfdmExt.tPow2x[0] = (u8)min(
  3164. (u16)targetPowerOfdmExt.tPow2x[0],
  3165. minCtlPower);
  3166. break;
  3167. case CTL_5GHT40:
  3168. case CTL_2GHT40:
  3169. for (i = 0;
  3170. i < ARRAY_SIZE(targetPowerHt40.tPow2x);
  3171. i++) {
  3172. targetPowerHt40.tPow2x[i] = (u8)min(
  3173. (u16)targetPowerHt40.tPow2x[i],
  3174. minCtlPower);
  3175. }
  3176. break;
  3177. default:
  3178. break;
  3179. }
  3180. }
  3181. ratesArray[rate6mb] =
  3182. ratesArray[rate9mb] =
  3183. ratesArray[rate12mb] =
  3184. ratesArray[rate18mb] =
  3185. ratesArray[rate24mb] =
  3186. targetPowerOfdm.tPow2x[0];
  3187. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  3188. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  3189. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  3190. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  3191. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  3192. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  3193. if (IS_CHAN_2GHZ(chan)) {
  3194. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  3195. ratesArray[rate2s] = ratesArray[rate2l] =
  3196. targetPowerCck.tPow2x[1];
  3197. ratesArray[rate5_5s] = ratesArray[rate5_5l] =
  3198. targetPowerCck.tPow2x[2];
  3199. ratesArray[rate11s] = ratesArray[rate11l] =
  3200. targetPowerCck.tPow2x[3];
  3201. }
  3202. if (IS_CHAN_HT40(chan)) {
  3203. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++)
  3204. ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i];
  3205. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  3206. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  3207. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  3208. if (IS_CHAN_2GHZ(chan))
  3209. ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
  3210. }
  3211. #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
  3212. #undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
  3213. }
  3214. static void ath9k_hw_AR9287_set_txpower(struct ath_hw *ah,
  3215. struct ath9k_channel *chan, u16 cfgCtl,
  3216. u8 twiceAntennaReduction,
  3217. u8 twiceMaxRegulatoryPower,
  3218. u8 powerLimit)
  3219. {
  3220. #define INCREASE_MAXPOW_BY_TWO_CHAIN 6
  3221. #define INCREASE_MAXPOW_BY_THREE_CHAIN 10
  3222. struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
  3223. struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader;
  3224. int16_t ratesArray[Ar5416RateSize];
  3225. int16_t txPowerIndexOffset = 0;
  3226. u8 ht40PowerIncForPdadc = 2;
  3227. int i;
  3228. memset(ratesArray, 0, sizeof(ratesArray));
  3229. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  3230. AR9287_EEP_MINOR_VER_2)
  3231. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  3232. ath9k_hw_set_AR9287_power_per_rate_table(ah, chan,
  3233. &ratesArray[0], cfgCtl,
  3234. twiceAntennaReduction,
  3235. twiceMaxRegulatoryPower,
  3236. powerLimit);
  3237. ath9k_hw_set_AR9287_power_cal_table(ah, chan, &txPowerIndexOffset);
  3238. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  3239. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  3240. if (ratesArray[i] > AR9287_MAX_RATE_POWER)
  3241. ratesArray[i] = AR9287_MAX_RATE_POWER;
  3242. }
  3243. if (AR_SREV_9280_10_OR_LATER(ah)) {
  3244. for (i = 0; i < Ar5416RateSize; i++)
  3245. ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
  3246. }
  3247. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  3248. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  3249. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  3250. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  3251. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  3252. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  3253. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  3254. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  3255. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  3256. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  3257. if (IS_CHAN_2GHZ(chan)) {
  3258. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  3259. ATH9K_POW_SM(ratesArray[rate2s], 24)
  3260. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  3261. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  3262. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  3263. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  3264. ATH9K_POW_SM(ratesArray[rate11s], 24)
  3265. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  3266. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  3267. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  3268. }
  3269. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  3270. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  3271. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  3272. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  3273. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  3274. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  3275. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  3276. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  3277. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  3278. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  3279. if (IS_CHAN_HT40(chan)) {
  3280. if (ath9k_hw_AR9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  3281. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  3282. ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
  3283. | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
  3284. | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
  3285. | ATH9K_POW_SM(ratesArray[rateHt40_0], 0));
  3286. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  3287. ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
  3288. | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
  3289. | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
  3290. | ATH9K_POW_SM(ratesArray[rateHt40_4], 0));
  3291. } else {
  3292. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  3293. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  3294. ht40PowerIncForPdadc, 24)
  3295. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  3296. ht40PowerIncForPdadc, 16)
  3297. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  3298. ht40PowerIncForPdadc, 8)
  3299. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  3300. ht40PowerIncForPdadc, 0));
  3301. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  3302. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  3303. ht40PowerIncForPdadc, 24)
  3304. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  3305. ht40PowerIncForPdadc, 16)
  3306. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  3307. ht40PowerIncForPdadc, 8)
  3308. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  3309. ht40PowerIncForPdadc, 0));
  3310. }
  3311. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  3312. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  3313. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  3314. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  3315. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  3316. }
  3317. if (IS_CHAN_2GHZ(chan))
  3318. i = rate1l;
  3319. else
  3320. i = rate6mb;
  3321. if (AR_SREV_9280_10_OR_LATER(ah))
  3322. ah->regulatory.max_power_level =
  3323. ratesArray[i] + AR9287_PWR_TABLE_OFFSET_DB * 2;
  3324. else
  3325. ah->regulatory.max_power_level = ratesArray[i];
  3326. switch (ar5416_get_ntxchains(ah->txchainmask)) {
  3327. case 1:
  3328. break;
  3329. case 2:
  3330. ah->regulatory.max_power_level +=
  3331. INCREASE_MAXPOW_BY_TWO_CHAIN;
  3332. break;
  3333. case 3:
  3334. ah->regulatory.max_power_level +=
  3335. INCREASE_MAXPOW_BY_THREE_CHAIN;
  3336. break;
  3337. default:
  3338. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  3339. "Invalid chainmask configuration\n");
  3340. break;
  3341. }
  3342. }
  3343. static void ath9k_hw_AR9287_set_addac(struct ath_hw *ah,
  3344. struct ath9k_channel *chan)
  3345. {
  3346. }
  3347. static void ath9k_hw_AR9287_set_board_values(struct ath_hw *ah,
  3348. struct ath9k_channel *chan)
  3349. {
  3350. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  3351. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  3352. u16 antWrites[AR9287_ANT_16S];
  3353. u32 regChainOffset;
  3354. u8 txRxAttenLocal;
  3355. int i, j, offset_num;
  3356. pModal = &eep->modalHeader;
  3357. antWrites[0] = (u16)((pModal->antCtrlCommon >> 28) & 0xF);
  3358. antWrites[1] = (u16)((pModal->antCtrlCommon >> 24) & 0xF);
  3359. antWrites[2] = (u16)((pModal->antCtrlCommon >> 20) & 0xF);
  3360. antWrites[3] = (u16)((pModal->antCtrlCommon >> 16) & 0xF);
  3361. antWrites[4] = (u16)((pModal->antCtrlCommon >> 12) & 0xF);
  3362. antWrites[5] = (u16)((pModal->antCtrlCommon >> 8) & 0xF);
  3363. antWrites[6] = (u16)((pModal->antCtrlCommon >> 4) & 0xF);
  3364. antWrites[7] = (u16)(pModal->antCtrlCommon & 0xF);
  3365. offset_num = 8;
  3366. for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) {
  3367. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 28) & 0xf);
  3368. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 10) & 0x3);
  3369. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 8) & 0x3);
  3370. antWrites[j++] = 0;
  3371. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 6) & 0x3);
  3372. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 4) & 0x3);
  3373. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 2) & 0x3);
  3374. antWrites[j++] = (u16)(pModal->antCtrlChain[i] & 0x3);
  3375. }
  3376. REG_WRITE(ah, AR_PHY_SWITCH_COM,
  3377. ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
  3378. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  3379. regChainOffset = i * 0x1000;
  3380. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  3381. pModal->antCtrlChain[i]);
  3382. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  3383. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
  3384. & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  3385. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  3386. SM(pModal->iqCalICh[i],
  3387. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  3388. SM(pModal->iqCalQCh[i],
  3389. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  3390. txRxAttenLocal = pModal->txRxAttenCh[i];
  3391. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  3392. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  3393. pModal->bswMargin[i]);
  3394. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  3395. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  3396. pModal->bswAtten[i]);
  3397. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  3398. AR9280_PHY_RXGAIN_TXRX_ATTEN,
  3399. txRxAttenLocal);
  3400. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  3401. AR9280_PHY_RXGAIN_TXRX_MARGIN,
  3402. pModal->rxTxMarginCh[i]);
  3403. }
  3404. if (IS_CHAN_HT40(chan))
  3405. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  3406. AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
  3407. else
  3408. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  3409. AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
  3410. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  3411. AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
  3412. REG_WRITE(ah, AR_PHY_RF_CTL4,
  3413. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  3414. | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  3415. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  3416. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  3417. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
  3418. AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
  3419. REG_RMW_FIELD(ah, AR_PHY_CCA,
  3420. AR9280_PHY_CCA_THRESH62, pModal->thresh62);
  3421. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  3422. AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
  3423. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0, AR9287_AN_RF2G3_DB1,
  3424. AR9287_AN_RF2G3_DB1_S, pModal->db1);
  3425. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0, AR9287_AN_RF2G3_DB2,
  3426. AR9287_AN_RF2G3_DB2_S, pModal->db2);
  3427. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0,
  3428. AR9287_AN_RF2G3_OB_CCK,
  3429. AR9287_AN_RF2G3_OB_CCK_S, pModal->ob_cck);
  3430. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0,
  3431. AR9287_AN_RF2G3_OB_PSK,
  3432. AR9287_AN_RF2G3_OB_PSK_S, pModal->ob_psk);
  3433. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0,
  3434. AR9287_AN_RF2G3_OB_QAM,
  3435. AR9287_AN_RF2G3_OB_QAM_S, pModal->ob_qam);
  3436. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0,
  3437. AR9287_AN_RF2G3_OB_PAL_OFF,
  3438. AR9287_AN_RF2G3_OB_PAL_OFF_S,
  3439. pModal->ob_pal_off);
  3440. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1,
  3441. AR9287_AN_RF2G3_DB1, AR9287_AN_RF2G3_DB1_S,
  3442. pModal->db1);
  3443. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1, AR9287_AN_RF2G3_DB2,
  3444. AR9287_AN_RF2G3_DB2_S, pModal->db2);
  3445. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1,
  3446. AR9287_AN_RF2G3_OB_CCK,
  3447. AR9287_AN_RF2G3_OB_CCK_S, pModal->ob_cck);
  3448. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1,
  3449. AR9287_AN_RF2G3_OB_PSK,
  3450. AR9287_AN_RF2G3_OB_PSK_S, pModal->ob_psk);
  3451. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1,
  3452. AR9287_AN_RF2G3_OB_QAM,
  3453. AR9287_AN_RF2G3_OB_QAM_S, pModal->ob_qam);
  3454. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1,
  3455. AR9287_AN_RF2G3_OB_PAL_OFF,
  3456. AR9287_AN_RF2G3_OB_PAL_OFF_S,
  3457. pModal->ob_pal_off);
  3458. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  3459. AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
  3460. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  3461. AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
  3462. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
  3463. AR9287_AN_TOP2_XPABIAS_LVL,
  3464. AR9287_AN_TOP2_XPABIAS_LVL_S,
  3465. pModal->xpaBiasLvl);
  3466. }
  3467. static u8 ath9k_hw_AR9287_get_num_ant_config(struct ath_hw *ah,
  3468. enum ieee80211_band freq_band)
  3469. {
  3470. return 1;
  3471. }
  3472. static u16 ath9k_hw_AR9287_get_eeprom_antenna_cfg(struct ath_hw *ah,
  3473. struct ath9k_channel *chan)
  3474. {
  3475. struct ar9287_eeprom *eep = &ah->eeprom.map9287;
  3476. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  3477. return pModal->antCtrlCommon & 0xFFFF;
  3478. }
  3479. static u16 ath9k_hw_AR9287_get_spur_channel(struct ath_hw *ah,
  3480. u16 i, bool is2GHz)
  3481. {
  3482. #define EEP_MAP9287_SPURCHAN \
  3483. (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan)
  3484. u16 spur_val = AR_NO_SPUR;
  3485. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  3486. "Getting spur idx %d is2Ghz. %d val %x\n",
  3487. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  3488. switch (ah->config.spurmode) {
  3489. case SPUR_DISABLE:
  3490. break;
  3491. case SPUR_ENABLE_IOCTL:
  3492. spur_val = ah->config.spurchans[i][is2GHz];
  3493. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  3494. "Getting spur val from new loc. %d\n", spur_val);
  3495. break;
  3496. case SPUR_ENABLE_EEPROM:
  3497. spur_val = EEP_MAP9287_SPURCHAN;
  3498. break;
  3499. }
  3500. return spur_val;
  3501. #undef EEP_MAP9287_SPURCHAN
  3502. }
  3503. static struct eeprom_ops eep_AR9287_ops = {
  3504. .check_eeprom = ath9k_hw_AR9287_check_eeprom,
  3505. .get_eeprom = ath9k_hw_AR9287_get_eeprom,
  3506. .fill_eeprom = ath9k_hw_AR9287_fill_eeprom,
  3507. .get_eeprom_ver = ath9k_hw_AR9287_get_eeprom_ver,
  3508. .get_eeprom_rev = ath9k_hw_AR9287_get_eeprom_rev,
  3509. .get_num_ant_config = ath9k_hw_AR9287_get_num_ant_config,
  3510. .get_eeprom_antenna_cfg = ath9k_hw_AR9287_get_eeprom_antenna_cfg,
  3511. .set_board_values = ath9k_hw_AR9287_set_board_values,
  3512. .set_addac = ath9k_hw_AR9287_set_addac,
  3513. .set_txpower = ath9k_hw_AR9287_set_txpower,
  3514. .get_spur_channel = ath9k_hw_AR9287_get_spur_channel
  3515. };
  3516. int ath9k_hw_eeprom_init(struct ath_hw *ah)
  3517. {
  3518. int status;
  3519. if (AR_SREV_9287(ah)) {
  3520. ah->eep_map = EEP_MAP_AR9287;
  3521. ah->eep_ops = &eep_AR9287_ops;
  3522. } else if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
  3523. ah->eep_map = EEP_MAP_4KBITS;
  3524. ah->eep_ops = &eep_4k_ops;
  3525. } else {
  3526. ah->eep_map = EEP_MAP_DEFAULT;
  3527. ah->eep_ops = &eep_def_ops;
  3528. }
  3529. if (!ah->eep_ops->fill_eeprom(ah))
  3530. return -EIO;
  3531. status = ah->eep_ops->check_eeprom(ah);
  3532. return status;
  3533. }