phy_cmn.c 70 KB

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