ar9003_eeprom.c 63 KB

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