ar9003_eeprom.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860
  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. static const struct ar9300_eeprom ar9300_default = {
  34. .eepromVersion = 2,
  35. .templateVersion = 2,
  36. .macAddr = {1, 2, 3, 4, 5, 6},
  37. .custData = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  38. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  39. .baseEepHeader = {
  40. .regDmn = {0, 0x1f},
  41. .txrxMask = 0x77, /* 4 bits tx and 4 bits rx */
  42. .opCapFlags = {
  43. .opFlags = AR9300_OPFLAGS_11G | AR9300_OPFLAGS_11A,
  44. .eepMisc = 0,
  45. },
  46. .rfSilent = 0,
  47. .blueToothOptions = 0,
  48. .deviceCap = 0,
  49. .deviceType = 5, /* takes lower byte in eeprom location */
  50. .pwrTableOffset = AR9300_PWR_TABLE_OFFSET,
  51. .params_for_tuning_caps = {0, 0},
  52. .featureEnable = 0x0c,
  53. /*
  54. * bit0 - enable tx temp comp - disabled
  55. * bit1 - enable tx volt comp - disabled
  56. * bit2 - enable fastClock - enabled
  57. * bit3 - enable doubling - enabled
  58. * bit4 - enable internal regulator - disabled
  59. */
  60. .miscConfiguration = 0, /* bit0 - turn down drivestrength */
  61. .eepromWriteEnableGpio = 3,
  62. .wlanDisableGpio = 0,
  63. .wlanLedGpio = 8,
  64. .rxBandSelectGpio = 0xff,
  65. .txrxgain = 0,
  66. .swreg = 0,
  67. },
  68. .modalHeader2G = {
  69. /* ar9300_modal_eep_header 2g */
  70. /* 4 idle,t1,t2,b(4 bits per setting) */
  71. .antCtrlCommon = 0x110,
  72. /* 4 ra1l1, ra2l1, ra1l2, ra2l2, ra12 */
  73. .antCtrlCommon2 = 0x22222,
  74. /*
  75. * antCtrlChain[AR9300_MAX_CHAINS]; 6 idle, t, r,
  76. * rx1, rx12, b (2 bits each)
  77. */
  78. .antCtrlChain = {0x150, 0x150, 0x150},
  79. /*
  80. * xatten1DB[AR9300_MAX_CHAINS]; 3 xatten1_db
  81. * for ar9280 (0xa20c/b20c 5:0)
  82. */
  83. .xatten1DB = {0, 0, 0},
  84. /*
  85. * xatten1Margin[AR9300_MAX_CHAINS]; 3 xatten1_margin
  86. * for ar9280 (0xa20c/b20c 16:12
  87. */
  88. .xatten1Margin = {0, 0, 0},
  89. .tempSlope = 36,
  90. .voltSlope = 0,
  91. /*
  92. * spurChans[OSPREY_EEPROM_MODAL_SPURS]; spur
  93. * channels in usual fbin coding format
  94. */
  95. .spurChans = {0, 0, 0, 0, 0},
  96. /*
  97. * noiseFloorThreshCh[AR9300_MAX_CHAINS]; 3 Check
  98. * if the register is per chain
  99. */
  100. .noiseFloorThreshCh = {-1, 0, 0},
  101. .ob = {1, 1, 1},/* 3 chain */
  102. .db_stage2 = {1, 1, 1}, /* 3 chain */
  103. .db_stage3 = {0, 0, 0},
  104. .db_stage4 = {0, 0, 0},
  105. .xpaBiasLvl = 0,
  106. .txFrameToDataStart = 0x0e,
  107. .txFrameToPaOn = 0x0e,
  108. .txClip = 3, /* 4 bits tx_clip, 4 bits dac_scale_cck */
  109. .antennaGain = 0,
  110. .switchSettling = 0x2c,
  111. .adcDesiredSize = -30,
  112. .txEndToXpaOff = 0,
  113. .txEndToRxOn = 0x2,
  114. .txFrameToXpaOn = 0xe,
  115. .thresh62 = 28,
  116. .futureModal = { /* [32] */
  117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  119. },
  120. },
  121. .calFreqPier2G = {
  122. FREQ2FBIN(2412, 1),
  123. FREQ2FBIN(2437, 1),
  124. FREQ2FBIN(2472, 1),
  125. },
  126. /* ar9300_cal_data_per_freq_op_loop 2g */
  127. .calPierData2G = {
  128. { {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0} },
  129. { {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0} },
  130. { {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0} },
  131. },
  132. .calTarget_freqbin_Cck = {
  133. FREQ2FBIN(2412, 1),
  134. FREQ2FBIN(2484, 1),
  135. },
  136. .calTarget_freqbin_2G = {
  137. FREQ2FBIN(2412, 1),
  138. FREQ2FBIN(2437, 1),
  139. FREQ2FBIN(2472, 1)
  140. },
  141. .calTarget_freqbin_2GHT20 = {
  142. FREQ2FBIN(2412, 1),
  143. FREQ2FBIN(2437, 1),
  144. FREQ2FBIN(2472, 1)
  145. },
  146. .calTarget_freqbin_2GHT40 = {
  147. FREQ2FBIN(2412, 1),
  148. FREQ2FBIN(2437, 1),
  149. FREQ2FBIN(2472, 1)
  150. },
  151. .calTargetPowerCck = {
  152. /* 1L-5L,5S,11L,11S */
  153. { {36, 36, 36, 36} },
  154. { {36, 36, 36, 36} },
  155. },
  156. .calTargetPower2G = {
  157. /* 6-24,36,48,54 */
  158. { {32, 32, 28, 24} },
  159. { {32, 32, 28, 24} },
  160. { {32, 32, 28, 24} },
  161. },
  162. .calTargetPower2GHT20 = {
  163. { {32, 32, 32, 32, 28, 20, 32, 32, 28, 20, 32, 32, 28, 20} },
  164. { {32, 32, 32, 32, 28, 20, 32, 32, 28, 20, 32, 32, 28, 20} },
  165. { {32, 32, 32, 32, 28, 20, 32, 32, 28, 20, 32, 32, 28, 20} },
  166. },
  167. .calTargetPower2GHT40 = {
  168. { {32, 32, 32, 32, 28, 20, 32, 32, 28, 20, 32, 32, 28, 20} },
  169. { {32, 32, 32, 32, 28, 20, 32, 32, 28, 20, 32, 32, 28, 20} },
  170. { {32, 32, 32, 32, 28, 20, 32, 32, 28, 20, 32, 32, 28, 20} },
  171. },
  172. .ctlIndex_2G = {
  173. 0x11, 0x12, 0x15, 0x17, 0x41, 0x42,
  174. 0x45, 0x47, 0x31, 0x32, 0x35, 0x37,
  175. },
  176. .ctl_freqbin_2G = {
  177. {
  178. FREQ2FBIN(2412, 1),
  179. FREQ2FBIN(2417, 1),
  180. FREQ2FBIN(2457, 1),
  181. FREQ2FBIN(2462, 1)
  182. },
  183. {
  184. FREQ2FBIN(2412, 1),
  185. FREQ2FBIN(2417, 1),
  186. FREQ2FBIN(2462, 1),
  187. 0xFF,
  188. },
  189. {
  190. FREQ2FBIN(2412, 1),
  191. FREQ2FBIN(2417, 1),
  192. FREQ2FBIN(2462, 1),
  193. 0xFF,
  194. },
  195. {
  196. FREQ2FBIN(2422, 1),
  197. FREQ2FBIN(2427, 1),
  198. FREQ2FBIN(2447, 1),
  199. FREQ2FBIN(2452, 1)
  200. },
  201. {
  202. /* Data[4].ctlEdges[0].bChannel */ FREQ2FBIN(2412, 1),
  203. /* Data[4].ctlEdges[1].bChannel */ FREQ2FBIN(2417, 1),
  204. /* Data[4].ctlEdges[2].bChannel */ FREQ2FBIN(2472, 1),
  205. /* Data[4].ctlEdges[3].bChannel */ FREQ2FBIN(2484, 1),
  206. },
  207. {
  208. /* Data[5].ctlEdges[0].bChannel */ FREQ2FBIN(2412, 1),
  209. /* Data[5].ctlEdges[1].bChannel */ FREQ2FBIN(2417, 1),
  210. /* Data[5].ctlEdges[2].bChannel */ FREQ2FBIN(2472, 1),
  211. 0,
  212. },
  213. {
  214. /* Data[6].ctlEdges[0].bChannel */ FREQ2FBIN(2412, 1),
  215. /* Data[6].ctlEdges[1].bChannel */ FREQ2FBIN(2417, 1),
  216. FREQ2FBIN(2472, 1),
  217. 0,
  218. },
  219. {
  220. /* Data[7].ctlEdges[0].bChannel */ FREQ2FBIN(2422, 1),
  221. /* Data[7].ctlEdges[1].bChannel */ FREQ2FBIN(2427, 1),
  222. /* Data[7].ctlEdges[2].bChannel */ FREQ2FBIN(2447, 1),
  223. /* Data[7].ctlEdges[3].bChannel */ FREQ2FBIN(2462, 1),
  224. },
  225. {
  226. /* Data[8].ctlEdges[0].bChannel */ FREQ2FBIN(2412, 1),
  227. /* Data[8].ctlEdges[1].bChannel */ FREQ2FBIN(2417, 1),
  228. /* Data[8].ctlEdges[2].bChannel */ FREQ2FBIN(2472, 1),
  229. },
  230. {
  231. /* Data[9].ctlEdges[0].bChannel */ FREQ2FBIN(2412, 1),
  232. /* Data[9].ctlEdges[1].bChannel */ FREQ2FBIN(2417, 1),
  233. /* Data[9].ctlEdges[2].bChannel */ FREQ2FBIN(2472, 1),
  234. 0
  235. },
  236. {
  237. /* Data[10].ctlEdges[0].bChannel */ FREQ2FBIN(2412, 1),
  238. /* Data[10].ctlEdges[1].bChannel */ FREQ2FBIN(2417, 1),
  239. /* Data[10].ctlEdges[2].bChannel */ FREQ2FBIN(2472, 1),
  240. 0
  241. },
  242. {
  243. /* Data[11].ctlEdges[0].bChannel */ FREQ2FBIN(2422, 1),
  244. /* Data[11].ctlEdges[1].bChannel */ FREQ2FBIN(2427, 1),
  245. /* Data[11].ctlEdges[2].bChannel */ FREQ2FBIN(2447, 1),
  246. /* Data[11].ctlEdges[3].bChannel */
  247. FREQ2FBIN(2462, 1),
  248. }
  249. },
  250. .ctlPowerData_2G = {
  251. { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } },
  252. { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } },
  253. { { {60, 1}, {60, 0}, {60, 0}, {60, 1} } },
  254. { { {60, 1}, {60, 0}, {0, 0}, {0, 0} } },
  255. { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } },
  256. { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } },
  257. { { {60, 0}, {60, 1}, {60, 1}, {60, 0} } },
  258. { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } },
  259. { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } },
  260. { { {60, 0}, {60, 1}, {60, 0}, {60, 0} } },
  261. { { {60, 0}, {60, 1}, {60, 1}, {60, 1} } },
  262. },
  263. .modalHeader5G = {
  264. /* 4 idle,t1,t2,b (4 bits per setting) */
  265. .antCtrlCommon = 0x110,
  266. /* 4 ra1l1, ra2l1, ra1l2,ra2l2,ra12 */
  267. .antCtrlCommon2 = 0x22222,
  268. /* antCtrlChain 6 idle, t,r,rx1,rx12,b (2 bits each) */
  269. .antCtrlChain = {
  270. 0x000, 0x000, 0x000,
  271. },
  272. /* xatten1DB 3 xatten1_db for AR9280 (0xa20c/b20c 5:0) */
  273. .xatten1DB = {0, 0, 0},
  274. /*
  275. * xatten1Margin[AR9300_MAX_CHAINS]; 3 xatten1_margin
  276. * for merlin (0xa20c/b20c 16:12
  277. */
  278. .xatten1Margin = {0, 0, 0},
  279. .tempSlope = 68,
  280. .voltSlope = 0,
  281. /* spurChans spur channels in usual fbin coding format */
  282. .spurChans = {0, 0, 0, 0, 0},
  283. /* noiseFloorThreshCh Check if the register is per chain */
  284. .noiseFloorThreshCh = {-1, 0, 0},
  285. .ob = {3, 3, 3}, /* 3 chain */
  286. .db_stage2 = {3, 3, 3}, /* 3 chain */
  287. .db_stage3 = {3, 3, 3}, /* doesn't exist for 2G */
  288. .db_stage4 = {3, 3, 3}, /* don't exist for 2G */
  289. .xpaBiasLvl = 0,
  290. .txFrameToDataStart = 0x0e,
  291. .txFrameToPaOn = 0x0e,
  292. .txClip = 3, /* 4 bits tx_clip, 4 bits dac_scale_cck */
  293. .antennaGain = 0,
  294. .switchSettling = 0x2d,
  295. .adcDesiredSize = -30,
  296. .txEndToXpaOff = 0,
  297. .txEndToRxOn = 0x2,
  298. .txFrameToXpaOn = 0xe,
  299. .thresh62 = 28,
  300. .futureModal = {
  301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  303. },
  304. },
  305. .calFreqPier5G = {
  306. FREQ2FBIN(5180, 0),
  307. FREQ2FBIN(5220, 0),
  308. FREQ2FBIN(5320, 0),
  309. FREQ2FBIN(5400, 0),
  310. FREQ2FBIN(5500, 0),
  311. FREQ2FBIN(5600, 0),
  312. FREQ2FBIN(5725, 0),
  313. FREQ2FBIN(5825, 0)
  314. },
  315. .calPierData5G = {
  316. {
  317. {0, 0, 0, 0, 0},
  318. {0, 0, 0, 0, 0},
  319. {0, 0, 0, 0, 0},
  320. {0, 0, 0, 0, 0},
  321. {0, 0, 0, 0, 0},
  322. {0, 0, 0, 0, 0},
  323. {0, 0, 0, 0, 0},
  324. {0, 0, 0, 0, 0},
  325. },
  326. {
  327. {0, 0, 0, 0, 0},
  328. {0, 0, 0, 0, 0},
  329. {0, 0, 0, 0, 0},
  330. {0, 0, 0, 0, 0},
  331. {0, 0, 0, 0, 0},
  332. {0, 0, 0, 0, 0},
  333. {0, 0, 0, 0, 0},
  334. {0, 0, 0, 0, 0},
  335. },
  336. {
  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. {0, 0, 0, 0, 0},
  345. },
  346. },
  347. .calTarget_freqbin_5G = {
  348. FREQ2FBIN(5180, 0),
  349. FREQ2FBIN(5220, 0),
  350. FREQ2FBIN(5320, 0),
  351. FREQ2FBIN(5400, 0),
  352. FREQ2FBIN(5500, 0),
  353. FREQ2FBIN(5600, 0),
  354. FREQ2FBIN(5725, 0),
  355. FREQ2FBIN(5825, 0)
  356. },
  357. .calTarget_freqbin_5GHT20 = {
  358. FREQ2FBIN(5180, 0),
  359. FREQ2FBIN(5240, 0),
  360. FREQ2FBIN(5320, 0),
  361. FREQ2FBIN(5500, 0),
  362. FREQ2FBIN(5700, 0),
  363. FREQ2FBIN(5745, 0),
  364. FREQ2FBIN(5725, 0),
  365. FREQ2FBIN(5825, 0)
  366. },
  367. .calTarget_freqbin_5GHT40 = {
  368. FREQ2FBIN(5180, 0),
  369. FREQ2FBIN(5240, 0),
  370. FREQ2FBIN(5320, 0),
  371. FREQ2FBIN(5500, 0),
  372. FREQ2FBIN(5700, 0),
  373. FREQ2FBIN(5745, 0),
  374. FREQ2FBIN(5725, 0),
  375. FREQ2FBIN(5825, 0)
  376. },
  377. .calTargetPower5G = {
  378. /* 6-24,36,48,54 */
  379. { {20, 20, 20, 10} },
  380. { {20, 20, 20, 10} },
  381. { {20, 20, 20, 10} },
  382. { {20, 20, 20, 10} },
  383. { {20, 20, 20, 10} },
  384. { {20, 20, 20, 10} },
  385. { {20, 20, 20, 10} },
  386. { {20, 20, 20, 10} },
  387. },
  388. .calTargetPower5GHT20 = {
  389. /*
  390. * 0_8_16,1-3_9-11_17-19,
  391. * 4,5,6,7,12,13,14,15,20,21,22,23
  392. */
  393. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  394. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  395. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  396. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  397. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  398. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  399. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  400. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  401. },
  402. .calTargetPower5GHT40 = {
  403. /*
  404. * 0_8_16,1-3_9-11_17-19,
  405. * 4,5,6,7,12,13,14,15,20,21,22,23
  406. */
  407. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  408. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  409. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  410. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  411. { {20, 20, 10, 10, 0, 0, 10, 10, 0, 0, 10, 10, 0, 0} },
  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. },
  416. .ctlIndex_5G = {
  417. 0x10, 0x16, 0x18, 0x40, 0x46,
  418. 0x48, 0x30, 0x36, 0x38
  419. },
  420. .ctl_freqbin_5G = {
  421. {
  422. /* Data[0].ctlEdges[0].bChannel */ FREQ2FBIN(5180, 0),
  423. /* Data[0].ctlEdges[1].bChannel */ FREQ2FBIN(5260, 0),
  424. /* Data[0].ctlEdges[2].bChannel */ FREQ2FBIN(5280, 0),
  425. /* Data[0].ctlEdges[3].bChannel */ FREQ2FBIN(5500, 0),
  426. /* Data[0].ctlEdges[4].bChannel */ FREQ2FBIN(5600, 0),
  427. /* Data[0].ctlEdges[5].bChannel */ FREQ2FBIN(5700, 0),
  428. /* Data[0].ctlEdges[6].bChannel */ FREQ2FBIN(5745, 0),
  429. /* Data[0].ctlEdges[7].bChannel */ FREQ2FBIN(5825, 0)
  430. },
  431. {
  432. /* Data[1].ctlEdges[0].bChannel */ FREQ2FBIN(5180, 0),
  433. /* Data[1].ctlEdges[1].bChannel */ FREQ2FBIN(5260, 0),
  434. /* Data[1].ctlEdges[2].bChannel */ FREQ2FBIN(5280, 0),
  435. /* Data[1].ctlEdges[3].bChannel */ FREQ2FBIN(5500, 0),
  436. /* Data[1].ctlEdges[4].bChannel */ FREQ2FBIN(5520, 0),
  437. /* Data[1].ctlEdges[5].bChannel */ FREQ2FBIN(5700, 0),
  438. /* Data[1].ctlEdges[6].bChannel */ FREQ2FBIN(5745, 0),
  439. /* Data[1].ctlEdges[7].bChannel */ FREQ2FBIN(5825, 0)
  440. },
  441. {
  442. /* Data[2].ctlEdges[0].bChannel */ FREQ2FBIN(5190, 0),
  443. /* Data[2].ctlEdges[1].bChannel */ FREQ2FBIN(5230, 0),
  444. /* Data[2].ctlEdges[2].bChannel */ FREQ2FBIN(5270, 0),
  445. /* Data[2].ctlEdges[3].bChannel */ FREQ2FBIN(5310, 0),
  446. /* Data[2].ctlEdges[4].bChannel */ FREQ2FBIN(5510, 0),
  447. /* Data[2].ctlEdges[5].bChannel */ FREQ2FBIN(5550, 0),
  448. /* Data[2].ctlEdges[6].bChannel */ FREQ2FBIN(5670, 0),
  449. /* Data[2].ctlEdges[7].bChannel */ FREQ2FBIN(5755, 0)
  450. },
  451. {
  452. /* Data[3].ctlEdges[0].bChannel */ FREQ2FBIN(5180, 0),
  453. /* Data[3].ctlEdges[1].bChannel */ FREQ2FBIN(5200, 0),
  454. /* Data[3].ctlEdges[2].bChannel */ FREQ2FBIN(5260, 0),
  455. /* Data[3].ctlEdges[3].bChannel */ FREQ2FBIN(5320, 0),
  456. /* Data[3].ctlEdges[4].bChannel */ FREQ2FBIN(5500, 0),
  457. /* Data[3].ctlEdges[5].bChannel */ FREQ2FBIN(5700, 0),
  458. /* Data[3].ctlEdges[6].bChannel */ 0xFF,
  459. /* Data[3].ctlEdges[7].bChannel */ 0xFF,
  460. },
  461. {
  462. /* Data[4].ctlEdges[0].bChannel */ FREQ2FBIN(5180, 0),
  463. /* Data[4].ctlEdges[1].bChannel */ FREQ2FBIN(5260, 0),
  464. /* Data[4].ctlEdges[2].bChannel */ FREQ2FBIN(5500, 0),
  465. /* Data[4].ctlEdges[3].bChannel */ FREQ2FBIN(5700, 0),
  466. /* Data[4].ctlEdges[4].bChannel */ 0xFF,
  467. /* Data[4].ctlEdges[5].bChannel */ 0xFF,
  468. /* Data[4].ctlEdges[6].bChannel */ 0xFF,
  469. /* Data[4].ctlEdges[7].bChannel */ 0xFF,
  470. },
  471. {
  472. /* Data[5].ctlEdges[0].bChannel */ FREQ2FBIN(5190, 0),
  473. /* Data[5].ctlEdges[1].bChannel */ FREQ2FBIN(5270, 0),
  474. /* Data[5].ctlEdges[2].bChannel */ FREQ2FBIN(5310, 0),
  475. /* Data[5].ctlEdges[3].bChannel */ FREQ2FBIN(5510, 0),
  476. /* Data[5].ctlEdges[4].bChannel */ FREQ2FBIN(5590, 0),
  477. /* Data[5].ctlEdges[5].bChannel */ FREQ2FBIN(5670, 0),
  478. /* Data[5].ctlEdges[6].bChannel */ 0xFF,
  479. /* Data[5].ctlEdges[7].bChannel */ 0xFF
  480. },
  481. {
  482. /* Data[6].ctlEdges[0].bChannel */ FREQ2FBIN(5180, 0),
  483. /* Data[6].ctlEdges[1].bChannel */ FREQ2FBIN(5200, 0),
  484. /* Data[6].ctlEdges[2].bChannel */ FREQ2FBIN(5220, 0),
  485. /* Data[6].ctlEdges[3].bChannel */ FREQ2FBIN(5260, 0),
  486. /* Data[6].ctlEdges[4].bChannel */ FREQ2FBIN(5500, 0),
  487. /* Data[6].ctlEdges[5].bChannel */ FREQ2FBIN(5600, 0),
  488. /* Data[6].ctlEdges[6].bChannel */ FREQ2FBIN(5700, 0),
  489. /* Data[6].ctlEdges[7].bChannel */ FREQ2FBIN(5745, 0)
  490. },
  491. {
  492. /* Data[7].ctlEdges[0].bChannel */ FREQ2FBIN(5180, 0),
  493. /* Data[7].ctlEdges[1].bChannel */ FREQ2FBIN(5260, 0),
  494. /* Data[7].ctlEdges[2].bChannel */ FREQ2FBIN(5320, 0),
  495. /* Data[7].ctlEdges[3].bChannel */ FREQ2FBIN(5500, 0),
  496. /* Data[7].ctlEdges[4].bChannel */ FREQ2FBIN(5560, 0),
  497. /* Data[7].ctlEdges[5].bChannel */ FREQ2FBIN(5700, 0),
  498. /* Data[7].ctlEdges[6].bChannel */ FREQ2FBIN(5745, 0),
  499. /* Data[7].ctlEdges[7].bChannel */ FREQ2FBIN(5825, 0)
  500. },
  501. {
  502. /* Data[8].ctlEdges[0].bChannel */ FREQ2FBIN(5190, 0),
  503. /* Data[8].ctlEdges[1].bChannel */ FREQ2FBIN(5230, 0),
  504. /* Data[8].ctlEdges[2].bChannel */ FREQ2FBIN(5270, 0),
  505. /* Data[8].ctlEdges[3].bChannel */ FREQ2FBIN(5510, 0),
  506. /* Data[8].ctlEdges[4].bChannel */ FREQ2FBIN(5550, 0),
  507. /* Data[8].ctlEdges[5].bChannel */ FREQ2FBIN(5670, 0),
  508. /* Data[8].ctlEdges[6].bChannel */ FREQ2FBIN(5755, 0),
  509. /* Data[8].ctlEdges[7].bChannel */ FREQ2FBIN(5795, 0)
  510. }
  511. },
  512. .ctlPowerData_5G = {
  513. {
  514. {
  515. {60, 1}, {60, 1}, {60, 1}, {60, 1},
  516. {60, 1}, {60, 1}, {60, 1}, {60, 0},
  517. }
  518. },
  519. {
  520. {
  521. {60, 1}, {60, 1}, {60, 1}, {60, 1},
  522. {60, 1}, {60, 1}, {60, 1}, {60, 0},
  523. }
  524. },
  525. {
  526. {
  527. {60, 0}, {60, 1}, {60, 0}, {60, 1},
  528. {60, 1}, {60, 1}, {60, 1}, {60, 1},
  529. }
  530. },
  531. {
  532. {
  533. {60, 0}, {60, 1}, {60, 1}, {60, 0},
  534. {60, 1}, {60, 0}, {60, 0}, {60, 0},
  535. }
  536. },
  537. {
  538. {
  539. {60, 1}, {60, 1}, {60, 1}, {60, 0},
  540. {60, 0}, {60, 0}, {60, 0}, {60, 0},
  541. }
  542. },
  543. {
  544. {
  545. {60, 1}, {60, 1}, {60, 1}, {60, 1},
  546. {60, 1}, {60, 0}, {60, 0}, {60, 0},
  547. }
  548. },
  549. {
  550. {
  551. {60, 1}, {60, 1}, {60, 1}, {60, 1},
  552. {60, 1}, {60, 1}, {60, 1}, {60, 1},
  553. }
  554. },
  555. {
  556. {
  557. {60, 1}, {60, 1}, {60, 0}, {60, 1},
  558. {60, 1}, {60, 1}, {60, 1}, {60, 0},
  559. }
  560. },
  561. {
  562. {
  563. {60, 1}, {60, 0}, {60, 1}, {60, 1},
  564. {60, 1}, {60, 1}, {60, 0}, {60, 1},
  565. }
  566. },
  567. }
  568. };
  569. static int ath9k_hw_ar9300_check_eeprom(struct ath_hw *ah)
  570. {
  571. return 0;
  572. }
  573. static u32 ath9k_hw_ar9300_get_eeprom(struct ath_hw *ah,
  574. enum eeprom_param param)
  575. {
  576. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  577. struct ar9300_base_eep_hdr *pBase = &eep->baseEepHeader;
  578. switch (param) {
  579. case EEP_MAC_LSW:
  580. return eep->macAddr[0] << 8 | eep->macAddr[1];
  581. case EEP_MAC_MID:
  582. return eep->macAddr[2] << 8 | eep->macAddr[3];
  583. case EEP_MAC_MSW:
  584. return eep->macAddr[4] << 8 | eep->macAddr[5];
  585. case EEP_REG_0:
  586. return pBase->regDmn[0];
  587. case EEP_REG_1:
  588. return pBase->regDmn[1];
  589. case EEP_OP_CAP:
  590. return pBase->deviceCap;
  591. case EEP_OP_MODE:
  592. return pBase->opCapFlags.opFlags;
  593. case EEP_RF_SILENT:
  594. return pBase->rfSilent;
  595. case EEP_TX_MASK:
  596. return (pBase->txrxMask >> 4) & 0xf;
  597. case EEP_RX_MASK:
  598. return pBase->txrxMask & 0xf;
  599. case EEP_DRIVE_STRENGTH:
  600. #define AR9300_EEP_BASE_DRIV_STRENGTH 0x1
  601. return pBase->miscConfiguration & AR9300_EEP_BASE_DRIV_STRENGTH;
  602. case EEP_INTERNAL_REGULATOR:
  603. /* Bit 4 is internal regulator flag */
  604. return (pBase->featureEnable & 0x10) >> 4;
  605. case EEP_SWREG:
  606. return pBase->swreg;
  607. default:
  608. return 0;
  609. }
  610. }
  611. #ifdef __BIG_ENDIAN
  612. static void ar9300_swap_eeprom(struct ar9300_eeprom *eep)
  613. {
  614. u32 dword;
  615. u16 word;
  616. int i;
  617. word = swab16(eep->baseEepHeader.regDmn[0]);
  618. eep->baseEepHeader.regDmn[0] = word;
  619. word = swab16(eep->baseEepHeader.regDmn[1]);
  620. eep->baseEepHeader.regDmn[1] = word;
  621. dword = swab32(eep->baseEepHeader.swreg);
  622. eep->baseEepHeader.swreg = dword;
  623. dword = swab32(eep->modalHeader2G.antCtrlCommon);
  624. eep->modalHeader2G.antCtrlCommon = dword;
  625. dword = swab32(eep->modalHeader2G.antCtrlCommon2);
  626. eep->modalHeader2G.antCtrlCommon2 = dword;
  627. dword = swab32(eep->modalHeader5G.antCtrlCommon);
  628. eep->modalHeader5G.antCtrlCommon = dword;
  629. dword = swab32(eep->modalHeader5G.antCtrlCommon2);
  630. eep->modalHeader5G.antCtrlCommon2 = dword;
  631. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  632. word = swab16(eep->modalHeader2G.antCtrlChain[i]);
  633. eep->modalHeader2G.antCtrlChain[i] = word;
  634. word = swab16(eep->modalHeader5G.antCtrlChain[i]);
  635. eep->modalHeader5G.antCtrlChain[i] = word;
  636. }
  637. }
  638. #endif
  639. static bool ar9300_hw_read_eeprom(struct ath_hw *ah,
  640. long address, u8 *buffer, int many)
  641. {
  642. int i;
  643. u8 value[2];
  644. unsigned long eepAddr;
  645. unsigned long byteAddr;
  646. u16 *svalue;
  647. struct ath_common *common = ath9k_hw_common(ah);
  648. if ((address < 0) || ((address + many) > AR9300_EEPROM_SIZE - 1)) {
  649. ath_print(common, ATH_DBG_EEPROM,
  650. "eeprom address not in range\n");
  651. return false;
  652. }
  653. for (i = 0; i < many; i++) {
  654. eepAddr = (u16) (address + i) / 2;
  655. byteAddr = (u16) (address + i) % 2;
  656. svalue = (u16 *) value;
  657. if (!ath9k_hw_nvram_read(common, eepAddr, svalue)) {
  658. ath_print(common, ATH_DBG_EEPROM,
  659. "unable to read eeprom region\n");
  660. return false;
  661. }
  662. *svalue = le16_to_cpu(*svalue);
  663. buffer[i] = value[byteAddr];
  664. }
  665. return true;
  666. }
  667. static bool ar9300_read_eeprom(struct ath_hw *ah,
  668. int address, u8 *buffer, int many)
  669. {
  670. int it;
  671. for (it = 0; it < many; it++)
  672. if (!ar9300_hw_read_eeprom(ah,
  673. (address - it),
  674. (buffer + it), 1))
  675. return false;
  676. return true;
  677. }
  678. static void ar9300_comp_hdr_unpack(u8 *best, int *code, int *reference,
  679. int *length, int *major, int *minor)
  680. {
  681. unsigned long value[4];
  682. value[0] = best[0];
  683. value[1] = best[1];
  684. value[2] = best[2];
  685. value[3] = best[3];
  686. *code = ((value[0] >> 5) & 0x0007);
  687. *reference = (value[0] & 0x001f) | ((value[1] >> 2) & 0x0020);
  688. *length = ((value[1] << 4) & 0x07f0) | ((value[2] >> 4) & 0x000f);
  689. *major = (value[2] & 0x000f);
  690. *minor = (value[3] & 0x00ff);
  691. }
  692. static u16 ar9300_comp_cksum(u8 *data, int dsize)
  693. {
  694. int it, checksum = 0;
  695. for (it = 0; it < dsize; it++) {
  696. checksum += data[it];
  697. checksum &= 0xffff;
  698. }
  699. return checksum;
  700. }
  701. static bool ar9300_uncompress_block(struct ath_hw *ah,
  702. u8 *mptr,
  703. int mdataSize,
  704. u8 *block,
  705. int size)
  706. {
  707. int it;
  708. int spot;
  709. int offset;
  710. int length;
  711. struct ath_common *common = ath9k_hw_common(ah);
  712. spot = 0;
  713. for (it = 0; it < size; it += (length+2)) {
  714. offset = block[it];
  715. offset &= 0xff;
  716. spot += offset;
  717. length = block[it+1];
  718. length &= 0xff;
  719. if (length > 0 && spot >= 0 && spot+length < mdataSize) {
  720. ath_print(common, ATH_DBG_EEPROM,
  721. "Restore at %d: spot=%d "
  722. "offset=%d length=%d\n",
  723. it, spot, offset, length);
  724. memcpy(&mptr[spot], &block[it+2], length);
  725. spot += length;
  726. } else if (length > 0) {
  727. ath_print(common, ATH_DBG_EEPROM,
  728. "Bad restore at %d: spot=%d "
  729. "offset=%d length=%d\n",
  730. it, spot, offset, length);
  731. return false;
  732. }
  733. }
  734. return true;
  735. }
  736. static int ar9300_compress_decision(struct ath_hw *ah,
  737. int it,
  738. int code,
  739. int reference,
  740. u8 *mptr,
  741. u8 *word, int length, int mdata_size)
  742. {
  743. struct ath_common *common = ath9k_hw_common(ah);
  744. u8 *dptr;
  745. switch (code) {
  746. case _CompressNone:
  747. if (length != mdata_size) {
  748. ath_print(common, ATH_DBG_EEPROM,
  749. "EEPROM structure size mismatch"
  750. "memory=%d eeprom=%d\n", mdata_size, length);
  751. return -1;
  752. }
  753. memcpy(mptr, (u8 *) (word + COMP_HDR_LEN), length);
  754. ath_print(common, ATH_DBG_EEPROM, "restored eeprom %d:"
  755. " uncompressed, length %d\n", it, length);
  756. break;
  757. case _CompressBlock:
  758. if (reference == 0) {
  759. dptr = mptr;
  760. } else {
  761. if (reference != 2) {
  762. ath_print(common, ATH_DBG_EEPROM,
  763. "cant find reference eeprom"
  764. "struct %d\n", reference);
  765. return -1;
  766. }
  767. memcpy(mptr, &ar9300_default, mdata_size);
  768. }
  769. ath_print(common, ATH_DBG_EEPROM,
  770. "restore eeprom %d: block, reference %d,"
  771. " length %d\n", it, reference, length);
  772. ar9300_uncompress_block(ah, mptr, mdata_size,
  773. (u8 *) (word + COMP_HDR_LEN), length);
  774. break;
  775. default:
  776. ath_print(common, ATH_DBG_EEPROM, "unknown compression"
  777. " code %d\n", code);
  778. return -1;
  779. }
  780. return 0;
  781. }
  782. /*
  783. * Read the configuration data from the eeprom.
  784. * The data can be put in any specified memory buffer.
  785. *
  786. * Returns -1 on error.
  787. * Returns address of next memory location on success.
  788. */
  789. static int ar9300_eeprom_restore_internal(struct ath_hw *ah,
  790. u8 *mptr, int mdata_size)
  791. {
  792. #define MDEFAULT 15
  793. #define MSTATE 100
  794. int cptr;
  795. u8 *word;
  796. int code;
  797. int reference, length, major, minor;
  798. int osize;
  799. int it;
  800. u16 checksum, mchecksum;
  801. struct ath_common *common = ath9k_hw_common(ah);
  802. word = kzalloc(2048, GFP_KERNEL);
  803. if (!word)
  804. return -1;
  805. memcpy(mptr, &ar9300_default, mdata_size);
  806. cptr = AR9300_BASE_ADDR;
  807. for (it = 0; it < MSTATE; it++) {
  808. if (!ar9300_read_eeprom(ah, cptr, word, COMP_HDR_LEN))
  809. goto fail;
  810. if ((word[0] == 0 && word[1] == 0 && word[2] == 0 &&
  811. word[3] == 0) || (word[0] == 0xff && word[1] == 0xff
  812. && word[2] == 0xff && word[3] == 0xff))
  813. break;
  814. ar9300_comp_hdr_unpack(word, &code, &reference,
  815. &length, &major, &minor);
  816. ath_print(common, ATH_DBG_EEPROM,
  817. "Found block at %x: code=%d ref=%d"
  818. "length=%d major=%d minor=%d\n", cptr, code,
  819. reference, length, major, minor);
  820. if (length >= 1024) {
  821. ath_print(common, ATH_DBG_EEPROM,
  822. "Skipping bad header\n");
  823. cptr -= COMP_HDR_LEN;
  824. continue;
  825. }
  826. osize = length;
  827. ar9300_read_eeprom(ah, cptr, word,
  828. COMP_HDR_LEN + osize + COMP_CKSUM_LEN);
  829. checksum = ar9300_comp_cksum(&word[COMP_HDR_LEN], length);
  830. mchecksum = word[COMP_HDR_LEN + osize] |
  831. (word[COMP_HDR_LEN + osize + 1] << 8);
  832. ath_print(common, ATH_DBG_EEPROM,
  833. "checksum %x %x\n", checksum, mchecksum);
  834. if (checksum == mchecksum) {
  835. ar9300_compress_decision(ah, it, code, reference, mptr,
  836. word, length, mdata_size);
  837. } else {
  838. ath_print(common, ATH_DBG_EEPROM,
  839. "skipping block with bad checksum\n");
  840. }
  841. cptr -= (COMP_HDR_LEN + osize + COMP_CKSUM_LEN);
  842. }
  843. kfree(word);
  844. return cptr;
  845. fail:
  846. kfree(word);
  847. return -1;
  848. }
  849. /*
  850. * Restore the configuration structure by reading the eeprom.
  851. * This function destroys any existing in-memory structure
  852. * content.
  853. */
  854. static bool ath9k_hw_ar9300_fill_eeprom(struct ath_hw *ah)
  855. {
  856. u8 *mptr = NULL;
  857. int mdata_size;
  858. mptr = (u8 *) &ah->eeprom.ar9300_eep;
  859. mdata_size = sizeof(struct ar9300_eeprom);
  860. if (mptr && mdata_size > 0) {
  861. /* At this point, mptr points to the eeprom data structure
  862. * in it's "default" state. If this is big endian, swap the
  863. * data structures back to "little endian"
  864. */
  865. /* First swap, default to Little Endian */
  866. #ifdef __BIG_ENDIAN
  867. ar9300_swap_eeprom((struct ar9300_eeprom *)mptr);
  868. #endif
  869. if (ar9300_eeprom_restore_internal(ah, mptr, mdata_size) >= 0)
  870. return true;
  871. /* Second Swap, back to Big Endian */
  872. #ifdef __BIG_ENDIAN
  873. ar9300_swap_eeprom((struct ar9300_eeprom *)mptr);
  874. #endif
  875. }
  876. return false;
  877. }
  878. /* XXX: review hardware docs */
  879. static int ath9k_hw_ar9300_get_eeprom_ver(struct ath_hw *ah)
  880. {
  881. return ah->eeprom.ar9300_eep.eepromVersion;
  882. }
  883. /* XXX: could be read from the eepromVersion, not sure yet */
  884. static int ath9k_hw_ar9300_get_eeprom_rev(struct ath_hw *ah)
  885. {
  886. return 0;
  887. }
  888. static u8 ath9k_hw_ar9300_get_num_ant_config(struct ath_hw *ah,
  889. enum ieee80211_band freq_band)
  890. {
  891. return 1;
  892. }
  893. static u16 ath9k_hw_ar9300_get_eeprom_antenna_cfg(struct ath_hw *ah,
  894. struct ath9k_channel *chan)
  895. {
  896. return -EINVAL;
  897. }
  898. static s32 ar9003_hw_xpa_bias_level_get(struct ath_hw *ah, bool is2ghz)
  899. {
  900. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  901. if (is2ghz)
  902. return eep->modalHeader2G.xpaBiasLvl;
  903. else
  904. return eep->modalHeader5G.xpaBiasLvl;
  905. }
  906. static void ar9003_hw_xpa_bias_level_apply(struct ath_hw *ah, bool is2ghz)
  907. {
  908. int bias = ar9003_hw_xpa_bias_level_get(ah, is2ghz);
  909. REG_RMW_FIELD(ah, AR_CH0_TOP, AR_CH0_TOP_XPABIASLVL, (bias & 0x3));
  910. REG_RMW_FIELD(ah, AR_CH0_THERM, AR_CH0_THERM_SPARE,
  911. ((bias >> 2) & 0x3));
  912. }
  913. static u32 ar9003_hw_ant_ctrl_common_get(struct ath_hw *ah, bool is2ghz)
  914. {
  915. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  916. if (is2ghz)
  917. return eep->modalHeader2G.antCtrlCommon;
  918. else
  919. return eep->modalHeader5G.antCtrlCommon;
  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. if (is2ghz)
  925. return eep->modalHeader2G.antCtrlCommon2;
  926. else
  927. return eep->modalHeader5G.antCtrlCommon2;
  928. }
  929. static u16 ar9003_hw_ant_ctrl_chain_get(struct ath_hw *ah,
  930. int chain,
  931. bool is2ghz)
  932. {
  933. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  934. if (chain >= 0 && chain < AR9300_MAX_CHAINS) {
  935. if (is2ghz)
  936. return eep->modalHeader2G.antCtrlChain[chain];
  937. else
  938. return eep->modalHeader5G.antCtrlChain[chain];
  939. }
  940. return 0;
  941. }
  942. static void ar9003_hw_ant_ctrl_apply(struct ath_hw *ah, bool is2ghz)
  943. {
  944. u32 value = ar9003_hw_ant_ctrl_common_get(ah, is2ghz);
  945. REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM, AR_SWITCH_TABLE_COM_ALL, value);
  946. value = ar9003_hw_ant_ctrl_common_2_get(ah, is2ghz);
  947. REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2, AR_SWITCH_TABLE_COM2_ALL, value);
  948. value = ar9003_hw_ant_ctrl_chain_get(ah, 0, is2ghz);
  949. REG_RMW_FIELD(ah, AR_PHY_SWITCH_CHAIN_0, AR_SWITCH_TABLE_ALL, value);
  950. value = ar9003_hw_ant_ctrl_chain_get(ah, 1, is2ghz);
  951. REG_RMW_FIELD(ah, AR_PHY_SWITCH_CHAIN_1, AR_SWITCH_TABLE_ALL, value);
  952. value = ar9003_hw_ant_ctrl_chain_get(ah, 2, is2ghz);
  953. REG_RMW_FIELD(ah, AR_PHY_SWITCH_CHAIN_2, AR_SWITCH_TABLE_ALL, value);
  954. }
  955. static void ar9003_hw_drive_strength_apply(struct ath_hw *ah)
  956. {
  957. int drive_strength;
  958. unsigned long reg;
  959. drive_strength = ath9k_hw_ar9300_get_eeprom(ah, EEP_DRIVE_STRENGTH);
  960. if (!drive_strength)
  961. return;
  962. reg = REG_READ(ah, AR_PHY_65NM_CH0_BIAS1);
  963. reg &= ~0x00ffffc0;
  964. reg |= 0x5 << 21;
  965. reg |= 0x5 << 18;
  966. reg |= 0x5 << 15;
  967. reg |= 0x5 << 12;
  968. reg |= 0x5 << 9;
  969. reg |= 0x5 << 6;
  970. REG_WRITE(ah, AR_PHY_65NM_CH0_BIAS1, reg);
  971. reg = REG_READ(ah, AR_PHY_65NM_CH0_BIAS2);
  972. reg &= ~0xffffffe0;
  973. reg |= 0x5 << 29;
  974. reg |= 0x5 << 26;
  975. reg |= 0x5 << 23;
  976. reg |= 0x5 << 20;
  977. reg |= 0x5 << 17;
  978. reg |= 0x5 << 14;
  979. reg |= 0x5 << 11;
  980. reg |= 0x5 << 8;
  981. reg |= 0x5 << 5;
  982. REG_WRITE(ah, AR_PHY_65NM_CH0_BIAS2, reg);
  983. reg = REG_READ(ah, AR_PHY_65NM_CH0_BIAS4);
  984. reg &= ~0xff800000;
  985. reg |= 0x5 << 29;
  986. reg |= 0x5 << 26;
  987. reg |= 0x5 << 23;
  988. REG_WRITE(ah, AR_PHY_65NM_CH0_BIAS4, reg);
  989. }
  990. static void ar9003_hw_internal_regulator_apply(struct ath_hw *ah)
  991. {
  992. int internal_regulator =
  993. ath9k_hw_ar9300_get_eeprom(ah, EEP_INTERNAL_REGULATOR);
  994. if (internal_regulator) {
  995. /* Internal regulator is ON. Write swreg register. */
  996. int swreg = ath9k_hw_ar9300_get_eeprom(ah, EEP_SWREG);
  997. REG_WRITE(ah, AR_RTC_REG_CONTROL1,
  998. REG_READ(ah, AR_RTC_REG_CONTROL1) &
  999. (~AR_RTC_REG_CONTROL1_SWREG_PROGRAM));
  1000. REG_WRITE(ah, AR_RTC_REG_CONTROL0, swreg);
  1001. /* Set REG_CONTROL1.SWREG_PROGRAM */
  1002. REG_WRITE(ah, AR_RTC_REG_CONTROL1,
  1003. REG_READ(ah,
  1004. AR_RTC_REG_CONTROL1) |
  1005. AR_RTC_REG_CONTROL1_SWREG_PROGRAM);
  1006. } else {
  1007. REG_WRITE(ah, AR_RTC_SLEEP_CLK,
  1008. (REG_READ(ah,
  1009. AR_RTC_SLEEP_CLK) |
  1010. AR_RTC_FORCE_SWREG_PRD));
  1011. }
  1012. }
  1013. static void ath9k_hw_ar9300_set_board_values(struct ath_hw *ah,
  1014. struct ath9k_channel *chan)
  1015. {
  1016. ar9003_hw_xpa_bias_level_apply(ah, IS_CHAN_2GHZ(chan));
  1017. ar9003_hw_ant_ctrl_apply(ah, IS_CHAN_2GHZ(chan));
  1018. ar9003_hw_drive_strength_apply(ah);
  1019. ar9003_hw_internal_regulator_apply(ah);
  1020. }
  1021. static void ath9k_hw_ar9300_set_addac(struct ath_hw *ah,
  1022. struct ath9k_channel *chan)
  1023. {
  1024. }
  1025. /*
  1026. * Returns the interpolated y value corresponding to the specified x value
  1027. * from the np ordered pairs of data (px,py).
  1028. * The pairs do not have to be in any order.
  1029. * If the specified x value is less than any of the px,
  1030. * the returned y value is equal to the py for the lowest px.
  1031. * If the specified x value is greater than any of the px,
  1032. * the returned y value is equal to the py for the highest px.
  1033. */
  1034. static int ar9003_hw_power_interpolate(int32_t x,
  1035. int32_t *px, int32_t *py, u_int16_t np)
  1036. {
  1037. int ip = 0;
  1038. int lx = 0, ly = 0, lhave = 0;
  1039. int hx = 0, hy = 0, hhave = 0;
  1040. int dx = 0;
  1041. int y = 0;
  1042. lhave = 0;
  1043. hhave = 0;
  1044. /* identify best lower and higher x calibration measurement */
  1045. for (ip = 0; ip < np; ip++) {
  1046. dx = x - px[ip];
  1047. /* this measurement is higher than our desired x */
  1048. if (dx <= 0) {
  1049. if (!hhave || dx > (x - hx)) {
  1050. /* new best higher x measurement */
  1051. hx = px[ip];
  1052. hy = py[ip];
  1053. hhave = 1;
  1054. }
  1055. }
  1056. /* this measurement is lower than our desired x */
  1057. if (dx >= 0) {
  1058. if (!lhave || dx < (x - lx)) {
  1059. /* new best lower x measurement */
  1060. lx = px[ip];
  1061. ly = py[ip];
  1062. lhave = 1;
  1063. }
  1064. }
  1065. }
  1066. /* the low x is good */
  1067. if (lhave) {
  1068. /* so is the high x */
  1069. if (hhave) {
  1070. /* they're the same, so just pick one */
  1071. if (hx == lx)
  1072. y = ly;
  1073. else /* interpolate */
  1074. y = ly + (((x - lx) * (hy - ly)) / (hx - lx));
  1075. } else /* only low is good, use it */
  1076. y = ly;
  1077. } else if (hhave) /* only high is good, use it */
  1078. y = hy;
  1079. else /* nothing is good,this should never happen unless np=0, ???? */
  1080. y = -(1 << 30);
  1081. return y;
  1082. }
  1083. static u8 ar9003_hw_eeprom_get_tgt_pwr(struct ath_hw *ah,
  1084. u16 rateIndex, u16 freq, bool is2GHz)
  1085. {
  1086. u16 numPiers, i;
  1087. s32 targetPowerArray[AR9300_NUM_5G_20_TARGET_POWERS];
  1088. s32 freqArray[AR9300_NUM_5G_20_TARGET_POWERS];
  1089. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1090. struct cal_tgt_pow_legacy *pEepromTargetPwr;
  1091. u8 *pFreqBin;
  1092. if (is2GHz) {
  1093. numPiers = AR9300_NUM_2G_20_TARGET_POWERS;
  1094. pEepromTargetPwr = eep->calTargetPower2G;
  1095. pFreqBin = eep->calTarget_freqbin_2G;
  1096. } else {
  1097. numPiers = AR9300_NUM_5G_20_TARGET_POWERS;
  1098. pEepromTargetPwr = eep->calTargetPower5G;
  1099. pFreqBin = eep->calTarget_freqbin_5G;
  1100. }
  1101. /*
  1102. * create array of channels and targetpower from
  1103. * targetpower piers stored on eeprom
  1104. */
  1105. for (i = 0; i < numPiers; i++) {
  1106. freqArray[i] = FBIN2FREQ(pFreqBin[i], is2GHz);
  1107. targetPowerArray[i] = pEepromTargetPwr[i].tPow2x[rateIndex];
  1108. }
  1109. /* interpolate to get target power for given frequency */
  1110. return (u8) ar9003_hw_power_interpolate((s32) freq,
  1111. freqArray,
  1112. targetPowerArray, numPiers);
  1113. }
  1114. static u8 ar9003_hw_eeprom_get_ht20_tgt_pwr(struct ath_hw *ah,
  1115. u16 rateIndex,
  1116. u16 freq, bool is2GHz)
  1117. {
  1118. u16 numPiers, i;
  1119. s32 targetPowerArray[AR9300_NUM_5G_20_TARGET_POWERS];
  1120. s32 freqArray[AR9300_NUM_5G_20_TARGET_POWERS];
  1121. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1122. struct cal_tgt_pow_ht *pEepromTargetPwr;
  1123. u8 *pFreqBin;
  1124. if (is2GHz) {
  1125. numPiers = AR9300_NUM_2G_20_TARGET_POWERS;
  1126. pEepromTargetPwr = eep->calTargetPower2GHT20;
  1127. pFreqBin = eep->calTarget_freqbin_2GHT20;
  1128. } else {
  1129. numPiers = AR9300_NUM_5G_20_TARGET_POWERS;
  1130. pEepromTargetPwr = eep->calTargetPower5GHT20;
  1131. pFreqBin = eep->calTarget_freqbin_5GHT20;
  1132. }
  1133. /*
  1134. * create array of channels and targetpower
  1135. * from targetpower piers stored on eeprom
  1136. */
  1137. for (i = 0; i < numPiers; i++) {
  1138. freqArray[i] = FBIN2FREQ(pFreqBin[i], is2GHz);
  1139. targetPowerArray[i] = pEepromTargetPwr[i].tPow2x[rateIndex];
  1140. }
  1141. /* interpolate to get target power for given frequency */
  1142. return (u8) ar9003_hw_power_interpolate((s32) freq,
  1143. freqArray,
  1144. targetPowerArray, numPiers);
  1145. }
  1146. static u8 ar9003_hw_eeprom_get_ht40_tgt_pwr(struct ath_hw *ah,
  1147. u16 rateIndex,
  1148. u16 freq, bool is2GHz)
  1149. {
  1150. u16 numPiers, i;
  1151. s32 targetPowerArray[AR9300_NUM_5G_40_TARGET_POWERS];
  1152. s32 freqArray[AR9300_NUM_5G_40_TARGET_POWERS];
  1153. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1154. struct cal_tgt_pow_ht *pEepromTargetPwr;
  1155. u8 *pFreqBin;
  1156. if (is2GHz) {
  1157. numPiers = AR9300_NUM_2G_40_TARGET_POWERS;
  1158. pEepromTargetPwr = eep->calTargetPower2GHT40;
  1159. pFreqBin = eep->calTarget_freqbin_2GHT40;
  1160. } else {
  1161. numPiers = AR9300_NUM_5G_40_TARGET_POWERS;
  1162. pEepromTargetPwr = eep->calTargetPower5GHT40;
  1163. pFreqBin = eep->calTarget_freqbin_5GHT40;
  1164. }
  1165. /*
  1166. * create array of channels and targetpower from
  1167. * targetpower piers stored on eeprom
  1168. */
  1169. for (i = 0; i < numPiers; i++) {
  1170. freqArray[i] = FBIN2FREQ(pFreqBin[i], is2GHz);
  1171. targetPowerArray[i] = pEepromTargetPwr[i].tPow2x[rateIndex];
  1172. }
  1173. /* interpolate to get target power for given frequency */
  1174. return (u8) ar9003_hw_power_interpolate((s32) freq,
  1175. freqArray,
  1176. targetPowerArray, numPiers);
  1177. }
  1178. static u8 ar9003_hw_eeprom_get_cck_tgt_pwr(struct ath_hw *ah,
  1179. u16 rateIndex, u16 freq)
  1180. {
  1181. u16 numPiers = AR9300_NUM_2G_CCK_TARGET_POWERS, i;
  1182. s32 targetPowerArray[AR9300_NUM_2G_CCK_TARGET_POWERS];
  1183. s32 freqArray[AR9300_NUM_2G_CCK_TARGET_POWERS];
  1184. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1185. struct cal_tgt_pow_legacy *pEepromTargetPwr = eep->calTargetPowerCck;
  1186. u8 *pFreqBin = eep->calTarget_freqbin_Cck;
  1187. /*
  1188. * create array of channels and targetpower from
  1189. * targetpower piers stored on eeprom
  1190. */
  1191. for (i = 0; i < numPiers; i++) {
  1192. freqArray[i] = FBIN2FREQ(pFreqBin[i], 1);
  1193. targetPowerArray[i] = pEepromTargetPwr[i].tPow2x[rateIndex];
  1194. }
  1195. /* interpolate to get target power for given frequency */
  1196. return (u8) ar9003_hw_power_interpolate((s32) freq,
  1197. freqArray,
  1198. targetPowerArray, numPiers);
  1199. }
  1200. /* Set tx power registers to array of values passed in */
  1201. static int ar9003_hw_tx_power_regwrite(struct ath_hw *ah, u8 * pPwrArray)
  1202. {
  1203. #define POW_SM(_r, _s) (((_r) & 0x3f) << (_s))
  1204. /* make sure forced gain is not set */
  1205. REG_WRITE(ah, 0xa458, 0);
  1206. /* Write the OFDM power per rate set */
  1207. /* 6 (LSB), 9, 12, 18 (MSB) */
  1208. REG_WRITE(ah, 0xa3c0,
  1209. POW_SM(pPwrArray[ALL_TARGET_LEGACY_6_24], 24) |
  1210. POW_SM(pPwrArray[ALL_TARGET_LEGACY_6_24], 16) |
  1211. POW_SM(pPwrArray[ALL_TARGET_LEGACY_6_24], 8) |
  1212. POW_SM(pPwrArray[ALL_TARGET_LEGACY_6_24], 0));
  1213. /* 24 (LSB), 36, 48, 54 (MSB) */
  1214. REG_WRITE(ah, 0xa3c4,
  1215. POW_SM(pPwrArray[ALL_TARGET_LEGACY_54], 24) |
  1216. POW_SM(pPwrArray[ALL_TARGET_LEGACY_48], 16) |
  1217. POW_SM(pPwrArray[ALL_TARGET_LEGACY_36], 8) |
  1218. POW_SM(pPwrArray[ALL_TARGET_LEGACY_6_24], 0));
  1219. /* Write the CCK power per rate set */
  1220. /* 1L (LSB), reserved, 2L, 2S (MSB) */
  1221. REG_WRITE(ah, 0xa3c8,
  1222. POW_SM(pPwrArray[ALL_TARGET_LEGACY_1L_5L], 24) |
  1223. POW_SM(pPwrArray[ALL_TARGET_LEGACY_1L_5L], 16) |
  1224. /* POW_SM(txPowerTimes2, 8) | this is reserved for AR9003 */
  1225. POW_SM(pPwrArray[ALL_TARGET_LEGACY_1L_5L], 0));
  1226. /* 5.5L (LSB), 5.5S, 11L, 11S (MSB) */
  1227. REG_WRITE(ah, 0xa3cc,
  1228. POW_SM(pPwrArray[ALL_TARGET_LEGACY_11S], 24) |
  1229. POW_SM(pPwrArray[ALL_TARGET_LEGACY_11L], 16) |
  1230. POW_SM(pPwrArray[ALL_TARGET_LEGACY_5S], 8) |
  1231. POW_SM(pPwrArray[ALL_TARGET_LEGACY_1L_5L], 0)
  1232. );
  1233. /* Write the HT20 power per rate set */
  1234. /* 0/8/16 (LSB), 1-3/9-11/17-19, 4, 5 (MSB) */
  1235. REG_WRITE(ah, 0xa3d0,
  1236. POW_SM(pPwrArray[ALL_TARGET_HT20_5], 24) |
  1237. POW_SM(pPwrArray[ALL_TARGET_HT20_4], 16) |
  1238. POW_SM(pPwrArray[ALL_TARGET_HT20_1_3_9_11_17_19], 8) |
  1239. POW_SM(pPwrArray[ALL_TARGET_HT20_0_8_16], 0)
  1240. );
  1241. /* 6 (LSB), 7, 12, 13 (MSB) */
  1242. REG_WRITE(ah, 0xa3d4,
  1243. POW_SM(pPwrArray[ALL_TARGET_HT20_13], 24) |
  1244. POW_SM(pPwrArray[ALL_TARGET_HT20_12], 16) |
  1245. POW_SM(pPwrArray[ALL_TARGET_HT20_7], 8) |
  1246. POW_SM(pPwrArray[ALL_TARGET_HT20_6], 0)
  1247. );
  1248. /* 14 (LSB), 15, 20, 21 */
  1249. REG_WRITE(ah, 0xa3e4,
  1250. POW_SM(pPwrArray[ALL_TARGET_HT20_21], 24) |
  1251. POW_SM(pPwrArray[ALL_TARGET_HT20_20], 16) |
  1252. POW_SM(pPwrArray[ALL_TARGET_HT20_15], 8) |
  1253. POW_SM(pPwrArray[ALL_TARGET_HT20_14], 0)
  1254. );
  1255. /* Mixed HT20 and HT40 rates */
  1256. /* HT20 22 (LSB), HT20 23, HT40 22, HT40 23 (MSB) */
  1257. REG_WRITE(ah, 0xa3e8,
  1258. POW_SM(pPwrArray[ALL_TARGET_HT40_23], 24) |
  1259. POW_SM(pPwrArray[ALL_TARGET_HT40_22], 16) |
  1260. POW_SM(pPwrArray[ALL_TARGET_HT20_23], 8) |
  1261. POW_SM(pPwrArray[ALL_TARGET_HT20_22], 0)
  1262. );
  1263. /*
  1264. * Write the HT40 power per rate set
  1265. * correct PAR difference between HT40 and HT20/LEGACY
  1266. * 0/8/16 (LSB), 1-3/9-11/17-19, 4, 5 (MSB)
  1267. */
  1268. REG_WRITE(ah, 0xa3d8,
  1269. POW_SM(pPwrArray[ALL_TARGET_HT40_5], 24) |
  1270. POW_SM(pPwrArray[ALL_TARGET_HT40_4], 16) |
  1271. POW_SM(pPwrArray[ALL_TARGET_HT40_1_3_9_11_17_19], 8) |
  1272. POW_SM(pPwrArray[ALL_TARGET_HT40_0_8_16], 0)
  1273. );
  1274. /* 6 (LSB), 7, 12, 13 (MSB) */
  1275. REG_WRITE(ah, 0xa3dc,
  1276. POW_SM(pPwrArray[ALL_TARGET_HT40_13], 24) |
  1277. POW_SM(pPwrArray[ALL_TARGET_HT40_12], 16) |
  1278. POW_SM(pPwrArray[ALL_TARGET_HT40_7], 8) |
  1279. POW_SM(pPwrArray[ALL_TARGET_HT40_6], 0)
  1280. );
  1281. /* 14 (LSB), 15, 20, 21 */
  1282. REG_WRITE(ah, 0xa3ec,
  1283. POW_SM(pPwrArray[ALL_TARGET_HT40_21], 24) |
  1284. POW_SM(pPwrArray[ALL_TARGET_HT40_20], 16) |
  1285. POW_SM(pPwrArray[ALL_TARGET_HT40_15], 8) |
  1286. POW_SM(pPwrArray[ALL_TARGET_HT40_14], 0)
  1287. );
  1288. return 0;
  1289. #undef POW_SM
  1290. }
  1291. static void ar9003_hw_set_target_power_eeprom(struct ath_hw *ah, u16 freq)
  1292. {
  1293. u8 targetPowerValT2[ar9300RateSize];
  1294. /* XXX: hard code for now, need to get from eeprom struct */
  1295. u8 ht40PowerIncForPdadc = 0;
  1296. bool is2GHz = false;
  1297. unsigned int i = 0;
  1298. struct ath_common *common = ath9k_hw_common(ah);
  1299. if (freq < 4000)
  1300. is2GHz = true;
  1301. targetPowerValT2[ALL_TARGET_LEGACY_6_24] =
  1302. ar9003_hw_eeprom_get_tgt_pwr(ah, LEGACY_TARGET_RATE_6_24, freq,
  1303. is2GHz);
  1304. targetPowerValT2[ALL_TARGET_LEGACY_36] =
  1305. ar9003_hw_eeprom_get_tgt_pwr(ah, LEGACY_TARGET_RATE_36, freq,
  1306. is2GHz);
  1307. targetPowerValT2[ALL_TARGET_LEGACY_48] =
  1308. ar9003_hw_eeprom_get_tgt_pwr(ah, LEGACY_TARGET_RATE_48, freq,
  1309. is2GHz);
  1310. targetPowerValT2[ALL_TARGET_LEGACY_54] =
  1311. ar9003_hw_eeprom_get_tgt_pwr(ah, LEGACY_TARGET_RATE_54, freq,
  1312. is2GHz);
  1313. targetPowerValT2[ALL_TARGET_LEGACY_1L_5L] =
  1314. ar9003_hw_eeprom_get_cck_tgt_pwr(ah, LEGACY_TARGET_RATE_1L_5L,
  1315. freq);
  1316. targetPowerValT2[ALL_TARGET_LEGACY_5S] =
  1317. ar9003_hw_eeprom_get_cck_tgt_pwr(ah, LEGACY_TARGET_RATE_5S, freq);
  1318. targetPowerValT2[ALL_TARGET_LEGACY_11L] =
  1319. ar9003_hw_eeprom_get_cck_tgt_pwr(ah, LEGACY_TARGET_RATE_11L, freq);
  1320. targetPowerValT2[ALL_TARGET_LEGACY_11S] =
  1321. ar9003_hw_eeprom_get_cck_tgt_pwr(ah, LEGACY_TARGET_RATE_11S, freq);
  1322. targetPowerValT2[ALL_TARGET_HT20_0_8_16] =
  1323. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_0_8_16, freq,
  1324. is2GHz);
  1325. targetPowerValT2[ALL_TARGET_HT20_1_3_9_11_17_19] =
  1326. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_1_3_9_11_17_19,
  1327. freq, is2GHz);
  1328. targetPowerValT2[ALL_TARGET_HT20_4] =
  1329. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_4, freq,
  1330. is2GHz);
  1331. targetPowerValT2[ALL_TARGET_HT20_5] =
  1332. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_5, freq,
  1333. is2GHz);
  1334. targetPowerValT2[ALL_TARGET_HT20_6] =
  1335. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_6, freq,
  1336. is2GHz);
  1337. targetPowerValT2[ALL_TARGET_HT20_7] =
  1338. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_7, freq,
  1339. is2GHz);
  1340. targetPowerValT2[ALL_TARGET_HT20_12] =
  1341. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_12, freq,
  1342. is2GHz);
  1343. targetPowerValT2[ALL_TARGET_HT20_13] =
  1344. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_13, freq,
  1345. is2GHz);
  1346. targetPowerValT2[ALL_TARGET_HT20_14] =
  1347. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_14, freq,
  1348. is2GHz);
  1349. targetPowerValT2[ALL_TARGET_HT20_15] =
  1350. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_15, freq,
  1351. is2GHz);
  1352. targetPowerValT2[ALL_TARGET_HT20_20] =
  1353. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_20, freq,
  1354. is2GHz);
  1355. targetPowerValT2[ALL_TARGET_HT20_21] =
  1356. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_21, freq,
  1357. is2GHz);
  1358. targetPowerValT2[ALL_TARGET_HT20_22] =
  1359. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_22, freq,
  1360. is2GHz);
  1361. targetPowerValT2[ALL_TARGET_HT20_23] =
  1362. ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_23, freq,
  1363. is2GHz);
  1364. targetPowerValT2[ALL_TARGET_HT40_0_8_16] =
  1365. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_0_8_16, freq,
  1366. is2GHz) + ht40PowerIncForPdadc;
  1367. targetPowerValT2[ALL_TARGET_HT40_1_3_9_11_17_19] =
  1368. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_1_3_9_11_17_19,
  1369. freq,
  1370. is2GHz) + ht40PowerIncForPdadc;
  1371. targetPowerValT2[ALL_TARGET_HT40_4] =
  1372. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_4, freq,
  1373. is2GHz) + ht40PowerIncForPdadc;
  1374. targetPowerValT2[ALL_TARGET_HT40_5] =
  1375. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_5, freq,
  1376. is2GHz) + ht40PowerIncForPdadc;
  1377. targetPowerValT2[ALL_TARGET_HT40_6] =
  1378. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_6, freq,
  1379. is2GHz) + ht40PowerIncForPdadc;
  1380. targetPowerValT2[ALL_TARGET_HT40_7] =
  1381. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_7, freq,
  1382. is2GHz) + ht40PowerIncForPdadc;
  1383. targetPowerValT2[ALL_TARGET_HT40_12] =
  1384. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_12, freq,
  1385. is2GHz) + ht40PowerIncForPdadc;
  1386. targetPowerValT2[ALL_TARGET_HT40_13] =
  1387. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_13, freq,
  1388. is2GHz) + ht40PowerIncForPdadc;
  1389. targetPowerValT2[ALL_TARGET_HT40_14] =
  1390. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_14, freq,
  1391. is2GHz) + ht40PowerIncForPdadc;
  1392. targetPowerValT2[ALL_TARGET_HT40_15] =
  1393. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_15, freq,
  1394. is2GHz) + ht40PowerIncForPdadc;
  1395. targetPowerValT2[ALL_TARGET_HT40_20] =
  1396. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_20, freq,
  1397. is2GHz) + ht40PowerIncForPdadc;
  1398. targetPowerValT2[ALL_TARGET_HT40_21] =
  1399. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_21, freq,
  1400. is2GHz) + ht40PowerIncForPdadc;
  1401. targetPowerValT2[ALL_TARGET_HT40_22] =
  1402. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_22, freq,
  1403. is2GHz) + ht40PowerIncForPdadc;
  1404. targetPowerValT2[ALL_TARGET_HT40_23] =
  1405. ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_23, freq,
  1406. is2GHz) + ht40PowerIncForPdadc;
  1407. while (i < ar9300RateSize) {
  1408. ath_print(common, ATH_DBG_EEPROM,
  1409. "TPC[%02d] 0x%08x ", i, targetPowerValT2[i]);
  1410. i++;
  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\n", i, targetPowerValT2[i]);
  1419. i++;
  1420. }
  1421. /* Write target power array to registers */
  1422. ar9003_hw_tx_power_regwrite(ah, targetPowerValT2);
  1423. }
  1424. static int ar9003_hw_cal_pier_get(struct ath_hw *ah,
  1425. int mode,
  1426. int ipier,
  1427. int ichain,
  1428. int *pfrequency,
  1429. int *pcorrection,
  1430. int *ptemperature, int *pvoltage)
  1431. {
  1432. u8 *pCalPier;
  1433. struct ar9300_cal_data_per_freq_op_loop *pCalPierStruct;
  1434. int is2GHz;
  1435. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1436. struct ath_common *common = ath9k_hw_common(ah);
  1437. if (ichain >= AR9300_MAX_CHAINS) {
  1438. ath_print(common, ATH_DBG_EEPROM,
  1439. "Invalid chain index, must be less than %d\n",
  1440. AR9300_MAX_CHAINS);
  1441. return -1;
  1442. }
  1443. if (mode) { /* 5GHz */
  1444. if (ipier >= AR9300_NUM_5G_CAL_PIERS) {
  1445. ath_print(common, ATH_DBG_EEPROM,
  1446. "Invalid 5GHz cal pier index, must "
  1447. "be less than %d\n",
  1448. AR9300_NUM_5G_CAL_PIERS);
  1449. return -1;
  1450. }
  1451. pCalPier = &(eep->calFreqPier5G[ipier]);
  1452. pCalPierStruct = &(eep->calPierData5G[ichain][ipier]);
  1453. is2GHz = 0;
  1454. } else {
  1455. if (ipier >= AR9300_NUM_2G_CAL_PIERS) {
  1456. ath_print(common, ATH_DBG_EEPROM,
  1457. "Invalid 2GHz cal pier index, must "
  1458. "be less than %d\n", AR9300_NUM_2G_CAL_PIERS);
  1459. return -1;
  1460. }
  1461. pCalPier = &(eep->calFreqPier2G[ipier]);
  1462. pCalPierStruct = &(eep->calPierData2G[ichain][ipier]);
  1463. is2GHz = 1;
  1464. }
  1465. *pfrequency = FBIN2FREQ(*pCalPier, is2GHz);
  1466. *pcorrection = pCalPierStruct->refPower;
  1467. *ptemperature = pCalPierStruct->tempMeas;
  1468. *pvoltage = pCalPierStruct->voltMeas;
  1469. return 0;
  1470. }
  1471. static int ar9003_hw_power_control_override(struct ath_hw *ah,
  1472. int frequency,
  1473. int *correction,
  1474. int *voltage, int *temperature)
  1475. {
  1476. int tempSlope = 0;
  1477. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1478. REG_RMW(ah, AR_PHY_TPC_11_B0,
  1479. (correction[0] << AR_PHY_TPC_OLPC_GAIN_DELTA_S),
  1480. AR_PHY_TPC_OLPC_GAIN_DELTA);
  1481. REG_RMW(ah, AR_PHY_TPC_11_B1,
  1482. (correction[1] << AR_PHY_TPC_OLPC_GAIN_DELTA_S),
  1483. AR_PHY_TPC_OLPC_GAIN_DELTA);
  1484. REG_RMW(ah, AR_PHY_TPC_11_B2,
  1485. (correction[2] << AR_PHY_TPC_OLPC_GAIN_DELTA_S),
  1486. AR_PHY_TPC_OLPC_GAIN_DELTA);
  1487. /* enable open loop power control on chip */
  1488. REG_RMW(ah, AR_PHY_TPC_6_B0,
  1489. (3 << AR_PHY_TPC_6_ERROR_EST_MODE_S),
  1490. AR_PHY_TPC_6_ERROR_EST_MODE);
  1491. REG_RMW(ah, AR_PHY_TPC_6_B1,
  1492. (3 << AR_PHY_TPC_6_ERROR_EST_MODE_S),
  1493. AR_PHY_TPC_6_ERROR_EST_MODE);
  1494. REG_RMW(ah, AR_PHY_TPC_6_B2,
  1495. (3 << AR_PHY_TPC_6_ERROR_EST_MODE_S),
  1496. AR_PHY_TPC_6_ERROR_EST_MODE);
  1497. /*
  1498. * enable temperature compensation
  1499. * Need to use register names
  1500. */
  1501. if (frequency < 4000)
  1502. tempSlope = eep->modalHeader2G.tempSlope;
  1503. else
  1504. tempSlope = eep->modalHeader5G.tempSlope;
  1505. REG_RMW_FIELD(ah, AR_PHY_TPC_19, AR_PHY_TPC_19_ALPHA_THERM, tempSlope);
  1506. REG_RMW_FIELD(ah, AR_PHY_TPC_18, AR_PHY_TPC_18_THERM_CAL_VALUE,
  1507. temperature[0]);
  1508. return 0;
  1509. }
  1510. /* Apply the recorded correction values. */
  1511. static int ar9003_hw_calibration_apply(struct ath_hw *ah, int frequency)
  1512. {
  1513. int ichain, ipier, npier;
  1514. int mode;
  1515. int lfrequency[AR9300_MAX_CHAINS],
  1516. lcorrection[AR9300_MAX_CHAINS],
  1517. ltemperature[AR9300_MAX_CHAINS], lvoltage[AR9300_MAX_CHAINS];
  1518. int hfrequency[AR9300_MAX_CHAINS],
  1519. hcorrection[AR9300_MAX_CHAINS],
  1520. htemperature[AR9300_MAX_CHAINS], hvoltage[AR9300_MAX_CHAINS];
  1521. int fdiff;
  1522. int correction[AR9300_MAX_CHAINS],
  1523. voltage[AR9300_MAX_CHAINS], temperature[AR9300_MAX_CHAINS];
  1524. int pfrequency, pcorrection, ptemperature, pvoltage;
  1525. struct ath_common *common = ath9k_hw_common(ah);
  1526. mode = (frequency >= 4000);
  1527. if (mode)
  1528. npier = AR9300_NUM_5G_CAL_PIERS;
  1529. else
  1530. npier = AR9300_NUM_2G_CAL_PIERS;
  1531. for (ichain = 0; ichain < AR9300_MAX_CHAINS; ichain++) {
  1532. lfrequency[ichain] = 0;
  1533. hfrequency[ichain] = 100000;
  1534. }
  1535. /* identify best lower and higher frequency calibration measurement */
  1536. for (ichain = 0; ichain < AR9300_MAX_CHAINS; ichain++) {
  1537. for (ipier = 0; ipier < npier; ipier++) {
  1538. if (!ar9003_hw_cal_pier_get(ah, mode, ipier, ichain,
  1539. &pfrequency, &pcorrection,
  1540. &ptemperature, &pvoltage)) {
  1541. fdiff = frequency - pfrequency;
  1542. /*
  1543. * this measurement is higher than
  1544. * our desired frequency
  1545. */
  1546. if (fdiff <= 0) {
  1547. if (hfrequency[ichain] <= 0 ||
  1548. hfrequency[ichain] >= 100000 ||
  1549. fdiff >
  1550. (frequency - hfrequency[ichain])) {
  1551. /*
  1552. * new best higher
  1553. * frequency measurement
  1554. */
  1555. hfrequency[ichain] = pfrequency;
  1556. hcorrection[ichain] =
  1557. pcorrection;
  1558. htemperature[ichain] =
  1559. ptemperature;
  1560. hvoltage[ichain] = pvoltage;
  1561. }
  1562. }
  1563. if (fdiff >= 0) {
  1564. if (lfrequency[ichain] <= 0
  1565. || fdiff <
  1566. (frequency - lfrequency[ichain])) {
  1567. /*
  1568. * new best lower
  1569. * frequency measurement
  1570. */
  1571. lfrequency[ichain] = pfrequency;
  1572. lcorrection[ichain] =
  1573. pcorrection;
  1574. ltemperature[ichain] =
  1575. ptemperature;
  1576. lvoltage[ichain] = pvoltage;
  1577. }
  1578. }
  1579. }
  1580. }
  1581. }
  1582. /* interpolate */
  1583. for (ichain = 0; ichain < AR9300_MAX_CHAINS; ichain++) {
  1584. ath_print(common, ATH_DBG_EEPROM,
  1585. "ch=%d f=%d low=%d %d h=%d %d\n",
  1586. ichain, frequency, lfrequency[ichain],
  1587. lcorrection[ichain], hfrequency[ichain],
  1588. hcorrection[ichain]);
  1589. /* they're the same, so just pick one */
  1590. if (hfrequency[ichain] == lfrequency[ichain]) {
  1591. correction[ichain] = lcorrection[ichain];
  1592. voltage[ichain] = lvoltage[ichain];
  1593. temperature[ichain] = ltemperature[ichain];
  1594. }
  1595. /* the low frequency is good */
  1596. else if (frequency - lfrequency[ichain] < 1000) {
  1597. /* so is the high frequency, interpolate */
  1598. if (hfrequency[ichain] - frequency < 1000) {
  1599. correction[ichain] = lcorrection[ichain] +
  1600. (((frequency - lfrequency[ichain]) *
  1601. (hcorrection[ichain] -
  1602. lcorrection[ichain])) /
  1603. (hfrequency[ichain] - lfrequency[ichain]));
  1604. temperature[ichain] = ltemperature[ichain] +
  1605. (((frequency - lfrequency[ichain]) *
  1606. (htemperature[ichain] -
  1607. ltemperature[ichain])) /
  1608. (hfrequency[ichain] - lfrequency[ichain]));
  1609. voltage[ichain] =
  1610. lvoltage[ichain] +
  1611. (((frequency -
  1612. lfrequency[ichain]) * (hvoltage[ichain] -
  1613. lvoltage[ichain]))
  1614. / (hfrequency[ichain] -
  1615. lfrequency[ichain]));
  1616. }
  1617. /* only low is good, use it */
  1618. else {
  1619. correction[ichain] = lcorrection[ichain];
  1620. temperature[ichain] = ltemperature[ichain];
  1621. voltage[ichain] = lvoltage[ichain];
  1622. }
  1623. }
  1624. /* only high is good, use it */
  1625. else if (hfrequency[ichain] - frequency < 1000) {
  1626. correction[ichain] = hcorrection[ichain];
  1627. temperature[ichain] = htemperature[ichain];
  1628. voltage[ichain] = hvoltage[ichain];
  1629. } else { /* nothing is good, presume 0???? */
  1630. correction[ichain] = 0;
  1631. temperature[ichain] = 0;
  1632. voltage[ichain] = 0;
  1633. }
  1634. }
  1635. ar9003_hw_power_control_override(ah, frequency, correction, voltage,
  1636. temperature);
  1637. ath_print(common, ATH_DBG_EEPROM,
  1638. "for frequency=%d, calibration correction = %d %d %d\n",
  1639. frequency, correction[0], correction[1], correction[2]);
  1640. return 0;
  1641. }
  1642. static void ath9k_hw_ar9300_set_txpower(struct ath_hw *ah,
  1643. struct ath9k_channel *chan, u16 cfgCtl,
  1644. u8 twiceAntennaReduction,
  1645. u8 twiceMaxRegulatoryPower,
  1646. u8 powerLimit)
  1647. {
  1648. ah->txpower_limit = powerLimit;
  1649. ar9003_hw_set_target_power_eeprom(ah, chan->channel);
  1650. ar9003_hw_calibration_apply(ah, chan->channel);
  1651. }
  1652. static u16 ath9k_hw_ar9300_get_spur_channel(struct ath_hw *ah,
  1653. u16 i, bool is2GHz)
  1654. {
  1655. return AR_NO_SPUR;
  1656. }
  1657. s32 ar9003_hw_get_tx_gain_idx(struct ath_hw *ah)
  1658. {
  1659. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1660. return (eep->baseEepHeader.txrxgain >> 4) & 0xf; /* bits 7:4 */
  1661. }
  1662. s32 ar9003_hw_get_rx_gain_idx(struct ath_hw *ah)
  1663. {
  1664. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  1665. return (eep->baseEepHeader.txrxgain) & 0xf; /* bits 3:0 */
  1666. }
  1667. const struct eeprom_ops eep_ar9300_ops = {
  1668. .check_eeprom = ath9k_hw_ar9300_check_eeprom,
  1669. .get_eeprom = ath9k_hw_ar9300_get_eeprom,
  1670. .fill_eeprom = ath9k_hw_ar9300_fill_eeprom,
  1671. .get_eeprom_ver = ath9k_hw_ar9300_get_eeprom_ver,
  1672. .get_eeprom_rev = ath9k_hw_ar9300_get_eeprom_rev,
  1673. .get_num_ant_config = ath9k_hw_ar9300_get_num_ant_config,
  1674. .get_eeprom_antenna_cfg = ath9k_hw_ar9300_get_eeprom_antenna_cfg,
  1675. .set_board_values = ath9k_hw_ar9300_set_board_values,
  1676. .set_addac = ath9k_hw_ar9300_set_addac,
  1677. .set_txpower = ath9k_hw_ar9300_set_txpower,
  1678. .get_spur_channel = ath9k_hw_ar9300_get_spur_channel
  1679. };