eeprom.c 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001
  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. static void ath9k_hw_4k_set_board_values(struct ath_hw *ah,
  1063. struct ath9k_channel *chan)
  1064. {
  1065. struct modal_eep_4k_header *pModal;
  1066. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  1067. u8 txRxAttenLocal;
  1068. u8 ob[5], db1[5], db2[5];
  1069. u8 ant_div_control1, ant_div_control2;
  1070. u32 regVal;
  1071. pModal = &eep->modalHeader;
  1072. txRxAttenLocal = 23;
  1073. REG_WRITE(ah, AR_PHY_SWITCH_COM,
  1074. ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
  1075. /* Single chain for 4K EEPROM*/
  1076. ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal, 0);
  1077. /* Initialize Ant Diversity settings from EEPROM */
  1078. if (pModal->version >= 3) {
  1079. ant_div_control1 = ((pModal->ob_234 >> 12) & 0xf);
  1080. ant_div_control2 = ((pModal->db1_234 >> 12) & 0xf);
  1081. regVal = REG_READ(ah, 0x99ac);
  1082. regVal &= (~(0x7f000000));
  1083. regVal |= ((ant_div_control1 & 0x1) << 24);
  1084. regVal |= (((ant_div_control1 >> 1) & 0x1) << 29);
  1085. regVal |= (((ant_div_control1 >> 2) & 0x1) << 30);
  1086. regVal |= ((ant_div_control2 & 0x3) << 25);
  1087. regVal |= (((ant_div_control2 >> 2) & 0x3) << 27);
  1088. REG_WRITE(ah, 0x99ac, regVal);
  1089. regVal = REG_READ(ah, 0x99ac);
  1090. regVal = REG_READ(ah, 0xa208);
  1091. regVal &= (~(0x1 << 13));
  1092. regVal |= (((ant_div_control1 >> 3) & 0x1) << 13);
  1093. REG_WRITE(ah, 0xa208, regVal);
  1094. regVal = REG_READ(ah, 0xa208);
  1095. }
  1096. if (pModal->version >= 2) {
  1097. ob[0] = (pModal->ob_01 & 0xf);
  1098. ob[1] = (pModal->ob_01 >> 4) & 0xf;
  1099. ob[2] = (pModal->ob_234 & 0xf);
  1100. ob[3] = ((pModal->ob_234 >> 4) & 0xf);
  1101. ob[4] = ((pModal->ob_234 >> 8) & 0xf);
  1102. db1[0] = (pModal->db1_01 & 0xf);
  1103. db1[1] = ((pModal->db1_01 >> 4) & 0xf);
  1104. db1[2] = (pModal->db1_234 & 0xf);
  1105. db1[3] = ((pModal->db1_234 >> 4) & 0xf);
  1106. db1[4] = ((pModal->db1_234 >> 8) & 0xf);
  1107. db2[0] = (pModal->db2_01 & 0xf);
  1108. db2[1] = ((pModal->db2_01 >> 4) & 0xf);
  1109. db2[2] = (pModal->db2_234 & 0xf);
  1110. db2[3] = ((pModal->db2_234 >> 4) & 0xf);
  1111. db2[4] = ((pModal->db2_234 >> 8) & 0xf);
  1112. } else if (pModal->version == 1) {
  1113. ob[0] = (pModal->ob_01 & 0xf);
  1114. ob[1] = ob[2] = ob[3] = ob[4] = (pModal->ob_01 >> 4) & 0xf;
  1115. db1[0] = (pModal->db1_01 & 0xf);
  1116. db1[1] = db1[2] = db1[3] =
  1117. db1[4] = ((pModal->db1_01 >> 4) & 0xf);
  1118. db2[0] = (pModal->db2_01 & 0xf);
  1119. db2[1] = db2[2] = db2[3] =
  1120. db2[4] = ((pModal->db2_01 >> 4) & 0xf);
  1121. } else {
  1122. int i;
  1123. for (i = 0; i < 5; i++) {
  1124. ob[i] = pModal->ob_01;
  1125. db1[i] = pModal->db1_01;
  1126. db2[i] = pModal->db1_01;
  1127. }
  1128. }
  1129. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1130. AR9285_AN_RF2G3_OB_0, AR9285_AN_RF2G3_OB_0_S, ob[0]);
  1131. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1132. AR9285_AN_RF2G3_OB_1, AR9285_AN_RF2G3_OB_1_S, ob[1]);
  1133. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1134. AR9285_AN_RF2G3_OB_2, AR9285_AN_RF2G3_OB_2_S, ob[2]);
  1135. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1136. AR9285_AN_RF2G3_OB_3, AR9285_AN_RF2G3_OB_3_S, ob[3]);
  1137. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1138. AR9285_AN_RF2G3_OB_4, AR9285_AN_RF2G3_OB_4_S, ob[4]);
  1139. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1140. AR9285_AN_RF2G3_DB1_0, AR9285_AN_RF2G3_DB1_0_S, db1[0]);
  1141. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1142. AR9285_AN_RF2G3_DB1_1, AR9285_AN_RF2G3_DB1_1_S, db1[1]);
  1143. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
  1144. AR9285_AN_RF2G3_DB1_2, AR9285_AN_RF2G3_DB1_2_S, db1[2]);
  1145. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1146. AR9285_AN_RF2G4_DB1_3, AR9285_AN_RF2G4_DB1_3_S, db1[3]);
  1147. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1148. AR9285_AN_RF2G4_DB1_4, AR9285_AN_RF2G4_DB1_4_S, db1[4]);
  1149. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1150. AR9285_AN_RF2G4_DB2_0, AR9285_AN_RF2G4_DB2_0_S, db2[0]);
  1151. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1152. AR9285_AN_RF2G4_DB2_1, AR9285_AN_RF2G4_DB2_1_S, db2[1]);
  1153. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1154. AR9285_AN_RF2G4_DB2_2, AR9285_AN_RF2G4_DB2_2_S, db2[2]);
  1155. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1156. AR9285_AN_RF2G4_DB2_3, AR9285_AN_RF2G4_DB2_3_S, db2[3]);
  1157. ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
  1158. AR9285_AN_RF2G4_DB2_4, AR9285_AN_RF2G4_DB2_4_S, db2[4]);
  1159. if (AR_SREV_9285_11(ah))
  1160. REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT);
  1161. REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
  1162. pModal->switchSettling);
  1163. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
  1164. pModal->adcDesiredSize);
  1165. REG_WRITE(ah, AR_PHY_RF_CTL4,
  1166. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
  1167. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
  1168. SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
  1169. SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  1170. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  1171. pModal->txEndToRxOn);
  1172. REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
  1173. pModal->thresh62);
  1174. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
  1175. pModal->thresh62);
  1176. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1177. AR5416_EEP_MINOR_VER_2) {
  1178. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
  1179. pModal->txFrameToDataStart);
  1180. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
  1181. pModal->txFrameToPaOn);
  1182. }
  1183. if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1184. AR5416_EEP_MINOR_VER_3) {
  1185. if (IS_CHAN_HT40(chan))
  1186. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  1187. AR_PHY_SETTLING_SWITCH,
  1188. pModal->swSettleHt40);
  1189. }
  1190. }
  1191. static u16 ath9k_hw_4k_get_eeprom_antenna_cfg(struct ath_hw *ah,
  1192. struct ath9k_channel *chan)
  1193. {
  1194. struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
  1195. struct modal_eep_4k_header *pModal = &eep->modalHeader;
  1196. return pModal->antCtrlCommon & 0xFFFF;
  1197. }
  1198. static u8 ath9k_hw_4k_get_num_ant_config(struct ath_hw *ah,
  1199. enum ieee80211_band freq_band)
  1200. {
  1201. return 1;
  1202. }
  1203. static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
  1204. {
  1205. #define EEP_MAP4K_SPURCHAN \
  1206. (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan)
  1207. u16 spur_val = AR_NO_SPUR;
  1208. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  1209. "Getting spur idx %d is2Ghz. %d val %x\n",
  1210. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  1211. switch (ah->config.spurmode) {
  1212. case SPUR_DISABLE:
  1213. break;
  1214. case SPUR_ENABLE_IOCTL:
  1215. spur_val = ah->config.spurchans[i][is2GHz];
  1216. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  1217. "Getting spur val from new loc. %d\n", spur_val);
  1218. break;
  1219. case SPUR_ENABLE_EEPROM:
  1220. spur_val = EEP_MAP4K_SPURCHAN;
  1221. break;
  1222. }
  1223. return spur_val;
  1224. #undef EEP_MAP4K_SPURCHAN
  1225. }
  1226. static struct eeprom_ops eep_4k_ops = {
  1227. .check_eeprom = ath9k_hw_4k_check_eeprom,
  1228. .get_eeprom = ath9k_hw_4k_get_eeprom,
  1229. .fill_eeprom = ath9k_hw_4k_fill_eeprom,
  1230. .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver,
  1231. .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev,
  1232. .get_num_ant_config = ath9k_hw_4k_get_num_ant_config,
  1233. .get_eeprom_antenna_cfg = ath9k_hw_4k_get_eeprom_antenna_cfg,
  1234. .set_board_values = ath9k_hw_4k_set_board_values,
  1235. .set_addac = ath9k_hw_4k_set_addac,
  1236. .set_txpower = ath9k_hw_4k_set_txpower,
  1237. .get_spur_channel = ath9k_hw_4k_get_spur_channel
  1238. };
  1239. /************************************************/
  1240. /* EEPROM Operations for non-4K (Default) cards */
  1241. /************************************************/
  1242. static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
  1243. {
  1244. return ((ah->eeprom.def.baseEepHeader.version >> 12) & 0xF);
  1245. }
  1246. static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
  1247. {
  1248. return ((ah->eeprom.def.baseEepHeader.version) & 0xFFF);
  1249. }
  1250. static bool ath9k_hw_def_fill_eeprom(struct ath_hw *ah)
  1251. {
  1252. #define SIZE_EEPROM_DEF (sizeof(struct ar5416_eeprom_def) / sizeof(u16))
  1253. u16 *eep_data = (u16 *)&ah->eeprom.def;
  1254. int addr, ar5416_eep_start_loc = 0x100;
  1255. for (addr = 0; addr < SIZE_EEPROM_DEF; addr++) {
  1256. if (!ath9k_hw_nvram_read(ah, addr + ar5416_eep_start_loc,
  1257. eep_data)) {
  1258. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  1259. "Unable to read eeprom region\n");
  1260. return false;
  1261. }
  1262. eep_data++;
  1263. }
  1264. return true;
  1265. #undef SIZE_EEPROM_DEF
  1266. }
  1267. static int ath9k_hw_def_check_eeprom(struct ath_hw *ah)
  1268. {
  1269. struct ar5416_eeprom_def *eep =
  1270. (struct ar5416_eeprom_def *) &ah->eeprom.def;
  1271. u16 *eepdata, temp, magic, magic2;
  1272. u32 sum = 0, el;
  1273. bool need_swap = false;
  1274. int i, addr, size;
  1275. if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
  1276. DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Reading Magic # failed\n");
  1277. return false;
  1278. }
  1279. if (!ath9k_hw_use_flash(ah)) {
  1280. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1281. "Read Magic = 0x%04X\n", magic);
  1282. if (magic != AR5416_EEPROM_MAGIC) {
  1283. magic2 = swab16(magic);
  1284. if (magic2 == AR5416_EEPROM_MAGIC) {
  1285. size = sizeof(struct ar5416_eeprom_def);
  1286. need_swap = true;
  1287. eepdata = (u16 *) (&ah->eeprom);
  1288. for (addr = 0; addr < size / sizeof(u16); addr++) {
  1289. temp = swab16(*eepdata);
  1290. *eepdata = temp;
  1291. eepdata++;
  1292. }
  1293. } else {
  1294. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  1295. "Invalid EEPROM Magic. "
  1296. "Endianness mismatch.\n");
  1297. return -EINVAL;
  1298. }
  1299. }
  1300. }
  1301. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
  1302. need_swap ? "True" : "False");
  1303. if (need_swap)
  1304. el = swab16(ah->eeprom.def.baseEepHeader.length);
  1305. else
  1306. el = ah->eeprom.def.baseEepHeader.length;
  1307. if (el > sizeof(struct ar5416_eeprom_def))
  1308. el = sizeof(struct ar5416_eeprom_def) / sizeof(u16);
  1309. else
  1310. el = el / sizeof(u16);
  1311. eepdata = (u16 *)(&ah->eeprom);
  1312. for (i = 0; i < el; i++)
  1313. sum ^= *eepdata++;
  1314. if (need_swap) {
  1315. u32 integer, j;
  1316. u16 word;
  1317. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1318. "EEPROM Endianness is not native.. Changing.\n");
  1319. word = swab16(eep->baseEepHeader.length);
  1320. eep->baseEepHeader.length = word;
  1321. word = swab16(eep->baseEepHeader.checksum);
  1322. eep->baseEepHeader.checksum = word;
  1323. word = swab16(eep->baseEepHeader.version);
  1324. eep->baseEepHeader.version = word;
  1325. word = swab16(eep->baseEepHeader.regDmn[0]);
  1326. eep->baseEepHeader.regDmn[0] = word;
  1327. word = swab16(eep->baseEepHeader.regDmn[1]);
  1328. eep->baseEepHeader.regDmn[1] = word;
  1329. word = swab16(eep->baseEepHeader.rfSilent);
  1330. eep->baseEepHeader.rfSilent = word;
  1331. word = swab16(eep->baseEepHeader.blueToothOptions);
  1332. eep->baseEepHeader.blueToothOptions = word;
  1333. word = swab16(eep->baseEepHeader.deviceCap);
  1334. eep->baseEepHeader.deviceCap = word;
  1335. for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
  1336. struct modal_eep_header *pModal =
  1337. &eep->modalHeader[j];
  1338. integer = swab32(pModal->antCtrlCommon);
  1339. pModal->antCtrlCommon = integer;
  1340. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  1341. integer = swab32(pModal->antCtrlChain[i]);
  1342. pModal->antCtrlChain[i] = integer;
  1343. }
  1344. for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
  1345. word = swab16(pModal->spurChans[i].spurChan);
  1346. pModal->spurChans[i].spurChan = word;
  1347. }
  1348. }
  1349. }
  1350. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
  1351. ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  1352. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  1353. "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  1354. sum, ah->eep_ops->get_eeprom_ver(ah));
  1355. return -EINVAL;
  1356. }
  1357. return 0;
  1358. }
  1359. static u32 ath9k_hw_def_get_eeprom(struct ath_hw *ah,
  1360. enum eeprom_param param)
  1361. {
  1362. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  1363. struct modal_eep_header *pModal = eep->modalHeader;
  1364. struct base_eep_header *pBase = &eep->baseEepHeader;
  1365. switch (param) {
  1366. case EEP_NFTHRESH_5:
  1367. return pModal[0].noiseFloorThreshCh[0];
  1368. case EEP_NFTHRESH_2:
  1369. return pModal[1].noiseFloorThreshCh[0];
  1370. case AR_EEPROM_MAC(0):
  1371. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  1372. case AR_EEPROM_MAC(1):
  1373. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  1374. case AR_EEPROM_MAC(2):
  1375. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  1376. case EEP_REG_0:
  1377. return pBase->regDmn[0];
  1378. case EEP_REG_1:
  1379. return pBase->regDmn[1];
  1380. case EEP_OP_CAP:
  1381. return pBase->deviceCap;
  1382. case EEP_OP_MODE:
  1383. return pBase->opCapFlags;
  1384. case EEP_RF_SILENT:
  1385. return pBase->rfSilent;
  1386. case EEP_OB_5:
  1387. return pModal[0].ob;
  1388. case EEP_DB_5:
  1389. return pModal[0].db;
  1390. case EEP_OB_2:
  1391. return pModal[1].ob;
  1392. case EEP_DB_2:
  1393. return pModal[1].db;
  1394. case EEP_MINOR_REV:
  1395. return AR5416_VER_MASK;
  1396. case EEP_TX_MASK:
  1397. return pBase->txMask;
  1398. case EEP_RX_MASK:
  1399. return pBase->rxMask;
  1400. case EEP_RXGAIN_TYPE:
  1401. return pBase->rxGainType;
  1402. case EEP_TXGAIN_TYPE:
  1403. return pBase->txGainType;
  1404. case EEP_OL_PWRCTRL:
  1405. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  1406. return pBase->openLoopPwrCntl ? true : false;
  1407. else
  1408. return false;
  1409. case EEP_RC_CHAIN_MASK:
  1410. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  1411. return pBase->rcChainMask;
  1412. else
  1413. return 0;
  1414. case EEP_DAC_HPWR_5G:
  1415. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
  1416. return pBase->dacHiPwrMode_5G;
  1417. else
  1418. return 0;
  1419. case EEP_FRAC_N_5G:
  1420. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
  1421. return pBase->frac_n_5g;
  1422. else
  1423. return 0;
  1424. default:
  1425. return 0;
  1426. }
  1427. }
  1428. static void ath9k_hw_def_set_gain(struct ath_hw *ah,
  1429. struct modal_eep_header *pModal,
  1430. struct ar5416_eeprom_def *eep,
  1431. u8 txRxAttenLocal, int regChainOffset, int i)
  1432. {
  1433. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
  1434. txRxAttenLocal = pModal->txRxAttenCh[i];
  1435. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1436. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1437. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  1438. pModal->bswMargin[i]);
  1439. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1440. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  1441. pModal->bswAtten[i]);
  1442. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1443. AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
  1444. pModal->xatten2Margin[i]);
  1445. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1446. AR_PHY_GAIN_2GHZ_XATTEN2_DB,
  1447. pModal->xatten2Db[i]);
  1448. } else {
  1449. REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1450. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  1451. ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
  1452. | SM(pModal-> bswMargin[i],
  1453. AR_PHY_GAIN_2GHZ_BSW_MARGIN));
  1454. REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  1455. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  1456. ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
  1457. | SM(pModal->bswAtten[i],
  1458. AR_PHY_GAIN_2GHZ_BSW_ATTEN));
  1459. }
  1460. }
  1461. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1462. REG_RMW_FIELD(ah,
  1463. AR_PHY_RXGAIN + regChainOffset,
  1464. AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
  1465. REG_RMW_FIELD(ah,
  1466. AR_PHY_RXGAIN + regChainOffset,
  1467. AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[i]);
  1468. } else {
  1469. REG_WRITE(ah,
  1470. AR_PHY_RXGAIN + regChainOffset,
  1471. (REG_READ(ah, AR_PHY_RXGAIN + regChainOffset) &
  1472. ~AR_PHY_RXGAIN_TXRX_ATTEN)
  1473. | SM(txRxAttenLocal, AR_PHY_RXGAIN_TXRX_ATTEN));
  1474. REG_WRITE(ah,
  1475. AR_PHY_GAIN_2GHZ + regChainOffset,
  1476. (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
  1477. ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
  1478. SM(pModal->rxTxMarginCh[i], AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
  1479. }
  1480. }
  1481. static void ath9k_hw_def_set_board_values(struct ath_hw *ah,
  1482. struct ath9k_channel *chan)
  1483. {
  1484. struct modal_eep_header *pModal;
  1485. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  1486. int i, regChainOffset;
  1487. u8 txRxAttenLocal;
  1488. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  1489. txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
  1490. REG_WRITE(ah, AR_PHY_SWITCH_COM,
  1491. ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
  1492. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  1493. if (AR_SREV_9280(ah)) {
  1494. if (i >= 2)
  1495. break;
  1496. }
  1497. if (AR_SREV_5416_20_OR_LATER(ah) &&
  1498. (ah->rxchainmask == 5 || ah->txchainmask == 5) && (i != 0))
  1499. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  1500. else
  1501. regChainOffset = i * 0x1000;
  1502. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  1503. pModal->antCtrlChain[i]);
  1504. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  1505. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
  1506. ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  1507. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  1508. SM(pModal->iqCalICh[i],
  1509. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  1510. SM(pModal->iqCalQCh[i],
  1511. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  1512. if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah))
  1513. ath9k_hw_def_set_gain(ah, pModal, eep, txRxAttenLocal,
  1514. regChainOffset, i);
  1515. }
  1516. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1517. if (IS_CHAN_2GHZ(chan)) {
  1518. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  1519. AR_AN_RF2G1_CH0_OB,
  1520. AR_AN_RF2G1_CH0_OB_S,
  1521. pModal->ob);
  1522. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
  1523. AR_AN_RF2G1_CH0_DB,
  1524. AR_AN_RF2G1_CH0_DB_S,
  1525. pModal->db);
  1526. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  1527. AR_AN_RF2G1_CH1_OB,
  1528. AR_AN_RF2G1_CH1_OB_S,
  1529. pModal->ob_ch1);
  1530. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
  1531. AR_AN_RF2G1_CH1_DB,
  1532. AR_AN_RF2G1_CH1_DB_S,
  1533. pModal->db_ch1);
  1534. } else {
  1535. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  1536. AR_AN_RF5G1_CH0_OB5,
  1537. AR_AN_RF5G1_CH0_OB5_S,
  1538. pModal->ob);
  1539. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
  1540. AR_AN_RF5G1_CH0_DB5,
  1541. AR_AN_RF5G1_CH0_DB5_S,
  1542. pModal->db);
  1543. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  1544. AR_AN_RF5G1_CH1_OB5,
  1545. AR_AN_RF5G1_CH1_OB5_S,
  1546. pModal->ob_ch1);
  1547. ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
  1548. AR_AN_RF5G1_CH1_DB5,
  1549. AR_AN_RF5G1_CH1_DB5_S,
  1550. pModal->db_ch1);
  1551. }
  1552. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  1553. AR_AN_TOP2_XPABIAS_LVL,
  1554. AR_AN_TOP2_XPABIAS_LVL_S,
  1555. pModal->xpaBiasLvl);
  1556. ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
  1557. AR_AN_TOP2_LOCALBIAS,
  1558. AR_AN_TOP2_LOCALBIAS_S,
  1559. pModal->local_bias);
  1560. REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
  1561. pModal->force_xpaon);
  1562. }
  1563. REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
  1564. pModal->switchSettling);
  1565. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
  1566. pModal->adcDesiredSize);
  1567. if (!AR_SREV_9280_10_OR_LATER(ah))
  1568. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  1569. AR_PHY_DESIRED_SZ_PGA,
  1570. pModal->pgaDesiredSize);
  1571. REG_WRITE(ah, AR_PHY_RF_CTL4,
  1572. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  1573. | SM(pModal->txEndToXpaOff,
  1574. AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  1575. | SM(pModal->txFrameToXpaOn,
  1576. AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  1577. | SM(pModal->txFrameToXpaOn,
  1578. AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  1579. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
  1580. pModal->txEndToRxOn);
  1581. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1582. REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
  1583. pModal->thresh62);
  1584. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  1585. AR_PHY_EXT_CCA0_THRESH62,
  1586. pModal->thresh62);
  1587. } else {
  1588. REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
  1589. pModal->thresh62);
  1590. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  1591. AR_PHY_EXT_CCA_THRESH62,
  1592. pModal->thresh62);
  1593. }
  1594. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
  1595. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  1596. AR_PHY_TX_END_DATA_START,
  1597. pModal->txFrameToDataStart);
  1598. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
  1599. pModal->txFrameToPaOn);
  1600. }
  1601. if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
  1602. if (IS_CHAN_HT40(chan))
  1603. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  1604. AR_PHY_SETTLING_SWITCH,
  1605. pModal->swSettleHt40);
  1606. }
  1607. if (AR_SREV_9280_20_OR_LATER(ah) &&
  1608. AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
  1609. REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL,
  1610. AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK,
  1611. pModal->miscBits);
  1612. if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) {
  1613. if (IS_CHAN_2GHZ(chan))
  1614. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
  1615. eep->baseEepHeader.dacLpMode);
  1616. else if (eep->baseEepHeader.dacHiPwrMode_5G)
  1617. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, 0);
  1618. else
  1619. REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
  1620. eep->baseEepHeader.dacLpMode);
  1621. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, AR_PHY_FRAME_CTL_TX_CLIP,
  1622. pModal->miscBits >> 2);
  1623. REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL9,
  1624. AR_PHY_TX_DESIRED_SCALE_CCK,
  1625. eep->baseEepHeader.desiredScaleCCK);
  1626. }
  1627. }
  1628. static void ath9k_hw_def_set_addac(struct ath_hw *ah,
  1629. struct ath9k_channel *chan)
  1630. {
  1631. #define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt])
  1632. struct modal_eep_header *pModal;
  1633. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  1634. u8 biaslevel;
  1635. if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
  1636. return;
  1637. if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
  1638. return;
  1639. pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  1640. if (pModal->xpaBiasLvl != 0xff) {
  1641. biaslevel = pModal->xpaBiasLvl;
  1642. } else {
  1643. u16 resetFreqBin, freqBin, freqCount = 0;
  1644. struct chan_centers centers;
  1645. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1646. resetFreqBin = FREQ2FBIN(centers.synth_center,
  1647. IS_CHAN_2GHZ(chan));
  1648. freqBin = XPA_LVL_FREQ(0) & 0xff;
  1649. biaslevel = (u8) (XPA_LVL_FREQ(0) >> 14);
  1650. freqCount++;
  1651. while (freqCount < 3) {
  1652. if (XPA_LVL_FREQ(freqCount) == 0x0)
  1653. break;
  1654. freqBin = XPA_LVL_FREQ(freqCount) & 0xff;
  1655. if (resetFreqBin >= freqBin)
  1656. biaslevel = (u8)(XPA_LVL_FREQ(freqCount) >> 14);
  1657. else
  1658. break;
  1659. freqCount++;
  1660. }
  1661. }
  1662. if (IS_CHAN_2GHZ(chan)) {
  1663. INI_RA(&ah->iniAddac, 7, 1) = (INI_RA(&ah->iniAddac,
  1664. 7, 1) & (~0x18)) | biaslevel << 3;
  1665. } else {
  1666. INI_RA(&ah->iniAddac, 6, 1) = (INI_RA(&ah->iniAddac,
  1667. 6, 1) & (~0xc0)) | biaslevel << 6;
  1668. }
  1669. #undef XPA_LVL_FREQ
  1670. }
  1671. static void ath9k_hw_get_def_gain_boundaries_pdadcs(struct ath_hw *ah,
  1672. struct ath9k_channel *chan,
  1673. struct cal_data_per_freq *pRawDataSet,
  1674. u8 *bChans, u16 availPiers,
  1675. u16 tPdGainOverlap, int16_t *pMinCalPower,
  1676. u16 *pPdGainBoundaries, u8 *pPDADCValues,
  1677. u16 numXpdGains)
  1678. {
  1679. int i, j, k;
  1680. int16_t ss;
  1681. u16 idxL = 0, idxR = 0, numPiers;
  1682. static u8 vpdTableL[AR5416_NUM_PD_GAINS]
  1683. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  1684. static u8 vpdTableR[AR5416_NUM_PD_GAINS]
  1685. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  1686. static u8 vpdTableI[AR5416_NUM_PD_GAINS]
  1687. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  1688. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  1689. u8 minPwrT4[AR5416_NUM_PD_GAINS];
  1690. u8 maxPwrT4[AR5416_NUM_PD_GAINS];
  1691. int16_t vpdStep;
  1692. int16_t tmpVal;
  1693. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  1694. bool match;
  1695. int16_t minDelta = 0;
  1696. struct chan_centers centers;
  1697. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1698. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  1699. if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
  1700. break;
  1701. }
  1702. match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center,
  1703. IS_CHAN_2GHZ(chan)),
  1704. bChans, numPiers, &idxL, &idxR);
  1705. if (match) {
  1706. for (i = 0; i < numXpdGains; i++) {
  1707. minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
  1708. maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
  1709. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  1710. pRawDataSet[idxL].pwrPdg[i],
  1711. pRawDataSet[idxL].vpdPdg[i],
  1712. AR5416_PD_GAIN_ICEPTS,
  1713. vpdTableI[i]);
  1714. }
  1715. } else {
  1716. for (i = 0; i < numXpdGains; i++) {
  1717. pVpdL = pRawDataSet[idxL].vpdPdg[i];
  1718. pPwrL = pRawDataSet[idxL].pwrPdg[i];
  1719. pVpdR = pRawDataSet[idxR].vpdPdg[i];
  1720. pPwrR = pRawDataSet[idxR].pwrPdg[i];
  1721. minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
  1722. maxPwrT4[i] =
  1723. min(pPwrL[AR5416_PD_GAIN_ICEPTS - 1],
  1724. pPwrR[AR5416_PD_GAIN_ICEPTS - 1]);
  1725. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  1726. pPwrL, pVpdL,
  1727. AR5416_PD_GAIN_ICEPTS,
  1728. vpdTableL[i]);
  1729. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  1730. pPwrR, pVpdR,
  1731. AR5416_PD_GAIN_ICEPTS,
  1732. vpdTableR[i]);
  1733. for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
  1734. vpdTableI[i][j] =
  1735. (u8)(ath9k_hw_interpolate((u16)
  1736. FREQ2FBIN(centers.
  1737. synth_center,
  1738. IS_CHAN_2GHZ
  1739. (chan)),
  1740. bChans[idxL], bChans[idxR],
  1741. vpdTableL[i][j], vpdTableR[i][j]));
  1742. }
  1743. }
  1744. }
  1745. *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
  1746. k = 0;
  1747. for (i = 0; i < numXpdGains; i++) {
  1748. if (i == (numXpdGains - 1))
  1749. pPdGainBoundaries[i] =
  1750. (u16)(maxPwrT4[i] / 2);
  1751. else
  1752. pPdGainBoundaries[i] =
  1753. (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
  1754. pPdGainBoundaries[i] =
  1755. min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
  1756. if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
  1757. minDelta = pPdGainBoundaries[0] - 23;
  1758. pPdGainBoundaries[0] = 23;
  1759. } else {
  1760. minDelta = 0;
  1761. }
  1762. if (i == 0) {
  1763. if (AR_SREV_9280_10_OR_LATER(ah))
  1764. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  1765. else
  1766. ss = 0;
  1767. } else {
  1768. ss = (int16_t)((pPdGainBoundaries[i - 1] -
  1769. (minPwrT4[i] / 2)) -
  1770. tPdGainOverlap + 1 + minDelta);
  1771. }
  1772. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  1773. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  1774. while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  1775. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  1776. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  1777. ss++;
  1778. }
  1779. sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  1780. tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
  1781. (minPwrT4[i] / 2));
  1782. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  1783. tgtIndex : sizeCurrVpdTable;
  1784. while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  1785. pPDADCValues[k++] = vpdTableI[i][ss++];
  1786. }
  1787. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  1788. vpdTableI[i][sizeCurrVpdTable - 2]);
  1789. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  1790. if (tgtIndex > maxIndex) {
  1791. while ((ss <= tgtIndex) &&
  1792. (k < (AR5416_NUM_PDADC_VALUES - 1))) {
  1793. tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] +
  1794. (ss - maxIndex + 1) * vpdStep));
  1795. pPDADCValues[k++] = (u8)((tmpVal > 255) ?
  1796. 255 : tmpVal);
  1797. ss++;
  1798. }
  1799. }
  1800. }
  1801. while (i < AR5416_PD_GAINS_IN_MASK) {
  1802. pPdGainBoundaries[i] = pPdGainBoundaries[i - 1];
  1803. i++;
  1804. }
  1805. while (k < AR5416_NUM_PDADC_VALUES) {
  1806. pPDADCValues[k] = pPDADCValues[k - 1];
  1807. k++;
  1808. }
  1809. return;
  1810. }
  1811. static void ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
  1812. struct ath9k_channel *chan,
  1813. int16_t *pTxPowerIndexOffset)
  1814. {
  1815. #define SM_PD_GAIN(x) SM(0x38, AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##x)
  1816. #define SM_PDGAIN_B(x, y) \
  1817. SM((gainBoundaries[x]), AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##y)
  1818. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  1819. struct cal_data_per_freq *pRawDataset;
  1820. u8 *pCalBChans = NULL;
  1821. u16 pdGainOverlap_t2;
  1822. static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
  1823. u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
  1824. u16 numPiers, i, j;
  1825. int16_t tMinCalPower;
  1826. u16 numXpdGain, xpdMask;
  1827. u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
  1828. u32 reg32, regOffset, regChainOffset;
  1829. int16_t modalIdx;
  1830. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  1831. xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
  1832. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  1833. AR5416_EEP_MINOR_VER_2) {
  1834. pdGainOverlap_t2 =
  1835. pEepData->modalHeader[modalIdx].pdGainOverlap;
  1836. } else {
  1837. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  1838. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  1839. }
  1840. if (IS_CHAN_2GHZ(chan)) {
  1841. pCalBChans = pEepData->calFreqPier2G;
  1842. numPiers = AR5416_NUM_2G_CAL_PIERS;
  1843. } else {
  1844. pCalBChans = pEepData->calFreqPier5G;
  1845. numPiers = AR5416_NUM_5G_CAL_PIERS;
  1846. }
  1847. if (OLC_FOR_AR9280_20_LATER && IS_CHAN_2GHZ(chan)) {
  1848. pRawDataset = pEepData->calPierData2G[0];
  1849. ah->initPDADC = ((struct calDataPerFreqOpLoop *)
  1850. pRawDataset)->vpdPdg[0][0];
  1851. }
  1852. numXpdGain = 0;
  1853. for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
  1854. if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
  1855. if (numXpdGain >= AR5416_NUM_PD_GAINS)
  1856. break;
  1857. xpdGainValues[numXpdGain] =
  1858. (u16)(AR5416_PD_GAINS_IN_MASK - i);
  1859. numXpdGain++;
  1860. }
  1861. }
  1862. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  1863. (numXpdGain - 1) & 0x3);
  1864. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  1865. xpdGainValues[0]);
  1866. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  1867. xpdGainValues[1]);
  1868. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  1869. xpdGainValues[2]);
  1870. for (i = 0; i < AR5416_MAX_CHAINS; i++) {
  1871. if (AR_SREV_5416_20_OR_LATER(ah) &&
  1872. (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
  1873. (i != 0)) {
  1874. regChainOffset = (i == 1) ? 0x2000 : 0x1000;
  1875. } else
  1876. regChainOffset = i * 0x1000;
  1877. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  1878. if (IS_CHAN_2GHZ(chan))
  1879. pRawDataset = pEepData->calPierData2G[i];
  1880. else
  1881. pRawDataset = pEepData->calPierData5G[i];
  1882. if (OLC_FOR_AR9280_20_LATER) {
  1883. u8 pcdacIdx;
  1884. u8 txPower;
  1885. ath9k_get_txgain_index(ah, chan,
  1886. (struct calDataPerFreqOpLoop *)pRawDataset,
  1887. pCalBChans, numPiers, &txPower, &pcdacIdx);
  1888. ath9k_olc_get_pdadcs(ah, pcdacIdx,
  1889. txPower/2, pdadcValues);
  1890. } else {
  1891. ath9k_hw_get_def_gain_boundaries_pdadcs(ah,
  1892. chan, pRawDataset,
  1893. pCalBChans, numPiers,
  1894. pdGainOverlap_t2,
  1895. &tMinCalPower,
  1896. gainBoundaries,
  1897. pdadcValues,
  1898. numXpdGain);
  1899. }
  1900. if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
  1901. if (OLC_FOR_AR9280_20_LATER) {
  1902. REG_WRITE(ah,
  1903. AR_PHY_TPCRG5 + regChainOffset,
  1904. SM(0x6,
  1905. AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
  1906. SM_PD_GAIN(1) | SM_PD_GAIN(2) |
  1907. SM_PD_GAIN(3) | SM_PD_GAIN(4));
  1908. } else {
  1909. REG_WRITE(ah,
  1910. AR_PHY_TPCRG5 + regChainOffset,
  1911. SM(pdGainOverlap_t2,
  1912. AR_PHY_TPCRG5_PD_GAIN_OVERLAP)|
  1913. SM_PDGAIN_B(0, 1) |
  1914. SM_PDGAIN_B(1, 2) |
  1915. SM_PDGAIN_B(2, 3) |
  1916. SM_PDGAIN_B(3, 4));
  1917. }
  1918. }
  1919. regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
  1920. for (j = 0; j < 32; j++) {
  1921. reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
  1922. ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
  1923. ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
  1924. ((pdadcValues[4 * j + 3] & 0xFF) << 24);
  1925. REG_WRITE(ah, regOffset, reg32);
  1926. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1927. "PDADC (%d,%4x): %4.4x %8.8x\n",
  1928. i, regChainOffset, regOffset,
  1929. reg32);
  1930. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1931. "PDADC: Chain %d | PDADC %3d "
  1932. "Value %3d | PDADC %3d Value %3d | "
  1933. "PDADC %3d Value %3d | PDADC %3d "
  1934. "Value %3d |\n",
  1935. i, 4 * j, pdadcValues[4 * j],
  1936. 4 * j + 1, pdadcValues[4 * j + 1],
  1937. 4 * j + 2, pdadcValues[4 * j + 2],
  1938. 4 * j + 3,
  1939. pdadcValues[4 * j + 3]);
  1940. regOffset += 4;
  1941. }
  1942. }
  1943. }
  1944. *pTxPowerIndexOffset = 0;
  1945. #undef SM_PD_GAIN
  1946. #undef SM_PDGAIN_B
  1947. }
  1948. static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
  1949. struct ath9k_channel *chan,
  1950. int16_t *ratesArray,
  1951. u16 cfgCtl,
  1952. u16 AntennaReduction,
  1953. u16 twiceMaxRegulatoryPower,
  1954. u16 powerLimit)
  1955. {
  1956. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */
  1957. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */
  1958. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  1959. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  1960. static const u16 tpScaleReductionTable[5] =
  1961. { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
  1962. int i;
  1963. int16_t twiceLargestAntenna;
  1964. struct cal_ctl_data *rep;
  1965. struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
  1966. 0, { 0, 0, 0, 0}
  1967. };
  1968. struct cal_target_power_leg targetPowerOfdmExt = {
  1969. 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
  1970. 0, { 0, 0, 0, 0 }
  1971. };
  1972. struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
  1973. 0, {0, 0, 0, 0}
  1974. };
  1975. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  1976. u16 ctlModesFor11a[] =
  1977. { CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40 };
  1978. u16 ctlModesFor11g[] =
  1979. { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
  1980. CTL_2GHT40
  1981. };
  1982. u16 numCtlModes, *pCtlMode, ctlMode, freq;
  1983. struct chan_centers centers;
  1984. int tx_chainmask;
  1985. u16 twiceMinEdgePower;
  1986. tx_chainmask = ah->txchainmask;
  1987. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1988. twiceLargestAntenna = max(
  1989. pEepData->modalHeader
  1990. [IS_CHAN_2GHZ(chan)].antennaGainCh[0],
  1991. pEepData->modalHeader
  1992. [IS_CHAN_2GHZ(chan)].antennaGainCh[1]);
  1993. twiceLargestAntenna = max((u8)twiceLargestAntenna,
  1994. pEepData->modalHeader
  1995. [IS_CHAN_2GHZ(chan)].antennaGainCh[2]);
  1996. twiceLargestAntenna = (int16_t)min(AntennaReduction -
  1997. twiceLargestAntenna, 0);
  1998. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  1999. if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) {
  2000. maxRegAllowedPower -=
  2001. (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2);
  2002. }
  2003. scaledPower = min(powerLimit, maxRegAllowedPower);
  2004. switch (ar5416_get_ntxchains(tx_chainmask)) {
  2005. case 1:
  2006. break;
  2007. case 2:
  2008. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  2009. break;
  2010. case 3:
  2011. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  2012. break;
  2013. }
  2014. scaledPower = max((u16)0, scaledPower);
  2015. if (IS_CHAN_2GHZ(chan)) {
  2016. numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
  2017. SUB_NUM_CTL_MODES_AT_2G_40;
  2018. pCtlMode = ctlModesFor11g;
  2019. ath9k_hw_get_legacy_target_powers(ah, chan,
  2020. pEepData->calTargetPowerCck,
  2021. AR5416_NUM_2G_CCK_TARGET_POWERS,
  2022. &targetPowerCck, 4, false);
  2023. ath9k_hw_get_legacy_target_powers(ah, chan,
  2024. pEepData->calTargetPower2G,
  2025. AR5416_NUM_2G_20_TARGET_POWERS,
  2026. &targetPowerOfdm, 4, false);
  2027. ath9k_hw_get_target_powers(ah, chan,
  2028. pEepData->calTargetPower2GHT20,
  2029. AR5416_NUM_2G_20_TARGET_POWERS,
  2030. &targetPowerHt20, 8, false);
  2031. if (IS_CHAN_HT40(chan)) {
  2032. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  2033. ath9k_hw_get_target_powers(ah, chan,
  2034. pEepData->calTargetPower2GHT40,
  2035. AR5416_NUM_2G_40_TARGET_POWERS,
  2036. &targetPowerHt40, 8, true);
  2037. ath9k_hw_get_legacy_target_powers(ah, chan,
  2038. pEepData->calTargetPowerCck,
  2039. AR5416_NUM_2G_CCK_TARGET_POWERS,
  2040. &targetPowerCckExt, 4, true);
  2041. ath9k_hw_get_legacy_target_powers(ah, chan,
  2042. pEepData->calTargetPower2G,
  2043. AR5416_NUM_2G_20_TARGET_POWERS,
  2044. &targetPowerOfdmExt, 4, true);
  2045. }
  2046. } else {
  2047. numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
  2048. SUB_NUM_CTL_MODES_AT_5G_40;
  2049. pCtlMode = ctlModesFor11a;
  2050. ath9k_hw_get_legacy_target_powers(ah, chan,
  2051. pEepData->calTargetPower5G,
  2052. AR5416_NUM_5G_20_TARGET_POWERS,
  2053. &targetPowerOfdm, 4, false);
  2054. ath9k_hw_get_target_powers(ah, chan,
  2055. pEepData->calTargetPower5GHT20,
  2056. AR5416_NUM_5G_20_TARGET_POWERS,
  2057. &targetPowerHt20, 8, false);
  2058. if (IS_CHAN_HT40(chan)) {
  2059. numCtlModes = ARRAY_SIZE(ctlModesFor11a);
  2060. ath9k_hw_get_target_powers(ah, chan,
  2061. pEepData->calTargetPower5GHT40,
  2062. AR5416_NUM_5G_40_TARGET_POWERS,
  2063. &targetPowerHt40, 8, true);
  2064. ath9k_hw_get_legacy_target_powers(ah, chan,
  2065. pEepData->calTargetPower5G,
  2066. AR5416_NUM_5G_20_TARGET_POWERS,
  2067. &targetPowerOfdmExt, 4, true);
  2068. }
  2069. }
  2070. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  2071. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  2072. (pCtlMode[ctlMode] == CTL_2GHT40);
  2073. if (isHt40CtlMode)
  2074. freq = centers.synth_center;
  2075. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  2076. freq = centers.ext_center;
  2077. else
  2078. freq = centers.ctl_center;
  2079. if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
  2080. ah->eep_ops->get_eeprom_rev(ah) <= 2)
  2081. twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  2082. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2083. "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
  2084. "EXT_ADDITIVE %d\n",
  2085. ctlMode, numCtlModes, isHt40CtlMode,
  2086. (pCtlMode[ctlMode] & EXT_ADDITIVE));
  2087. for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
  2088. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2089. " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
  2090. "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
  2091. "chan %d\n",
  2092. i, cfgCtl, pCtlMode[ctlMode],
  2093. pEepData->ctlIndex[i], chan->channel);
  2094. if ((((cfgCtl & ~CTL_MODE_M) |
  2095. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  2096. pEepData->ctlIndex[i]) ||
  2097. (((cfgCtl & ~CTL_MODE_M) |
  2098. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  2099. ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
  2100. rep = &(pEepData->ctlData[i]);
  2101. twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
  2102. rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
  2103. IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
  2104. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2105. " MATCH-EE_IDX %d: ch %d is2 %d "
  2106. "2xMinEdge %d chainmask %d chains %d\n",
  2107. i, freq, IS_CHAN_2GHZ(chan),
  2108. twiceMinEdgePower, tx_chainmask,
  2109. ar5416_get_ntxchains
  2110. (tx_chainmask));
  2111. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
  2112. twiceMaxEdgePower = min(twiceMaxEdgePower,
  2113. twiceMinEdgePower);
  2114. } else {
  2115. twiceMaxEdgePower = twiceMinEdgePower;
  2116. break;
  2117. }
  2118. }
  2119. }
  2120. minCtlPower = min(twiceMaxEdgePower, scaledPower);
  2121. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2122. " SEL-Min ctlMode %d pCtlMode %d "
  2123. "2xMaxEdge %d sP %d minCtlPwr %d\n",
  2124. ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
  2125. scaledPower, minCtlPower);
  2126. switch (pCtlMode[ctlMode]) {
  2127. case CTL_11B:
  2128. for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
  2129. targetPowerCck.tPow2x[i] =
  2130. min((u16)targetPowerCck.tPow2x[i],
  2131. minCtlPower);
  2132. }
  2133. break;
  2134. case CTL_11A:
  2135. case CTL_11G:
  2136. for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
  2137. targetPowerOfdm.tPow2x[i] =
  2138. min((u16)targetPowerOfdm.tPow2x[i],
  2139. minCtlPower);
  2140. }
  2141. break;
  2142. case CTL_5GHT20:
  2143. case CTL_2GHT20:
  2144. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
  2145. targetPowerHt20.tPow2x[i] =
  2146. min((u16)targetPowerHt20.tPow2x[i],
  2147. minCtlPower);
  2148. }
  2149. break;
  2150. case CTL_11B_EXT:
  2151. targetPowerCckExt.tPow2x[0] = min((u16)
  2152. targetPowerCckExt.tPow2x[0],
  2153. minCtlPower);
  2154. break;
  2155. case CTL_11A_EXT:
  2156. case CTL_11G_EXT:
  2157. targetPowerOfdmExt.tPow2x[0] = min((u16)
  2158. targetPowerOfdmExt.tPow2x[0],
  2159. minCtlPower);
  2160. break;
  2161. case CTL_5GHT40:
  2162. case CTL_2GHT40:
  2163. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  2164. targetPowerHt40.tPow2x[i] =
  2165. min((u16)targetPowerHt40.tPow2x[i],
  2166. minCtlPower);
  2167. }
  2168. break;
  2169. default:
  2170. break;
  2171. }
  2172. }
  2173. ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
  2174. ratesArray[rate18mb] = ratesArray[rate24mb] =
  2175. targetPowerOfdm.tPow2x[0];
  2176. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  2177. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  2178. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  2179. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  2180. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  2181. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  2182. if (IS_CHAN_2GHZ(chan)) {
  2183. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  2184. ratesArray[rate2s] = ratesArray[rate2l] =
  2185. targetPowerCck.tPow2x[1];
  2186. ratesArray[rate5_5s] = ratesArray[rate5_5l] =
  2187. targetPowerCck.tPow2x[2];
  2188. ratesArray[rate11s] = ratesArray[rate11l] =
  2189. targetPowerCck.tPow2x[3];
  2190. }
  2191. if (IS_CHAN_HT40(chan)) {
  2192. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
  2193. ratesArray[rateHt40_0 + i] =
  2194. targetPowerHt40.tPow2x[i];
  2195. }
  2196. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  2197. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  2198. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  2199. if (IS_CHAN_2GHZ(chan)) {
  2200. ratesArray[rateExtCck] =
  2201. targetPowerCckExt.tPow2x[0];
  2202. }
  2203. }
  2204. }
  2205. static void ath9k_hw_def_set_txpower(struct ath_hw *ah,
  2206. struct ath9k_channel *chan,
  2207. u16 cfgCtl,
  2208. u8 twiceAntennaReduction,
  2209. u8 twiceMaxRegulatoryPower,
  2210. u8 powerLimit)
  2211. {
  2212. #define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
  2213. struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
  2214. struct modal_eep_header *pModal =
  2215. &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
  2216. int16_t ratesArray[Ar5416RateSize];
  2217. int16_t txPowerIndexOffset = 0;
  2218. u8 ht40PowerIncForPdadc = 2;
  2219. int i, cck_ofdm_delta = 0;
  2220. memset(ratesArray, 0, sizeof(ratesArray));
  2221. if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
  2222. AR5416_EEP_MINOR_VER_2) {
  2223. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  2224. }
  2225. ath9k_hw_set_def_power_per_rate_table(ah, chan,
  2226. &ratesArray[0], cfgCtl,
  2227. twiceAntennaReduction,
  2228. twiceMaxRegulatoryPower,
  2229. powerLimit);
  2230. ath9k_hw_set_def_power_cal_table(ah, chan, &txPowerIndexOffset);
  2231. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  2232. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  2233. if (ratesArray[i] > AR5416_MAX_RATE_POWER)
  2234. ratesArray[i] = AR5416_MAX_RATE_POWER;
  2235. }
  2236. if (AR_SREV_9280_10_OR_LATER(ah)) {
  2237. for (i = 0; i < Ar5416RateSize; i++)
  2238. ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
  2239. }
  2240. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  2241. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  2242. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  2243. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  2244. | ATH9K_POW_SM(ratesArray[rate6mb], 0));
  2245. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  2246. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  2247. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  2248. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  2249. | ATH9K_POW_SM(ratesArray[rate24mb], 0));
  2250. if (IS_CHAN_2GHZ(chan)) {
  2251. if (OLC_FOR_AR9280_20_LATER) {
  2252. cck_ofdm_delta = 2;
  2253. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  2254. ATH9K_POW_SM(RT_AR_DELTA(rate2s), 24)
  2255. | ATH9K_POW_SM(RT_AR_DELTA(rate2l), 16)
  2256. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  2257. | ATH9K_POW_SM(RT_AR_DELTA(rate1l), 0));
  2258. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  2259. ATH9K_POW_SM(RT_AR_DELTA(rate11s), 24)
  2260. | ATH9K_POW_SM(RT_AR_DELTA(rate11l), 16)
  2261. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5s), 8)
  2262. | ATH9K_POW_SM(RT_AR_DELTA(rate5_5l), 0));
  2263. } else {
  2264. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  2265. ATH9K_POW_SM(ratesArray[rate2s], 24)
  2266. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  2267. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  2268. | ATH9K_POW_SM(ratesArray[rate1l], 0));
  2269. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  2270. ATH9K_POW_SM(ratesArray[rate11s], 24)
  2271. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  2272. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  2273. | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
  2274. }
  2275. }
  2276. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  2277. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  2278. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  2279. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  2280. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
  2281. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  2282. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  2283. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  2284. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  2285. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
  2286. if (IS_CHAN_HT40(chan)) {
  2287. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  2288. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  2289. ht40PowerIncForPdadc, 24)
  2290. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  2291. ht40PowerIncForPdadc, 16)
  2292. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  2293. ht40PowerIncForPdadc, 8)
  2294. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  2295. ht40PowerIncForPdadc, 0));
  2296. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  2297. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  2298. ht40PowerIncForPdadc, 24)
  2299. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  2300. ht40PowerIncForPdadc, 16)
  2301. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  2302. ht40PowerIncForPdadc, 8)
  2303. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  2304. ht40PowerIncForPdadc, 0));
  2305. if (OLC_FOR_AR9280_20_LATER) {
  2306. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  2307. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  2308. | ATH9K_POW_SM(RT_AR_DELTA(rateExtCck), 16)
  2309. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  2310. | ATH9K_POW_SM(RT_AR_DELTA(rateDupCck), 0));
  2311. } else {
  2312. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  2313. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  2314. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  2315. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  2316. | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
  2317. }
  2318. }
  2319. REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
  2320. ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
  2321. | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
  2322. i = rate6mb;
  2323. if (IS_CHAN_HT40(chan))
  2324. i = rateHt40_0;
  2325. else if (IS_CHAN_HT20(chan))
  2326. i = rateHt20_0;
  2327. if (AR_SREV_9280_10_OR_LATER(ah))
  2328. ah->regulatory.max_power_level =
  2329. ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
  2330. else
  2331. ah->regulatory.max_power_level = ratesArray[i];
  2332. switch(ar5416_get_ntxchains(ah->txchainmask)) {
  2333. case 1:
  2334. break;
  2335. case 2:
  2336. ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
  2337. break;
  2338. case 3:
  2339. ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
  2340. break;
  2341. default:
  2342. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2343. "Invalid chainmask configuration\n");
  2344. break;
  2345. }
  2346. }
  2347. static u8 ath9k_hw_def_get_num_ant_config(struct ath_hw *ah,
  2348. enum ieee80211_band freq_band)
  2349. {
  2350. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  2351. struct modal_eep_header *pModal =
  2352. &(eep->modalHeader[ATH9K_HAL_FREQ_BAND_2GHZ == freq_band]);
  2353. struct base_eep_header *pBase = &eep->baseEepHeader;
  2354. u8 num_ant_config;
  2355. num_ant_config = 1;
  2356. if (pBase->version >= 0x0E0D)
  2357. if (pModal->useAnt1)
  2358. num_ant_config += 1;
  2359. return num_ant_config;
  2360. }
  2361. static u16 ath9k_hw_def_get_eeprom_antenna_cfg(struct ath_hw *ah,
  2362. struct ath9k_channel *chan)
  2363. {
  2364. struct ar5416_eeprom_def *eep = &ah->eeprom.def;
  2365. struct modal_eep_header *pModal =
  2366. &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
  2367. return pModal->antCtrlCommon & 0xFFFF;
  2368. }
  2369. static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
  2370. {
  2371. #define EEP_DEF_SPURCHAN \
  2372. (ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan)
  2373. u16 spur_val = AR_NO_SPUR;
  2374. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  2375. "Getting spur idx %d is2Ghz. %d val %x\n",
  2376. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  2377. switch (ah->config.spurmode) {
  2378. case SPUR_DISABLE:
  2379. break;
  2380. case SPUR_ENABLE_IOCTL:
  2381. spur_val = ah->config.spurchans[i][is2GHz];
  2382. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  2383. "Getting spur val from new loc. %d\n", spur_val);
  2384. break;
  2385. case SPUR_ENABLE_EEPROM:
  2386. spur_val = EEP_DEF_SPURCHAN;
  2387. break;
  2388. }
  2389. return spur_val;
  2390. #undef EEP_DEF_SPURCHAN
  2391. }
  2392. static struct eeprom_ops eep_def_ops = {
  2393. .check_eeprom = ath9k_hw_def_check_eeprom,
  2394. .get_eeprom = ath9k_hw_def_get_eeprom,
  2395. .fill_eeprom = ath9k_hw_def_fill_eeprom,
  2396. .get_eeprom_ver = ath9k_hw_def_get_eeprom_ver,
  2397. .get_eeprom_rev = ath9k_hw_def_get_eeprom_rev,
  2398. .get_num_ant_config = ath9k_hw_def_get_num_ant_config,
  2399. .get_eeprom_antenna_cfg = ath9k_hw_def_get_eeprom_antenna_cfg,
  2400. .set_board_values = ath9k_hw_def_set_board_values,
  2401. .set_addac = ath9k_hw_def_set_addac,
  2402. .set_txpower = ath9k_hw_def_set_txpower,
  2403. .get_spur_channel = ath9k_hw_def_get_spur_channel
  2404. };
  2405. static int ath9k_hw_AR9287_get_eeprom_ver(struct ath_hw *ah)
  2406. {
  2407. return (ah->eeprom.map9287.baseEepHeader.version >> 12) & 0xF;
  2408. }
  2409. static int ath9k_hw_AR9287_get_eeprom_rev(struct ath_hw *ah)
  2410. {
  2411. return (ah->eeprom.map9287.baseEepHeader.version) & 0xFFF;
  2412. }
  2413. static bool ath9k_hw_AR9287_fill_eeprom(struct ath_hw *ah)
  2414. {
  2415. struct ar9287_eeprom_t *eep = &ah->eeprom.map9287;
  2416. u16 *eep_data;
  2417. int addr, eep_start_loc = AR9287_EEP_START_LOC;
  2418. eep_data = (u16 *)eep;
  2419. if (!ath9k_hw_use_flash(ah)) {
  2420. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2421. "Reading from EEPROM, not flash\n");
  2422. }
  2423. for (addr = 0; addr < sizeof(struct ar9287_eeprom_t) / sizeof(u16);
  2424. addr++) {
  2425. if (!ath9k_hw_nvram_read(ah, addr + eep_start_loc, eep_data)) {
  2426. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2427. "Unable to read eeprom region \n");
  2428. return false;
  2429. }
  2430. eep_data++;
  2431. }
  2432. return true;
  2433. }
  2434. static int ath9k_hw_AR9287_check_eeprom(struct ath_hw *ah)
  2435. {
  2436. #define SIZE_EEPROM_87 (sizeof(struct ar9287_eeprom_t) / sizeof(u16))
  2437. u32 sum = 0, el, integer;
  2438. u16 temp, word, magic, magic2, *eepdata;
  2439. int i, addr;
  2440. bool need_swap = false;
  2441. struct ar9287_eeprom_t *eep = &ah->eeprom.map9287;
  2442. if (!ath9k_hw_use_flash(ah)) {
  2443. if (!ath9k_hw_nvram_read
  2444. (ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
  2445. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  2446. "Reading Magic # failed\n");
  2447. return false;
  2448. }
  2449. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2450. "Read Magic = 0x%04X\n", magic);
  2451. if (magic != AR5416_EEPROM_MAGIC) {
  2452. magic2 = swab16(magic);
  2453. if (magic2 == AR5416_EEPROM_MAGIC) {
  2454. need_swap = true;
  2455. eepdata = (u16 *)(&ah->eeprom);
  2456. for (addr = 0; addr < SIZE_EEPROM_87; addr++) {
  2457. temp = swab16(*eepdata);
  2458. *eepdata = temp;
  2459. eepdata++;
  2460. }
  2461. } else {
  2462. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  2463. "Invalid EEPROM Magic. "
  2464. "endianness mismatch.\n");
  2465. return -EINVAL; }
  2466. }
  2467. }
  2468. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n", need_swap ?
  2469. "True" : "False");
  2470. if (need_swap)
  2471. el = swab16(ah->eeprom.map9287.baseEepHeader.length);
  2472. else
  2473. el = ah->eeprom.map9287.baseEepHeader.length;
  2474. eepdata = (u16 *)(&ah->eeprom);
  2475. for (i = 0; i < min(el, SIZE_EEPROM_87); i++)
  2476. sum ^= *eepdata++;
  2477. if (need_swap) {
  2478. word = swab16(eep->baseEepHeader.length);
  2479. eep->baseEepHeader.length = word;
  2480. word = swab16(eep->baseEepHeader.checksum);
  2481. eep->baseEepHeader.checksum = word;
  2482. word = swab16(eep->baseEepHeader.version);
  2483. eep->baseEepHeader.version = word;
  2484. word = swab16(eep->baseEepHeader.regDmn[0]);
  2485. eep->baseEepHeader.regDmn[0] = word;
  2486. word = swab16(eep->baseEepHeader.regDmn[1]);
  2487. eep->baseEepHeader.regDmn[1] = word;
  2488. word = swab16(eep->baseEepHeader.rfSilent);
  2489. eep->baseEepHeader.rfSilent = word;
  2490. word = swab16(eep->baseEepHeader.blueToothOptions);
  2491. eep->baseEepHeader.blueToothOptions = word;
  2492. word = swab16(eep->baseEepHeader.deviceCap);
  2493. eep->baseEepHeader.deviceCap = word;
  2494. integer = swab32(eep->modalHeader.antCtrlCommon);
  2495. eep->modalHeader.antCtrlCommon = integer;
  2496. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  2497. integer = swab32(eep->modalHeader.antCtrlChain[i]);
  2498. eep->modalHeader.antCtrlChain[i] = integer;
  2499. }
  2500. for (i = 0; i < AR9287_EEPROM_MODAL_SPURS; i++) {
  2501. word = swab16(eep->modalHeader.spurChans[i].spurChan);
  2502. eep->modalHeader.spurChans[i].spurChan = word;
  2503. }
  2504. }
  2505. if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR9287_EEP_VER
  2506. || ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
  2507. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  2508. "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
  2509. sum, ah->eep_ops->get_eeprom_ver(ah));
  2510. return -EINVAL;
  2511. }
  2512. return 0;
  2513. #undef SIZE_EEPROM_87
  2514. }
  2515. static u32 ath9k_hw_AR9287_get_eeprom(struct ath_hw *ah,
  2516. enum eeprom_param param)
  2517. {
  2518. struct ar9287_eeprom_t *eep = &ah->eeprom.map9287;
  2519. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  2520. struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
  2521. u16 ver_minor;
  2522. ver_minor = pBase->version & AR9287_EEP_VER_MINOR_MASK;
  2523. switch (param) {
  2524. case EEP_NFTHRESH_2:
  2525. return pModal->noiseFloorThreshCh[0];
  2526. case AR_EEPROM_MAC(0):
  2527. return pBase->macAddr[0] << 8 | pBase->macAddr[1];
  2528. case AR_EEPROM_MAC(1):
  2529. return pBase->macAddr[2] << 8 | pBase->macAddr[3];
  2530. case AR_EEPROM_MAC(2):
  2531. return pBase->macAddr[4] << 8 | pBase->macAddr[5];
  2532. case EEP_REG_0:
  2533. return pBase->regDmn[0];
  2534. case EEP_REG_1:
  2535. return pBase->regDmn[1];
  2536. case EEP_OP_CAP:
  2537. return pBase->deviceCap;
  2538. case EEP_OP_MODE:
  2539. return pBase->opCapFlags;
  2540. case EEP_RF_SILENT:
  2541. return pBase->rfSilent;
  2542. case EEP_MINOR_REV:
  2543. return ver_minor;
  2544. case EEP_TX_MASK:
  2545. return pBase->txMask;
  2546. case EEP_RX_MASK:
  2547. return pBase->rxMask;
  2548. case EEP_DEV_TYPE:
  2549. return pBase->deviceType;
  2550. case EEP_OL_PWRCTRL:
  2551. return pBase->openLoopPwrCntl;
  2552. case EEP_TEMPSENSE_SLOPE:
  2553. if (ver_minor >= AR9287_EEP_MINOR_VER_2)
  2554. return pBase->tempSensSlope;
  2555. else
  2556. return 0;
  2557. case EEP_TEMPSENSE_SLOPE_PAL_ON:
  2558. if (ver_minor >= AR9287_EEP_MINOR_VER_3)
  2559. return pBase->tempSensSlopePalOn;
  2560. else
  2561. return 0;
  2562. default:
  2563. return 0;
  2564. }
  2565. }
  2566. static void ath9k_hw_get_AR9287_gain_boundaries_pdadcs(struct ath_hw *ah,
  2567. struct ath9k_channel *chan,
  2568. struct cal_data_per_freq_ar9287 *pRawDataSet,
  2569. u8 *bChans, u16 availPiers,
  2570. u16 tPdGainOverlap, int16_t *pMinCalPower,
  2571. u16 *pPdGainBoundaries, u8 *pPDADCValues,
  2572. u16 numXpdGains)
  2573. {
  2574. #define TMP_VAL_VPD_TABLE \
  2575. ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep));
  2576. int i, j, k;
  2577. int16_t ss;
  2578. u16 idxL = 0, idxR = 0, numPiers;
  2579. u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
  2580. u8 minPwrT4[AR9287_NUM_PD_GAINS];
  2581. u8 maxPwrT4[AR9287_NUM_PD_GAINS];
  2582. int16_t vpdStep;
  2583. int16_t tmpVal;
  2584. u16 sizeCurrVpdTable, maxIndex, tgtIndex;
  2585. bool match;
  2586. int16_t minDelta = 0;
  2587. struct chan_centers centers;
  2588. static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS]
  2589. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  2590. static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS]
  2591. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  2592. static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS]
  2593. [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
  2594. ath9k_hw_get_channel_centers(ah, chan, &centers);
  2595. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  2596. if (bChans[numPiers] == AR9287_BCHAN_UNUSED)
  2597. break;
  2598. }
  2599. match = ath9k_hw_get_lower_upper_index(
  2600. (u8)FREQ2FBIN(centers.synth_center,
  2601. IS_CHAN_2GHZ(chan)), bChans, numPiers,
  2602. &idxL, &idxR);
  2603. if (match) {
  2604. for (i = 0; i < numXpdGains; i++) {
  2605. minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
  2606. maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
  2607. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  2608. pRawDataSet[idxL].pwrPdg[i],
  2609. pRawDataSet[idxL].vpdPdg[i],
  2610. AR9287_PD_GAIN_ICEPTS, vpdTableI[i]);
  2611. }
  2612. } else {
  2613. for (i = 0; i < numXpdGains; i++) {
  2614. pVpdL = pRawDataSet[idxL].vpdPdg[i];
  2615. pPwrL = pRawDataSet[idxL].pwrPdg[i];
  2616. pVpdR = pRawDataSet[idxR].vpdPdg[i];
  2617. pPwrR = pRawDataSet[idxR].pwrPdg[i];
  2618. minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
  2619. maxPwrT4[i] =
  2620. min(pPwrL[AR9287_PD_GAIN_ICEPTS - 1],
  2621. pPwrR[AR9287_PD_GAIN_ICEPTS - 1]);
  2622. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  2623. pPwrL, pVpdL,
  2624. AR9287_PD_GAIN_ICEPTS,
  2625. vpdTableL[i]);
  2626. ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
  2627. pPwrR, pVpdR,
  2628. AR9287_PD_GAIN_ICEPTS,
  2629. vpdTableR[i]);
  2630. for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
  2631. vpdTableI[i][j] =
  2632. (u8)(ath9k_hw_interpolate((u16)
  2633. FREQ2FBIN(centers. synth_center,
  2634. IS_CHAN_2GHZ(chan)),
  2635. bChans[idxL], bChans[idxR],
  2636. vpdTableL[i][j], vpdTableR[i][j]));
  2637. }
  2638. }
  2639. }
  2640. *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
  2641. k = 0;
  2642. for (i = 0; i < numXpdGains; i++) {
  2643. if (i == (numXpdGains - 1))
  2644. pPdGainBoundaries[i] = (u16)(maxPwrT4[i] / 2);
  2645. else
  2646. pPdGainBoundaries[i] = (u16)((maxPwrT4[i] +
  2647. minPwrT4[i+1]) / 4);
  2648. pPdGainBoundaries[i] = min((u16)AR5416_MAX_RATE_POWER,
  2649. pPdGainBoundaries[i]);
  2650. if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
  2651. minDelta = pPdGainBoundaries[0] - 23;
  2652. pPdGainBoundaries[0] = 23;
  2653. } else
  2654. minDelta = 0;
  2655. if (i == 0) {
  2656. if (AR_SREV_9280_10_OR_LATER(ah))
  2657. ss = (int16_t)(0 - (minPwrT4[i] / 2));
  2658. else
  2659. ss = 0;
  2660. } else
  2661. ss = (int16_t)((pPdGainBoundaries[i-1] -
  2662. (minPwrT4[i] / 2)) -
  2663. tPdGainOverlap + 1 + minDelta);
  2664. vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
  2665. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  2666. while ((ss < 0) && (k < (AR9287_NUM_PDADC_VALUES - 1))) {
  2667. tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
  2668. pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
  2669. ss++;
  2670. }
  2671. sizeCurrVpdTable = (u8)((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
  2672. tgtIndex = (u8)(pPdGainBoundaries[i] +
  2673. tPdGainOverlap - (minPwrT4[i] / 2));
  2674. maxIndex = (tgtIndex < sizeCurrVpdTable) ?
  2675. tgtIndex : sizeCurrVpdTable;
  2676. while ((ss < maxIndex) && (k < (AR9287_NUM_PDADC_VALUES - 1)))
  2677. pPDADCValues[k++] = vpdTableI[i][ss++];
  2678. vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
  2679. vpdTableI[i][sizeCurrVpdTable - 2]);
  2680. vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
  2681. if (tgtIndex > maxIndex) {
  2682. while ((ss <= tgtIndex) &&
  2683. (k < (AR9287_NUM_PDADC_VALUES - 1))) {
  2684. tmpVal = (int16_t) TMP_VAL_VPD_TABLE;
  2685. pPDADCValues[k++] = (u8)((tmpVal > 255) ?
  2686. 255 : tmpVal);
  2687. ss++;
  2688. }
  2689. }
  2690. }
  2691. while (i < AR9287_PD_GAINS_IN_MASK) {
  2692. pPdGainBoundaries[i] = pPdGainBoundaries[i-1];
  2693. i++;
  2694. }
  2695. while (k < AR9287_NUM_PDADC_VALUES) {
  2696. pPDADCValues[k] = pPDADCValues[k-1];
  2697. k++;
  2698. }
  2699. #undef TMP_VAL_VPD_TABLE
  2700. }
  2701. static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah,
  2702. struct ath9k_channel *chan,
  2703. struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop,
  2704. u8 *pCalChans, u16 availPiers,
  2705. int8_t *pPwr)
  2706. {
  2707. u8 pcdac, i = 0;
  2708. u16 idxL = 0, idxR = 0, numPiers;
  2709. bool match;
  2710. struct chan_centers centers;
  2711. ath9k_hw_get_channel_centers(ah, chan, &centers);
  2712. for (numPiers = 0; numPiers < availPiers; numPiers++) {
  2713. if (pCalChans[numPiers] == AR9287_BCHAN_UNUSED)
  2714. break;
  2715. }
  2716. match = ath9k_hw_get_lower_upper_index(
  2717. (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
  2718. pCalChans, numPiers,
  2719. &idxL, &idxR);
  2720. if (match) {
  2721. pcdac = pRawDatasetOpLoop[idxL].pcdac[0][0];
  2722. *pPwr = pRawDatasetOpLoop[idxL].pwrPdg[0][0];
  2723. } else {
  2724. pcdac = pRawDatasetOpLoop[idxR].pcdac[0][0];
  2725. *pPwr = (pRawDatasetOpLoop[idxL].pwrPdg[0][0] +
  2726. pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
  2727. }
  2728. while ((pcdac > ah->originalGain[i]) &&
  2729. (i < (AR9280_TX_GAIN_TABLE_SIZE - 1)))
  2730. i++;
  2731. }
  2732. static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah,
  2733. int32_t txPower, u16 chain)
  2734. {
  2735. u32 tmpVal;
  2736. u32 a;
  2737. tmpVal = REG_READ(ah, 0xa270);
  2738. tmpVal = tmpVal & 0xFCFFFFFF;
  2739. tmpVal = tmpVal | (0x3 << 24);
  2740. REG_WRITE(ah, 0xa270, tmpVal);
  2741. tmpVal = REG_READ(ah, 0xb270);
  2742. tmpVal = tmpVal & 0xFCFFFFFF;
  2743. tmpVal = tmpVal | (0x3 << 24);
  2744. REG_WRITE(ah, 0xb270, tmpVal);
  2745. if (chain == 0) {
  2746. tmpVal = REG_READ(ah, 0xa398);
  2747. tmpVal = tmpVal & 0xff00ffff;
  2748. a = (txPower)&0xff;
  2749. tmpVal = tmpVal | (a << 16);
  2750. REG_WRITE(ah, 0xa398, tmpVal);
  2751. }
  2752. if (chain == 1) {
  2753. tmpVal = REG_READ(ah, 0xb398);
  2754. tmpVal = tmpVal & 0xff00ffff;
  2755. a = (txPower)&0xff;
  2756. tmpVal = tmpVal | (a << 16);
  2757. REG_WRITE(ah, 0xb398, tmpVal);
  2758. }
  2759. }
  2760. static void ath9k_hw_set_AR9287_power_cal_table(struct ath_hw *ah,
  2761. struct ath9k_channel *chan, int16_t *pTxPowerIndexOffset)
  2762. {
  2763. struct cal_data_per_freq_ar9287 *pRawDataset;
  2764. struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
  2765. u8 *pCalBChans = NULL;
  2766. u16 pdGainOverlap_t2;
  2767. u8 pdadcValues[AR9287_NUM_PDADC_VALUES];
  2768. u16 gainBoundaries[AR9287_PD_GAINS_IN_MASK];
  2769. u16 numPiers = 0, i, j;
  2770. int16_t tMinCalPower;
  2771. u16 numXpdGain, xpdMask;
  2772. u16 xpdGainValues[AR9287_NUM_PD_GAINS] = {0, 0, 0, 0};
  2773. u32 reg32, regOffset, regChainOffset;
  2774. int16_t modalIdx, diff = 0;
  2775. struct ar9287_eeprom_t *pEepData = &ah->eeprom.map9287;
  2776. modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
  2777. xpdMask = pEepData->modalHeader.xpdGain;
  2778. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  2779. AR9287_EEP_MINOR_VER_2)
  2780. pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
  2781. else
  2782. pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
  2783. AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
  2784. if (IS_CHAN_2GHZ(chan)) {
  2785. pCalBChans = pEepData->calFreqPier2G;
  2786. numPiers = AR9287_NUM_2G_CAL_PIERS;
  2787. if (ath9k_hw_AR9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  2788. pRawDatasetOpenLoop =
  2789. (struct cal_data_op_loop_ar9287 *)
  2790. pEepData->calPierData2G[0];
  2791. ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
  2792. }
  2793. }
  2794. numXpdGain = 0;
  2795. for (i = 1; i <= AR9287_PD_GAINS_IN_MASK; i++) {
  2796. if ((xpdMask >> (AR9287_PD_GAINS_IN_MASK - i)) & 1) {
  2797. if (numXpdGain >= AR9287_NUM_PD_GAINS)
  2798. break;
  2799. xpdGainValues[numXpdGain] =
  2800. (u16)(AR9287_PD_GAINS_IN_MASK-i);
  2801. numXpdGain++;
  2802. }
  2803. }
  2804. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
  2805. (numXpdGain - 1) & 0x3);
  2806. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
  2807. xpdGainValues[0]);
  2808. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
  2809. xpdGainValues[1]);
  2810. REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
  2811. xpdGainValues[2]);
  2812. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  2813. regChainOffset = i * 0x1000;
  2814. if (pEepData->baseEepHeader.txMask & (1 << i)) {
  2815. pRawDatasetOpenLoop = (struct cal_data_op_loop_ar9287 *)
  2816. pEepData->calPierData2G[i];
  2817. if (ath9k_hw_AR9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  2818. int8_t txPower;
  2819. ar9287_eeprom_get_tx_gain_index(ah, chan,
  2820. pRawDatasetOpenLoop,
  2821. pCalBChans, numPiers,
  2822. &txPower);
  2823. ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i);
  2824. } else {
  2825. pRawDataset =
  2826. (struct cal_data_per_freq_ar9287 *)
  2827. pEepData->calPierData2G[i];
  2828. ath9k_hw_get_AR9287_gain_boundaries_pdadcs(
  2829. ah, chan, pRawDataset,
  2830. pCalBChans, numPiers,
  2831. pdGainOverlap_t2,
  2832. &tMinCalPower, gainBoundaries,
  2833. pdadcValues, numXpdGain);
  2834. }
  2835. if (i == 0) {
  2836. if (!ath9k_hw_AR9287_get_eeprom(
  2837. ah, EEP_OL_PWRCTRL)) {
  2838. REG_WRITE(ah, AR_PHY_TPCRG5 +
  2839. regChainOffset,
  2840. SM(pdGainOverlap_t2,
  2841. AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
  2842. SM(gainBoundaries[0],
  2843. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
  2844. | SM(gainBoundaries[1],
  2845. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
  2846. | SM(gainBoundaries[2],
  2847. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
  2848. | SM(gainBoundaries[3],
  2849. AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
  2850. }
  2851. }
  2852. if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB !=
  2853. pEepData->baseEepHeader.pwrTableOffset) {
  2854. diff = (u16)
  2855. (pEepData->baseEepHeader.pwrTableOffset
  2856. - (int32_t)AR9287_PWR_TABLE_OFFSET_DB);
  2857. diff *= 2;
  2858. for (j = 0;
  2859. j < ((u16)AR9287_NUM_PDADC_VALUES-diff);
  2860. j++)
  2861. pdadcValues[j] = pdadcValues[j+diff];
  2862. for (j = (u16)(AR9287_NUM_PDADC_VALUES-diff);
  2863. j < AR9287_NUM_PDADC_VALUES; j++)
  2864. pdadcValues[j] =
  2865. pdadcValues[
  2866. AR9287_NUM_PDADC_VALUES-diff];
  2867. }
  2868. if (!ath9k_hw_AR9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  2869. regOffset = AR_PHY_BASE + (672 << 2) +
  2870. regChainOffset;
  2871. for (j = 0; j < 32; j++) {
  2872. reg32 = ((pdadcValues[4*j + 0]
  2873. & 0xFF) << 0) |
  2874. ((pdadcValues[4*j + 1]
  2875. & 0xFF) << 8) |
  2876. ((pdadcValues[4*j + 2]
  2877. & 0xFF) << 16) |
  2878. ((pdadcValues[4*j + 3]
  2879. & 0xFF) << 24) ;
  2880. REG_WRITE(ah, regOffset, reg32);
  2881. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2882. "PDADC (%d,%4x): %4.4x %8.8x\n",
  2883. i, regChainOffset, regOffset,
  2884. reg32);
  2885. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2886. "PDADC: Chain %d | "
  2887. "PDADC %3d Value %3d | "
  2888. "PDADC %3d Value %3d | "
  2889. "PDADC %3d Value %3d | "
  2890. "PDADC %3d Value %3d |\n",
  2891. i, 4 * j, pdadcValues[4 * j],
  2892. 4 * j + 1,
  2893. pdadcValues[4 * j + 1],
  2894. 4 * j + 2,
  2895. pdadcValues[4 * j + 2],
  2896. 4 * j + 3,
  2897. pdadcValues[4 * j + 3]);
  2898. regOffset += 4;
  2899. }
  2900. }
  2901. }
  2902. }
  2903. *pTxPowerIndexOffset = 0;
  2904. }
  2905. static void ath9k_hw_set_AR9287_power_per_rate_table(struct ath_hw *ah,
  2906. struct ath9k_channel *chan, int16_t *ratesArray, u16 cfgCtl,
  2907. u16 AntennaReduction, u16 twiceMaxRegulatoryPower,
  2908. u16 powerLimit)
  2909. {
  2910. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
  2911. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
  2912. u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  2913. static const u16 tpScaleReductionTable[5] = { 0, 3, 6, 9,
  2914. AR5416_MAX_RATE_POWER };
  2915. int i;
  2916. int16_t twiceLargestAntenna;
  2917. struct cal_ctl_data_ar9287 *rep;
  2918. struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
  2919. targetPowerCck = {0, {0, 0, 0, 0} };
  2920. struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
  2921. targetPowerCckExt = {0, {0, 0, 0, 0} };
  2922. struct cal_target_power_ht targetPowerHt20,
  2923. targetPowerHt40 = {0, {0, 0, 0, 0} };
  2924. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  2925. u16 ctlModesFor11g[] = {CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT,
  2926. CTL_11G_EXT, CTL_2GHT40};
  2927. u16 numCtlModes = 0, *pCtlMode = NULL, ctlMode, freq;
  2928. struct chan_centers centers;
  2929. int tx_chainmask;
  2930. u16 twiceMinEdgePower;
  2931. struct ar9287_eeprom_t *pEepData = &ah->eeprom.map9287;
  2932. tx_chainmask = ah->txchainmask;
  2933. ath9k_hw_get_channel_centers(ah, chan, &centers);
  2934. twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
  2935. pEepData->modalHeader.antennaGainCh[1]);
  2936. twiceLargestAntenna = (int16_t)min((AntennaReduction) -
  2937. twiceLargestAntenna, 0);
  2938. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  2939. if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX)
  2940. maxRegAllowedPower -=
  2941. (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2);
  2942. scaledPower = min(powerLimit, maxRegAllowedPower);
  2943. switch (ar5416_get_ntxchains(tx_chainmask)) {
  2944. case 1:
  2945. break;
  2946. case 2:
  2947. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  2948. break;
  2949. case 3:
  2950. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  2951. break;
  2952. }
  2953. scaledPower = max((u16)0, scaledPower);
  2954. if (IS_CHAN_2GHZ(chan)) {
  2955. numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
  2956. SUB_NUM_CTL_MODES_AT_2G_40;
  2957. pCtlMode = ctlModesFor11g;
  2958. ath9k_hw_get_legacy_target_powers(ah, chan,
  2959. pEepData->calTargetPowerCck,
  2960. AR9287_NUM_2G_CCK_TARGET_POWERS,
  2961. &targetPowerCck, 4, false);
  2962. ath9k_hw_get_legacy_target_powers(ah, chan,
  2963. pEepData->calTargetPower2G,
  2964. AR9287_NUM_2G_20_TARGET_POWERS,
  2965. &targetPowerOfdm, 4, false);
  2966. ath9k_hw_get_target_powers(ah, chan,
  2967. pEepData->calTargetPower2GHT20,
  2968. AR9287_NUM_2G_20_TARGET_POWERS,
  2969. &targetPowerHt20, 8, false);
  2970. if (IS_CHAN_HT40(chan)) {
  2971. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  2972. ath9k_hw_get_target_powers(ah, chan,
  2973. pEepData->calTargetPower2GHT40,
  2974. AR9287_NUM_2G_40_TARGET_POWERS,
  2975. &targetPowerHt40, 8, true);
  2976. ath9k_hw_get_legacy_target_powers(ah, chan,
  2977. pEepData->calTargetPowerCck,
  2978. AR9287_NUM_2G_CCK_TARGET_POWERS,
  2979. &targetPowerCckExt, 4, true);
  2980. ath9k_hw_get_legacy_target_powers(ah, chan,
  2981. pEepData->calTargetPower2G,
  2982. AR9287_NUM_2G_20_TARGET_POWERS,
  2983. &targetPowerOfdmExt, 4, true);
  2984. }
  2985. }
  2986. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  2987. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  2988. (pCtlMode[ctlMode] == CTL_2GHT40);
  2989. if (isHt40CtlMode)
  2990. freq = centers.synth_center;
  2991. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  2992. freq = centers.ext_center;
  2993. else
  2994. freq = centers.ctl_center;
  2995. if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
  2996. ah->eep_ops->get_eeprom_rev(ah) <= 2)
  2997. twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
  2998. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  2999. "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d,"
  3000. "EXT_ADDITIVE %d\n", ctlMode, numCtlModes,
  3001. isHt40CtlMode, (pCtlMode[ctlMode] & EXT_ADDITIVE));
  3002. for (i = 0; (i < AR9287_NUM_CTLS)
  3003. && pEepData->ctlIndex[i]; i++) {
  3004. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  3005. "LOOP-Ctlidx %d: cfgCtl 0x%2.2x"
  3006. "pCtlMode 0x%2.2x ctlIndex 0x%2.2x"
  3007. "chan %d chanctl=xxxx\n",
  3008. i, cfgCtl, pCtlMode[ctlMode],
  3009. pEepData->ctlIndex[i], chan->channel);
  3010. if ((((cfgCtl & ~CTL_MODE_M) |
  3011. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  3012. pEepData->ctlIndex[i]) ||
  3013. (((cfgCtl & ~CTL_MODE_M) |
  3014. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  3015. ((pEepData->ctlIndex[i] &
  3016. CTL_MODE_M) | SD_NO_CTL))) {
  3017. rep = &(pEepData->ctlData[i]);
  3018. twiceMinEdgePower = ath9k_hw_get_max_edge_power(
  3019. freq,
  3020. rep->ctlEdges[ar5416_get_ntxchains(
  3021. tx_chainmask) - 1],
  3022. IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
  3023. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  3024. "MATCH-EE_IDX %d: ch %d is2 %d"
  3025. "2xMinEdge %d chainmask %d chains %d\n",
  3026. i, freq, IS_CHAN_2GHZ(chan),
  3027. twiceMinEdgePower, tx_chainmask,
  3028. ar5416_get_ntxchains(tx_chainmask));
  3029. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL)
  3030. twiceMaxEdgePower = min(
  3031. twiceMaxEdgePower,
  3032. twiceMinEdgePower);
  3033. else {
  3034. twiceMaxEdgePower = twiceMinEdgePower;
  3035. break;
  3036. }
  3037. }
  3038. }
  3039. minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
  3040. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  3041. "SEL-Min ctlMode %d pCtlMode %d 2xMaxEdge %d"
  3042. "sP %d minCtlPwr %d\n",
  3043. ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
  3044. scaledPower, minCtlPower);
  3045. switch (pCtlMode[ctlMode]) {
  3046. case CTL_11B:
  3047. for (i = 0;
  3048. i < ARRAY_SIZE(targetPowerCck.tPow2x);
  3049. i++) {
  3050. targetPowerCck.tPow2x[i] = (u8)min(
  3051. (u16)targetPowerCck.tPow2x[i],
  3052. minCtlPower);
  3053. }
  3054. break;
  3055. case CTL_11A:
  3056. case CTL_11G:
  3057. for (i = 0;
  3058. i < ARRAY_SIZE(targetPowerOfdm.tPow2x);
  3059. i++) {
  3060. targetPowerOfdm.tPow2x[i] = (u8)min(
  3061. (u16)targetPowerOfdm.tPow2x[i],
  3062. minCtlPower);
  3063. }
  3064. break;
  3065. case CTL_5GHT20:
  3066. case CTL_2GHT20:
  3067. for (i = 0;
  3068. i < ARRAY_SIZE(targetPowerHt20.tPow2x);
  3069. i++) {
  3070. targetPowerHt20.tPow2x[i] = (u8)min(
  3071. (u16)targetPowerHt20.tPow2x[i],
  3072. minCtlPower);
  3073. }
  3074. break;
  3075. case CTL_11B_EXT:
  3076. targetPowerCckExt.tPow2x[0] = (u8)min(
  3077. (u16)targetPowerCckExt.tPow2x[0],
  3078. minCtlPower);
  3079. break;
  3080. case CTL_11A_EXT:
  3081. case CTL_11G_EXT:
  3082. targetPowerOfdmExt.tPow2x[0] = (u8)min(
  3083. (u16)targetPowerOfdmExt.tPow2x[0],
  3084. minCtlPower);
  3085. break;
  3086. case CTL_5GHT40:
  3087. case CTL_2GHT40:
  3088. for (i = 0;
  3089. i < ARRAY_SIZE(targetPowerHt40.tPow2x);
  3090. i++) {
  3091. targetPowerHt40.tPow2x[i] = (u8)min(
  3092. (u16)targetPowerHt40.tPow2x[i],
  3093. minCtlPower);
  3094. }
  3095. break;
  3096. default:
  3097. break;
  3098. }
  3099. }
  3100. ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
  3101. ratesArray[rate18mb] = ratesArray[rate24mb] =
  3102. targetPowerOfdm.tPow2x[0];
  3103. ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
  3104. ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
  3105. ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
  3106. ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
  3107. for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
  3108. ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
  3109. if (IS_CHAN_2GHZ(chan)) {
  3110. ratesArray[rate1l] = targetPowerCck.tPow2x[0];
  3111. ratesArray[rate2s] = ratesArray[rate2l] =
  3112. targetPowerCck.tPow2x[1];
  3113. ratesArray[rate5_5s] = ratesArray[rate5_5l] =
  3114. targetPowerCck.tPow2x[2];
  3115. ratesArray[rate11s] = ratesArray[rate11l] =
  3116. targetPowerCck.tPow2x[3];
  3117. }
  3118. if (IS_CHAN_HT40(chan)) {
  3119. for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++)
  3120. ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i];
  3121. ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
  3122. ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
  3123. ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
  3124. if (IS_CHAN_2GHZ(chan))
  3125. ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
  3126. }
  3127. #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
  3128. #undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
  3129. }
  3130. static void ath9k_hw_AR9287_set_txpower(struct ath_hw *ah,
  3131. struct ath9k_channel *chan, u16 cfgCtl,
  3132. u8 twiceAntennaReduction, u8 twiceMaxRegulatoryPower,
  3133. u8 powerLimit)
  3134. {
  3135. #define INCREASE_MAXPOW_BY_TWO_CHAIN 6
  3136. #define INCREASE_MAXPOW_BY_THREE_CHAIN 10
  3137. struct ar9287_eeprom_t *pEepData = &ah->eeprom.map9287;
  3138. struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader;
  3139. int16_t ratesArray[Ar5416RateSize];
  3140. int16_t txPowerIndexOffset = 0;
  3141. u8 ht40PowerIncForPdadc = 2;
  3142. int i;
  3143. memset(ratesArray, 0, sizeof(ratesArray));
  3144. if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
  3145. AR9287_EEP_MINOR_VER_2)
  3146. ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
  3147. ath9k_hw_set_AR9287_power_per_rate_table(ah, chan,
  3148. &ratesArray[0], cfgCtl,
  3149. twiceAntennaReduction,
  3150. twiceMaxRegulatoryPower,
  3151. powerLimit);
  3152. ath9k_hw_set_AR9287_power_cal_table(ah, chan, &txPowerIndexOffset);
  3153. for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
  3154. ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
  3155. if (ratesArray[i] > AR9287_MAX_RATE_POWER)
  3156. ratesArray[i] = AR9287_MAX_RATE_POWER;
  3157. }
  3158. if (AR_SREV_9280_10_OR_LATER(ah)) {
  3159. for (i = 0; i < Ar5416RateSize; i++)
  3160. ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
  3161. }
  3162. REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
  3163. ATH9K_POW_SM(ratesArray[rate18mb], 24)
  3164. | ATH9K_POW_SM(ratesArray[rate12mb], 16)
  3165. | ATH9K_POW_SM(ratesArray[rate9mb], 8)
  3166. | ATH9K_POW_SM(ratesArray[rate6mb], 0)
  3167. );
  3168. REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
  3169. ATH9K_POW_SM(ratesArray[rate54mb], 24)
  3170. | ATH9K_POW_SM(ratesArray[rate48mb], 16)
  3171. | ATH9K_POW_SM(ratesArray[rate36mb], 8)
  3172. | ATH9K_POW_SM(ratesArray[rate24mb], 0)
  3173. );
  3174. if (IS_CHAN_2GHZ(chan)) {
  3175. REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
  3176. ATH9K_POW_SM(ratesArray[rate2s], 24)
  3177. | ATH9K_POW_SM(ratesArray[rate2l], 16)
  3178. | ATH9K_POW_SM(ratesArray[rateXr], 8)
  3179. | ATH9K_POW_SM(ratesArray[rate1l], 0)
  3180. );
  3181. REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
  3182. ATH9K_POW_SM(ratesArray[rate11s], 24)
  3183. | ATH9K_POW_SM(ratesArray[rate11l], 16)
  3184. | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
  3185. | ATH9K_POW_SM(ratesArray[rate5_5l], 0)
  3186. );
  3187. }
  3188. REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
  3189. ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
  3190. | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
  3191. | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
  3192. | ATH9K_POW_SM(ratesArray[rateHt20_0], 0)
  3193. );
  3194. REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
  3195. ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
  3196. | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
  3197. | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
  3198. | ATH9K_POW_SM(ratesArray[rateHt20_4], 0)
  3199. );
  3200. if (IS_CHAN_HT40(chan)) {
  3201. if (ath9k_hw_AR9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
  3202. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  3203. ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
  3204. | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
  3205. | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
  3206. | ATH9K_POW_SM(ratesArray[rateHt40_0], 0)
  3207. );
  3208. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  3209. ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
  3210. | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
  3211. | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
  3212. | ATH9K_POW_SM(ratesArray[rateHt40_4], 0)
  3213. );
  3214. } else {
  3215. REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
  3216. ATH9K_POW_SM(ratesArray[rateHt40_3] +
  3217. ht40PowerIncForPdadc, 24)
  3218. | ATH9K_POW_SM(ratesArray[rateHt40_2] +
  3219. ht40PowerIncForPdadc, 16)
  3220. | ATH9K_POW_SM(ratesArray[rateHt40_1] +
  3221. ht40PowerIncForPdadc, 8)
  3222. | ATH9K_POW_SM(ratesArray[rateHt40_0] +
  3223. ht40PowerIncForPdadc, 0)
  3224. );
  3225. REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
  3226. ATH9K_POW_SM(ratesArray[rateHt40_7] +
  3227. ht40PowerIncForPdadc, 24)
  3228. | ATH9K_POW_SM(ratesArray[rateHt40_6] +
  3229. ht40PowerIncForPdadc, 16)
  3230. | ATH9K_POW_SM(ratesArray[rateHt40_5] +
  3231. ht40PowerIncForPdadc, 8)
  3232. | ATH9K_POW_SM(ratesArray[rateHt40_4] +
  3233. ht40PowerIncForPdadc, 0)
  3234. );
  3235. }
  3236. REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
  3237. ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
  3238. | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
  3239. | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
  3240. | ATH9K_POW_SM(ratesArray[rateDupCck], 0)
  3241. );
  3242. }
  3243. if (IS_CHAN_2GHZ(chan))
  3244. i = rate1l;
  3245. else
  3246. i = rate6mb;
  3247. if (AR_SREV_9280_10_OR_LATER(ah))
  3248. ah->regulatory.max_power_level =
  3249. ratesArray[i] + AR9287_PWR_TABLE_OFFSET_DB * 2;
  3250. else
  3251. ah->regulatory.max_power_level = ratesArray[i];
  3252. switch (ar5416_get_ntxchains(ah->txchainmask)) {
  3253. case 1:
  3254. break;
  3255. case 2:
  3256. ah->regulatory.max_power_level +=
  3257. INCREASE_MAXPOW_BY_TWO_CHAIN;
  3258. break;
  3259. case 3:
  3260. ah->regulatory.max_power_level +=
  3261. INCREASE_MAXPOW_BY_THREE_CHAIN;
  3262. break;
  3263. default:
  3264. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  3265. "Invalid chainmask configuration\n");
  3266. break;
  3267. }
  3268. }
  3269. static void ath9k_hw_AR9287_set_addac(struct ath_hw *ah,
  3270. struct ath9k_channel *chan)
  3271. {
  3272. return;
  3273. }
  3274. static void ath9k_hw_AR9287_set_board_values(struct ath_hw *ah,
  3275. struct ath9k_channel *chan)
  3276. {
  3277. struct ar9287_eeprom_t *eep = &ah->eeprom.map9287;
  3278. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  3279. u16 antWrites[AR9287_ANT_16S];
  3280. u32 regChainOffset;
  3281. u8 txRxAttenLocal;
  3282. int i, j, offset_num;
  3283. pModal = &eep->modalHeader;
  3284. antWrites[0] = (u16)((pModal->antCtrlCommon >> 28) & 0xF);
  3285. antWrites[1] = (u16)((pModal->antCtrlCommon >> 24) & 0xF);
  3286. antWrites[2] = (u16)((pModal->antCtrlCommon >> 20) & 0xF);
  3287. antWrites[3] = (u16)((pModal->antCtrlCommon >> 16) & 0xF);
  3288. antWrites[4] = (u16)((pModal->antCtrlCommon >> 12) & 0xF);
  3289. antWrites[5] = (u16)((pModal->antCtrlCommon >> 8) & 0xF);
  3290. antWrites[6] = (u16)((pModal->antCtrlCommon >> 4) & 0xF);
  3291. antWrites[7] = (u16)(pModal->antCtrlCommon & 0xF);
  3292. offset_num = 8;
  3293. for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) {
  3294. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 28) & 0xf);
  3295. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 10) & 0x3);
  3296. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 8) & 0x3);
  3297. antWrites[j++] = 0;
  3298. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 6) & 0x3);
  3299. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 4) & 0x3);
  3300. antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 2) & 0x3);
  3301. antWrites[j++] = (u16)(pModal->antCtrlChain[i] & 0x3);
  3302. }
  3303. REG_WRITE(ah, AR_PHY_SWITCH_COM,
  3304. ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
  3305. for (i = 0; i < AR9287_MAX_CHAINS; i++) {
  3306. regChainOffset = i * 0x1000;
  3307. REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
  3308. pModal->antCtrlChain[i]);
  3309. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
  3310. (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
  3311. & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
  3312. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
  3313. SM(pModal->iqCalICh[i],
  3314. AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
  3315. SM(pModal->iqCalQCh[i],
  3316. AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
  3317. txRxAttenLocal = pModal->txRxAttenCh[i];
  3318. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  3319. AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
  3320. pModal->bswMargin[i]);
  3321. REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
  3322. AR_PHY_GAIN_2GHZ_XATTEN1_DB,
  3323. pModal->bswAtten[i]);
  3324. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  3325. AR9280_PHY_RXGAIN_TXRX_ATTEN,
  3326. txRxAttenLocal);
  3327. REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
  3328. AR9280_PHY_RXGAIN_TXRX_MARGIN,
  3329. pModal->rxTxMarginCh[i]);
  3330. }
  3331. if (IS_CHAN_HT40(chan))
  3332. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  3333. AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
  3334. else
  3335. REG_RMW_FIELD(ah, AR_PHY_SETTLING,
  3336. AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
  3337. REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
  3338. AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
  3339. REG_WRITE(ah, AR_PHY_RF_CTL4,
  3340. SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
  3341. | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
  3342. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
  3343. | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
  3344. REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
  3345. AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
  3346. REG_RMW_FIELD(ah, AR_PHY_CCA,
  3347. AR9280_PHY_CCA_THRESH62, pModal->thresh62);
  3348. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
  3349. AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
  3350. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0, AR9287_AN_RF2G3_DB1,
  3351. AR9287_AN_RF2G3_DB1_S, pModal->db1);
  3352. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0, AR9287_AN_RF2G3_DB2,
  3353. AR9287_AN_RF2G3_DB2_S, pModal->db2);
  3354. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0,
  3355. AR9287_AN_RF2G3_OB_CCK,
  3356. AR9287_AN_RF2G3_OB_CCK_S, pModal->ob_cck);
  3357. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0,
  3358. AR9287_AN_RF2G3_OB_PSK,
  3359. AR9287_AN_RF2G3_OB_PSK_S, pModal->ob_psk);
  3360. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0,
  3361. AR9287_AN_RF2G3_OB_QAM,
  3362. AR9287_AN_RF2G3_OB_QAM_S, pModal->ob_qam);
  3363. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH0,
  3364. AR9287_AN_RF2G3_OB_PAL_OFF,
  3365. AR9287_AN_RF2G3_OB_PAL_OFF_S,
  3366. pModal->ob_pal_off);
  3367. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1,
  3368. AR9287_AN_RF2G3_DB1, AR9287_AN_RF2G3_DB1_S,
  3369. pModal->db1);
  3370. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1, AR9287_AN_RF2G3_DB2,
  3371. AR9287_AN_RF2G3_DB2_S, pModal->db2);
  3372. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1,
  3373. AR9287_AN_RF2G3_OB_CCK,
  3374. AR9287_AN_RF2G3_OB_CCK_S, pModal->ob_cck);
  3375. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1,
  3376. AR9287_AN_RF2G3_OB_PSK,
  3377. AR9287_AN_RF2G3_OB_PSK_S, pModal->ob_psk);
  3378. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1,
  3379. AR9287_AN_RF2G3_OB_QAM,
  3380. AR9287_AN_RF2G3_OB_QAM_S, pModal->ob_qam);
  3381. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_RF2G3_CH1,
  3382. AR9287_AN_RF2G3_OB_PAL_OFF,
  3383. AR9287_AN_RF2G3_OB_PAL_OFF_S,
  3384. pModal->ob_pal_off);
  3385. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  3386. AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
  3387. REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
  3388. AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
  3389. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
  3390. AR9287_AN_TOP2_XPABIAS_LVL,
  3391. AR9287_AN_TOP2_XPABIAS_LVL_S,
  3392. pModal->xpaBiasLvl);
  3393. }
  3394. static u8 ath9k_hw_AR9287_get_num_ant_config(struct ath_hw *ah,
  3395. enum ieee80211_band freq_band)
  3396. {
  3397. return 1;
  3398. }
  3399. static u16 ath9k_hw_AR9287_get_eeprom_antenna_cfg(struct ath_hw *ah,
  3400. struct ath9k_channel *chan)
  3401. {
  3402. struct ar9287_eeprom_t *eep = &ah->eeprom.map9287;
  3403. struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
  3404. return pModal->antCtrlCommon & 0xFFFF;
  3405. }
  3406. static u16 ath9k_hw_AR9287_get_spur_channel(struct ath_hw *ah,
  3407. u16 i, bool is2GHz)
  3408. {
  3409. #define EEP_MAP9287_SPURCHAN \
  3410. (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan)
  3411. u16 spur_val = AR_NO_SPUR;
  3412. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  3413. "Getting spur idx %d is2Ghz. %d val %x\n",
  3414. i, is2GHz, ah->config.spurchans[i][is2GHz]);
  3415. switch (ah->config.spurmode) {
  3416. case SPUR_DISABLE:
  3417. break;
  3418. case SPUR_ENABLE_IOCTL:
  3419. spur_val = ah->config.spurchans[i][is2GHz];
  3420. DPRINTF(ah->ah_sc, ATH_DBG_ANI,
  3421. "Getting spur val from new loc. %d\n", spur_val);
  3422. break;
  3423. case SPUR_ENABLE_EEPROM:
  3424. spur_val = EEP_MAP9287_SPURCHAN;
  3425. break;
  3426. }
  3427. return spur_val;
  3428. #undef EEP_MAP9287_SPURCHAN
  3429. }
  3430. static struct eeprom_ops eep_AR9287_ops = {
  3431. .check_eeprom = ath9k_hw_AR9287_check_eeprom,
  3432. .get_eeprom = ath9k_hw_AR9287_get_eeprom,
  3433. .fill_eeprom = ath9k_hw_AR9287_fill_eeprom,
  3434. .get_eeprom_ver = ath9k_hw_AR9287_get_eeprom_ver,
  3435. .get_eeprom_rev = ath9k_hw_AR9287_get_eeprom_rev,
  3436. .get_num_ant_config = ath9k_hw_AR9287_get_num_ant_config,
  3437. .get_eeprom_antenna_cfg = ath9k_hw_AR9287_get_eeprom_antenna_cfg,
  3438. .set_board_values = ath9k_hw_AR9287_set_board_values,
  3439. .set_addac = ath9k_hw_AR9287_set_addac,
  3440. .set_txpower = ath9k_hw_AR9287_set_txpower,
  3441. .get_spur_channel = ath9k_hw_AR9287_get_spur_channel
  3442. };
  3443. int ath9k_hw_eeprom_attach(struct ath_hw *ah)
  3444. {
  3445. int status;
  3446. if (AR_SREV_9287(ah)) {
  3447. ah->eep_map = EEP_MAP_AR9287;
  3448. ah->eep_ops = &eep_AR9287_ops;
  3449. } else if (AR_SREV_9285(ah)) {
  3450. ah->eep_map = EEP_MAP_4KBITS;
  3451. ah->eep_ops = &eep_4k_ops;
  3452. } else {
  3453. ah->eep_map = EEP_MAP_DEFAULT;
  3454. ah->eep_ops = &eep_def_ops;
  3455. }
  3456. if (!ah->eep_ops->fill_eeprom(ah))
  3457. return -EIO;
  3458. status = ah->eep_ops->check_eeprom(ah);
  3459. return status;
  3460. }