phy_cmn.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  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 ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/delay.h>
  18. #include <linux/bitops.h>
  19. #include <brcm_hw_ids.h>
  20. #include <chipcommon.h>
  21. #include <aiutils.h>
  22. #include <d11.h>
  23. #include <phy_shim.h>
  24. #include "phy_hal.h"
  25. #include "phy_int.h"
  26. #include "phy_radio.h"
  27. #include "phy_lcn.h"
  28. #include "phyreg_n.h"
  29. #define VALID_N_RADIO(radioid) ((radioid == BCM2055_ID) || \
  30. (radioid == BCM2056_ID) || \
  31. (radioid == BCM2057_ID))
  32. #define VALID_LCN_RADIO(radioid) (radioid == BCM2064_ID)
  33. #define VALID_RADIO(pi, radioid) ( \
  34. (ISNPHY(pi) ? VALID_N_RADIO(radioid) : false) || \
  35. (ISLCNPHY(pi) ? VALID_LCN_RADIO(radioid) : false))
  36. /* basic mux operation - can be optimized on several architectures */
  37. #define MUX(pred, true, false) ((pred) ? (true) : (false))
  38. /* modulo inc/dec - assumes x E [0, bound - 1] */
  39. #define MODINC(x, bound) MUX((x) == (bound) - 1, 0, (x) + 1)
  40. /* modulo inc/dec, bound = 2^k */
  41. #define MODDEC_POW2(x, bound) (((x) - 1) & ((bound) - 1))
  42. #define MODINC_POW2(x, bound) (((x) + 1) & ((bound) - 1))
  43. struct chan_info_basic {
  44. u16 chan;
  45. u16 freq;
  46. };
  47. static const struct chan_info_basic chan_info_all[] = {
  48. {1, 2412},
  49. {2, 2417},
  50. {3, 2422},
  51. {4, 2427},
  52. {5, 2432},
  53. {6, 2437},
  54. {7, 2442},
  55. {8, 2447},
  56. {9, 2452},
  57. {10, 2457},
  58. {11, 2462},
  59. {12, 2467},
  60. {13, 2472},
  61. {14, 2484},
  62. {34, 5170},
  63. {38, 5190},
  64. {42, 5210},
  65. {46, 5230},
  66. {36, 5180},
  67. {40, 5200},
  68. {44, 5220},
  69. {48, 5240},
  70. {52, 5260},
  71. {56, 5280},
  72. {60, 5300},
  73. {64, 5320},
  74. {100, 5500},
  75. {104, 5520},
  76. {108, 5540},
  77. {112, 5560},
  78. {116, 5580},
  79. {120, 5600},
  80. {124, 5620},
  81. {128, 5640},
  82. {132, 5660},
  83. {136, 5680},
  84. {140, 5700},
  85. {149, 5745},
  86. {153, 5765},
  87. {157, 5785},
  88. {161, 5805},
  89. {165, 5825},
  90. {184, 4920},
  91. {188, 4940},
  92. {192, 4960},
  93. {196, 4980},
  94. {200, 5000},
  95. {204, 5020},
  96. {208, 5040},
  97. {212, 5060},
  98. {216, 5080}
  99. };
  100. static const u8 ofdm_rate_lookup[] = {
  101. BRCM_RATE_48M,
  102. BRCM_RATE_24M,
  103. BRCM_RATE_12M,
  104. BRCM_RATE_6M,
  105. BRCM_RATE_54M,
  106. BRCM_RATE_36M,
  107. BRCM_RATE_18M,
  108. BRCM_RATE_9M
  109. };
  110. #define PHY_WREG_LIMIT 24
  111. void wlc_phyreg_enter(struct brcms_phy_pub *pih)
  112. {
  113. struct brcms_phy *pi = (struct brcms_phy *) pih;
  114. wlapi_bmac_ucode_wake_override_phyreg_set(pi->sh->physhim);
  115. }
  116. void wlc_phyreg_exit(struct brcms_phy_pub *pih)
  117. {
  118. struct brcms_phy *pi = (struct brcms_phy *) pih;
  119. wlapi_bmac_ucode_wake_override_phyreg_clear(pi->sh->physhim);
  120. }
  121. void wlc_radioreg_enter(struct brcms_phy_pub *pih)
  122. {
  123. struct brcms_phy *pi = (struct brcms_phy *) pih;
  124. wlapi_bmac_mctrl(pi->sh->physhim, MCTL_LOCK_RADIO, MCTL_LOCK_RADIO);
  125. udelay(10);
  126. }
  127. void wlc_radioreg_exit(struct brcms_phy_pub *pih)
  128. {
  129. struct brcms_phy *pi = (struct brcms_phy *) pih;
  130. (void)bcma_read16(pi->d11core, D11REGOFFS(phyversion));
  131. pi->phy_wreg = 0;
  132. wlapi_bmac_mctrl(pi->sh->physhim, MCTL_LOCK_RADIO, 0);
  133. }
  134. u16 read_radio_reg(struct brcms_phy *pi, u16 addr)
  135. {
  136. u16 data;
  137. if ((addr == RADIO_IDCODE))
  138. return 0xffff;
  139. switch (pi->pubpi.phy_type) {
  140. case PHY_TYPE_N:
  141. if (!CONF_HAS(PHYTYPE, PHY_TYPE_N))
  142. break;
  143. if (NREV_GE(pi->pubpi.phy_rev, 7))
  144. addr |= RADIO_2057_READ_OFF;
  145. else
  146. addr |= RADIO_2055_READ_OFF;
  147. break;
  148. case PHY_TYPE_LCN:
  149. if (!CONF_HAS(PHYTYPE, PHY_TYPE_LCN))
  150. break;
  151. addr |= RADIO_2064_READ_OFF;
  152. break;
  153. default:
  154. break;
  155. }
  156. if ((D11REV_GE(pi->sh->corerev, 24)) ||
  157. (D11REV_IS(pi->sh->corerev, 22)
  158. && (pi->pubpi.phy_type != PHY_TYPE_SSN))) {
  159. bcma_wflush16(pi->d11core, D11REGOFFS(radioregaddr), addr);
  160. data = bcma_read16(pi->d11core, D11REGOFFS(radioregdata));
  161. } else {
  162. bcma_wflush16(pi->d11core, D11REGOFFS(phy4waddr), addr);
  163. data = bcma_read16(pi->d11core, D11REGOFFS(phy4wdatalo));
  164. }
  165. pi->phy_wreg = 0;
  166. return data;
  167. }
  168. void write_radio_reg(struct brcms_phy *pi, u16 addr, u16 val)
  169. {
  170. if ((D11REV_GE(pi->sh->corerev, 24)) ||
  171. (D11REV_IS(pi->sh->corerev, 22)
  172. && (pi->pubpi.phy_type != PHY_TYPE_SSN))) {
  173. bcma_wflush16(pi->d11core, D11REGOFFS(radioregaddr), addr);
  174. bcma_write16(pi->d11core, D11REGOFFS(radioregdata), val);
  175. } else {
  176. bcma_wflush16(pi->d11core, D11REGOFFS(phy4waddr), addr);
  177. bcma_write16(pi->d11core, D11REGOFFS(phy4wdatalo), val);
  178. }
  179. if (++pi->phy_wreg >= pi->phy_wreg_limit) {
  180. (void)bcma_read32(pi->d11core, D11REGOFFS(maccontrol));
  181. pi->phy_wreg = 0;
  182. }
  183. }
  184. static u32 read_radio_id(struct brcms_phy *pi)
  185. {
  186. u32 id;
  187. if (D11REV_GE(pi->sh->corerev, 24)) {
  188. u32 b0, b1, b2;
  189. bcma_wflush16(pi->d11core, D11REGOFFS(radioregaddr), 0);
  190. b0 = (u32) bcma_read16(pi->d11core, D11REGOFFS(radioregdata));
  191. bcma_wflush16(pi->d11core, D11REGOFFS(radioregaddr), 1);
  192. b1 = (u32) bcma_read16(pi->d11core, D11REGOFFS(radioregdata));
  193. bcma_wflush16(pi->d11core, D11REGOFFS(radioregaddr), 2);
  194. b2 = (u32) bcma_read16(pi->d11core, D11REGOFFS(radioregdata));
  195. id = ((b0 & 0xf) << 28) | (((b2 << 8) | b1) << 12) | ((b0 >> 4)
  196. & 0xf);
  197. } else {
  198. bcma_wflush16(pi->d11core, D11REGOFFS(phy4waddr), RADIO_IDCODE);
  199. id = (u32) bcma_read16(pi->d11core, D11REGOFFS(phy4wdatalo));
  200. id |= (u32) bcma_read16(pi->d11core,
  201. D11REGOFFS(phy4wdatahi)) << 16;
  202. }
  203. pi->phy_wreg = 0;
  204. return id;
  205. }
  206. void and_radio_reg(struct brcms_phy *pi, u16 addr, u16 val)
  207. {
  208. u16 rval;
  209. rval = read_radio_reg(pi, addr);
  210. write_radio_reg(pi, addr, (rval & val));
  211. }
  212. void or_radio_reg(struct brcms_phy *pi, u16 addr, u16 val)
  213. {
  214. u16 rval;
  215. rval = read_radio_reg(pi, addr);
  216. write_radio_reg(pi, addr, (rval | val));
  217. }
  218. void xor_radio_reg(struct brcms_phy *pi, u16 addr, u16 mask)
  219. {
  220. u16 rval;
  221. rval = read_radio_reg(pi, addr);
  222. write_radio_reg(pi, addr, (rval ^ mask));
  223. }
  224. void mod_radio_reg(struct brcms_phy *pi, u16 addr, u16 mask, u16 val)
  225. {
  226. u16 rval;
  227. rval = read_radio_reg(pi, addr);
  228. write_radio_reg(pi, addr, (rval & ~mask) | (val & mask));
  229. }
  230. void write_phy_channel_reg(struct brcms_phy *pi, uint val)
  231. {
  232. bcma_write16(pi->d11core, D11REGOFFS(phychannel), val);
  233. }
  234. u16 read_phy_reg(struct brcms_phy *pi, u16 addr)
  235. {
  236. bcma_wflush16(pi->d11core, D11REGOFFS(phyregaddr), addr);
  237. pi->phy_wreg = 0;
  238. return bcma_read16(pi->d11core, D11REGOFFS(phyregdata));
  239. }
  240. void write_phy_reg(struct brcms_phy *pi, u16 addr, u16 val)
  241. {
  242. #ifdef CONFIG_BCM47XX
  243. bcma_wflush16(pi->d11core, D11REGOFFS(phyregaddr), addr);
  244. bcma_write16(pi->d11core, D11REGOFFS(phyregdata), val);
  245. if (addr == 0x72)
  246. (void)bcma_read16(pi->d11core, D11REGOFFS(phyversion));
  247. #else
  248. bcma_write32(pi->d11core, D11REGOFFS(phyregaddr), addr | (val << 16));
  249. if (++pi->phy_wreg >= pi->phy_wreg_limit) {
  250. pi->phy_wreg = 0;
  251. (void)bcma_read16(pi->d11core, D11REGOFFS(phyversion));
  252. }
  253. #endif
  254. }
  255. void and_phy_reg(struct brcms_phy *pi, u16 addr, u16 val)
  256. {
  257. bcma_wflush16(pi->d11core, D11REGOFFS(phyregaddr), addr);
  258. bcma_mask16(pi->d11core, D11REGOFFS(phyregdata), val);
  259. pi->phy_wreg = 0;
  260. }
  261. void or_phy_reg(struct brcms_phy *pi, u16 addr, u16 val)
  262. {
  263. bcma_wflush16(pi->d11core, D11REGOFFS(phyregaddr), addr);
  264. bcma_set16(pi->d11core, D11REGOFFS(phyregdata), val);
  265. pi->phy_wreg = 0;
  266. }
  267. void mod_phy_reg(struct brcms_phy *pi, u16 addr, u16 mask, u16 val)
  268. {
  269. val &= mask;
  270. bcma_wflush16(pi->d11core, D11REGOFFS(phyregaddr), addr);
  271. bcma_maskset16(pi->d11core, D11REGOFFS(phyregdata), ~mask, val);
  272. pi->phy_wreg = 0;
  273. }
  274. static void wlc_set_phy_uninitted(struct brcms_phy *pi)
  275. {
  276. int i, j;
  277. pi->initialized = false;
  278. pi->tx_vos = 0xffff;
  279. pi->nrssi_table_delta = 0x7fffffff;
  280. pi->rc_cal = 0xffff;
  281. pi->mintxbias = 0xffff;
  282. pi->txpwridx = -1;
  283. if (ISNPHY(pi)) {
  284. pi->phy_spuravoid = SPURAVOID_DISABLE;
  285. if (NREV_GE(pi->pubpi.phy_rev, 3)
  286. && NREV_LT(pi->pubpi.phy_rev, 7))
  287. pi->phy_spuravoid = SPURAVOID_AUTO;
  288. pi->nphy_papd_skip = 0;
  289. pi->nphy_papd_epsilon_offset[0] = 0xf588;
  290. pi->nphy_papd_epsilon_offset[1] = 0xf588;
  291. pi->nphy_txpwr_idx[0] = 128;
  292. pi->nphy_txpwr_idx[1] = 128;
  293. pi->nphy_txpwrindex[0].index_internal = 40;
  294. pi->nphy_txpwrindex[1].index_internal = 40;
  295. pi->phy_pabias = 0;
  296. } else {
  297. pi->phy_spuravoid = SPURAVOID_AUTO;
  298. }
  299. pi->radiopwr = 0xffff;
  300. for (i = 0; i < STATIC_NUM_RF; i++) {
  301. for (j = 0; j < STATIC_NUM_BB; j++)
  302. pi->stats_11b_txpower[i][j] = -1;
  303. }
  304. }
  305. struct shared_phy *wlc_phy_shared_attach(struct shared_phy_params *shp)
  306. {
  307. struct shared_phy *sh;
  308. sh = kzalloc(sizeof(struct shared_phy), GFP_ATOMIC);
  309. if (sh == NULL)
  310. return NULL;
  311. sh->sih = shp->sih;
  312. sh->physhim = shp->physhim;
  313. sh->unit = shp->unit;
  314. sh->corerev = shp->corerev;
  315. sh->vid = shp->vid;
  316. sh->did = shp->did;
  317. sh->chip = shp->chip;
  318. sh->chiprev = shp->chiprev;
  319. sh->chippkg = shp->chippkg;
  320. sh->sromrev = shp->sromrev;
  321. sh->boardtype = shp->boardtype;
  322. sh->boardrev = shp->boardrev;
  323. sh->boardflags = shp->boardflags;
  324. sh->boardflags2 = shp->boardflags2;
  325. sh->fast_timer = PHY_SW_TIMER_FAST;
  326. sh->slow_timer = PHY_SW_TIMER_SLOW;
  327. sh->glacial_timer = PHY_SW_TIMER_GLACIAL;
  328. sh->rssi_mode = RSSI_ANT_MERGE_MAX;
  329. return sh;
  330. }
  331. static void wlc_phy_timercb_phycal(struct brcms_phy *pi)
  332. {
  333. uint delay = 5;
  334. if (PHY_PERICAL_MPHASE_PENDING(pi)) {
  335. if (!pi->sh->up) {
  336. wlc_phy_cal_perical_mphase_reset(pi);
  337. return;
  338. }
  339. if (SCAN_RM_IN_PROGRESS(pi) || PLT_INPROG_PHY(pi)) {
  340. delay = 1000;
  341. wlc_phy_cal_perical_mphase_restart(pi);
  342. } else
  343. wlc_phy_cal_perical_nphy_run(pi, PHY_PERICAL_AUTO);
  344. wlapi_add_timer(pi->phycal_timer, delay, 0);
  345. return;
  346. }
  347. }
  348. static u32 wlc_phy_get_radio_ver(struct brcms_phy *pi)
  349. {
  350. u32 ver;
  351. ver = read_radio_id(pi);
  352. return ver;
  353. }
  354. struct brcms_phy_pub *
  355. wlc_phy_attach(struct shared_phy *sh, struct bcma_device *d11core,
  356. int bandtype, struct wiphy *wiphy)
  357. {
  358. struct brcms_phy *pi;
  359. u32 sflags = 0;
  360. uint phyversion;
  361. u32 idcode;
  362. int i;
  363. if (D11REV_IS(sh->corerev, 4))
  364. sflags = SISF_2G_PHY | SISF_5G_PHY;
  365. else
  366. sflags = bcma_aread32(d11core, BCMA_IOST);
  367. if (bandtype == BRCM_BAND_5G) {
  368. if ((sflags & (SISF_5G_PHY | SISF_DB_PHY)) == 0)
  369. return NULL;
  370. }
  371. pi = sh->phy_head;
  372. if ((sflags & SISF_DB_PHY) && pi) {
  373. wlapi_bmac_corereset(pi->sh->physhim, pi->pubpi.coreflags);
  374. pi->refcnt++;
  375. return &pi->pubpi_ro;
  376. }
  377. pi = kzalloc(sizeof(struct brcms_phy), GFP_ATOMIC);
  378. if (pi == NULL)
  379. return NULL;
  380. pi->wiphy = wiphy;
  381. pi->d11core = d11core;
  382. pi->sh = sh;
  383. pi->phy_init_por = true;
  384. pi->phy_wreg_limit = PHY_WREG_LIMIT;
  385. pi->txpwr_percent = 100;
  386. pi->do_initcal = true;
  387. pi->phycal_tempdelta = 0;
  388. if (bandtype == BRCM_BAND_2G && (sflags & SISF_2G_PHY))
  389. pi->pubpi.coreflags = SICF_GMODE;
  390. wlapi_bmac_corereset(pi->sh->physhim, pi->pubpi.coreflags);
  391. phyversion = bcma_read16(pi->d11core, D11REGOFFS(phyversion));
  392. pi->pubpi.phy_type = PHY_TYPE(phyversion);
  393. pi->pubpi.phy_rev = phyversion & PV_PV_MASK;
  394. if (pi->pubpi.phy_type == PHY_TYPE_LCNXN) {
  395. pi->pubpi.phy_type = PHY_TYPE_N;
  396. pi->pubpi.phy_rev += LCNXN_BASEREV;
  397. }
  398. pi->pubpi.phy_corenum = PHY_CORE_NUM_2;
  399. pi->pubpi.ana_rev = (phyversion & PV_AV_MASK) >> PV_AV_SHIFT;
  400. if (pi->pubpi.phy_type != PHY_TYPE_N &&
  401. pi->pubpi.phy_type != PHY_TYPE_LCN)
  402. goto err;
  403. if (bandtype == BRCM_BAND_5G) {
  404. if (!ISNPHY(pi))
  405. goto err;
  406. } else if (!ISNPHY(pi) && !ISLCNPHY(pi)) {
  407. goto err;
  408. }
  409. wlc_phy_anacore((struct brcms_phy_pub *) pi, ON);
  410. idcode = wlc_phy_get_radio_ver(pi);
  411. pi->pubpi.radioid =
  412. (idcode & IDCODE_ID_MASK) >> IDCODE_ID_SHIFT;
  413. pi->pubpi.radiorev =
  414. (idcode & IDCODE_REV_MASK) >> IDCODE_REV_SHIFT;
  415. pi->pubpi.radiover =
  416. (idcode & IDCODE_VER_MASK) >> IDCODE_VER_SHIFT;
  417. if (!VALID_RADIO(pi, pi->pubpi.radioid))
  418. goto err;
  419. wlc_phy_switch_radio((struct brcms_phy_pub *) pi, OFF);
  420. wlc_set_phy_uninitted(pi);
  421. pi->bw = WL_CHANSPEC_BW_20;
  422. pi->radio_chanspec = (bandtype == BRCM_BAND_2G) ?
  423. ch20mhz_chspec(1) : ch20mhz_chspec(36);
  424. pi->rxiq_samps = PHY_NOISE_SAMPLE_LOG_NUM_NPHY;
  425. pi->rxiq_antsel = ANT_RX_DIV_DEF;
  426. pi->watchdog_override = true;
  427. pi->cal_type_override = PHY_PERICAL_AUTO;
  428. pi->nphy_saved_noisevars.bufcount = 0;
  429. if (ISNPHY(pi))
  430. pi->min_txpower = PHY_TXPWR_MIN_NPHY;
  431. else
  432. pi->min_txpower = PHY_TXPWR_MIN;
  433. pi->sh->phyrxchain = 0x3;
  434. pi->rx2tx_biasentry = -1;
  435. pi->phy_txcore_disable_temp = PHY_CHAIN_TX_DISABLE_TEMP;
  436. pi->phy_txcore_enable_temp =
  437. PHY_CHAIN_TX_DISABLE_TEMP - PHY_HYSTERESIS_DELTATEMP;
  438. pi->phy_tempsense_offset = 0;
  439. pi->phy_txcore_heatedup = false;
  440. pi->nphy_lastcal_temp = -50;
  441. pi->phynoise_polling = true;
  442. if (ISNPHY(pi) || ISLCNPHY(pi))
  443. pi->phynoise_polling = false;
  444. for (i = 0; i < TXP_NUM_RATES; i++) {
  445. pi->txpwr_limit[i] = BRCMS_TXPWR_MAX;
  446. pi->txpwr_env_limit[i] = BRCMS_TXPWR_MAX;
  447. pi->tx_user_target[i] = BRCMS_TXPWR_MAX;
  448. }
  449. pi->radiopwr_override = RADIOPWR_OVERRIDE_DEF;
  450. pi->user_txpwr_at_rfport = false;
  451. if (ISNPHY(pi)) {
  452. pi->phycal_timer = wlapi_init_timer(pi->sh->physhim,
  453. wlc_phy_timercb_phycal,
  454. pi, "phycal");
  455. if (!pi->phycal_timer)
  456. goto err;
  457. if (!wlc_phy_attach_nphy(pi))
  458. goto err;
  459. } else if (ISLCNPHY(pi)) {
  460. if (!wlc_phy_attach_lcnphy(pi))
  461. goto err;
  462. }
  463. pi->refcnt++;
  464. pi->next = pi->sh->phy_head;
  465. sh->phy_head = pi;
  466. memcpy(&pi->pubpi_ro, &pi->pubpi, sizeof(struct brcms_phy_pub));
  467. return &pi->pubpi_ro;
  468. err:
  469. kfree(pi);
  470. return NULL;
  471. }
  472. void wlc_phy_detach(struct brcms_phy_pub *pih)
  473. {
  474. struct brcms_phy *pi = (struct brcms_phy *) pih;
  475. if (pih) {
  476. if (--pi->refcnt)
  477. return;
  478. if (pi->phycal_timer) {
  479. wlapi_free_timer(pi->phycal_timer);
  480. pi->phycal_timer = NULL;
  481. }
  482. if (pi->sh->phy_head == pi)
  483. pi->sh->phy_head = pi->next;
  484. else if (pi->sh->phy_head->next == pi)
  485. pi->sh->phy_head->next = NULL;
  486. if (pi->pi_fptr.detach)
  487. (pi->pi_fptr.detach)(pi);
  488. kfree(pi);
  489. }
  490. }
  491. bool
  492. wlc_phy_get_phyversion(struct brcms_phy_pub *pih, u16 *phytype, u16 *phyrev,
  493. u16 *radioid, u16 *radiover)
  494. {
  495. struct brcms_phy *pi = (struct brcms_phy *) pih;
  496. *phytype = (u16) pi->pubpi.phy_type;
  497. *phyrev = (u16) pi->pubpi.phy_rev;
  498. *radioid = pi->pubpi.radioid;
  499. *radiover = pi->pubpi.radiorev;
  500. return true;
  501. }
  502. bool wlc_phy_get_encore(struct brcms_phy_pub *pih)
  503. {
  504. struct brcms_phy *pi = (struct brcms_phy *) pih;
  505. return pi->pubpi.abgphy_encore;
  506. }
  507. u32 wlc_phy_get_coreflags(struct brcms_phy_pub *pih)
  508. {
  509. struct brcms_phy *pi = (struct brcms_phy *) pih;
  510. return pi->pubpi.coreflags;
  511. }
  512. void wlc_phy_anacore(struct brcms_phy_pub *pih, bool on)
  513. {
  514. struct brcms_phy *pi = (struct brcms_phy *) pih;
  515. if (ISNPHY(pi)) {
  516. if (on) {
  517. if (NREV_GE(pi->pubpi.phy_rev, 3)) {
  518. write_phy_reg(pi, 0xa6, 0x0d);
  519. write_phy_reg(pi, 0x8f, 0x0);
  520. write_phy_reg(pi, 0xa7, 0x0d);
  521. write_phy_reg(pi, 0xa5, 0x0);
  522. } else {
  523. write_phy_reg(pi, 0xa5, 0x0);
  524. }
  525. } else {
  526. if (NREV_GE(pi->pubpi.phy_rev, 3)) {
  527. write_phy_reg(pi, 0x8f, 0x07ff);
  528. write_phy_reg(pi, 0xa6, 0x0fd);
  529. write_phy_reg(pi, 0xa5, 0x07ff);
  530. write_phy_reg(pi, 0xa7, 0x0fd);
  531. } else {
  532. write_phy_reg(pi, 0xa5, 0x7fff);
  533. }
  534. }
  535. } else if (ISLCNPHY(pi)) {
  536. if (on) {
  537. and_phy_reg(pi, 0x43b,
  538. ~((0x1 << 0) | (0x1 << 1) | (0x1 << 2)));
  539. } else {
  540. or_phy_reg(pi, 0x43c,
  541. (0x1 << 0) | (0x1 << 1) | (0x1 << 2));
  542. or_phy_reg(pi, 0x43b,
  543. (0x1 << 0) | (0x1 << 1) | (0x1 << 2));
  544. }
  545. }
  546. }
  547. u32 wlc_phy_clk_bwbits(struct brcms_phy_pub *pih)
  548. {
  549. struct brcms_phy *pi = (struct brcms_phy *) pih;
  550. u32 phy_bw_clkbits = 0;
  551. if (pi && (ISNPHY(pi) || ISLCNPHY(pi))) {
  552. switch (pi->bw) {
  553. case WL_CHANSPEC_BW_10:
  554. phy_bw_clkbits = SICF_BW10;
  555. break;
  556. case WL_CHANSPEC_BW_20:
  557. phy_bw_clkbits = SICF_BW20;
  558. break;
  559. case WL_CHANSPEC_BW_40:
  560. phy_bw_clkbits = SICF_BW40;
  561. break;
  562. default:
  563. break;
  564. }
  565. }
  566. return phy_bw_clkbits;
  567. }
  568. void wlc_phy_por_inform(struct brcms_phy_pub *ppi)
  569. {
  570. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  571. pi->phy_init_por = true;
  572. }
  573. void wlc_phy_edcrs_lock(struct brcms_phy_pub *pih, bool lock)
  574. {
  575. struct brcms_phy *pi = (struct brcms_phy *) pih;
  576. pi->edcrs_threshold_lock = lock;
  577. write_phy_reg(pi, 0x22c, 0x46b);
  578. write_phy_reg(pi, 0x22d, 0x46b);
  579. write_phy_reg(pi, 0x22e, 0x3c0);
  580. write_phy_reg(pi, 0x22f, 0x3c0);
  581. }
  582. void wlc_phy_initcal_enable(struct brcms_phy_pub *pih, bool initcal)
  583. {
  584. struct brcms_phy *pi = (struct brcms_phy *) pih;
  585. pi->do_initcal = initcal;
  586. }
  587. void wlc_phy_hw_clk_state_upd(struct brcms_phy_pub *pih, bool newstate)
  588. {
  589. struct brcms_phy *pi = (struct brcms_phy *) pih;
  590. if (!pi || !pi->sh)
  591. return;
  592. pi->sh->clk = newstate;
  593. }
  594. void wlc_phy_hw_state_upd(struct brcms_phy_pub *pih, bool newstate)
  595. {
  596. struct brcms_phy *pi = (struct brcms_phy *) pih;
  597. if (!pi || !pi->sh)
  598. return;
  599. pi->sh->up = newstate;
  600. }
  601. void wlc_phy_init(struct brcms_phy_pub *pih, u16 chanspec)
  602. {
  603. u32 mc;
  604. void (*phy_init)(struct brcms_phy *) = NULL;
  605. struct brcms_phy *pi = (struct brcms_phy *) pih;
  606. if (pi->init_in_progress)
  607. return;
  608. pi->init_in_progress = true;
  609. pi->radio_chanspec = chanspec;
  610. mc = bcma_read32(pi->d11core, D11REGOFFS(maccontrol));
  611. if (WARN(mc & MCTL_EN_MAC, "HW error MAC running on init"))
  612. return;
  613. if (!(pi->measure_hold & PHY_HOLD_FOR_SCAN))
  614. pi->measure_hold |= PHY_HOLD_FOR_NOT_ASSOC;
  615. if (WARN(!(bcma_aread32(pi->d11core, BCMA_IOST) & SISF_FCLKA),
  616. "HW error SISF_FCLKA\n"))
  617. return;
  618. phy_init = pi->pi_fptr.init;
  619. if (phy_init == NULL)
  620. return;
  621. wlc_phy_anacore(pih, ON);
  622. if (CHSPEC_BW(pi->radio_chanspec) != pi->bw)
  623. wlapi_bmac_bw_set(pi->sh->physhim,
  624. CHSPEC_BW(pi->radio_chanspec));
  625. pi->nphy_gain_boost = true;
  626. wlc_phy_switch_radio((struct brcms_phy_pub *) pi, ON);
  627. (*phy_init)(pi);
  628. pi->phy_init_por = false;
  629. if (D11REV_IS(pi->sh->corerev, 11) || D11REV_IS(pi->sh->corerev, 12))
  630. wlc_phy_do_dummy_tx(pi, true, OFF);
  631. if (!(ISNPHY(pi)))
  632. wlc_phy_txpower_update_shm(pi);
  633. wlc_phy_ant_rxdiv_set((struct brcms_phy_pub *) pi, pi->sh->rx_antdiv);
  634. pi->init_in_progress = false;
  635. }
  636. void wlc_phy_cal_init(struct brcms_phy_pub *pih)
  637. {
  638. struct brcms_phy *pi = (struct brcms_phy *) pih;
  639. void (*cal_init)(struct brcms_phy *) = NULL;
  640. if (WARN((bcma_read32(pi->d11core, D11REGOFFS(maccontrol)) &
  641. MCTL_EN_MAC) != 0, "HW error: MAC enabled during phy cal\n"))
  642. return;
  643. if (!pi->initialized) {
  644. cal_init = pi->pi_fptr.calinit;
  645. if (cal_init)
  646. (*cal_init)(pi);
  647. pi->initialized = true;
  648. }
  649. }
  650. int wlc_phy_down(struct brcms_phy_pub *pih)
  651. {
  652. struct brcms_phy *pi = (struct brcms_phy *) pih;
  653. int callbacks = 0;
  654. if (pi->phycal_timer
  655. && !wlapi_del_timer(pi->phycal_timer))
  656. callbacks++;
  657. pi->nphy_iqcal_chanspec_2G = 0;
  658. pi->nphy_iqcal_chanspec_5G = 0;
  659. return callbacks;
  660. }
  661. void
  662. wlc_phy_table_addr(struct brcms_phy *pi, uint tbl_id, uint tbl_offset,
  663. u16 tblAddr, u16 tblDataHi, u16 tblDataLo)
  664. {
  665. write_phy_reg(pi, tblAddr, (tbl_id << 10) | tbl_offset);
  666. pi->tbl_data_hi = tblDataHi;
  667. pi->tbl_data_lo = tblDataLo;
  668. if (pi->sh->chip == BCM43224_CHIP_ID &&
  669. pi->sh->chiprev == 1) {
  670. pi->tbl_addr = tblAddr;
  671. pi->tbl_save_id = tbl_id;
  672. pi->tbl_save_offset = tbl_offset;
  673. }
  674. }
  675. void wlc_phy_table_data_write(struct brcms_phy *pi, uint width, u32 val)
  676. {
  677. if ((pi->sh->chip == BCM43224_CHIP_ID) &&
  678. (pi->sh->chiprev == 1) &&
  679. (pi->tbl_save_id == NPHY_TBL_ID_ANTSWCTRLLUT)) {
  680. read_phy_reg(pi, pi->tbl_data_lo);
  681. write_phy_reg(pi, pi->tbl_addr,
  682. (pi->tbl_save_id << 10) | pi->tbl_save_offset);
  683. pi->tbl_save_offset++;
  684. }
  685. if (width == 32) {
  686. write_phy_reg(pi, pi->tbl_data_hi, (u16) (val >> 16));
  687. write_phy_reg(pi, pi->tbl_data_lo, (u16) val);
  688. } else {
  689. write_phy_reg(pi, pi->tbl_data_lo, (u16) val);
  690. }
  691. }
  692. void
  693. wlc_phy_write_table(struct brcms_phy *pi, const struct phytbl_info *ptbl_info,
  694. u16 tblAddr, u16 tblDataHi, u16 tblDataLo)
  695. {
  696. uint idx;
  697. uint tbl_id = ptbl_info->tbl_id;
  698. uint tbl_offset = ptbl_info->tbl_offset;
  699. uint tbl_width = ptbl_info->tbl_width;
  700. const u8 *ptbl_8b = (const u8 *)ptbl_info->tbl_ptr;
  701. const u16 *ptbl_16b = (const u16 *)ptbl_info->tbl_ptr;
  702. const u32 *ptbl_32b = (const u32 *)ptbl_info->tbl_ptr;
  703. write_phy_reg(pi, tblAddr, (tbl_id << 10) | tbl_offset);
  704. for (idx = 0; idx < ptbl_info->tbl_len; idx++) {
  705. if ((pi->sh->chip == BCM43224_CHIP_ID) &&
  706. (pi->sh->chiprev == 1) &&
  707. (tbl_id == NPHY_TBL_ID_ANTSWCTRLLUT)) {
  708. read_phy_reg(pi, tblDataLo);
  709. write_phy_reg(pi, tblAddr,
  710. (tbl_id << 10) | (tbl_offset + idx));
  711. }
  712. if (tbl_width == 32) {
  713. write_phy_reg(pi, tblDataHi,
  714. (u16) (ptbl_32b[idx] >> 16));
  715. write_phy_reg(pi, tblDataLo, (u16) ptbl_32b[idx]);
  716. } else if (tbl_width == 16) {
  717. write_phy_reg(pi, tblDataLo, ptbl_16b[idx]);
  718. } else {
  719. write_phy_reg(pi, tblDataLo, ptbl_8b[idx]);
  720. }
  721. }
  722. }
  723. void
  724. wlc_phy_read_table(struct brcms_phy *pi, const struct phytbl_info *ptbl_info,
  725. u16 tblAddr, u16 tblDataHi, u16 tblDataLo)
  726. {
  727. uint idx;
  728. uint tbl_id = ptbl_info->tbl_id;
  729. uint tbl_offset = ptbl_info->tbl_offset;
  730. uint tbl_width = ptbl_info->tbl_width;
  731. u8 *ptbl_8b = (u8 *)ptbl_info->tbl_ptr;
  732. u16 *ptbl_16b = (u16 *)ptbl_info->tbl_ptr;
  733. u32 *ptbl_32b = (u32 *)ptbl_info->tbl_ptr;
  734. write_phy_reg(pi, tblAddr, (tbl_id << 10) | tbl_offset);
  735. for (idx = 0; idx < ptbl_info->tbl_len; idx++) {
  736. if ((pi->sh->chip == BCM43224_CHIP_ID) &&
  737. (pi->sh->chiprev == 1)) {
  738. (void)read_phy_reg(pi, tblDataLo);
  739. write_phy_reg(pi, tblAddr,
  740. (tbl_id << 10) | (tbl_offset + idx));
  741. }
  742. if (tbl_width == 32) {
  743. ptbl_32b[idx] = read_phy_reg(pi, tblDataLo);
  744. ptbl_32b[idx] |= (read_phy_reg(pi, tblDataHi) << 16);
  745. } else if (tbl_width == 16) {
  746. ptbl_16b[idx] = read_phy_reg(pi, tblDataLo);
  747. } else {
  748. ptbl_8b[idx] = (u8) read_phy_reg(pi, tblDataLo);
  749. }
  750. }
  751. }
  752. uint
  753. wlc_phy_init_radio_regs_allbands(struct brcms_phy *pi,
  754. struct radio_20xx_regs *radioregs)
  755. {
  756. uint i = 0;
  757. do {
  758. if (radioregs[i].do_init)
  759. write_radio_reg(pi, radioregs[i].address,
  760. (u16) radioregs[i].init);
  761. i++;
  762. } while (radioregs[i].address != 0xffff);
  763. return i;
  764. }
  765. uint
  766. wlc_phy_init_radio_regs(struct brcms_phy *pi,
  767. const struct radio_regs *radioregs,
  768. u16 core_offset)
  769. {
  770. uint i = 0;
  771. uint count = 0;
  772. do {
  773. if (CHSPEC_IS5G(pi->radio_chanspec)) {
  774. if (radioregs[i].do_init_a) {
  775. write_radio_reg(pi,
  776. radioregs[i].
  777. address | core_offset,
  778. (u16) radioregs[i].init_a);
  779. if (ISNPHY(pi) && (++count % 4 == 0))
  780. BRCMS_PHY_WAR_PR51571(pi);
  781. }
  782. } else {
  783. if (radioregs[i].do_init_g) {
  784. write_radio_reg(pi,
  785. radioregs[i].
  786. address | core_offset,
  787. (u16) radioregs[i].init_g);
  788. if (ISNPHY(pi) && (++count % 4 == 0))
  789. BRCMS_PHY_WAR_PR51571(pi);
  790. }
  791. }
  792. i++;
  793. } while (radioregs[i].address != 0xffff);
  794. return i;
  795. }
  796. void wlc_phy_do_dummy_tx(struct brcms_phy *pi, bool ofdm, bool pa_on)
  797. {
  798. #define DUMMY_PKT_LEN 20
  799. struct bcma_device *core = pi->d11core;
  800. int i, count;
  801. u8 ofdmpkt[DUMMY_PKT_LEN] = {
  802. 0xcc, 0x01, 0x02, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00,
  803. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
  804. };
  805. u8 cckpkt[DUMMY_PKT_LEN] = {
  806. 0x6e, 0x84, 0x0b, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00,
  807. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
  808. };
  809. u32 *dummypkt;
  810. dummypkt = (u32 *) (ofdm ? ofdmpkt : cckpkt);
  811. wlapi_bmac_write_template_ram(pi->sh->physhim, 0, DUMMY_PKT_LEN,
  812. dummypkt);
  813. bcma_write16(core, D11REGOFFS(xmtsel), 0);
  814. if (D11REV_GE(pi->sh->corerev, 11))
  815. bcma_write16(core, D11REGOFFS(wepctl), 0x100);
  816. else
  817. bcma_write16(core, D11REGOFFS(wepctl), 0);
  818. bcma_write16(core, D11REGOFFS(txe_phyctl),
  819. (ofdm ? 1 : 0) | PHY_TXC_ANT_0);
  820. if (ISNPHY(pi) || ISLCNPHY(pi))
  821. bcma_write16(core, D11REGOFFS(txe_phyctl1), 0x1A02);
  822. bcma_write16(core, D11REGOFFS(txe_wm_0), 0);
  823. bcma_write16(core, D11REGOFFS(txe_wm_1), 0);
  824. bcma_write16(core, D11REGOFFS(xmttplatetxptr), 0);
  825. bcma_write16(core, D11REGOFFS(xmttxcnt), DUMMY_PKT_LEN);
  826. bcma_write16(core, D11REGOFFS(xmtsel),
  827. ((8 << 8) | (1 << 5) | (1 << 2) | 2));
  828. bcma_write16(core, D11REGOFFS(txe_ctl), 0);
  829. if (!pa_on) {
  830. if (ISNPHY(pi))
  831. wlc_phy_pa_override_nphy(pi, OFF);
  832. }
  833. if (ISNPHY(pi) || ISLCNPHY(pi))
  834. bcma_write16(core, D11REGOFFS(txe_aux), 0xD0);
  835. else
  836. bcma_write16(core, D11REGOFFS(txe_aux), ((1 << 5) | (1 << 4)));
  837. (void)bcma_read16(core, D11REGOFFS(txe_aux));
  838. i = 0;
  839. count = ofdm ? 30 : 250;
  840. while ((i++ < count)
  841. && (bcma_read16(core, D11REGOFFS(txe_status)) & (1 << 7)))
  842. udelay(10);
  843. i = 0;
  844. while ((i++ < 10) &&
  845. ((bcma_read16(core, D11REGOFFS(txe_status)) & (1 << 10)) == 0))
  846. udelay(10);
  847. i = 0;
  848. while ((i++ < 10) &&
  849. ((bcma_read16(core, D11REGOFFS(ifsstat)) & (1 << 8))))
  850. udelay(10);
  851. if (!pa_on) {
  852. if (ISNPHY(pi))
  853. wlc_phy_pa_override_nphy(pi, ON);
  854. }
  855. }
  856. void wlc_phy_hold_upd(struct brcms_phy_pub *pih, u32 id, bool set)
  857. {
  858. struct brcms_phy *pi = (struct brcms_phy *) pih;
  859. if (set)
  860. mboolset(pi->measure_hold, id);
  861. else
  862. mboolclr(pi->measure_hold, id);
  863. return;
  864. }
  865. void wlc_phy_mute_upd(struct brcms_phy_pub *pih, bool mute, u32 flags)
  866. {
  867. struct brcms_phy *pi = (struct brcms_phy *) pih;
  868. if (mute)
  869. mboolset(pi->measure_hold, PHY_HOLD_FOR_MUTE);
  870. else
  871. mboolclr(pi->measure_hold, PHY_HOLD_FOR_MUTE);
  872. if (!mute && (flags & PHY_MUTE_FOR_PREISM))
  873. pi->nphy_perical_last = pi->sh->now - pi->sh->glacial_timer;
  874. return;
  875. }
  876. void wlc_phy_clear_tssi(struct brcms_phy_pub *pih)
  877. {
  878. struct brcms_phy *pi = (struct brcms_phy *) pih;
  879. if (ISNPHY(pi)) {
  880. return;
  881. } else {
  882. wlapi_bmac_write_shm(pi->sh->physhim, M_B_TSSI_0, NULL_TSSI_W);
  883. wlapi_bmac_write_shm(pi->sh->physhim, M_B_TSSI_1, NULL_TSSI_W);
  884. wlapi_bmac_write_shm(pi->sh->physhim, M_G_TSSI_0, NULL_TSSI_W);
  885. wlapi_bmac_write_shm(pi->sh->physhim, M_G_TSSI_1, NULL_TSSI_W);
  886. }
  887. }
  888. static bool wlc_phy_cal_txpower_recalc_sw(struct brcms_phy *pi)
  889. {
  890. return false;
  891. }
  892. void wlc_phy_switch_radio(struct brcms_phy_pub *pih, bool on)
  893. {
  894. struct brcms_phy *pi = (struct brcms_phy *) pih;
  895. (void)bcma_read32(pi->d11core, D11REGOFFS(maccontrol));
  896. if (ISNPHY(pi)) {
  897. wlc_phy_switch_radio_nphy(pi, on);
  898. } else if (ISLCNPHY(pi)) {
  899. if (on) {
  900. and_phy_reg(pi, 0x44c,
  901. ~((0x1 << 8) |
  902. (0x1 << 9) |
  903. (0x1 << 10) | (0x1 << 11) | (0x1 << 12)));
  904. and_phy_reg(pi, 0x4b0, ~((0x1 << 3) | (0x1 << 11)));
  905. and_phy_reg(pi, 0x4f9, ~(0x1 << 3));
  906. } else {
  907. and_phy_reg(pi, 0x44d,
  908. ~((0x1 << 10) |
  909. (0x1 << 11) |
  910. (0x1 << 12) | (0x1 << 13) | (0x1 << 14)));
  911. or_phy_reg(pi, 0x44c,
  912. (0x1 << 8) |
  913. (0x1 << 9) |
  914. (0x1 << 10) | (0x1 << 11) | (0x1 << 12));
  915. and_phy_reg(pi, 0x4b7, ~((0x7f << 8)));
  916. and_phy_reg(pi, 0x4b1, ~((0x1 << 13)));
  917. or_phy_reg(pi, 0x4b0, (0x1 << 3) | (0x1 << 11));
  918. and_phy_reg(pi, 0x4fa, ~((0x1 << 3)));
  919. or_phy_reg(pi, 0x4f9, (0x1 << 3));
  920. }
  921. }
  922. }
  923. u16 wlc_phy_bw_state_get(struct brcms_phy_pub *ppi)
  924. {
  925. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  926. return pi->bw;
  927. }
  928. void wlc_phy_bw_state_set(struct brcms_phy_pub *ppi, u16 bw)
  929. {
  930. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  931. pi->bw = bw;
  932. }
  933. void wlc_phy_chanspec_radio_set(struct brcms_phy_pub *ppi, u16 newch)
  934. {
  935. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  936. pi->radio_chanspec = newch;
  937. }
  938. u16 wlc_phy_chanspec_get(struct brcms_phy_pub *ppi)
  939. {
  940. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  941. return pi->radio_chanspec;
  942. }
  943. void wlc_phy_chanspec_set(struct brcms_phy_pub *ppi, u16 chanspec)
  944. {
  945. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  946. u16 m_cur_channel;
  947. void (*chanspec_set)(struct brcms_phy *, u16) = NULL;
  948. m_cur_channel = CHSPEC_CHANNEL(chanspec);
  949. if (CHSPEC_IS5G(chanspec))
  950. m_cur_channel |= D11_CURCHANNEL_5G;
  951. if (CHSPEC_IS40(chanspec))
  952. m_cur_channel |= D11_CURCHANNEL_40;
  953. wlapi_bmac_write_shm(pi->sh->physhim, M_CURCHANNEL, m_cur_channel);
  954. chanspec_set = pi->pi_fptr.chanset;
  955. if (chanspec_set)
  956. (*chanspec_set)(pi, chanspec);
  957. }
  958. int wlc_phy_chanspec_freq2bandrange_lpssn(uint freq)
  959. {
  960. int range = -1;
  961. if (freq < 2500)
  962. range = WL_CHAN_FREQ_RANGE_2G;
  963. else if (freq <= 5320)
  964. range = WL_CHAN_FREQ_RANGE_5GL;
  965. else if (freq <= 5700)
  966. range = WL_CHAN_FREQ_RANGE_5GM;
  967. else
  968. range = WL_CHAN_FREQ_RANGE_5GH;
  969. return range;
  970. }
  971. int wlc_phy_chanspec_bandrange_get(struct brcms_phy *pi, u16 chanspec)
  972. {
  973. int range = -1;
  974. uint channel = CHSPEC_CHANNEL(chanspec);
  975. uint freq = wlc_phy_channel2freq(channel);
  976. if (ISNPHY(pi))
  977. range = wlc_phy_get_chan_freq_range_nphy(pi, channel);
  978. else if (ISLCNPHY(pi))
  979. range = wlc_phy_chanspec_freq2bandrange_lpssn(freq);
  980. return range;
  981. }
  982. void wlc_phy_chanspec_ch14_widefilter_set(struct brcms_phy_pub *ppi,
  983. bool wide_filter)
  984. {
  985. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  986. pi->channel_14_wide_filter = wide_filter;
  987. }
  988. int wlc_phy_channel2freq(uint channel)
  989. {
  990. uint i;
  991. for (i = 0; i < ARRAY_SIZE(chan_info_all); i++)
  992. if (chan_info_all[i].chan == channel)
  993. return chan_info_all[i].freq;
  994. return 0;
  995. }
  996. void
  997. wlc_phy_chanspec_band_validch(struct brcms_phy_pub *ppi, uint band,
  998. struct brcms_chanvec *channels)
  999. {
  1000. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1001. uint i;
  1002. uint channel;
  1003. memset(channels, 0, sizeof(struct brcms_chanvec));
  1004. for (i = 0; i < ARRAY_SIZE(chan_info_all); i++) {
  1005. channel = chan_info_all[i].chan;
  1006. if ((pi->a_band_high_disable) && (channel >= FIRST_REF5_CHANNUM)
  1007. && (channel <= LAST_REF5_CHANNUM))
  1008. continue;
  1009. if ((band == BRCM_BAND_2G && channel <= CH_MAX_2G_CHANNEL) ||
  1010. (band == BRCM_BAND_5G && channel > CH_MAX_2G_CHANNEL))
  1011. setbit(channels->vec, channel);
  1012. }
  1013. }
  1014. u16 wlc_phy_chanspec_band_firstch(struct brcms_phy_pub *ppi, uint band)
  1015. {
  1016. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1017. uint i;
  1018. uint channel;
  1019. u16 chspec;
  1020. for (i = 0; i < ARRAY_SIZE(chan_info_all); i++) {
  1021. channel = chan_info_all[i].chan;
  1022. if (ISNPHY(pi) && pi->bw == WL_CHANSPEC_BW_40) {
  1023. uint j;
  1024. for (j = 0; j < ARRAY_SIZE(chan_info_all); j++) {
  1025. if (chan_info_all[j].chan ==
  1026. channel + CH_10MHZ_APART)
  1027. break;
  1028. }
  1029. if (j == ARRAY_SIZE(chan_info_all))
  1030. continue;
  1031. channel = upper_20_sb(channel);
  1032. chspec = channel | WL_CHANSPEC_BW_40 |
  1033. WL_CHANSPEC_CTL_SB_LOWER;
  1034. if (band == BRCM_BAND_2G)
  1035. chspec |= WL_CHANSPEC_BAND_2G;
  1036. else
  1037. chspec |= WL_CHANSPEC_BAND_5G;
  1038. } else
  1039. chspec = ch20mhz_chspec(channel);
  1040. if ((pi->a_band_high_disable) && (channel >= FIRST_REF5_CHANNUM)
  1041. && (channel <= LAST_REF5_CHANNUM))
  1042. continue;
  1043. if ((band == BRCM_BAND_2G && channel <= CH_MAX_2G_CHANNEL) ||
  1044. (band == BRCM_BAND_5G && channel > CH_MAX_2G_CHANNEL))
  1045. return chspec;
  1046. }
  1047. return (u16) INVCHANSPEC;
  1048. }
  1049. int wlc_phy_txpower_get(struct brcms_phy_pub *ppi, uint *qdbm, bool *override)
  1050. {
  1051. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1052. *qdbm = pi->tx_user_target[0];
  1053. if (override != NULL)
  1054. *override = pi->txpwroverride;
  1055. return 0;
  1056. }
  1057. void wlc_phy_txpower_target_set(struct brcms_phy_pub *ppi,
  1058. struct txpwr_limits *txpwr)
  1059. {
  1060. bool mac_enabled = false;
  1061. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1062. memcpy(&pi->tx_user_target[TXP_FIRST_CCK],
  1063. &txpwr->cck[0], BRCMS_NUM_RATES_CCK);
  1064. memcpy(&pi->tx_user_target[TXP_FIRST_OFDM],
  1065. &txpwr->ofdm[0], BRCMS_NUM_RATES_OFDM);
  1066. memcpy(&pi->tx_user_target[TXP_FIRST_OFDM_20_CDD],
  1067. &txpwr->ofdm_cdd[0], BRCMS_NUM_RATES_OFDM);
  1068. memcpy(&pi->tx_user_target[TXP_FIRST_OFDM_40_SISO],
  1069. &txpwr->ofdm_40_siso[0], BRCMS_NUM_RATES_OFDM);
  1070. memcpy(&pi->tx_user_target[TXP_FIRST_OFDM_40_CDD],
  1071. &txpwr->ofdm_40_cdd[0], BRCMS_NUM_RATES_OFDM);
  1072. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_20_SISO],
  1073. &txpwr->mcs_20_siso[0], BRCMS_NUM_RATES_MCS_1_STREAM);
  1074. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_20_CDD],
  1075. &txpwr->mcs_20_cdd[0], BRCMS_NUM_RATES_MCS_1_STREAM);
  1076. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_20_STBC],
  1077. &txpwr->mcs_20_stbc[0], BRCMS_NUM_RATES_MCS_1_STREAM);
  1078. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_20_SDM],
  1079. &txpwr->mcs_20_mimo[0], BRCMS_NUM_RATES_MCS_2_STREAM);
  1080. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_40_SISO],
  1081. &txpwr->mcs_40_siso[0], BRCMS_NUM_RATES_MCS_1_STREAM);
  1082. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_40_CDD],
  1083. &txpwr->mcs_40_cdd[0], BRCMS_NUM_RATES_MCS_1_STREAM);
  1084. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_40_STBC],
  1085. &txpwr->mcs_40_stbc[0], BRCMS_NUM_RATES_MCS_1_STREAM);
  1086. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_40_SDM],
  1087. &txpwr->mcs_40_mimo[0], BRCMS_NUM_RATES_MCS_2_STREAM);
  1088. if (bcma_read32(pi->d11core, D11REGOFFS(maccontrol)) & MCTL_EN_MAC)
  1089. mac_enabled = true;
  1090. if (mac_enabled)
  1091. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1092. wlc_phy_txpower_recalc_target(pi);
  1093. wlc_phy_cal_txpower_recalc_sw(pi);
  1094. if (mac_enabled)
  1095. wlapi_enable_mac(pi->sh->physhim);
  1096. }
  1097. int wlc_phy_txpower_set(struct brcms_phy_pub *ppi, uint qdbm, bool override)
  1098. {
  1099. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1100. int i;
  1101. if (qdbm > 127)
  1102. return -EINVAL;
  1103. for (i = 0; i < TXP_NUM_RATES; i++)
  1104. pi->tx_user_target[i] = (u8) qdbm;
  1105. pi->txpwroverride = false;
  1106. if (pi->sh->up) {
  1107. if (!SCAN_INPROG_PHY(pi)) {
  1108. bool suspend;
  1109. suspend = (0 == (bcma_read32(pi->d11core,
  1110. D11REGOFFS(maccontrol)) &
  1111. MCTL_EN_MAC));
  1112. if (!suspend)
  1113. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1114. wlc_phy_txpower_recalc_target(pi);
  1115. wlc_phy_cal_txpower_recalc_sw(pi);
  1116. if (!suspend)
  1117. wlapi_enable_mac(pi->sh->physhim);
  1118. }
  1119. }
  1120. return 0;
  1121. }
  1122. void
  1123. wlc_phy_txpower_sromlimit(struct brcms_phy_pub *ppi, uint channel, u8 *min_pwr,
  1124. u8 *max_pwr, int txp_rate_idx)
  1125. {
  1126. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1127. uint i;
  1128. *min_pwr = pi->min_txpower * BRCMS_TXPWR_DB_FACTOR;
  1129. if (ISNPHY(pi)) {
  1130. if (txp_rate_idx < 0)
  1131. txp_rate_idx = TXP_FIRST_CCK;
  1132. wlc_phy_txpower_sromlimit_get_nphy(pi, channel, max_pwr,
  1133. (u8) txp_rate_idx);
  1134. } else if ((channel <= CH_MAX_2G_CHANNEL)) {
  1135. if (txp_rate_idx < 0)
  1136. txp_rate_idx = TXP_FIRST_CCK;
  1137. *max_pwr = pi->tx_srom_max_rate_2g[txp_rate_idx];
  1138. } else {
  1139. *max_pwr = BRCMS_TXPWR_MAX;
  1140. if (txp_rate_idx < 0)
  1141. txp_rate_idx = TXP_FIRST_OFDM;
  1142. for (i = 0; i < ARRAY_SIZE(chan_info_all); i++) {
  1143. if (channel == chan_info_all[i].chan)
  1144. break;
  1145. }
  1146. if (pi->hwtxpwr) {
  1147. *max_pwr = pi->hwtxpwr[i];
  1148. } else {
  1149. if ((i >= FIRST_MID_5G_CHAN) && (i <= LAST_MID_5G_CHAN))
  1150. *max_pwr =
  1151. pi->tx_srom_max_rate_5g_mid[txp_rate_idx];
  1152. if ((i >= FIRST_HIGH_5G_CHAN)
  1153. && (i <= LAST_HIGH_5G_CHAN))
  1154. *max_pwr =
  1155. pi->tx_srom_max_rate_5g_hi[txp_rate_idx];
  1156. if ((i >= FIRST_LOW_5G_CHAN) && (i <= LAST_LOW_5G_CHAN))
  1157. *max_pwr =
  1158. pi->tx_srom_max_rate_5g_low[txp_rate_idx];
  1159. }
  1160. }
  1161. }
  1162. void
  1163. wlc_phy_txpower_sromlimit_max_get(struct brcms_phy_pub *ppi, uint chan,
  1164. u8 *max_txpwr, u8 *min_txpwr)
  1165. {
  1166. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1167. u8 tx_pwr_max = 0;
  1168. u8 tx_pwr_min = 255;
  1169. u8 max_num_rate;
  1170. u8 maxtxpwr, mintxpwr, rate, pactrl;
  1171. pactrl = 0;
  1172. max_num_rate = ISNPHY(pi) ? TXP_NUM_RATES :
  1173. ISLCNPHY(pi) ? (TXP_LAST_SISO_MCS_20 +
  1174. 1) : (TXP_LAST_OFDM + 1);
  1175. for (rate = 0; rate < max_num_rate; rate++) {
  1176. wlc_phy_txpower_sromlimit(ppi, chan, &mintxpwr, &maxtxpwr,
  1177. rate);
  1178. maxtxpwr = (maxtxpwr > pactrl) ? (maxtxpwr - pactrl) : 0;
  1179. maxtxpwr = (maxtxpwr > 6) ? (maxtxpwr - 6) : 0;
  1180. tx_pwr_max = max(tx_pwr_max, maxtxpwr);
  1181. tx_pwr_min = min(tx_pwr_min, maxtxpwr);
  1182. }
  1183. *max_txpwr = tx_pwr_max;
  1184. *min_txpwr = tx_pwr_min;
  1185. }
  1186. void
  1187. wlc_phy_txpower_boardlimit_band(struct brcms_phy_pub *ppi, uint bandunit,
  1188. s32 *max_pwr, s32 *min_pwr, u32 *step_pwr)
  1189. {
  1190. return;
  1191. }
  1192. u8 wlc_phy_txpower_get_target_min(struct brcms_phy_pub *ppi)
  1193. {
  1194. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1195. return pi->tx_power_min;
  1196. }
  1197. u8 wlc_phy_txpower_get_target_max(struct brcms_phy_pub *ppi)
  1198. {
  1199. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1200. return pi->tx_power_max;
  1201. }
  1202. static s8 wlc_phy_env_measure_vbat(struct brcms_phy *pi)
  1203. {
  1204. if (ISLCNPHY(pi))
  1205. return wlc_lcnphy_vbatsense(pi, 0);
  1206. else
  1207. return 0;
  1208. }
  1209. static s8 wlc_phy_env_measure_temperature(struct brcms_phy *pi)
  1210. {
  1211. if (ISLCNPHY(pi))
  1212. return wlc_lcnphy_tempsense_degree(pi, 0);
  1213. else
  1214. return 0;
  1215. }
  1216. static void wlc_phy_upd_env_txpwr_rate_limits(struct brcms_phy *pi, u32 band)
  1217. {
  1218. u8 i;
  1219. s8 temp, vbat;
  1220. for (i = 0; i < TXP_NUM_RATES; i++)
  1221. pi->txpwr_env_limit[i] = BRCMS_TXPWR_MAX;
  1222. vbat = wlc_phy_env_measure_vbat(pi);
  1223. temp = wlc_phy_env_measure_temperature(pi);
  1224. }
  1225. static s8
  1226. wlc_user_txpwr_antport_to_rfport(struct brcms_phy *pi, uint chan, u32 band,
  1227. u8 rate)
  1228. {
  1229. s8 offset = 0;
  1230. if (!pi->user_txpwr_at_rfport)
  1231. return offset;
  1232. return offset;
  1233. }
  1234. void wlc_phy_txpower_recalc_target(struct brcms_phy *pi)
  1235. {
  1236. u8 maxtxpwr, mintxpwr, rate, pactrl;
  1237. uint target_chan;
  1238. u8 tx_pwr_target[TXP_NUM_RATES];
  1239. u8 tx_pwr_max = 0;
  1240. u8 tx_pwr_min = 255;
  1241. u8 tx_pwr_max_rate_ind = 0;
  1242. u8 max_num_rate;
  1243. u8 start_rate = 0;
  1244. u16 chspec;
  1245. u32 band = CHSPEC2BAND(pi->radio_chanspec);
  1246. void (*txpwr_recalc_fn)(struct brcms_phy *) = NULL;
  1247. chspec = pi->radio_chanspec;
  1248. if (CHSPEC_CTL_SB(chspec) == WL_CHANSPEC_CTL_SB_NONE)
  1249. target_chan = CHSPEC_CHANNEL(chspec);
  1250. else if (CHSPEC_CTL_SB(chspec) == WL_CHANSPEC_CTL_SB_UPPER)
  1251. target_chan = upper_20_sb(CHSPEC_CHANNEL(chspec));
  1252. else
  1253. target_chan = lower_20_sb(CHSPEC_CHANNEL(chspec));
  1254. pactrl = 0;
  1255. if (ISLCNPHY(pi)) {
  1256. u32 offset_mcs, i;
  1257. if (CHSPEC_IS40(pi->radio_chanspec)) {
  1258. offset_mcs = pi->mcs40_po;
  1259. for (i = TXP_FIRST_SISO_MCS_20;
  1260. i <= TXP_LAST_SISO_MCS_20; i++) {
  1261. pi->tx_srom_max_rate_2g[i - 8] =
  1262. pi->tx_srom_max_2g -
  1263. ((offset_mcs & 0xf) * 2);
  1264. offset_mcs >>= 4;
  1265. }
  1266. } else {
  1267. offset_mcs = pi->mcs20_po;
  1268. for (i = TXP_FIRST_SISO_MCS_20;
  1269. i <= TXP_LAST_SISO_MCS_20; i++) {
  1270. pi->tx_srom_max_rate_2g[i - 8] =
  1271. pi->tx_srom_max_2g -
  1272. ((offset_mcs & 0xf) * 2);
  1273. offset_mcs >>= 4;
  1274. }
  1275. }
  1276. }
  1277. max_num_rate = ((ISNPHY(pi)) ? (TXP_NUM_RATES) :
  1278. ((ISLCNPHY(pi)) ?
  1279. (TXP_LAST_SISO_MCS_20 + 1) : (TXP_LAST_OFDM + 1)));
  1280. wlc_phy_upd_env_txpwr_rate_limits(pi, band);
  1281. for (rate = start_rate; rate < max_num_rate; rate++) {
  1282. tx_pwr_target[rate] = pi->tx_user_target[rate];
  1283. if (pi->user_txpwr_at_rfport)
  1284. tx_pwr_target[rate] +=
  1285. wlc_user_txpwr_antport_to_rfport(pi,
  1286. target_chan,
  1287. band,
  1288. rate);
  1289. wlc_phy_txpower_sromlimit((struct brcms_phy_pub *) pi,
  1290. target_chan,
  1291. &mintxpwr, &maxtxpwr, rate);
  1292. maxtxpwr = min(maxtxpwr, pi->txpwr_limit[rate]);
  1293. maxtxpwr = (maxtxpwr > pactrl) ? (maxtxpwr - pactrl) : 0;
  1294. maxtxpwr = (maxtxpwr > 6) ? (maxtxpwr - 6) : 0;
  1295. maxtxpwr = min(maxtxpwr, tx_pwr_target[rate]);
  1296. if (pi->txpwr_percent <= 100)
  1297. maxtxpwr = (maxtxpwr * pi->txpwr_percent) / 100;
  1298. tx_pwr_target[rate] = max(maxtxpwr, mintxpwr);
  1299. tx_pwr_target[rate] =
  1300. min(tx_pwr_target[rate], pi->txpwr_env_limit[rate]);
  1301. if (tx_pwr_target[rate] > tx_pwr_max)
  1302. tx_pwr_max_rate_ind = rate;
  1303. tx_pwr_max = max(tx_pwr_max, tx_pwr_target[rate]);
  1304. tx_pwr_min = min(tx_pwr_min, tx_pwr_target[rate]);
  1305. }
  1306. memset(pi->tx_power_offset, 0, sizeof(pi->tx_power_offset));
  1307. pi->tx_power_max = tx_pwr_max;
  1308. pi->tx_power_min = tx_pwr_min;
  1309. pi->tx_power_max_rate_ind = tx_pwr_max_rate_ind;
  1310. for (rate = 0; rate < max_num_rate; rate++) {
  1311. pi->tx_power_target[rate] = tx_pwr_target[rate];
  1312. if (!pi->hwpwrctrl || ISNPHY(pi))
  1313. pi->tx_power_offset[rate] =
  1314. pi->tx_power_max - pi->tx_power_target[rate];
  1315. else
  1316. pi->tx_power_offset[rate] =
  1317. pi->tx_power_target[rate] - pi->tx_power_min;
  1318. }
  1319. txpwr_recalc_fn = pi->pi_fptr.txpwrrecalc;
  1320. if (txpwr_recalc_fn)
  1321. (*txpwr_recalc_fn)(pi);
  1322. }
  1323. static void
  1324. wlc_phy_txpower_reg_limit_calc(struct brcms_phy *pi, struct txpwr_limits *txpwr,
  1325. u16 chanspec)
  1326. {
  1327. u8 tmp_txpwr_limit[2 * BRCMS_NUM_RATES_OFDM];
  1328. u8 *txpwr_ptr1 = NULL, *txpwr_ptr2 = NULL;
  1329. int rate_start_index = 0, rate1, rate2, k;
  1330. for (rate1 = WL_TX_POWER_CCK_FIRST, rate2 = 0;
  1331. rate2 < WL_TX_POWER_CCK_NUM; rate1++, rate2++)
  1332. pi->txpwr_limit[rate1] = txpwr->cck[rate2];
  1333. for (rate1 = WL_TX_POWER_OFDM_FIRST, rate2 = 0;
  1334. rate2 < WL_TX_POWER_OFDM_NUM; rate1++, rate2++)
  1335. pi->txpwr_limit[rate1] = txpwr->ofdm[rate2];
  1336. if (ISNPHY(pi)) {
  1337. for (k = 0; k < 4; k++) {
  1338. switch (k) {
  1339. case 0:
  1340. txpwr_ptr1 = txpwr->mcs_20_siso;
  1341. txpwr_ptr2 = txpwr->ofdm;
  1342. rate_start_index = WL_TX_POWER_OFDM_FIRST;
  1343. break;
  1344. case 1:
  1345. txpwr_ptr1 = txpwr->mcs_20_cdd;
  1346. txpwr_ptr2 = txpwr->ofdm_cdd;
  1347. rate_start_index = WL_TX_POWER_OFDM20_CDD_FIRST;
  1348. break;
  1349. case 2:
  1350. txpwr_ptr1 = txpwr->mcs_40_siso;
  1351. txpwr_ptr2 = txpwr->ofdm_40_siso;
  1352. rate_start_index =
  1353. WL_TX_POWER_OFDM40_SISO_FIRST;
  1354. break;
  1355. case 3:
  1356. txpwr_ptr1 = txpwr->mcs_40_cdd;
  1357. txpwr_ptr2 = txpwr->ofdm_40_cdd;
  1358. rate_start_index = WL_TX_POWER_OFDM40_CDD_FIRST;
  1359. break;
  1360. }
  1361. for (rate2 = 0; rate2 < BRCMS_NUM_RATES_OFDM;
  1362. rate2++) {
  1363. tmp_txpwr_limit[rate2] = 0;
  1364. tmp_txpwr_limit[BRCMS_NUM_RATES_OFDM + rate2] =
  1365. txpwr_ptr1[rate2];
  1366. }
  1367. wlc_phy_mcs_to_ofdm_powers_nphy(
  1368. tmp_txpwr_limit, 0,
  1369. BRCMS_NUM_RATES_OFDM -
  1370. 1, BRCMS_NUM_RATES_OFDM);
  1371. for (rate1 = rate_start_index, rate2 = 0;
  1372. rate2 < BRCMS_NUM_RATES_OFDM; rate1++, rate2++)
  1373. pi->txpwr_limit[rate1] =
  1374. min(txpwr_ptr2[rate2],
  1375. tmp_txpwr_limit[rate2]);
  1376. }
  1377. for (k = 0; k < 4; k++) {
  1378. switch (k) {
  1379. case 0:
  1380. txpwr_ptr1 = txpwr->ofdm;
  1381. txpwr_ptr2 = txpwr->mcs_20_siso;
  1382. rate_start_index = WL_TX_POWER_MCS20_SISO_FIRST;
  1383. break;
  1384. case 1:
  1385. txpwr_ptr1 = txpwr->ofdm_cdd;
  1386. txpwr_ptr2 = txpwr->mcs_20_cdd;
  1387. rate_start_index = WL_TX_POWER_MCS20_CDD_FIRST;
  1388. break;
  1389. case 2:
  1390. txpwr_ptr1 = txpwr->ofdm_40_siso;
  1391. txpwr_ptr2 = txpwr->mcs_40_siso;
  1392. rate_start_index = WL_TX_POWER_MCS40_SISO_FIRST;
  1393. break;
  1394. case 3:
  1395. txpwr_ptr1 = txpwr->ofdm_40_cdd;
  1396. txpwr_ptr2 = txpwr->mcs_40_cdd;
  1397. rate_start_index = WL_TX_POWER_MCS40_CDD_FIRST;
  1398. break;
  1399. }
  1400. for (rate2 = 0; rate2 < BRCMS_NUM_RATES_OFDM;
  1401. rate2++) {
  1402. tmp_txpwr_limit[rate2] = 0;
  1403. tmp_txpwr_limit[BRCMS_NUM_RATES_OFDM + rate2] =
  1404. txpwr_ptr1[rate2];
  1405. }
  1406. wlc_phy_ofdm_to_mcs_powers_nphy(
  1407. tmp_txpwr_limit, 0,
  1408. BRCMS_NUM_RATES_OFDM -
  1409. 1, BRCMS_NUM_RATES_OFDM);
  1410. for (rate1 = rate_start_index, rate2 = 0;
  1411. rate2 < BRCMS_NUM_RATES_MCS_1_STREAM;
  1412. rate1++, rate2++)
  1413. pi->txpwr_limit[rate1] =
  1414. min(txpwr_ptr2[rate2],
  1415. tmp_txpwr_limit[rate2]);
  1416. }
  1417. for (k = 0; k < 2; k++) {
  1418. switch (k) {
  1419. case 0:
  1420. rate_start_index = WL_TX_POWER_MCS20_STBC_FIRST;
  1421. txpwr_ptr1 = txpwr->mcs_20_stbc;
  1422. break;
  1423. case 1:
  1424. rate_start_index = WL_TX_POWER_MCS40_STBC_FIRST;
  1425. txpwr_ptr1 = txpwr->mcs_40_stbc;
  1426. break;
  1427. }
  1428. for (rate1 = rate_start_index, rate2 = 0;
  1429. rate2 < BRCMS_NUM_RATES_MCS_1_STREAM;
  1430. rate1++, rate2++)
  1431. pi->txpwr_limit[rate1] = txpwr_ptr1[rate2];
  1432. }
  1433. for (k = 0; k < 2; k++) {
  1434. switch (k) {
  1435. case 0:
  1436. rate_start_index = WL_TX_POWER_MCS20_SDM_FIRST;
  1437. txpwr_ptr1 = txpwr->mcs_20_mimo;
  1438. break;
  1439. case 1:
  1440. rate_start_index = WL_TX_POWER_MCS40_SDM_FIRST;
  1441. txpwr_ptr1 = txpwr->mcs_40_mimo;
  1442. break;
  1443. }
  1444. for (rate1 = rate_start_index, rate2 = 0;
  1445. rate2 < BRCMS_NUM_RATES_MCS_2_STREAM;
  1446. rate1++, rate2++)
  1447. pi->txpwr_limit[rate1] = txpwr_ptr1[rate2];
  1448. }
  1449. pi->txpwr_limit[WL_TX_POWER_MCS_32] = txpwr->mcs32;
  1450. pi->txpwr_limit[WL_TX_POWER_MCS40_CDD_FIRST] =
  1451. min(pi->txpwr_limit[WL_TX_POWER_MCS40_CDD_FIRST],
  1452. pi->txpwr_limit[WL_TX_POWER_MCS_32]);
  1453. pi->txpwr_limit[WL_TX_POWER_MCS_32] =
  1454. pi->txpwr_limit[WL_TX_POWER_MCS40_CDD_FIRST];
  1455. }
  1456. }
  1457. void wlc_phy_txpwr_percent_set(struct brcms_phy_pub *ppi, u8 txpwr_percent)
  1458. {
  1459. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1460. pi->txpwr_percent = txpwr_percent;
  1461. }
  1462. void wlc_phy_machwcap_set(struct brcms_phy_pub *ppi, u32 machwcap)
  1463. {
  1464. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1465. pi->sh->machwcap = machwcap;
  1466. }
  1467. void wlc_phy_runbist_config(struct brcms_phy_pub *ppi, bool start_end)
  1468. {
  1469. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1470. u16 rxc;
  1471. rxc = 0;
  1472. if (start_end == ON) {
  1473. if (!ISNPHY(pi))
  1474. return;
  1475. if (NREV_IS(pi->pubpi.phy_rev, 3)
  1476. || NREV_IS(pi->pubpi.phy_rev, 4)) {
  1477. bcma_wflush16(pi->d11core, D11REGOFFS(phyregaddr),
  1478. 0xa0);
  1479. bcma_set16(pi->d11core, D11REGOFFS(phyregdata),
  1480. 0x1 << 15);
  1481. }
  1482. } else {
  1483. if (NREV_IS(pi->pubpi.phy_rev, 3)
  1484. || NREV_IS(pi->pubpi.phy_rev, 4)) {
  1485. bcma_wflush16(pi->d11core, D11REGOFFS(phyregaddr),
  1486. 0xa0);
  1487. bcma_write16(pi->d11core, D11REGOFFS(phyregdata), rxc);
  1488. }
  1489. wlc_phy_por_inform(ppi);
  1490. }
  1491. }
  1492. void
  1493. wlc_phy_txpower_limit_set(struct brcms_phy_pub *ppi, struct txpwr_limits *txpwr,
  1494. u16 chanspec)
  1495. {
  1496. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1497. wlc_phy_txpower_reg_limit_calc(pi, txpwr, chanspec);
  1498. if (ISLCNPHY(pi)) {
  1499. int i, j;
  1500. for (i = TXP_FIRST_OFDM_20_CDD, j = 0;
  1501. j < BRCMS_NUM_RATES_MCS_1_STREAM; i++, j++) {
  1502. if (txpwr->mcs_20_siso[j])
  1503. pi->txpwr_limit[i] = txpwr->mcs_20_siso[j];
  1504. else
  1505. pi->txpwr_limit[i] = txpwr->ofdm[j];
  1506. }
  1507. }
  1508. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1509. wlc_phy_txpower_recalc_target(pi);
  1510. wlc_phy_cal_txpower_recalc_sw(pi);
  1511. wlapi_enable_mac(pi->sh->physhim);
  1512. }
  1513. void wlc_phy_ofdm_rateset_war(struct brcms_phy_pub *pih, bool war)
  1514. {
  1515. struct brcms_phy *pi = (struct brcms_phy *) pih;
  1516. pi->ofdm_rateset_war = war;
  1517. }
  1518. void wlc_phy_bf_preempt_enable(struct brcms_phy_pub *pih, bool bf_preempt)
  1519. {
  1520. struct brcms_phy *pi = (struct brcms_phy *) pih;
  1521. pi->bf_preempt_4306 = bf_preempt;
  1522. }
  1523. void wlc_phy_txpower_update_shm(struct brcms_phy *pi)
  1524. {
  1525. int j;
  1526. if (ISNPHY(pi))
  1527. return;
  1528. if (!pi->sh->clk)
  1529. return;
  1530. if (pi->hwpwrctrl) {
  1531. u16 offset;
  1532. wlapi_bmac_write_shm(pi->sh->physhim, M_TXPWR_MAX, 63);
  1533. wlapi_bmac_write_shm(pi->sh->physhim, M_TXPWR_N,
  1534. 1 << NUM_TSSI_FRAMES);
  1535. wlapi_bmac_write_shm(pi->sh->physhim, M_TXPWR_TARGET,
  1536. pi->tx_power_min << NUM_TSSI_FRAMES);
  1537. wlapi_bmac_write_shm(pi->sh->physhim, M_TXPWR_CUR,
  1538. pi->hwpwr_txcur);
  1539. for (j = TXP_FIRST_OFDM; j <= TXP_LAST_OFDM; j++) {
  1540. const u8 ucode_ofdm_rates[] = {
  1541. 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c
  1542. };
  1543. offset = wlapi_bmac_rate_shm_offset(
  1544. pi->sh->physhim,
  1545. ucode_ofdm_rates[j - TXP_FIRST_OFDM]);
  1546. wlapi_bmac_write_shm(pi->sh->physhim, offset + 6,
  1547. pi->tx_power_offset[j]);
  1548. wlapi_bmac_write_shm(pi->sh->physhim, offset + 14,
  1549. -(pi->tx_power_offset[j] / 2));
  1550. }
  1551. wlapi_bmac_mhf(pi->sh->physhim, MHF2, MHF2_HWPWRCTL,
  1552. MHF2_HWPWRCTL, BRCM_BAND_ALL);
  1553. } else {
  1554. int i;
  1555. for (i = TXP_FIRST_OFDM; i <= TXP_LAST_OFDM; i++)
  1556. pi->tx_power_offset[i] =
  1557. (u8) roundup(pi->tx_power_offset[i], 8);
  1558. wlapi_bmac_write_shm(pi->sh->physhim, M_OFDM_OFFSET,
  1559. (u16)
  1560. ((pi->tx_power_offset[TXP_FIRST_OFDM]
  1561. + 7) >> 3));
  1562. }
  1563. }
  1564. bool wlc_phy_txpower_hw_ctrl_get(struct brcms_phy_pub *ppi)
  1565. {
  1566. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1567. if (ISNPHY(pi))
  1568. return pi->nphy_txpwrctrl;
  1569. else
  1570. return pi->hwpwrctrl;
  1571. }
  1572. void wlc_phy_txpower_hw_ctrl_set(struct brcms_phy_pub *ppi, bool hwpwrctrl)
  1573. {
  1574. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1575. bool suspend;
  1576. if (!pi->hwpwrctrl_capable)
  1577. return;
  1578. pi->hwpwrctrl = hwpwrctrl;
  1579. pi->nphy_txpwrctrl = hwpwrctrl;
  1580. pi->txpwrctrl = hwpwrctrl;
  1581. if (ISNPHY(pi)) {
  1582. suspend = (0 == (bcma_read32(pi->d11core,
  1583. D11REGOFFS(maccontrol)) &
  1584. MCTL_EN_MAC));
  1585. if (!suspend)
  1586. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1587. wlc_phy_txpwrctrl_enable_nphy(pi, pi->nphy_txpwrctrl);
  1588. if (pi->nphy_txpwrctrl == PHY_TPC_HW_OFF)
  1589. wlc_phy_txpwr_fixpower_nphy(pi);
  1590. else
  1591. mod_phy_reg(pi, 0x1e7, (0x7f << 0),
  1592. pi->saved_txpwr_idx);
  1593. if (!suspend)
  1594. wlapi_enable_mac(pi->sh->physhim);
  1595. }
  1596. }
  1597. void wlc_phy_txpower_ipa_upd(struct brcms_phy *pi)
  1598. {
  1599. if (NREV_GE(pi->pubpi.phy_rev, 3)) {
  1600. pi->ipa2g_on = (pi->srom_fem2g.extpagain == 2);
  1601. pi->ipa5g_on = (pi->srom_fem5g.extpagain == 2);
  1602. } else {
  1603. pi->ipa2g_on = false;
  1604. pi->ipa5g_on = false;
  1605. }
  1606. }
  1607. static u32 wlc_phy_txpower_est_power_nphy(struct brcms_phy *pi)
  1608. {
  1609. s16 tx0_status, tx1_status;
  1610. u16 estPower1, estPower2;
  1611. u8 pwr0, pwr1, adj_pwr0, adj_pwr1;
  1612. u32 est_pwr;
  1613. estPower1 = read_phy_reg(pi, 0x118);
  1614. estPower2 = read_phy_reg(pi, 0x119);
  1615. if ((estPower1 & (0x1 << 8)) == (0x1 << 8))
  1616. pwr0 = (u8) (estPower1 & (0xff << 0)) >> 0;
  1617. else
  1618. pwr0 = 0x80;
  1619. if ((estPower2 & (0x1 << 8)) == (0x1 << 8))
  1620. pwr1 = (u8) (estPower2 & (0xff << 0)) >> 0;
  1621. else
  1622. pwr1 = 0x80;
  1623. tx0_status = read_phy_reg(pi, 0x1ed);
  1624. tx1_status = read_phy_reg(pi, 0x1ee);
  1625. if ((tx0_status & (0x1 << 15)) == (0x1 << 15))
  1626. adj_pwr0 = (u8) (tx0_status & (0xff << 0)) >> 0;
  1627. else
  1628. adj_pwr0 = 0x80;
  1629. if ((tx1_status & (0x1 << 15)) == (0x1 << 15))
  1630. adj_pwr1 = (u8) (tx1_status & (0xff << 0)) >> 0;
  1631. else
  1632. adj_pwr1 = 0x80;
  1633. est_pwr = (u32) ((pwr0 << 24) | (pwr1 << 16) | (adj_pwr0 << 8) |
  1634. adj_pwr1);
  1635. return est_pwr;
  1636. }
  1637. void
  1638. wlc_phy_txpower_get_current(struct brcms_phy_pub *ppi, struct tx_power *power,
  1639. uint channel)
  1640. {
  1641. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1642. uint rate, num_rates;
  1643. u8 min_pwr, max_pwr;
  1644. #if WL_TX_POWER_RATES != TXP_NUM_RATES
  1645. #error "struct tx_power out of sync with this fn"
  1646. #endif
  1647. if (ISNPHY(pi)) {
  1648. power->rf_cores = 2;
  1649. power->flags |= (WL_TX_POWER_F_MIMO);
  1650. if (pi->nphy_txpwrctrl == PHY_TPC_HW_ON)
  1651. power->flags |=
  1652. (WL_TX_POWER_F_ENABLED | WL_TX_POWER_F_HW);
  1653. } else if (ISLCNPHY(pi)) {
  1654. power->rf_cores = 1;
  1655. power->flags |= (WL_TX_POWER_F_SISO);
  1656. if (pi->radiopwr_override == RADIOPWR_OVERRIDE_DEF)
  1657. power->flags |= WL_TX_POWER_F_ENABLED;
  1658. if (pi->hwpwrctrl)
  1659. power->flags |= WL_TX_POWER_F_HW;
  1660. }
  1661. num_rates = ((ISNPHY(pi)) ? (TXP_NUM_RATES) :
  1662. ((ISLCNPHY(pi)) ?
  1663. (TXP_LAST_OFDM_20_CDD + 1) : (TXP_LAST_OFDM + 1)));
  1664. for (rate = 0; rate < num_rates; rate++) {
  1665. power->user_limit[rate] = pi->tx_user_target[rate];
  1666. wlc_phy_txpower_sromlimit(ppi, channel, &min_pwr, &max_pwr,
  1667. rate);
  1668. power->board_limit[rate] = (u8) max_pwr;
  1669. power->target[rate] = pi->tx_power_target[rate];
  1670. }
  1671. if (ISNPHY(pi)) {
  1672. u32 est_pout;
  1673. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1674. wlc_phyreg_enter((struct brcms_phy_pub *) pi);
  1675. est_pout = wlc_phy_txpower_est_power_nphy(pi);
  1676. wlc_phyreg_exit((struct brcms_phy_pub *) pi);
  1677. wlapi_enable_mac(pi->sh->physhim);
  1678. power->est_Pout[0] = (est_pout >> 8) & 0xff;
  1679. power->est_Pout[1] = est_pout & 0xff;
  1680. power->est_Pout_act[0] = est_pout >> 24;
  1681. power->est_Pout_act[1] = (est_pout >> 16) & 0xff;
  1682. if (power->est_Pout[0] == 0x80)
  1683. power->est_Pout[0] = 0;
  1684. if (power->est_Pout[1] == 0x80)
  1685. power->est_Pout[1] = 0;
  1686. if (power->est_Pout_act[0] == 0x80)
  1687. power->est_Pout_act[0] = 0;
  1688. if (power->est_Pout_act[1] == 0x80)
  1689. power->est_Pout_act[1] = 0;
  1690. power->est_Pout_cck = 0;
  1691. power->tx_power_max[0] = pi->tx_power_max;
  1692. power->tx_power_max[1] = pi->tx_power_max;
  1693. power->tx_power_max_rate_ind[0] = pi->tx_power_max_rate_ind;
  1694. power->tx_power_max_rate_ind[1] = pi->tx_power_max_rate_ind;
  1695. } else if (pi->hwpwrctrl && pi->sh->up) {
  1696. wlc_phyreg_enter(ppi);
  1697. if (ISLCNPHY(pi)) {
  1698. power->tx_power_max[0] = pi->tx_power_max;
  1699. power->tx_power_max[1] = pi->tx_power_max;
  1700. power->tx_power_max_rate_ind[0] =
  1701. pi->tx_power_max_rate_ind;
  1702. power->tx_power_max_rate_ind[1] =
  1703. pi->tx_power_max_rate_ind;
  1704. if (wlc_phy_tpc_isenabled_lcnphy(pi))
  1705. power->flags |=
  1706. (WL_TX_POWER_F_HW |
  1707. WL_TX_POWER_F_ENABLED);
  1708. else
  1709. power->flags &=
  1710. ~(WL_TX_POWER_F_HW |
  1711. WL_TX_POWER_F_ENABLED);
  1712. wlc_lcnphy_get_tssi(pi, (s8 *) &power->est_Pout[0],
  1713. (s8 *) &power->est_Pout_cck);
  1714. }
  1715. wlc_phyreg_exit(ppi);
  1716. }
  1717. }
  1718. void wlc_phy_antsel_type_set(struct brcms_phy_pub *ppi, u8 antsel_type)
  1719. {
  1720. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1721. pi->antsel_type = antsel_type;
  1722. }
  1723. bool wlc_phy_test_ison(struct brcms_phy_pub *ppi)
  1724. {
  1725. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1726. return pi->phytest_on;
  1727. }
  1728. void wlc_phy_ant_rxdiv_set(struct brcms_phy_pub *ppi, u8 val)
  1729. {
  1730. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1731. bool suspend;
  1732. pi->sh->rx_antdiv = val;
  1733. if (!(ISNPHY(pi) && D11REV_IS(pi->sh->corerev, 16))) {
  1734. if (val > ANT_RX_DIV_FORCE_1)
  1735. wlapi_bmac_mhf(pi->sh->physhim, MHF1, MHF1_ANTDIV,
  1736. MHF1_ANTDIV, BRCM_BAND_ALL);
  1737. else
  1738. wlapi_bmac_mhf(pi->sh->physhim, MHF1, MHF1_ANTDIV, 0,
  1739. BRCM_BAND_ALL);
  1740. }
  1741. if (ISNPHY(pi))
  1742. return;
  1743. if (!pi->sh->clk)
  1744. return;
  1745. suspend = (0 == (bcma_read32(pi->d11core, D11REGOFFS(maccontrol)) &
  1746. MCTL_EN_MAC));
  1747. if (!suspend)
  1748. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1749. if (ISLCNPHY(pi)) {
  1750. if (val > ANT_RX_DIV_FORCE_1) {
  1751. mod_phy_reg(pi, 0x410, (0x1 << 1), 0x01 << 1);
  1752. mod_phy_reg(pi, 0x410,
  1753. (0x1 << 0),
  1754. ((ANT_RX_DIV_START_1 == val) ? 1 : 0) << 0);
  1755. } else {
  1756. mod_phy_reg(pi, 0x410, (0x1 << 1), 0x00 << 1);
  1757. mod_phy_reg(pi, 0x410, (0x1 << 0), (u16) val << 0);
  1758. }
  1759. }
  1760. if (!suspend)
  1761. wlapi_enable_mac(pi->sh->physhim);
  1762. return;
  1763. }
  1764. static bool
  1765. wlc_phy_noise_calc_phy(struct brcms_phy *pi, u32 *cmplx_pwr, s8 *pwr_ant)
  1766. {
  1767. s8 cmplx_pwr_dbm[PHY_CORE_MAX];
  1768. u8 i;
  1769. memset((u8 *) cmplx_pwr_dbm, 0, sizeof(cmplx_pwr_dbm));
  1770. wlc_phy_compute_dB(cmplx_pwr, cmplx_pwr_dbm, pi->pubpi.phy_corenum);
  1771. for (i = 0; i < pi->pubpi.phy_corenum; i++) {
  1772. if (NREV_GE(pi->pubpi.phy_rev, 3))
  1773. cmplx_pwr_dbm[i] += (s8) PHY_NOISE_OFFSETFACT_4322;
  1774. else
  1775. cmplx_pwr_dbm[i] += (s8) (16 - (15) * 3 - 70);
  1776. }
  1777. for (i = 0; i < pi->pubpi.phy_corenum; i++) {
  1778. pi->nphy_noise_win[i][pi->nphy_noise_index] = cmplx_pwr_dbm[i];
  1779. pwr_ant[i] = cmplx_pwr_dbm[i];
  1780. }
  1781. pi->nphy_noise_index =
  1782. MODINC_POW2(pi->nphy_noise_index, PHY_NOISE_WINDOW_SZ);
  1783. return true;
  1784. }
  1785. static void wlc_phy_noise_cb(struct brcms_phy *pi, u8 channel, s8 noise_dbm)
  1786. {
  1787. if (!pi->phynoise_state)
  1788. return;
  1789. if (pi->phynoise_state & PHY_NOISE_STATE_MON) {
  1790. if (pi->phynoise_chan_watchdog == channel) {
  1791. pi->sh->phy_noise_window[pi->sh->phy_noise_index] =
  1792. noise_dbm;
  1793. pi->sh->phy_noise_index =
  1794. MODINC(pi->sh->phy_noise_index, MA_WINDOW_SZ);
  1795. }
  1796. pi->phynoise_state &= ~PHY_NOISE_STATE_MON;
  1797. }
  1798. if (pi->phynoise_state & PHY_NOISE_STATE_EXTERNAL)
  1799. pi->phynoise_state &= ~PHY_NOISE_STATE_EXTERNAL;
  1800. }
  1801. static s8 wlc_phy_noise_read_shmem(struct brcms_phy *pi)
  1802. {
  1803. u32 cmplx_pwr[PHY_CORE_MAX];
  1804. s8 noise_dbm_ant[PHY_CORE_MAX];
  1805. u16 lo, hi;
  1806. u32 cmplx_pwr_tot = 0;
  1807. s8 noise_dbm = PHY_NOISE_FIXED_VAL_NPHY;
  1808. u8 idx, core;
  1809. memset((u8 *) cmplx_pwr, 0, sizeof(cmplx_pwr));
  1810. memset((u8 *) noise_dbm_ant, 0, sizeof(noise_dbm_ant));
  1811. for (idx = 0, core = 0; core < pi->pubpi.phy_corenum; idx += 2,
  1812. core++) {
  1813. lo = wlapi_bmac_read_shm(pi->sh->physhim, M_PWRIND_MAP(idx));
  1814. hi = wlapi_bmac_read_shm(pi->sh->physhim,
  1815. M_PWRIND_MAP(idx + 1));
  1816. cmplx_pwr[core] = (hi << 16) + lo;
  1817. cmplx_pwr_tot += cmplx_pwr[core];
  1818. if (cmplx_pwr[core] == 0)
  1819. noise_dbm_ant[core] = PHY_NOISE_FIXED_VAL_NPHY;
  1820. else
  1821. cmplx_pwr[core] >>= PHY_NOISE_SAMPLE_LOG_NUM_UCODE;
  1822. }
  1823. if (cmplx_pwr_tot != 0)
  1824. wlc_phy_noise_calc_phy(pi, cmplx_pwr, noise_dbm_ant);
  1825. for (core = 0; core < pi->pubpi.phy_corenum; core++) {
  1826. pi->nphy_noise_win[core][pi->nphy_noise_index] =
  1827. noise_dbm_ant[core];
  1828. if (noise_dbm_ant[core] > noise_dbm)
  1829. noise_dbm = noise_dbm_ant[core];
  1830. }
  1831. pi->nphy_noise_index =
  1832. MODINC_POW2(pi->nphy_noise_index, PHY_NOISE_WINDOW_SZ);
  1833. return noise_dbm;
  1834. }
  1835. void wlc_phy_noise_sample_intr(struct brcms_phy_pub *pih)
  1836. {
  1837. struct brcms_phy *pi = (struct brcms_phy *) pih;
  1838. u16 jssi_aux;
  1839. u8 channel = 0;
  1840. s8 noise_dbm = PHY_NOISE_FIXED_VAL_NPHY;
  1841. if (ISLCNPHY(pi)) {
  1842. u32 cmplx_pwr, cmplx_pwr0, cmplx_pwr1;
  1843. u16 lo, hi;
  1844. s32 pwr_offset_dB, gain_dB;
  1845. u16 status_0, status_1;
  1846. jssi_aux = wlapi_bmac_read_shm(pi->sh->physhim, M_JSSI_AUX);
  1847. channel = jssi_aux & D11_CURCHANNEL_MAX;
  1848. lo = wlapi_bmac_read_shm(pi->sh->physhim, M_PWRIND_MAP0);
  1849. hi = wlapi_bmac_read_shm(pi->sh->physhim, M_PWRIND_MAP1);
  1850. cmplx_pwr0 = (hi << 16) + lo;
  1851. lo = wlapi_bmac_read_shm(pi->sh->physhim, M_PWRIND_MAP2);
  1852. hi = wlapi_bmac_read_shm(pi->sh->physhim, M_PWRIND_MAP3);
  1853. cmplx_pwr1 = (hi << 16) + lo;
  1854. cmplx_pwr = (cmplx_pwr0 + cmplx_pwr1) >> 6;
  1855. status_0 = 0x44;
  1856. status_1 = wlapi_bmac_read_shm(pi->sh->physhim, M_JSSI_0);
  1857. if ((cmplx_pwr > 0 && cmplx_pwr < 500)
  1858. && ((status_1 & 0xc000) == 0x4000)) {
  1859. wlc_phy_compute_dB(&cmplx_pwr, &noise_dbm,
  1860. pi->pubpi.phy_corenum);
  1861. pwr_offset_dB = (read_phy_reg(pi, 0x434) & 0xFF);
  1862. if (pwr_offset_dB > 127)
  1863. pwr_offset_dB -= 256;
  1864. noise_dbm += (s8) (pwr_offset_dB - 30);
  1865. gain_dB = (status_0 & 0x1ff);
  1866. noise_dbm -= (s8) (gain_dB);
  1867. } else {
  1868. noise_dbm = PHY_NOISE_FIXED_VAL_LCNPHY;
  1869. }
  1870. } else if (ISNPHY(pi)) {
  1871. jssi_aux = wlapi_bmac_read_shm(pi->sh->physhim, M_JSSI_AUX);
  1872. channel = jssi_aux & D11_CURCHANNEL_MAX;
  1873. noise_dbm = wlc_phy_noise_read_shmem(pi);
  1874. }
  1875. wlc_phy_noise_cb(pi, channel, noise_dbm);
  1876. }
  1877. static void
  1878. wlc_phy_noise_sample_request(struct brcms_phy_pub *pih, u8 reason, u8 ch)
  1879. {
  1880. struct brcms_phy *pi = (struct brcms_phy *) pih;
  1881. s8 noise_dbm = PHY_NOISE_FIXED_VAL_NPHY;
  1882. bool sampling_in_progress = (pi->phynoise_state != 0);
  1883. bool wait_for_intr = true;
  1884. switch (reason) {
  1885. case PHY_NOISE_SAMPLE_MON:
  1886. pi->phynoise_chan_watchdog = ch;
  1887. pi->phynoise_state |= PHY_NOISE_STATE_MON;
  1888. break;
  1889. case PHY_NOISE_SAMPLE_EXTERNAL:
  1890. pi->phynoise_state |= PHY_NOISE_STATE_EXTERNAL;
  1891. break;
  1892. default:
  1893. break;
  1894. }
  1895. if (sampling_in_progress)
  1896. return;
  1897. pi->phynoise_now = pi->sh->now;
  1898. if (pi->phy_fixed_noise) {
  1899. if (ISNPHY(pi)) {
  1900. pi->nphy_noise_win[WL_ANT_IDX_1][pi->nphy_noise_index] =
  1901. PHY_NOISE_FIXED_VAL_NPHY;
  1902. pi->nphy_noise_win[WL_ANT_IDX_2][pi->nphy_noise_index] =
  1903. PHY_NOISE_FIXED_VAL_NPHY;
  1904. pi->nphy_noise_index = MODINC_POW2(pi->nphy_noise_index,
  1905. PHY_NOISE_WINDOW_SZ);
  1906. noise_dbm = PHY_NOISE_FIXED_VAL_NPHY;
  1907. } else {
  1908. noise_dbm = PHY_NOISE_FIXED_VAL;
  1909. }
  1910. wait_for_intr = false;
  1911. goto done;
  1912. }
  1913. if (ISLCNPHY(pi)) {
  1914. if (!pi->phynoise_polling
  1915. || (reason == PHY_NOISE_SAMPLE_EXTERNAL)) {
  1916. wlapi_bmac_write_shm(pi->sh->physhim, M_JSSI_0, 0);
  1917. wlapi_bmac_write_shm(pi->sh->physhim, M_PWRIND_MAP0, 0);
  1918. wlapi_bmac_write_shm(pi->sh->physhim, M_PWRIND_MAP1, 0);
  1919. wlapi_bmac_write_shm(pi->sh->physhim, M_PWRIND_MAP2, 0);
  1920. wlapi_bmac_write_shm(pi->sh->physhim, M_PWRIND_MAP3, 0);
  1921. bcma_set32(pi->d11core, D11REGOFFS(maccommand),
  1922. MCMD_BG_NOISE);
  1923. } else {
  1924. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1925. wlc_lcnphy_deaf_mode(pi, (bool) 0);
  1926. noise_dbm = (s8) wlc_lcnphy_rx_signal_power(pi, 20);
  1927. wlc_lcnphy_deaf_mode(pi, (bool) 1);
  1928. wlapi_enable_mac(pi->sh->physhim);
  1929. wait_for_intr = false;
  1930. }
  1931. } else if (ISNPHY(pi)) {
  1932. if (!pi->phynoise_polling
  1933. || (reason == PHY_NOISE_SAMPLE_EXTERNAL)) {
  1934. wlapi_bmac_write_shm(pi->sh->physhim, M_PWRIND_MAP0, 0);
  1935. wlapi_bmac_write_shm(pi->sh->physhim, M_PWRIND_MAP1, 0);
  1936. wlapi_bmac_write_shm(pi->sh->physhim, M_PWRIND_MAP2, 0);
  1937. wlapi_bmac_write_shm(pi->sh->physhim, M_PWRIND_MAP3, 0);
  1938. bcma_set32(pi->d11core, D11REGOFFS(maccommand),
  1939. MCMD_BG_NOISE);
  1940. } else {
  1941. struct phy_iq_est est[PHY_CORE_MAX];
  1942. u32 cmplx_pwr[PHY_CORE_MAX];
  1943. s8 noise_dbm_ant[PHY_CORE_MAX];
  1944. u16 log_num_samps, num_samps, classif_state = 0;
  1945. u8 wait_time = 32;
  1946. u8 wait_crs = 0;
  1947. u8 i;
  1948. memset((u8 *) est, 0, sizeof(est));
  1949. memset((u8 *) cmplx_pwr, 0, sizeof(cmplx_pwr));
  1950. memset((u8 *) noise_dbm_ant, 0, sizeof(noise_dbm_ant));
  1951. log_num_samps = PHY_NOISE_SAMPLE_LOG_NUM_NPHY;
  1952. num_samps = 1 << log_num_samps;
  1953. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1954. classif_state = wlc_phy_classifier_nphy(pi, 0, 0);
  1955. wlc_phy_classifier_nphy(pi, 3, 0);
  1956. wlc_phy_rx_iq_est_nphy(pi, est, num_samps, wait_time,
  1957. wait_crs);
  1958. wlc_phy_classifier_nphy(pi, (0x7 << 0), classif_state);
  1959. wlapi_enable_mac(pi->sh->physhim);
  1960. for (i = 0; i < pi->pubpi.phy_corenum; i++)
  1961. cmplx_pwr[i] = (est[i].i_pwr + est[i].q_pwr) >>
  1962. log_num_samps;
  1963. wlc_phy_noise_calc_phy(pi, cmplx_pwr, noise_dbm_ant);
  1964. for (i = 0; i < pi->pubpi.phy_corenum; i++) {
  1965. pi->nphy_noise_win[i][pi->nphy_noise_index] =
  1966. noise_dbm_ant[i];
  1967. if (noise_dbm_ant[i] > noise_dbm)
  1968. noise_dbm = noise_dbm_ant[i];
  1969. }
  1970. pi->nphy_noise_index = MODINC_POW2(pi->nphy_noise_index,
  1971. PHY_NOISE_WINDOW_SZ);
  1972. wait_for_intr = false;
  1973. }
  1974. }
  1975. done:
  1976. if (!wait_for_intr)
  1977. wlc_phy_noise_cb(pi, ch, noise_dbm);
  1978. }
  1979. void wlc_phy_noise_sample_request_external(struct brcms_phy_pub *pih)
  1980. {
  1981. u8 channel;
  1982. channel = CHSPEC_CHANNEL(wlc_phy_chanspec_get(pih));
  1983. wlc_phy_noise_sample_request(pih, PHY_NOISE_SAMPLE_EXTERNAL, channel);
  1984. }
  1985. static const s8 lcnphy_gain_index_offset_for_pkt_rssi[] = {
  1986. 8,
  1987. 8,
  1988. 8,
  1989. 8,
  1990. 8,
  1991. 8,
  1992. 8,
  1993. 9,
  1994. 10,
  1995. 8,
  1996. 8,
  1997. 7,
  1998. 7,
  1999. 1,
  2000. 2,
  2001. 2,
  2002. 2,
  2003. 2,
  2004. 2,
  2005. 2,
  2006. 2,
  2007. 2,
  2008. 2,
  2009. 2,
  2010. 2,
  2011. 2,
  2012. 2,
  2013. 2,
  2014. 2,
  2015. 2,
  2016. 2,
  2017. 2,
  2018. 1,
  2019. 1,
  2020. 0,
  2021. 0,
  2022. 0,
  2023. 0
  2024. };
  2025. void wlc_phy_compute_dB(u32 *cmplx_pwr, s8 *p_cmplx_pwr_dB, u8 core)
  2026. {
  2027. u8 msb, secondmsb, i;
  2028. u32 tmp;
  2029. for (i = 0; i < core; i++) {
  2030. secondmsb = 0;
  2031. tmp = cmplx_pwr[i];
  2032. msb = fls(tmp);
  2033. if (msb)
  2034. secondmsb = (u8) ((tmp >> (--msb - 1)) & 1);
  2035. p_cmplx_pwr_dB[i] = (s8) (3 * msb + 2 * secondmsb);
  2036. }
  2037. }
  2038. int wlc_phy_rssi_compute(struct brcms_phy_pub *pih,
  2039. struct d11rxhdr *rxh)
  2040. {
  2041. int rssi = rxh->PhyRxStatus_1 & PRXS1_JSSI_MASK;
  2042. uint radioid = pih->radioid;
  2043. struct brcms_phy *pi = (struct brcms_phy *) pih;
  2044. if ((pi->sh->corerev >= 11)
  2045. && !(rxh->RxStatus2 & RXS_PHYRXST_VALID)) {
  2046. rssi = BRCMS_RSSI_INVALID;
  2047. goto end;
  2048. }
  2049. if (ISLCNPHY(pi)) {
  2050. u8 gidx = (rxh->PhyRxStatus_2 & 0xFC00) >> 10;
  2051. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  2052. if (rssi > 127)
  2053. rssi -= 256;
  2054. rssi = rssi + lcnphy_gain_index_offset_for_pkt_rssi[gidx];
  2055. if ((rssi > -46) && (gidx > 18))
  2056. rssi = rssi + 7;
  2057. rssi = rssi + pi_lcn->lcnphy_pkteng_rssi_slope;
  2058. rssi = rssi + 2;
  2059. }
  2060. if (ISLCNPHY(pi)) {
  2061. if (rssi > 127)
  2062. rssi -= 256;
  2063. } else if (radioid == BCM2055_ID || radioid == BCM2056_ID
  2064. || radioid == BCM2057_ID) {
  2065. rssi = wlc_phy_rssi_compute_nphy(pi, rxh);
  2066. }
  2067. end:
  2068. return rssi;
  2069. }
  2070. void wlc_phy_freqtrack_start(struct brcms_phy_pub *pih)
  2071. {
  2072. return;
  2073. }
  2074. void wlc_phy_freqtrack_end(struct brcms_phy_pub *pih)
  2075. {
  2076. return;
  2077. }
  2078. void wlc_phy_set_deaf(struct brcms_phy_pub *ppi, bool user_flag)
  2079. {
  2080. struct brcms_phy *pi;
  2081. pi = (struct brcms_phy *) ppi;
  2082. if (ISLCNPHY(pi))
  2083. wlc_lcnphy_deaf_mode(pi, true);
  2084. else if (ISNPHY(pi))
  2085. wlc_nphy_deaf_mode(pi, true);
  2086. }
  2087. void wlc_phy_watchdog(struct brcms_phy_pub *pih)
  2088. {
  2089. struct brcms_phy *pi = (struct brcms_phy *) pih;
  2090. bool delay_phy_cal = false;
  2091. pi->sh->now++;
  2092. if (!pi->watchdog_override)
  2093. return;
  2094. if (!(SCAN_RM_IN_PROGRESS(pi) || PLT_INPROG_PHY(pi)))
  2095. wlc_phy_noise_sample_request((struct brcms_phy_pub *) pi,
  2096. PHY_NOISE_SAMPLE_MON,
  2097. CHSPEC_CHANNEL(pi->
  2098. radio_chanspec));
  2099. if (pi->phynoise_state && (pi->sh->now - pi->phynoise_now) > 5)
  2100. pi->phynoise_state = 0;
  2101. if ((!pi->phycal_txpower) ||
  2102. ((pi->sh->now - pi->phycal_txpower) >= pi->sh->fast_timer)) {
  2103. if (!SCAN_INPROG_PHY(pi) && wlc_phy_cal_txpower_recalc_sw(pi))
  2104. pi->phycal_txpower = pi->sh->now;
  2105. }
  2106. if ((SCAN_RM_IN_PROGRESS(pi) || PLT_INPROG_PHY(pi)
  2107. || ASSOC_INPROG_PHY(pi)))
  2108. return;
  2109. if (ISNPHY(pi) && !pi->disable_percal && !delay_phy_cal) {
  2110. if ((pi->nphy_perical != PHY_PERICAL_DISABLE) &&
  2111. (pi->nphy_perical != PHY_PERICAL_MANUAL) &&
  2112. ((pi->sh->now - pi->nphy_perical_last) >=
  2113. pi->sh->glacial_timer))
  2114. wlc_phy_cal_perical((struct brcms_phy_pub *) pi,
  2115. PHY_PERICAL_WATCHDOG);
  2116. wlc_phy_txpwr_papd_cal_nphy(pi);
  2117. }
  2118. if (ISLCNPHY(pi)) {
  2119. if (pi->phy_forcecal ||
  2120. ((pi->sh->now - pi->phy_lastcal) >=
  2121. pi->sh->glacial_timer)) {
  2122. if (!(SCAN_RM_IN_PROGRESS(pi) || ASSOC_INPROG_PHY(pi)))
  2123. wlc_lcnphy_calib_modes(
  2124. pi,
  2125. LCNPHY_PERICAL_TEMPBASED_TXPWRCTRL);
  2126. if (!
  2127. (SCAN_RM_IN_PROGRESS(pi) || PLT_INPROG_PHY(pi)
  2128. || ASSOC_INPROG_PHY(pi)
  2129. || pi->carrier_suppr_disable
  2130. || pi->disable_percal))
  2131. wlc_lcnphy_calib_modes(pi,
  2132. PHY_PERICAL_WATCHDOG);
  2133. }
  2134. }
  2135. }
  2136. void wlc_phy_BSSinit(struct brcms_phy_pub *pih, bool bonlyap, int rssi)
  2137. {
  2138. struct brcms_phy *pi = (struct brcms_phy *) pih;
  2139. uint i;
  2140. uint k;
  2141. for (i = 0; i < MA_WINDOW_SZ; i++)
  2142. pi->sh->phy_noise_window[i] = (s8) (rssi & 0xff);
  2143. if (ISLCNPHY(pi)) {
  2144. for (i = 0; i < MA_WINDOW_SZ; i++)
  2145. pi->sh->phy_noise_window[i] =
  2146. PHY_NOISE_FIXED_VAL_LCNPHY;
  2147. }
  2148. pi->sh->phy_noise_index = 0;
  2149. for (i = 0; i < PHY_NOISE_WINDOW_SZ; i++) {
  2150. for (k = WL_ANT_IDX_1; k < WL_ANT_RX_MAX; k++)
  2151. pi->nphy_noise_win[k][i] = PHY_NOISE_FIXED_VAL_NPHY;
  2152. }
  2153. pi->nphy_noise_index = 0;
  2154. }
  2155. void
  2156. wlc_phy_papd_decode_epsilon(u32 epsilon, s32 *eps_real, s32 *eps_imag)
  2157. {
  2158. *eps_imag = (epsilon >> 13);
  2159. if (*eps_imag > 0xfff)
  2160. *eps_imag -= 0x2000;
  2161. *eps_real = (epsilon & 0x1fff);
  2162. if (*eps_real > 0xfff)
  2163. *eps_real -= 0x2000;
  2164. }
  2165. void wlc_phy_cal_perical_mphase_reset(struct brcms_phy *pi)
  2166. {
  2167. wlapi_del_timer(pi->phycal_timer);
  2168. pi->cal_type_override = PHY_PERICAL_AUTO;
  2169. pi->mphase_cal_phase_id = MPHASE_CAL_STATE_IDLE;
  2170. pi->mphase_txcal_cmdidx = 0;
  2171. }
  2172. static void
  2173. wlc_phy_cal_perical_mphase_schedule(struct brcms_phy *pi, uint delay)
  2174. {
  2175. if ((pi->nphy_perical != PHY_PERICAL_MPHASE) &&
  2176. (pi->nphy_perical != PHY_PERICAL_MANUAL))
  2177. return;
  2178. wlapi_del_timer(pi->phycal_timer);
  2179. pi->mphase_cal_phase_id = MPHASE_CAL_STATE_INIT;
  2180. wlapi_add_timer(pi->phycal_timer, delay, 0);
  2181. }
  2182. void wlc_phy_cal_perical(struct brcms_phy_pub *pih, u8 reason)
  2183. {
  2184. s16 nphy_currtemp = 0;
  2185. s16 delta_temp = 0;
  2186. bool do_periodic_cal = true;
  2187. struct brcms_phy *pi = (struct brcms_phy *) pih;
  2188. if (!ISNPHY(pi))
  2189. return;
  2190. if ((pi->nphy_perical == PHY_PERICAL_DISABLE) ||
  2191. (pi->nphy_perical == PHY_PERICAL_MANUAL))
  2192. return;
  2193. switch (reason) {
  2194. case PHY_PERICAL_DRIVERUP:
  2195. break;
  2196. case PHY_PERICAL_PHYINIT:
  2197. if (pi->nphy_perical == PHY_PERICAL_MPHASE) {
  2198. if (PHY_PERICAL_MPHASE_PENDING(pi))
  2199. wlc_phy_cal_perical_mphase_reset(pi);
  2200. wlc_phy_cal_perical_mphase_schedule(
  2201. pi,
  2202. PHY_PERICAL_INIT_DELAY);
  2203. }
  2204. break;
  2205. case PHY_PERICAL_JOIN_BSS:
  2206. case PHY_PERICAL_START_IBSS:
  2207. case PHY_PERICAL_UP_BSS:
  2208. if ((pi->nphy_perical == PHY_PERICAL_MPHASE) &&
  2209. PHY_PERICAL_MPHASE_PENDING(pi))
  2210. wlc_phy_cal_perical_mphase_reset(pi);
  2211. pi->first_cal_after_assoc = true;
  2212. pi->cal_type_override = PHY_PERICAL_FULL;
  2213. if (pi->phycal_tempdelta)
  2214. pi->nphy_lastcal_temp = wlc_phy_tempsense_nphy(pi);
  2215. wlc_phy_cal_perical_nphy_run(pi, PHY_PERICAL_FULL);
  2216. break;
  2217. case PHY_PERICAL_WATCHDOG:
  2218. if (pi->phycal_tempdelta) {
  2219. nphy_currtemp = wlc_phy_tempsense_nphy(pi);
  2220. delta_temp =
  2221. (nphy_currtemp > pi->nphy_lastcal_temp) ?
  2222. nphy_currtemp - pi->nphy_lastcal_temp :
  2223. pi->nphy_lastcal_temp - nphy_currtemp;
  2224. if ((delta_temp < (s16) pi->phycal_tempdelta) &&
  2225. (pi->nphy_txiqlocal_chanspec ==
  2226. pi->radio_chanspec))
  2227. do_periodic_cal = false;
  2228. else
  2229. pi->nphy_lastcal_temp = nphy_currtemp;
  2230. }
  2231. if (do_periodic_cal) {
  2232. if (pi->nphy_perical == PHY_PERICAL_MPHASE) {
  2233. if (!PHY_PERICAL_MPHASE_PENDING(pi))
  2234. wlc_phy_cal_perical_mphase_schedule(
  2235. pi,
  2236. PHY_PERICAL_WDOG_DELAY);
  2237. } else if (pi->nphy_perical == PHY_PERICAL_SPHASE)
  2238. wlc_phy_cal_perical_nphy_run(pi,
  2239. PHY_PERICAL_AUTO);
  2240. }
  2241. break;
  2242. default:
  2243. break;
  2244. }
  2245. }
  2246. void wlc_phy_cal_perical_mphase_restart(struct brcms_phy *pi)
  2247. {
  2248. pi->mphase_cal_phase_id = MPHASE_CAL_STATE_INIT;
  2249. pi->mphase_txcal_cmdidx = 0;
  2250. }
  2251. u8 wlc_phy_nbits(s32 value)
  2252. {
  2253. s32 abs_val;
  2254. u8 nbits = 0;
  2255. abs_val = abs(value);
  2256. while ((abs_val >> nbits) > 0)
  2257. nbits++;
  2258. return nbits;
  2259. }
  2260. void wlc_phy_stf_chain_init(struct brcms_phy_pub *pih, u8 txchain, u8 rxchain)
  2261. {
  2262. struct brcms_phy *pi = (struct brcms_phy *) pih;
  2263. pi->sh->hw_phytxchain = txchain;
  2264. pi->sh->hw_phyrxchain = rxchain;
  2265. pi->sh->phytxchain = txchain;
  2266. pi->sh->phyrxchain = rxchain;
  2267. pi->pubpi.phy_corenum = (u8)hweight8(pi->sh->phyrxchain);
  2268. }
  2269. void wlc_phy_stf_chain_set(struct brcms_phy_pub *pih, u8 txchain, u8 rxchain)
  2270. {
  2271. struct brcms_phy *pi = (struct brcms_phy *) pih;
  2272. pi->sh->phytxchain = txchain;
  2273. if (ISNPHY(pi))
  2274. wlc_phy_rxcore_setstate_nphy(pih, rxchain);
  2275. pi->pubpi.phy_corenum = (u8)hweight8(pi->sh->phyrxchain);
  2276. }
  2277. void wlc_phy_stf_chain_get(struct brcms_phy_pub *pih, u8 *txchain, u8 *rxchain)
  2278. {
  2279. struct brcms_phy *pi = (struct brcms_phy *) pih;
  2280. *txchain = pi->sh->phytxchain;
  2281. *rxchain = pi->sh->phyrxchain;
  2282. }
  2283. u8 wlc_phy_stf_chain_active_get(struct brcms_phy_pub *pih)
  2284. {
  2285. s16 nphy_currtemp;
  2286. u8 active_bitmap;
  2287. struct brcms_phy *pi = (struct brcms_phy *) pih;
  2288. active_bitmap = (pi->phy_txcore_heatedup) ? 0x31 : 0x33;
  2289. if (!pi->watchdog_override)
  2290. return active_bitmap;
  2291. if (NREV_GE(pi->pubpi.phy_rev, 6)) {
  2292. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  2293. nphy_currtemp = wlc_phy_tempsense_nphy(pi);
  2294. wlapi_enable_mac(pi->sh->physhim);
  2295. if (!pi->phy_txcore_heatedup) {
  2296. if (nphy_currtemp >= pi->phy_txcore_disable_temp) {
  2297. active_bitmap &= 0xFD;
  2298. pi->phy_txcore_heatedup = true;
  2299. }
  2300. } else {
  2301. if (nphy_currtemp <= pi->phy_txcore_enable_temp) {
  2302. active_bitmap |= 0x2;
  2303. pi->phy_txcore_heatedup = false;
  2304. }
  2305. }
  2306. }
  2307. return active_bitmap;
  2308. }
  2309. s8 wlc_phy_stf_ssmode_get(struct brcms_phy_pub *pih, u16 chanspec)
  2310. {
  2311. struct brcms_phy *pi = (struct brcms_phy *) pih;
  2312. u8 siso_mcs_id, cdd_mcs_id;
  2313. siso_mcs_id =
  2314. (CHSPEC_IS40(chanspec)) ? TXP_FIRST_MCS_40_SISO :
  2315. TXP_FIRST_MCS_20_SISO;
  2316. cdd_mcs_id =
  2317. (CHSPEC_IS40(chanspec)) ? TXP_FIRST_MCS_40_CDD :
  2318. TXP_FIRST_MCS_20_CDD;
  2319. if (pi->tx_power_target[siso_mcs_id] >
  2320. (pi->tx_power_target[cdd_mcs_id] + 12))
  2321. return PHY_TXC1_MODE_SISO;
  2322. else
  2323. return PHY_TXC1_MODE_CDD;
  2324. }
  2325. const u8 *wlc_phy_get_ofdm_rate_lookup(void)
  2326. {
  2327. return ofdm_rate_lookup;
  2328. }
  2329. void wlc_lcnphy_epa_switch(struct brcms_phy *pi, bool mode)
  2330. {
  2331. if ((pi->sh->chip == BCM4313_CHIP_ID) &&
  2332. (pi->sh->boardflags & BFL_FEM)) {
  2333. if (mode) {
  2334. u16 txant = 0;
  2335. txant = wlapi_bmac_get_txant(pi->sh->physhim);
  2336. if (txant == 1) {
  2337. mod_phy_reg(pi, 0x44d, (0x1 << 2), (1) << 2);
  2338. mod_phy_reg(pi, 0x44c, (0x1 << 2), (1) << 2);
  2339. }
  2340. ai_cc_reg(pi->sh->sih,
  2341. offsetof(struct chipcregs, gpiocontrol),
  2342. ~0x0, 0x0);
  2343. ai_cc_reg(pi->sh->sih,
  2344. offsetof(struct chipcregs, gpioout),
  2345. 0x40, 0x40);
  2346. ai_cc_reg(pi->sh->sih,
  2347. offsetof(struct chipcregs, gpioouten),
  2348. 0x40, 0x40);
  2349. } else {
  2350. mod_phy_reg(pi, 0x44c, (0x1 << 2), (0) << 2);
  2351. mod_phy_reg(pi, 0x44d, (0x1 << 2), (0) << 2);
  2352. ai_cc_reg(pi->sh->sih,
  2353. offsetof(struct chipcregs, gpioout),
  2354. 0x40, 0x00);
  2355. ai_cc_reg(pi->sh->sih,
  2356. offsetof(struct chipcregs, gpioouten),
  2357. 0x40, 0x0);
  2358. ai_cc_reg(pi->sh->sih,
  2359. offsetof(struct chipcregs, gpiocontrol),
  2360. ~0x0, 0x40);
  2361. }
  2362. }
  2363. }
  2364. void wlc_phy_ldpc_override_set(struct brcms_phy_pub *ppi, bool ldpc)
  2365. {
  2366. return;
  2367. }
  2368. void
  2369. wlc_phy_get_pwrdet_offsets(struct brcms_phy *pi, s8 *cckoffset, s8 *ofdmoffset)
  2370. {
  2371. *cckoffset = 0;
  2372. *ofdmoffset = 0;
  2373. }
  2374. s8 wlc_phy_upd_rssi_offset(struct brcms_phy *pi, s8 rssi, u16 chanspec)
  2375. {
  2376. return rssi;
  2377. }
  2378. bool wlc_phy_txpower_ipa_ison(struct brcms_phy_pub *ppi)
  2379. {
  2380. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  2381. if (ISNPHY(pi))
  2382. return wlc_phy_n_txpower_ipa_ison(pi);
  2383. else
  2384. return 0;
  2385. }