phy_g.c 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071
  1. /*
  2. Broadcom B43 wireless driver
  3. IEEE 802.11g PHY driver
  4. Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
  5. Copyright (c) 2005-2007 Stefano Brivio <stefano.brivio@polimi.it>
  6. Copyright (c) 2005-2008 Michael Buesch <m@bues.ch>
  7. Copyright (c) 2005, 2006 Danny van Dyk <kugelfang@gentoo.org>
  8. Copyright (c) 2005, 2006 Andreas Jaggi <andreas.jaggi@waterwave.ch>
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; see the file COPYING. If not, write to
  19. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  20. Boston, MA 02110-1301, USA.
  21. */
  22. #include "b43.h"
  23. #include "phy_g.h"
  24. #include "phy_common.h"
  25. #include "lo.h"
  26. #include "main.h"
  27. #include "wa.h"
  28. #include <linux/bitrev.h>
  29. #include <linux/slab.h>
  30. static const s8 b43_tssi2dbm_g_table[] = {
  31. 77, 77, 77, 76,
  32. 76, 76, 75, 75,
  33. 74, 74, 73, 73,
  34. 73, 72, 72, 71,
  35. 71, 70, 70, 69,
  36. 68, 68, 67, 67,
  37. 66, 65, 65, 64,
  38. 63, 63, 62, 61,
  39. 60, 59, 58, 57,
  40. 56, 55, 54, 53,
  41. 52, 50, 49, 47,
  42. 45, 43, 40, 37,
  43. 33, 28, 22, 14,
  44. 5, -7, -20, -20,
  45. -20, -20, -20, -20,
  46. -20, -20, -20, -20,
  47. };
  48. static const u8 b43_radio_channel_codes_bg[] = {
  49. 12, 17, 22, 27,
  50. 32, 37, 42, 47,
  51. 52, 57, 62, 67,
  52. 72, 84,
  53. };
  54. static void b43_calc_nrssi_threshold(struct b43_wldev *dev);
  55. #define bitrev4(tmp) (bitrev8(tmp) >> 4)
  56. /* Get the freq, as it has to be written to the device. */
  57. static inline u16 channel2freq_bg(u8 channel)
  58. {
  59. B43_WARN_ON(!(channel >= 1 && channel <= 14));
  60. return b43_radio_channel_codes_bg[channel - 1];
  61. }
  62. static void generate_rfatt_list(struct b43_wldev *dev,
  63. struct b43_rfatt_list *list)
  64. {
  65. struct b43_phy *phy = &dev->phy;
  66. /* APHY.rev < 5 || GPHY.rev < 6 */
  67. static const struct b43_rfatt rfatt_0[] = {
  68. {.att = 3,.with_padmix = 0,},
  69. {.att = 1,.with_padmix = 0,},
  70. {.att = 5,.with_padmix = 0,},
  71. {.att = 7,.with_padmix = 0,},
  72. {.att = 9,.with_padmix = 0,},
  73. {.att = 2,.with_padmix = 0,},
  74. {.att = 0,.with_padmix = 0,},
  75. {.att = 4,.with_padmix = 0,},
  76. {.att = 6,.with_padmix = 0,},
  77. {.att = 8,.with_padmix = 0,},
  78. {.att = 1,.with_padmix = 1,},
  79. {.att = 2,.with_padmix = 1,},
  80. {.att = 3,.with_padmix = 1,},
  81. {.att = 4,.with_padmix = 1,},
  82. };
  83. /* Radio.rev == 8 && Radio.version == 0x2050 */
  84. static const struct b43_rfatt rfatt_1[] = {
  85. {.att = 2,.with_padmix = 1,},
  86. {.att = 4,.with_padmix = 1,},
  87. {.att = 6,.with_padmix = 1,},
  88. {.att = 8,.with_padmix = 1,},
  89. {.att = 10,.with_padmix = 1,},
  90. {.att = 12,.with_padmix = 1,},
  91. {.att = 14,.with_padmix = 1,},
  92. };
  93. /* Otherwise */
  94. static const struct b43_rfatt rfatt_2[] = {
  95. {.att = 0,.with_padmix = 1,},
  96. {.att = 2,.with_padmix = 1,},
  97. {.att = 4,.with_padmix = 1,},
  98. {.att = 6,.with_padmix = 1,},
  99. {.att = 8,.with_padmix = 1,},
  100. {.att = 9,.with_padmix = 1,},
  101. {.att = 9,.with_padmix = 1,},
  102. };
  103. if (!b43_has_hardware_pctl(dev)) {
  104. /* Software pctl */
  105. list->list = rfatt_0;
  106. list->len = ARRAY_SIZE(rfatt_0);
  107. list->min_val = 0;
  108. list->max_val = 9;
  109. return;
  110. }
  111. if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
  112. /* Hardware pctl */
  113. list->list = rfatt_1;
  114. list->len = ARRAY_SIZE(rfatt_1);
  115. list->min_val = 0;
  116. list->max_val = 14;
  117. return;
  118. }
  119. /* Hardware pctl */
  120. list->list = rfatt_2;
  121. list->len = ARRAY_SIZE(rfatt_2);
  122. list->min_val = 0;
  123. list->max_val = 9;
  124. }
  125. static void generate_bbatt_list(struct b43_wldev *dev,
  126. struct b43_bbatt_list *list)
  127. {
  128. static const struct b43_bbatt bbatt_0[] = {
  129. {.att = 0,},
  130. {.att = 1,},
  131. {.att = 2,},
  132. {.att = 3,},
  133. {.att = 4,},
  134. {.att = 5,},
  135. {.att = 6,},
  136. {.att = 7,},
  137. {.att = 8,},
  138. };
  139. list->list = bbatt_0;
  140. list->len = ARRAY_SIZE(bbatt_0);
  141. list->min_val = 0;
  142. list->max_val = 8;
  143. }
  144. static void b43_shm_clear_tssi(struct b43_wldev *dev)
  145. {
  146. b43_shm_write16(dev, B43_SHM_SHARED, 0x0058, 0x7F7F);
  147. b43_shm_write16(dev, B43_SHM_SHARED, 0x005a, 0x7F7F);
  148. b43_shm_write16(dev, B43_SHM_SHARED, 0x0070, 0x7F7F);
  149. b43_shm_write16(dev, B43_SHM_SHARED, 0x0072, 0x7F7F);
  150. }
  151. /* Synthetic PU workaround */
  152. static void b43_synth_pu_workaround(struct b43_wldev *dev, u8 channel)
  153. {
  154. struct b43_phy *phy = &dev->phy;
  155. might_sleep();
  156. if (phy->radio_ver != 0x2050 || phy->radio_rev >= 6) {
  157. /* We do not need the workaround. */
  158. return;
  159. }
  160. if (channel <= 10) {
  161. b43_write16(dev, B43_MMIO_CHANNEL,
  162. channel2freq_bg(channel + 4));
  163. } else {
  164. b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(1));
  165. }
  166. msleep(1);
  167. b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(channel));
  168. }
  169. /* Set the baseband attenuation value on chip. */
  170. void b43_gphy_set_baseband_attenuation(struct b43_wldev *dev,
  171. u16 baseband_attenuation)
  172. {
  173. struct b43_phy *phy = &dev->phy;
  174. if (phy->analog == 0) {
  175. b43_write16(dev, B43_MMIO_PHY0, (b43_read16(dev, B43_MMIO_PHY0)
  176. & 0xFFF0) |
  177. baseband_attenuation);
  178. } else if (phy->analog > 1) {
  179. b43_phy_maskset(dev, B43_PHY_DACCTL, 0xFFC3, (baseband_attenuation << 2));
  180. } else {
  181. b43_phy_maskset(dev, B43_PHY_DACCTL, 0xFF87, (baseband_attenuation << 3));
  182. }
  183. }
  184. /* Adjust the transmission power output (G-PHY) */
  185. static void b43_set_txpower_g(struct b43_wldev *dev,
  186. const struct b43_bbatt *bbatt,
  187. const struct b43_rfatt *rfatt, u8 tx_control)
  188. {
  189. struct b43_phy *phy = &dev->phy;
  190. struct b43_phy_g *gphy = phy->g;
  191. struct b43_txpower_lo_control *lo = gphy->lo_control;
  192. u16 bb, rf;
  193. u16 tx_bias, tx_magn;
  194. bb = bbatt->att;
  195. rf = rfatt->att;
  196. tx_bias = lo->tx_bias;
  197. tx_magn = lo->tx_magn;
  198. if (unlikely(tx_bias == 0xFF))
  199. tx_bias = 0;
  200. /* Save the values for later. Use memmove, because it's valid
  201. * to pass &gphy->rfatt as rfatt pointer argument. Same for bbatt. */
  202. gphy->tx_control = tx_control;
  203. memmove(&gphy->rfatt, rfatt, sizeof(*rfatt));
  204. gphy->rfatt.with_padmix = !!(tx_control & B43_TXCTL_TXMIX);
  205. memmove(&gphy->bbatt, bbatt, sizeof(*bbatt));
  206. if (b43_debug(dev, B43_DBG_XMITPOWER)) {
  207. b43dbg(dev->wl, "Tuning TX-power to bbatt(%u), "
  208. "rfatt(%u), tx_control(0x%02X), "
  209. "tx_bias(0x%02X), tx_magn(0x%02X)\n",
  210. bb, rf, tx_control, tx_bias, tx_magn);
  211. }
  212. b43_gphy_set_baseband_attenuation(dev, bb);
  213. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_RFATT, rf);
  214. if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
  215. b43_radio_write16(dev, 0x43,
  216. (rf & 0x000F) | (tx_control & 0x0070));
  217. } else {
  218. b43_radio_maskset(dev, 0x43, 0xFFF0, (rf & 0x000F));
  219. b43_radio_maskset(dev, 0x52, ~0x0070, (tx_control & 0x0070));
  220. }
  221. if (has_tx_magnification(phy)) {
  222. b43_radio_write16(dev, 0x52, tx_magn | tx_bias);
  223. } else {
  224. b43_radio_maskset(dev, 0x52, 0xFFF0, (tx_bias & 0x000F));
  225. }
  226. b43_lo_g_adjust(dev);
  227. }
  228. /* GPHY_TSSI_Power_Lookup_Table_Init */
  229. static void b43_gphy_tssi_power_lt_init(struct b43_wldev *dev)
  230. {
  231. struct b43_phy_g *gphy = dev->phy.g;
  232. int i;
  233. u16 value;
  234. for (i = 0; i < 32; i++)
  235. b43_ofdmtab_write16(dev, 0x3C20, i, gphy->tssi2dbm[i]);
  236. for (i = 32; i < 64; i++)
  237. b43_ofdmtab_write16(dev, 0x3C00, i - 32, gphy->tssi2dbm[i]);
  238. for (i = 0; i < 64; i += 2) {
  239. value = (u16) gphy->tssi2dbm[i];
  240. value |= ((u16) gphy->tssi2dbm[i + 1]) << 8;
  241. b43_phy_write(dev, 0x380 + (i / 2), value);
  242. }
  243. }
  244. /* GPHY_Gain_Lookup_Table_Init */
  245. static void b43_gphy_gain_lt_init(struct b43_wldev *dev)
  246. {
  247. struct b43_phy *phy = &dev->phy;
  248. struct b43_phy_g *gphy = phy->g;
  249. struct b43_txpower_lo_control *lo = gphy->lo_control;
  250. u16 nr_written = 0;
  251. u16 tmp;
  252. u8 rf, bb;
  253. for (rf = 0; rf < lo->rfatt_list.len; rf++) {
  254. for (bb = 0; bb < lo->bbatt_list.len; bb++) {
  255. if (nr_written >= 0x40)
  256. return;
  257. tmp = lo->bbatt_list.list[bb].att;
  258. tmp <<= 8;
  259. if (phy->radio_rev == 8)
  260. tmp |= 0x50;
  261. else
  262. tmp |= 0x40;
  263. tmp |= lo->rfatt_list.list[rf].att;
  264. b43_phy_write(dev, 0x3C0 + nr_written, tmp);
  265. nr_written++;
  266. }
  267. }
  268. }
  269. static void b43_set_all_gains(struct b43_wldev *dev,
  270. s16 first, s16 second, s16 third)
  271. {
  272. struct b43_phy *phy = &dev->phy;
  273. u16 i;
  274. u16 start = 0x08, end = 0x18;
  275. u16 tmp;
  276. u16 table;
  277. if (phy->rev <= 1) {
  278. start = 0x10;
  279. end = 0x20;
  280. }
  281. table = B43_OFDMTAB_GAINX;
  282. if (phy->rev <= 1)
  283. table = B43_OFDMTAB_GAINX_R1;
  284. for (i = 0; i < 4; i++)
  285. b43_ofdmtab_write16(dev, table, i, first);
  286. for (i = start; i < end; i++)
  287. b43_ofdmtab_write16(dev, table, i, second);
  288. if (third != -1) {
  289. tmp = ((u16) third << 14) | ((u16) third << 6);
  290. b43_phy_maskset(dev, 0x04A0, 0xBFBF, tmp);
  291. b43_phy_maskset(dev, 0x04A1, 0xBFBF, tmp);
  292. b43_phy_maskset(dev, 0x04A2, 0xBFBF, tmp);
  293. }
  294. b43_dummy_transmission(dev, false, true);
  295. }
  296. static void b43_set_original_gains(struct b43_wldev *dev)
  297. {
  298. struct b43_phy *phy = &dev->phy;
  299. u16 i, tmp;
  300. u16 table;
  301. u16 start = 0x0008, end = 0x0018;
  302. if (phy->rev <= 1) {
  303. start = 0x0010;
  304. end = 0x0020;
  305. }
  306. table = B43_OFDMTAB_GAINX;
  307. if (phy->rev <= 1)
  308. table = B43_OFDMTAB_GAINX_R1;
  309. for (i = 0; i < 4; i++) {
  310. tmp = (i & 0xFFFC);
  311. tmp |= (i & 0x0001) << 1;
  312. tmp |= (i & 0x0002) >> 1;
  313. b43_ofdmtab_write16(dev, table, i, tmp);
  314. }
  315. for (i = start; i < end; i++)
  316. b43_ofdmtab_write16(dev, table, i, i - start);
  317. b43_phy_maskset(dev, 0x04A0, 0xBFBF, 0x4040);
  318. b43_phy_maskset(dev, 0x04A1, 0xBFBF, 0x4040);
  319. b43_phy_maskset(dev, 0x04A2, 0xBFBF, 0x4000);
  320. b43_dummy_transmission(dev, false, true);
  321. }
  322. /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
  323. static void b43_nrssi_hw_write(struct b43_wldev *dev, u16 offset, s16 val)
  324. {
  325. b43_phy_write(dev, B43_PHY_NRSSILT_CTRL, offset);
  326. b43_phy_write(dev, B43_PHY_NRSSILT_DATA, (u16) val);
  327. }
  328. /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
  329. static s16 b43_nrssi_hw_read(struct b43_wldev *dev, u16 offset)
  330. {
  331. u16 val;
  332. b43_phy_write(dev, B43_PHY_NRSSILT_CTRL, offset);
  333. val = b43_phy_read(dev, B43_PHY_NRSSILT_DATA);
  334. return (s16) val;
  335. }
  336. /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
  337. static void b43_nrssi_hw_update(struct b43_wldev *dev, u16 val)
  338. {
  339. u16 i;
  340. s16 tmp;
  341. for (i = 0; i < 64; i++) {
  342. tmp = b43_nrssi_hw_read(dev, i);
  343. tmp -= val;
  344. tmp = clamp_val(tmp, -32, 31);
  345. b43_nrssi_hw_write(dev, i, tmp);
  346. }
  347. }
  348. /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
  349. static void b43_nrssi_mem_update(struct b43_wldev *dev)
  350. {
  351. struct b43_phy_g *gphy = dev->phy.g;
  352. s16 i, delta;
  353. s32 tmp;
  354. delta = 0x1F - gphy->nrssi[0];
  355. for (i = 0; i < 64; i++) {
  356. tmp = (i - delta) * gphy->nrssislope;
  357. tmp /= 0x10000;
  358. tmp += 0x3A;
  359. tmp = clamp_val(tmp, 0, 0x3F);
  360. gphy->nrssi_lt[i] = tmp;
  361. }
  362. }
  363. static void b43_calc_nrssi_offset(struct b43_wldev *dev)
  364. {
  365. struct b43_phy *phy = &dev->phy;
  366. u16 backup[20] = { 0 };
  367. s16 v47F;
  368. u16 i;
  369. u16 saved = 0xFFFF;
  370. backup[0] = b43_phy_read(dev, 0x0001);
  371. backup[1] = b43_phy_read(dev, 0x0811);
  372. backup[2] = b43_phy_read(dev, 0x0812);
  373. if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
  374. backup[3] = b43_phy_read(dev, 0x0814);
  375. backup[4] = b43_phy_read(dev, 0x0815);
  376. }
  377. backup[5] = b43_phy_read(dev, 0x005A);
  378. backup[6] = b43_phy_read(dev, 0x0059);
  379. backup[7] = b43_phy_read(dev, 0x0058);
  380. backup[8] = b43_phy_read(dev, 0x000A);
  381. backup[9] = b43_phy_read(dev, 0x0003);
  382. backup[10] = b43_radio_read16(dev, 0x007A);
  383. backup[11] = b43_radio_read16(dev, 0x0043);
  384. b43_phy_mask(dev, 0x0429, 0x7FFF);
  385. b43_phy_maskset(dev, 0x0001, 0x3FFF, 0x4000);
  386. b43_phy_set(dev, 0x0811, 0x000C);
  387. b43_phy_maskset(dev, 0x0812, 0xFFF3, 0x0004);
  388. b43_phy_mask(dev, 0x0802, ~(0x1 | 0x2));
  389. if (phy->rev >= 6) {
  390. backup[12] = b43_phy_read(dev, 0x002E);
  391. backup[13] = b43_phy_read(dev, 0x002F);
  392. backup[14] = b43_phy_read(dev, 0x080F);
  393. backup[15] = b43_phy_read(dev, 0x0810);
  394. backup[16] = b43_phy_read(dev, 0x0801);
  395. backup[17] = b43_phy_read(dev, 0x0060);
  396. backup[18] = b43_phy_read(dev, 0x0014);
  397. backup[19] = b43_phy_read(dev, 0x0478);
  398. b43_phy_write(dev, 0x002E, 0);
  399. b43_phy_write(dev, 0x002F, 0);
  400. b43_phy_write(dev, 0x080F, 0);
  401. b43_phy_write(dev, 0x0810, 0);
  402. b43_phy_set(dev, 0x0478, 0x0100);
  403. b43_phy_set(dev, 0x0801, 0x0040);
  404. b43_phy_set(dev, 0x0060, 0x0040);
  405. b43_phy_set(dev, 0x0014, 0x0200);
  406. }
  407. b43_radio_set(dev, 0x007A, 0x0070);
  408. b43_radio_set(dev, 0x007A, 0x0080);
  409. udelay(30);
  410. v47F = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
  411. if (v47F >= 0x20)
  412. v47F -= 0x40;
  413. if (v47F == 31) {
  414. for (i = 7; i >= 4; i--) {
  415. b43_radio_write16(dev, 0x007B, i);
  416. udelay(20);
  417. v47F =
  418. (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
  419. if (v47F >= 0x20)
  420. v47F -= 0x40;
  421. if (v47F < 31 && saved == 0xFFFF)
  422. saved = i;
  423. }
  424. if (saved == 0xFFFF)
  425. saved = 4;
  426. } else {
  427. b43_radio_mask(dev, 0x007A, 0x007F);
  428. if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
  429. b43_phy_set(dev, 0x0814, 0x0001);
  430. b43_phy_mask(dev, 0x0815, 0xFFFE);
  431. }
  432. b43_phy_set(dev, 0x0811, 0x000C);
  433. b43_phy_set(dev, 0x0812, 0x000C);
  434. b43_phy_set(dev, 0x0811, 0x0030);
  435. b43_phy_set(dev, 0x0812, 0x0030);
  436. b43_phy_write(dev, 0x005A, 0x0480);
  437. b43_phy_write(dev, 0x0059, 0x0810);
  438. b43_phy_write(dev, 0x0058, 0x000D);
  439. if (phy->rev == 0) {
  440. b43_phy_write(dev, 0x0003, 0x0122);
  441. } else {
  442. b43_phy_set(dev, 0x000A, 0x2000);
  443. }
  444. if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
  445. b43_phy_set(dev, 0x0814, 0x0004);
  446. b43_phy_mask(dev, 0x0815, 0xFFFB);
  447. }
  448. b43_phy_maskset(dev, 0x0003, 0xFF9F, 0x0040);
  449. b43_radio_set(dev, 0x007A, 0x000F);
  450. b43_set_all_gains(dev, 3, 0, 1);
  451. b43_radio_maskset(dev, 0x0043, 0x00F0, 0x000F);
  452. udelay(30);
  453. v47F = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
  454. if (v47F >= 0x20)
  455. v47F -= 0x40;
  456. if (v47F == -32) {
  457. for (i = 0; i < 4; i++) {
  458. b43_radio_write16(dev, 0x007B, i);
  459. udelay(20);
  460. v47F =
  461. (s16) ((b43_phy_read(dev, 0x047F) >> 8) &
  462. 0x003F);
  463. if (v47F >= 0x20)
  464. v47F -= 0x40;
  465. if (v47F > -31 && saved == 0xFFFF)
  466. saved = i;
  467. }
  468. if (saved == 0xFFFF)
  469. saved = 3;
  470. } else
  471. saved = 0;
  472. }
  473. b43_radio_write16(dev, 0x007B, saved);
  474. if (phy->rev >= 6) {
  475. b43_phy_write(dev, 0x002E, backup[12]);
  476. b43_phy_write(dev, 0x002F, backup[13]);
  477. b43_phy_write(dev, 0x080F, backup[14]);
  478. b43_phy_write(dev, 0x0810, backup[15]);
  479. }
  480. if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
  481. b43_phy_write(dev, 0x0814, backup[3]);
  482. b43_phy_write(dev, 0x0815, backup[4]);
  483. }
  484. b43_phy_write(dev, 0x005A, backup[5]);
  485. b43_phy_write(dev, 0x0059, backup[6]);
  486. b43_phy_write(dev, 0x0058, backup[7]);
  487. b43_phy_write(dev, 0x000A, backup[8]);
  488. b43_phy_write(dev, 0x0003, backup[9]);
  489. b43_radio_write16(dev, 0x0043, backup[11]);
  490. b43_radio_write16(dev, 0x007A, backup[10]);
  491. b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x1 | 0x2);
  492. b43_phy_set(dev, 0x0429, 0x8000);
  493. b43_set_original_gains(dev);
  494. if (phy->rev >= 6) {
  495. b43_phy_write(dev, 0x0801, backup[16]);
  496. b43_phy_write(dev, 0x0060, backup[17]);
  497. b43_phy_write(dev, 0x0014, backup[18]);
  498. b43_phy_write(dev, 0x0478, backup[19]);
  499. }
  500. b43_phy_write(dev, 0x0001, backup[0]);
  501. b43_phy_write(dev, 0x0812, backup[2]);
  502. b43_phy_write(dev, 0x0811, backup[1]);
  503. }
  504. static void b43_calc_nrssi_slope(struct b43_wldev *dev)
  505. {
  506. struct b43_phy *phy = &dev->phy;
  507. struct b43_phy_g *gphy = phy->g;
  508. u16 backup[18] = { 0 };
  509. u16 tmp;
  510. s16 nrssi0, nrssi1;
  511. B43_WARN_ON(phy->type != B43_PHYTYPE_G);
  512. if (phy->radio_rev >= 9)
  513. return;
  514. if (phy->radio_rev == 8)
  515. b43_calc_nrssi_offset(dev);
  516. b43_phy_mask(dev, B43_PHY_G_CRS, 0x7FFF);
  517. b43_phy_mask(dev, 0x0802, 0xFFFC);
  518. backup[7] = b43_read16(dev, 0x03E2);
  519. b43_write16(dev, 0x03E2, b43_read16(dev, 0x03E2) | 0x8000);
  520. backup[0] = b43_radio_read16(dev, 0x007A);
  521. backup[1] = b43_radio_read16(dev, 0x0052);
  522. backup[2] = b43_radio_read16(dev, 0x0043);
  523. backup[3] = b43_phy_read(dev, 0x0015);
  524. backup[4] = b43_phy_read(dev, 0x005A);
  525. backup[5] = b43_phy_read(dev, 0x0059);
  526. backup[6] = b43_phy_read(dev, 0x0058);
  527. backup[8] = b43_read16(dev, 0x03E6);
  528. backup[9] = b43_read16(dev, B43_MMIO_CHANNEL_EXT);
  529. if (phy->rev >= 3) {
  530. backup[10] = b43_phy_read(dev, 0x002E);
  531. backup[11] = b43_phy_read(dev, 0x002F);
  532. backup[12] = b43_phy_read(dev, 0x080F);
  533. backup[13] = b43_phy_read(dev, B43_PHY_G_LO_CONTROL);
  534. backup[14] = b43_phy_read(dev, 0x0801);
  535. backup[15] = b43_phy_read(dev, 0x0060);
  536. backup[16] = b43_phy_read(dev, 0x0014);
  537. backup[17] = b43_phy_read(dev, 0x0478);
  538. b43_phy_write(dev, 0x002E, 0);
  539. b43_phy_write(dev, B43_PHY_G_LO_CONTROL, 0);
  540. switch (phy->rev) {
  541. case 4:
  542. case 6:
  543. case 7:
  544. b43_phy_set(dev, 0x0478, 0x0100);
  545. b43_phy_set(dev, 0x0801, 0x0040);
  546. break;
  547. case 3:
  548. case 5:
  549. b43_phy_mask(dev, 0x0801, 0xFFBF);
  550. break;
  551. }
  552. b43_phy_set(dev, 0x0060, 0x0040);
  553. b43_phy_set(dev, 0x0014, 0x0200);
  554. }
  555. b43_radio_set(dev, 0x007A, 0x0070);
  556. b43_set_all_gains(dev, 0, 8, 0);
  557. b43_radio_mask(dev, 0x007A, 0x00F7);
  558. if (phy->rev >= 2) {
  559. b43_phy_maskset(dev, 0x0811, 0xFFCF, 0x0030);
  560. b43_phy_maskset(dev, 0x0812, 0xFFCF, 0x0010);
  561. }
  562. b43_radio_set(dev, 0x007A, 0x0080);
  563. udelay(20);
  564. nrssi0 = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
  565. if (nrssi0 >= 0x0020)
  566. nrssi0 -= 0x0040;
  567. b43_radio_mask(dev, 0x007A, 0x007F);
  568. if (phy->rev >= 2) {
  569. b43_phy_maskset(dev, 0x0003, 0xFF9F, 0x0040);
  570. }
  571. b43_write16(dev, B43_MMIO_CHANNEL_EXT,
  572. b43_read16(dev, B43_MMIO_CHANNEL_EXT)
  573. | 0x2000);
  574. b43_radio_set(dev, 0x007A, 0x000F);
  575. b43_phy_write(dev, 0x0015, 0xF330);
  576. if (phy->rev >= 2) {
  577. b43_phy_maskset(dev, 0x0812, 0xFFCF, 0x0020);
  578. b43_phy_maskset(dev, 0x0811, 0xFFCF, 0x0020);
  579. }
  580. b43_set_all_gains(dev, 3, 0, 1);
  581. if (phy->radio_rev == 8) {
  582. b43_radio_write16(dev, 0x0043, 0x001F);
  583. } else {
  584. tmp = b43_radio_read16(dev, 0x0052) & 0xFF0F;
  585. b43_radio_write16(dev, 0x0052, tmp | 0x0060);
  586. tmp = b43_radio_read16(dev, 0x0043) & 0xFFF0;
  587. b43_radio_write16(dev, 0x0043, tmp | 0x0009);
  588. }
  589. b43_phy_write(dev, 0x005A, 0x0480);
  590. b43_phy_write(dev, 0x0059, 0x0810);
  591. b43_phy_write(dev, 0x0058, 0x000D);
  592. udelay(20);
  593. nrssi1 = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
  594. if (nrssi1 >= 0x0020)
  595. nrssi1 -= 0x0040;
  596. if (nrssi0 == nrssi1)
  597. gphy->nrssislope = 0x00010000;
  598. else
  599. gphy->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
  600. if (nrssi0 >= -4) {
  601. gphy->nrssi[0] = nrssi1;
  602. gphy->nrssi[1] = nrssi0;
  603. }
  604. if (phy->rev >= 3) {
  605. b43_phy_write(dev, 0x002E, backup[10]);
  606. b43_phy_write(dev, 0x002F, backup[11]);
  607. b43_phy_write(dev, 0x080F, backup[12]);
  608. b43_phy_write(dev, B43_PHY_G_LO_CONTROL, backup[13]);
  609. }
  610. if (phy->rev >= 2) {
  611. b43_phy_mask(dev, 0x0812, 0xFFCF);
  612. b43_phy_mask(dev, 0x0811, 0xFFCF);
  613. }
  614. b43_radio_write16(dev, 0x007A, backup[0]);
  615. b43_radio_write16(dev, 0x0052, backup[1]);
  616. b43_radio_write16(dev, 0x0043, backup[2]);
  617. b43_write16(dev, 0x03E2, backup[7]);
  618. b43_write16(dev, 0x03E6, backup[8]);
  619. b43_write16(dev, B43_MMIO_CHANNEL_EXT, backup[9]);
  620. b43_phy_write(dev, 0x0015, backup[3]);
  621. b43_phy_write(dev, 0x005A, backup[4]);
  622. b43_phy_write(dev, 0x0059, backup[5]);
  623. b43_phy_write(dev, 0x0058, backup[6]);
  624. b43_synth_pu_workaround(dev, phy->channel);
  625. b43_phy_set(dev, 0x0802, (0x0001 | 0x0002));
  626. b43_set_original_gains(dev);
  627. b43_phy_set(dev, B43_PHY_G_CRS, 0x8000);
  628. if (phy->rev >= 3) {
  629. b43_phy_write(dev, 0x0801, backup[14]);
  630. b43_phy_write(dev, 0x0060, backup[15]);
  631. b43_phy_write(dev, 0x0014, backup[16]);
  632. b43_phy_write(dev, 0x0478, backup[17]);
  633. }
  634. b43_nrssi_mem_update(dev);
  635. b43_calc_nrssi_threshold(dev);
  636. }
  637. static void b43_calc_nrssi_threshold(struct b43_wldev *dev)
  638. {
  639. struct b43_phy *phy = &dev->phy;
  640. struct b43_phy_g *gphy = phy->g;
  641. s32 a, b;
  642. s16 tmp16;
  643. u16 tmp_u16;
  644. B43_WARN_ON(phy->type != B43_PHYTYPE_G);
  645. if (!phy->gmode ||
  646. !(dev->dev->bus_sprom->boardflags_lo & B43_BFL_RSSI)) {
  647. tmp16 = b43_nrssi_hw_read(dev, 0x20);
  648. if (tmp16 >= 0x20)
  649. tmp16 -= 0x40;
  650. if (tmp16 < 3) {
  651. b43_phy_maskset(dev, 0x048A, 0xF000, 0x09EB);
  652. } else {
  653. b43_phy_maskset(dev, 0x048A, 0xF000, 0x0AED);
  654. }
  655. } else {
  656. if (gphy->interfmode == B43_INTERFMODE_NONWLAN) {
  657. a = 0xE;
  658. b = 0xA;
  659. } else if (!gphy->aci_wlan_automatic && gphy->aci_enable) {
  660. a = 0x13;
  661. b = 0x12;
  662. } else {
  663. a = 0xE;
  664. b = 0x11;
  665. }
  666. a = a * (gphy->nrssi[1] - gphy->nrssi[0]);
  667. a += (gphy->nrssi[0] << 6);
  668. if (a < 32)
  669. a += 31;
  670. else
  671. a += 32;
  672. a = a >> 6;
  673. a = clamp_val(a, -31, 31);
  674. b = b * (gphy->nrssi[1] - gphy->nrssi[0]);
  675. b += (gphy->nrssi[0] << 6);
  676. if (b < 32)
  677. b += 31;
  678. else
  679. b += 32;
  680. b = b >> 6;
  681. b = clamp_val(b, -31, 31);
  682. tmp_u16 = b43_phy_read(dev, 0x048A) & 0xF000;
  683. tmp_u16 |= ((u32) b & 0x0000003F);
  684. tmp_u16 |= (((u32) a & 0x0000003F) << 6);
  685. b43_phy_write(dev, 0x048A, tmp_u16);
  686. }
  687. }
  688. /* Stack implementation to save/restore values from the
  689. * interference mitigation code.
  690. * It is save to restore values in random order.
  691. */
  692. static void _stack_save(u32 *_stackptr, size_t *stackidx,
  693. u8 id, u16 offset, u16 value)
  694. {
  695. u32 *stackptr = &(_stackptr[*stackidx]);
  696. B43_WARN_ON(offset & 0xF000);
  697. B43_WARN_ON(id & 0xF0);
  698. *stackptr = offset;
  699. *stackptr |= ((u32) id) << 12;
  700. *stackptr |= ((u32) value) << 16;
  701. (*stackidx)++;
  702. B43_WARN_ON(*stackidx >= B43_INTERFSTACK_SIZE);
  703. }
  704. static u16 _stack_restore(u32 *stackptr, u8 id, u16 offset)
  705. {
  706. size_t i;
  707. B43_WARN_ON(offset & 0xF000);
  708. B43_WARN_ON(id & 0xF0);
  709. for (i = 0; i < B43_INTERFSTACK_SIZE; i++, stackptr++) {
  710. if ((*stackptr & 0x00000FFF) != offset)
  711. continue;
  712. if (((*stackptr & 0x0000F000) >> 12) != id)
  713. continue;
  714. return ((*stackptr & 0xFFFF0000) >> 16);
  715. }
  716. B43_WARN_ON(1);
  717. return 0;
  718. }
  719. #define phy_stacksave(offset) \
  720. do { \
  721. _stack_save(stack, &stackidx, 0x1, (offset), \
  722. b43_phy_read(dev, (offset))); \
  723. } while (0)
  724. #define phy_stackrestore(offset) \
  725. do { \
  726. b43_phy_write(dev, (offset), \
  727. _stack_restore(stack, 0x1, \
  728. (offset))); \
  729. } while (0)
  730. #define radio_stacksave(offset) \
  731. do { \
  732. _stack_save(stack, &stackidx, 0x2, (offset), \
  733. b43_radio_read16(dev, (offset))); \
  734. } while (0)
  735. #define radio_stackrestore(offset) \
  736. do { \
  737. b43_radio_write16(dev, (offset), \
  738. _stack_restore(stack, 0x2, \
  739. (offset))); \
  740. } while (0)
  741. #define ofdmtab_stacksave(table, offset) \
  742. do { \
  743. _stack_save(stack, &stackidx, 0x3, (offset)|(table), \
  744. b43_ofdmtab_read16(dev, (table), (offset))); \
  745. } while (0)
  746. #define ofdmtab_stackrestore(table, offset) \
  747. do { \
  748. b43_ofdmtab_write16(dev, (table), (offset), \
  749. _stack_restore(stack, 0x3, \
  750. (offset)|(table))); \
  751. } while (0)
  752. static void
  753. b43_radio_interference_mitigation_enable(struct b43_wldev *dev, int mode)
  754. {
  755. struct b43_phy *phy = &dev->phy;
  756. struct b43_phy_g *gphy = phy->g;
  757. u16 tmp, flipped;
  758. size_t stackidx = 0;
  759. u32 *stack = gphy->interfstack;
  760. switch (mode) {
  761. case B43_INTERFMODE_NONWLAN:
  762. if (phy->rev != 1) {
  763. b43_phy_set(dev, 0x042B, 0x0800);
  764. b43_phy_mask(dev, B43_PHY_G_CRS, ~0x4000);
  765. break;
  766. }
  767. radio_stacksave(0x0078);
  768. tmp = (b43_radio_read16(dev, 0x0078) & 0x001E);
  769. B43_WARN_ON(tmp > 15);
  770. flipped = bitrev4(tmp);
  771. if (flipped < 10 && flipped >= 8)
  772. flipped = 7;
  773. else if (flipped >= 10)
  774. flipped -= 3;
  775. flipped = (bitrev4(flipped) << 1) | 0x0020;
  776. b43_radio_write16(dev, 0x0078, flipped);
  777. b43_calc_nrssi_threshold(dev);
  778. phy_stacksave(0x0406);
  779. b43_phy_write(dev, 0x0406, 0x7E28);
  780. b43_phy_set(dev, 0x042B, 0x0800);
  781. b43_phy_set(dev, B43_PHY_RADIO_BITFIELD, 0x1000);
  782. phy_stacksave(0x04A0);
  783. b43_phy_maskset(dev, 0x04A0, 0xC0C0, 0x0008);
  784. phy_stacksave(0x04A1);
  785. b43_phy_maskset(dev, 0x04A1, 0xC0C0, 0x0605);
  786. phy_stacksave(0x04A2);
  787. b43_phy_maskset(dev, 0x04A2, 0xC0C0, 0x0204);
  788. phy_stacksave(0x04A8);
  789. b43_phy_maskset(dev, 0x04A8, 0xC0C0, 0x0803);
  790. phy_stacksave(0x04AB);
  791. b43_phy_maskset(dev, 0x04AB, 0xC0C0, 0x0605);
  792. phy_stacksave(0x04A7);
  793. b43_phy_write(dev, 0x04A7, 0x0002);
  794. phy_stacksave(0x04A3);
  795. b43_phy_write(dev, 0x04A3, 0x287A);
  796. phy_stacksave(0x04A9);
  797. b43_phy_write(dev, 0x04A9, 0x2027);
  798. phy_stacksave(0x0493);
  799. b43_phy_write(dev, 0x0493, 0x32F5);
  800. phy_stacksave(0x04AA);
  801. b43_phy_write(dev, 0x04AA, 0x2027);
  802. phy_stacksave(0x04AC);
  803. b43_phy_write(dev, 0x04AC, 0x32F5);
  804. break;
  805. case B43_INTERFMODE_MANUALWLAN:
  806. if (b43_phy_read(dev, 0x0033) & 0x0800)
  807. break;
  808. gphy->aci_enable = true;
  809. phy_stacksave(B43_PHY_RADIO_BITFIELD);
  810. phy_stacksave(B43_PHY_G_CRS);
  811. if (phy->rev < 2) {
  812. phy_stacksave(0x0406);
  813. } else {
  814. phy_stacksave(0x04C0);
  815. phy_stacksave(0x04C1);
  816. }
  817. phy_stacksave(0x0033);
  818. phy_stacksave(0x04A7);
  819. phy_stacksave(0x04A3);
  820. phy_stacksave(0x04A9);
  821. phy_stacksave(0x04AA);
  822. phy_stacksave(0x04AC);
  823. phy_stacksave(0x0493);
  824. phy_stacksave(0x04A1);
  825. phy_stacksave(0x04A0);
  826. phy_stacksave(0x04A2);
  827. phy_stacksave(0x048A);
  828. phy_stacksave(0x04A8);
  829. phy_stacksave(0x04AB);
  830. if (phy->rev == 2) {
  831. phy_stacksave(0x04AD);
  832. phy_stacksave(0x04AE);
  833. } else if (phy->rev >= 3) {
  834. phy_stacksave(0x04AD);
  835. phy_stacksave(0x0415);
  836. phy_stacksave(0x0416);
  837. phy_stacksave(0x0417);
  838. ofdmtab_stacksave(0x1A00, 0x2);
  839. ofdmtab_stacksave(0x1A00, 0x3);
  840. }
  841. phy_stacksave(0x042B);
  842. phy_stacksave(0x048C);
  843. b43_phy_mask(dev, B43_PHY_RADIO_BITFIELD, ~0x1000);
  844. b43_phy_maskset(dev, B43_PHY_G_CRS, 0xFFFC, 0x0002);
  845. b43_phy_write(dev, 0x0033, 0x0800);
  846. b43_phy_write(dev, 0x04A3, 0x2027);
  847. b43_phy_write(dev, 0x04A9, 0x1CA8);
  848. b43_phy_write(dev, 0x0493, 0x287A);
  849. b43_phy_write(dev, 0x04AA, 0x1CA8);
  850. b43_phy_write(dev, 0x04AC, 0x287A);
  851. b43_phy_maskset(dev, 0x04A0, 0xFFC0, 0x001A);
  852. b43_phy_write(dev, 0x04A7, 0x000D);
  853. if (phy->rev < 2) {
  854. b43_phy_write(dev, 0x0406, 0xFF0D);
  855. } else if (phy->rev == 2) {
  856. b43_phy_write(dev, 0x04C0, 0xFFFF);
  857. b43_phy_write(dev, 0x04C1, 0x00A9);
  858. } else {
  859. b43_phy_write(dev, 0x04C0, 0x00C1);
  860. b43_phy_write(dev, 0x04C1, 0x0059);
  861. }
  862. b43_phy_maskset(dev, 0x04A1, 0xC0FF, 0x1800);
  863. b43_phy_maskset(dev, 0x04A1, 0xFFC0, 0x0015);
  864. b43_phy_maskset(dev, 0x04A8, 0xCFFF, 0x1000);
  865. b43_phy_maskset(dev, 0x04A8, 0xF0FF, 0x0A00);
  866. b43_phy_maskset(dev, 0x04AB, 0xCFFF, 0x1000);
  867. b43_phy_maskset(dev, 0x04AB, 0xF0FF, 0x0800);
  868. b43_phy_maskset(dev, 0x04AB, 0xFFCF, 0x0010);
  869. b43_phy_maskset(dev, 0x04AB, 0xFFF0, 0x0005);
  870. b43_phy_maskset(dev, 0x04A8, 0xFFCF, 0x0010);
  871. b43_phy_maskset(dev, 0x04A8, 0xFFF0, 0x0006);
  872. b43_phy_maskset(dev, 0x04A2, 0xF0FF, 0x0800);
  873. b43_phy_maskset(dev, 0x04A0, 0xF0FF, 0x0500);
  874. b43_phy_maskset(dev, 0x04A2, 0xFFF0, 0x000B);
  875. if (phy->rev >= 3) {
  876. b43_phy_mask(dev, 0x048A, 0x7FFF);
  877. b43_phy_maskset(dev, 0x0415, 0x8000, 0x36D8);
  878. b43_phy_maskset(dev, 0x0416, 0x8000, 0x36D8);
  879. b43_phy_maskset(dev, 0x0417, 0xFE00, 0x016D);
  880. } else {
  881. b43_phy_set(dev, 0x048A, 0x1000);
  882. b43_phy_maskset(dev, 0x048A, 0x9FFF, 0x2000);
  883. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_ACIW);
  884. }
  885. if (phy->rev >= 2) {
  886. b43_phy_set(dev, 0x042B, 0x0800);
  887. }
  888. b43_phy_maskset(dev, 0x048C, 0xF0FF, 0x0200);
  889. if (phy->rev == 2) {
  890. b43_phy_maskset(dev, 0x04AE, 0xFF00, 0x007F);
  891. b43_phy_maskset(dev, 0x04AD, 0x00FF, 0x1300);
  892. } else if (phy->rev >= 6) {
  893. b43_ofdmtab_write16(dev, 0x1A00, 0x3, 0x007F);
  894. b43_ofdmtab_write16(dev, 0x1A00, 0x2, 0x007F);
  895. b43_phy_mask(dev, 0x04AD, 0x00FF);
  896. }
  897. b43_calc_nrssi_slope(dev);
  898. break;
  899. default:
  900. B43_WARN_ON(1);
  901. }
  902. }
  903. static void
  904. b43_radio_interference_mitigation_disable(struct b43_wldev *dev, int mode)
  905. {
  906. struct b43_phy *phy = &dev->phy;
  907. struct b43_phy_g *gphy = phy->g;
  908. u32 *stack = gphy->interfstack;
  909. switch (mode) {
  910. case B43_INTERFMODE_NONWLAN:
  911. if (phy->rev != 1) {
  912. b43_phy_mask(dev, 0x042B, ~0x0800);
  913. b43_phy_set(dev, B43_PHY_G_CRS, 0x4000);
  914. break;
  915. }
  916. radio_stackrestore(0x0078);
  917. b43_calc_nrssi_threshold(dev);
  918. phy_stackrestore(0x0406);
  919. b43_phy_mask(dev, 0x042B, ~0x0800);
  920. if (!dev->bad_frames_preempt) {
  921. b43_phy_mask(dev, B43_PHY_RADIO_BITFIELD, ~(1 << 11));
  922. }
  923. b43_phy_set(dev, B43_PHY_G_CRS, 0x4000);
  924. phy_stackrestore(0x04A0);
  925. phy_stackrestore(0x04A1);
  926. phy_stackrestore(0x04A2);
  927. phy_stackrestore(0x04A8);
  928. phy_stackrestore(0x04AB);
  929. phy_stackrestore(0x04A7);
  930. phy_stackrestore(0x04A3);
  931. phy_stackrestore(0x04A9);
  932. phy_stackrestore(0x0493);
  933. phy_stackrestore(0x04AA);
  934. phy_stackrestore(0x04AC);
  935. break;
  936. case B43_INTERFMODE_MANUALWLAN:
  937. if (!(b43_phy_read(dev, 0x0033) & 0x0800))
  938. break;
  939. gphy->aci_enable = false;
  940. phy_stackrestore(B43_PHY_RADIO_BITFIELD);
  941. phy_stackrestore(B43_PHY_G_CRS);
  942. phy_stackrestore(0x0033);
  943. phy_stackrestore(0x04A3);
  944. phy_stackrestore(0x04A9);
  945. phy_stackrestore(0x0493);
  946. phy_stackrestore(0x04AA);
  947. phy_stackrestore(0x04AC);
  948. phy_stackrestore(0x04A0);
  949. phy_stackrestore(0x04A7);
  950. if (phy->rev >= 2) {
  951. phy_stackrestore(0x04C0);
  952. phy_stackrestore(0x04C1);
  953. } else
  954. phy_stackrestore(0x0406);
  955. phy_stackrestore(0x04A1);
  956. phy_stackrestore(0x04AB);
  957. phy_stackrestore(0x04A8);
  958. if (phy->rev == 2) {
  959. phy_stackrestore(0x04AD);
  960. phy_stackrestore(0x04AE);
  961. } else if (phy->rev >= 3) {
  962. phy_stackrestore(0x04AD);
  963. phy_stackrestore(0x0415);
  964. phy_stackrestore(0x0416);
  965. phy_stackrestore(0x0417);
  966. ofdmtab_stackrestore(0x1A00, 0x2);
  967. ofdmtab_stackrestore(0x1A00, 0x3);
  968. }
  969. phy_stackrestore(0x04A2);
  970. phy_stackrestore(0x048A);
  971. phy_stackrestore(0x042B);
  972. phy_stackrestore(0x048C);
  973. b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_ACIW);
  974. b43_calc_nrssi_slope(dev);
  975. break;
  976. default:
  977. B43_WARN_ON(1);
  978. }
  979. }
  980. #undef phy_stacksave
  981. #undef phy_stackrestore
  982. #undef radio_stacksave
  983. #undef radio_stackrestore
  984. #undef ofdmtab_stacksave
  985. #undef ofdmtab_stackrestore
  986. static u16 b43_radio_core_calibration_value(struct b43_wldev *dev)
  987. {
  988. u16 reg, index, ret;
  989. static const u8 rcc_table[] = {
  990. 0x02, 0x03, 0x01, 0x0F,
  991. 0x06, 0x07, 0x05, 0x0F,
  992. 0x0A, 0x0B, 0x09, 0x0F,
  993. 0x0E, 0x0F, 0x0D, 0x0F,
  994. };
  995. reg = b43_radio_read16(dev, 0x60);
  996. index = (reg & 0x001E) >> 1;
  997. ret = rcc_table[index] << 1;
  998. ret |= (reg & 0x0001);
  999. ret |= 0x0020;
  1000. return ret;
  1001. }
  1002. #define LPD(L, P, D) (((L) << 2) | ((P) << 1) | ((D) << 0))
  1003. static u16 radio2050_rfover_val(struct b43_wldev *dev,
  1004. u16 phy_register, unsigned int lpd)
  1005. {
  1006. struct b43_phy *phy = &dev->phy;
  1007. struct b43_phy_g *gphy = phy->g;
  1008. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  1009. if (!phy->gmode)
  1010. return 0;
  1011. if (has_loopback_gain(phy)) {
  1012. int max_lb_gain = gphy->max_lb_gain;
  1013. u16 extlna;
  1014. u16 i;
  1015. if (phy->radio_rev == 8)
  1016. max_lb_gain += 0x3E;
  1017. else
  1018. max_lb_gain += 0x26;
  1019. if (max_lb_gain >= 0x46) {
  1020. extlna = 0x3000;
  1021. max_lb_gain -= 0x46;
  1022. } else if (max_lb_gain >= 0x3A) {
  1023. extlna = 0x1000;
  1024. max_lb_gain -= 0x3A;
  1025. } else if (max_lb_gain >= 0x2E) {
  1026. extlna = 0x2000;
  1027. max_lb_gain -= 0x2E;
  1028. } else {
  1029. extlna = 0;
  1030. max_lb_gain -= 0x10;
  1031. }
  1032. for (i = 0; i < 16; i++) {
  1033. max_lb_gain -= (i * 6);
  1034. if (max_lb_gain < 6)
  1035. break;
  1036. }
  1037. if ((phy->rev < 7) ||
  1038. !(sprom->boardflags_lo & B43_BFL_EXTLNA)) {
  1039. if (phy_register == B43_PHY_RFOVER) {
  1040. return 0x1B3;
  1041. } else if (phy_register == B43_PHY_RFOVERVAL) {
  1042. extlna |= (i << 8);
  1043. switch (lpd) {
  1044. case LPD(0, 1, 1):
  1045. return 0x0F92;
  1046. case LPD(0, 0, 1):
  1047. case LPD(1, 0, 1):
  1048. return (0x0092 | extlna);
  1049. case LPD(1, 0, 0):
  1050. return (0x0093 | extlna);
  1051. }
  1052. B43_WARN_ON(1);
  1053. }
  1054. B43_WARN_ON(1);
  1055. } else {
  1056. if (phy_register == B43_PHY_RFOVER) {
  1057. return 0x9B3;
  1058. } else if (phy_register == B43_PHY_RFOVERVAL) {
  1059. if (extlna)
  1060. extlna |= 0x8000;
  1061. extlna |= (i << 8);
  1062. switch (lpd) {
  1063. case LPD(0, 1, 1):
  1064. return 0x8F92;
  1065. case LPD(0, 0, 1):
  1066. return (0x8092 | extlna);
  1067. case LPD(1, 0, 1):
  1068. return (0x2092 | extlna);
  1069. case LPD(1, 0, 0):
  1070. return (0x2093 | extlna);
  1071. }
  1072. B43_WARN_ON(1);
  1073. }
  1074. B43_WARN_ON(1);
  1075. }
  1076. } else {
  1077. if ((phy->rev < 7) ||
  1078. !(sprom->boardflags_lo & B43_BFL_EXTLNA)) {
  1079. if (phy_register == B43_PHY_RFOVER) {
  1080. return 0x1B3;
  1081. } else if (phy_register == B43_PHY_RFOVERVAL) {
  1082. switch (lpd) {
  1083. case LPD(0, 1, 1):
  1084. return 0x0FB2;
  1085. case LPD(0, 0, 1):
  1086. return 0x00B2;
  1087. case LPD(1, 0, 1):
  1088. return 0x30B2;
  1089. case LPD(1, 0, 0):
  1090. return 0x30B3;
  1091. }
  1092. B43_WARN_ON(1);
  1093. }
  1094. B43_WARN_ON(1);
  1095. } else {
  1096. if (phy_register == B43_PHY_RFOVER) {
  1097. return 0x9B3;
  1098. } else if (phy_register == B43_PHY_RFOVERVAL) {
  1099. switch (lpd) {
  1100. case LPD(0, 1, 1):
  1101. return 0x8FB2;
  1102. case LPD(0, 0, 1):
  1103. return 0x80B2;
  1104. case LPD(1, 0, 1):
  1105. return 0x20B2;
  1106. case LPD(1, 0, 0):
  1107. return 0x20B3;
  1108. }
  1109. B43_WARN_ON(1);
  1110. }
  1111. B43_WARN_ON(1);
  1112. }
  1113. }
  1114. return 0;
  1115. }
  1116. struct init2050_saved_values {
  1117. /* Core registers */
  1118. u16 reg_3EC;
  1119. u16 reg_3E6;
  1120. u16 reg_3F4;
  1121. /* Radio registers */
  1122. u16 radio_43;
  1123. u16 radio_51;
  1124. u16 radio_52;
  1125. /* PHY registers */
  1126. u16 phy_pgactl;
  1127. u16 phy_cck_5A;
  1128. u16 phy_cck_59;
  1129. u16 phy_cck_58;
  1130. u16 phy_cck_30;
  1131. u16 phy_rfover;
  1132. u16 phy_rfoverval;
  1133. u16 phy_analogover;
  1134. u16 phy_analogoverval;
  1135. u16 phy_crs0;
  1136. u16 phy_classctl;
  1137. u16 phy_lo_mask;
  1138. u16 phy_lo_ctl;
  1139. u16 phy_syncctl;
  1140. };
  1141. static u16 b43_radio_init2050(struct b43_wldev *dev)
  1142. {
  1143. struct b43_phy *phy = &dev->phy;
  1144. struct init2050_saved_values sav;
  1145. u16 rcc;
  1146. u16 radio78;
  1147. u16 ret;
  1148. u16 i, j;
  1149. u32 tmp1 = 0, tmp2 = 0;
  1150. memset(&sav, 0, sizeof(sav)); /* get rid of "may be used uninitialized..." */
  1151. sav.radio_43 = b43_radio_read16(dev, 0x43);
  1152. sav.radio_51 = b43_radio_read16(dev, 0x51);
  1153. sav.radio_52 = b43_radio_read16(dev, 0x52);
  1154. sav.phy_pgactl = b43_phy_read(dev, B43_PHY_PGACTL);
  1155. sav.phy_cck_5A = b43_phy_read(dev, B43_PHY_CCK(0x5A));
  1156. sav.phy_cck_59 = b43_phy_read(dev, B43_PHY_CCK(0x59));
  1157. sav.phy_cck_58 = b43_phy_read(dev, B43_PHY_CCK(0x58));
  1158. if (phy->type == B43_PHYTYPE_B) {
  1159. sav.phy_cck_30 = b43_phy_read(dev, B43_PHY_CCK(0x30));
  1160. sav.reg_3EC = b43_read16(dev, 0x3EC);
  1161. b43_phy_write(dev, B43_PHY_CCK(0x30), 0xFF);
  1162. b43_write16(dev, 0x3EC, 0x3F3F);
  1163. } else if (phy->gmode || phy->rev >= 2) {
  1164. sav.phy_rfover = b43_phy_read(dev, B43_PHY_RFOVER);
  1165. sav.phy_rfoverval = b43_phy_read(dev, B43_PHY_RFOVERVAL);
  1166. sav.phy_analogover = b43_phy_read(dev, B43_PHY_ANALOGOVER);
  1167. sav.phy_analogoverval =
  1168. b43_phy_read(dev, B43_PHY_ANALOGOVERVAL);
  1169. sav.phy_crs0 = b43_phy_read(dev, B43_PHY_CRS0);
  1170. sav.phy_classctl = b43_phy_read(dev, B43_PHY_CLASSCTL);
  1171. b43_phy_set(dev, B43_PHY_ANALOGOVER, 0x0003);
  1172. b43_phy_mask(dev, B43_PHY_ANALOGOVERVAL, 0xFFFC);
  1173. b43_phy_mask(dev, B43_PHY_CRS0, 0x7FFF);
  1174. b43_phy_mask(dev, B43_PHY_CLASSCTL, 0xFFFC);
  1175. if (has_loopback_gain(phy)) {
  1176. sav.phy_lo_mask = b43_phy_read(dev, B43_PHY_LO_MASK);
  1177. sav.phy_lo_ctl = b43_phy_read(dev, B43_PHY_LO_CTL);
  1178. if (phy->rev >= 3)
  1179. b43_phy_write(dev, B43_PHY_LO_MASK, 0xC020);
  1180. else
  1181. b43_phy_write(dev, B43_PHY_LO_MASK, 0x8020);
  1182. b43_phy_write(dev, B43_PHY_LO_CTL, 0);
  1183. }
  1184. b43_phy_write(dev, B43_PHY_RFOVERVAL,
  1185. radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
  1186. LPD(0, 1, 1)));
  1187. b43_phy_write(dev, B43_PHY_RFOVER,
  1188. radio2050_rfover_val(dev, B43_PHY_RFOVER, 0));
  1189. }
  1190. b43_write16(dev, 0x3E2, b43_read16(dev, 0x3E2) | 0x8000);
  1191. sav.phy_syncctl = b43_phy_read(dev, B43_PHY_SYNCCTL);
  1192. b43_phy_mask(dev, B43_PHY_SYNCCTL, 0xFF7F);
  1193. sav.reg_3E6 = b43_read16(dev, 0x3E6);
  1194. sav.reg_3F4 = b43_read16(dev, 0x3F4);
  1195. if (phy->analog == 0) {
  1196. b43_write16(dev, 0x03E6, 0x0122);
  1197. } else {
  1198. if (phy->analog >= 2) {
  1199. b43_phy_maskset(dev, B43_PHY_CCK(0x03), 0xFFBF, 0x40);
  1200. }
  1201. b43_write16(dev, B43_MMIO_CHANNEL_EXT,
  1202. (b43_read16(dev, B43_MMIO_CHANNEL_EXT) | 0x2000));
  1203. }
  1204. rcc = b43_radio_core_calibration_value(dev);
  1205. if (phy->type == B43_PHYTYPE_B)
  1206. b43_radio_write16(dev, 0x78, 0x26);
  1207. if (phy->gmode || phy->rev >= 2) {
  1208. b43_phy_write(dev, B43_PHY_RFOVERVAL,
  1209. radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
  1210. LPD(0, 1, 1)));
  1211. }
  1212. b43_phy_write(dev, B43_PHY_PGACTL, 0xBFAF);
  1213. b43_phy_write(dev, B43_PHY_CCK(0x2B), 0x1403);
  1214. if (phy->gmode || phy->rev >= 2) {
  1215. b43_phy_write(dev, B43_PHY_RFOVERVAL,
  1216. radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
  1217. LPD(0, 0, 1)));
  1218. }
  1219. b43_phy_write(dev, B43_PHY_PGACTL, 0xBFA0);
  1220. b43_radio_set(dev, 0x51, 0x0004);
  1221. if (phy->radio_rev == 8) {
  1222. b43_radio_write16(dev, 0x43, 0x1F);
  1223. } else {
  1224. b43_radio_write16(dev, 0x52, 0);
  1225. b43_radio_maskset(dev, 0x43, 0xFFF0, 0x0009);
  1226. }
  1227. b43_phy_write(dev, B43_PHY_CCK(0x58), 0);
  1228. for (i = 0; i < 16; i++) {
  1229. b43_phy_write(dev, B43_PHY_CCK(0x5A), 0x0480);
  1230. b43_phy_write(dev, B43_PHY_CCK(0x59), 0xC810);
  1231. b43_phy_write(dev, B43_PHY_CCK(0x58), 0x000D);
  1232. if (phy->gmode || phy->rev >= 2) {
  1233. b43_phy_write(dev, B43_PHY_RFOVERVAL,
  1234. radio2050_rfover_val(dev,
  1235. B43_PHY_RFOVERVAL,
  1236. LPD(1, 0, 1)));
  1237. }
  1238. b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
  1239. udelay(10);
  1240. if (phy->gmode || phy->rev >= 2) {
  1241. b43_phy_write(dev, B43_PHY_RFOVERVAL,
  1242. radio2050_rfover_val(dev,
  1243. B43_PHY_RFOVERVAL,
  1244. LPD(1, 0, 1)));
  1245. }
  1246. b43_phy_write(dev, B43_PHY_PGACTL, 0xEFB0);
  1247. udelay(10);
  1248. if (phy->gmode || phy->rev >= 2) {
  1249. b43_phy_write(dev, B43_PHY_RFOVERVAL,
  1250. radio2050_rfover_val(dev,
  1251. B43_PHY_RFOVERVAL,
  1252. LPD(1, 0, 0)));
  1253. }
  1254. b43_phy_write(dev, B43_PHY_PGACTL, 0xFFF0);
  1255. udelay(20);
  1256. tmp1 += b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
  1257. b43_phy_write(dev, B43_PHY_CCK(0x58), 0);
  1258. if (phy->gmode || phy->rev >= 2) {
  1259. b43_phy_write(dev, B43_PHY_RFOVERVAL,
  1260. radio2050_rfover_val(dev,
  1261. B43_PHY_RFOVERVAL,
  1262. LPD(1, 0, 1)));
  1263. }
  1264. b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
  1265. }
  1266. udelay(10);
  1267. b43_phy_write(dev, B43_PHY_CCK(0x58), 0);
  1268. tmp1++;
  1269. tmp1 >>= 9;
  1270. for (i = 0; i < 16; i++) {
  1271. radio78 = (bitrev4(i) << 1) | 0x0020;
  1272. b43_radio_write16(dev, 0x78, radio78);
  1273. udelay(10);
  1274. for (j = 0; j < 16; j++) {
  1275. b43_phy_write(dev, B43_PHY_CCK(0x5A), 0x0D80);
  1276. b43_phy_write(dev, B43_PHY_CCK(0x59), 0xC810);
  1277. b43_phy_write(dev, B43_PHY_CCK(0x58), 0x000D);
  1278. if (phy->gmode || phy->rev >= 2) {
  1279. b43_phy_write(dev, B43_PHY_RFOVERVAL,
  1280. radio2050_rfover_val(dev,
  1281. B43_PHY_RFOVERVAL,
  1282. LPD(1, 0,
  1283. 1)));
  1284. }
  1285. b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
  1286. udelay(10);
  1287. if (phy->gmode || phy->rev >= 2) {
  1288. b43_phy_write(dev, B43_PHY_RFOVERVAL,
  1289. radio2050_rfover_val(dev,
  1290. B43_PHY_RFOVERVAL,
  1291. LPD(1, 0,
  1292. 1)));
  1293. }
  1294. b43_phy_write(dev, B43_PHY_PGACTL, 0xEFB0);
  1295. udelay(10);
  1296. if (phy->gmode || phy->rev >= 2) {
  1297. b43_phy_write(dev, B43_PHY_RFOVERVAL,
  1298. radio2050_rfover_val(dev,
  1299. B43_PHY_RFOVERVAL,
  1300. LPD(1, 0,
  1301. 0)));
  1302. }
  1303. b43_phy_write(dev, B43_PHY_PGACTL, 0xFFF0);
  1304. udelay(10);
  1305. tmp2 += b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
  1306. b43_phy_write(dev, B43_PHY_CCK(0x58), 0);
  1307. if (phy->gmode || phy->rev >= 2) {
  1308. b43_phy_write(dev, B43_PHY_RFOVERVAL,
  1309. radio2050_rfover_val(dev,
  1310. B43_PHY_RFOVERVAL,
  1311. LPD(1, 0,
  1312. 1)));
  1313. }
  1314. b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
  1315. }
  1316. tmp2++;
  1317. tmp2 >>= 8;
  1318. if (tmp1 < tmp2)
  1319. break;
  1320. }
  1321. /* Restore the registers */
  1322. b43_phy_write(dev, B43_PHY_PGACTL, sav.phy_pgactl);
  1323. b43_radio_write16(dev, 0x51, sav.radio_51);
  1324. b43_radio_write16(dev, 0x52, sav.radio_52);
  1325. b43_radio_write16(dev, 0x43, sav.radio_43);
  1326. b43_phy_write(dev, B43_PHY_CCK(0x5A), sav.phy_cck_5A);
  1327. b43_phy_write(dev, B43_PHY_CCK(0x59), sav.phy_cck_59);
  1328. b43_phy_write(dev, B43_PHY_CCK(0x58), sav.phy_cck_58);
  1329. b43_write16(dev, 0x3E6, sav.reg_3E6);
  1330. if (phy->analog != 0)
  1331. b43_write16(dev, 0x3F4, sav.reg_3F4);
  1332. b43_phy_write(dev, B43_PHY_SYNCCTL, sav.phy_syncctl);
  1333. b43_synth_pu_workaround(dev, phy->channel);
  1334. if (phy->type == B43_PHYTYPE_B) {
  1335. b43_phy_write(dev, B43_PHY_CCK(0x30), sav.phy_cck_30);
  1336. b43_write16(dev, 0x3EC, sav.reg_3EC);
  1337. } else if (phy->gmode) {
  1338. b43_write16(dev, B43_MMIO_PHY_RADIO,
  1339. b43_read16(dev, B43_MMIO_PHY_RADIO)
  1340. & 0x7FFF);
  1341. b43_phy_write(dev, B43_PHY_RFOVER, sav.phy_rfover);
  1342. b43_phy_write(dev, B43_PHY_RFOVERVAL, sav.phy_rfoverval);
  1343. b43_phy_write(dev, B43_PHY_ANALOGOVER, sav.phy_analogover);
  1344. b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
  1345. sav.phy_analogoverval);
  1346. b43_phy_write(dev, B43_PHY_CRS0, sav.phy_crs0);
  1347. b43_phy_write(dev, B43_PHY_CLASSCTL, sav.phy_classctl);
  1348. if (has_loopback_gain(phy)) {
  1349. b43_phy_write(dev, B43_PHY_LO_MASK, sav.phy_lo_mask);
  1350. b43_phy_write(dev, B43_PHY_LO_CTL, sav.phy_lo_ctl);
  1351. }
  1352. }
  1353. if (i > 15)
  1354. ret = radio78;
  1355. else
  1356. ret = rcc;
  1357. return ret;
  1358. }
  1359. static void b43_phy_initb5(struct b43_wldev *dev)
  1360. {
  1361. struct b43_phy *phy = &dev->phy;
  1362. struct b43_phy_g *gphy = phy->g;
  1363. u16 offset, value;
  1364. u8 old_channel;
  1365. if (phy->analog == 1) {
  1366. b43_radio_set(dev, 0x007A, 0x0050);
  1367. }
  1368. if ((dev->dev->board_vendor != SSB_BOARDVENDOR_BCM) &&
  1369. (dev->dev->board_type != SSB_BOARD_BU4306)) {
  1370. value = 0x2120;
  1371. for (offset = 0x00A8; offset < 0x00C7; offset++) {
  1372. b43_phy_write(dev, offset, value);
  1373. value += 0x202;
  1374. }
  1375. }
  1376. b43_phy_maskset(dev, 0x0035, 0xF0FF, 0x0700);
  1377. if (phy->radio_ver == 0x2050)
  1378. b43_phy_write(dev, 0x0038, 0x0667);
  1379. if (phy->gmode || phy->rev >= 2) {
  1380. if (phy->radio_ver == 0x2050) {
  1381. b43_radio_set(dev, 0x007A, 0x0020);
  1382. b43_radio_set(dev, 0x0051, 0x0004);
  1383. }
  1384. b43_write16(dev, B43_MMIO_PHY_RADIO, 0x0000);
  1385. b43_phy_set(dev, 0x0802, 0x0100);
  1386. b43_phy_set(dev, 0x042B, 0x2000);
  1387. b43_phy_write(dev, 0x001C, 0x186A);
  1388. b43_phy_maskset(dev, 0x0013, 0x00FF, 0x1900);
  1389. b43_phy_maskset(dev, 0x0035, 0xFFC0, 0x0064);
  1390. b43_phy_maskset(dev, 0x005D, 0xFF80, 0x000A);
  1391. }
  1392. if (dev->bad_frames_preempt) {
  1393. b43_phy_set(dev, B43_PHY_RADIO_BITFIELD, (1 << 11));
  1394. }
  1395. if (phy->analog == 1) {
  1396. b43_phy_write(dev, 0x0026, 0xCE00);
  1397. b43_phy_write(dev, 0x0021, 0x3763);
  1398. b43_phy_write(dev, 0x0022, 0x1BC3);
  1399. b43_phy_write(dev, 0x0023, 0x06F9);
  1400. b43_phy_write(dev, 0x0024, 0x037E);
  1401. } else
  1402. b43_phy_write(dev, 0x0026, 0xCC00);
  1403. b43_phy_write(dev, 0x0030, 0x00C6);
  1404. b43_write16(dev, 0x03EC, 0x3F22);
  1405. if (phy->analog == 1)
  1406. b43_phy_write(dev, 0x0020, 0x3E1C);
  1407. else
  1408. b43_phy_write(dev, 0x0020, 0x301C);
  1409. if (phy->analog == 0)
  1410. b43_write16(dev, 0x03E4, 0x3000);
  1411. old_channel = phy->channel;
  1412. /* Force to channel 7, even if not supported. */
  1413. b43_gphy_channel_switch(dev, 7, 0);
  1414. if (phy->radio_ver != 0x2050) {
  1415. b43_radio_write16(dev, 0x0075, 0x0080);
  1416. b43_radio_write16(dev, 0x0079, 0x0081);
  1417. }
  1418. b43_radio_write16(dev, 0x0050, 0x0020);
  1419. b43_radio_write16(dev, 0x0050, 0x0023);
  1420. if (phy->radio_ver == 0x2050) {
  1421. b43_radio_write16(dev, 0x0050, 0x0020);
  1422. b43_radio_write16(dev, 0x005A, 0x0070);
  1423. }
  1424. b43_radio_write16(dev, 0x005B, 0x007B);
  1425. b43_radio_write16(dev, 0x005C, 0x00B0);
  1426. b43_radio_set(dev, 0x007A, 0x0007);
  1427. b43_gphy_channel_switch(dev, old_channel, 0);
  1428. b43_phy_write(dev, 0x0014, 0x0080);
  1429. b43_phy_write(dev, 0x0032, 0x00CA);
  1430. b43_phy_write(dev, 0x002A, 0x88A3);
  1431. b43_set_txpower_g(dev, &gphy->bbatt, &gphy->rfatt, gphy->tx_control);
  1432. if (phy->radio_ver == 0x2050)
  1433. b43_radio_write16(dev, 0x005D, 0x000D);
  1434. b43_write16(dev, 0x03E4, (b43_read16(dev, 0x03E4) & 0xFFC0) | 0x0004);
  1435. }
  1436. /* http://bcm-v4.sipsolutions.net/802.11/PHY/Init/B6 */
  1437. static void b43_phy_initb6(struct b43_wldev *dev)
  1438. {
  1439. struct b43_phy *phy = &dev->phy;
  1440. struct b43_phy_g *gphy = phy->g;
  1441. u16 offset, val;
  1442. u8 old_channel;
  1443. b43_phy_write(dev, 0x003E, 0x817A);
  1444. b43_radio_write16(dev, 0x007A,
  1445. (b43_radio_read16(dev, 0x007A) | 0x0058));
  1446. if (phy->radio_rev == 4 || phy->radio_rev == 5) {
  1447. b43_radio_write16(dev, 0x51, 0x37);
  1448. b43_radio_write16(dev, 0x52, 0x70);
  1449. b43_radio_write16(dev, 0x53, 0xB3);
  1450. b43_radio_write16(dev, 0x54, 0x9B);
  1451. b43_radio_write16(dev, 0x5A, 0x88);
  1452. b43_radio_write16(dev, 0x5B, 0x88);
  1453. b43_radio_write16(dev, 0x5D, 0x88);
  1454. b43_radio_write16(dev, 0x5E, 0x88);
  1455. b43_radio_write16(dev, 0x7D, 0x88);
  1456. b43_hf_write(dev, b43_hf_read(dev)
  1457. | B43_HF_TSSIRPSMW);
  1458. }
  1459. B43_WARN_ON(phy->radio_rev == 6 || phy->radio_rev == 7); /* We had code for these revs here... */
  1460. if (phy->radio_rev == 8) {
  1461. b43_radio_write16(dev, 0x51, 0);
  1462. b43_radio_write16(dev, 0x52, 0x40);
  1463. b43_radio_write16(dev, 0x53, 0xB7);
  1464. b43_radio_write16(dev, 0x54, 0x98);
  1465. b43_radio_write16(dev, 0x5A, 0x88);
  1466. b43_radio_write16(dev, 0x5B, 0x6B);
  1467. b43_radio_write16(dev, 0x5C, 0x0F);
  1468. if (dev->dev->bus_sprom->boardflags_lo & B43_BFL_ALTIQ) {
  1469. b43_radio_write16(dev, 0x5D, 0xFA);
  1470. b43_radio_write16(dev, 0x5E, 0xD8);
  1471. } else {
  1472. b43_radio_write16(dev, 0x5D, 0xF5);
  1473. b43_radio_write16(dev, 0x5E, 0xB8);
  1474. }
  1475. b43_radio_write16(dev, 0x0073, 0x0003);
  1476. b43_radio_write16(dev, 0x007D, 0x00A8);
  1477. b43_radio_write16(dev, 0x007C, 0x0001);
  1478. b43_radio_write16(dev, 0x007E, 0x0008);
  1479. }
  1480. val = 0x1E1F;
  1481. for (offset = 0x0088; offset < 0x0098; offset++) {
  1482. b43_phy_write(dev, offset, val);
  1483. val -= 0x0202;
  1484. }
  1485. val = 0x3E3F;
  1486. for (offset = 0x0098; offset < 0x00A8; offset++) {
  1487. b43_phy_write(dev, offset, val);
  1488. val -= 0x0202;
  1489. }
  1490. val = 0x2120;
  1491. for (offset = 0x00A8; offset < 0x00C8; offset++) {
  1492. b43_phy_write(dev, offset, (val & 0x3F3F));
  1493. val += 0x0202;
  1494. }
  1495. if (phy->type == B43_PHYTYPE_G) {
  1496. b43_radio_set(dev, 0x007A, 0x0020);
  1497. b43_radio_set(dev, 0x0051, 0x0004);
  1498. b43_phy_set(dev, 0x0802, 0x0100);
  1499. b43_phy_set(dev, 0x042B, 0x2000);
  1500. b43_phy_write(dev, 0x5B, 0);
  1501. b43_phy_write(dev, 0x5C, 0);
  1502. }
  1503. old_channel = phy->channel;
  1504. if (old_channel >= 8)
  1505. b43_gphy_channel_switch(dev, 1, 0);
  1506. else
  1507. b43_gphy_channel_switch(dev, 13, 0);
  1508. b43_radio_write16(dev, 0x0050, 0x0020);
  1509. b43_radio_write16(dev, 0x0050, 0x0023);
  1510. udelay(40);
  1511. if (phy->radio_rev < 6 || phy->radio_rev == 8) {
  1512. b43_radio_write16(dev, 0x7C, (b43_radio_read16(dev, 0x7C)
  1513. | 0x0002));
  1514. b43_radio_write16(dev, 0x50, 0x20);
  1515. }
  1516. if (phy->radio_rev <= 2) {
  1517. b43_radio_write16(dev, 0x50, 0x20);
  1518. b43_radio_write16(dev, 0x5A, 0x70);
  1519. b43_radio_write16(dev, 0x5B, 0x7B);
  1520. b43_radio_write16(dev, 0x5C, 0xB0);
  1521. }
  1522. b43_radio_maskset(dev, 0x007A, 0x00F8, 0x0007);
  1523. b43_gphy_channel_switch(dev, old_channel, 0);
  1524. b43_phy_write(dev, 0x0014, 0x0200);
  1525. if (phy->radio_rev >= 6)
  1526. b43_phy_write(dev, 0x2A, 0x88C2);
  1527. else
  1528. b43_phy_write(dev, 0x2A, 0x8AC0);
  1529. b43_phy_write(dev, 0x0038, 0x0668);
  1530. b43_set_txpower_g(dev, &gphy->bbatt, &gphy->rfatt, gphy->tx_control);
  1531. if (phy->radio_rev == 4 || phy->radio_rev == 5)
  1532. b43_phy_maskset(dev, 0x5D, 0xFF80, 0x0003);
  1533. if (phy->radio_rev <= 2)
  1534. b43_radio_write16(dev, 0x005D, 0x000D);
  1535. if (phy->analog == 4) {
  1536. b43_write16(dev, 0x3E4, 9);
  1537. b43_phy_mask(dev, 0x61, 0x0FFF);
  1538. } else {
  1539. b43_phy_maskset(dev, 0x0002, 0xFFC0, 0x0004);
  1540. }
  1541. if (phy->type == B43_PHYTYPE_B)
  1542. B43_WARN_ON(1);
  1543. else if (phy->type == B43_PHYTYPE_G)
  1544. b43_write16(dev, 0x03E6, 0x0);
  1545. }
  1546. static void b43_calc_loopback_gain(struct b43_wldev *dev)
  1547. {
  1548. struct b43_phy *phy = &dev->phy;
  1549. struct b43_phy_g *gphy = phy->g;
  1550. u16 backup_phy[16] = { 0 };
  1551. u16 backup_radio[3];
  1552. u16 backup_bband;
  1553. u16 i, j, loop_i_max;
  1554. u16 trsw_rx;
  1555. u16 loop1_outer_done, loop1_inner_done;
  1556. backup_phy[0] = b43_phy_read(dev, B43_PHY_CRS0);
  1557. backup_phy[1] = b43_phy_read(dev, B43_PHY_CCKBBANDCFG);
  1558. backup_phy[2] = b43_phy_read(dev, B43_PHY_RFOVER);
  1559. backup_phy[3] = b43_phy_read(dev, B43_PHY_RFOVERVAL);
  1560. if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
  1561. backup_phy[4] = b43_phy_read(dev, B43_PHY_ANALOGOVER);
  1562. backup_phy[5] = b43_phy_read(dev, B43_PHY_ANALOGOVERVAL);
  1563. }
  1564. backup_phy[6] = b43_phy_read(dev, B43_PHY_CCK(0x5A));
  1565. backup_phy[7] = b43_phy_read(dev, B43_PHY_CCK(0x59));
  1566. backup_phy[8] = b43_phy_read(dev, B43_PHY_CCK(0x58));
  1567. backup_phy[9] = b43_phy_read(dev, B43_PHY_CCK(0x0A));
  1568. backup_phy[10] = b43_phy_read(dev, B43_PHY_CCK(0x03));
  1569. backup_phy[11] = b43_phy_read(dev, B43_PHY_LO_MASK);
  1570. backup_phy[12] = b43_phy_read(dev, B43_PHY_LO_CTL);
  1571. backup_phy[13] = b43_phy_read(dev, B43_PHY_CCK(0x2B));
  1572. backup_phy[14] = b43_phy_read(dev, B43_PHY_PGACTL);
  1573. backup_phy[15] = b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
  1574. backup_bband = gphy->bbatt.att;
  1575. backup_radio[0] = b43_radio_read16(dev, 0x52);
  1576. backup_radio[1] = b43_radio_read16(dev, 0x43);
  1577. backup_radio[2] = b43_radio_read16(dev, 0x7A);
  1578. b43_phy_mask(dev, B43_PHY_CRS0, 0x3FFF);
  1579. b43_phy_set(dev, B43_PHY_CCKBBANDCFG, 0x8000);
  1580. b43_phy_set(dev, B43_PHY_RFOVER, 0x0002);
  1581. b43_phy_mask(dev, B43_PHY_RFOVERVAL, 0xFFFD);
  1582. b43_phy_set(dev, B43_PHY_RFOVER, 0x0001);
  1583. b43_phy_mask(dev, B43_PHY_RFOVERVAL, 0xFFFE);
  1584. if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
  1585. b43_phy_set(dev, B43_PHY_ANALOGOVER, 0x0001);
  1586. b43_phy_mask(dev, B43_PHY_ANALOGOVERVAL, 0xFFFE);
  1587. b43_phy_set(dev, B43_PHY_ANALOGOVER, 0x0002);
  1588. b43_phy_mask(dev, B43_PHY_ANALOGOVERVAL, 0xFFFD);
  1589. }
  1590. b43_phy_set(dev, B43_PHY_RFOVER, 0x000C);
  1591. b43_phy_set(dev, B43_PHY_RFOVERVAL, 0x000C);
  1592. b43_phy_set(dev, B43_PHY_RFOVER, 0x0030);
  1593. b43_phy_maskset(dev, B43_PHY_RFOVERVAL, 0xFFCF, 0x10);
  1594. b43_phy_write(dev, B43_PHY_CCK(0x5A), 0x0780);
  1595. b43_phy_write(dev, B43_PHY_CCK(0x59), 0xC810);
  1596. b43_phy_write(dev, B43_PHY_CCK(0x58), 0x000D);
  1597. b43_phy_set(dev, B43_PHY_CCK(0x0A), 0x2000);
  1598. if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
  1599. b43_phy_set(dev, B43_PHY_ANALOGOVER, 0x0004);
  1600. b43_phy_mask(dev, B43_PHY_ANALOGOVERVAL, 0xFFFB);
  1601. }
  1602. b43_phy_maskset(dev, B43_PHY_CCK(0x03), 0xFF9F, 0x40);
  1603. if (phy->radio_rev == 8) {
  1604. b43_radio_write16(dev, 0x43, 0x000F);
  1605. } else {
  1606. b43_radio_write16(dev, 0x52, 0);
  1607. b43_radio_maskset(dev, 0x43, 0xFFF0, 0x9);
  1608. }
  1609. b43_gphy_set_baseband_attenuation(dev, 11);
  1610. if (phy->rev >= 3)
  1611. b43_phy_write(dev, B43_PHY_LO_MASK, 0xC020);
  1612. else
  1613. b43_phy_write(dev, B43_PHY_LO_MASK, 0x8020);
  1614. b43_phy_write(dev, B43_PHY_LO_CTL, 0);
  1615. b43_phy_maskset(dev, B43_PHY_CCK(0x2B), 0xFFC0, 0x01);
  1616. b43_phy_maskset(dev, B43_PHY_CCK(0x2B), 0xC0FF, 0x800);
  1617. b43_phy_set(dev, B43_PHY_RFOVER, 0x0100);
  1618. b43_phy_mask(dev, B43_PHY_RFOVERVAL, 0xCFFF);
  1619. if (dev->dev->bus_sprom->boardflags_lo & B43_BFL_EXTLNA) {
  1620. if (phy->rev >= 7) {
  1621. b43_phy_set(dev, B43_PHY_RFOVER, 0x0800);
  1622. b43_phy_set(dev, B43_PHY_RFOVERVAL, 0x8000);
  1623. }
  1624. }
  1625. b43_radio_mask(dev, 0x7A, 0x00F7);
  1626. j = 0;
  1627. loop_i_max = (phy->radio_rev == 8) ? 15 : 9;
  1628. for (i = 0; i < loop_i_max; i++) {
  1629. for (j = 0; j < 16; j++) {
  1630. b43_radio_write16(dev, 0x43, i);
  1631. b43_phy_maskset(dev, B43_PHY_RFOVERVAL, 0xF0FF, (j << 8));
  1632. b43_phy_maskset(dev, B43_PHY_PGACTL, 0x0FFF, 0xA000);
  1633. b43_phy_set(dev, B43_PHY_PGACTL, 0xF000);
  1634. udelay(20);
  1635. if (b43_phy_read(dev, B43_PHY_LO_LEAKAGE) >= 0xDFC)
  1636. goto exit_loop1;
  1637. }
  1638. }
  1639. exit_loop1:
  1640. loop1_outer_done = i;
  1641. loop1_inner_done = j;
  1642. if (j >= 8) {
  1643. b43_phy_set(dev, B43_PHY_RFOVERVAL, 0x30);
  1644. trsw_rx = 0x1B;
  1645. for (j = j - 8; j < 16; j++) {
  1646. b43_phy_maskset(dev, B43_PHY_RFOVERVAL, 0xF0FF, (j << 8));
  1647. b43_phy_maskset(dev, B43_PHY_PGACTL, 0x0FFF, 0xA000);
  1648. b43_phy_set(dev, B43_PHY_PGACTL, 0xF000);
  1649. udelay(20);
  1650. trsw_rx -= 3;
  1651. if (b43_phy_read(dev, B43_PHY_LO_LEAKAGE) >= 0xDFC)
  1652. goto exit_loop2;
  1653. }
  1654. } else
  1655. trsw_rx = 0x18;
  1656. exit_loop2:
  1657. if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
  1658. b43_phy_write(dev, B43_PHY_ANALOGOVER, backup_phy[4]);
  1659. b43_phy_write(dev, B43_PHY_ANALOGOVERVAL, backup_phy[5]);
  1660. }
  1661. b43_phy_write(dev, B43_PHY_CCK(0x5A), backup_phy[6]);
  1662. b43_phy_write(dev, B43_PHY_CCK(0x59), backup_phy[7]);
  1663. b43_phy_write(dev, B43_PHY_CCK(0x58), backup_phy[8]);
  1664. b43_phy_write(dev, B43_PHY_CCK(0x0A), backup_phy[9]);
  1665. b43_phy_write(dev, B43_PHY_CCK(0x03), backup_phy[10]);
  1666. b43_phy_write(dev, B43_PHY_LO_MASK, backup_phy[11]);
  1667. b43_phy_write(dev, B43_PHY_LO_CTL, backup_phy[12]);
  1668. b43_phy_write(dev, B43_PHY_CCK(0x2B), backup_phy[13]);
  1669. b43_phy_write(dev, B43_PHY_PGACTL, backup_phy[14]);
  1670. b43_gphy_set_baseband_attenuation(dev, backup_bband);
  1671. b43_radio_write16(dev, 0x52, backup_radio[0]);
  1672. b43_radio_write16(dev, 0x43, backup_radio[1]);
  1673. b43_radio_write16(dev, 0x7A, backup_radio[2]);
  1674. b43_phy_write(dev, B43_PHY_RFOVER, backup_phy[2] | 0x0003);
  1675. udelay(10);
  1676. b43_phy_write(dev, B43_PHY_RFOVER, backup_phy[2]);
  1677. b43_phy_write(dev, B43_PHY_RFOVERVAL, backup_phy[3]);
  1678. b43_phy_write(dev, B43_PHY_CRS0, backup_phy[0]);
  1679. b43_phy_write(dev, B43_PHY_CCKBBANDCFG, backup_phy[1]);
  1680. gphy->max_lb_gain =
  1681. ((loop1_inner_done * 6) - (loop1_outer_done * 4)) - 11;
  1682. gphy->trsw_rx_gain = trsw_rx * 2;
  1683. }
  1684. static void b43_hardware_pctl_early_init(struct b43_wldev *dev)
  1685. {
  1686. struct b43_phy *phy = &dev->phy;
  1687. if (!b43_has_hardware_pctl(dev)) {
  1688. b43_phy_write(dev, 0x047A, 0xC111);
  1689. return;
  1690. }
  1691. b43_phy_mask(dev, 0x0036, 0xFEFF);
  1692. b43_phy_write(dev, 0x002F, 0x0202);
  1693. b43_phy_set(dev, 0x047C, 0x0002);
  1694. b43_phy_set(dev, 0x047A, 0xF000);
  1695. if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
  1696. b43_phy_maskset(dev, 0x047A, 0xFF0F, 0x0010);
  1697. b43_phy_set(dev, 0x005D, 0x8000);
  1698. b43_phy_maskset(dev, 0x004E, 0xFFC0, 0x0010);
  1699. b43_phy_write(dev, 0x002E, 0xC07F);
  1700. b43_phy_set(dev, 0x0036, 0x0400);
  1701. } else {
  1702. b43_phy_set(dev, 0x0036, 0x0200);
  1703. b43_phy_set(dev, 0x0036, 0x0400);
  1704. b43_phy_mask(dev, 0x005D, 0x7FFF);
  1705. b43_phy_mask(dev, 0x004F, 0xFFFE);
  1706. b43_phy_maskset(dev, 0x004E, 0xFFC0, 0x0010);
  1707. b43_phy_write(dev, 0x002E, 0xC07F);
  1708. b43_phy_maskset(dev, 0x047A, 0xFF0F, 0x0010);
  1709. }
  1710. }
  1711. /* Hardware power control for G-PHY */
  1712. static void b43_hardware_pctl_init_gphy(struct b43_wldev *dev)
  1713. {
  1714. struct b43_phy *phy = &dev->phy;
  1715. struct b43_phy_g *gphy = phy->g;
  1716. if (!b43_has_hardware_pctl(dev)) {
  1717. /* No hardware power control */
  1718. b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_HWPCTL);
  1719. return;
  1720. }
  1721. b43_phy_maskset(dev, 0x0036, 0xFFC0, (gphy->tgt_idle_tssi - gphy->cur_idle_tssi));
  1722. b43_phy_maskset(dev, 0x0478, 0xFF00, (gphy->tgt_idle_tssi - gphy->cur_idle_tssi));
  1723. b43_gphy_tssi_power_lt_init(dev);
  1724. b43_gphy_gain_lt_init(dev);
  1725. b43_phy_mask(dev, 0x0060, 0xFFBF);
  1726. b43_phy_write(dev, 0x0014, 0x0000);
  1727. B43_WARN_ON(phy->rev < 6);
  1728. b43_phy_set(dev, 0x0478, 0x0800);
  1729. b43_phy_mask(dev, 0x0478, 0xFEFF);
  1730. b43_phy_mask(dev, 0x0801, 0xFFBF);
  1731. b43_gphy_dc_lt_init(dev, 1);
  1732. /* Enable hardware pctl in firmware. */
  1733. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_HWPCTL);
  1734. }
  1735. /* Initialize B/G PHY power control */
  1736. static void b43_phy_init_pctl(struct b43_wldev *dev)
  1737. {
  1738. struct b43_phy *phy = &dev->phy;
  1739. struct b43_phy_g *gphy = phy->g;
  1740. struct b43_rfatt old_rfatt;
  1741. struct b43_bbatt old_bbatt;
  1742. u8 old_tx_control = 0;
  1743. B43_WARN_ON(phy->type != B43_PHYTYPE_G);
  1744. if ((dev->dev->board_vendor == SSB_BOARDVENDOR_BCM) &&
  1745. (dev->dev->board_type == SSB_BOARD_BU4306))
  1746. return;
  1747. b43_phy_write(dev, 0x0028, 0x8018);
  1748. /* This does something with the Analog... */
  1749. b43_write16(dev, B43_MMIO_PHY0, b43_read16(dev, B43_MMIO_PHY0)
  1750. & 0xFFDF);
  1751. if (!phy->gmode)
  1752. return;
  1753. b43_hardware_pctl_early_init(dev);
  1754. if (gphy->cur_idle_tssi == 0) {
  1755. if (phy->radio_ver == 0x2050 && phy->analog == 0) {
  1756. b43_radio_maskset(dev, 0x0076, 0x00F7, 0x0084);
  1757. } else {
  1758. struct b43_rfatt rfatt;
  1759. struct b43_bbatt bbatt;
  1760. memcpy(&old_rfatt, &gphy->rfatt, sizeof(old_rfatt));
  1761. memcpy(&old_bbatt, &gphy->bbatt, sizeof(old_bbatt));
  1762. old_tx_control = gphy->tx_control;
  1763. bbatt.att = 11;
  1764. if (phy->radio_rev == 8) {
  1765. rfatt.att = 15;
  1766. rfatt.with_padmix = true;
  1767. } else {
  1768. rfatt.att = 9;
  1769. rfatt.with_padmix = false;
  1770. }
  1771. b43_set_txpower_g(dev, &bbatt, &rfatt, 0);
  1772. }
  1773. b43_dummy_transmission(dev, false, true);
  1774. gphy->cur_idle_tssi = b43_phy_read(dev, B43_PHY_ITSSI);
  1775. if (B43_DEBUG) {
  1776. /* Current-Idle-TSSI sanity check. */
  1777. if (abs(gphy->cur_idle_tssi - gphy->tgt_idle_tssi) >= 20) {
  1778. b43dbg(dev->wl,
  1779. "!WARNING! Idle-TSSI phy->cur_idle_tssi "
  1780. "measuring failed. (cur=%d, tgt=%d). Disabling TX power "
  1781. "adjustment.\n", gphy->cur_idle_tssi,
  1782. gphy->tgt_idle_tssi);
  1783. gphy->cur_idle_tssi = 0;
  1784. }
  1785. }
  1786. if (phy->radio_ver == 0x2050 && phy->analog == 0) {
  1787. b43_radio_mask(dev, 0x0076, 0xFF7B);
  1788. } else {
  1789. b43_set_txpower_g(dev, &old_bbatt,
  1790. &old_rfatt, old_tx_control);
  1791. }
  1792. }
  1793. b43_hardware_pctl_init_gphy(dev);
  1794. b43_shm_clear_tssi(dev);
  1795. }
  1796. static void b43_phy_inita(struct b43_wldev *dev)
  1797. {
  1798. struct b43_phy *phy = &dev->phy;
  1799. might_sleep();
  1800. if (phy->rev >= 6) {
  1801. if (b43_phy_read(dev, B43_PHY_ENCORE) & B43_PHY_ENCORE_EN)
  1802. b43_phy_set(dev, B43_PHY_ENCORE, 0x0010);
  1803. else
  1804. b43_phy_mask(dev, B43_PHY_ENCORE, ~0x1010);
  1805. }
  1806. b43_wa_all(dev);
  1807. if (dev->dev->bus_sprom->boardflags_lo & B43_BFL_PACTRL)
  1808. b43_phy_maskset(dev, B43_PHY_OFDM(0x6E), 0xE000, 0x3CF);
  1809. }
  1810. static void b43_phy_initg(struct b43_wldev *dev)
  1811. {
  1812. struct b43_phy *phy = &dev->phy;
  1813. struct b43_phy_g *gphy = phy->g;
  1814. u16 tmp;
  1815. if (phy->rev == 1)
  1816. b43_phy_initb5(dev);
  1817. else
  1818. b43_phy_initb6(dev);
  1819. if (phy->rev >= 2 || phy->gmode)
  1820. b43_phy_inita(dev);
  1821. if (phy->rev >= 2) {
  1822. b43_phy_write(dev, B43_PHY_ANALOGOVER, 0);
  1823. b43_phy_write(dev, B43_PHY_ANALOGOVERVAL, 0);
  1824. }
  1825. if (phy->rev == 2) {
  1826. b43_phy_write(dev, B43_PHY_RFOVER, 0);
  1827. b43_phy_write(dev, B43_PHY_PGACTL, 0xC0);
  1828. }
  1829. if (phy->rev > 5) {
  1830. b43_phy_write(dev, B43_PHY_RFOVER, 0x400);
  1831. b43_phy_write(dev, B43_PHY_PGACTL, 0xC0);
  1832. }
  1833. if (phy->gmode || phy->rev >= 2) {
  1834. tmp = b43_phy_read(dev, B43_PHY_VERSION_OFDM);
  1835. tmp &= B43_PHYVER_VERSION;
  1836. if (tmp == 3 || tmp == 5) {
  1837. b43_phy_write(dev, B43_PHY_OFDM(0xC2), 0x1816);
  1838. b43_phy_write(dev, B43_PHY_OFDM(0xC3), 0x8006);
  1839. }
  1840. if (tmp == 5) {
  1841. b43_phy_maskset(dev, B43_PHY_OFDM(0xCC), 0x00FF, 0x1F00);
  1842. }
  1843. }
  1844. if ((phy->rev <= 2 && phy->gmode) || phy->rev >= 2)
  1845. b43_phy_write(dev, B43_PHY_OFDM(0x7E), 0x78);
  1846. if (phy->radio_rev == 8) {
  1847. b43_phy_set(dev, B43_PHY_EXTG(0x01), 0x80);
  1848. b43_phy_set(dev, B43_PHY_OFDM(0x3E), 0x4);
  1849. }
  1850. if (has_loopback_gain(phy))
  1851. b43_calc_loopback_gain(dev);
  1852. if (phy->radio_rev != 8) {
  1853. if (gphy->initval == 0xFFFF)
  1854. gphy->initval = b43_radio_init2050(dev);
  1855. else
  1856. b43_radio_write16(dev, 0x0078, gphy->initval);
  1857. }
  1858. b43_lo_g_init(dev);
  1859. if (has_tx_magnification(phy)) {
  1860. b43_radio_write16(dev, 0x52,
  1861. (b43_radio_read16(dev, 0x52) & 0xFF00)
  1862. | gphy->lo_control->tx_bias | gphy->
  1863. lo_control->tx_magn);
  1864. } else {
  1865. b43_radio_maskset(dev, 0x52, 0xFFF0, gphy->lo_control->tx_bias);
  1866. }
  1867. if (phy->rev >= 6) {
  1868. b43_phy_maskset(dev, B43_PHY_CCK(0x36), 0x0FFF, (gphy->lo_control->tx_bias << 12));
  1869. }
  1870. if (dev->dev->bus_sprom->boardflags_lo & B43_BFL_PACTRL)
  1871. b43_phy_write(dev, B43_PHY_CCK(0x2E), 0x8075);
  1872. else
  1873. b43_phy_write(dev, B43_PHY_CCK(0x2E), 0x807F);
  1874. if (phy->rev < 2)
  1875. b43_phy_write(dev, B43_PHY_CCK(0x2F), 0x101);
  1876. else
  1877. b43_phy_write(dev, B43_PHY_CCK(0x2F), 0x202);
  1878. if (phy->gmode || phy->rev >= 2) {
  1879. b43_lo_g_adjust(dev);
  1880. b43_phy_write(dev, B43_PHY_LO_MASK, 0x8078);
  1881. }
  1882. if (!(dev->dev->bus_sprom->boardflags_lo & B43_BFL_RSSI)) {
  1883. /* The specs state to update the NRSSI LT with
  1884. * the value 0x7FFFFFFF here. I think that is some weird
  1885. * compiler optimization in the original driver.
  1886. * Essentially, what we do here is resetting all NRSSI LT
  1887. * entries to -32 (see the clamp_val() in nrssi_hw_update())
  1888. */
  1889. b43_nrssi_hw_update(dev, 0xFFFF); //FIXME?
  1890. b43_calc_nrssi_threshold(dev);
  1891. } else if (phy->gmode || phy->rev >= 2) {
  1892. if (gphy->nrssi[0] == -1000) {
  1893. B43_WARN_ON(gphy->nrssi[1] != -1000);
  1894. b43_calc_nrssi_slope(dev);
  1895. } else
  1896. b43_calc_nrssi_threshold(dev);
  1897. }
  1898. if (phy->radio_rev == 8)
  1899. b43_phy_write(dev, B43_PHY_EXTG(0x05), 0x3230);
  1900. b43_phy_init_pctl(dev);
  1901. /* FIXME: The spec says in the following if, the 0 should be replaced
  1902. 'if OFDM may not be used in the current locale'
  1903. but OFDM is legal everywhere */
  1904. if ((dev->dev->chip_id == 0x4306
  1905. && dev->dev->chip_pkg == 2) || 0) {
  1906. b43_phy_mask(dev, B43_PHY_CRS0, 0xBFFF);
  1907. b43_phy_mask(dev, B43_PHY_OFDM(0xC3), 0x7FFF);
  1908. }
  1909. }
  1910. void b43_gphy_channel_switch(struct b43_wldev *dev,
  1911. unsigned int channel,
  1912. bool synthetic_pu_workaround)
  1913. {
  1914. if (synthetic_pu_workaround)
  1915. b43_synth_pu_workaround(dev, channel);
  1916. b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(channel));
  1917. if (channel == 14) {
  1918. if (dev->dev->bus_sprom->country_code ==
  1919. SSB_SPROM1CCODE_JAPAN)
  1920. b43_hf_write(dev,
  1921. b43_hf_read(dev) & ~B43_HF_ACPR);
  1922. else
  1923. b43_hf_write(dev,
  1924. b43_hf_read(dev) | B43_HF_ACPR);
  1925. b43_write16(dev, B43_MMIO_CHANNEL_EXT,
  1926. b43_read16(dev, B43_MMIO_CHANNEL_EXT)
  1927. | (1 << 11));
  1928. } else {
  1929. b43_write16(dev, B43_MMIO_CHANNEL_EXT,
  1930. b43_read16(dev, B43_MMIO_CHANNEL_EXT)
  1931. & 0xF7BF);
  1932. }
  1933. }
  1934. static void default_baseband_attenuation(struct b43_wldev *dev,
  1935. struct b43_bbatt *bb)
  1936. {
  1937. struct b43_phy *phy = &dev->phy;
  1938. if (phy->radio_ver == 0x2050 && phy->radio_rev < 6)
  1939. bb->att = 0;
  1940. else
  1941. bb->att = 2;
  1942. }
  1943. static void default_radio_attenuation(struct b43_wldev *dev,
  1944. struct b43_rfatt *rf)
  1945. {
  1946. struct b43_bus_dev *bdev = dev->dev;
  1947. struct b43_phy *phy = &dev->phy;
  1948. rf->with_padmix = false;
  1949. if (dev->dev->board_vendor == SSB_BOARDVENDOR_BCM &&
  1950. dev->dev->board_type == SSB_BOARD_BCM4309G) {
  1951. if (dev->dev->board_rev < 0x43) {
  1952. rf->att = 2;
  1953. return;
  1954. } else if (dev->dev->board_rev < 0x51) {
  1955. rf->att = 3;
  1956. return;
  1957. }
  1958. }
  1959. switch (phy->radio_ver) {
  1960. case 0x2053:
  1961. switch (phy->radio_rev) {
  1962. case 1:
  1963. rf->att = 6;
  1964. return;
  1965. }
  1966. break;
  1967. case 0x2050:
  1968. switch (phy->radio_rev) {
  1969. case 0:
  1970. rf->att = 5;
  1971. return;
  1972. case 1:
  1973. if (phy->type == B43_PHYTYPE_G) {
  1974. if (bdev->board_vendor == SSB_BOARDVENDOR_BCM
  1975. && bdev->board_type == SSB_BOARD_BCM4309G
  1976. && bdev->board_rev >= 30)
  1977. rf->att = 3;
  1978. else if (bdev->board_vendor ==
  1979. SSB_BOARDVENDOR_BCM
  1980. && bdev->board_type ==
  1981. SSB_BOARD_BU4306)
  1982. rf->att = 3;
  1983. else
  1984. rf->att = 1;
  1985. } else {
  1986. if (bdev->board_vendor == SSB_BOARDVENDOR_BCM
  1987. && bdev->board_type == SSB_BOARD_BCM4309G
  1988. && bdev->board_rev >= 30)
  1989. rf->att = 7;
  1990. else
  1991. rf->att = 6;
  1992. }
  1993. return;
  1994. case 2:
  1995. if (phy->type == B43_PHYTYPE_G) {
  1996. if (bdev->board_vendor == SSB_BOARDVENDOR_BCM
  1997. && bdev->board_type == SSB_BOARD_BCM4309G
  1998. && bdev->board_rev >= 30)
  1999. rf->att = 3;
  2000. else if (bdev->board_vendor ==
  2001. SSB_BOARDVENDOR_BCM
  2002. && bdev->board_type ==
  2003. SSB_BOARD_BU4306)
  2004. rf->att = 5;
  2005. else if (bdev->chip_id == 0x4320)
  2006. rf->att = 4;
  2007. else
  2008. rf->att = 3;
  2009. } else
  2010. rf->att = 6;
  2011. return;
  2012. case 3:
  2013. rf->att = 5;
  2014. return;
  2015. case 4:
  2016. case 5:
  2017. rf->att = 1;
  2018. return;
  2019. case 6:
  2020. case 7:
  2021. rf->att = 5;
  2022. return;
  2023. case 8:
  2024. rf->att = 0xA;
  2025. rf->with_padmix = true;
  2026. return;
  2027. case 9:
  2028. default:
  2029. rf->att = 5;
  2030. return;
  2031. }
  2032. }
  2033. rf->att = 5;
  2034. }
  2035. static u16 default_tx_control(struct b43_wldev *dev)
  2036. {
  2037. struct b43_phy *phy = &dev->phy;
  2038. if (phy->radio_ver != 0x2050)
  2039. return 0;
  2040. if (phy->radio_rev == 1)
  2041. return B43_TXCTL_PA2DB | B43_TXCTL_TXMIX;
  2042. if (phy->radio_rev < 6)
  2043. return B43_TXCTL_PA2DB;
  2044. if (phy->radio_rev == 8)
  2045. return B43_TXCTL_TXMIX;
  2046. return 0;
  2047. }
  2048. static u8 b43_gphy_aci_detect(struct b43_wldev *dev, u8 channel)
  2049. {
  2050. struct b43_phy *phy = &dev->phy;
  2051. struct b43_phy_g *gphy = phy->g;
  2052. u8 ret = 0;
  2053. u16 saved, rssi, temp;
  2054. int i, j = 0;
  2055. saved = b43_phy_read(dev, 0x0403);
  2056. b43_switch_channel(dev, channel);
  2057. b43_phy_write(dev, 0x0403, (saved & 0xFFF8) | 5);
  2058. if (gphy->aci_hw_rssi)
  2059. rssi = b43_phy_read(dev, 0x048A) & 0x3F;
  2060. else
  2061. rssi = saved & 0x3F;
  2062. /* clamp temp to signed 5bit */
  2063. if (rssi > 32)
  2064. rssi -= 64;
  2065. for (i = 0; i < 100; i++) {
  2066. temp = (b43_phy_read(dev, 0x047F) >> 8) & 0x3F;
  2067. if (temp > 32)
  2068. temp -= 64;
  2069. if (temp < rssi)
  2070. j++;
  2071. if (j >= 20)
  2072. ret = 1;
  2073. }
  2074. b43_phy_write(dev, 0x0403, saved);
  2075. return ret;
  2076. }
  2077. static u8 b43_gphy_aci_scan(struct b43_wldev *dev)
  2078. {
  2079. struct b43_phy *phy = &dev->phy;
  2080. u8 ret[13] = { 0 };
  2081. unsigned int channel = phy->channel;
  2082. unsigned int i, j, start, end;
  2083. if (!((phy->type == B43_PHYTYPE_G) && (phy->rev > 0)))
  2084. return 0;
  2085. b43_phy_lock(dev);
  2086. b43_radio_lock(dev);
  2087. b43_phy_mask(dev, 0x0802, 0xFFFC);
  2088. b43_phy_mask(dev, B43_PHY_G_CRS, 0x7FFF);
  2089. b43_set_all_gains(dev, 3, 8, 1);
  2090. start = (channel - 5 > 0) ? channel - 5 : 1;
  2091. end = (channel + 5 < 14) ? channel + 5 : 13;
  2092. for (i = start; i <= end; i++) {
  2093. if (abs(channel - i) > 2)
  2094. ret[i - 1] = b43_gphy_aci_detect(dev, i);
  2095. }
  2096. b43_switch_channel(dev, channel);
  2097. b43_phy_maskset(dev, 0x0802, 0xFFFC, 0x0003);
  2098. b43_phy_mask(dev, 0x0403, 0xFFF8);
  2099. b43_phy_set(dev, B43_PHY_G_CRS, 0x8000);
  2100. b43_set_original_gains(dev);
  2101. for (i = 0; i < 13; i++) {
  2102. if (!ret[i])
  2103. continue;
  2104. end = (i + 5 < 13) ? i + 5 : 13;
  2105. for (j = i; j < end; j++)
  2106. ret[j] = 1;
  2107. }
  2108. b43_radio_unlock(dev);
  2109. b43_phy_unlock(dev);
  2110. return ret[channel - 1];
  2111. }
  2112. static s32 b43_tssi2dbm_ad(s32 num, s32 den)
  2113. {
  2114. if (num < 0)
  2115. return num / den;
  2116. else
  2117. return (num + den / 2) / den;
  2118. }
  2119. static s8 b43_tssi2dbm_entry(s8 entry[], u8 index,
  2120. s16 pab0, s16 pab1, s16 pab2)
  2121. {
  2122. s32 m1, m2, f = 256, q, delta;
  2123. s8 i = 0;
  2124. m1 = b43_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
  2125. m2 = max(b43_tssi2dbm_ad(32768 + index * pab2, 256), 1);
  2126. do {
  2127. if (i > 15)
  2128. return -EINVAL;
  2129. q = b43_tssi2dbm_ad(f * 4096 -
  2130. b43_tssi2dbm_ad(m2 * f, 16) * f, 2048);
  2131. delta = abs(q - f);
  2132. f = q;
  2133. i++;
  2134. } while (delta >= 2);
  2135. entry[index] = clamp_val(b43_tssi2dbm_ad(m1 * f, 8192), -127, 128);
  2136. return 0;
  2137. }
  2138. u8 *b43_generate_dyn_tssi2dbm_tab(struct b43_wldev *dev,
  2139. s16 pab0, s16 pab1, s16 pab2)
  2140. {
  2141. unsigned int i;
  2142. u8 *tab;
  2143. int err;
  2144. tab = kmalloc(64, GFP_KERNEL);
  2145. if (!tab) {
  2146. b43err(dev->wl, "Could not allocate memory "
  2147. "for tssi2dbm table\n");
  2148. return NULL;
  2149. }
  2150. for (i = 0; i < 64; i++) {
  2151. err = b43_tssi2dbm_entry(tab, i, pab0, pab1, pab2);
  2152. if (err) {
  2153. b43err(dev->wl, "Could not generate "
  2154. "tssi2dBm table\n");
  2155. kfree(tab);
  2156. return NULL;
  2157. }
  2158. }
  2159. return tab;
  2160. }
  2161. /* Initialise the TSSI->dBm lookup table */
  2162. static int b43_gphy_init_tssi2dbm_table(struct b43_wldev *dev)
  2163. {
  2164. struct b43_phy *phy = &dev->phy;
  2165. struct b43_phy_g *gphy = phy->g;
  2166. s16 pab0, pab1, pab2;
  2167. pab0 = (s16) (dev->dev->bus_sprom->pa0b0);
  2168. pab1 = (s16) (dev->dev->bus_sprom->pa0b1);
  2169. pab2 = (s16) (dev->dev->bus_sprom->pa0b2);
  2170. B43_WARN_ON((dev->dev->chip_id == 0x4301) &&
  2171. (phy->radio_ver != 0x2050)); /* Not supported anymore */
  2172. gphy->dyn_tssi_tbl = false;
  2173. if (pab0 != 0 && pab1 != 0 && pab2 != 0 &&
  2174. pab0 != -1 && pab1 != -1 && pab2 != -1) {
  2175. /* The pabX values are set in SPROM. Use them. */
  2176. if ((s8) dev->dev->bus_sprom->itssi_bg != 0 &&
  2177. (s8) dev->dev->bus_sprom->itssi_bg != -1) {
  2178. gphy->tgt_idle_tssi =
  2179. (s8) (dev->dev->bus_sprom->itssi_bg);
  2180. } else
  2181. gphy->tgt_idle_tssi = 62;
  2182. gphy->tssi2dbm = b43_generate_dyn_tssi2dbm_tab(dev, pab0,
  2183. pab1, pab2);
  2184. if (!gphy->tssi2dbm)
  2185. return -ENOMEM;
  2186. gphy->dyn_tssi_tbl = true;
  2187. } else {
  2188. /* pabX values not set in SPROM. */
  2189. gphy->tgt_idle_tssi = 52;
  2190. gphy->tssi2dbm = b43_tssi2dbm_g_table;
  2191. }
  2192. return 0;
  2193. }
  2194. static int b43_gphy_op_allocate(struct b43_wldev *dev)
  2195. {
  2196. struct b43_phy_g *gphy;
  2197. struct b43_txpower_lo_control *lo;
  2198. int err;
  2199. gphy = kzalloc(sizeof(*gphy), GFP_KERNEL);
  2200. if (!gphy) {
  2201. err = -ENOMEM;
  2202. goto error;
  2203. }
  2204. dev->phy.g = gphy;
  2205. lo = kzalloc(sizeof(*lo), GFP_KERNEL);
  2206. if (!lo) {
  2207. err = -ENOMEM;
  2208. goto err_free_gphy;
  2209. }
  2210. gphy->lo_control = lo;
  2211. err = b43_gphy_init_tssi2dbm_table(dev);
  2212. if (err)
  2213. goto err_free_lo;
  2214. return 0;
  2215. err_free_lo:
  2216. kfree(lo);
  2217. err_free_gphy:
  2218. kfree(gphy);
  2219. error:
  2220. return err;
  2221. }
  2222. static void b43_gphy_op_prepare_structs(struct b43_wldev *dev)
  2223. {
  2224. struct b43_phy *phy = &dev->phy;
  2225. struct b43_phy_g *gphy = phy->g;
  2226. const void *tssi2dbm;
  2227. int tgt_idle_tssi;
  2228. struct b43_txpower_lo_control *lo;
  2229. unsigned int i;
  2230. /* tssi2dbm table is constant, so it is initialized at alloc time.
  2231. * Save a copy of the pointer. */
  2232. tssi2dbm = gphy->tssi2dbm;
  2233. tgt_idle_tssi = gphy->tgt_idle_tssi;
  2234. /* Save the LO pointer. */
  2235. lo = gphy->lo_control;
  2236. /* Zero out the whole PHY structure. */
  2237. memset(gphy, 0, sizeof(*gphy));
  2238. /* Restore pointers. */
  2239. gphy->tssi2dbm = tssi2dbm;
  2240. gphy->tgt_idle_tssi = tgt_idle_tssi;
  2241. gphy->lo_control = lo;
  2242. memset(gphy->minlowsig, 0xFF, sizeof(gphy->minlowsig));
  2243. /* NRSSI */
  2244. for (i = 0; i < ARRAY_SIZE(gphy->nrssi); i++)
  2245. gphy->nrssi[i] = -1000;
  2246. for (i = 0; i < ARRAY_SIZE(gphy->nrssi_lt); i++)
  2247. gphy->nrssi_lt[i] = i;
  2248. gphy->lofcal = 0xFFFF;
  2249. gphy->initval = 0xFFFF;
  2250. gphy->interfmode = B43_INTERFMODE_NONE;
  2251. /* OFDM-table address caching. */
  2252. gphy->ofdmtab_addr_direction = B43_OFDMTAB_DIRECTION_UNKNOWN;
  2253. gphy->average_tssi = 0xFF;
  2254. /* Local Osciallator structure */
  2255. lo->tx_bias = 0xFF;
  2256. INIT_LIST_HEAD(&lo->calib_list);
  2257. }
  2258. static void b43_gphy_op_free(struct b43_wldev *dev)
  2259. {
  2260. struct b43_phy *phy = &dev->phy;
  2261. struct b43_phy_g *gphy = phy->g;
  2262. kfree(gphy->lo_control);
  2263. if (gphy->dyn_tssi_tbl)
  2264. kfree(gphy->tssi2dbm);
  2265. gphy->dyn_tssi_tbl = false;
  2266. gphy->tssi2dbm = NULL;
  2267. kfree(gphy);
  2268. dev->phy.g = NULL;
  2269. }
  2270. static int b43_gphy_op_prepare_hardware(struct b43_wldev *dev)
  2271. {
  2272. struct b43_phy *phy = &dev->phy;
  2273. struct b43_phy_g *gphy = phy->g;
  2274. struct b43_txpower_lo_control *lo = gphy->lo_control;
  2275. B43_WARN_ON(phy->type != B43_PHYTYPE_G);
  2276. default_baseband_attenuation(dev, &gphy->bbatt);
  2277. default_radio_attenuation(dev, &gphy->rfatt);
  2278. gphy->tx_control = (default_tx_control(dev) << 4);
  2279. generate_rfatt_list(dev, &lo->rfatt_list);
  2280. generate_bbatt_list(dev, &lo->bbatt_list);
  2281. /* Commit previous writes */
  2282. b43_read32(dev, B43_MMIO_MACCTL);
  2283. if (phy->rev == 1) {
  2284. /* Workaround: Temporarly disable gmode through the early init
  2285. * phase, as the gmode stuff is not needed for phy rev 1 */
  2286. phy->gmode = false;
  2287. b43_wireless_core_reset(dev, 0);
  2288. b43_phy_initg(dev);
  2289. phy->gmode = true;
  2290. b43_wireless_core_reset(dev, 1);
  2291. }
  2292. return 0;
  2293. }
  2294. static int b43_gphy_op_init(struct b43_wldev *dev)
  2295. {
  2296. b43_phy_initg(dev);
  2297. return 0;
  2298. }
  2299. static void b43_gphy_op_exit(struct b43_wldev *dev)
  2300. {
  2301. b43_lo_g_cleanup(dev);
  2302. }
  2303. static u16 b43_gphy_op_read(struct b43_wldev *dev, u16 reg)
  2304. {
  2305. b43_write16f(dev, B43_MMIO_PHY_CONTROL, reg);
  2306. return b43_read16(dev, B43_MMIO_PHY_DATA);
  2307. }
  2308. static void b43_gphy_op_write(struct b43_wldev *dev, u16 reg, u16 value)
  2309. {
  2310. b43_write16f(dev, B43_MMIO_PHY_CONTROL, reg);
  2311. b43_write16(dev, B43_MMIO_PHY_DATA, value);
  2312. }
  2313. static u16 b43_gphy_op_radio_read(struct b43_wldev *dev, u16 reg)
  2314. {
  2315. /* Register 1 is a 32-bit register. */
  2316. B43_WARN_ON(reg == 1);
  2317. /* G-PHY needs 0x80 for read access. */
  2318. reg |= 0x80;
  2319. b43_write16f(dev, B43_MMIO_RADIO_CONTROL, reg);
  2320. return b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
  2321. }
  2322. static void b43_gphy_op_radio_write(struct b43_wldev *dev, u16 reg, u16 value)
  2323. {
  2324. /* Register 1 is a 32-bit register. */
  2325. B43_WARN_ON(reg == 1);
  2326. b43_write16f(dev, B43_MMIO_RADIO_CONTROL, reg);
  2327. b43_write16(dev, B43_MMIO_RADIO_DATA_LOW, value);
  2328. }
  2329. static bool b43_gphy_op_supports_hwpctl(struct b43_wldev *dev)
  2330. {
  2331. return (dev->phy.rev >= 6);
  2332. }
  2333. static void b43_gphy_op_software_rfkill(struct b43_wldev *dev,
  2334. bool blocked)
  2335. {
  2336. struct b43_phy *phy = &dev->phy;
  2337. struct b43_phy_g *gphy = phy->g;
  2338. unsigned int channel;
  2339. might_sleep();
  2340. if (!blocked) {
  2341. /* Turn radio ON */
  2342. if (phy->radio_on)
  2343. return;
  2344. b43_phy_write(dev, 0x0015, 0x8000);
  2345. b43_phy_write(dev, 0x0015, 0xCC00);
  2346. b43_phy_write(dev, 0x0015, (phy->gmode ? 0x00C0 : 0x0000));
  2347. if (gphy->radio_off_context.valid) {
  2348. /* Restore the RFover values. */
  2349. b43_phy_write(dev, B43_PHY_RFOVER,
  2350. gphy->radio_off_context.rfover);
  2351. b43_phy_write(dev, B43_PHY_RFOVERVAL,
  2352. gphy->radio_off_context.rfoverval);
  2353. gphy->radio_off_context.valid = false;
  2354. }
  2355. channel = phy->channel;
  2356. b43_gphy_channel_switch(dev, 6, 1);
  2357. b43_gphy_channel_switch(dev, channel, 0);
  2358. } else {
  2359. /* Turn radio OFF */
  2360. u16 rfover, rfoverval;
  2361. rfover = b43_phy_read(dev, B43_PHY_RFOVER);
  2362. rfoverval = b43_phy_read(dev, B43_PHY_RFOVERVAL);
  2363. gphy->radio_off_context.rfover = rfover;
  2364. gphy->radio_off_context.rfoverval = rfoverval;
  2365. gphy->radio_off_context.valid = true;
  2366. b43_phy_write(dev, B43_PHY_RFOVER, rfover | 0x008C);
  2367. b43_phy_write(dev, B43_PHY_RFOVERVAL, rfoverval & 0xFF73);
  2368. }
  2369. }
  2370. static int b43_gphy_op_switch_channel(struct b43_wldev *dev,
  2371. unsigned int new_channel)
  2372. {
  2373. if ((new_channel < 1) || (new_channel > 14))
  2374. return -EINVAL;
  2375. b43_gphy_channel_switch(dev, new_channel, 0);
  2376. return 0;
  2377. }
  2378. static unsigned int b43_gphy_op_get_default_chan(struct b43_wldev *dev)
  2379. {
  2380. return 1; /* Default to channel 1 */
  2381. }
  2382. static void b43_gphy_op_set_rx_antenna(struct b43_wldev *dev, int antenna)
  2383. {
  2384. struct b43_phy *phy = &dev->phy;
  2385. u16 tmp;
  2386. int autodiv = 0;
  2387. if (antenna == B43_ANTENNA_AUTO0 || antenna == B43_ANTENNA_AUTO1)
  2388. autodiv = 1;
  2389. b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_ANTDIVHELP);
  2390. b43_phy_maskset(dev, B43_PHY_BBANDCFG, ~B43_PHY_BBANDCFG_RXANT,
  2391. (autodiv ? B43_ANTENNA_AUTO1 : antenna) <<
  2392. B43_PHY_BBANDCFG_RXANT_SHIFT);
  2393. if (autodiv) {
  2394. tmp = b43_phy_read(dev, B43_PHY_ANTDWELL);
  2395. if (antenna == B43_ANTENNA_AUTO1)
  2396. tmp &= ~B43_PHY_ANTDWELL_AUTODIV1;
  2397. else
  2398. tmp |= B43_PHY_ANTDWELL_AUTODIV1;
  2399. b43_phy_write(dev, B43_PHY_ANTDWELL, tmp);
  2400. }
  2401. tmp = b43_phy_read(dev, B43_PHY_ANTWRSETT);
  2402. if (autodiv)
  2403. tmp |= B43_PHY_ANTWRSETT_ARXDIV;
  2404. else
  2405. tmp &= ~B43_PHY_ANTWRSETT_ARXDIV;
  2406. b43_phy_write(dev, B43_PHY_ANTWRSETT, tmp);
  2407. if (autodiv)
  2408. b43_phy_set(dev, B43_PHY_ANTWRSETT, B43_PHY_ANTWRSETT_ARXDIV);
  2409. else {
  2410. b43_phy_mask(dev, B43_PHY_ANTWRSETT,
  2411. B43_PHY_ANTWRSETT_ARXDIV);
  2412. }
  2413. if (phy->rev >= 2) {
  2414. b43_phy_set(dev, B43_PHY_OFDM61, B43_PHY_OFDM61_10);
  2415. b43_phy_maskset(dev, B43_PHY_DIVSRCHGAINBACK, 0xFF00, 0x15);
  2416. if (phy->rev == 2)
  2417. b43_phy_write(dev, B43_PHY_ADIVRELATED, 8);
  2418. else
  2419. b43_phy_maskset(dev, B43_PHY_ADIVRELATED, 0xFF00, 8);
  2420. }
  2421. if (phy->rev >= 6)
  2422. b43_phy_write(dev, B43_PHY_OFDM9B, 0xDC);
  2423. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_ANTDIVHELP);
  2424. }
  2425. static int b43_gphy_op_interf_mitigation(struct b43_wldev *dev,
  2426. enum b43_interference_mitigation mode)
  2427. {
  2428. struct b43_phy *phy = &dev->phy;
  2429. struct b43_phy_g *gphy = phy->g;
  2430. int currentmode;
  2431. B43_WARN_ON(phy->type != B43_PHYTYPE_G);
  2432. if ((phy->rev == 0) || (!phy->gmode))
  2433. return -ENODEV;
  2434. gphy->aci_wlan_automatic = false;
  2435. switch (mode) {
  2436. case B43_INTERFMODE_AUTOWLAN:
  2437. gphy->aci_wlan_automatic = true;
  2438. if (gphy->aci_enable)
  2439. mode = B43_INTERFMODE_MANUALWLAN;
  2440. else
  2441. mode = B43_INTERFMODE_NONE;
  2442. break;
  2443. case B43_INTERFMODE_NONE:
  2444. case B43_INTERFMODE_NONWLAN:
  2445. case B43_INTERFMODE_MANUALWLAN:
  2446. break;
  2447. default:
  2448. return -EINVAL;
  2449. }
  2450. currentmode = gphy->interfmode;
  2451. if (currentmode == mode)
  2452. return 0;
  2453. if (currentmode != B43_INTERFMODE_NONE)
  2454. b43_radio_interference_mitigation_disable(dev, currentmode);
  2455. if (mode == B43_INTERFMODE_NONE) {
  2456. gphy->aci_enable = false;
  2457. gphy->aci_hw_rssi = false;
  2458. } else
  2459. b43_radio_interference_mitigation_enable(dev, mode);
  2460. gphy->interfmode = mode;
  2461. return 0;
  2462. }
  2463. /* http://bcm-specs.sipsolutions.net/EstimatePowerOut
  2464. * This function converts a TSSI value to dBm in Q5.2
  2465. */
  2466. static s8 b43_gphy_estimate_power_out(struct b43_wldev *dev, s8 tssi)
  2467. {
  2468. struct b43_phy_g *gphy = dev->phy.g;
  2469. s8 dbm;
  2470. s32 tmp;
  2471. tmp = (gphy->tgt_idle_tssi - gphy->cur_idle_tssi + tssi);
  2472. tmp = clamp_val(tmp, 0x00, 0x3F);
  2473. dbm = gphy->tssi2dbm[tmp];
  2474. return dbm;
  2475. }
  2476. static void b43_put_attenuation_into_ranges(struct b43_wldev *dev,
  2477. int *_bbatt, int *_rfatt)
  2478. {
  2479. int rfatt = *_rfatt;
  2480. int bbatt = *_bbatt;
  2481. struct b43_txpower_lo_control *lo = dev->phy.g->lo_control;
  2482. /* Get baseband and radio attenuation values into their permitted ranges.
  2483. * Radio attenuation affects power level 4 times as much as baseband. */
  2484. /* Range constants */
  2485. const int rf_min = lo->rfatt_list.min_val;
  2486. const int rf_max = lo->rfatt_list.max_val;
  2487. const int bb_min = lo->bbatt_list.min_val;
  2488. const int bb_max = lo->bbatt_list.max_val;
  2489. while (1) {
  2490. if (rfatt > rf_max && bbatt > bb_max - 4)
  2491. break; /* Can not get it into ranges */
  2492. if (rfatt < rf_min && bbatt < bb_min + 4)
  2493. break; /* Can not get it into ranges */
  2494. if (bbatt > bb_max && rfatt > rf_max - 1)
  2495. break; /* Can not get it into ranges */
  2496. if (bbatt < bb_min && rfatt < rf_min + 1)
  2497. break; /* Can not get it into ranges */
  2498. if (bbatt > bb_max) {
  2499. bbatt -= 4;
  2500. rfatt += 1;
  2501. continue;
  2502. }
  2503. if (bbatt < bb_min) {
  2504. bbatt += 4;
  2505. rfatt -= 1;
  2506. continue;
  2507. }
  2508. if (rfatt > rf_max) {
  2509. rfatt -= 1;
  2510. bbatt += 4;
  2511. continue;
  2512. }
  2513. if (rfatt < rf_min) {
  2514. rfatt += 1;
  2515. bbatt -= 4;
  2516. continue;
  2517. }
  2518. break;
  2519. }
  2520. *_rfatt = clamp_val(rfatt, rf_min, rf_max);
  2521. *_bbatt = clamp_val(bbatt, bb_min, bb_max);
  2522. }
  2523. static void b43_gphy_op_adjust_txpower(struct b43_wldev *dev)
  2524. {
  2525. struct b43_phy *phy = &dev->phy;
  2526. struct b43_phy_g *gphy = phy->g;
  2527. int rfatt, bbatt;
  2528. u8 tx_control;
  2529. b43_mac_suspend(dev);
  2530. /* Calculate the new attenuation values. */
  2531. bbatt = gphy->bbatt.att;
  2532. bbatt += gphy->bbatt_delta;
  2533. rfatt = gphy->rfatt.att;
  2534. rfatt += gphy->rfatt_delta;
  2535. b43_put_attenuation_into_ranges(dev, &bbatt, &rfatt);
  2536. tx_control = gphy->tx_control;
  2537. if ((phy->radio_ver == 0x2050) && (phy->radio_rev == 2)) {
  2538. if (rfatt <= 1) {
  2539. if (tx_control == 0) {
  2540. tx_control =
  2541. B43_TXCTL_PA2DB |
  2542. B43_TXCTL_TXMIX;
  2543. rfatt += 2;
  2544. bbatt += 2;
  2545. } else if (dev->dev->bus_sprom->
  2546. boardflags_lo &
  2547. B43_BFL_PACTRL) {
  2548. bbatt += 4 * (rfatt - 2);
  2549. rfatt = 2;
  2550. }
  2551. } else if (rfatt > 4 && tx_control) {
  2552. tx_control = 0;
  2553. if (bbatt < 3) {
  2554. rfatt -= 3;
  2555. bbatt += 2;
  2556. } else {
  2557. rfatt -= 2;
  2558. bbatt -= 2;
  2559. }
  2560. }
  2561. }
  2562. /* Save the control values */
  2563. gphy->tx_control = tx_control;
  2564. b43_put_attenuation_into_ranges(dev, &bbatt, &rfatt);
  2565. gphy->rfatt.att = rfatt;
  2566. gphy->bbatt.att = bbatt;
  2567. if (b43_debug(dev, B43_DBG_XMITPOWER))
  2568. b43dbg(dev->wl, "Adjusting TX power\n");
  2569. /* Adjust the hardware */
  2570. b43_phy_lock(dev);
  2571. b43_radio_lock(dev);
  2572. b43_set_txpower_g(dev, &gphy->bbatt, &gphy->rfatt,
  2573. gphy->tx_control);
  2574. b43_radio_unlock(dev);
  2575. b43_phy_unlock(dev);
  2576. b43_mac_enable(dev);
  2577. }
  2578. static enum b43_txpwr_result b43_gphy_op_recalc_txpower(struct b43_wldev *dev,
  2579. bool ignore_tssi)
  2580. {
  2581. struct b43_phy *phy = &dev->phy;
  2582. struct b43_phy_g *gphy = phy->g;
  2583. unsigned int average_tssi;
  2584. int cck_result, ofdm_result;
  2585. int estimated_pwr, desired_pwr, pwr_adjust;
  2586. int rfatt_delta, bbatt_delta;
  2587. unsigned int max_pwr;
  2588. /* First get the average TSSI */
  2589. cck_result = b43_phy_shm_tssi_read(dev, B43_SHM_SH_TSSI_CCK);
  2590. ofdm_result = b43_phy_shm_tssi_read(dev, B43_SHM_SH_TSSI_OFDM_G);
  2591. if ((cck_result < 0) && (ofdm_result < 0)) {
  2592. /* No TSSI information available */
  2593. if (!ignore_tssi)
  2594. goto no_adjustment_needed;
  2595. cck_result = 0;
  2596. ofdm_result = 0;
  2597. }
  2598. if (cck_result < 0)
  2599. average_tssi = ofdm_result;
  2600. else if (ofdm_result < 0)
  2601. average_tssi = cck_result;
  2602. else
  2603. average_tssi = (cck_result + ofdm_result) / 2;
  2604. /* Merge the average with the stored value. */
  2605. if (likely(gphy->average_tssi != 0xFF))
  2606. average_tssi = (average_tssi + gphy->average_tssi) / 2;
  2607. gphy->average_tssi = average_tssi;
  2608. B43_WARN_ON(average_tssi >= B43_TSSI_MAX);
  2609. /* Estimate the TX power emission based on the TSSI */
  2610. estimated_pwr = b43_gphy_estimate_power_out(dev, average_tssi);
  2611. B43_WARN_ON(phy->type != B43_PHYTYPE_G);
  2612. max_pwr = dev->dev->bus_sprom->maxpwr_bg;
  2613. if (dev->dev->bus_sprom->boardflags_lo & B43_BFL_PACTRL)
  2614. max_pwr -= 3; /* minus 0.75 */
  2615. if (unlikely(max_pwr >= INT_TO_Q52(30/*dBm*/))) {
  2616. b43warn(dev->wl,
  2617. "Invalid max-TX-power value in SPROM.\n");
  2618. max_pwr = INT_TO_Q52(20); /* fake it */
  2619. dev->dev->bus_sprom->maxpwr_bg = max_pwr;
  2620. }
  2621. /* Get desired power (in Q5.2) */
  2622. if (phy->desired_txpower < 0)
  2623. desired_pwr = INT_TO_Q52(0);
  2624. else
  2625. desired_pwr = INT_TO_Q52(phy->desired_txpower);
  2626. /* And limit it. max_pwr already is Q5.2 */
  2627. desired_pwr = clamp_val(desired_pwr, 0, max_pwr);
  2628. if (b43_debug(dev, B43_DBG_XMITPOWER)) {
  2629. b43dbg(dev->wl,
  2630. "[TX power] current = " Q52_FMT
  2631. " dBm, desired = " Q52_FMT
  2632. " dBm, max = " Q52_FMT "\n",
  2633. Q52_ARG(estimated_pwr),
  2634. Q52_ARG(desired_pwr),
  2635. Q52_ARG(max_pwr));
  2636. }
  2637. /* Calculate the adjustment delta. */
  2638. pwr_adjust = desired_pwr - estimated_pwr;
  2639. if (pwr_adjust == 0)
  2640. goto no_adjustment_needed;
  2641. /* RF attenuation delta. */
  2642. rfatt_delta = ((pwr_adjust + 7) / 8);
  2643. /* Lower attenuation => Bigger power output. Negate it. */
  2644. rfatt_delta = -rfatt_delta;
  2645. /* Baseband attenuation delta. */
  2646. bbatt_delta = pwr_adjust / 2;
  2647. /* Lower attenuation => Bigger power output. Negate it. */
  2648. bbatt_delta = -bbatt_delta;
  2649. /* RF att affects power level 4 times as much as
  2650. * Baseband attennuation. Subtract it. */
  2651. bbatt_delta -= 4 * rfatt_delta;
  2652. #if B43_DEBUG
  2653. if (b43_debug(dev, B43_DBG_XMITPOWER)) {
  2654. int dbm = pwr_adjust < 0 ? -pwr_adjust : pwr_adjust;
  2655. b43dbg(dev->wl,
  2656. "[TX power deltas] %s" Q52_FMT " dBm => "
  2657. "bbatt-delta = %d, rfatt-delta = %d\n",
  2658. (pwr_adjust < 0 ? "-" : ""), Q52_ARG(dbm),
  2659. bbatt_delta, rfatt_delta);
  2660. }
  2661. #endif /* DEBUG */
  2662. /* So do we finally need to adjust something in hardware? */
  2663. if ((rfatt_delta == 0) && (bbatt_delta == 0))
  2664. goto no_adjustment_needed;
  2665. /* Save the deltas for later when we adjust the power. */
  2666. gphy->bbatt_delta = bbatt_delta;
  2667. gphy->rfatt_delta = rfatt_delta;
  2668. /* We need to adjust the TX power on the device. */
  2669. return B43_TXPWR_RES_NEED_ADJUST;
  2670. no_adjustment_needed:
  2671. return B43_TXPWR_RES_DONE;
  2672. }
  2673. static void b43_gphy_op_pwork_15sec(struct b43_wldev *dev)
  2674. {
  2675. struct b43_phy *phy = &dev->phy;
  2676. struct b43_phy_g *gphy = phy->g;
  2677. b43_mac_suspend(dev);
  2678. //TODO: update_aci_moving_average
  2679. if (gphy->aci_enable && gphy->aci_wlan_automatic) {
  2680. if (!gphy->aci_enable && 1 /*TODO: not scanning? */ ) {
  2681. if (0 /*TODO: bunch of conditions */ ) {
  2682. phy->ops->interf_mitigation(dev,
  2683. B43_INTERFMODE_MANUALWLAN);
  2684. }
  2685. } else if (0 /*TODO*/) {
  2686. if (/*(aci_average > 1000) &&*/ !b43_gphy_aci_scan(dev))
  2687. phy->ops->interf_mitigation(dev, B43_INTERFMODE_NONE);
  2688. }
  2689. } else if (gphy->interfmode == B43_INTERFMODE_NONWLAN &&
  2690. phy->rev == 1) {
  2691. //TODO: implement rev1 workaround
  2692. }
  2693. b43_lo_g_maintenance_work(dev);
  2694. b43_mac_enable(dev);
  2695. }
  2696. static void b43_gphy_op_pwork_60sec(struct b43_wldev *dev)
  2697. {
  2698. struct b43_phy *phy = &dev->phy;
  2699. if (!(dev->dev->bus_sprom->boardflags_lo & B43_BFL_RSSI))
  2700. return;
  2701. b43_mac_suspend(dev);
  2702. b43_calc_nrssi_slope(dev);
  2703. if ((phy->radio_ver == 0x2050) && (phy->radio_rev == 8)) {
  2704. u8 old_chan = phy->channel;
  2705. /* VCO Calibration */
  2706. if (old_chan >= 8)
  2707. b43_switch_channel(dev, 1);
  2708. else
  2709. b43_switch_channel(dev, 13);
  2710. b43_switch_channel(dev, old_chan);
  2711. }
  2712. b43_mac_enable(dev);
  2713. }
  2714. const struct b43_phy_operations b43_phyops_g = {
  2715. .allocate = b43_gphy_op_allocate,
  2716. .free = b43_gphy_op_free,
  2717. .prepare_structs = b43_gphy_op_prepare_structs,
  2718. .prepare_hardware = b43_gphy_op_prepare_hardware,
  2719. .init = b43_gphy_op_init,
  2720. .exit = b43_gphy_op_exit,
  2721. .phy_read = b43_gphy_op_read,
  2722. .phy_write = b43_gphy_op_write,
  2723. .radio_read = b43_gphy_op_radio_read,
  2724. .radio_write = b43_gphy_op_radio_write,
  2725. .supports_hwpctl = b43_gphy_op_supports_hwpctl,
  2726. .software_rfkill = b43_gphy_op_software_rfkill,
  2727. .switch_analog = b43_phyop_switch_analog_generic,
  2728. .switch_channel = b43_gphy_op_switch_channel,
  2729. .get_default_chan = b43_gphy_op_get_default_chan,
  2730. .set_rx_antenna = b43_gphy_op_set_rx_antenna,
  2731. .interf_mitigation = b43_gphy_op_interf_mitigation,
  2732. .recalc_txpower = b43_gphy_op_recalc_txpower,
  2733. .adjust_txpower = b43_gphy_op_adjust_txpower,
  2734. .pwork_15sec = b43_gphy_op_pwork_15sec,
  2735. .pwork_60sec = b43_gphy_op_pwork_60sec,
  2736. };