eeprom.c 80 KB

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