ar9003_eeprom.c 63 KB

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