ar9003_eeprom.c 63 KB

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