ar9003_eeprom.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222
  1. /*
  2. * Copyright (c) 2010 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 "hw.h"
  17. #include "ar9003_phy.h"
  18. #include "ar9003_eeprom.h"
  19. #define COMP_HDR_LEN 4
  20. #define COMP_CKSUM_LEN 2
  21. #define AR_CH0_TOP (0x00016288)
  22. #define AR_CH0_TOP_XPABIASLVL (0x3)
  23. #define AR_CH0_TOP_XPABIASLVL_S (8)
  24. #define AR_CH0_THERM (0x00016290)
  25. #define AR_CH0_THERM_SPARE (0x3f)
  26. #define AR_CH0_THERM_SPARE_S (0)
  27. #define AR_SWITCH_TABLE_COM_ALL (0xffff)
  28. #define AR_SWITCH_TABLE_COM_ALL_S (0)
  29. #define AR_SWITCH_TABLE_COM2_ALL (0xffffff)
  30. #define AR_SWITCH_TABLE_COM2_ALL_S (0)
  31. #define AR_SWITCH_TABLE_ALL (0xfff)
  32. #define AR_SWITCH_TABLE_ALL_S (0)
  33. #define LE16(x) __constant_cpu_to_le16(x)
  34. #define LE32(x) __constant_cpu_to_le32(x)
  35. /* Local defines to distinguish between extension and control CTL's */
  36. #define EXT_ADDITIVE (0x8000)
  37. #define CTL_11A_EXT (CTL_11A | EXT_ADDITIVE)
  38. #define CTL_11G_EXT (CTL_11G | EXT_ADDITIVE)
  39. #define CTL_11B_EXT (CTL_11B | EXT_ADDITIVE)
  40. #define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */
  41. #define REDUCE_SCALED_POWER_BY_THREE_CHAIN 9 /* 10*log10(3)*2 */
  42. #define PWRINCR_3_TO_1_CHAIN 9 /* 10*log(3)*2 */
  43. #define PWRINCR_3_TO_2_CHAIN 3 /* floor(10*log(3/2)*2) */
  44. #define PWRINCR_2_TO_1_CHAIN 6 /* 10*log(2)*2 */
  45. #define SUB_NUM_CTL_MODES_AT_5G_40 2 /* excluding HT40, EXT-OFDM */
  46. #define SUB_NUM_CTL_MODES_AT_2G_40 3 /* excluding HT40, EXT-OFDM, EXT-CCK */
  47. #define CTL(_tpower, _flag) ((_tpower) | ((_flag) << 6))
  48. static const struct ar9300_eeprom ar9300_default = {
  49. .eepromVersion = 2,
  50. .templateVersion = 2,
  51. .macAddr = {1, 2, 3, 4, 5, 6},
  52. .custData = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  53. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  54. .baseEepHeader = {
  55. .regDmn = { LE16(0), LE16(0x1f) },
  56. .txrxMask = 0x77, /* 4 bits tx and 4 bits rx */
  57. .opCapFlags = {
  58. .opFlags = AR9300_OPFLAGS_11G | AR9300_OPFLAGS_11A,
  59. .eepMisc = 0,
  60. },
  61. .rfSilent = 0,
  62. .blueToothOptions = 0,
  63. .deviceCap = 0,
  64. .deviceType = 5, /* takes lower byte in eeprom location */
  65. .pwrTableOffset = AR9300_PWR_TABLE_OFFSET,
  66. .params_for_tuning_caps = {0, 0},
  67. .featureEnable = 0x0c,
  68. /*
  69. * bit0 - enable tx temp comp - disabled
  70. * bit1 - enable tx volt comp - disabled
  71. * bit2 - enable fastClock - enabled
  72. * bit3 - enable doubling - enabled
  73. * bit4 - enable internal regulator - disabled
  74. * bit5 - enable pa predistortion - disabled
  75. */
  76. .miscConfiguration = 0, /* bit0 - turn down drivestrength */
  77. .eepromWriteEnableGpio = 3,
  78. .wlanDisableGpio = 0,
  79. .wlanLedGpio = 8,
  80. .rxBandSelectGpio = 0xff,
  81. .txrxgain = 0,
  82. .swreg = 0,
  83. },
  84. .modalHeader2G = {
  85. /* ar9300_modal_eep_header 2g */
  86. /* 4 idle,t1,t2,b(4 bits per setting) */
  87. .antCtrlCommon = LE32(0x110),
  88. /* 4 ra1l1, ra2l1, ra1l2, ra2l2, ra12 */
  89. .antCtrlCommon2 = LE32(0x22222),
  90. /*
  91. * antCtrlChain[AR9300_MAX_CHAINS]; 6 idle, t, r,
  92. * rx1, rx12, b (2 bits each)
  93. */
  94. .antCtrlChain = { LE16(0x150), LE16(0x150), LE16(0x150) },
  95. /*
  96. * xatten1DB[AR9300_MAX_CHAINS]; 3 xatten1_db
  97. * for ar9280 (0xa20c/b20c 5:0)
  98. */
  99. .xatten1DB = {0, 0, 0},
  100. /*
  101. * xatten1Margin[AR9300_MAX_CHAINS]; 3 xatten1_margin
  102. * for ar9280 (0xa20c/b20c 16:12
  103. */
  104. .xatten1Margin = {0, 0, 0},
  105. .tempSlope = 36,
  106. .voltSlope = 0,
  107. /*
  108. * spurChans[OSPREY_EEPROM_MODAL_SPURS]; spur
  109. * channels in usual fbin coding format
  110. */
  111. .spurChans = {0, 0, 0, 0, 0},
  112. /*
  113. * noiseFloorThreshCh[AR9300_MAX_CHAINS]; 3 Check
  114. * if the register is per chain
  115. */
  116. .noiseFloorThreshCh = {-1, 0, 0},
  117. .ob = {1, 1, 1},/* 3 chain */
  118. .db_stage2 = {1, 1, 1}, /* 3 chain */
  119. .db_stage3 = {0, 0, 0},
  120. .db_stage4 = {0, 0, 0},
  121. .xpaBiasLvl = 0,
  122. .txFrameToDataStart = 0x0e,
  123. .txFrameToPaOn = 0x0e,
  124. .txClip = 3, /* 4 bits tx_clip, 4 bits dac_scale_cck */
  125. .antennaGain = 0,
  126. .switchSettling = 0x2c,
  127. .adcDesiredSize = -30,
  128. .txEndToXpaOff = 0,
  129. .txEndToRxOn = 0x2,
  130. .txFrameToXpaOn = 0xe,
  131. .thresh62 = 28,
  132. .papdRateMaskHt20 = LE32(0x80c080),
  133. .papdRateMaskHt40 = LE32(0x80c080),
  134. .futureModal = {
  135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  136. 0, 0, 0, 0, 0, 0, 0, 0
  137. },
  138. },
  139. .calFreqPier2G = {
  140. FREQ2FBIN(2412, 1),
  141. FREQ2FBIN(2437, 1),
  142. FREQ2FBIN(2472, 1),
  143. },
  144. /* ar9300_cal_data_per_freq_op_loop 2g */
  145. .calPierData2G = {
  146. { {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0} },
  147. { {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0} },
  148. { {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0} },
  149. },
  150. .calTarget_freqbin_Cck = {
  151. FREQ2FBIN(2412, 1),
  152. FREQ2FBIN(2484, 1),
  153. },
  154. .calTarget_freqbin_2G = {
  155. FREQ2FBIN(2412, 1),
  156. FREQ2FBIN(2437, 1),
  157. FREQ2FBIN(2472, 1)
  158. },
  159. .calTarget_freqbin_2GHT20 = {
  160. FREQ2FBIN(2412, 1),
  161. FREQ2FBIN(2437, 1),
  162. FREQ2FBIN(2472, 1)
  163. },
  164. .calTarget_freqbin_2GHT40 = {
  165. FREQ2FBIN(2412, 1),
  166. FREQ2FBIN(2437, 1),
  167. FREQ2FBIN(2472, 1)
  168. },
  169. .calTargetPowerCck = {
  170. /* 1L-5L,5S,11L,11S */
  171. { {36, 36, 36, 36} },
  172. { {36, 36, 36, 36} },
  173. },
  174. .calTargetPower2G = {
  175. /* 6-24,36,48,54 */
  176. { {32, 32, 28, 24} },
  177. { {32, 32, 28, 24} },
  178. { {32, 32, 28, 24} },
  179. },
  180. .calTargetPower2GHT20 = {
  181. { {32, 32, 32, 32, 28, 20, 32, 32, 28, 20, 32, 32, 28, 20} },
  182. { {32, 32, 32, 32, 28, 20, 32, 32, 28, 20, 32, 32, 28, 20} },
  183. { {32, 32, 32, 32, 28, 20, 32, 32, 28, 20, 32, 32, 28, 20} },
  184. },
  185. .calTargetPower2GHT40 = {
  186. { {32, 32, 32, 32, 28, 20, 32, 32, 28, 20, 32, 32, 28, 20} },
  187. { {32, 32, 32, 32, 28, 20, 32, 32, 28, 20, 32, 32, 28, 20} },
  188. { {32, 32, 32, 32, 28, 20, 32, 32, 28, 20, 32, 32, 28, 20} },
  189. },
  190. .ctlIndex_2G = {
  191. 0x11, 0x12, 0x15, 0x17, 0x41, 0x42,
  192. 0x45, 0x47, 0x31, 0x32, 0x35, 0x37,
  193. },
  194. .ctl_freqbin_2G = {
  195. {
  196. FREQ2FBIN(2412, 1),
  197. FREQ2FBIN(2417, 1),
  198. FREQ2FBIN(2457, 1),
  199. FREQ2FBIN(2462, 1)
  200. },
  201. {
  202. FREQ2FBIN(2412, 1),
  203. FREQ2FBIN(2417, 1),
  204. FREQ2FBIN(2462, 1),
  205. 0xFF,
  206. },
  207. {
  208. FREQ2FBIN(2412, 1),
  209. FREQ2FBIN(2417, 1),
  210. FREQ2FBIN(2462, 1),
  211. 0xFF,
  212. },
  213. {
  214. FREQ2FBIN(2422, 1),
  215. FREQ2FBIN(2427, 1),
  216. FREQ2FBIN(2447, 1),
  217. FREQ2FBIN(2452, 1)
  218. },
  219. {
  220. /* Data[4].ctlEdges[0].bChannel */ FREQ2FBIN(2412, 1),
  221. /* Data[4].ctlEdges[1].bChannel */ FREQ2FBIN(2417, 1),
  222. /* Data[4].ctlEdges[2].bChannel */ FREQ2FBIN(2472, 1),
  223. /* Data[4].ctlEdges[3].bChannel */ FREQ2FBIN(2484, 1),
  224. },
  225. {
  226. /* Data[5].ctlEdges[0].bChannel */ FREQ2FBIN(2412, 1),
  227. /* Data[5].ctlEdges[1].bChannel */ FREQ2FBIN(2417, 1),
  228. /* Data[5].ctlEdges[2].bChannel */ FREQ2FBIN(2472, 1),
  229. 0,
  230. },
  231. {
  232. /* Data[6].ctlEdges[0].bChannel */ FREQ2FBIN(2412, 1),
  233. /* Data[6].ctlEdges[1].bChannel */ FREQ2FBIN(2417, 1),
  234. FREQ2FBIN(2472, 1),
  235. 0,
  236. },
  237. {
  238. /* Data[7].ctlEdges[0].bChannel */ FREQ2FBIN(2422, 1),
  239. /* Data[7].ctlEdges[1].bChannel */ FREQ2FBIN(2427, 1),
  240. /* Data[7].ctlEdges[2].bChannel */ FREQ2FBIN(2447, 1),
  241. /* Data[7].ctlEdges[3].bChannel */ FREQ2FBIN(2462, 1),
  242. },
  243. {
  244. /* Data[8].ctlEdges[0].bChannel */ FREQ2FBIN(2412, 1),
  245. /* Data[8].ctlEdges[1].bChannel */ FREQ2FBIN(2417, 1),
  246. /* Data[8].ctlEdges[2].bChannel */ FREQ2FBIN(2472, 1),
  247. },
  248. {
  249. /* Data[9].ctlEdges[0].bChannel */ FREQ2FBIN(2412, 1),
  250. /* Data[9].ctlEdges[1].bChannel */ FREQ2FBIN(2417, 1),
  251. /* Data[9].ctlEdges[2].bChannel */ FREQ2FBIN(2472, 1),
  252. 0
  253. },
  254. {
  255. /* Data[10].ctlEdges[0].bChannel */ FREQ2FBIN(2412, 1),
  256. /* Data[10].ctlEdges[1].bChannel */ FREQ2FBIN(2417, 1),
  257. /* Data[10].ctlEdges[2].bChannel */ FREQ2FBIN(2472, 1),
  258. 0
  259. },
  260. {
  261. /* Data[11].ctlEdges[0].bChannel */ FREQ2FBIN(2422, 1),
  262. /* Data[11].ctlEdges[1].bChannel */ FREQ2FBIN(2427, 1),
  263. /* Data[11].ctlEdges[2].bChannel */ FREQ2FBIN(2447, 1),
  264. /* Data[11].ctlEdges[3].bChannel */
  265. FREQ2FBIN(2462, 1),
  266. }
  267. },
  268. .ctlPowerData_2G = {
  269. { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
  270. { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
  271. { { CTL(60, 1), CTL(60, 0), CTL(60, 0), CTL(60, 1) } },
  272. { { CTL(60, 1), CTL(60, 0), CTL(0, 0), CTL(0, 0) } },
  273. { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
  274. { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
  275. { { CTL(60, 0), CTL(60, 1), CTL(60, 1), CTL(60, 0) } },
  276. { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
  277. { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
  278. { { CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 0) } },
  279. { { CTL(60, 0), CTL(60, 1), CTL(60, 1), CTL(60, 1) } },
  280. { { CTL(60, 0), CTL(60, 1), CTL(60, 1), CTL(60, 1) } },
  281. },
  282. .modalHeader5G = {
  283. /* 4 idle,t1,t2,b (4 bits per setting) */
  284. .antCtrlCommon = LE32(0x110),
  285. /* 4 ra1l1, ra2l1, ra1l2,ra2l2,ra12 */
  286. .antCtrlCommon2 = LE32(0x22222),
  287. /* antCtrlChain 6 idle, t,r,rx1,rx12,b (2 bits each) */
  288. .antCtrlChain = {
  289. LE16(0x000), LE16(0x000), LE16(0x000),
  290. },
  291. /* xatten1DB 3 xatten1_db for AR9280 (0xa20c/b20c 5:0) */
  292. .xatten1DB = {0, 0, 0},
  293. /*
  294. * xatten1Margin[AR9300_MAX_CHAINS]; 3 xatten1_margin
  295. * for merlin (0xa20c/b20c 16:12
  296. */
  297. .xatten1Margin = {0, 0, 0},
  298. .tempSlope = 68,
  299. .voltSlope = 0,
  300. /* spurChans spur channels in usual fbin coding format */
  301. .spurChans = {0, 0, 0, 0, 0},
  302. /* noiseFloorThreshCh Check if the register is per chain */
  303. .noiseFloorThreshCh = {-1, 0, 0},
  304. .ob = {3, 3, 3}, /* 3 chain */
  305. .db_stage2 = {3, 3, 3}, /* 3 chain */
  306. .db_stage3 = {3, 3, 3}, /* doesn't exist for 2G */
  307. .db_stage4 = {3, 3, 3}, /* don't exist for 2G */
  308. .xpaBiasLvl = 0,
  309. .txFrameToDataStart = 0x0e,
  310. .txFrameToPaOn = 0x0e,
  311. .txClip = 3, /* 4 bits tx_clip, 4 bits dac_scale_cck */
  312. .antennaGain = 0,
  313. .switchSettling = 0x2d,
  314. .adcDesiredSize = -30,
  315. .txEndToXpaOff = 0,
  316. .txEndToRxOn = 0x2,
  317. .txFrameToXpaOn = 0xe,
  318. .thresh62 = 28,
  319. .papdRateMaskHt20 = LE32(0xf0e0e0),
  320. .papdRateMaskHt40 = LE32(0xf0e0e0),
  321. .futureModal = {
  322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  323. 0, 0, 0, 0, 0, 0, 0, 0
  324. },
  325. },
  326. .calFreqPier5G = {
  327. FREQ2FBIN(5180, 0),
  328. FREQ2FBIN(5220, 0),
  329. FREQ2FBIN(5320, 0),
  330. FREQ2FBIN(5400, 0),
  331. FREQ2FBIN(5500, 0),
  332. FREQ2FBIN(5600, 0),
  333. FREQ2FBIN(5725, 0),
  334. FREQ2FBIN(5825, 0)
  335. },
  336. .calPierData5G = {
  337. {
  338. {0, 0, 0, 0, 0},
  339. {0, 0, 0, 0, 0},
  340. {0, 0, 0, 0, 0},
  341. {0, 0, 0, 0, 0},
  342. {0, 0, 0, 0, 0},
  343. {0, 0, 0, 0, 0},
  344. {0, 0, 0, 0, 0},
  345. {0, 0, 0, 0, 0},
  346. },
  347. {
  348. {0, 0, 0, 0, 0},
  349. {0, 0, 0, 0, 0},
  350. {0, 0, 0, 0, 0},
  351. {0, 0, 0, 0, 0},
  352. {0, 0, 0, 0, 0},
  353. {0, 0, 0, 0, 0},
  354. {0, 0, 0, 0, 0},
  355. {0, 0, 0, 0, 0},
  356. },
  357. {
  358. {0, 0, 0, 0, 0},
  359. {0, 0, 0, 0, 0},
  360. {0, 0, 0, 0, 0},
  361. {0, 0, 0, 0, 0},
  362. {0, 0, 0, 0, 0},
  363. {0, 0, 0, 0, 0},
  364. {0, 0, 0, 0, 0},
  365. {0, 0, 0, 0, 0},
  366. },
  367. },
  368. .calTarget_freqbin_5G = {
  369. FREQ2FBIN(5180, 0),
  370. FREQ2FBIN(5220, 0),
  371. FREQ2FBIN(5320, 0),
  372. FREQ2FBIN(5400, 0),
  373. FREQ2FBIN(5500, 0),
  374. FREQ2FBIN(5600, 0),
  375. FREQ2FBIN(5725, 0),
  376. FREQ2FBIN(5825, 0)
  377. },
  378. .calTarget_freqbin_5GHT20 = {
  379. FREQ2FBIN(5180, 0),
  380. FREQ2FBIN(5240, 0),
  381. FREQ2FBIN(5320, 0),
  382. FREQ2FBIN(5500, 0),
  383. FREQ2FBIN(5700, 0),
  384. FREQ2FBIN(5745, 0),
  385. FREQ2FBIN(5725, 0),
  386. FREQ2FBIN(5825, 0)
  387. },
  388. .calTarget_freqbin_5GHT40 = {
  389. FREQ2FBIN(5180, 0),
  390. FREQ2FBIN(5240, 0),
  391. FREQ2FBIN(5320, 0),
  392. FREQ2FBIN(5500, 0),
  393. FREQ2FBIN(5700, 0),
  394. FREQ2FBIN(5745, 0),
  395. FREQ2FBIN(5725, 0),
  396. FREQ2FBIN(5825, 0)
  397. },
  398. .calTargetPower5G = {
  399. /* 6-24,36,48,54 */
  400. { {20, 20, 20, 10} },
  401. { {20, 20, 20, 10} },
  402. { {20, 20, 20, 10} },
  403. { {20, 20, 20, 10} },
  404. { {20, 20, 20, 10} },
  405. { {20, 20, 20, 10} },
  406. { {20, 20, 20, 10} },
  407. { {20, 20, 20, 10} },
  408. },
  409. .calTargetPower5GHT20 = {
  410. /*
  411. * 0_8_16,1-3_9-11_17-19,
  412. * 4,5,6,7,12,13,14,15,20,21,22,23
  413. */
  414. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  415. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  416. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  417. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  418. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  419. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  420. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  421. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  422. },
  423. .calTargetPower5GHT40 = {
  424. /*
  425. * 0_8_16,1-3_9-11_17-19,
  426. * 4,5,6,7,12,13,14,15,20,21,22,23
  427. */
  428. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  429. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  430. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  431. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  432. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  433. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  434. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  435. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  436. },
  437. .ctlIndex_5G = {
  438. 0x10, 0x16, 0x18, 0x40, 0x46,
  439. 0x48, 0x30, 0x36, 0x38
  440. },
  441. .ctl_freqbin_5G = {
  442. {
  443. /* Data[0].ctlEdges[0].bChannel */ FREQ2FBIN(5180, 0),
  444. /* Data[0].ctlEdges[1].bChannel */ FREQ2FBIN(5260, 0),
  445. /* Data[0].ctlEdges[2].bChannel */ FREQ2FBIN(5280, 0),
  446. /* Data[0].ctlEdges[3].bChannel */ FREQ2FBIN(5500, 0),
  447. /* Data[0].ctlEdges[4].bChannel */ FREQ2FBIN(5600, 0),
  448. /* Data[0].ctlEdges[5].bChannel */ FREQ2FBIN(5700, 0),
  449. /* Data[0].ctlEdges[6].bChannel */ FREQ2FBIN(5745, 0),
  450. /* Data[0].ctlEdges[7].bChannel */ FREQ2FBIN(5825, 0)
  451. },
  452. {
  453. /* Data[1].ctlEdges[0].bChannel */ FREQ2FBIN(5180, 0),
  454. /* Data[1].ctlEdges[1].bChannel */ FREQ2FBIN(5260, 0),
  455. /* Data[1].ctlEdges[2].bChannel */ FREQ2FBIN(5280, 0),
  456. /* Data[1].ctlEdges[3].bChannel */ FREQ2FBIN(5500, 0),
  457. /* Data[1].ctlEdges[4].bChannel */ FREQ2FBIN(5520, 0),
  458. /* Data[1].ctlEdges[5].bChannel */ FREQ2FBIN(5700, 0),
  459. /* Data[1].ctlEdges[6].bChannel */ FREQ2FBIN(5745, 0),
  460. /* Data[1].ctlEdges[7].bChannel */ FREQ2FBIN(5825, 0)
  461. },
  462. {
  463. /* Data[2].ctlEdges[0].bChannel */ FREQ2FBIN(5190, 0),
  464. /* Data[2].ctlEdges[1].bChannel */ FREQ2FBIN(5230, 0),
  465. /* Data[2].ctlEdges[2].bChannel */ FREQ2FBIN(5270, 0),
  466. /* Data[2].ctlEdges[3].bChannel */ FREQ2FBIN(5310, 0),
  467. /* Data[2].ctlEdges[4].bChannel */ FREQ2FBIN(5510, 0),
  468. /* Data[2].ctlEdges[5].bChannel */ FREQ2FBIN(5550, 0),
  469. /* Data[2].ctlEdges[6].bChannel */ FREQ2FBIN(5670, 0),
  470. /* Data[2].ctlEdges[7].bChannel */ FREQ2FBIN(5755, 0)
  471. },
  472. {
  473. /* Data[3].ctlEdges[0].bChannel */ FREQ2FBIN(5180, 0),
  474. /* Data[3].ctlEdges[1].bChannel */ FREQ2FBIN(5200, 0),
  475. /* Data[3].ctlEdges[2].bChannel */ FREQ2FBIN(5260, 0),
  476. /* Data[3].ctlEdges[3].bChannel */ FREQ2FBIN(5320, 0),
  477. /* Data[3].ctlEdges[4].bChannel */ FREQ2FBIN(5500, 0),
  478. /* Data[3].ctlEdges[5].bChannel */ FREQ2FBIN(5700, 0),
  479. /* Data[3].ctlEdges[6].bChannel */ 0xFF,
  480. /* Data[3].ctlEdges[7].bChannel */ 0xFF,
  481. },
  482. {
  483. /* Data[4].ctlEdges[0].bChannel */ FREQ2FBIN(5180, 0),
  484. /* Data[4].ctlEdges[1].bChannel */ FREQ2FBIN(5260, 0),
  485. /* Data[4].ctlEdges[2].bChannel */ FREQ2FBIN(5500, 0),
  486. /* Data[4].ctlEdges[3].bChannel */ FREQ2FBIN(5700, 0),
  487. /* Data[4].ctlEdges[4].bChannel */ 0xFF,
  488. /* Data[4].ctlEdges[5].bChannel */ 0xFF,
  489. /* Data[4].ctlEdges[6].bChannel */ 0xFF,
  490. /* Data[4].ctlEdges[7].bChannel */ 0xFF,
  491. },
  492. {
  493. /* Data[5].ctlEdges[0].bChannel */ FREQ2FBIN(5190, 0),
  494. /* Data[5].ctlEdges[1].bChannel */ FREQ2FBIN(5270, 0),
  495. /* Data[5].ctlEdges[2].bChannel */ FREQ2FBIN(5310, 0),
  496. /* Data[5].ctlEdges[3].bChannel */ FREQ2FBIN(5510, 0),
  497. /* Data[5].ctlEdges[4].bChannel */ FREQ2FBIN(5590, 0),
  498. /* Data[5].ctlEdges[5].bChannel */ FREQ2FBIN(5670, 0),
  499. /* Data[5].ctlEdges[6].bChannel */ 0xFF,
  500. /* Data[5].ctlEdges[7].bChannel */ 0xFF
  501. },
  502. {
  503. /* Data[6].ctlEdges[0].bChannel */ FREQ2FBIN(5180, 0),
  504. /* Data[6].ctlEdges[1].bChannel */ FREQ2FBIN(5200, 0),
  505. /* Data[6].ctlEdges[2].bChannel */ FREQ2FBIN(5220, 0),
  506. /* Data[6].ctlEdges[3].bChannel */ FREQ2FBIN(5260, 0),
  507. /* Data[6].ctlEdges[4].bChannel */ FREQ2FBIN(5500, 0),
  508. /* Data[6].ctlEdges[5].bChannel */ FREQ2FBIN(5600, 0),
  509. /* Data[6].ctlEdges[6].bChannel */ FREQ2FBIN(5700, 0),
  510. /* Data[6].ctlEdges[7].bChannel */ FREQ2FBIN(5745, 0)
  511. },
  512. {
  513. /* Data[7].ctlEdges[0].bChannel */ FREQ2FBIN(5180, 0),
  514. /* Data[7].ctlEdges[1].bChannel */ FREQ2FBIN(5260, 0),
  515. /* Data[7].ctlEdges[2].bChannel */ FREQ2FBIN(5320, 0),
  516. /* Data[7].ctlEdges[3].bChannel */ FREQ2FBIN(5500, 0),
  517. /* Data[7].ctlEdges[4].bChannel */ FREQ2FBIN(5560, 0),
  518. /* Data[7].ctlEdges[5].bChannel */ FREQ2FBIN(5700, 0),
  519. /* Data[7].ctlEdges[6].bChannel */ FREQ2FBIN(5745, 0),
  520. /* Data[7].ctlEdges[7].bChannel */ FREQ2FBIN(5825, 0)
  521. },
  522. {
  523. /* Data[8].ctlEdges[0].bChannel */ FREQ2FBIN(5190, 0),
  524. /* Data[8].ctlEdges[1].bChannel */ FREQ2FBIN(5230, 0),
  525. /* Data[8].ctlEdges[2].bChannel */ FREQ2FBIN(5270, 0),
  526. /* Data[8].ctlEdges[3].bChannel */ FREQ2FBIN(5510, 0),
  527. /* Data[8].ctlEdges[4].bChannel */ FREQ2FBIN(5550, 0),
  528. /* Data[8].ctlEdges[5].bChannel */ FREQ2FBIN(5670, 0),
  529. /* Data[8].ctlEdges[6].bChannel */ FREQ2FBIN(5755, 0),
  530. /* Data[8].ctlEdges[7].bChannel */ FREQ2FBIN(5795, 0)
  531. }
  532. },
  533. .ctlPowerData_5G = {
  534. {
  535. {
  536. CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 1),
  537. CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 0),
  538. }
  539. },
  540. {
  541. {
  542. CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 1),
  543. CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 0),
  544. }
  545. },
  546. {
  547. {
  548. CTL(60, 0), CTL(60, 1), CTL(60, 0), CTL(60, 1),
  549. CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 1),
  550. }
  551. },
  552. {
  553. {
  554. CTL(60, 0), CTL(60, 1), CTL(60, 1), CTL(60, 0),
  555. CTL(60, 1), CTL(60, 0), CTL(60, 0), CTL(60, 0),
  556. }
  557. },
  558. {
  559. {
  560. CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 0),
  561. CTL(60, 0), CTL(60, 0), CTL(60, 0), CTL(60, 0),
  562. }
  563. },
  564. {
  565. {
  566. CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 1),
  567. CTL(60, 1), CTL(60, 0), CTL(60, 0), CTL(60, 0),
  568. }
  569. },
  570. {
  571. {
  572. CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 1),
  573. CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 1),
  574. }
  575. },
  576. {
  577. {
  578. CTL(60, 1), CTL(60, 1), CTL(60, 0), CTL(60, 1),
  579. CTL(60, 1), CTL(60, 1), CTL(60, 1), CTL(60, 0),
  580. }
  581. },
  582. {
  583. {
  584. CTL(60, 1), CTL(60, 0), CTL(60, 1), CTL(60, 1),
  585. CTL(60, 1), CTL(60, 1), CTL(60, 0), CTL(60, 1),
  586. }
  587. },
  588. }
  589. };
  590. static u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz)
  591. {
  592. if (fbin == AR9300_BCHAN_UNUSED)
  593. return fbin;
  594. return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
  595. }
  596. static int ath9k_hw_ar9300_check_eeprom(struct ath_hw *ah)
  597. {
  598. return 0;
  599. }
  600. static u32 ath9k_hw_ar9300_get_eeprom(struct ath_hw *ah,
  601. enum eeprom_param param)
  602. {
  603. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  604. struct ar9300_base_eep_hdr *pBase = &eep->baseEepHeader;
  605. switch (param) {
  606. case EEP_MAC_LSW:
  607. return eep->macAddr[0] << 8 | eep->macAddr[1];
  608. case EEP_MAC_MID:
  609. return eep->macAddr[2] << 8 | eep->macAddr[3];
  610. case EEP_MAC_MSW:
  611. return eep->macAddr[4] << 8 | eep->macAddr[5];
  612. case EEP_REG_0:
  613. return le16_to_cpu(pBase->regDmn[0]);
  614. case EEP_REG_1:
  615. return le16_to_cpu(pBase->regDmn[1]);
  616. case EEP_OP_CAP:
  617. return pBase->deviceCap;
  618. case EEP_OP_MODE:
  619. return pBase->opCapFlags.opFlags;
  620. case EEP_RF_SILENT:
  621. return pBase->rfSilent;
  622. case EEP_TX_MASK:
  623. return (pBase->txrxMask >> 4) & 0xf;
  624. case EEP_RX_MASK:
  625. return pBase->txrxMask & 0xf;
  626. case EEP_DRIVE_STRENGTH:
  627. #define AR9300_EEP_BASE_DRIV_STRENGTH 0x1
  628. return pBase->miscConfiguration & AR9300_EEP_BASE_DRIV_STRENGTH;
  629. case EEP_INTERNAL_REGULATOR:
  630. /* Bit 4 is internal regulator flag */
  631. return (pBase->featureEnable & 0x10) >> 4;
  632. case EEP_SWREG:
  633. return le32_to_cpu(pBase->swreg);
  634. case EEP_PAPRD:
  635. return !!(pBase->featureEnable & BIT(5));
  636. default:
  637. return 0;
  638. }
  639. }
  640. static bool ar9300_eeprom_read_byte(struct ath_common *common, int address,
  641. u8 *buffer)
  642. {
  643. u16 val;
  644. if (unlikely(!ath9k_hw_nvram_read(common, address / 2, &val)))
  645. return false;
  646. *buffer = (val >> (8 * (address % 2))) & 0xff;
  647. return true;
  648. }
  649. static bool ar9300_eeprom_read_word(struct ath_common *common, int address,
  650. u8 *buffer)
  651. {
  652. u16 val;
  653. if (unlikely(!ath9k_hw_nvram_read(common, address / 2, &val)))
  654. return false;
  655. buffer[0] = val >> 8;
  656. buffer[1] = val & 0xff;
  657. return true;
  658. }
  659. static bool ar9300_read_eeprom(struct ath_hw *ah, int address, u8 *buffer,
  660. int count)
  661. {
  662. struct ath_common *common = ath9k_hw_common(ah);
  663. int i;
  664. if ((address < 0) || ((address + count) / 2 > AR9300_EEPROM_SIZE - 1)) {
  665. ath_print(common, ATH_DBG_EEPROM,
  666. "eeprom address not in range\n");
  667. return false;
  668. }
  669. /*
  670. * Since we're reading the bytes in reverse order from a little-endian
  671. * word stream, an even address means we only use the lower half of
  672. * the 16-bit word at that address
  673. */
  674. if (address % 2 == 0) {
  675. if (!ar9300_eeprom_read_byte(common, address--, buffer++))
  676. goto error;
  677. count--;
  678. }
  679. for (i = 0; i < count / 2; i++) {
  680. if (!ar9300_eeprom_read_word(common, address, buffer))
  681. goto error;
  682. address -= 2;
  683. buffer += 2;
  684. }
  685. if (count % 2)
  686. if (!ar9300_eeprom_read_byte(common, address, buffer))
  687. goto error;
  688. return true;
  689. error:
  690. ath_print(common, ATH_DBG_EEPROM,
  691. "unable to read eeprom region at offset %d\n", address);
  692. return false;
  693. }
  694. static void ar9300_comp_hdr_unpack(u8 *best, int *code, int *reference,
  695. int *length, int *major, int *minor)
  696. {
  697. unsigned long value[4];
  698. value[0] = best[0];
  699. value[1] = best[1];
  700. value[2] = best[2];
  701. value[3] = best[3];
  702. *code = ((value[0] >> 5) & 0x0007);
  703. *reference = (value[0] & 0x001f) | ((value[1] >> 2) & 0x0020);
  704. *length = ((value[1] << 4) & 0x07f0) | ((value[2] >> 4) & 0x000f);
  705. *major = (value[2] & 0x000f);
  706. *minor = (value[3] & 0x00ff);
  707. }
  708. static u16 ar9300_comp_cksum(u8 *data, int dsize)
  709. {
  710. int it, checksum = 0;
  711. for (it = 0; it < dsize; it++) {
  712. checksum += data[it];
  713. checksum &= 0xffff;
  714. }
  715. return checksum;
  716. }
  717. static bool ar9300_uncompress_block(struct ath_hw *ah,
  718. u8 *mptr,
  719. int mdataSize,
  720. u8 *block,
  721. int size)
  722. {
  723. int it;
  724. int spot;
  725. int offset;
  726. int length;
  727. struct ath_common *common = ath9k_hw_common(ah);
  728. spot = 0;
  729. for (it = 0; it < size; it += (length+2)) {
  730. offset = block[it];
  731. offset &= 0xff;
  732. spot += offset;
  733. length = block[it+1];
  734. length &= 0xff;
  735. if (length > 0 && spot >= 0 && spot+length <= mdataSize) {
  736. ath_print(common, ATH_DBG_EEPROM,
  737. "Restore at %d: spot=%d "
  738. "offset=%d length=%d\n",
  739. it, spot, offset, length);
  740. memcpy(&mptr[spot], &block[it+2], length);
  741. spot += length;
  742. } else if (length > 0) {
  743. ath_print(common, ATH_DBG_EEPROM,
  744. "Bad restore at %d: spot=%d "
  745. "offset=%d length=%d\n",
  746. it, spot, offset, length);
  747. return false;
  748. }
  749. }
  750. return true;
  751. }
  752. static int ar9300_compress_decision(struct ath_hw *ah,
  753. int it,
  754. int code,
  755. int reference,
  756. u8 *mptr,
  757. u8 *word, int length, int mdata_size)
  758. {
  759. struct ath_common *common = ath9k_hw_common(ah);
  760. u8 *dptr;
  761. switch (code) {
  762. case _CompressNone:
  763. if (length != mdata_size) {
  764. ath_print(common, ATH_DBG_EEPROM,
  765. "EEPROM structure size mismatch"
  766. "memory=%d eeprom=%d\n", mdata_size, length);
  767. return -1;
  768. }
  769. memcpy(mptr, (u8 *) (word + COMP_HDR_LEN), length);
  770. ath_print(common, ATH_DBG_EEPROM, "restored eeprom %d:"
  771. " uncompressed, length %d\n", it, length);
  772. break;
  773. case _CompressBlock:
  774. if (reference == 0) {
  775. dptr = mptr;
  776. } else {
  777. if (reference != 2) {
  778. ath_print(common, ATH_DBG_EEPROM,
  779. "cant find reference eeprom"
  780. "struct %d\n", reference);
  781. return -1;
  782. }
  783. memcpy(mptr, &ar9300_default, mdata_size);
  784. }
  785. ath_print(common, ATH_DBG_EEPROM,
  786. "restore eeprom %d: block, reference %d,"
  787. " length %d\n", it, reference, length);
  788. ar9300_uncompress_block(ah, mptr, mdata_size,
  789. (u8 *) (word + COMP_HDR_LEN), length);
  790. break;
  791. default:
  792. ath_print(common, ATH_DBG_EEPROM, "unknown compression"
  793. " code %d\n", code);
  794. return -1;
  795. }
  796. return 0;
  797. }
  798. /*
  799. * Read the configuration data from the eeprom.
  800. * The data can be put in any specified memory buffer.
  801. *
  802. * Returns -1 on error.
  803. * Returns address of next memory location on success.
  804. */
  805. static int ar9300_eeprom_restore_internal(struct ath_hw *ah,
  806. u8 *mptr, int mdata_size)
  807. {
  808. #define MDEFAULT 15
  809. #define MSTATE 100
  810. int cptr;
  811. u8 *word;
  812. int code;
  813. int reference, length, major, minor;
  814. int osize;
  815. int it;
  816. u16 checksum, mchecksum;
  817. struct ath_common *common = ath9k_hw_common(ah);
  818. word = kzalloc(2048, GFP_KERNEL);
  819. if (!word)
  820. return -1;
  821. memcpy(mptr, &ar9300_default, mdata_size);
  822. cptr = AR9300_BASE_ADDR;
  823. for (it = 0; it < MSTATE; it++) {
  824. if (!ar9300_read_eeprom(ah, cptr, word, COMP_HDR_LEN))
  825. goto fail;
  826. if ((word[0] == 0 && word[1] == 0 && word[2] == 0 &&
  827. word[3] == 0) || (word[0] == 0xff && word[1] == 0xff
  828. && word[2] == 0xff && word[3] == 0xff))
  829. break;
  830. ar9300_comp_hdr_unpack(word, &code, &reference,
  831. &length, &major, &minor);
  832. ath_print(common, ATH_DBG_EEPROM,
  833. "Found block at %x: code=%d ref=%d"
  834. "length=%d major=%d minor=%d\n", cptr, code,
  835. reference, length, major, minor);
  836. if (length >= 1024) {
  837. ath_print(common, ATH_DBG_EEPROM,
  838. "Skipping bad header\n");
  839. cptr -= COMP_HDR_LEN;
  840. continue;
  841. }
  842. osize = length;
  843. ar9300_read_eeprom(ah, cptr, word,
  844. COMP_HDR_LEN + osize + COMP_CKSUM_LEN);
  845. checksum = ar9300_comp_cksum(&word[COMP_HDR_LEN], length);
  846. mchecksum = word[COMP_HDR_LEN + osize] |
  847. (word[COMP_HDR_LEN + osize + 1] << 8);
  848. ath_print(common, ATH_DBG_EEPROM,
  849. "checksum %x %x\n", checksum, mchecksum);
  850. if (checksum == mchecksum) {
  851. ar9300_compress_decision(ah, it, code, reference, mptr,
  852. word, length, mdata_size);
  853. } else {
  854. ath_print(common, ATH_DBG_EEPROM,
  855. "skipping block with bad checksum\n");
  856. }
  857. cptr -= (COMP_HDR_LEN + osize + COMP_CKSUM_LEN);
  858. }
  859. kfree(word);
  860. return cptr;
  861. fail:
  862. kfree(word);
  863. return -1;
  864. }
  865. /*
  866. * Restore the configuration structure by reading the eeprom.
  867. * This function destroys any existing in-memory structure
  868. * content.
  869. */
  870. static bool ath9k_hw_ar9300_fill_eeprom(struct ath_hw *ah)
  871. {
  872. u8 *mptr = (u8 *) &ah->eeprom.ar9300_eep;
  873. if (ar9300_eeprom_restore_internal(ah, mptr,
  874. sizeof(struct ar9300_eeprom)) < 0)
  875. return false;
  876. return true;
  877. }
  878. /* XXX: review hardware docs */
  879. static int ath9k_hw_ar9300_get_eeprom_ver(struct ath_hw *ah)
  880. {
  881. return ah->eeprom.ar9300_eep.eepromVersion;
  882. }
  883. /* XXX: could be read from the eepromVersion, not sure yet */
  884. static int ath9k_hw_ar9300_get_eeprom_rev(struct ath_hw *ah)
  885. {
  886. return 0;
  887. }
  888. static u8 ath9k_hw_ar9300_get_num_ant_config(struct ath_hw *ah,
  889. enum ath9k_hal_freq_band freq_band)
  890. {
  891. return 1;
  892. }
  893. static u32 ath9k_hw_ar9300_get_eeprom_antenna_cfg(struct ath_hw *ah,
  894. struct ath9k_channel *chan)
  895. {
  896. return -EINVAL;
  897. }
  898. static s32 ar9003_hw_xpa_bias_level_get(struct ath_hw *ah, bool is2ghz)
  899. {
  900. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  901. if (is2ghz)
  902. return eep->modalHeader2G.xpaBiasLvl;
  903. else
  904. return eep->modalHeader5G.xpaBiasLvl;
  905. }
  906. static void ar9003_hw_xpa_bias_level_apply(struct ath_hw *ah, bool is2ghz)
  907. {
  908. int bias = ar9003_hw_xpa_bias_level_get(ah, is2ghz);
  909. REG_RMW_FIELD(ah, AR_CH0_TOP, AR_CH0_TOP_XPABIASLVL, (bias & 0x3));
  910. REG_RMW_FIELD(ah, AR_CH0_THERM, AR_CH0_THERM_SPARE,
  911. ((bias >> 2) & 0x3));
  912. }
  913. static u32 ar9003_hw_ant_ctrl_common_get(struct ath_hw *ah, bool is2ghz)
  914. {
  915. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  916. __le32 val;
  917. if (is2ghz)
  918. val = eep->modalHeader2G.antCtrlCommon;
  919. else
  920. val = eep->modalHeader5G.antCtrlCommon;
  921. return le32_to_cpu(val);
  922. }
  923. static u32 ar9003_hw_ant_ctrl_common_2_get(struct ath_hw *ah, bool is2ghz)
  924. {
  925. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  926. __le32 val;
  927. if (is2ghz)
  928. val = eep->modalHeader2G.antCtrlCommon2;
  929. else
  930. val = eep->modalHeader5G.antCtrlCommon2;
  931. return le32_to_cpu(val);
  932. }
  933. static u16 ar9003_hw_ant_ctrl_chain_get(struct ath_hw *ah,
  934. int chain,
  935. bool is2ghz)
  936. {
  937. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  938. __le16 val = 0;
  939. if (chain >= 0 && chain < AR9300_MAX_CHAINS) {
  940. if (is2ghz)
  941. val = eep->modalHeader2G.antCtrlChain[chain];
  942. else
  943. val = eep->modalHeader5G.antCtrlChain[chain];
  944. }
  945. return le16_to_cpu(val);
  946. }
  947. static void ar9003_hw_ant_ctrl_apply(struct ath_hw *ah, bool is2ghz)
  948. {
  949. u32 value = ar9003_hw_ant_ctrl_common_get(ah, is2ghz);
  950. REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM, AR_SWITCH_TABLE_COM_ALL, value);
  951. value = ar9003_hw_ant_ctrl_common_2_get(ah, is2ghz);
  952. REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2, AR_SWITCH_TABLE_COM2_ALL, value);
  953. value = ar9003_hw_ant_ctrl_chain_get(ah, 0, is2ghz);
  954. REG_RMW_FIELD(ah, AR_PHY_SWITCH_CHAIN_0, AR_SWITCH_TABLE_ALL, value);
  955. value = ar9003_hw_ant_ctrl_chain_get(ah, 1, is2ghz);
  956. REG_RMW_FIELD(ah, AR_PHY_SWITCH_CHAIN_1, AR_SWITCH_TABLE_ALL, value);
  957. value = ar9003_hw_ant_ctrl_chain_get(ah, 2, is2ghz);
  958. REG_RMW_FIELD(ah, AR_PHY_SWITCH_CHAIN_2, AR_SWITCH_TABLE_ALL, value);
  959. }
  960. static void ar9003_hw_drive_strength_apply(struct ath_hw *ah)
  961. {
  962. int drive_strength;
  963. unsigned long reg;
  964. drive_strength = ath9k_hw_ar9300_get_eeprom(ah, EEP_DRIVE_STRENGTH);
  965. if (!drive_strength)
  966. return;
  967. reg = REG_READ(ah, AR_PHY_65NM_CH0_BIAS1);
  968. reg &= ~0x00ffffc0;
  969. reg |= 0x5 << 21;
  970. reg |= 0x5 << 18;
  971. reg |= 0x5 << 15;
  972. reg |= 0x5 << 12;
  973. reg |= 0x5 << 9;
  974. reg |= 0x5 << 6;
  975. REG_WRITE(ah, AR_PHY_65NM_CH0_BIAS1, reg);
  976. reg = REG_READ(ah, AR_PHY_65NM_CH0_BIAS2);
  977. reg &= ~0xffffffe0;
  978. reg |= 0x5 << 29;
  979. reg |= 0x5 << 26;
  980. reg |= 0x5 << 23;
  981. reg |= 0x5 << 20;
  982. reg |= 0x5 << 17;
  983. reg |= 0x5 << 14;
  984. reg |= 0x5 << 11;
  985. reg |= 0x5 << 8;
  986. reg |= 0x5 << 5;
  987. REG_WRITE(ah, AR_PHY_65NM_CH0_BIAS2, reg);
  988. reg = REG_READ(ah, AR_PHY_65NM_CH0_BIAS4);
  989. reg &= ~0xff800000;
  990. reg |= 0x5 << 29;
  991. reg |= 0x5 << 26;
  992. reg |= 0x5 << 23;
  993. REG_WRITE(ah, AR_PHY_65NM_CH0_BIAS4, reg);
  994. }
  995. static void ar9003_hw_internal_regulator_apply(struct ath_hw *ah)
  996. {
  997. int internal_regulator =
  998. ath9k_hw_ar9300_get_eeprom(ah, EEP_INTERNAL_REGULATOR);
  999. if (internal_regulator) {
  1000. /* Internal regulator is ON. Write swreg register. */
  1001. int swreg = ath9k_hw_ar9300_get_eeprom(ah, EEP_SWREG);
  1002. REG_WRITE(ah, AR_RTC_REG_CONTROL1,
  1003. REG_READ(ah, AR_RTC_REG_CONTROL1) &
  1004. (~AR_RTC_REG_CONTROL1_SWREG_PROGRAM));
  1005. REG_WRITE(ah, AR_RTC_REG_CONTROL0, swreg);
  1006. /* Set REG_CONTROL1.SWREG_PROGRAM */
  1007. REG_WRITE(ah, AR_RTC_REG_CONTROL1,
  1008. REG_READ(ah,
  1009. AR_RTC_REG_CONTROL1) |
  1010. AR_RTC_REG_CONTROL1_SWREG_PROGRAM);
  1011. } else {
  1012. REG_WRITE(ah, AR_RTC_SLEEP_CLK,
  1013. (REG_READ(ah,
  1014. AR_RTC_SLEEP_CLK) |
  1015. AR_RTC_FORCE_SWREG_PRD));
  1016. }
  1017. }
  1018. static void ath9k_hw_ar9300_set_board_values(struct ath_hw *ah,
  1019. struct ath9k_channel *chan)
  1020. {
  1021. ar9003_hw_xpa_bias_level_apply(ah, IS_CHAN_2GHZ(chan));
  1022. ar9003_hw_ant_ctrl_apply(ah, IS_CHAN_2GHZ(chan));
  1023. ar9003_hw_drive_strength_apply(ah);
  1024. ar9003_hw_internal_regulator_apply(ah);
  1025. }
  1026. static void ath9k_hw_ar9300_set_addac(struct ath_hw *ah,
  1027. struct ath9k_channel *chan)
  1028. {
  1029. }
  1030. /*
  1031. * Returns the interpolated y value corresponding to the specified x value
  1032. * from the np ordered pairs of data (px,py).
  1033. * The pairs do not have to be in any order.
  1034. * If the specified x value is less than any of the px,
  1035. * the returned y value is equal to the py for the lowest px.
  1036. * If the specified x value is greater than any of the px,
  1037. * the returned y value is equal to the py for the highest px.
  1038. */
  1039. static int ar9003_hw_power_interpolate(int32_t x,
  1040. int32_t *px, int32_t *py, u_int16_t np)
  1041. {
  1042. int ip = 0;
  1043. int lx = 0, ly = 0, lhave = 0;
  1044. int hx = 0, hy = 0, hhave = 0;
  1045. int dx = 0;
  1046. int y = 0;
  1047. lhave = 0;
  1048. hhave = 0;
  1049. /* identify best lower and higher x calibration measurement */
  1050. for (ip = 0; ip < np; ip++) {
  1051. dx = x - px[ip];
  1052. /* this measurement is higher than our desired x */
  1053. if (dx <= 0) {
  1054. if (!hhave || dx > (x - hx)) {
  1055. /* new best higher x measurement */
  1056. hx = px[ip];
  1057. hy = py[ip];
  1058. hhave = 1;
  1059. }
  1060. }
  1061. /* this measurement is lower than our desired x */
  1062. if (dx >= 0) {
  1063. if (!lhave || dx < (x - lx)) {
  1064. /* new best lower x measurement */
  1065. lx = px[ip];
  1066. ly = py[ip];
  1067. lhave = 1;
  1068. }
  1069. }
  1070. }
  1071. /* the low x is good */
  1072. if (lhave) {
  1073. /* so is the high x */
  1074. if (hhave) {
  1075. /* they're the same, so just pick one */
  1076. if (hx == lx)
  1077. y = ly;
  1078. else /* interpolate */
  1079. y = ly + (((x - lx) * (hy - ly)) / (hx - lx));
  1080. } else /* only low is good, use it */
  1081. y = ly;
  1082. } else if (hhave) /* only high is good, use it */
  1083. y = hy;
  1084. else /* nothing is good,this should never happen unless np=0, ???? */
  1085. y = -(1 << 30);
  1086. return y;
  1087. }
  1088. static u8 ar9003_hw_eeprom_get_tgt_pwr(struct ath_hw *ah,
  1089. u16 rateIndex, u16 freq, bool is2GHz)
  1090. {
  1091. u16 numPiers, i;
  1092. s32 targetPowerArray[AR9300_NUM_5G_20_TARGET_POWERS];
  1093. s32 freqArray[AR9300_NUM_5G_20_TARGET_POWERS];
  1094. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1095. struct cal_tgt_pow_legacy *pEepromTargetPwr;
  1096. u8 *pFreqBin;
  1097. if (is2GHz) {
  1098. numPiers = AR9300_NUM_2G_20_TARGET_POWERS;
  1099. pEepromTargetPwr = eep->calTargetPower2G;
  1100. pFreqBin = eep->calTarget_freqbin_2G;
  1101. } else {
  1102. numPiers = AR9300_NUM_5G_20_TARGET_POWERS;
  1103. pEepromTargetPwr = eep->calTargetPower5G;
  1104. pFreqBin = eep->calTarget_freqbin_5G;
  1105. }
  1106. /*
  1107. * create array of channels and targetpower from
  1108. * targetpower piers stored on eeprom
  1109. */
  1110. for (i = 0; i < numPiers; i++) {
  1111. freqArray[i] = FBIN2FREQ(pFreqBin[i], is2GHz);
  1112. targetPowerArray[i] = pEepromTargetPwr[i].tPow2x[rateIndex];
  1113. }
  1114. /* interpolate to get target power for given frequency */
  1115. return (u8) ar9003_hw_power_interpolate((s32) freq,
  1116. freqArray,
  1117. targetPowerArray, numPiers);
  1118. }
  1119. static u8 ar9003_hw_eeprom_get_ht20_tgt_pwr(struct ath_hw *ah,
  1120. u16 rateIndex,
  1121. u16 freq, bool is2GHz)
  1122. {
  1123. u16 numPiers, i;
  1124. s32 targetPowerArray[AR9300_NUM_5G_20_TARGET_POWERS];
  1125. s32 freqArray[AR9300_NUM_5G_20_TARGET_POWERS];
  1126. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1127. struct cal_tgt_pow_ht *pEepromTargetPwr;
  1128. u8 *pFreqBin;
  1129. if (is2GHz) {
  1130. numPiers = AR9300_NUM_2G_20_TARGET_POWERS;
  1131. pEepromTargetPwr = eep->calTargetPower2GHT20;
  1132. pFreqBin = eep->calTarget_freqbin_2GHT20;
  1133. } else {
  1134. numPiers = AR9300_NUM_5G_20_TARGET_POWERS;
  1135. pEepromTargetPwr = eep->calTargetPower5GHT20;
  1136. pFreqBin = eep->calTarget_freqbin_5GHT20;
  1137. }
  1138. /*
  1139. * create array of channels and targetpower
  1140. * from targetpower piers stored on eeprom
  1141. */
  1142. for (i = 0; i < numPiers; i++) {
  1143. freqArray[i] = FBIN2FREQ(pFreqBin[i], is2GHz);
  1144. targetPowerArray[i] = pEepromTargetPwr[i].tPow2x[rateIndex];
  1145. }
  1146. /* interpolate to get target power for given frequency */
  1147. return (u8) ar9003_hw_power_interpolate((s32) freq,
  1148. freqArray,
  1149. targetPowerArray, numPiers);
  1150. }
  1151. static u8 ar9003_hw_eeprom_get_ht40_tgt_pwr(struct ath_hw *ah,
  1152. u16 rateIndex,
  1153. u16 freq, bool is2GHz)
  1154. {
  1155. u16 numPiers, i;
  1156. s32 targetPowerArray[AR9300_NUM_5G_40_TARGET_POWERS];
  1157. s32 freqArray[AR9300_NUM_5G_40_TARGET_POWERS];
  1158. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1159. struct cal_tgt_pow_ht *pEepromTargetPwr;
  1160. u8 *pFreqBin;
  1161. if (is2GHz) {
  1162. numPiers = AR9300_NUM_2G_40_TARGET_POWERS;
  1163. pEepromTargetPwr = eep->calTargetPower2GHT40;
  1164. pFreqBin = eep->calTarget_freqbin_2GHT40;
  1165. } else {
  1166. numPiers = AR9300_NUM_5G_40_TARGET_POWERS;
  1167. pEepromTargetPwr = eep->calTargetPower5GHT40;
  1168. pFreqBin = eep->calTarget_freqbin_5GHT40;
  1169. }
  1170. /*
  1171. * create array of channels and targetpower from
  1172. * targetpower piers stored on eeprom
  1173. */
  1174. for (i = 0; i < numPiers; i++) {
  1175. freqArray[i] = FBIN2FREQ(pFreqBin[i], is2GHz);
  1176. targetPowerArray[i] = pEepromTargetPwr[i].tPow2x[rateIndex];
  1177. }
  1178. /* interpolate to get target power for given frequency */
  1179. return (u8) ar9003_hw_power_interpolate((s32) freq,
  1180. freqArray,
  1181. targetPowerArray, numPiers);
  1182. }
  1183. static u8 ar9003_hw_eeprom_get_cck_tgt_pwr(struct ath_hw *ah,
  1184. u16 rateIndex, u16 freq)
  1185. {
  1186. u16 numPiers = AR9300_NUM_2G_CCK_TARGET_POWERS, i;
  1187. s32 targetPowerArray[AR9300_NUM_2G_CCK_TARGET_POWERS];
  1188. s32 freqArray[AR9300_NUM_2G_CCK_TARGET_POWERS];
  1189. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1190. struct cal_tgt_pow_legacy *pEepromTargetPwr = eep->calTargetPowerCck;
  1191. u8 *pFreqBin = eep->calTarget_freqbin_Cck;
  1192. /*
  1193. * create array of channels and targetpower from
  1194. * targetpower piers stored on eeprom
  1195. */
  1196. for (i = 0; i < numPiers; i++) {
  1197. freqArray[i] = FBIN2FREQ(pFreqBin[i], 1);
  1198. targetPowerArray[i] = pEepromTargetPwr[i].tPow2x[rateIndex];
  1199. }
  1200. /* interpolate to get target power for given frequency */
  1201. return (u8) ar9003_hw_power_interpolate((s32) freq,
  1202. freqArray,
  1203. targetPowerArray, numPiers);
  1204. }
  1205. /* Set tx power registers to array of values passed in */
  1206. static int ar9003_hw_tx_power_regwrite(struct ath_hw *ah, u8 * pPwrArray)
  1207. {
  1208. #define POW_SM(_r, _s) (((_r) & 0x3f) << (_s))
  1209. /* make sure forced gain is not set */
  1210. REG_WRITE(ah, 0xa458, 0);
  1211. /* Write the OFDM power per rate set */
  1212. /* 6 (LSB), 9, 12, 18 (MSB) */
  1213. REG_WRITE(ah, 0xa3c0,
  1214. POW_SM(pPwrArray[ALL_TARGET_LEGACY_6_24], 24) |
  1215. POW_SM(pPwrArray[ALL_TARGET_LEGACY_6_24], 16) |
  1216. POW_SM(pPwrArray[ALL_TARGET_LEGACY_6_24], 8) |
  1217. POW_SM(pPwrArray[ALL_TARGET_LEGACY_6_24], 0));
  1218. /* 24 (LSB), 36, 48, 54 (MSB) */
  1219. REG_WRITE(ah, 0xa3c4,
  1220. POW_SM(pPwrArray[ALL_TARGET_LEGACY_54], 24) |
  1221. POW_SM(pPwrArray[ALL_TARGET_LEGACY_48], 16) |
  1222. POW_SM(pPwrArray[ALL_TARGET_LEGACY_36], 8) |
  1223. POW_SM(pPwrArray[ALL_TARGET_LEGACY_6_24], 0));
  1224. /* Write the CCK power per rate set */
  1225. /* 1L (LSB), reserved, 2L, 2S (MSB) */
  1226. REG_WRITE(ah, 0xa3c8,
  1227. POW_SM(pPwrArray[ALL_TARGET_LEGACY_1L_5L], 24) |
  1228. POW_SM(pPwrArray[ALL_TARGET_LEGACY_1L_5L], 16) |
  1229. /* POW_SM(txPowerTimes2, 8) | this is reserved for AR9003 */
  1230. POW_SM(pPwrArray[ALL_TARGET_LEGACY_1L_5L], 0));
  1231. /* 5.5L (LSB), 5.5S, 11L, 11S (MSB) */
  1232. REG_WRITE(ah, 0xa3cc,
  1233. POW_SM(pPwrArray[ALL_TARGET_LEGACY_11S], 24) |
  1234. POW_SM(pPwrArray[ALL_TARGET_LEGACY_11L], 16) |
  1235. POW_SM(pPwrArray[ALL_TARGET_LEGACY_5S], 8) |
  1236. POW_SM(pPwrArray[ALL_TARGET_LEGACY_1L_5L], 0)
  1237. );
  1238. /* Write the HT20 power per rate set */
  1239. /* 0/8/16 (LSB), 1-3/9-11/17-19, 4, 5 (MSB) */
  1240. REG_WRITE(ah, 0xa3d0,
  1241. POW_SM(pPwrArray[ALL_TARGET_HT20_5], 24) |
  1242. POW_SM(pPwrArray[ALL_TARGET_HT20_4], 16) |
  1243. POW_SM(pPwrArray[ALL_TARGET_HT20_1_3_9_11_17_19], 8) |
  1244. POW_SM(pPwrArray[ALL_TARGET_HT20_0_8_16], 0)
  1245. );
  1246. /* 6 (LSB), 7, 12, 13 (MSB) */
  1247. REG_WRITE(ah, 0xa3d4,
  1248. POW_SM(pPwrArray[ALL_TARGET_HT20_13], 24) |
  1249. POW_SM(pPwrArray[ALL_TARGET_HT20_12], 16) |
  1250. POW_SM(pPwrArray[ALL_TARGET_HT20_7], 8) |
  1251. POW_SM(pPwrArray[ALL_TARGET_HT20_6], 0)
  1252. );
  1253. /* 14 (LSB), 15, 20, 21 */
  1254. REG_WRITE(ah, 0xa3e4,
  1255. POW_SM(pPwrArray[ALL_TARGET_HT20_21], 24) |
  1256. POW_SM(pPwrArray[ALL_TARGET_HT20_20], 16) |
  1257. POW_SM(pPwrArray[ALL_TARGET_HT20_15], 8) |
  1258. POW_SM(pPwrArray[ALL_TARGET_HT20_14], 0)
  1259. );
  1260. /* Mixed HT20 and HT40 rates */
  1261. /* HT20 22 (LSB), HT20 23, HT40 22, HT40 23 (MSB) */
  1262. REG_WRITE(ah, 0xa3e8,
  1263. POW_SM(pPwrArray[ALL_TARGET_HT40_23], 24) |
  1264. POW_SM(pPwrArray[ALL_TARGET_HT40_22], 16) |
  1265. POW_SM(pPwrArray[ALL_TARGET_HT20_23], 8) |
  1266. POW_SM(pPwrArray[ALL_TARGET_HT20_22], 0)
  1267. );
  1268. /*
  1269. * Write the HT40 power per rate set
  1270. * correct PAR difference between HT40 and HT20/LEGACY
  1271. * 0/8/16 (LSB), 1-3/9-11/17-19, 4, 5 (MSB)
  1272. */
  1273. REG_WRITE(ah, 0xa3d8,
  1274. POW_SM(pPwrArray[ALL_TARGET_HT40_5], 24) |
  1275. POW_SM(pPwrArray[ALL_TARGET_HT40_4], 16) |
  1276. POW_SM(pPwrArray[ALL_TARGET_HT40_1_3_9_11_17_19], 8) |
  1277. POW_SM(pPwrArray[ALL_TARGET_HT40_0_8_16], 0)
  1278. );
  1279. /* 6 (LSB), 7, 12, 13 (MSB) */
  1280. REG_WRITE(ah, 0xa3dc,
  1281. POW_SM(pPwrArray[ALL_TARGET_HT40_13], 24) |
  1282. POW_SM(pPwrArray[ALL_TARGET_HT40_12], 16) |
  1283. POW_SM(pPwrArray[ALL_TARGET_HT40_7], 8) |
  1284. POW_SM(pPwrArray[ALL_TARGET_HT40_6], 0)
  1285. );
  1286. /* 14 (LSB), 15, 20, 21 */
  1287. REG_WRITE(ah, 0xa3ec,
  1288. POW_SM(pPwrArray[ALL_TARGET_HT40_21], 24) |
  1289. POW_SM(pPwrArray[ALL_TARGET_HT40_20], 16) |
  1290. POW_SM(pPwrArray[ALL_TARGET_HT40_15], 8) |
  1291. POW_SM(pPwrArray[ALL_TARGET_HT40_14], 0)
  1292. );
  1293. return 0;
  1294. #undef POW_SM
  1295. }
  1296. static void ar9003_hw_set_target_power_eeprom(struct ath_hw *ah, u16 freq,
  1297. u8 *targetPowerValT2)
  1298. {
  1299. /* XXX: hard code for now, need to get from eeprom struct */
  1300. u8 ht40PowerIncForPdadc = 0;
  1301. bool is2GHz = false;
  1302. unsigned int i = 0;
  1303. struct ath_common *common = ath9k_hw_common(ah);
  1304. if (freq < 4000)
  1305. is2GHz = true;
  1306. targetPowerValT2[ALL_TARGET_LEGACY_6_24] =
  1307. ar9003_hw_eeprom_get_tgt_pwr(ah, LEGACY_TARGET_RATE_6_24, freq,
  1308. is2GHz);
  1309. targetPowerValT2[ALL_TARGET_LEGACY_36] =
  1310. ar9003_hw_eeprom_get_tgt_pwr(ah, LEGACY_TARGET_RATE_36, freq,
  1311. is2GHz);
  1312. targetPowerValT2[ALL_TARGET_LEGACY_48] =
  1313. ar9003_hw_eeprom_get_tgt_pwr(ah, LEGACY_TARGET_RATE_48, freq,
  1314. is2GHz);
  1315. targetPowerValT2[ALL_TARGET_LEGACY_54] =
  1316. ar9003_hw_eeprom_get_tgt_pwr(ah, LEGACY_TARGET_RATE_54, freq,
  1317. is2GHz);
  1318. targetPowerValT2[ALL_TARGET_LEGACY_1L_5L] =
  1319. ar9003_hw_eeprom_get_cck_tgt_pwr(ah, LEGACY_TARGET_RATE_1L_5L,
  1320. freq);
  1321. targetPowerValT2[ALL_TARGET_LEGACY_5S] =
  1322. ar9003_hw_eeprom_get_cck_tgt_pwr(ah, LEGACY_TARGET_RATE_5S, freq);
  1323. targetPowerValT2[ALL_TARGET_LEGACY_11L] =
  1324. ar9003_hw_eeprom_get_cck_tgt_pwr(ah, LEGACY_TARGET_RATE_11L, freq);
  1325. targetPowerValT2[ALL_TARGET_LEGACY_11S] =
  1326. ar9003_hw_eeprom_get_cck_tgt_pwr(ah, LEGACY_TARGET_RATE_11S, freq);
  1327. targetPowerValT2[ALL_TARGET_HT20_0_8_16] =
  1328. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_0_8_16, freq,
  1329. is2GHz);
  1330. targetPowerValT2[ALL_TARGET_HT20_1_3_9_11_17_19] =
  1331. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_1_3_9_11_17_19,
  1332. freq, is2GHz);
  1333. targetPowerValT2[ALL_TARGET_HT20_4] =
  1334. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_4, freq,
  1335. is2GHz);
  1336. targetPowerValT2[ALL_TARGET_HT20_5] =
  1337. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_5, freq,
  1338. is2GHz);
  1339. targetPowerValT2[ALL_TARGET_HT20_6] =
  1340. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_6, freq,
  1341. is2GHz);
  1342. targetPowerValT2[ALL_TARGET_HT20_7] =
  1343. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_7, freq,
  1344. is2GHz);
  1345. targetPowerValT2[ALL_TARGET_HT20_12] =
  1346. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_12, freq,
  1347. is2GHz);
  1348. targetPowerValT2[ALL_TARGET_HT20_13] =
  1349. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_13, freq,
  1350. is2GHz);
  1351. targetPowerValT2[ALL_TARGET_HT20_14] =
  1352. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_14, freq,
  1353. is2GHz);
  1354. targetPowerValT2[ALL_TARGET_HT20_15] =
  1355. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_15, freq,
  1356. is2GHz);
  1357. targetPowerValT2[ALL_TARGET_HT20_20] =
  1358. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_20, freq,
  1359. is2GHz);
  1360. targetPowerValT2[ALL_TARGET_HT20_21] =
  1361. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_21, freq,
  1362. is2GHz);
  1363. targetPowerValT2[ALL_TARGET_HT20_22] =
  1364. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_22, freq,
  1365. is2GHz);
  1366. targetPowerValT2[ALL_TARGET_HT20_23] =
  1367. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_23, freq,
  1368. is2GHz);
  1369. targetPowerValT2[ALL_TARGET_HT40_0_8_16] =
  1370. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_0_8_16, freq,
  1371. is2GHz) + ht40PowerIncForPdadc;
  1372. targetPowerValT2[ALL_TARGET_HT40_1_3_9_11_17_19] =
  1373. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_1_3_9_11_17_19,
  1374. freq,
  1375. is2GHz) + ht40PowerIncForPdadc;
  1376. targetPowerValT2[ALL_TARGET_HT40_4] =
  1377. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_4, freq,
  1378. is2GHz) + ht40PowerIncForPdadc;
  1379. targetPowerValT2[ALL_TARGET_HT40_5] =
  1380. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_5, freq,
  1381. is2GHz) + ht40PowerIncForPdadc;
  1382. targetPowerValT2[ALL_TARGET_HT40_6] =
  1383. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_6, freq,
  1384. is2GHz) + ht40PowerIncForPdadc;
  1385. targetPowerValT2[ALL_TARGET_HT40_7] =
  1386. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_7, freq,
  1387. is2GHz) + ht40PowerIncForPdadc;
  1388. targetPowerValT2[ALL_TARGET_HT40_12] =
  1389. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_12, freq,
  1390. is2GHz) + ht40PowerIncForPdadc;
  1391. targetPowerValT2[ALL_TARGET_HT40_13] =
  1392. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_13, freq,
  1393. is2GHz) + ht40PowerIncForPdadc;
  1394. targetPowerValT2[ALL_TARGET_HT40_14] =
  1395. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_14, freq,
  1396. is2GHz) + ht40PowerIncForPdadc;
  1397. targetPowerValT2[ALL_TARGET_HT40_15] =
  1398. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_15, freq,
  1399. is2GHz) + ht40PowerIncForPdadc;
  1400. targetPowerValT2[ALL_TARGET_HT40_20] =
  1401. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_20, freq,
  1402. is2GHz) + ht40PowerIncForPdadc;
  1403. targetPowerValT2[ALL_TARGET_HT40_21] =
  1404. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_21, freq,
  1405. is2GHz) + ht40PowerIncForPdadc;
  1406. targetPowerValT2[ALL_TARGET_HT40_22] =
  1407. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_22, freq,
  1408. is2GHz) + ht40PowerIncForPdadc;
  1409. targetPowerValT2[ALL_TARGET_HT40_23] =
  1410. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_23, freq,
  1411. is2GHz) + ht40PowerIncForPdadc;
  1412. while (i < ar9300RateSize) {
  1413. ath_print(common, ATH_DBG_EEPROM,
  1414. "TPC[%02d] 0x%08x ", i, targetPowerValT2[i]);
  1415. i++;
  1416. ath_print(common, ATH_DBG_EEPROM,
  1417. "TPC[%02d] 0x%08x ", i, targetPowerValT2[i]);
  1418. i++;
  1419. ath_print(common, ATH_DBG_EEPROM,
  1420. "TPC[%02d] 0x%08x ", i, targetPowerValT2[i]);
  1421. i++;
  1422. ath_print(common, ATH_DBG_EEPROM,
  1423. "TPC[%02d] 0x%08x\n", i, targetPowerValT2[i]);
  1424. i++;
  1425. }
  1426. }
  1427. static int ar9003_hw_cal_pier_get(struct ath_hw *ah,
  1428. int mode,
  1429. int ipier,
  1430. int ichain,
  1431. int *pfrequency,
  1432. int *pcorrection,
  1433. int *ptemperature, int *pvoltage)
  1434. {
  1435. u8 *pCalPier;
  1436. struct ar9300_cal_data_per_freq_op_loop *pCalPierStruct;
  1437. int is2GHz;
  1438. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1439. struct ath_common *common = ath9k_hw_common(ah);
  1440. if (ichain >= AR9300_MAX_CHAINS) {
  1441. ath_print(common, ATH_DBG_EEPROM,
  1442. "Invalid chain index, must be less than %d\n",
  1443. AR9300_MAX_CHAINS);
  1444. return -1;
  1445. }
  1446. if (mode) { /* 5GHz */
  1447. if (ipier >= AR9300_NUM_5G_CAL_PIERS) {
  1448. ath_print(common, ATH_DBG_EEPROM,
  1449. "Invalid 5GHz cal pier index, must "
  1450. "be less than %d\n",
  1451. AR9300_NUM_5G_CAL_PIERS);
  1452. return -1;
  1453. }
  1454. pCalPier = &(eep->calFreqPier5G[ipier]);
  1455. pCalPierStruct = &(eep->calPierData5G[ichain][ipier]);
  1456. is2GHz = 0;
  1457. } else {
  1458. if (ipier >= AR9300_NUM_2G_CAL_PIERS) {
  1459. ath_print(common, ATH_DBG_EEPROM,
  1460. "Invalid 2GHz cal pier index, must "
  1461. "be less than %d\n", AR9300_NUM_2G_CAL_PIERS);
  1462. return -1;
  1463. }
  1464. pCalPier = &(eep->calFreqPier2G[ipier]);
  1465. pCalPierStruct = &(eep->calPierData2G[ichain][ipier]);
  1466. is2GHz = 1;
  1467. }
  1468. *pfrequency = FBIN2FREQ(*pCalPier, is2GHz);
  1469. *pcorrection = pCalPierStruct->refPower;
  1470. *ptemperature = pCalPierStruct->tempMeas;
  1471. *pvoltage = pCalPierStruct->voltMeas;
  1472. return 0;
  1473. }
  1474. static int ar9003_hw_power_control_override(struct ath_hw *ah,
  1475. int frequency,
  1476. int *correction,
  1477. int *voltage, int *temperature)
  1478. {
  1479. int tempSlope = 0;
  1480. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1481. REG_RMW(ah, AR_PHY_TPC_11_B0,
  1482. (correction[0] << AR_PHY_TPC_OLPC_GAIN_DELTA_S),
  1483. AR_PHY_TPC_OLPC_GAIN_DELTA);
  1484. REG_RMW(ah, AR_PHY_TPC_11_B1,
  1485. (correction[1] << AR_PHY_TPC_OLPC_GAIN_DELTA_S),
  1486. AR_PHY_TPC_OLPC_GAIN_DELTA);
  1487. REG_RMW(ah, AR_PHY_TPC_11_B2,
  1488. (correction[2] << AR_PHY_TPC_OLPC_GAIN_DELTA_S),
  1489. AR_PHY_TPC_OLPC_GAIN_DELTA);
  1490. /* enable open loop power control on chip */
  1491. REG_RMW(ah, AR_PHY_TPC_6_B0,
  1492. (3 << AR_PHY_TPC_6_ERROR_EST_MODE_S),
  1493. AR_PHY_TPC_6_ERROR_EST_MODE);
  1494. REG_RMW(ah, AR_PHY_TPC_6_B1,
  1495. (3 << AR_PHY_TPC_6_ERROR_EST_MODE_S),
  1496. AR_PHY_TPC_6_ERROR_EST_MODE);
  1497. REG_RMW(ah, AR_PHY_TPC_6_B2,
  1498. (3 << AR_PHY_TPC_6_ERROR_EST_MODE_S),
  1499. AR_PHY_TPC_6_ERROR_EST_MODE);
  1500. /*
  1501. * enable temperature compensation
  1502. * Need to use register names
  1503. */
  1504. if (frequency < 4000)
  1505. tempSlope = eep->modalHeader2G.tempSlope;
  1506. else
  1507. tempSlope = eep->modalHeader5G.tempSlope;
  1508. REG_RMW_FIELD(ah, AR_PHY_TPC_19, AR_PHY_TPC_19_ALPHA_THERM, tempSlope);
  1509. REG_RMW_FIELD(ah, AR_PHY_TPC_18, AR_PHY_TPC_18_THERM_CAL_VALUE,
  1510. temperature[0]);
  1511. return 0;
  1512. }
  1513. /* Apply the recorded correction values. */
  1514. static int ar9003_hw_calibration_apply(struct ath_hw *ah, int frequency)
  1515. {
  1516. int ichain, ipier, npier;
  1517. int mode;
  1518. int lfrequency[AR9300_MAX_CHAINS],
  1519. lcorrection[AR9300_MAX_CHAINS],
  1520. ltemperature[AR9300_MAX_CHAINS], lvoltage[AR9300_MAX_CHAINS];
  1521. int hfrequency[AR9300_MAX_CHAINS],
  1522. hcorrection[AR9300_MAX_CHAINS],
  1523. htemperature[AR9300_MAX_CHAINS], hvoltage[AR9300_MAX_CHAINS];
  1524. int fdiff;
  1525. int correction[AR9300_MAX_CHAINS],
  1526. voltage[AR9300_MAX_CHAINS], temperature[AR9300_MAX_CHAINS];
  1527. int pfrequency, pcorrection, ptemperature, pvoltage;
  1528. struct ath_common *common = ath9k_hw_common(ah);
  1529. mode = (frequency >= 4000);
  1530. if (mode)
  1531. npier = AR9300_NUM_5G_CAL_PIERS;
  1532. else
  1533. npier = AR9300_NUM_2G_CAL_PIERS;
  1534. for (ichain = 0; ichain < AR9300_MAX_CHAINS; ichain++) {
  1535. lfrequency[ichain] = 0;
  1536. hfrequency[ichain] = 100000;
  1537. }
  1538. /* identify best lower and higher frequency calibration measurement */
  1539. for (ichain = 0; ichain < AR9300_MAX_CHAINS; ichain++) {
  1540. for (ipier = 0; ipier < npier; ipier++) {
  1541. if (!ar9003_hw_cal_pier_get(ah, mode, ipier, ichain,
  1542. &pfrequency, &pcorrection,
  1543. &ptemperature, &pvoltage)) {
  1544. fdiff = frequency - pfrequency;
  1545. /*
  1546. * this measurement is higher than
  1547. * our desired frequency
  1548. */
  1549. if (fdiff <= 0) {
  1550. if (hfrequency[ichain] <= 0 ||
  1551. hfrequency[ichain] >= 100000 ||
  1552. fdiff >
  1553. (frequency - hfrequency[ichain])) {
  1554. /*
  1555. * new best higher
  1556. * frequency measurement
  1557. */
  1558. hfrequency[ichain] = pfrequency;
  1559. hcorrection[ichain] =
  1560. pcorrection;
  1561. htemperature[ichain] =
  1562. ptemperature;
  1563. hvoltage[ichain] = pvoltage;
  1564. }
  1565. }
  1566. if (fdiff >= 0) {
  1567. if (lfrequency[ichain] <= 0
  1568. || fdiff <
  1569. (frequency - lfrequency[ichain])) {
  1570. /*
  1571. * new best lower
  1572. * frequency measurement
  1573. */
  1574. lfrequency[ichain] = pfrequency;
  1575. lcorrection[ichain] =
  1576. pcorrection;
  1577. ltemperature[ichain] =
  1578. ptemperature;
  1579. lvoltage[ichain] = pvoltage;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. }
  1585. /* interpolate */
  1586. for (ichain = 0; ichain < AR9300_MAX_CHAINS; ichain++) {
  1587. ath_print(common, ATH_DBG_EEPROM,
  1588. "ch=%d f=%d low=%d %d h=%d %d\n",
  1589. ichain, frequency, lfrequency[ichain],
  1590. lcorrection[ichain], hfrequency[ichain],
  1591. hcorrection[ichain]);
  1592. /* they're the same, so just pick one */
  1593. if (hfrequency[ichain] == lfrequency[ichain]) {
  1594. correction[ichain] = lcorrection[ichain];
  1595. voltage[ichain] = lvoltage[ichain];
  1596. temperature[ichain] = ltemperature[ichain];
  1597. }
  1598. /* the low frequency is good */
  1599. else if (frequency - lfrequency[ichain] < 1000) {
  1600. /* so is the high frequency, interpolate */
  1601. if (hfrequency[ichain] - frequency < 1000) {
  1602. correction[ichain] = lcorrection[ichain] +
  1603. (((frequency - lfrequency[ichain]) *
  1604. (hcorrection[ichain] -
  1605. lcorrection[ichain])) /
  1606. (hfrequency[ichain] - lfrequency[ichain]));
  1607. temperature[ichain] = ltemperature[ichain] +
  1608. (((frequency - lfrequency[ichain]) *
  1609. (htemperature[ichain] -
  1610. ltemperature[ichain])) /
  1611. (hfrequency[ichain] - lfrequency[ichain]));
  1612. voltage[ichain] =
  1613. lvoltage[ichain] +
  1614. (((frequency -
  1615. lfrequency[ichain]) * (hvoltage[ichain] -
  1616. lvoltage[ichain]))
  1617. / (hfrequency[ichain] -
  1618. lfrequency[ichain]));
  1619. }
  1620. /* only low is good, use it */
  1621. else {
  1622. correction[ichain] = lcorrection[ichain];
  1623. temperature[ichain] = ltemperature[ichain];
  1624. voltage[ichain] = lvoltage[ichain];
  1625. }
  1626. }
  1627. /* only high is good, use it */
  1628. else if (hfrequency[ichain] - frequency < 1000) {
  1629. correction[ichain] = hcorrection[ichain];
  1630. temperature[ichain] = htemperature[ichain];
  1631. voltage[ichain] = hvoltage[ichain];
  1632. } else { /* nothing is good, presume 0???? */
  1633. correction[ichain] = 0;
  1634. temperature[ichain] = 0;
  1635. voltage[ichain] = 0;
  1636. }
  1637. }
  1638. ar9003_hw_power_control_override(ah, frequency, correction, voltage,
  1639. temperature);
  1640. ath_print(common, ATH_DBG_EEPROM,
  1641. "for frequency=%d, calibration correction = %d %d %d\n",
  1642. frequency, correction[0], correction[1], correction[2]);
  1643. return 0;
  1644. }
  1645. static u16 ar9003_hw_get_direct_edge_power(struct ar9300_eeprom *eep,
  1646. int idx,
  1647. int edge,
  1648. bool is2GHz)
  1649. {
  1650. struct cal_ctl_data_2g *ctl_2g = eep->ctlPowerData_2G;
  1651. struct cal_ctl_data_5g *ctl_5g = eep->ctlPowerData_5G;
  1652. if (is2GHz)
  1653. return CTL_EDGE_TPOWER(ctl_2g[idx].ctlEdges[edge]);
  1654. else
  1655. return CTL_EDGE_TPOWER(ctl_5g[idx].ctlEdges[edge]);
  1656. }
  1657. static u16 ar9003_hw_get_indirect_edge_power(struct ar9300_eeprom *eep,
  1658. int idx,
  1659. unsigned int edge,
  1660. u16 freq,
  1661. bool is2GHz)
  1662. {
  1663. struct cal_ctl_data_2g *ctl_2g = eep->ctlPowerData_2G;
  1664. struct cal_ctl_data_5g *ctl_5g = eep->ctlPowerData_5G;
  1665. u8 *ctl_freqbin = is2GHz ?
  1666. &eep->ctl_freqbin_2G[idx][0] :
  1667. &eep->ctl_freqbin_5G[idx][0];
  1668. if (is2GHz) {
  1669. if (ath9k_hw_fbin2freq(ctl_freqbin[edge - 1], 1) < freq &&
  1670. CTL_EDGE_FLAGS(ctl_2g[idx].ctlEdges[edge - 1]))
  1671. return CTL_EDGE_TPOWER(ctl_2g[idx].ctlEdges[edge - 1]);
  1672. } else {
  1673. if (ath9k_hw_fbin2freq(ctl_freqbin[edge - 1], 0) < freq &&
  1674. CTL_EDGE_FLAGS(ctl_5g[idx].ctlEdges[edge - 1]))
  1675. return CTL_EDGE_TPOWER(ctl_5g[idx].ctlEdges[edge - 1]);
  1676. }
  1677. return AR9300_MAX_RATE_POWER;
  1678. }
  1679. /*
  1680. * Find the maximum conformance test limit for the given channel and CTL info
  1681. */
  1682. static u16 ar9003_hw_get_max_edge_power(struct ar9300_eeprom *eep,
  1683. u16 freq, int idx, bool is2GHz)
  1684. {
  1685. u16 twiceMaxEdgePower = AR9300_MAX_RATE_POWER;
  1686. u8 *ctl_freqbin = is2GHz ?
  1687. &eep->ctl_freqbin_2G[idx][0] :
  1688. &eep->ctl_freqbin_5G[idx][0];
  1689. u16 num_edges = is2GHz ?
  1690. AR9300_NUM_BAND_EDGES_2G : AR9300_NUM_BAND_EDGES_5G;
  1691. unsigned int edge;
  1692. /* Get the edge power */
  1693. for (edge = 0;
  1694. (edge < num_edges) && (ctl_freqbin[edge] != AR9300_BCHAN_UNUSED);
  1695. edge++) {
  1696. /*
  1697. * If there's an exact channel match or an inband flag set
  1698. * on the lower channel use the given rdEdgePower
  1699. */
  1700. if (freq == ath9k_hw_fbin2freq(ctl_freqbin[edge], is2GHz)) {
  1701. twiceMaxEdgePower =
  1702. ar9003_hw_get_direct_edge_power(eep, idx,
  1703. edge, is2GHz);
  1704. break;
  1705. } else if ((edge > 0) &&
  1706. (freq < ath9k_hw_fbin2freq(ctl_freqbin[edge],
  1707. is2GHz))) {
  1708. twiceMaxEdgePower =
  1709. ar9003_hw_get_indirect_edge_power(eep, idx,
  1710. edge, freq,
  1711. is2GHz);
  1712. /*
  1713. * Leave loop - no more affecting edges possible in
  1714. * this monotonic increasing list
  1715. */
  1716. break;
  1717. }
  1718. }
  1719. return twiceMaxEdgePower;
  1720. }
  1721. static void ar9003_hw_set_power_per_rate_table(struct ath_hw *ah,
  1722. struct ath9k_channel *chan,
  1723. u8 *pPwrArray, u16 cfgCtl,
  1724. u8 twiceAntennaReduction,
  1725. u8 twiceMaxRegulatoryPower,
  1726. u16 powerLimit)
  1727. {
  1728. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1729. struct ath_common *common = ath9k_hw_common(ah);
  1730. struct ar9300_eeprom *pEepData = &ah->eeprom.ar9300_eep;
  1731. u16 twiceMaxEdgePower = AR9300_MAX_RATE_POWER;
  1732. static const u16 tpScaleReductionTable[5] = {
  1733. 0, 3, 6, 9, AR9300_MAX_RATE_POWER
  1734. };
  1735. int i;
  1736. int16_t twiceLargestAntenna;
  1737. u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
  1738. u16 ctlModesFor11a[] = {
  1739. CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40
  1740. };
  1741. u16 ctlModesFor11g[] = {
  1742. CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT,
  1743. CTL_11G_EXT, CTL_2GHT40
  1744. };
  1745. u16 numCtlModes, *pCtlMode, ctlMode, freq;
  1746. struct chan_centers centers;
  1747. u8 *ctlIndex;
  1748. u8 ctlNum;
  1749. u16 twiceMinEdgePower;
  1750. bool is2ghz = IS_CHAN_2GHZ(chan);
  1751. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1752. /* Compute TxPower reduction due to Antenna Gain */
  1753. if (is2ghz)
  1754. twiceLargestAntenna = pEepData->modalHeader2G.antennaGain;
  1755. else
  1756. twiceLargestAntenna = pEepData->modalHeader5G.antennaGain;
  1757. twiceLargestAntenna = (int16_t)min((twiceAntennaReduction) -
  1758. twiceLargestAntenna, 0);
  1759. /*
  1760. * scaledPower is the minimum of the user input power level
  1761. * and the regulatory allowed power level
  1762. */
  1763. maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
  1764. if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX) {
  1765. maxRegAllowedPower -=
  1766. (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
  1767. }
  1768. scaledPower = min(powerLimit, maxRegAllowedPower);
  1769. /*
  1770. * Reduce scaled Power by number of chains active to get
  1771. * to per chain tx power level
  1772. */
  1773. switch (ar5416_get_ntxchains(ah->txchainmask)) {
  1774. case 1:
  1775. break;
  1776. case 2:
  1777. scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
  1778. break;
  1779. case 3:
  1780. scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
  1781. break;
  1782. }
  1783. scaledPower = max((u16)0, scaledPower);
  1784. /*
  1785. * Get target powers from EEPROM - our baseline for TX Power
  1786. */
  1787. if (is2ghz) {
  1788. /* Setup for CTL modes */
  1789. /* CTL_11B, CTL_11G, CTL_2GHT20 */
  1790. numCtlModes =
  1791. ARRAY_SIZE(ctlModesFor11g) -
  1792. SUB_NUM_CTL_MODES_AT_2G_40;
  1793. pCtlMode = ctlModesFor11g;
  1794. if (IS_CHAN_HT40(chan))
  1795. /* All 2G CTL's */
  1796. numCtlModes = ARRAY_SIZE(ctlModesFor11g);
  1797. } else {
  1798. /* Setup for CTL modes */
  1799. /* CTL_11A, CTL_5GHT20 */
  1800. numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
  1801. SUB_NUM_CTL_MODES_AT_5G_40;
  1802. pCtlMode = ctlModesFor11a;
  1803. if (IS_CHAN_HT40(chan))
  1804. /* All 5G CTL's */
  1805. numCtlModes = ARRAY_SIZE(ctlModesFor11a);
  1806. }
  1807. /*
  1808. * For MIMO, need to apply regulatory caps individually across
  1809. * dynamically running modes: CCK, OFDM, HT20, HT40
  1810. *
  1811. * The outer loop walks through each possible applicable runtime mode.
  1812. * The inner loop walks through each ctlIndex entry in EEPROM.
  1813. * The ctl value is encoded as [7:4] == test group, [3:0] == test mode.
  1814. */
  1815. for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
  1816. bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
  1817. (pCtlMode[ctlMode] == CTL_2GHT40);
  1818. if (isHt40CtlMode)
  1819. freq = centers.synth_center;
  1820. else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
  1821. freq = centers.ext_center;
  1822. else
  1823. freq = centers.ctl_center;
  1824. ath_print(common, ATH_DBG_REGULATORY,
  1825. "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
  1826. "EXT_ADDITIVE %d\n",
  1827. ctlMode, numCtlModes, isHt40CtlMode,
  1828. (pCtlMode[ctlMode] & EXT_ADDITIVE));
  1829. /* walk through each CTL index stored in EEPROM */
  1830. if (is2ghz) {
  1831. ctlIndex = pEepData->ctlIndex_2G;
  1832. ctlNum = AR9300_NUM_CTLS_2G;
  1833. } else {
  1834. ctlIndex = pEepData->ctlIndex_5G;
  1835. ctlNum = AR9300_NUM_CTLS_5G;
  1836. }
  1837. for (i = 0; (i < ctlNum) && ctlIndex[i]; i++) {
  1838. ath_print(common, ATH_DBG_REGULATORY,
  1839. "LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
  1840. "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
  1841. "chan %dn",
  1842. i, cfgCtl, pCtlMode[ctlMode], ctlIndex[i],
  1843. chan->channel);
  1844. /*
  1845. * compare test group from regulatory
  1846. * channel list with test mode from pCtlMode
  1847. * list
  1848. */
  1849. if ((((cfgCtl & ~CTL_MODE_M) |
  1850. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  1851. ctlIndex[i]) ||
  1852. (((cfgCtl & ~CTL_MODE_M) |
  1853. (pCtlMode[ctlMode] & CTL_MODE_M)) ==
  1854. ((ctlIndex[i] & CTL_MODE_M) |
  1855. SD_NO_CTL))) {
  1856. twiceMinEdgePower =
  1857. ar9003_hw_get_max_edge_power(pEepData,
  1858. freq, i,
  1859. is2ghz);
  1860. if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL)
  1861. /*
  1862. * Find the minimum of all CTL
  1863. * edge powers that apply to
  1864. * this channel
  1865. */
  1866. twiceMaxEdgePower =
  1867. min(twiceMaxEdgePower,
  1868. twiceMinEdgePower);
  1869. else {
  1870. /* specific */
  1871. twiceMaxEdgePower =
  1872. twiceMinEdgePower;
  1873. break;
  1874. }
  1875. }
  1876. }
  1877. minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
  1878. ath_print(common, ATH_DBG_REGULATORY,
  1879. "SEL-Min ctlMode %d pCtlMode %d 2xMaxEdge %d "
  1880. "sP %d minCtlPwr %d\n",
  1881. ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
  1882. scaledPower, minCtlPower);
  1883. /* Apply ctl mode to correct target power set */
  1884. switch (pCtlMode[ctlMode]) {
  1885. case CTL_11B:
  1886. for (i = ALL_TARGET_LEGACY_1L_5L;
  1887. i <= ALL_TARGET_LEGACY_11S; i++)
  1888. pPwrArray[i] =
  1889. (u8)min((u16)pPwrArray[i],
  1890. minCtlPower);
  1891. break;
  1892. case CTL_11A:
  1893. case CTL_11G:
  1894. for (i = ALL_TARGET_LEGACY_6_24;
  1895. i <= ALL_TARGET_LEGACY_54; i++)
  1896. pPwrArray[i] =
  1897. (u8)min((u16)pPwrArray[i],
  1898. minCtlPower);
  1899. break;
  1900. case CTL_5GHT20:
  1901. case CTL_2GHT20:
  1902. for (i = ALL_TARGET_HT20_0_8_16;
  1903. i <= ALL_TARGET_HT20_21; i++)
  1904. pPwrArray[i] =
  1905. (u8)min((u16)pPwrArray[i],
  1906. minCtlPower);
  1907. pPwrArray[ALL_TARGET_HT20_22] =
  1908. (u8)min((u16)pPwrArray[ALL_TARGET_HT20_22],
  1909. minCtlPower);
  1910. pPwrArray[ALL_TARGET_HT20_23] =
  1911. (u8)min((u16)pPwrArray[ALL_TARGET_HT20_23],
  1912. minCtlPower);
  1913. break;
  1914. case CTL_5GHT40:
  1915. case CTL_2GHT40:
  1916. for (i = ALL_TARGET_HT40_0_8_16;
  1917. i <= ALL_TARGET_HT40_23; i++)
  1918. pPwrArray[i] =
  1919. (u8)min((u16)pPwrArray[i],
  1920. minCtlPower);
  1921. break;
  1922. default:
  1923. break;
  1924. }
  1925. } /* end ctl mode checking */
  1926. }
  1927. static void ath9k_hw_ar9300_set_txpower(struct ath_hw *ah,
  1928. struct ath9k_channel *chan, u16 cfgCtl,
  1929. u8 twiceAntennaReduction,
  1930. u8 twiceMaxRegulatoryPower,
  1931. u8 powerLimit)
  1932. {
  1933. struct ath_common *common = ath9k_hw_common(ah);
  1934. u8 targetPowerValT2[ar9300RateSize];
  1935. unsigned int i = 0;
  1936. ar9003_hw_set_target_power_eeprom(ah, chan->channel, targetPowerValT2);
  1937. ar9003_hw_set_power_per_rate_table(ah, chan,
  1938. targetPowerValT2, cfgCtl,
  1939. twiceAntennaReduction,
  1940. twiceMaxRegulatoryPower,
  1941. powerLimit);
  1942. while (i < ar9300RateSize) {
  1943. ath_print(common, ATH_DBG_EEPROM,
  1944. "TPC[%02d] 0x%08x ", i, targetPowerValT2[i]);
  1945. i++;
  1946. ath_print(common, ATH_DBG_EEPROM,
  1947. "TPC[%02d] 0x%08x ", i, targetPowerValT2[i]);
  1948. i++;
  1949. ath_print(common, ATH_DBG_EEPROM,
  1950. "TPC[%02d] 0x%08x ", i, targetPowerValT2[i]);
  1951. i++;
  1952. ath_print(common, ATH_DBG_EEPROM,
  1953. "TPC[%02d] 0x%08x\n\n", i, targetPowerValT2[i]);
  1954. i++;
  1955. }
  1956. /* Write target power array to registers */
  1957. ar9003_hw_tx_power_regwrite(ah, targetPowerValT2);
  1958. /*
  1959. * This is the TX power we send back to driver core,
  1960. * and it can use to pass to userspace to display our
  1961. * currently configured TX power setting.
  1962. *
  1963. * Since power is rate dependent, use one of the indices
  1964. * from the AR9300_Rates enum to select an entry from
  1965. * targetPowerValT2[] to report. Currently returns the
  1966. * power for HT40 MCS 0, HT20 MCS 0, or OFDM 6 Mbps
  1967. * as CCK power is less interesting (?).
  1968. */
  1969. i = ALL_TARGET_LEGACY_6_24; /* legacy */
  1970. if (IS_CHAN_HT40(chan))
  1971. i = ALL_TARGET_HT40_0_8_16; /* ht40 */
  1972. else if (IS_CHAN_HT20(chan))
  1973. i = ALL_TARGET_HT20_0_8_16; /* ht20 */
  1974. ah->txpower_limit = targetPowerValT2[i];
  1975. ar9003_hw_calibration_apply(ah, chan->channel);
  1976. }
  1977. static u16 ath9k_hw_ar9300_get_spur_channel(struct ath_hw *ah,
  1978. u16 i, bool is2GHz)
  1979. {
  1980. return AR_NO_SPUR;
  1981. }
  1982. s32 ar9003_hw_get_tx_gain_idx(struct ath_hw *ah)
  1983. {
  1984. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1985. return (eep->baseEepHeader.txrxgain >> 4) & 0xf; /* bits 7:4 */
  1986. }
  1987. s32 ar9003_hw_get_rx_gain_idx(struct ath_hw *ah)
  1988. {
  1989. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1990. return (eep->baseEepHeader.txrxgain) & 0xf; /* bits 3:0 */
  1991. }
  1992. const struct eeprom_ops eep_ar9300_ops = {
  1993. .check_eeprom = ath9k_hw_ar9300_check_eeprom,
  1994. .get_eeprom = ath9k_hw_ar9300_get_eeprom,
  1995. .fill_eeprom = ath9k_hw_ar9300_fill_eeprom,
  1996. .get_eeprom_ver = ath9k_hw_ar9300_get_eeprom_ver,
  1997. .get_eeprom_rev = ath9k_hw_ar9300_get_eeprom_rev,
  1998. .get_num_ant_config = ath9k_hw_ar9300_get_num_ant_config,
  1999. .get_eeprom_antenna_cfg = ath9k_hw_ar9300_get_eeprom_antenna_cfg,
  2000. .set_board_values = ath9k_hw_ar9300_set_board_values,
  2001. .set_addac = ath9k_hw_ar9300_set_addac,
  2002. .set_txpower = ath9k_hw_ar9300_set_txpower,
  2003. .get_spur_channel = ath9k_hw_ar9300_get_spur_channel
  2004. };