ar9003_eeprom.c 52 KB

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