phy_cmn.c 70 KB

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