eeprom.c 116 KB

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