phy_cmn.c 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978
  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. u16 dummy;
  131. dummy = R_REG(&pi->regs->phyversion);
  132. pi->phy_wreg = 0;
  133. wlapi_bmac_mctrl(pi->sh->physhim, MCTL_LOCK_RADIO, 0);
  134. }
  135. u16 read_radio_reg(struct brcms_phy *pi, u16 addr)
  136. {
  137. u16 data;
  138. if ((addr == RADIO_IDCODE))
  139. return 0xffff;
  140. switch (pi->pubpi.phy_type) {
  141. case PHY_TYPE_N:
  142. if (!CONF_HAS(PHYTYPE, PHY_TYPE_N))
  143. break;
  144. if (NREV_GE(pi->pubpi.phy_rev, 7))
  145. addr |= RADIO_2057_READ_OFF;
  146. else
  147. addr |= RADIO_2055_READ_OFF;
  148. break;
  149. case PHY_TYPE_LCN:
  150. if (!CONF_HAS(PHYTYPE, PHY_TYPE_LCN))
  151. break;
  152. addr |= RADIO_2064_READ_OFF;
  153. break;
  154. default:
  155. break;
  156. }
  157. if ((D11REV_GE(pi->sh->corerev, 24)) ||
  158. (D11REV_IS(pi->sh->corerev, 22)
  159. && (pi->pubpi.phy_type != PHY_TYPE_SSN))) {
  160. W_REG_FLUSH(&pi->regs->radioregaddr, addr);
  161. data = R_REG(&pi->regs->radioregdata);
  162. } else {
  163. W_REG_FLUSH(&pi->regs->phy4waddr, addr);
  164. data = R_REG(&pi->regs->phy4wdatalo);
  165. }
  166. pi->phy_wreg = 0;
  167. return data;
  168. }
  169. void write_radio_reg(struct brcms_phy *pi, u16 addr, u16 val)
  170. {
  171. if ((D11REV_GE(pi->sh->corerev, 24)) ||
  172. (D11REV_IS(pi->sh->corerev, 22)
  173. && (pi->pubpi.phy_type != PHY_TYPE_SSN))) {
  174. W_REG_FLUSH(&pi->regs->radioregaddr, addr);
  175. W_REG(&pi->regs->radioregdata, val);
  176. } else {
  177. W_REG_FLUSH(&pi->regs->phy4waddr, addr);
  178. W_REG(&pi->regs->phy4wdatalo, val);
  179. }
  180. if (++pi->phy_wreg >= pi->phy_wreg_limit) {
  181. (void)R_REG(&pi->regs->maccontrol);
  182. pi->phy_wreg = 0;
  183. }
  184. }
  185. static u32 read_radio_id(struct brcms_phy *pi)
  186. {
  187. u32 id;
  188. if (D11REV_GE(pi->sh->corerev, 24)) {
  189. u32 b0, b1, b2;
  190. W_REG_FLUSH(&pi->regs->radioregaddr, 0);
  191. b0 = (u32) R_REG(&pi->regs->radioregdata);
  192. W_REG_FLUSH(&pi->regs->radioregaddr, 1);
  193. b1 = (u32) R_REG(&pi->regs->radioregdata);
  194. W_REG_FLUSH(&pi->regs->radioregaddr, 2);
  195. b2 = (u32) R_REG(&pi->regs->radioregdata);
  196. id = ((b0 & 0xf) << 28) | (((b2 << 8) | b1) << 12) | ((b0 >> 4)
  197. & 0xf);
  198. } else {
  199. W_REG_FLUSH(&pi->regs->phy4waddr, RADIO_IDCODE);
  200. id = (u32) R_REG(&pi->regs->phy4wdatalo);
  201. id |= (u32) R_REG(&pi->regs->phy4wdatahi) << 16;
  202. }
  203. pi->phy_wreg = 0;
  204. return id;
  205. }
  206. void and_radio_reg(struct brcms_phy *pi, u16 addr, u16 val)
  207. {
  208. u16 rval;
  209. rval = read_radio_reg(pi, addr);
  210. write_radio_reg(pi, addr, (rval & val));
  211. }
  212. void or_radio_reg(struct brcms_phy *pi, u16 addr, u16 val)
  213. {
  214. u16 rval;
  215. rval = read_radio_reg(pi, addr);
  216. write_radio_reg(pi, addr, (rval | val));
  217. }
  218. void xor_radio_reg(struct brcms_phy *pi, u16 addr, u16 mask)
  219. {
  220. u16 rval;
  221. rval = read_radio_reg(pi, addr);
  222. write_radio_reg(pi, addr, (rval ^ mask));
  223. }
  224. void mod_radio_reg(struct brcms_phy *pi, u16 addr, u16 mask, u16 val)
  225. {
  226. u16 rval;
  227. rval = read_radio_reg(pi, addr);
  228. write_radio_reg(pi, addr, (rval & ~mask) | (val & mask));
  229. }
  230. void write_phy_channel_reg(struct brcms_phy *pi, uint val)
  231. {
  232. W_REG(&pi->regs->phychannel, val);
  233. }
  234. u16 read_phy_reg(struct brcms_phy *pi, u16 addr)
  235. {
  236. struct d11regs __iomem *regs;
  237. regs = pi->regs;
  238. W_REG_FLUSH(&regs->phyregaddr, addr);
  239. pi->phy_wreg = 0;
  240. return R_REG(&regs->phyregdata);
  241. }
  242. void write_phy_reg(struct brcms_phy *pi, u16 addr, u16 val)
  243. {
  244. struct d11regs __iomem *regs;
  245. regs = pi->regs;
  246. #ifdef CONFIG_BCM47XX
  247. W_REG_FLUSH(&regs->phyregaddr, addr);
  248. W_REG(&regs->phyregdata, val);
  249. if (addr == 0x72)
  250. (void)R_REG(&regs->phyregdata);
  251. #else
  252. W_REG((u32 __iomem *)(&regs->phyregaddr), addr | (val << 16));
  253. if (++pi->phy_wreg >= pi->phy_wreg_limit) {
  254. pi->phy_wreg = 0;
  255. (void)R_REG(&regs->phyversion);
  256. }
  257. #endif
  258. }
  259. void and_phy_reg(struct brcms_phy *pi, u16 addr, u16 val)
  260. {
  261. struct d11regs __iomem *regs;
  262. regs = pi->regs;
  263. W_REG_FLUSH(&regs->phyregaddr, addr);
  264. W_REG(&regs->phyregdata, (R_REG(&regs->phyregdata) & val));
  265. pi->phy_wreg = 0;
  266. }
  267. void or_phy_reg(struct brcms_phy *pi, u16 addr, u16 val)
  268. {
  269. struct d11regs __iomem *regs;
  270. regs = pi->regs;
  271. W_REG_FLUSH(&regs->phyregaddr, addr);
  272. W_REG(&regs->phyregdata, (R_REG(&regs->phyregdata) | val));
  273. pi->phy_wreg = 0;
  274. }
  275. void mod_phy_reg(struct brcms_phy *pi, u16 addr, u16 mask, u16 val)
  276. {
  277. struct d11regs __iomem *regs;
  278. regs = pi->regs;
  279. W_REG_FLUSH(&regs->phyregaddr, addr);
  280. W_REG(&regs->phyregdata,
  281. ((R_REG(&regs->phyregdata) & ~mask) | (val & mask)));
  282. pi->phy_wreg = 0;
  283. }
  284. static void wlc_set_phy_uninitted(struct brcms_phy *pi)
  285. {
  286. int i, j;
  287. pi->initialized = false;
  288. pi->tx_vos = 0xffff;
  289. pi->nrssi_table_delta = 0x7fffffff;
  290. pi->rc_cal = 0xffff;
  291. pi->mintxbias = 0xffff;
  292. pi->txpwridx = -1;
  293. if (ISNPHY(pi)) {
  294. pi->phy_spuravoid = SPURAVOID_DISABLE;
  295. if (NREV_GE(pi->pubpi.phy_rev, 3)
  296. && NREV_LT(pi->pubpi.phy_rev, 7))
  297. pi->phy_spuravoid = SPURAVOID_AUTO;
  298. pi->nphy_papd_skip = 0;
  299. pi->nphy_papd_epsilon_offset[0] = 0xf588;
  300. pi->nphy_papd_epsilon_offset[1] = 0xf588;
  301. pi->nphy_txpwr_idx[0] = 128;
  302. pi->nphy_txpwr_idx[1] = 128;
  303. pi->nphy_txpwrindex[0].index_internal = 40;
  304. pi->nphy_txpwrindex[1].index_internal = 40;
  305. pi->phy_pabias = 0;
  306. } else {
  307. pi->phy_spuravoid = SPURAVOID_AUTO;
  308. }
  309. pi->radiopwr = 0xffff;
  310. for (i = 0; i < STATIC_NUM_RF; i++) {
  311. for (j = 0; j < STATIC_NUM_BB; j++)
  312. pi->stats_11b_txpower[i][j] = -1;
  313. }
  314. }
  315. struct shared_phy *wlc_phy_shared_attach(struct shared_phy_params *shp)
  316. {
  317. struct shared_phy *sh;
  318. sh = kzalloc(sizeof(struct shared_phy), GFP_ATOMIC);
  319. if (sh == NULL)
  320. return NULL;
  321. sh->sih = shp->sih;
  322. sh->physhim = shp->physhim;
  323. sh->unit = shp->unit;
  324. sh->corerev = shp->corerev;
  325. sh->vid = shp->vid;
  326. sh->did = shp->did;
  327. sh->chip = shp->chip;
  328. sh->chiprev = shp->chiprev;
  329. sh->chippkg = shp->chippkg;
  330. sh->sromrev = shp->sromrev;
  331. sh->boardtype = shp->boardtype;
  332. sh->boardrev = shp->boardrev;
  333. sh->boardflags = shp->boardflags;
  334. sh->boardflags2 = shp->boardflags2;
  335. sh->fast_timer = PHY_SW_TIMER_FAST;
  336. sh->slow_timer = PHY_SW_TIMER_SLOW;
  337. sh->glacial_timer = PHY_SW_TIMER_GLACIAL;
  338. sh->rssi_mode = RSSI_ANT_MERGE_MAX;
  339. return sh;
  340. }
  341. static void wlc_phy_timercb_phycal(struct brcms_phy *pi)
  342. {
  343. uint delay = 5;
  344. if (PHY_PERICAL_MPHASE_PENDING(pi)) {
  345. if (!pi->sh->up) {
  346. wlc_phy_cal_perical_mphase_reset(pi);
  347. return;
  348. }
  349. if (SCAN_RM_IN_PROGRESS(pi) || PLT_INPROG_PHY(pi)) {
  350. delay = 1000;
  351. wlc_phy_cal_perical_mphase_restart(pi);
  352. } else
  353. wlc_phy_cal_perical_nphy_run(pi, PHY_PERICAL_AUTO);
  354. wlapi_add_timer(pi->phycal_timer, delay, 0);
  355. return;
  356. }
  357. }
  358. static u32 wlc_phy_get_radio_ver(struct brcms_phy *pi)
  359. {
  360. u32 ver;
  361. ver = read_radio_id(pi);
  362. return ver;
  363. }
  364. struct brcms_phy_pub *
  365. wlc_phy_attach(struct shared_phy *sh, struct d11regs __iomem *regs,
  366. int bandtype, struct wiphy *wiphy)
  367. {
  368. struct brcms_phy *pi;
  369. u32 sflags = 0;
  370. uint phyversion;
  371. u32 idcode;
  372. int i;
  373. if (D11REV_IS(sh->corerev, 4))
  374. sflags = SISF_2G_PHY | SISF_5G_PHY;
  375. else
  376. sflags = ai_core_sflags(sh->sih, 0, 0);
  377. if (bandtype == BRCM_BAND_5G) {
  378. if ((sflags & (SISF_5G_PHY | SISF_DB_PHY)) == 0)
  379. return NULL;
  380. }
  381. pi = sh->phy_head;
  382. if ((sflags & SISF_DB_PHY) && pi) {
  383. wlapi_bmac_corereset(pi->sh->physhim, pi->pubpi.coreflags);
  384. pi->refcnt++;
  385. return &pi->pubpi_ro;
  386. }
  387. pi = kzalloc(sizeof(struct brcms_phy), GFP_ATOMIC);
  388. if (pi == NULL)
  389. return NULL;
  390. pi->wiphy = wiphy;
  391. pi->regs = regs;
  392. pi->sh = sh;
  393. pi->phy_init_por = true;
  394. pi->phy_wreg_limit = PHY_WREG_LIMIT;
  395. pi->txpwr_percent = 100;
  396. pi->do_initcal = true;
  397. pi->phycal_tempdelta = 0;
  398. if (bandtype == BRCM_BAND_2G && (sflags & SISF_2G_PHY))
  399. pi->pubpi.coreflags = SICF_GMODE;
  400. wlapi_bmac_corereset(pi->sh->physhim, pi->pubpi.coreflags);
  401. phyversion = R_REG(&pi->regs->phyversion);
  402. pi->pubpi.phy_type = PHY_TYPE(phyversion);
  403. pi->pubpi.phy_rev = phyversion & PV_PV_MASK;
  404. if (pi->pubpi.phy_type == PHY_TYPE_LCNXN) {
  405. pi->pubpi.phy_type = PHY_TYPE_N;
  406. pi->pubpi.phy_rev += LCNXN_BASEREV;
  407. }
  408. pi->pubpi.phy_corenum = PHY_CORE_NUM_2;
  409. pi->pubpi.ana_rev = (phyversion & PV_AV_MASK) >> PV_AV_SHIFT;
  410. if (!pi->pubpi.phy_type == PHY_TYPE_N &&
  411. !pi->pubpi.phy_type == PHY_TYPE_LCN)
  412. goto err;
  413. if (bandtype == BRCM_BAND_5G) {
  414. if (!ISNPHY(pi))
  415. goto err;
  416. } else if (!ISNPHY(pi) && !ISLCNPHY(pi)) {
  417. goto err;
  418. }
  419. wlc_phy_anacore((struct brcms_phy_pub *) pi, ON);
  420. idcode = wlc_phy_get_radio_ver(pi);
  421. pi->pubpi.radioid =
  422. (idcode & IDCODE_ID_MASK) >> IDCODE_ID_SHIFT;
  423. pi->pubpi.radiorev =
  424. (idcode & IDCODE_REV_MASK) >> IDCODE_REV_SHIFT;
  425. pi->pubpi.radiover =
  426. (idcode & IDCODE_VER_MASK) >> IDCODE_VER_SHIFT;
  427. if (!VALID_RADIO(pi, pi->pubpi.radioid))
  428. goto err;
  429. wlc_phy_switch_radio((struct brcms_phy_pub *) pi, OFF);
  430. wlc_set_phy_uninitted(pi);
  431. pi->bw = WL_CHANSPEC_BW_20;
  432. pi->radio_chanspec = (bandtype == BRCM_BAND_2G) ?
  433. ch20mhz_chspec(1) : ch20mhz_chspec(36);
  434. pi->rxiq_samps = PHY_NOISE_SAMPLE_LOG_NUM_NPHY;
  435. pi->rxiq_antsel = ANT_RX_DIV_DEF;
  436. pi->watchdog_override = true;
  437. pi->cal_type_override = PHY_PERICAL_AUTO;
  438. pi->nphy_saved_noisevars.bufcount = 0;
  439. if (ISNPHY(pi))
  440. pi->min_txpower = PHY_TXPWR_MIN_NPHY;
  441. else
  442. pi->min_txpower = PHY_TXPWR_MIN;
  443. pi->sh->phyrxchain = 0x3;
  444. pi->rx2tx_biasentry = -1;
  445. pi->phy_txcore_disable_temp = PHY_CHAIN_TX_DISABLE_TEMP;
  446. pi->phy_txcore_enable_temp =
  447. PHY_CHAIN_TX_DISABLE_TEMP - PHY_HYSTERESIS_DELTATEMP;
  448. pi->phy_tempsense_offset = 0;
  449. pi->phy_txcore_heatedup = false;
  450. pi->nphy_lastcal_temp = -50;
  451. pi->phynoise_polling = true;
  452. if (ISNPHY(pi) || ISLCNPHY(pi))
  453. pi->phynoise_polling = false;
  454. for (i = 0; i < TXP_NUM_RATES; i++) {
  455. pi->txpwr_limit[i] = BRCMS_TXPWR_MAX;
  456. pi->txpwr_env_limit[i] = BRCMS_TXPWR_MAX;
  457. pi->tx_user_target[i] = BRCMS_TXPWR_MAX;
  458. }
  459. pi->radiopwr_override = RADIOPWR_OVERRIDE_DEF;
  460. pi->user_txpwr_at_rfport = false;
  461. if (ISNPHY(pi)) {
  462. pi->phycal_timer = wlapi_init_timer(pi->sh->physhim,
  463. wlc_phy_timercb_phycal,
  464. pi, "phycal");
  465. if (!pi->phycal_timer)
  466. goto err;
  467. if (!wlc_phy_attach_nphy(pi))
  468. goto err;
  469. } else if (ISLCNPHY(pi)) {
  470. if (!wlc_phy_attach_lcnphy(pi))
  471. goto err;
  472. }
  473. pi->refcnt++;
  474. pi->next = pi->sh->phy_head;
  475. sh->phy_head = pi;
  476. memcpy(&pi->pubpi_ro, &pi->pubpi, sizeof(struct brcms_phy_pub));
  477. return &pi->pubpi_ro;
  478. err:
  479. kfree(pi);
  480. return NULL;
  481. }
  482. void wlc_phy_detach(struct brcms_phy_pub *pih)
  483. {
  484. struct brcms_phy *pi = (struct brcms_phy *) pih;
  485. if (pih) {
  486. if (--pi->refcnt)
  487. return;
  488. if (pi->phycal_timer) {
  489. wlapi_free_timer(pi->phycal_timer);
  490. pi->phycal_timer = NULL;
  491. }
  492. if (pi->sh->phy_head == pi)
  493. pi->sh->phy_head = pi->next;
  494. else if (pi->sh->phy_head->next == pi)
  495. pi->sh->phy_head->next = NULL;
  496. if (pi->pi_fptr.detach)
  497. (pi->pi_fptr.detach)(pi);
  498. kfree(pi);
  499. }
  500. }
  501. bool
  502. wlc_phy_get_phyversion(struct brcms_phy_pub *pih, u16 *phytype, u16 *phyrev,
  503. u16 *radioid, u16 *radiover)
  504. {
  505. struct brcms_phy *pi = (struct brcms_phy *) pih;
  506. *phytype = (u16) pi->pubpi.phy_type;
  507. *phyrev = (u16) pi->pubpi.phy_rev;
  508. *radioid = pi->pubpi.radioid;
  509. *radiover = pi->pubpi.radiorev;
  510. return true;
  511. }
  512. bool wlc_phy_get_encore(struct brcms_phy_pub *pih)
  513. {
  514. struct brcms_phy *pi = (struct brcms_phy *) pih;
  515. return pi->pubpi.abgphy_encore;
  516. }
  517. u32 wlc_phy_get_coreflags(struct brcms_phy_pub *pih)
  518. {
  519. struct brcms_phy *pi = (struct brcms_phy *) pih;
  520. return pi->pubpi.coreflags;
  521. }
  522. void wlc_phy_anacore(struct brcms_phy_pub *pih, bool on)
  523. {
  524. struct brcms_phy *pi = (struct brcms_phy *) pih;
  525. if (ISNPHY(pi)) {
  526. if (on) {
  527. if (NREV_GE(pi->pubpi.phy_rev, 3)) {
  528. write_phy_reg(pi, 0xa6, 0x0d);
  529. write_phy_reg(pi, 0x8f, 0x0);
  530. write_phy_reg(pi, 0xa7, 0x0d);
  531. write_phy_reg(pi, 0xa5, 0x0);
  532. } else {
  533. write_phy_reg(pi, 0xa5, 0x0);
  534. }
  535. } else {
  536. if (NREV_GE(pi->pubpi.phy_rev, 3)) {
  537. write_phy_reg(pi, 0x8f, 0x07ff);
  538. write_phy_reg(pi, 0xa6, 0x0fd);
  539. write_phy_reg(pi, 0xa5, 0x07ff);
  540. write_phy_reg(pi, 0xa7, 0x0fd);
  541. } else {
  542. write_phy_reg(pi, 0xa5, 0x7fff);
  543. }
  544. }
  545. } else if (ISLCNPHY(pi)) {
  546. if (on) {
  547. and_phy_reg(pi, 0x43b,
  548. ~((0x1 << 0) | (0x1 << 1) | (0x1 << 2)));
  549. } else {
  550. or_phy_reg(pi, 0x43c,
  551. (0x1 << 0) | (0x1 << 1) | (0x1 << 2));
  552. or_phy_reg(pi, 0x43b,
  553. (0x1 << 0) | (0x1 << 1) | (0x1 << 2));
  554. }
  555. }
  556. }
  557. u32 wlc_phy_clk_bwbits(struct brcms_phy_pub *pih)
  558. {
  559. struct brcms_phy *pi = (struct brcms_phy *) pih;
  560. u32 phy_bw_clkbits = 0;
  561. if (pi && (ISNPHY(pi) || ISLCNPHY(pi))) {
  562. switch (pi->bw) {
  563. case WL_CHANSPEC_BW_10:
  564. phy_bw_clkbits = SICF_BW10;
  565. break;
  566. case WL_CHANSPEC_BW_20:
  567. phy_bw_clkbits = SICF_BW20;
  568. break;
  569. case WL_CHANSPEC_BW_40:
  570. phy_bw_clkbits = SICF_BW40;
  571. break;
  572. default:
  573. break;
  574. }
  575. }
  576. return phy_bw_clkbits;
  577. }
  578. void wlc_phy_por_inform(struct brcms_phy_pub *ppi)
  579. {
  580. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  581. pi->phy_init_por = true;
  582. }
  583. void wlc_phy_edcrs_lock(struct brcms_phy_pub *pih, bool lock)
  584. {
  585. struct brcms_phy *pi = (struct brcms_phy *) pih;
  586. pi->edcrs_threshold_lock = lock;
  587. write_phy_reg(pi, 0x22c, 0x46b);
  588. write_phy_reg(pi, 0x22d, 0x46b);
  589. write_phy_reg(pi, 0x22e, 0x3c0);
  590. write_phy_reg(pi, 0x22f, 0x3c0);
  591. }
  592. void wlc_phy_initcal_enable(struct brcms_phy_pub *pih, bool initcal)
  593. {
  594. struct brcms_phy *pi = (struct brcms_phy *) pih;
  595. pi->do_initcal = initcal;
  596. }
  597. void wlc_phy_hw_clk_state_upd(struct brcms_phy_pub *pih, bool newstate)
  598. {
  599. struct brcms_phy *pi = (struct brcms_phy *) pih;
  600. if (!pi || !pi->sh)
  601. return;
  602. pi->sh->clk = newstate;
  603. }
  604. void wlc_phy_hw_state_upd(struct brcms_phy_pub *pih, bool newstate)
  605. {
  606. struct brcms_phy *pi = (struct brcms_phy *) pih;
  607. if (!pi || !pi->sh)
  608. return;
  609. pi->sh->up = newstate;
  610. }
  611. void wlc_phy_init(struct brcms_phy_pub *pih, u16 chanspec)
  612. {
  613. u32 mc;
  614. void (*phy_init)(struct brcms_phy *) = NULL;
  615. struct brcms_phy *pi = (struct brcms_phy *) pih;
  616. if (pi->init_in_progress)
  617. return;
  618. pi->init_in_progress = true;
  619. pi->radio_chanspec = chanspec;
  620. mc = R_REG(&pi->regs->maccontrol);
  621. if (WARN(mc & MCTL_EN_MAC, "HW error MAC running on init"))
  622. return;
  623. if (!(pi->measure_hold & PHY_HOLD_FOR_SCAN))
  624. pi->measure_hold |= PHY_HOLD_FOR_NOT_ASSOC;
  625. if (WARN(!(ai_core_sflags(pi->sh->sih, 0, 0) & SISF_FCLKA),
  626. "HW error SISF_FCLKA\n"))
  627. return;
  628. phy_init = pi->pi_fptr.init;
  629. if (phy_init == NULL)
  630. return;
  631. wlc_phy_anacore(pih, ON);
  632. if (CHSPEC_BW(pi->radio_chanspec) != pi->bw)
  633. wlapi_bmac_bw_set(pi->sh->physhim,
  634. CHSPEC_BW(pi->radio_chanspec));
  635. pi->nphy_gain_boost = true;
  636. wlc_phy_switch_radio((struct brcms_phy_pub *) pi, ON);
  637. (*phy_init)(pi);
  638. pi->phy_init_por = false;
  639. if (D11REV_IS(pi->sh->corerev, 11) || D11REV_IS(pi->sh->corerev, 12))
  640. wlc_phy_do_dummy_tx(pi, true, OFF);
  641. if (!(ISNPHY(pi)))
  642. wlc_phy_txpower_update_shm(pi);
  643. wlc_phy_ant_rxdiv_set((struct brcms_phy_pub *) pi, pi->sh->rx_antdiv);
  644. pi->init_in_progress = false;
  645. }
  646. void wlc_phy_cal_init(struct brcms_phy_pub *pih)
  647. {
  648. struct brcms_phy *pi = (struct brcms_phy *) pih;
  649. void (*cal_init)(struct brcms_phy *) = NULL;
  650. if (WARN((R_REG(&pi->regs->maccontrol) & MCTL_EN_MAC) != 0,
  651. "HW error: MAC enabled during phy cal\n"))
  652. return;
  653. if (!pi->initialized) {
  654. cal_init = pi->pi_fptr.calinit;
  655. if (cal_init)
  656. (*cal_init)(pi);
  657. pi->initialized = true;
  658. }
  659. }
  660. int wlc_phy_down(struct brcms_phy_pub *pih)
  661. {
  662. struct brcms_phy *pi = (struct brcms_phy *) pih;
  663. int callbacks = 0;
  664. if (pi->phycal_timer
  665. && !wlapi_del_timer(pi->phycal_timer))
  666. callbacks++;
  667. pi->nphy_iqcal_chanspec_2G = 0;
  668. pi->nphy_iqcal_chanspec_5G = 0;
  669. return callbacks;
  670. }
  671. void
  672. wlc_phy_table_addr(struct brcms_phy *pi, uint tbl_id, uint tbl_offset,
  673. u16 tblAddr, u16 tblDataHi, u16 tblDataLo)
  674. {
  675. write_phy_reg(pi, tblAddr, (tbl_id << 10) | tbl_offset);
  676. pi->tbl_data_hi = tblDataHi;
  677. pi->tbl_data_lo = tblDataLo;
  678. if (pi->sh->chip == BCM43224_CHIP_ID &&
  679. pi->sh->chiprev == 1) {
  680. pi->tbl_addr = tblAddr;
  681. pi->tbl_save_id = tbl_id;
  682. pi->tbl_save_offset = tbl_offset;
  683. }
  684. }
  685. void wlc_phy_table_data_write(struct brcms_phy *pi, uint width, u32 val)
  686. {
  687. if ((pi->sh->chip == BCM43224_CHIP_ID) &&
  688. (pi->sh->chiprev == 1) &&
  689. (pi->tbl_save_id == NPHY_TBL_ID_ANTSWCTRLLUT)) {
  690. read_phy_reg(pi, pi->tbl_data_lo);
  691. write_phy_reg(pi, pi->tbl_addr,
  692. (pi->tbl_save_id << 10) | pi->tbl_save_offset);
  693. pi->tbl_save_offset++;
  694. }
  695. if (width == 32) {
  696. write_phy_reg(pi, pi->tbl_data_hi, (u16) (val >> 16));
  697. write_phy_reg(pi, pi->tbl_data_lo, (u16) val);
  698. } else {
  699. write_phy_reg(pi, pi->tbl_data_lo, (u16) val);
  700. }
  701. }
  702. void
  703. wlc_phy_write_table(struct brcms_phy *pi, const struct phytbl_info *ptbl_info,
  704. u16 tblAddr, u16 tblDataHi, u16 tblDataLo)
  705. {
  706. uint idx;
  707. uint tbl_id = ptbl_info->tbl_id;
  708. uint tbl_offset = ptbl_info->tbl_offset;
  709. uint tbl_width = ptbl_info->tbl_width;
  710. const u8 *ptbl_8b = (const u8 *)ptbl_info->tbl_ptr;
  711. const u16 *ptbl_16b = (const u16 *)ptbl_info->tbl_ptr;
  712. const u32 *ptbl_32b = (const u32 *)ptbl_info->tbl_ptr;
  713. write_phy_reg(pi, tblAddr, (tbl_id << 10) | tbl_offset);
  714. for (idx = 0; idx < ptbl_info->tbl_len; idx++) {
  715. if ((pi->sh->chip == BCM43224_CHIP_ID) &&
  716. (pi->sh->chiprev == 1) &&
  717. (tbl_id == NPHY_TBL_ID_ANTSWCTRLLUT)) {
  718. read_phy_reg(pi, tblDataLo);
  719. write_phy_reg(pi, tblAddr,
  720. (tbl_id << 10) | (tbl_offset + idx));
  721. }
  722. if (tbl_width == 32) {
  723. write_phy_reg(pi, tblDataHi,
  724. (u16) (ptbl_32b[idx] >> 16));
  725. write_phy_reg(pi, tblDataLo, (u16) ptbl_32b[idx]);
  726. } else if (tbl_width == 16) {
  727. write_phy_reg(pi, tblDataLo, ptbl_16b[idx]);
  728. } else {
  729. write_phy_reg(pi, tblDataLo, ptbl_8b[idx]);
  730. }
  731. }
  732. }
  733. void
  734. wlc_phy_read_table(struct brcms_phy *pi, const struct phytbl_info *ptbl_info,
  735. u16 tblAddr, u16 tblDataHi, u16 tblDataLo)
  736. {
  737. uint idx;
  738. uint tbl_id = ptbl_info->tbl_id;
  739. uint tbl_offset = ptbl_info->tbl_offset;
  740. uint tbl_width = ptbl_info->tbl_width;
  741. u8 *ptbl_8b = (u8 *)ptbl_info->tbl_ptr;
  742. u16 *ptbl_16b = (u16 *)ptbl_info->tbl_ptr;
  743. u32 *ptbl_32b = (u32 *)ptbl_info->tbl_ptr;
  744. write_phy_reg(pi, tblAddr, (tbl_id << 10) | tbl_offset);
  745. for (idx = 0; idx < ptbl_info->tbl_len; idx++) {
  746. if ((pi->sh->chip == BCM43224_CHIP_ID) &&
  747. (pi->sh->chiprev == 1)) {
  748. (void)read_phy_reg(pi, tblDataLo);
  749. write_phy_reg(pi, tblAddr,
  750. (tbl_id << 10) | (tbl_offset + idx));
  751. }
  752. if (tbl_width == 32) {
  753. ptbl_32b[idx] = read_phy_reg(pi, tblDataLo);
  754. ptbl_32b[idx] |= (read_phy_reg(pi, tblDataHi) << 16);
  755. } else if (tbl_width == 16) {
  756. ptbl_16b[idx] = read_phy_reg(pi, tblDataLo);
  757. } else {
  758. ptbl_8b[idx] = (u8) read_phy_reg(pi, tblDataLo);
  759. }
  760. }
  761. }
  762. uint
  763. wlc_phy_init_radio_regs_allbands(struct brcms_phy *pi,
  764. struct radio_20xx_regs *radioregs)
  765. {
  766. uint i = 0;
  767. do {
  768. if (radioregs[i].do_init)
  769. write_radio_reg(pi, radioregs[i].address,
  770. (u16) radioregs[i].init);
  771. i++;
  772. } while (radioregs[i].address != 0xffff);
  773. return i;
  774. }
  775. uint
  776. wlc_phy_init_radio_regs(struct brcms_phy *pi,
  777. const struct radio_regs *radioregs,
  778. u16 core_offset)
  779. {
  780. uint i = 0;
  781. uint count = 0;
  782. do {
  783. if (CHSPEC_IS5G(pi->radio_chanspec)) {
  784. if (radioregs[i].do_init_a) {
  785. write_radio_reg(pi,
  786. radioregs[i].
  787. address | core_offset,
  788. (u16) radioregs[i].init_a);
  789. if (ISNPHY(pi) && (++count % 4 == 0))
  790. BRCMS_PHY_WAR_PR51571(pi);
  791. }
  792. } else {
  793. if (radioregs[i].do_init_g) {
  794. write_radio_reg(pi,
  795. radioregs[i].
  796. address | core_offset,
  797. (u16) radioregs[i].init_g);
  798. if (ISNPHY(pi) && (++count % 4 == 0))
  799. BRCMS_PHY_WAR_PR51571(pi);
  800. }
  801. }
  802. i++;
  803. } while (radioregs[i].address != 0xffff);
  804. return i;
  805. }
  806. void wlc_phy_do_dummy_tx(struct brcms_phy *pi, bool ofdm, bool pa_on)
  807. {
  808. #define DUMMY_PKT_LEN 20
  809. struct d11regs __iomem *regs = pi->regs;
  810. int i, count;
  811. u8 ofdmpkt[DUMMY_PKT_LEN] = {
  812. 0xcc, 0x01, 0x02, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00,
  813. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
  814. };
  815. u8 cckpkt[DUMMY_PKT_LEN] = {
  816. 0x6e, 0x84, 0x0b, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00,
  817. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
  818. };
  819. u32 *dummypkt;
  820. dummypkt = (u32 *) (ofdm ? ofdmpkt : cckpkt);
  821. wlapi_bmac_write_template_ram(pi->sh->physhim, 0, DUMMY_PKT_LEN,
  822. dummypkt);
  823. W_REG(&regs->xmtsel, 0);
  824. if (D11REV_GE(pi->sh->corerev, 11))
  825. W_REG(&regs->wepctl, 0x100);
  826. else
  827. W_REG(&regs->wepctl, 0);
  828. W_REG(&regs->txe_phyctl, (ofdm ? 1 : 0) | PHY_TXC_ANT_0);
  829. if (ISNPHY(pi) || ISLCNPHY(pi))
  830. W_REG(&regs->txe_phyctl1, 0x1A02);
  831. W_REG(&regs->txe_wm_0, 0);
  832. W_REG(&regs->txe_wm_1, 0);
  833. W_REG(&regs->xmttplatetxptr, 0);
  834. W_REG(&regs->xmttxcnt, DUMMY_PKT_LEN);
  835. W_REG(&regs->xmtsel, ((8 << 8) | (1 << 5) | (1 << 2) | 2));
  836. W_REG(&regs->txe_ctl, 0);
  837. if (!pa_on) {
  838. if (ISNPHY(pi))
  839. wlc_phy_pa_override_nphy(pi, OFF);
  840. }
  841. if (ISNPHY(pi) || ISLCNPHY(pi))
  842. W_REG(&regs->txe_aux, 0xD0);
  843. else
  844. W_REG(&regs->txe_aux, ((1 << 5) | (1 << 4)));
  845. (void)R_REG(&regs->txe_aux);
  846. i = 0;
  847. count = ofdm ? 30 : 250;
  848. while ((i++ < count)
  849. && (R_REG(&regs->txe_status) & (1 << 7)))
  850. udelay(10);
  851. i = 0;
  852. while ((i++ < 10)
  853. && ((R_REG(&regs->txe_status) & (1 << 10)) == 0))
  854. udelay(10);
  855. i = 0;
  856. while ((i++ < 10) && ((R_REG(&regs->ifsstat) & (1 << 8))))
  857. udelay(10);
  858. if (!pa_on) {
  859. if (ISNPHY(pi))
  860. wlc_phy_pa_override_nphy(pi, ON);
  861. }
  862. }
  863. void wlc_phy_hold_upd(struct brcms_phy_pub *pih, u32 id, bool set)
  864. {
  865. struct brcms_phy *pi = (struct brcms_phy *) pih;
  866. if (set)
  867. mboolset(pi->measure_hold, id);
  868. else
  869. mboolclr(pi->measure_hold, id);
  870. return;
  871. }
  872. void wlc_phy_mute_upd(struct brcms_phy_pub *pih, bool mute, u32 flags)
  873. {
  874. struct brcms_phy *pi = (struct brcms_phy *) pih;
  875. if (mute)
  876. mboolset(pi->measure_hold, PHY_HOLD_FOR_MUTE);
  877. else
  878. mboolclr(pi->measure_hold, PHY_HOLD_FOR_MUTE);
  879. if (!mute && (flags & PHY_MUTE_FOR_PREISM))
  880. pi->nphy_perical_last = pi->sh->now - pi->sh->glacial_timer;
  881. return;
  882. }
  883. void wlc_phy_clear_tssi(struct brcms_phy_pub *pih)
  884. {
  885. struct brcms_phy *pi = (struct brcms_phy *) pih;
  886. if (ISNPHY(pi)) {
  887. return;
  888. } else {
  889. wlapi_bmac_write_shm(pi->sh->physhim, M_B_TSSI_0, NULL_TSSI_W);
  890. wlapi_bmac_write_shm(pi->sh->physhim, M_B_TSSI_1, NULL_TSSI_W);
  891. wlapi_bmac_write_shm(pi->sh->physhim, M_G_TSSI_0, NULL_TSSI_W);
  892. wlapi_bmac_write_shm(pi->sh->physhim, M_G_TSSI_1, NULL_TSSI_W);
  893. }
  894. }
  895. static bool wlc_phy_cal_txpower_recalc_sw(struct brcms_phy *pi)
  896. {
  897. return false;
  898. }
  899. void wlc_phy_switch_radio(struct brcms_phy_pub *pih, bool on)
  900. {
  901. struct brcms_phy *pi = (struct brcms_phy *) pih;
  902. (void)R_REG(&pi->regs->maccontrol);
  903. if (ISNPHY(pi)) {
  904. wlc_phy_switch_radio_nphy(pi, on);
  905. } else if (ISLCNPHY(pi)) {
  906. if (on) {
  907. and_phy_reg(pi, 0x44c,
  908. ~((0x1 << 8) |
  909. (0x1 << 9) |
  910. (0x1 << 10) | (0x1 << 11) | (0x1 << 12)));
  911. and_phy_reg(pi, 0x4b0, ~((0x1 << 3) | (0x1 << 11)));
  912. and_phy_reg(pi, 0x4f9, ~(0x1 << 3));
  913. } else {
  914. and_phy_reg(pi, 0x44d,
  915. ~((0x1 << 10) |
  916. (0x1 << 11) |
  917. (0x1 << 12) | (0x1 << 13) | (0x1 << 14)));
  918. or_phy_reg(pi, 0x44c,
  919. (0x1 << 8) |
  920. (0x1 << 9) |
  921. (0x1 << 10) | (0x1 << 11) | (0x1 << 12));
  922. and_phy_reg(pi, 0x4b7, ~((0x7f << 8)));
  923. and_phy_reg(pi, 0x4b1, ~((0x1 << 13)));
  924. or_phy_reg(pi, 0x4b0, (0x1 << 3) | (0x1 << 11));
  925. and_phy_reg(pi, 0x4fa, ~((0x1 << 3)));
  926. or_phy_reg(pi, 0x4f9, (0x1 << 3));
  927. }
  928. }
  929. }
  930. u16 wlc_phy_bw_state_get(struct brcms_phy_pub *ppi)
  931. {
  932. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  933. return pi->bw;
  934. }
  935. void wlc_phy_bw_state_set(struct brcms_phy_pub *ppi, u16 bw)
  936. {
  937. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  938. pi->bw = bw;
  939. }
  940. void wlc_phy_chanspec_radio_set(struct brcms_phy_pub *ppi, u16 newch)
  941. {
  942. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  943. pi->radio_chanspec = newch;
  944. }
  945. u16 wlc_phy_chanspec_get(struct brcms_phy_pub *ppi)
  946. {
  947. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  948. return pi->radio_chanspec;
  949. }
  950. void wlc_phy_chanspec_set(struct brcms_phy_pub *ppi, u16 chanspec)
  951. {
  952. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  953. u16 m_cur_channel;
  954. void (*chanspec_set)(struct brcms_phy *, u16) = NULL;
  955. m_cur_channel = CHSPEC_CHANNEL(chanspec);
  956. if (CHSPEC_IS5G(chanspec))
  957. m_cur_channel |= D11_CURCHANNEL_5G;
  958. if (CHSPEC_IS40(chanspec))
  959. m_cur_channel |= D11_CURCHANNEL_40;
  960. wlapi_bmac_write_shm(pi->sh->physhim, M_CURCHANNEL, m_cur_channel);
  961. chanspec_set = pi->pi_fptr.chanset;
  962. if (chanspec_set)
  963. (*chanspec_set)(pi, chanspec);
  964. }
  965. int wlc_phy_chanspec_freq2bandrange_lpssn(uint freq)
  966. {
  967. int range = -1;
  968. if (freq < 2500)
  969. range = WL_CHAN_FREQ_RANGE_2G;
  970. else if (freq <= 5320)
  971. range = WL_CHAN_FREQ_RANGE_5GL;
  972. else if (freq <= 5700)
  973. range = WL_CHAN_FREQ_RANGE_5GM;
  974. else
  975. range = WL_CHAN_FREQ_RANGE_5GH;
  976. return range;
  977. }
  978. int wlc_phy_chanspec_bandrange_get(struct brcms_phy *pi, u16 chanspec)
  979. {
  980. int range = -1;
  981. uint channel = CHSPEC_CHANNEL(chanspec);
  982. uint freq = wlc_phy_channel2freq(channel);
  983. if (ISNPHY(pi))
  984. range = wlc_phy_get_chan_freq_range_nphy(pi, channel);
  985. else if (ISLCNPHY(pi))
  986. range = wlc_phy_chanspec_freq2bandrange_lpssn(freq);
  987. return range;
  988. }
  989. void wlc_phy_chanspec_ch14_widefilter_set(struct brcms_phy_pub *ppi,
  990. bool wide_filter)
  991. {
  992. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  993. pi->channel_14_wide_filter = wide_filter;
  994. }
  995. int wlc_phy_channel2freq(uint channel)
  996. {
  997. uint i;
  998. for (i = 0; i < ARRAY_SIZE(chan_info_all); i++)
  999. if (chan_info_all[i].chan == channel)
  1000. return chan_info_all[i].freq;
  1001. return 0;
  1002. }
  1003. void
  1004. wlc_phy_chanspec_band_validch(struct brcms_phy_pub *ppi, uint band,
  1005. struct brcms_chanvec *channels)
  1006. {
  1007. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1008. uint i;
  1009. uint channel;
  1010. memset(channels, 0, sizeof(struct brcms_chanvec));
  1011. for (i = 0; i < ARRAY_SIZE(chan_info_all); i++) {
  1012. channel = chan_info_all[i].chan;
  1013. if ((pi->a_band_high_disable) && (channel >= FIRST_REF5_CHANNUM)
  1014. && (channel <= LAST_REF5_CHANNUM))
  1015. continue;
  1016. if ((band == BRCM_BAND_2G && channel <= CH_MAX_2G_CHANNEL) ||
  1017. (band == BRCM_BAND_5G && channel > CH_MAX_2G_CHANNEL))
  1018. setbit(channels->vec, channel);
  1019. }
  1020. }
  1021. u16 wlc_phy_chanspec_band_firstch(struct brcms_phy_pub *ppi, uint band)
  1022. {
  1023. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1024. uint i;
  1025. uint channel;
  1026. u16 chspec;
  1027. for (i = 0; i < ARRAY_SIZE(chan_info_all); i++) {
  1028. channel = chan_info_all[i].chan;
  1029. if (ISNPHY(pi) && pi->bw == WL_CHANSPEC_BW_40) {
  1030. uint j;
  1031. for (j = 0; j < ARRAY_SIZE(chan_info_all); j++) {
  1032. if (chan_info_all[j].chan ==
  1033. channel + CH_10MHZ_APART)
  1034. break;
  1035. }
  1036. if (j == ARRAY_SIZE(chan_info_all))
  1037. continue;
  1038. channel = upper_20_sb(channel);
  1039. chspec = channel | WL_CHANSPEC_BW_40 |
  1040. WL_CHANSPEC_CTL_SB_LOWER;
  1041. if (band == BRCM_BAND_2G)
  1042. chspec |= WL_CHANSPEC_BAND_2G;
  1043. else
  1044. chspec |= WL_CHANSPEC_BAND_5G;
  1045. } else
  1046. chspec = ch20mhz_chspec(channel);
  1047. if ((pi->a_band_high_disable) && (channel >= FIRST_REF5_CHANNUM)
  1048. && (channel <= LAST_REF5_CHANNUM))
  1049. continue;
  1050. if ((band == BRCM_BAND_2G && channel <= CH_MAX_2G_CHANNEL) ||
  1051. (band == BRCM_BAND_5G && channel > CH_MAX_2G_CHANNEL))
  1052. return chspec;
  1053. }
  1054. return (u16) INVCHANSPEC;
  1055. }
  1056. int wlc_phy_txpower_get(struct brcms_phy_pub *ppi, uint *qdbm, bool *override)
  1057. {
  1058. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1059. *qdbm = pi->tx_user_target[0];
  1060. if (override != NULL)
  1061. *override = pi->txpwroverride;
  1062. return 0;
  1063. }
  1064. void wlc_phy_txpower_target_set(struct brcms_phy_pub *ppi,
  1065. struct txpwr_limits *txpwr)
  1066. {
  1067. bool mac_enabled = false;
  1068. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1069. memcpy(&pi->tx_user_target[TXP_FIRST_CCK],
  1070. &txpwr->cck[0], BRCMS_NUM_RATES_CCK);
  1071. memcpy(&pi->tx_user_target[TXP_FIRST_OFDM],
  1072. &txpwr->ofdm[0], BRCMS_NUM_RATES_OFDM);
  1073. memcpy(&pi->tx_user_target[TXP_FIRST_OFDM_20_CDD],
  1074. &txpwr->ofdm_cdd[0], BRCMS_NUM_RATES_OFDM);
  1075. memcpy(&pi->tx_user_target[TXP_FIRST_OFDM_40_SISO],
  1076. &txpwr->ofdm_40_siso[0], BRCMS_NUM_RATES_OFDM);
  1077. memcpy(&pi->tx_user_target[TXP_FIRST_OFDM_40_CDD],
  1078. &txpwr->ofdm_40_cdd[0], BRCMS_NUM_RATES_OFDM);
  1079. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_20_SISO],
  1080. &txpwr->mcs_20_siso[0], BRCMS_NUM_RATES_MCS_1_STREAM);
  1081. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_20_CDD],
  1082. &txpwr->mcs_20_cdd[0], BRCMS_NUM_RATES_MCS_1_STREAM);
  1083. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_20_STBC],
  1084. &txpwr->mcs_20_stbc[0], BRCMS_NUM_RATES_MCS_1_STREAM);
  1085. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_20_SDM],
  1086. &txpwr->mcs_20_mimo[0], BRCMS_NUM_RATES_MCS_2_STREAM);
  1087. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_40_SISO],
  1088. &txpwr->mcs_40_siso[0], BRCMS_NUM_RATES_MCS_1_STREAM);
  1089. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_40_CDD],
  1090. &txpwr->mcs_40_cdd[0], BRCMS_NUM_RATES_MCS_1_STREAM);
  1091. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_40_STBC],
  1092. &txpwr->mcs_40_stbc[0], BRCMS_NUM_RATES_MCS_1_STREAM);
  1093. memcpy(&pi->tx_user_target[TXP_FIRST_MCS_40_SDM],
  1094. &txpwr->mcs_40_mimo[0], BRCMS_NUM_RATES_MCS_2_STREAM);
  1095. if (R_REG(&pi->regs->maccontrol) & MCTL_EN_MAC)
  1096. mac_enabled = true;
  1097. if (mac_enabled)
  1098. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1099. wlc_phy_txpower_recalc_target(pi);
  1100. wlc_phy_cal_txpower_recalc_sw(pi);
  1101. if (mac_enabled)
  1102. wlapi_enable_mac(pi->sh->physhim);
  1103. }
  1104. int wlc_phy_txpower_set(struct brcms_phy_pub *ppi, uint qdbm, bool override)
  1105. {
  1106. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1107. int i;
  1108. if (qdbm > 127)
  1109. return -EINVAL;
  1110. for (i = 0; i < TXP_NUM_RATES; i++)
  1111. pi->tx_user_target[i] = (u8) qdbm;
  1112. pi->txpwroverride = false;
  1113. if (pi->sh->up) {
  1114. if (!SCAN_INPROG_PHY(pi)) {
  1115. bool suspend;
  1116. suspend = (0 == (R_REG(&pi->regs->maccontrol) &
  1117. MCTL_EN_MAC));
  1118. if (!suspend)
  1119. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1120. wlc_phy_txpower_recalc_target(pi);
  1121. wlc_phy_cal_txpower_recalc_sw(pi);
  1122. if (!suspend)
  1123. wlapi_enable_mac(pi->sh->physhim);
  1124. }
  1125. }
  1126. return 0;
  1127. }
  1128. void
  1129. wlc_phy_txpower_sromlimit(struct brcms_phy_pub *ppi, uint channel, u8 *min_pwr,
  1130. u8 *max_pwr, int txp_rate_idx)
  1131. {
  1132. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1133. uint i;
  1134. *min_pwr = pi->min_txpower * BRCMS_TXPWR_DB_FACTOR;
  1135. if (ISNPHY(pi)) {
  1136. if (txp_rate_idx < 0)
  1137. txp_rate_idx = TXP_FIRST_CCK;
  1138. wlc_phy_txpower_sromlimit_get_nphy(pi, channel, max_pwr,
  1139. (u8) txp_rate_idx);
  1140. } else if ((channel <= CH_MAX_2G_CHANNEL)) {
  1141. if (txp_rate_idx < 0)
  1142. txp_rate_idx = TXP_FIRST_CCK;
  1143. *max_pwr = pi->tx_srom_max_rate_2g[txp_rate_idx];
  1144. } else {
  1145. *max_pwr = BRCMS_TXPWR_MAX;
  1146. if (txp_rate_idx < 0)
  1147. txp_rate_idx = TXP_FIRST_OFDM;
  1148. for (i = 0; i < ARRAY_SIZE(chan_info_all); i++) {
  1149. if (channel == chan_info_all[i].chan)
  1150. break;
  1151. }
  1152. if (pi->hwtxpwr) {
  1153. *max_pwr = pi->hwtxpwr[i];
  1154. } else {
  1155. if ((i >= FIRST_MID_5G_CHAN) && (i <= LAST_MID_5G_CHAN))
  1156. *max_pwr =
  1157. pi->tx_srom_max_rate_5g_mid[txp_rate_idx];
  1158. if ((i >= FIRST_HIGH_5G_CHAN)
  1159. && (i <= LAST_HIGH_5G_CHAN))
  1160. *max_pwr =
  1161. pi->tx_srom_max_rate_5g_hi[txp_rate_idx];
  1162. if ((i >= FIRST_LOW_5G_CHAN) && (i <= LAST_LOW_5G_CHAN))
  1163. *max_pwr =
  1164. pi->tx_srom_max_rate_5g_low[txp_rate_idx];
  1165. }
  1166. }
  1167. }
  1168. void
  1169. wlc_phy_txpower_sromlimit_max_get(struct brcms_phy_pub *ppi, uint chan,
  1170. u8 *max_txpwr, u8 *min_txpwr)
  1171. {
  1172. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1173. u8 tx_pwr_max = 0;
  1174. u8 tx_pwr_min = 255;
  1175. u8 max_num_rate;
  1176. u8 maxtxpwr, mintxpwr, rate, pactrl;
  1177. pactrl = 0;
  1178. max_num_rate = ISNPHY(pi) ? TXP_NUM_RATES :
  1179. ISLCNPHY(pi) ? (TXP_LAST_SISO_MCS_20 +
  1180. 1) : (TXP_LAST_OFDM + 1);
  1181. for (rate = 0; rate < max_num_rate; rate++) {
  1182. wlc_phy_txpower_sromlimit(ppi, chan, &mintxpwr, &maxtxpwr,
  1183. rate);
  1184. maxtxpwr = (maxtxpwr > pactrl) ? (maxtxpwr - pactrl) : 0;
  1185. maxtxpwr = (maxtxpwr > 6) ? (maxtxpwr - 6) : 0;
  1186. tx_pwr_max = max(tx_pwr_max, maxtxpwr);
  1187. tx_pwr_min = min(tx_pwr_min, maxtxpwr);
  1188. }
  1189. *max_txpwr = tx_pwr_max;
  1190. *min_txpwr = tx_pwr_min;
  1191. }
  1192. void
  1193. wlc_phy_txpower_boardlimit_band(struct brcms_phy_pub *ppi, uint bandunit,
  1194. s32 *max_pwr, s32 *min_pwr, u32 *step_pwr)
  1195. {
  1196. return;
  1197. }
  1198. u8 wlc_phy_txpower_get_target_min(struct brcms_phy_pub *ppi)
  1199. {
  1200. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1201. return pi->tx_power_min;
  1202. }
  1203. u8 wlc_phy_txpower_get_target_max(struct brcms_phy_pub *ppi)
  1204. {
  1205. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1206. return pi->tx_power_max;
  1207. }
  1208. static s8 wlc_phy_env_measure_vbat(struct brcms_phy *pi)
  1209. {
  1210. if (ISLCNPHY(pi))
  1211. return wlc_lcnphy_vbatsense(pi, 0);
  1212. else
  1213. return 0;
  1214. }
  1215. static s8 wlc_phy_env_measure_temperature(struct brcms_phy *pi)
  1216. {
  1217. if (ISLCNPHY(pi))
  1218. return wlc_lcnphy_tempsense_degree(pi, 0);
  1219. else
  1220. return 0;
  1221. }
  1222. static void wlc_phy_upd_env_txpwr_rate_limits(struct brcms_phy *pi, u32 band)
  1223. {
  1224. u8 i;
  1225. s8 temp, vbat;
  1226. for (i = 0; i < TXP_NUM_RATES; i++)
  1227. pi->txpwr_env_limit[i] = BRCMS_TXPWR_MAX;
  1228. vbat = wlc_phy_env_measure_vbat(pi);
  1229. temp = wlc_phy_env_measure_temperature(pi);
  1230. }
  1231. static s8
  1232. wlc_user_txpwr_antport_to_rfport(struct brcms_phy *pi, uint chan, u32 band,
  1233. u8 rate)
  1234. {
  1235. s8 offset = 0;
  1236. if (!pi->user_txpwr_at_rfport)
  1237. return offset;
  1238. return offset;
  1239. }
  1240. void wlc_phy_txpower_recalc_target(struct brcms_phy *pi)
  1241. {
  1242. u8 maxtxpwr, mintxpwr, rate, pactrl;
  1243. uint target_chan;
  1244. u8 tx_pwr_target[TXP_NUM_RATES];
  1245. u8 tx_pwr_max = 0;
  1246. u8 tx_pwr_min = 255;
  1247. u8 tx_pwr_max_rate_ind = 0;
  1248. u8 max_num_rate;
  1249. u8 start_rate = 0;
  1250. u16 chspec;
  1251. u32 band = CHSPEC2BAND(pi->radio_chanspec);
  1252. void (*txpwr_recalc_fn)(struct brcms_phy *) = NULL;
  1253. chspec = pi->radio_chanspec;
  1254. if (CHSPEC_CTL_SB(chspec) == WL_CHANSPEC_CTL_SB_NONE)
  1255. target_chan = CHSPEC_CHANNEL(chspec);
  1256. else if (CHSPEC_CTL_SB(chspec) == WL_CHANSPEC_CTL_SB_UPPER)
  1257. target_chan = upper_20_sb(CHSPEC_CHANNEL(chspec));
  1258. else
  1259. target_chan = lower_20_sb(CHSPEC_CHANNEL(chspec));
  1260. pactrl = 0;
  1261. if (ISLCNPHY(pi)) {
  1262. u32 offset_mcs, i;
  1263. if (CHSPEC_IS40(pi->radio_chanspec)) {
  1264. offset_mcs = pi->mcs40_po;
  1265. for (i = TXP_FIRST_SISO_MCS_20;
  1266. i <= TXP_LAST_SISO_MCS_20; i++) {
  1267. pi->tx_srom_max_rate_2g[i - 8] =
  1268. pi->tx_srom_max_2g -
  1269. ((offset_mcs & 0xf) * 2);
  1270. offset_mcs >>= 4;
  1271. }
  1272. } else {
  1273. offset_mcs = pi->mcs20_po;
  1274. for (i = TXP_FIRST_SISO_MCS_20;
  1275. i <= TXP_LAST_SISO_MCS_20; i++) {
  1276. pi->tx_srom_max_rate_2g[i - 8] =
  1277. pi->tx_srom_max_2g -
  1278. ((offset_mcs & 0xf) * 2);
  1279. offset_mcs >>= 4;
  1280. }
  1281. }
  1282. }
  1283. max_num_rate = ((ISNPHY(pi)) ? (TXP_NUM_RATES) :
  1284. ((ISLCNPHY(pi)) ?
  1285. (TXP_LAST_SISO_MCS_20 + 1) : (TXP_LAST_OFDM + 1)));
  1286. wlc_phy_upd_env_txpwr_rate_limits(pi, band);
  1287. for (rate = start_rate; rate < max_num_rate; rate++) {
  1288. tx_pwr_target[rate] = pi->tx_user_target[rate];
  1289. if (pi->user_txpwr_at_rfport)
  1290. tx_pwr_target[rate] +=
  1291. wlc_user_txpwr_antport_to_rfport(pi,
  1292. target_chan,
  1293. band,
  1294. rate);
  1295. wlc_phy_txpower_sromlimit((struct brcms_phy_pub *) pi,
  1296. target_chan,
  1297. &mintxpwr, &maxtxpwr, rate);
  1298. maxtxpwr = min(maxtxpwr, pi->txpwr_limit[rate]);
  1299. maxtxpwr = (maxtxpwr > pactrl) ? (maxtxpwr - pactrl) : 0;
  1300. maxtxpwr = (maxtxpwr > 6) ? (maxtxpwr - 6) : 0;
  1301. maxtxpwr = min(maxtxpwr, tx_pwr_target[rate]);
  1302. if (pi->txpwr_percent <= 100)
  1303. maxtxpwr = (maxtxpwr * pi->txpwr_percent) / 100;
  1304. tx_pwr_target[rate] = max(maxtxpwr, mintxpwr);
  1305. tx_pwr_target[rate] =
  1306. min(tx_pwr_target[rate], pi->txpwr_env_limit[rate]);
  1307. if (tx_pwr_target[rate] > tx_pwr_max)
  1308. tx_pwr_max_rate_ind = rate;
  1309. tx_pwr_max = max(tx_pwr_max, tx_pwr_target[rate]);
  1310. tx_pwr_min = min(tx_pwr_min, tx_pwr_target[rate]);
  1311. }
  1312. memset(pi->tx_power_offset, 0, sizeof(pi->tx_power_offset));
  1313. pi->tx_power_max = tx_pwr_max;
  1314. pi->tx_power_min = tx_pwr_min;
  1315. pi->tx_power_max_rate_ind = tx_pwr_max_rate_ind;
  1316. for (rate = 0; rate < max_num_rate; rate++) {
  1317. pi->tx_power_target[rate] = tx_pwr_target[rate];
  1318. if (!pi->hwpwrctrl || ISNPHY(pi))
  1319. pi->tx_power_offset[rate] =
  1320. pi->tx_power_max - pi->tx_power_target[rate];
  1321. else
  1322. pi->tx_power_offset[rate] =
  1323. pi->tx_power_target[rate] - pi->tx_power_min;
  1324. }
  1325. txpwr_recalc_fn = pi->pi_fptr.txpwrrecalc;
  1326. if (txpwr_recalc_fn)
  1327. (*txpwr_recalc_fn)(pi);
  1328. }
  1329. static void
  1330. wlc_phy_txpower_reg_limit_calc(struct brcms_phy *pi, struct txpwr_limits *txpwr,
  1331. u16 chanspec)
  1332. {
  1333. u8 tmp_txpwr_limit[2 * BRCMS_NUM_RATES_OFDM];
  1334. u8 *txpwr_ptr1 = NULL, *txpwr_ptr2 = NULL;
  1335. int rate_start_index = 0, rate1, rate2, k;
  1336. for (rate1 = WL_TX_POWER_CCK_FIRST, rate2 = 0;
  1337. rate2 < WL_TX_POWER_CCK_NUM; rate1++, rate2++)
  1338. pi->txpwr_limit[rate1] = txpwr->cck[rate2];
  1339. for (rate1 = WL_TX_POWER_OFDM_FIRST, rate2 = 0;
  1340. rate2 < WL_TX_POWER_OFDM_NUM; rate1++, rate2++)
  1341. pi->txpwr_limit[rate1] = txpwr->ofdm[rate2];
  1342. if (ISNPHY(pi)) {
  1343. for (k = 0; k < 4; k++) {
  1344. switch (k) {
  1345. case 0:
  1346. txpwr_ptr1 = txpwr->mcs_20_siso;
  1347. txpwr_ptr2 = txpwr->ofdm;
  1348. rate_start_index = WL_TX_POWER_OFDM_FIRST;
  1349. break;
  1350. case 1:
  1351. txpwr_ptr1 = txpwr->mcs_20_cdd;
  1352. txpwr_ptr2 = txpwr->ofdm_cdd;
  1353. rate_start_index = WL_TX_POWER_OFDM20_CDD_FIRST;
  1354. break;
  1355. case 2:
  1356. txpwr_ptr1 = txpwr->mcs_40_siso;
  1357. txpwr_ptr2 = txpwr->ofdm_40_siso;
  1358. rate_start_index =
  1359. WL_TX_POWER_OFDM40_SISO_FIRST;
  1360. break;
  1361. case 3:
  1362. txpwr_ptr1 = txpwr->mcs_40_cdd;
  1363. txpwr_ptr2 = txpwr->ofdm_40_cdd;
  1364. rate_start_index = WL_TX_POWER_OFDM40_CDD_FIRST;
  1365. break;
  1366. }
  1367. for (rate2 = 0; rate2 < BRCMS_NUM_RATES_OFDM;
  1368. rate2++) {
  1369. tmp_txpwr_limit[rate2] = 0;
  1370. tmp_txpwr_limit[BRCMS_NUM_RATES_OFDM + rate2] =
  1371. txpwr_ptr1[rate2];
  1372. }
  1373. wlc_phy_mcs_to_ofdm_powers_nphy(
  1374. tmp_txpwr_limit, 0,
  1375. BRCMS_NUM_RATES_OFDM -
  1376. 1, BRCMS_NUM_RATES_OFDM);
  1377. for (rate1 = rate_start_index, rate2 = 0;
  1378. rate2 < BRCMS_NUM_RATES_OFDM; rate1++, rate2++)
  1379. pi->txpwr_limit[rate1] =
  1380. min(txpwr_ptr2[rate2],
  1381. tmp_txpwr_limit[rate2]);
  1382. }
  1383. for (k = 0; k < 4; k++) {
  1384. switch (k) {
  1385. case 0:
  1386. txpwr_ptr1 = txpwr->ofdm;
  1387. txpwr_ptr2 = txpwr->mcs_20_siso;
  1388. rate_start_index = WL_TX_POWER_MCS20_SISO_FIRST;
  1389. break;
  1390. case 1:
  1391. txpwr_ptr1 = txpwr->ofdm_cdd;
  1392. txpwr_ptr2 = txpwr->mcs_20_cdd;
  1393. rate_start_index = WL_TX_POWER_MCS20_CDD_FIRST;
  1394. break;
  1395. case 2:
  1396. txpwr_ptr1 = txpwr->ofdm_40_siso;
  1397. txpwr_ptr2 = txpwr->mcs_40_siso;
  1398. rate_start_index = WL_TX_POWER_MCS40_SISO_FIRST;
  1399. break;
  1400. case 3:
  1401. txpwr_ptr1 = txpwr->ofdm_40_cdd;
  1402. txpwr_ptr2 = txpwr->mcs_40_cdd;
  1403. rate_start_index = WL_TX_POWER_MCS40_CDD_FIRST;
  1404. break;
  1405. }
  1406. for (rate2 = 0; rate2 < BRCMS_NUM_RATES_OFDM;
  1407. rate2++) {
  1408. tmp_txpwr_limit[rate2] = 0;
  1409. tmp_txpwr_limit[BRCMS_NUM_RATES_OFDM + rate2] =
  1410. txpwr_ptr1[rate2];
  1411. }
  1412. wlc_phy_ofdm_to_mcs_powers_nphy(
  1413. tmp_txpwr_limit, 0,
  1414. BRCMS_NUM_RATES_OFDM -
  1415. 1, BRCMS_NUM_RATES_OFDM);
  1416. for (rate1 = rate_start_index, rate2 = 0;
  1417. rate2 < BRCMS_NUM_RATES_MCS_1_STREAM;
  1418. rate1++, rate2++)
  1419. pi->txpwr_limit[rate1] =
  1420. min(txpwr_ptr2[rate2],
  1421. tmp_txpwr_limit[rate2]);
  1422. }
  1423. for (k = 0; k < 2; k++) {
  1424. switch (k) {
  1425. case 0:
  1426. rate_start_index = WL_TX_POWER_MCS20_STBC_FIRST;
  1427. txpwr_ptr1 = txpwr->mcs_20_stbc;
  1428. break;
  1429. case 1:
  1430. rate_start_index = WL_TX_POWER_MCS40_STBC_FIRST;
  1431. txpwr_ptr1 = txpwr->mcs_40_stbc;
  1432. break;
  1433. }
  1434. for (rate1 = rate_start_index, rate2 = 0;
  1435. rate2 < BRCMS_NUM_RATES_MCS_1_STREAM;
  1436. rate1++, rate2++)
  1437. pi->txpwr_limit[rate1] = txpwr_ptr1[rate2];
  1438. }
  1439. for (k = 0; k < 2; k++) {
  1440. switch (k) {
  1441. case 0:
  1442. rate_start_index = WL_TX_POWER_MCS20_SDM_FIRST;
  1443. txpwr_ptr1 = txpwr->mcs_20_mimo;
  1444. break;
  1445. case 1:
  1446. rate_start_index = WL_TX_POWER_MCS40_SDM_FIRST;
  1447. txpwr_ptr1 = txpwr->mcs_40_mimo;
  1448. break;
  1449. }
  1450. for (rate1 = rate_start_index, rate2 = 0;
  1451. rate2 < BRCMS_NUM_RATES_MCS_2_STREAM;
  1452. rate1++, rate2++)
  1453. pi->txpwr_limit[rate1] = txpwr_ptr1[rate2];
  1454. }
  1455. pi->txpwr_limit[WL_TX_POWER_MCS_32] = txpwr->mcs32;
  1456. pi->txpwr_limit[WL_TX_POWER_MCS40_CDD_FIRST] =
  1457. min(pi->txpwr_limit[WL_TX_POWER_MCS40_CDD_FIRST],
  1458. pi->txpwr_limit[WL_TX_POWER_MCS_32]);
  1459. pi->txpwr_limit[WL_TX_POWER_MCS_32] =
  1460. pi->txpwr_limit[WL_TX_POWER_MCS40_CDD_FIRST];
  1461. }
  1462. }
  1463. void wlc_phy_txpwr_percent_set(struct brcms_phy_pub *ppi, u8 txpwr_percent)
  1464. {
  1465. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1466. pi->txpwr_percent = txpwr_percent;
  1467. }
  1468. void wlc_phy_machwcap_set(struct brcms_phy_pub *ppi, u32 machwcap)
  1469. {
  1470. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1471. pi->sh->machwcap = machwcap;
  1472. }
  1473. void wlc_phy_runbist_config(struct brcms_phy_pub *ppi, bool start_end)
  1474. {
  1475. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1476. u16 rxc;
  1477. rxc = 0;
  1478. if (start_end == ON) {
  1479. if (!ISNPHY(pi))
  1480. return;
  1481. if (NREV_IS(pi->pubpi.phy_rev, 3)
  1482. || NREV_IS(pi->pubpi.phy_rev, 4)) {
  1483. W_REG(&pi->regs->phyregaddr, 0xa0);
  1484. (void)R_REG(&pi->regs->phyregaddr);
  1485. rxc = R_REG(&pi->regs->phyregdata);
  1486. W_REG(&pi->regs->phyregdata,
  1487. (0x1 << 15) | rxc);
  1488. }
  1489. } else {
  1490. if (NREV_IS(pi->pubpi.phy_rev, 3)
  1491. || NREV_IS(pi->pubpi.phy_rev, 4)) {
  1492. W_REG(&pi->regs->phyregaddr, 0xa0);
  1493. (void)R_REG(&pi->regs->phyregaddr);
  1494. W_REG(&pi->regs->phyregdata, rxc);
  1495. }
  1496. wlc_phy_por_inform(ppi);
  1497. }
  1498. }
  1499. void
  1500. wlc_phy_txpower_limit_set(struct brcms_phy_pub *ppi, struct txpwr_limits *txpwr,
  1501. u16 chanspec)
  1502. {
  1503. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1504. wlc_phy_txpower_reg_limit_calc(pi, txpwr, chanspec);
  1505. if (ISLCNPHY(pi)) {
  1506. int i, j;
  1507. for (i = TXP_FIRST_OFDM_20_CDD, j = 0;
  1508. j < BRCMS_NUM_RATES_MCS_1_STREAM; i++, j++) {
  1509. if (txpwr->mcs_20_siso[j])
  1510. pi->txpwr_limit[i] = txpwr->mcs_20_siso[j];
  1511. else
  1512. pi->txpwr_limit[i] = txpwr->ofdm[j];
  1513. }
  1514. }
  1515. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1516. wlc_phy_txpower_recalc_target(pi);
  1517. wlc_phy_cal_txpower_recalc_sw(pi);
  1518. wlapi_enable_mac(pi->sh->physhim);
  1519. }
  1520. void wlc_phy_ofdm_rateset_war(struct brcms_phy_pub *pih, bool war)
  1521. {
  1522. struct brcms_phy *pi = (struct brcms_phy *) pih;
  1523. pi->ofdm_rateset_war = war;
  1524. }
  1525. void wlc_phy_bf_preempt_enable(struct brcms_phy_pub *pih, bool bf_preempt)
  1526. {
  1527. struct brcms_phy *pi = (struct brcms_phy *) pih;
  1528. pi->bf_preempt_4306 = bf_preempt;
  1529. }
  1530. void wlc_phy_txpower_update_shm(struct brcms_phy *pi)
  1531. {
  1532. int j;
  1533. if (ISNPHY(pi))
  1534. return;
  1535. if (!pi->sh->clk)
  1536. return;
  1537. if (pi->hwpwrctrl) {
  1538. u16 offset;
  1539. wlapi_bmac_write_shm(pi->sh->physhim, M_TXPWR_MAX, 63);
  1540. wlapi_bmac_write_shm(pi->sh->physhim, M_TXPWR_N,
  1541. 1 << NUM_TSSI_FRAMES);
  1542. wlapi_bmac_write_shm(pi->sh->physhim, M_TXPWR_TARGET,
  1543. pi->tx_power_min << NUM_TSSI_FRAMES);
  1544. wlapi_bmac_write_shm(pi->sh->physhim, M_TXPWR_CUR,
  1545. pi->hwpwr_txcur);
  1546. for (j = TXP_FIRST_OFDM; j <= TXP_LAST_OFDM; j++) {
  1547. const u8 ucode_ofdm_rates[] = {
  1548. 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c
  1549. };
  1550. offset = wlapi_bmac_rate_shm_offset(
  1551. pi->sh->physhim,
  1552. ucode_ofdm_rates[j - TXP_FIRST_OFDM]);
  1553. wlapi_bmac_write_shm(pi->sh->physhim, offset + 6,
  1554. pi->tx_power_offset[j]);
  1555. wlapi_bmac_write_shm(pi->sh->physhim, offset + 14,
  1556. -(pi->tx_power_offset[j] / 2));
  1557. }
  1558. wlapi_bmac_mhf(pi->sh->physhim, MHF2, MHF2_HWPWRCTL,
  1559. MHF2_HWPWRCTL, BRCM_BAND_ALL);
  1560. } else {
  1561. int i;
  1562. for (i = TXP_FIRST_OFDM; i <= TXP_LAST_OFDM; i++)
  1563. pi->tx_power_offset[i] =
  1564. (u8) roundup(pi->tx_power_offset[i], 8);
  1565. wlapi_bmac_write_shm(pi->sh->physhim, M_OFDM_OFFSET,
  1566. (u16)
  1567. ((pi->tx_power_offset[TXP_FIRST_OFDM]
  1568. + 7) >> 3));
  1569. }
  1570. }
  1571. bool wlc_phy_txpower_hw_ctrl_get(struct brcms_phy_pub *ppi)
  1572. {
  1573. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1574. if (ISNPHY(pi))
  1575. return pi->nphy_txpwrctrl;
  1576. else
  1577. return pi->hwpwrctrl;
  1578. }
  1579. void wlc_phy_txpower_hw_ctrl_set(struct brcms_phy_pub *ppi, bool hwpwrctrl)
  1580. {
  1581. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1582. bool suspend;
  1583. if (!pi->hwpwrctrl_capable)
  1584. return;
  1585. pi->hwpwrctrl = hwpwrctrl;
  1586. pi->nphy_txpwrctrl = hwpwrctrl;
  1587. pi->txpwrctrl = hwpwrctrl;
  1588. if (ISNPHY(pi)) {
  1589. suspend = (0 == (R_REG(&pi->regs->maccontrol) & MCTL_EN_MAC));
  1590. if (!suspend)
  1591. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1592. wlc_phy_txpwrctrl_enable_nphy(pi, pi->nphy_txpwrctrl);
  1593. if (pi->nphy_txpwrctrl == PHY_TPC_HW_OFF)
  1594. wlc_phy_txpwr_fixpower_nphy(pi);
  1595. else
  1596. mod_phy_reg(pi, 0x1e7, (0x7f << 0),
  1597. pi->saved_txpwr_idx);
  1598. if (!suspend)
  1599. wlapi_enable_mac(pi->sh->physhim);
  1600. }
  1601. }
  1602. void wlc_phy_txpower_ipa_upd(struct brcms_phy *pi)
  1603. {
  1604. if (NREV_GE(pi->pubpi.phy_rev, 3)) {
  1605. pi->ipa2g_on = (pi->srom_fem2g.extpagain == 2);
  1606. pi->ipa5g_on = (pi->srom_fem5g.extpagain == 2);
  1607. } else {
  1608. pi->ipa2g_on = false;
  1609. pi->ipa5g_on = false;
  1610. }
  1611. }
  1612. static u32 wlc_phy_txpower_est_power_nphy(struct brcms_phy *pi)
  1613. {
  1614. s16 tx0_status, tx1_status;
  1615. u16 estPower1, estPower2;
  1616. u8 pwr0, pwr1, adj_pwr0, adj_pwr1;
  1617. u32 est_pwr;
  1618. estPower1 = read_phy_reg(pi, 0x118);
  1619. estPower2 = read_phy_reg(pi, 0x119);
  1620. if ((estPower1 & (0x1 << 8)) == (0x1 << 8))
  1621. pwr0 = (u8) (estPower1 & (0xff << 0)) >> 0;
  1622. else
  1623. pwr0 = 0x80;
  1624. if ((estPower2 & (0x1 << 8)) == (0x1 << 8))
  1625. pwr1 = (u8) (estPower2 & (0xff << 0)) >> 0;
  1626. else
  1627. pwr1 = 0x80;
  1628. tx0_status = read_phy_reg(pi, 0x1ed);
  1629. tx1_status = read_phy_reg(pi, 0x1ee);
  1630. if ((tx0_status & (0x1 << 15)) == (0x1 << 15))
  1631. adj_pwr0 = (u8) (tx0_status & (0xff << 0)) >> 0;
  1632. else
  1633. adj_pwr0 = 0x80;
  1634. if ((tx1_status & (0x1 << 15)) == (0x1 << 15))
  1635. adj_pwr1 = (u8) (tx1_status & (0xff << 0)) >> 0;
  1636. else
  1637. adj_pwr1 = 0x80;
  1638. est_pwr = (u32) ((pwr0 << 24) | (pwr1 << 16) | (adj_pwr0 << 8) |
  1639. adj_pwr1);
  1640. return est_pwr;
  1641. }
  1642. void
  1643. wlc_phy_txpower_get_current(struct brcms_phy_pub *ppi, struct tx_power *power,
  1644. uint channel)
  1645. {
  1646. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1647. uint rate, num_rates;
  1648. u8 min_pwr, max_pwr;
  1649. #if WL_TX_POWER_RATES != TXP_NUM_RATES
  1650. #error "struct tx_power out of sync with this fn"
  1651. #endif
  1652. if (ISNPHY(pi)) {
  1653. power->rf_cores = 2;
  1654. power->flags |= (WL_TX_POWER_F_MIMO);
  1655. if (pi->nphy_txpwrctrl == PHY_TPC_HW_ON)
  1656. power->flags |=
  1657. (WL_TX_POWER_F_ENABLED | WL_TX_POWER_F_HW);
  1658. } else if (ISLCNPHY(pi)) {
  1659. power->rf_cores = 1;
  1660. power->flags |= (WL_TX_POWER_F_SISO);
  1661. if (pi->radiopwr_override == RADIOPWR_OVERRIDE_DEF)
  1662. power->flags |= WL_TX_POWER_F_ENABLED;
  1663. if (pi->hwpwrctrl)
  1664. power->flags |= WL_TX_POWER_F_HW;
  1665. }
  1666. num_rates = ((ISNPHY(pi)) ? (TXP_NUM_RATES) :
  1667. ((ISLCNPHY(pi)) ?
  1668. (TXP_LAST_OFDM_20_CDD + 1) : (TXP_LAST_OFDM + 1)));
  1669. for (rate = 0; rate < num_rates; rate++) {
  1670. power->user_limit[rate] = pi->tx_user_target[rate];
  1671. wlc_phy_txpower_sromlimit(ppi, channel, &min_pwr, &max_pwr,
  1672. rate);
  1673. power->board_limit[rate] = (u8) max_pwr;
  1674. power->target[rate] = pi->tx_power_target[rate];
  1675. }
  1676. if (ISNPHY(pi)) {
  1677. u32 est_pout;
  1678. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  1679. wlc_phyreg_enter((struct brcms_phy_pub *) pi);
  1680. est_pout = wlc_phy_txpower_est_power_nphy(pi);
  1681. wlc_phyreg_exit((struct brcms_phy_pub *) pi);
  1682. wlapi_enable_mac(pi->sh->physhim);
  1683. power->est_Pout[0] = (est_pout >> 8) & 0xff;
  1684. power->est_Pout[1] = est_pout & 0xff;
  1685. power->est_Pout_act[0] = est_pout >> 24;
  1686. power->est_Pout_act[1] = (est_pout >> 16) & 0xff;
  1687. if (power->est_Pout[0] == 0x80)
  1688. power->est_Pout[0] = 0;
  1689. if (power->est_Pout[1] == 0x80)
  1690. power->est_Pout[1] = 0;
  1691. if (power->est_Pout_act[0] == 0x80)
  1692. power->est_Pout_act[0] = 0;
  1693. if (power->est_Pout_act[1] == 0x80)
  1694. power->est_Pout_act[1] = 0;
  1695. power->est_Pout_cck = 0;
  1696. power->tx_power_max[0] = pi->tx_power_max;
  1697. power->tx_power_max[1] = pi->tx_power_max;
  1698. power->tx_power_max_rate_ind[0] = pi->tx_power_max_rate_ind;
  1699. power->tx_power_max_rate_ind[1] = pi->tx_power_max_rate_ind;
  1700. } else if (pi->hwpwrctrl && pi->sh->up) {
  1701. wlc_phyreg_enter(ppi);
  1702. if (ISLCNPHY(pi)) {
  1703. power->tx_power_max[0] = pi->tx_power_max;
  1704. power->tx_power_max[1] = pi->tx_power_max;
  1705. power->tx_power_max_rate_ind[0] =
  1706. pi->tx_power_max_rate_ind;
  1707. power->tx_power_max_rate_ind[1] =
  1708. pi->tx_power_max_rate_ind;
  1709. if (wlc_phy_tpc_isenabled_lcnphy(pi))
  1710. power->flags |=
  1711. (WL_TX_POWER_F_HW |
  1712. WL_TX_POWER_F_ENABLED);
  1713. else
  1714. power->flags &=
  1715. ~(WL_TX_POWER_F_HW |
  1716. WL_TX_POWER_F_ENABLED);
  1717. wlc_lcnphy_get_tssi(pi, (s8 *) &power->est_Pout[0],
  1718. (s8 *) &power->est_Pout_cck);
  1719. }
  1720. wlc_phyreg_exit(ppi);
  1721. }
  1722. }
  1723. void wlc_phy_antsel_type_set(struct brcms_phy_pub *ppi, u8 antsel_type)
  1724. {
  1725. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1726. pi->antsel_type = antsel_type;
  1727. }
  1728. bool wlc_phy_test_ison(struct brcms_phy_pub *ppi)
  1729. {
  1730. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1731. return pi->phytest_on;
  1732. }
  1733. void wlc_phy_ant_rxdiv_set(struct brcms_phy_pub *ppi, u8 val)
  1734. {
  1735. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  1736. bool suspend;
  1737. pi->sh->rx_antdiv = val;
  1738. if (!(ISNPHY(pi) && D11REV_IS(pi->sh->corerev, 16))) {
  1739. if (val > ANT_RX_DIV_FORCE_1)
  1740. wlapi_bmac_mhf(pi->sh->physhim, MHF1, MHF1_ANTDIV,
  1741. MHF1_ANTDIV, BRCM_BAND_ALL);
  1742. else
  1743. wlapi_bmac_mhf(pi->sh->physhim, MHF1, MHF1_ANTDIV, 0,
  1744. BRCM_BAND_ALL);
  1745. }
  1746. if (ISNPHY(pi))
  1747. return;
  1748. if (!pi->sh->clk)
  1749. return;
  1750. suspend = (0 == (R_REG(&pi->regs->maccontrol) & 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. OR_REG(&pi->regs->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. OR_REG(&pi->regs->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 == BCM4313_CHIP_ID) &&
  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_corereg(pi->sh->sih, SI_CC_IDX,
  2345. offsetof(struct chipcregs, gpiocontrol),
  2346. ~0x0, 0x0);
  2347. ai_corereg(pi->sh->sih, SI_CC_IDX,
  2348. offsetof(struct chipcregs, gpioout), 0x40,
  2349. 0x40);
  2350. ai_corereg(pi->sh->sih, SI_CC_IDX,
  2351. offsetof(struct chipcregs, gpioouten), 0x40,
  2352. 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_corereg(pi->sh->sih, SI_CC_IDX,
  2357. offsetof(struct chipcregs, gpioout), 0x40,
  2358. 0x00);
  2359. ai_corereg(pi->sh->sih, SI_CC_IDX,
  2360. offsetof(struct chipcregs, gpioouten), 0x40,
  2361. 0x0);
  2362. ai_corereg(pi->sh->sih, SI_CC_IDX,
  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. }