phy_cmn.c 69 KB

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