eeprom.c 79 KB

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