eeprom.c 80 KB

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