eeprom.c 79 KB

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