eeprom.c 80 KB

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