phy.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721
  1. /*
  2. * Atheros AR9170 driver
  3. *
  4. * PHY and RF code
  5. *
  6. * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  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. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; see the file COPYING. If not, see
  20. * http://www.gnu.org/licenses/.
  21. *
  22. * This file incorporates work covered by the following copyright and
  23. * permission notice:
  24. * Copyright (c) 2007-2008 Atheros Communications, Inc.
  25. *
  26. * Permission to use, copy, modify, and/or distribute this software for any
  27. * purpose with or without fee is hereby granted, provided that the above
  28. * copyright notice and this permission notice appear in all copies.
  29. *
  30. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  31. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  32. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  33. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  34. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  35. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  36. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  37. */
  38. #include <linux/bitrev.h>
  39. #include "ar9170.h"
  40. #include "cmd.h"
  41. static int ar9170_init_power_cal(struct ar9170 *ar)
  42. {
  43. ar9170_regwrite_begin(ar);
  44. ar9170_regwrite(0x1bc000 + 0x993c, 0x7f);
  45. ar9170_regwrite(0x1bc000 + 0x9934, 0x3f3f3f3f);
  46. ar9170_regwrite(0x1bc000 + 0x9938, 0x3f3f3f3f);
  47. ar9170_regwrite(0x1bc000 + 0xa234, 0x3f3f3f3f);
  48. ar9170_regwrite(0x1bc000 + 0xa238, 0x3f3f3f3f);
  49. ar9170_regwrite(0x1bc000 + 0xa38c, 0x3f3f3f3f);
  50. ar9170_regwrite(0x1bc000 + 0xa390, 0x3f3f3f3f);
  51. ar9170_regwrite(0x1bc000 + 0xa3cc, 0x3f3f3f3f);
  52. ar9170_regwrite(0x1bc000 + 0xa3d0, 0x3f3f3f3f);
  53. ar9170_regwrite(0x1bc000 + 0xa3d4, 0x3f3f3f3f);
  54. ar9170_regwrite_finish();
  55. return ar9170_regwrite_result();
  56. }
  57. struct ar9170_phy_init {
  58. u32 reg, _5ghz_20, _5ghz_40, _2ghz_40, _2ghz_20;
  59. };
  60. static struct ar9170_phy_init ar5416_phy_init[] = {
  61. { 0x1c5800, 0x00000007, 0x00000007, 0x00000007, 0x00000007, },
  62. { 0x1c5804, 0x00000300, 0x000003c4, 0x000003c4, 0x00000300, },
  63. { 0x1c5808, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  64. { 0x1c580c, 0xad848e19, 0xad848e19, 0xad848e19, 0xad848e19, },
  65. { 0x1c5810, 0x7d14e000, 0x7d14e000, 0x7d14e000, 0x7d14e000, },
  66. { 0x1c5814, 0x9c0a9f6b, 0x9c0a9f6b, 0x9c0a9f6b, 0x9c0a9f6b, },
  67. { 0x1c5818, 0x00000090, 0x00000090, 0x00000090, 0x00000090, },
  68. { 0x1c581c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  69. { 0x1c5820, 0x02020200, 0x02020200, 0x02020200, 0x02020200, },
  70. { 0x1c5824, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, },
  71. { 0x1c5828, 0x0a020001, 0x0a020001, 0x0a020001, 0x0a020001, },
  72. { 0x1c582c, 0x0000a000, 0x0000a000, 0x0000a000, 0x0000a000, },
  73. { 0x1c5830, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  74. { 0x1c5834, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, },
  75. { 0x1c5838, 0x00000007, 0x00000007, 0x00000007, 0x00000007, },
  76. { 0x1c583c, 0x00200400, 0x00200400, 0x00200400, 0x00200400, },
  77. { 0x1c5840, 0x206a002e, 0x206a002e, 0x206a002e, 0x206a002e, },
  78. { 0x1c5844, 0x1372161e, 0x13721c1e, 0x13721c24, 0x137216a4, },
  79. { 0x1c5848, 0x001a6a65, 0x001a6a65, 0x00197a68, 0x00197a68, },
  80. { 0x1c584c, 0x1284233c, 0x1284233c, 0x1284233c, 0x1284233c, },
  81. { 0x1c5850, 0x6c48b4e4, 0x6c48b4e4, 0x6c48b0e4, 0x6c48b0e4, },
  82. { 0x1c5854, 0x00000859, 0x00000859, 0x00000859, 0x00000859, },
  83. { 0x1c5858, 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e, },
  84. { 0x1c585c, 0x31395c5e, 0x31395c5e, 0x31395c5e, 0x31395c5e, },
  85. { 0x1c5860, 0x0004dd10, 0x0004dd10, 0x0004dd20, 0x0004dd20, },
  86. { 0x1c5868, 0x409a4190, 0x409a4190, 0x409a4190, 0x409a4190, },
  87. { 0x1c586c, 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb081, },
  88. { 0x1c5900, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  89. { 0x1c5904, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  90. { 0x1c5908, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  91. { 0x1c590c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  92. { 0x1c5914, 0x000007d0, 0x000007d0, 0x00000898, 0x00000898, },
  93. { 0x1c5918, 0x00000118, 0x00000230, 0x00000268, 0x00000134, },
  94. { 0x1c591c, 0x10000fff, 0x10000fff, 0x10000fff, 0x10000fff, },
  95. { 0x1c5920, 0x0510081c, 0x0510081c, 0x0510001c, 0x0510001c, },
  96. { 0x1c5924, 0xd0058a15, 0xd0058a15, 0xd0058a15, 0xd0058a15, },
  97. { 0x1c5928, 0x00000001, 0x00000001, 0x00000001, 0x00000001, },
  98. { 0x1c592c, 0x00000004, 0x00000004, 0x00000004, 0x00000004, },
  99. { 0x1c5934, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
  100. { 0x1c5938, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
  101. { 0x1c593c, 0x0000007f, 0x0000007f, 0x0000007f, 0x0000007f, },
  102. { 0x1c5944, 0xdfb81020, 0xdfb81020, 0xdfb81020, 0xdfb81020, },
  103. { 0x1c5948, 0x9280b212, 0x9280b212, 0x9280b212, 0x9280b212, },
  104. { 0x1c594c, 0x00020028, 0x00020028, 0x00020028, 0x00020028, },
  105. { 0x1c5954, 0x5d50e188, 0x5d50e188, 0x5d50e188, 0x5d50e188, },
  106. { 0x1c5958, 0x00081fff, 0x00081fff, 0x00081fff, 0x00081fff, },
  107. { 0x1c5960, 0x00009b40, 0x00009b40, 0x00009b40, 0x00009b40, },
  108. { 0x1c5964, 0x00001120, 0x00001120, 0x00001120, 0x00001120, },
  109. { 0x1c5970, 0x190fb515, 0x190fb515, 0x190fb515, 0x190fb515, },
  110. { 0x1c5974, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  111. { 0x1c5978, 0x00000001, 0x00000001, 0x00000001, 0x00000001, },
  112. { 0x1c597c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  113. { 0x1c5980, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  114. { 0x1c5984, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  115. { 0x1c5988, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  116. { 0x1c598c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  117. { 0x1c5990, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  118. { 0x1c5994, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  119. { 0x1c5998, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  120. { 0x1c599c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  121. { 0x1c59a0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  122. { 0x1c59a4, 0x00000007, 0x00000007, 0x00000007, 0x00000007, },
  123. { 0x1c59a8, 0x001fff00, 0x001fff00, 0x001fff00, 0x001fff00, },
  124. { 0x1c59ac, 0x006f00c4, 0x006f00c4, 0x006f00c4, 0x006f00c4, },
  125. { 0x1c59b0, 0x03051000, 0x03051000, 0x03051000, 0x03051000, },
  126. { 0x1c59b4, 0x00000820, 0x00000820, 0x00000820, 0x00000820, },
  127. { 0x1c59c0, 0x038919be, 0x038919be, 0x038919be, 0x038919be, },
  128. { 0x1c59c4, 0x06336f77, 0x06336f77, 0x06336f77, 0x06336f77, },
  129. { 0x1c59c8, 0x60f6532c, 0x60f6532c, 0x60f6532c, 0x60f6532c, },
  130. { 0x1c59cc, 0x08f186c8, 0x08f186c8, 0x08f186c8, 0x08f186c8, },
  131. { 0x1c59d0, 0x00046384, 0x00046384, 0x00046384, 0x00046384, },
  132. { 0x1c59d4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  133. { 0x1c59d8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  134. { 0x1c59dc, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  135. { 0x1c59e0, 0x00000200, 0x00000200, 0x00000200, 0x00000200, },
  136. { 0x1c59e4, 0x64646464, 0x64646464, 0x64646464, 0x64646464, },
  137. { 0x1c59e8, 0x3c787878, 0x3c787878, 0x3c787878, 0x3c787878, },
  138. { 0x1c59ec, 0x000000aa, 0x000000aa, 0x000000aa, 0x000000aa, },
  139. { 0x1c59f0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  140. { 0x1c59fc, 0x00001042, 0x00001042, 0x00001042, 0x00001042, },
  141. { 0x1c5a00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  142. { 0x1c5a04, 0x00000040, 0x00000040, 0x00000040, 0x00000040, },
  143. { 0x1c5a08, 0x00000080, 0x00000080, 0x00000080, 0x00000080, },
  144. { 0x1c5a0c, 0x000001a1, 0x000001a1, 0x00000141, 0x00000141, },
  145. { 0x1c5a10, 0x000001e1, 0x000001e1, 0x00000181, 0x00000181, },
  146. { 0x1c5a14, 0x00000021, 0x00000021, 0x000001c1, 0x000001c1, },
  147. { 0x1c5a18, 0x00000061, 0x00000061, 0x00000001, 0x00000001, },
  148. { 0x1c5a1c, 0x00000168, 0x00000168, 0x00000041, 0x00000041, },
  149. { 0x1c5a20, 0x000001a8, 0x000001a8, 0x000001a8, 0x000001a8, },
  150. { 0x1c5a24, 0x000001e8, 0x000001e8, 0x000001e8, 0x000001e8, },
  151. { 0x1c5a28, 0x00000028, 0x00000028, 0x00000028, 0x00000028, },
  152. { 0x1c5a2c, 0x00000068, 0x00000068, 0x00000068, 0x00000068, },
  153. { 0x1c5a30, 0x00000189, 0x00000189, 0x000000a8, 0x000000a8, },
  154. { 0x1c5a34, 0x000001c9, 0x000001c9, 0x00000169, 0x00000169, },
  155. { 0x1c5a38, 0x00000009, 0x00000009, 0x000001a9, 0x000001a9, },
  156. { 0x1c5a3c, 0x00000049, 0x00000049, 0x000001e9, 0x000001e9, },
  157. { 0x1c5a40, 0x00000089, 0x00000089, 0x00000029, 0x00000029, },
  158. { 0x1c5a44, 0x00000170, 0x00000170, 0x00000069, 0x00000069, },
  159. { 0x1c5a48, 0x000001b0, 0x000001b0, 0x00000190, 0x00000190, },
  160. { 0x1c5a4c, 0x000001f0, 0x000001f0, 0x000001d0, 0x000001d0, },
  161. { 0x1c5a50, 0x00000030, 0x00000030, 0x00000010, 0x00000010, },
  162. { 0x1c5a54, 0x00000070, 0x00000070, 0x00000050, 0x00000050, },
  163. { 0x1c5a58, 0x00000191, 0x00000191, 0x00000090, 0x00000090, },
  164. { 0x1c5a5c, 0x000001d1, 0x000001d1, 0x00000151, 0x00000151, },
  165. { 0x1c5a60, 0x00000011, 0x00000011, 0x00000191, 0x00000191, },
  166. { 0x1c5a64, 0x00000051, 0x00000051, 0x000001d1, 0x000001d1, },
  167. { 0x1c5a68, 0x00000091, 0x00000091, 0x00000011, 0x00000011, },
  168. { 0x1c5a6c, 0x000001b8, 0x000001b8, 0x00000051, 0x00000051, },
  169. { 0x1c5a70, 0x000001f8, 0x000001f8, 0x00000198, 0x00000198, },
  170. { 0x1c5a74, 0x00000038, 0x00000038, 0x000001d8, 0x000001d8, },
  171. { 0x1c5a78, 0x00000078, 0x00000078, 0x00000018, 0x00000018, },
  172. { 0x1c5a7c, 0x00000199, 0x00000199, 0x00000058, 0x00000058, },
  173. { 0x1c5a80, 0x000001d9, 0x000001d9, 0x00000098, 0x00000098, },
  174. { 0x1c5a84, 0x00000019, 0x00000019, 0x00000159, 0x00000159, },
  175. { 0x1c5a88, 0x00000059, 0x00000059, 0x00000199, 0x00000199, },
  176. { 0x1c5a8c, 0x00000099, 0x00000099, 0x000001d9, 0x000001d9, },
  177. { 0x1c5a90, 0x000000d9, 0x000000d9, 0x00000019, 0x00000019, },
  178. { 0x1c5a94, 0x000000f9, 0x000000f9, 0x00000059, 0x00000059, },
  179. { 0x1c5a98, 0x000000f9, 0x000000f9, 0x00000099, 0x00000099, },
  180. { 0x1c5a9c, 0x000000f9, 0x000000f9, 0x000000d9, 0x000000d9, },
  181. { 0x1c5aa0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  182. { 0x1c5aa4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  183. { 0x1c5aa8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  184. { 0x1c5aac, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  185. { 0x1c5ab0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  186. { 0x1c5ab4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  187. { 0x1c5ab8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  188. { 0x1c5abc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  189. { 0x1c5ac0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  190. { 0x1c5ac4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  191. { 0x1c5ac8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  192. { 0x1c5acc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  193. { 0x1c5ad0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  194. { 0x1c5ad4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  195. { 0x1c5ad8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  196. { 0x1c5adc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  197. { 0x1c5ae0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  198. { 0x1c5ae4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  199. { 0x1c5ae8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  200. { 0x1c5aec, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  201. { 0x1c5af0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  202. { 0x1c5af4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  203. { 0x1c5af8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  204. { 0x1c5afc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
  205. { 0x1c5b00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  206. { 0x1c5b04, 0x00000001, 0x00000001, 0x00000001, 0x00000001, },
  207. { 0x1c5b08, 0x00000002, 0x00000002, 0x00000002, 0x00000002, },
  208. { 0x1c5b0c, 0x00000003, 0x00000003, 0x00000003, 0x00000003, },
  209. { 0x1c5b10, 0x00000004, 0x00000004, 0x00000004, 0x00000004, },
  210. { 0x1c5b14, 0x00000005, 0x00000005, 0x00000005, 0x00000005, },
  211. { 0x1c5b18, 0x00000008, 0x00000008, 0x00000008, 0x00000008, },
  212. { 0x1c5b1c, 0x00000009, 0x00000009, 0x00000009, 0x00000009, },
  213. { 0x1c5b20, 0x0000000a, 0x0000000a, 0x0000000a, 0x0000000a, },
  214. { 0x1c5b24, 0x0000000b, 0x0000000b, 0x0000000b, 0x0000000b, },
  215. { 0x1c5b28, 0x0000000c, 0x0000000c, 0x0000000c, 0x0000000c, },
  216. { 0x1c5b2c, 0x0000000d, 0x0000000d, 0x0000000d, 0x0000000d, },
  217. { 0x1c5b30, 0x00000010, 0x00000010, 0x00000010, 0x00000010, },
  218. { 0x1c5b34, 0x00000011, 0x00000011, 0x00000011, 0x00000011, },
  219. { 0x1c5b38, 0x00000012, 0x00000012, 0x00000012, 0x00000012, },
  220. { 0x1c5b3c, 0x00000013, 0x00000013, 0x00000013, 0x00000013, },
  221. { 0x1c5b40, 0x00000014, 0x00000014, 0x00000014, 0x00000014, },
  222. { 0x1c5b44, 0x00000015, 0x00000015, 0x00000015, 0x00000015, },
  223. { 0x1c5b48, 0x00000018, 0x00000018, 0x00000018, 0x00000018, },
  224. { 0x1c5b4c, 0x00000019, 0x00000019, 0x00000019, 0x00000019, },
  225. { 0x1c5b50, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a, },
  226. { 0x1c5b54, 0x0000001b, 0x0000001b, 0x0000001b, 0x0000001b, },
  227. { 0x1c5b58, 0x0000001c, 0x0000001c, 0x0000001c, 0x0000001c, },
  228. { 0x1c5b5c, 0x0000001d, 0x0000001d, 0x0000001d, 0x0000001d, },
  229. { 0x1c5b60, 0x00000020, 0x00000020, 0x00000020, 0x00000020, },
  230. { 0x1c5b64, 0x00000021, 0x00000021, 0x00000021, 0x00000021, },
  231. { 0x1c5b68, 0x00000022, 0x00000022, 0x00000022, 0x00000022, },
  232. { 0x1c5b6c, 0x00000023, 0x00000023, 0x00000023, 0x00000023, },
  233. { 0x1c5b70, 0x00000024, 0x00000024, 0x00000024, 0x00000024, },
  234. { 0x1c5b74, 0x00000025, 0x00000025, 0x00000025, 0x00000025, },
  235. { 0x1c5b78, 0x00000028, 0x00000028, 0x00000028, 0x00000028, },
  236. { 0x1c5b7c, 0x00000029, 0x00000029, 0x00000029, 0x00000029, },
  237. { 0x1c5b80, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, },
  238. { 0x1c5b84, 0x0000002b, 0x0000002b, 0x0000002b, 0x0000002b, },
  239. { 0x1c5b88, 0x0000002c, 0x0000002c, 0x0000002c, 0x0000002c, },
  240. { 0x1c5b8c, 0x0000002d, 0x0000002d, 0x0000002d, 0x0000002d, },
  241. { 0x1c5b90, 0x00000030, 0x00000030, 0x00000030, 0x00000030, },
  242. { 0x1c5b94, 0x00000031, 0x00000031, 0x00000031, 0x00000031, },
  243. { 0x1c5b98, 0x00000032, 0x00000032, 0x00000032, 0x00000032, },
  244. { 0x1c5b9c, 0x00000033, 0x00000033, 0x00000033, 0x00000033, },
  245. { 0x1c5ba0, 0x00000034, 0x00000034, 0x00000034, 0x00000034, },
  246. { 0x1c5ba4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  247. { 0x1c5ba8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  248. { 0x1c5bac, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  249. { 0x1c5bb0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  250. { 0x1c5bb4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  251. { 0x1c5bb8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  252. { 0x1c5bbc, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  253. { 0x1c5bc0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  254. { 0x1c5bc4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  255. { 0x1c5bc8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  256. { 0x1c5bcc, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  257. { 0x1c5bd0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  258. { 0x1c5bd4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  259. { 0x1c5bd8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  260. { 0x1c5bdc, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  261. { 0x1c5be0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  262. { 0x1c5be4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  263. { 0x1c5be8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  264. { 0x1c5bec, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  265. { 0x1c5bf0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  266. { 0x1c5bf4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
  267. { 0x1c5bf8, 0x00000010, 0x00000010, 0x00000010, 0x00000010, },
  268. { 0x1c5bfc, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a, },
  269. { 0x1c5c00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  270. { 0x1c5c0c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  271. { 0x1c5c10, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  272. { 0x1c5c14, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  273. { 0x1c5c18, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  274. { 0x1c5c1c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  275. { 0x1c5c20, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  276. { 0x1c5c24, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  277. { 0x1c5c28, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  278. { 0x1c5c2c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  279. { 0x1c5c30, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  280. { 0x1c5c34, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  281. { 0x1c5c38, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  282. { 0x1c5c3c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  283. { 0x1c5cf0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  284. { 0x1c5cf4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  285. { 0x1c5cf8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  286. { 0x1c5cfc, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  287. { 0x1c6200, 0x00000008, 0x00000008, 0x0000000e, 0x0000000e, },
  288. { 0x1c6204, 0x00000440, 0x00000440, 0x00000440, 0x00000440, },
  289. { 0x1c6208, 0xd6be4788, 0xd6be4788, 0xd03e4788, 0xd03e4788, },
  290. { 0x1c620c, 0x012e8160, 0x012e8160, 0x012a8160, 0x012a8160, },
  291. { 0x1c6210, 0x40806333, 0x40806333, 0x40806333, 0x40806333, },
  292. { 0x1c6214, 0x00106c10, 0x00106c10, 0x00106c10, 0x00106c10, },
  293. { 0x1c6218, 0x009c4060, 0x009c4060, 0x009c4060, 0x009c4060, },
  294. { 0x1c621c, 0x1883800a, 0x1883800a, 0x1883800a, 0x1883800a, },
  295. { 0x1c6220, 0x018830c6, 0x018830c6, 0x018830c6, 0x018830c6, },
  296. { 0x1c6224, 0x00000400, 0x00000400, 0x00000400, 0x00000400, },
  297. { 0x1c6228, 0x000009b5, 0x000009b5, 0x000009b5, 0x000009b5, },
  298. { 0x1c622c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  299. { 0x1c6230, 0x00000108, 0x00000210, 0x00000210, 0x00000108, },
  300. { 0x1c6234, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
  301. { 0x1c6238, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
  302. { 0x1c623c, 0x13c889af, 0x13c889af, 0x13c889af, 0x13c889af, },
  303. { 0x1c6240, 0x38490a20, 0x38490a20, 0x38490a20, 0x38490a20, },
  304. { 0x1c6244, 0x00007bb6, 0x00007bb6, 0x00007bb6, 0x00007bb6, },
  305. { 0x1c6248, 0x0fff3ffc, 0x0fff3ffc, 0x0fff3ffc, 0x0fff3ffc, },
  306. { 0x1c624c, 0x00000001, 0x00000001, 0x00000001, 0x00000001, },
  307. { 0x1c6250, 0x0000a000, 0x0000a000, 0x0000a000, 0x0000a000, },
  308. { 0x1c6254, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  309. { 0x1c6258, 0x0cc75380, 0x0cc75380, 0x0cc75380, 0x0cc75380, },
  310. { 0x1c625c, 0x0f0f0f01, 0x0f0f0f01, 0x0f0f0f01, 0x0f0f0f01, },
  311. { 0x1c6260, 0xdfa91f01, 0xdfa91f01, 0xdfa91f01, 0xdfa91f01, },
  312. { 0x1c6264, 0x00418a11, 0x00418a11, 0x00418a11, 0x00418a11, },
  313. { 0x1c6268, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  314. { 0x1c626c, 0x09249126, 0x09249126, 0x09249126, 0x09249126, },
  315. { 0x1c6274, 0x0a1a9caa, 0x0a1a9caa, 0x0a1a7caa, 0x0a1a7caa, },
  316. { 0x1c6278, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, },
  317. { 0x1c627c, 0x051701ce, 0x051701ce, 0x051701ce, 0x051701ce, },
  318. { 0x1c6300, 0x18010000, 0x18010000, 0x18010000, 0x18010000, },
  319. { 0x1c6304, 0x30032602, 0x30032602, 0x2e032402, 0x2e032402, },
  320. { 0x1c6308, 0x48073e06, 0x48073e06, 0x4a0a3c06, 0x4a0a3c06, },
  321. { 0x1c630c, 0x560b4c0a, 0x560b4c0a, 0x621a540b, 0x621a540b, },
  322. { 0x1c6310, 0x641a600f, 0x641a600f, 0x764f6c1b, 0x764f6c1b, },
  323. { 0x1c6314, 0x7a4f6e1b, 0x7a4f6e1b, 0x845b7a5a, 0x845b7a5a, },
  324. { 0x1c6318, 0x8c5b7e5a, 0x8c5b7e5a, 0x950f8ccf, 0x950f8ccf, },
  325. { 0x1c631c, 0x9d0f96cf, 0x9d0f96cf, 0xa5cf9b4f, 0xa5cf9b4f, },
  326. { 0x1c6320, 0xb51fa69f, 0xb51fa69f, 0xbddfaf1f, 0xbddfaf1f, },
  327. { 0x1c6324, 0xcb3fbd07, 0xcb3fbcbf, 0xd1ffc93f, 0xd1ffc93f, },
  328. { 0x1c6328, 0x0000d7bf, 0x0000d7bf, 0x00000000, 0x00000000, },
  329. { 0x1c632c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  330. { 0x1c6330, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  331. { 0x1c6334, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  332. { 0x1c6338, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  333. { 0x1c633c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  334. { 0x1c6340, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  335. { 0x1c6344, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  336. { 0x1c6348, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, },
  337. { 0x1c634c, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, },
  338. { 0x1c6350, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, },
  339. { 0x1c6354, 0x0003ffff, 0x0003ffff, 0x0003ffff, 0x0003ffff, },
  340. { 0x1c6358, 0x79a8aa1f, 0x79a8aa1f, 0x79a8aa1f, 0x79a8aa1f, },
  341. { 0x1c6388, 0x08000000, 0x08000000, 0x08000000, 0x08000000, },
  342. { 0x1c638c, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
  343. { 0x1c6390, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
  344. { 0x1c6394, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, },
  345. { 0x1c6398, 0x000001ce, 0x000001ce, 0x000001ce, 0x000001ce, },
  346. { 0x1c639c, 0x00000007, 0x00000007, 0x00000007, 0x00000007, },
  347. { 0x1c63a0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  348. { 0x1c63a4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  349. { 0x1c63a8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  350. { 0x1c63ac, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  351. { 0x1c63b0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  352. { 0x1c63b4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  353. { 0x1c63b8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  354. { 0x1c63bc, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  355. { 0x1c63c0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  356. { 0x1c63c4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  357. { 0x1c63c8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  358. { 0x1c63cc, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
  359. { 0x1c63d0, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
  360. { 0x1c63d4, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
  361. { 0x1c63d8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
  362. { 0x1c63dc, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, },
  363. { 0x1c63e0, 0x000000c0, 0x000000c0, 0x000000c0, 0x000000c0, },
  364. { 0x1c6848, 0x00180a65, 0x00180a65, 0x00180a68, 0x00180a68, },
  365. { 0x1c6920, 0x0510001c, 0x0510001c, 0x0510001c, 0x0510001c, },
  366. { 0x1c6960, 0x00009b40, 0x00009b40, 0x00009b40, 0x00009b40, },
  367. { 0x1c720c, 0x012e8160, 0x012e8160, 0x012a8160, 0x012a8160, },
  368. { 0x1c726c, 0x09249126, 0x09249126, 0x09249126, 0x09249126, },
  369. { 0x1c7848, 0x00180a65, 0x00180a65, 0x00180a68, 0x00180a68, },
  370. { 0x1c7920, 0x0510001c, 0x0510001c, 0x0510001c, 0x0510001c, },
  371. { 0x1c7960, 0x00009b40, 0x00009b40, 0x00009b40, 0x00009b40, },
  372. { 0x1c820c, 0x012e8160, 0x012e8160, 0x012a8160, 0x012a8160, },
  373. { 0x1c826c, 0x09249126, 0x09249126, 0x09249126, 0x09249126, },
  374. /* { 0x1c8864, 0x0001ce00, 0x0001ce00, 0x0001ce00, 0x0001ce00, }, */
  375. { 0x1c8864, 0x0001c600, 0x0001c600, 0x0001c600, 0x0001c600, },
  376. { 0x1c895c, 0x004b6a8e, 0x004b6a8e, 0x004b6a8e, 0x004b6a8e, },
  377. { 0x1c8968, 0x000003ce, 0x000003ce, 0x000003ce, 0x000003ce, },
  378. { 0x1c89bc, 0x00181400, 0x00181400, 0x00181400, 0x00181400, },
  379. { 0x1c9270, 0x00820820, 0x00820820, 0x00820820, 0x00820820, },
  380. { 0x1c935c, 0x066c420f, 0x066c420f, 0x066c420f, 0x066c420f, },
  381. { 0x1c9360, 0x0f282207, 0x0f282207, 0x0f282207, 0x0f282207, },
  382. { 0x1c9364, 0x17601685, 0x17601685, 0x17601685, 0x17601685, },
  383. { 0x1c9368, 0x1f801104, 0x1f801104, 0x1f801104, 0x1f801104, },
  384. { 0x1c936c, 0x37a00c03, 0x37a00c03, 0x37a00c03, 0x37a00c03, },
  385. { 0x1c9370, 0x3fc40883, 0x3fc40883, 0x3fc40883, 0x3fc40883, },
  386. { 0x1c9374, 0x57c00803, 0x57c00803, 0x57c00803, 0x57c00803, },
  387. { 0x1c9378, 0x5fd80682, 0x5fd80682, 0x5fd80682, 0x5fd80682, },
  388. { 0x1c937c, 0x7fe00482, 0x7fe00482, 0x7fe00482, 0x7fe00482, },
  389. { 0x1c9380, 0x7f3c7bba, 0x7f3c7bba, 0x7f3c7bba, 0x7f3c7bba, },
  390. { 0x1c9384, 0xf3307ff0, 0xf3307ff0, 0xf3307ff0, 0xf3307ff0, }
  391. };
  392. /*
  393. * look up a certain register in ar5416_phy_init[] and return the init. value
  394. * for the band and bandwidth given. Return 0 if register address not found.
  395. */
  396. static u32 ar9170_get_default_phy_reg_val(u32 reg, bool is_2ghz, bool is_40mhz)
  397. {
  398. unsigned int i;
  399. for (i = 0; i < ARRAY_SIZE(ar5416_phy_init); i++) {
  400. if (ar5416_phy_init[i].reg != reg)
  401. continue;
  402. if (is_2ghz) {
  403. if (is_40mhz)
  404. return ar5416_phy_init[i]._2ghz_40;
  405. else
  406. return ar5416_phy_init[i]._2ghz_20;
  407. } else {
  408. if (is_40mhz)
  409. return ar5416_phy_init[i]._5ghz_40;
  410. else
  411. return ar5416_phy_init[i]._5ghz_20;
  412. }
  413. }
  414. return 0;
  415. }
  416. /*
  417. * initialize some phy regs from eeprom values in modal_header[]
  418. * acc. to band and bandwith
  419. */
  420. static int ar9170_init_phy_from_eeprom(struct ar9170 *ar,
  421. bool is_2ghz, bool is_40mhz)
  422. {
  423. static const u8 xpd2pd[16] = {
  424. 0x2, 0x2, 0x2, 0x1, 0x2, 0x2, 0x6, 0x2,
  425. 0x2, 0x3, 0x7, 0x2, 0xB, 0x2, 0x2, 0x2
  426. };
  427. u32 defval, newval;
  428. /* pointer to the modal_header acc. to band */
  429. struct ar9170_eeprom_modal *m = &ar->eeprom.modal_header[is_2ghz];
  430. ar9170_regwrite_begin(ar);
  431. /* ant common control (index 0) */
  432. newval = le32_to_cpu(m->antCtrlCommon);
  433. ar9170_regwrite(0x1c5964, newval);
  434. /* ant control chain 0 (index 1) */
  435. newval = le32_to_cpu(m->antCtrlChain[0]);
  436. ar9170_regwrite(0x1c5960, newval);
  437. /* ant control chain 2 (index 2) */
  438. newval = le32_to_cpu(m->antCtrlChain[1]);
  439. ar9170_regwrite(0x1c7960, newval);
  440. /* SwSettle (index 3) */
  441. if (!is_40mhz) {
  442. defval = ar9170_get_default_phy_reg_val(0x1c5844,
  443. is_2ghz, is_40mhz);
  444. newval = (defval & ~0x3f80) |
  445. ((m->switchSettling & 0x7f) << 7);
  446. ar9170_regwrite(0x1c5844, newval);
  447. }
  448. /* adcDesired, pdaDesired (index 4) */
  449. defval = ar9170_get_default_phy_reg_val(0x1c5850, is_2ghz, is_40mhz);
  450. newval = (defval & ~0xffff) | ((u8)m->pgaDesiredSize << 8) |
  451. ((u8)m->adcDesiredSize);
  452. ar9170_regwrite(0x1c5850, newval);
  453. /* TxEndToXpaOff, TxFrameToXpaOn (index 5) */
  454. defval = ar9170_get_default_phy_reg_val(0x1c5834, is_2ghz, is_40mhz);
  455. newval = (m->txEndToXpaOff << 24) | (m->txEndToXpaOff << 16) |
  456. (m->txFrameToXpaOn << 8) | m->txFrameToXpaOn;
  457. ar9170_regwrite(0x1c5834, newval);
  458. /* TxEndToRxOn (index 6) */
  459. defval = ar9170_get_default_phy_reg_val(0x1c5828, is_2ghz, is_40mhz);
  460. newval = (defval & ~0xff0000) | (m->txEndToRxOn << 16);
  461. ar9170_regwrite(0x1c5828, newval);
  462. /* thresh62 (index 7) */
  463. defval = ar9170_get_default_phy_reg_val(0x1c8864, is_2ghz, is_40mhz);
  464. newval = (defval & ~0x7f000) | (m->thresh62 << 12);
  465. ar9170_regwrite(0x1c8864, newval);
  466. /* tx/rx attenuation chain 0 (index 8) */
  467. defval = ar9170_get_default_phy_reg_val(0x1c5848, is_2ghz, is_40mhz);
  468. newval = (defval & ~0x3f000) | ((m->txRxAttenCh[0] & 0x3f) << 12);
  469. ar9170_regwrite(0x1c5848, newval);
  470. /* tx/rx attenuation chain 2 (index 9) */
  471. defval = ar9170_get_default_phy_reg_val(0x1c7848, is_2ghz, is_40mhz);
  472. newval = (defval & ~0x3f000) | ((m->txRxAttenCh[1] & 0x3f) << 12);
  473. ar9170_regwrite(0x1c7848, newval);
  474. /* tx/rx margin chain 0 (index 10) */
  475. defval = ar9170_get_default_phy_reg_val(0x1c620c, is_2ghz, is_40mhz);
  476. newval = (defval & ~0xfc0000) | ((m->rxTxMarginCh[0] & 0x3f) << 18);
  477. /* bsw margin chain 0 for 5GHz only */
  478. if (!is_2ghz)
  479. newval = (newval & ~0x3c00) | ((m->bswMargin[0] & 0xf) << 10);
  480. ar9170_regwrite(0x1c620c, newval);
  481. /* tx/rx margin chain 2 (index 11) */
  482. defval = ar9170_get_default_phy_reg_val(0x1c820c, is_2ghz, is_40mhz);
  483. newval = (defval & ~0xfc0000) | ((m->rxTxMarginCh[1] & 0x3f) << 18);
  484. ar9170_regwrite(0x1c820c, newval);
  485. /* iqCall, iqCallq chain 0 (index 12) */
  486. defval = ar9170_get_default_phy_reg_val(0x1c5920, is_2ghz, is_40mhz);
  487. newval = (defval & ~0x7ff) | (((u8)m->iqCalICh[0] & 0x3f) << 5) |
  488. ((u8)m->iqCalQCh[0] & 0x1f);
  489. ar9170_regwrite(0x1c5920, newval);
  490. /* iqCall, iqCallq chain 2 (index 13) */
  491. defval = ar9170_get_default_phy_reg_val(0x1c7920, is_2ghz, is_40mhz);
  492. newval = (defval & ~0x7ff) | (((u8)m->iqCalICh[1] & 0x3f) << 5) |
  493. ((u8)m->iqCalQCh[1] & 0x1f);
  494. ar9170_regwrite(0x1c7920, newval);
  495. /* xpd gain mask (index 14) */
  496. defval = ar9170_get_default_phy_reg_val(0x1c6258, is_2ghz, is_40mhz);
  497. newval = (defval & ~0xf0000) | (xpd2pd[m->xpdGain & 0xf] << 16);
  498. ar9170_regwrite(0x1c6258, newval);
  499. ar9170_regwrite_finish();
  500. return ar9170_regwrite_result();
  501. }
  502. int ar9170_init_phy(struct ar9170 *ar, enum ieee80211_band band)
  503. {
  504. int i, err;
  505. u32 val;
  506. bool is_2ghz = band == IEEE80211_BAND_2GHZ;
  507. bool is_40mhz = conf_is_ht40(&ar->hw->conf);
  508. ar9170_regwrite_begin(ar);
  509. for (i = 0; i < ARRAY_SIZE(ar5416_phy_init); i++) {
  510. if (is_40mhz) {
  511. if (is_2ghz)
  512. val = ar5416_phy_init[i]._2ghz_40;
  513. else
  514. val = ar5416_phy_init[i]._5ghz_40;
  515. } else {
  516. if (is_2ghz)
  517. val = ar5416_phy_init[i]._2ghz_20;
  518. else
  519. val = ar5416_phy_init[i]._5ghz_20;
  520. }
  521. ar9170_regwrite(ar5416_phy_init[i].reg, val);
  522. }
  523. ar9170_regwrite_finish();
  524. err = ar9170_regwrite_result();
  525. if (err)
  526. return err;
  527. err = ar9170_init_phy_from_eeprom(ar, is_2ghz, is_40mhz);
  528. if (err)
  529. return err;
  530. err = ar9170_init_power_cal(ar);
  531. if (err)
  532. return err;
  533. /* XXX: remove magic! */
  534. if (is_2ghz)
  535. err = ar9170_write_reg(ar, 0x1d4014, 0x5163);
  536. else
  537. err = ar9170_write_reg(ar, 0x1d4014, 0x5143);
  538. return err;
  539. }
  540. struct ar9170_rf_init {
  541. u32 reg, _5ghz, _2ghz;
  542. };
  543. static struct ar9170_rf_init ar9170_rf_init[] = {
  544. /* bank 0 */
  545. { 0x1c58b0, 0x1e5795e5, 0x1e5795e5},
  546. { 0x1c58e0, 0x02008020, 0x02008020},
  547. /* bank 1 */
  548. { 0x1c58b0, 0x02108421, 0x02108421},
  549. { 0x1c58ec, 0x00000008, 0x00000008},
  550. /* bank 2 */
  551. { 0x1c58b0, 0x0e73ff17, 0x0e73ff17},
  552. { 0x1c58e0, 0x00000420, 0x00000420},
  553. /* bank 3 */
  554. { 0x1c58f0, 0x01400018, 0x01c00018},
  555. /* bank 4 */
  556. { 0x1c58b0, 0x000001a1, 0x000001a1},
  557. { 0x1c58e8, 0x00000001, 0x00000001},
  558. /* bank 5 */
  559. { 0x1c58b0, 0x00000013, 0x00000013},
  560. { 0x1c58e4, 0x00000002, 0x00000002},
  561. /* bank 6 */
  562. { 0x1c58b0, 0x00000000, 0x00000000},
  563. { 0x1c58b0, 0x00000000, 0x00000000},
  564. { 0x1c58b0, 0x00000000, 0x00000000},
  565. { 0x1c58b0, 0x00000000, 0x00000000},
  566. { 0x1c58b0, 0x00000000, 0x00000000},
  567. { 0x1c58b0, 0x00004000, 0x00004000},
  568. { 0x1c58b0, 0x00006c00, 0x00006c00},
  569. { 0x1c58b0, 0x00002c00, 0x00002c00},
  570. { 0x1c58b0, 0x00004800, 0x00004800},
  571. { 0x1c58b0, 0x00004000, 0x00004000},
  572. { 0x1c58b0, 0x00006000, 0x00006000},
  573. { 0x1c58b0, 0x00001000, 0x00001000},
  574. { 0x1c58b0, 0x00004000, 0x00004000},
  575. { 0x1c58b0, 0x00007c00, 0x00007c00},
  576. { 0x1c58b0, 0x00007c00, 0x00007c00},
  577. { 0x1c58b0, 0x00007c00, 0x00007c00},
  578. { 0x1c58b0, 0x00007c00, 0x00007c00},
  579. { 0x1c58b0, 0x00007c00, 0x00007c00},
  580. { 0x1c58b0, 0x00087c00, 0x00087c00},
  581. { 0x1c58b0, 0x00007c00, 0x00007c00},
  582. { 0x1c58b0, 0x00005400, 0x00005400},
  583. { 0x1c58b0, 0x00000c00, 0x00000c00},
  584. { 0x1c58b0, 0x00001800, 0x00001800},
  585. { 0x1c58b0, 0x00007c00, 0x00007c00},
  586. { 0x1c58b0, 0x00006c00, 0x00006c00},
  587. { 0x1c58b0, 0x00006c00, 0x00006c00},
  588. { 0x1c58b0, 0x00007c00, 0x00007c00},
  589. { 0x1c58b0, 0x00002c00, 0x00002c00},
  590. { 0x1c58b0, 0x00003c00, 0x00003c00},
  591. { 0x1c58b0, 0x00003800, 0x00003800},
  592. { 0x1c58b0, 0x00001c00, 0x00001c00},
  593. { 0x1c58b0, 0x00000800, 0x00000800},
  594. { 0x1c58b0, 0x00000408, 0x00000408},
  595. { 0x1c58b0, 0x00004c15, 0x00004c15},
  596. { 0x1c58b0, 0x00004188, 0x00004188},
  597. { 0x1c58b0, 0x0000201e, 0x0000201e},
  598. { 0x1c58b0, 0x00010408, 0x00010408},
  599. { 0x1c58b0, 0x00000801, 0x00000801},
  600. { 0x1c58b0, 0x00000c08, 0x00000c08},
  601. { 0x1c58b0, 0x0000181e, 0x0000181e},
  602. { 0x1c58b0, 0x00001016, 0x00001016},
  603. { 0x1c58b0, 0x00002800, 0x00002800},
  604. { 0x1c58b0, 0x00004010, 0x00004010},
  605. { 0x1c58b0, 0x0000081c, 0x0000081c},
  606. { 0x1c58b0, 0x00000115, 0x00000115},
  607. { 0x1c58b0, 0x00000015, 0x00000015},
  608. { 0x1c58b0, 0x00000066, 0x00000066},
  609. { 0x1c58b0, 0x0000001c, 0x0000001c},
  610. { 0x1c58b0, 0x00000000, 0x00000000},
  611. { 0x1c58b0, 0x00000004, 0x00000004},
  612. { 0x1c58b0, 0x00000015, 0x00000015},
  613. { 0x1c58b0, 0x0000001f, 0x0000001f},
  614. { 0x1c58e0, 0x00000000, 0x00000400},
  615. /* bank 7 */
  616. { 0x1c58b0, 0x000000a0, 0x000000a0},
  617. { 0x1c58b0, 0x00000000, 0x00000000},
  618. { 0x1c58b0, 0x00000040, 0x00000040},
  619. { 0x1c58f0, 0x0000001c, 0x0000001c},
  620. };
  621. static int ar9170_init_rf_banks_0_7(struct ar9170 *ar, bool band5ghz)
  622. {
  623. int err, i;
  624. ar9170_regwrite_begin(ar);
  625. for (i = 0; i < ARRAY_SIZE(ar9170_rf_init); i++)
  626. ar9170_regwrite(ar9170_rf_init[i].reg,
  627. band5ghz ? ar9170_rf_init[i]._5ghz
  628. : ar9170_rf_init[i]._2ghz);
  629. ar9170_regwrite_finish();
  630. err = ar9170_regwrite_result();
  631. if (err)
  632. printk(KERN_ERR "%s: rf init failed\n",
  633. wiphy_name(ar->hw->wiphy));
  634. return err;
  635. }
  636. static int ar9170_init_rf_bank4_pwr(struct ar9170 *ar, bool band5ghz,
  637. u32 freq, enum ar9170_bw bw)
  638. {
  639. int err;
  640. u32 d0, d1, td0, td1, fd0, fd1;
  641. u8 chansel;
  642. u8 refsel0 = 1, refsel1 = 0;
  643. u8 lf_synth = 0;
  644. switch (bw) {
  645. case AR9170_BW_40_ABOVE:
  646. freq += 10;
  647. break;
  648. case AR9170_BW_40_BELOW:
  649. freq -= 10;
  650. break;
  651. case AR9170_BW_20:
  652. break;
  653. case __AR9170_NUM_BW:
  654. BUG();
  655. }
  656. if (band5ghz) {
  657. if (freq % 10) {
  658. chansel = (freq - 4800) / 5;
  659. } else {
  660. chansel = ((freq - 4800) / 10) * 2;
  661. refsel0 = 0;
  662. refsel1 = 1;
  663. }
  664. chansel = byte_rev_table[chansel];
  665. } else {
  666. if (freq == 2484) {
  667. chansel = 10 + (freq - 2274) / 5;
  668. lf_synth = 1;
  669. } else
  670. chansel = 16 + (freq - 2272) / 5;
  671. chansel *= 4;
  672. chansel = byte_rev_table[chansel];
  673. }
  674. d1 = chansel;
  675. d0 = 0x21 |
  676. refsel0 << 3 |
  677. refsel1 << 2 |
  678. lf_synth << 1;
  679. td0 = d0 & 0x1f;
  680. td1 = d1 & 0x1f;
  681. fd0 = td1 << 5 | td0;
  682. td0 = (d0 >> 5) & 0x7;
  683. td1 = (d1 >> 5) & 0x7;
  684. fd1 = td1 << 5 | td0;
  685. ar9170_regwrite_begin(ar);
  686. ar9170_regwrite(0x1c58b0, fd0);
  687. ar9170_regwrite(0x1c58e8, fd1);
  688. ar9170_regwrite_finish();
  689. err = ar9170_regwrite_result();
  690. if (err)
  691. return err;
  692. msleep(10);
  693. return 0;
  694. }
  695. struct ar9170_phy_freq_params {
  696. u8 coeff_exp;
  697. u16 coeff_man;
  698. u8 coeff_exp_shgi;
  699. u16 coeff_man_shgi;
  700. };
  701. struct ar9170_phy_freq_entry {
  702. u16 freq;
  703. struct ar9170_phy_freq_params params[__AR9170_NUM_BW];
  704. };
  705. /* NB: must be in sync with channel tables in main! */
  706. static const struct ar9170_phy_freq_entry ar9170_phy_freq_params[] = {
  707. /*
  708. * freq,
  709. * 20MHz,
  710. * 40MHz (below),
  711. * 40Mhz (above),
  712. */
  713. { 2412, {
  714. { 3, 21737, 3, 19563, },
  715. { 3, 21827, 3, 19644, },
  716. { 3, 21647, 3, 19482, },
  717. } },
  718. { 2417, {
  719. { 3, 21692, 3, 19523, },
  720. { 3, 21782, 3, 19604, },
  721. { 3, 21602, 3, 19442, },
  722. } },
  723. { 2422, {
  724. { 3, 21647, 3, 19482, },
  725. { 3, 21737, 3, 19563, },
  726. { 3, 21558, 3, 19402, },
  727. } },
  728. { 2427, {
  729. { 3, 21602, 3, 19442, },
  730. { 3, 21692, 3, 19523, },
  731. { 3, 21514, 3, 19362, },
  732. } },
  733. { 2432, {
  734. { 3, 21558, 3, 19402, },
  735. { 3, 21647, 3, 19482, },
  736. { 3, 21470, 3, 19323, },
  737. } },
  738. { 2437, {
  739. { 3, 21514, 3, 19362, },
  740. { 3, 21602, 3, 19442, },
  741. { 3, 21426, 3, 19283, },
  742. } },
  743. { 2442, {
  744. { 3, 21470, 3, 19323, },
  745. { 3, 21558, 3, 19402, },
  746. { 3, 21382, 3, 19244, },
  747. } },
  748. { 2447, {
  749. { 3, 21426, 3, 19283, },
  750. { 3, 21514, 3, 19362, },
  751. { 3, 21339, 3, 19205, },
  752. } },
  753. { 2452, {
  754. { 3, 21382, 3, 19244, },
  755. { 3, 21470, 3, 19323, },
  756. { 3, 21295, 3, 19166, },
  757. } },
  758. { 2457, {
  759. { 3, 21339, 3, 19205, },
  760. { 3, 21426, 3, 19283, },
  761. { 3, 21252, 3, 19127, },
  762. } },
  763. { 2462, {
  764. { 3, 21295, 3, 19166, },
  765. { 3, 21382, 3, 19244, },
  766. { 3, 21209, 3, 19088, },
  767. } },
  768. { 2467, {
  769. { 3, 21252, 3, 19127, },
  770. { 3, 21339, 3, 19205, },
  771. { 3, 21166, 3, 19050, },
  772. } },
  773. { 2472, {
  774. { 3, 21209, 3, 19088, },
  775. { 3, 21295, 3, 19166, },
  776. { 3, 21124, 3, 19011, },
  777. } },
  778. { 2484, {
  779. { 3, 21107, 3, 18996, },
  780. { 3, 21192, 3, 19073, },
  781. { 3, 21022, 3, 18920, },
  782. } },
  783. { 4920, {
  784. { 4, 21313, 4, 19181, },
  785. { 4, 21356, 4, 19220, },
  786. { 4, 21269, 4, 19142, },
  787. } },
  788. { 4940, {
  789. { 4, 21226, 4, 19104, },
  790. { 4, 21269, 4, 19142, },
  791. { 4, 21183, 4, 19065, },
  792. } },
  793. { 4960, {
  794. { 4, 21141, 4, 19027, },
  795. { 4, 21183, 4, 19065, },
  796. { 4, 21098, 4, 18988, },
  797. } },
  798. { 4980, {
  799. { 4, 21056, 4, 18950, },
  800. { 4, 21098, 4, 18988, },
  801. { 4, 21014, 4, 18912, },
  802. } },
  803. { 5040, {
  804. { 4, 20805, 4, 18725, },
  805. { 4, 20846, 4, 18762, },
  806. { 4, 20764, 4, 18687, },
  807. } },
  808. { 5060, {
  809. { 4, 20723, 4, 18651, },
  810. { 4, 20764, 4, 18687, },
  811. { 4, 20682, 4, 18614, },
  812. } },
  813. { 5080, {
  814. { 4, 20641, 4, 18577, },
  815. { 4, 20682, 4, 18614, },
  816. { 4, 20601, 4, 18541, },
  817. } },
  818. { 5180, {
  819. { 4, 20243, 4, 18219, },
  820. { 4, 20282, 4, 18254, },
  821. { 4, 20204, 4, 18183, },
  822. } },
  823. { 5200, {
  824. { 4, 20165, 4, 18148, },
  825. { 4, 20204, 4, 18183, },
  826. { 4, 20126, 4, 18114, },
  827. } },
  828. { 5220, {
  829. { 4, 20088, 4, 18079, },
  830. { 4, 20126, 4, 18114, },
  831. { 4, 20049, 4, 18044, },
  832. } },
  833. { 5240, {
  834. { 4, 20011, 4, 18010, },
  835. { 4, 20049, 4, 18044, },
  836. { 4, 19973, 4, 17976, },
  837. } },
  838. { 5260, {
  839. { 4, 19935, 4, 17941, },
  840. { 4, 19973, 4, 17976, },
  841. { 4, 19897, 4, 17907, },
  842. } },
  843. { 5280, {
  844. { 4, 19859, 4, 17873, },
  845. { 4, 19897, 4, 17907, },
  846. { 4, 19822, 4, 17840, },
  847. } },
  848. { 5300, {
  849. { 4, 19784, 4, 17806, },
  850. { 4, 19822, 4, 17840, },
  851. { 4, 19747, 4, 17772, },
  852. } },
  853. { 5320, {
  854. { 4, 19710, 4, 17739, },
  855. { 4, 19747, 4, 17772, },
  856. { 4, 19673, 4, 17706, },
  857. } },
  858. { 5500, {
  859. { 4, 19065, 4, 17159, },
  860. { 4, 19100, 4, 17190, },
  861. { 4, 19030, 4, 17127, },
  862. } },
  863. { 5520, {
  864. { 4, 18996, 4, 17096, },
  865. { 4, 19030, 4, 17127, },
  866. { 4, 18962, 4, 17065, },
  867. } },
  868. { 5540, {
  869. { 4, 18927, 4, 17035, },
  870. { 4, 18962, 4, 17065, },
  871. { 4, 18893, 4, 17004, },
  872. } },
  873. { 5560, {
  874. { 4, 18859, 4, 16973, },
  875. { 4, 18893, 4, 17004, },
  876. { 4, 18825, 4, 16943, },
  877. } },
  878. { 5580, {
  879. { 4, 18792, 4, 16913, },
  880. { 4, 18825, 4, 16943, },
  881. { 4, 18758, 4, 16882, },
  882. } },
  883. { 5600, {
  884. { 4, 18725, 4, 16852, },
  885. { 4, 18758, 4, 16882, },
  886. { 4, 18691, 4, 16822, },
  887. } },
  888. { 5620, {
  889. { 4, 18658, 4, 16792, },
  890. { 4, 18691, 4, 16822, },
  891. { 4, 18625, 4, 16762, },
  892. } },
  893. { 5640, {
  894. { 4, 18592, 4, 16733, },
  895. { 4, 18625, 4, 16762, },
  896. { 4, 18559, 4, 16703, },
  897. } },
  898. { 5660, {
  899. { 4, 18526, 4, 16673, },
  900. { 4, 18559, 4, 16703, },
  901. { 4, 18493, 4, 16644, },
  902. } },
  903. { 5680, {
  904. { 4, 18461, 4, 16615, },
  905. { 4, 18493, 4, 16644, },
  906. { 4, 18428, 4, 16586, },
  907. } },
  908. { 5700, {
  909. { 4, 18396, 4, 16556, },
  910. { 4, 18428, 4, 16586, },
  911. { 4, 18364, 4, 16527, },
  912. } },
  913. { 5745, {
  914. { 4, 18252, 4, 16427, },
  915. { 4, 18284, 4, 16455, },
  916. { 4, 18220, 4, 16398, },
  917. } },
  918. { 5765, {
  919. { 4, 18189, 5, 32740, },
  920. { 4, 18220, 4, 16398, },
  921. { 4, 18157, 5, 32683, },
  922. } },
  923. { 5785, {
  924. { 4, 18126, 5, 32626, },
  925. { 4, 18157, 5, 32683, },
  926. { 4, 18094, 5, 32570, },
  927. } },
  928. { 5805, {
  929. { 4, 18063, 5, 32514, },
  930. { 4, 18094, 5, 32570, },
  931. { 4, 18032, 5, 32458, },
  932. } },
  933. { 5825, {
  934. { 4, 18001, 5, 32402, },
  935. { 4, 18032, 5, 32458, },
  936. { 4, 17970, 5, 32347, },
  937. } },
  938. { 5170, {
  939. { 4, 20282, 4, 18254, },
  940. { 4, 20321, 4, 18289, },
  941. { 4, 20243, 4, 18219, },
  942. } },
  943. { 5190, {
  944. { 4, 20204, 4, 18183, },
  945. { 4, 20243, 4, 18219, },
  946. { 4, 20165, 4, 18148, },
  947. } },
  948. { 5210, {
  949. { 4, 20126, 4, 18114, },
  950. { 4, 20165, 4, 18148, },
  951. { 4, 20088, 4, 18079, },
  952. } },
  953. { 5230, {
  954. { 4, 20049, 4, 18044, },
  955. { 4, 20088, 4, 18079, },
  956. { 4, 20011, 4, 18010, },
  957. } },
  958. };
  959. static const struct ar9170_phy_freq_params *
  960. ar9170_get_hw_dyn_params(struct ieee80211_channel *channel,
  961. enum ar9170_bw bw)
  962. {
  963. unsigned int chanidx = 0;
  964. u16 freq = 2412;
  965. if (channel) {
  966. chanidx = channel->hw_value;
  967. freq = channel->center_freq;
  968. }
  969. BUG_ON(chanidx >= ARRAY_SIZE(ar9170_phy_freq_params));
  970. BUILD_BUG_ON(__AR9170_NUM_BW != 3);
  971. WARN_ON(ar9170_phy_freq_params[chanidx].freq != freq);
  972. return &ar9170_phy_freq_params[chanidx].params[bw];
  973. }
  974. int ar9170_init_rf(struct ar9170 *ar)
  975. {
  976. const struct ar9170_phy_freq_params *freqpar;
  977. __le32 cmd[7];
  978. int err;
  979. err = ar9170_init_rf_banks_0_7(ar, false);
  980. if (err)
  981. return err;
  982. err = ar9170_init_rf_bank4_pwr(ar, false, 2412, AR9170_BW_20);
  983. if (err)
  984. return err;
  985. freqpar = ar9170_get_hw_dyn_params(NULL, AR9170_BW_20);
  986. cmd[0] = cpu_to_le32(2412 * 1000);
  987. cmd[1] = cpu_to_le32(0);
  988. cmd[2] = cpu_to_le32(1);
  989. cmd[3] = cpu_to_le32(freqpar->coeff_exp);
  990. cmd[4] = cpu_to_le32(freqpar->coeff_man);
  991. cmd[5] = cpu_to_le32(freqpar->coeff_exp_shgi);
  992. cmd[6] = cpu_to_le32(freqpar->coeff_man_shgi);
  993. /* RF_INIT echoes the command back to us */
  994. err = ar->exec_cmd(ar, AR9170_CMD_RF_INIT,
  995. sizeof(cmd), (u8 *)cmd,
  996. sizeof(cmd), (u8 *)cmd);
  997. if (err)
  998. return err;
  999. msleep(1000);
  1000. return ar9170_echo_test(ar, 0xaabbccdd);
  1001. }
  1002. static int ar9170_find_freq_idx(int nfreqs, u8 *freqs, u8 f)
  1003. {
  1004. int idx = nfreqs - 2;
  1005. while (idx >= 0) {
  1006. if (f >= freqs[idx])
  1007. return idx;
  1008. idx--;
  1009. }
  1010. return 0;
  1011. }
  1012. static s32 ar9170_interpolate_s32(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
  1013. {
  1014. /* nothing to interpolate, it's horizontal */
  1015. if (y2 == y1)
  1016. return y1;
  1017. /* check if we hit one of the edges */
  1018. if (x == x1)
  1019. return y1;
  1020. if (x == x2)
  1021. return y2;
  1022. /* x1 == x2 is bad, hopefully == x */
  1023. if (x2 == x1)
  1024. return y1;
  1025. return y1 + (((y2 - y1) * (x - x1)) / (x2 - x1));
  1026. }
  1027. static u8 ar9170_interpolate_u8(u8 x, u8 x1, u8 y1, u8 x2, u8 y2)
  1028. {
  1029. #define SHIFT 8
  1030. s32 y;
  1031. y = ar9170_interpolate_s32(x << SHIFT,
  1032. x1 << SHIFT, y1 << SHIFT,
  1033. x2 << SHIFT, y2 << SHIFT);
  1034. /*
  1035. * XXX: unwrap this expression
  1036. * Isn't it just DIV_ROUND_UP(y, 1<<SHIFT)?
  1037. * Can we rely on the compiler to optimise away the div?
  1038. */
  1039. return (y >> SHIFT) + ((y & (1<<(SHIFT-1))) >> (SHIFT - 1));
  1040. #undef SHIFT
  1041. }
  1042. static u8 ar9170_interpolate_val(u8 x, u8 *x_array, u8 *y_array)
  1043. {
  1044. int i;
  1045. for (i = 0; i < 3; i++)
  1046. if (x <= x_array[i + 1])
  1047. break;
  1048. return ar9170_interpolate_u8(x,
  1049. x_array[i],
  1050. y_array[i],
  1051. x_array[i + 1],
  1052. y_array[i + 1]);
  1053. }
  1054. static int ar9170_set_freq_cal_data(struct ar9170 *ar,
  1055. struct ieee80211_channel *channel)
  1056. {
  1057. u8 *cal_freq_pier;
  1058. u8 vpds[2][AR5416_PD_GAIN_ICEPTS];
  1059. u8 pwrs[2][AR5416_PD_GAIN_ICEPTS];
  1060. int chain, idx, i;
  1061. u32 phy_data = 0;
  1062. u8 f, tmp;
  1063. switch (channel->band) {
  1064. case IEEE80211_BAND_2GHZ:
  1065. f = channel->center_freq - 2300;
  1066. cal_freq_pier = ar->eeprom.cal_freq_pier_2G;
  1067. i = AR5416_NUM_2G_CAL_PIERS - 1;
  1068. break;
  1069. case IEEE80211_BAND_5GHZ:
  1070. f = (channel->center_freq - 4800) / 5;
  1071. cal_freq_pier = ar->eeprom.cal_freq_pier_5G;
  1072. i = AR5416_NUM_5G_CAL_PIERS - 1;
  1073. break;
  1074. default:
  1075. return -EINVAL;
  1076. break;
  1077. }
  1078. for (; i >= 0; i--) {
  1079. if (cal_freq_pier[i] != 0xff)
  1080. break;
  1081. }
  1082. if (i < 0)
  1083. return -EINVAL;
  1084. idx = ar9170_find_freq_idx(i, cal_freq_pier, f);
  1085. ar9170_regwrite_begin(ar);
  1086. for (chain = 0; chain < AR5416_MAX_CHAINS; chain++) {
  1087. for (i = 0; i < AR5416_PD_GAIN_ICEPTS; i++) {
  1088. struct ar9170_calibration_data_per_freq *cal_pier_data;
  1089. int j;
  1090. switch (channel->band) {
  1091. case IEEE80211_BAND_2GHZ:
  1092. cal_pier_data = &ar->eeprom.
  1093. cal_pier_data_2G[chain][idx];
  1094. break;
  1095. case IEEE80211_BAND_5GHZ:
  1096. cal_pier_data = &ar->eeprom.
  1097. cal_pier_data_5G[chain][idx];
  1098. break;
  1099. default:
  1100. return -EINVAL;
  1101. }
  1102. for (j = 0; j < 2; j++) {
  1103. vpds[j][i] = ar9170_interpolate_u8(f,
  1104. cal_freq_pier[idx],
  1105. cal_pier_data->vpd_pdg[j][i],
  1106. cal_freq_pier[idx + 1],
  1107. cal_pier_data[1].vpd_pdg[j][i]);
  1108. pwrs[j][i] = ar9170_interpolate_u8(f,
  1109. cal_freq_pier[idx],
  1110. cal_pier_data->pwr_pdg[j][i],
  1111. cal_freq_pier[idx + 1],
  1112. cal_pier_data[1].pwr_pdg[j][i]) / 2;
  1113. }
  1114. }
  1115. for (i = 0; i < 76; i++) {
  1116. if (i < 25) {
  1117. tmp = ar9170_interpolate_val(i, &pwrs[0][0],
  1118. &vpds[0][0]);
  1119. } else {
  1120. tmp = ar9170_interpolate_val(i - 12,
  1121. &pwrs[1][0],
  1122. &vpds[1][0]);
  1123. }
  1124. phy_data |= tmp << ((i & 3) << 3);
  1125. if ((i & 3) == 3) {
  1126. ar9170_regwrite(0x1c6280 + chain * 0x1000 +
  1127. (i & ~3), phy_data);
  1128. phy_data = 0;
  1129. }
  1130. }
  1131. for (i = 19; i < 32; i++)
  1132. ar9170_regwrite(0x1c6280 + chain * 0x1000 + (i << 2),
  1133. 0x0);
  1134. }
  1135. ar9170_regwrite_finish();
  1136. return ar9170_regwrite_result();
  1137. }
  1138. static u8 ar9170_get_max_edge_power(struct ar9170 *ar,
  1139. struct ar9170_calctl_edges edges[],
  1140. u32 freq)
  1141. {
  1142. int i;
  1143. u8 rc = AR5416_MAX_RATE_POWER;
  1144. u8 f;
  1145. if (freq < 3000)
  1146. f = freq - 2300;
  1147. else
  1148. f = (freq - 4800) / 5;
  1149. for (i = 0; i < AR5416_NUM_BAND_EDGES; i++) {
  1150. if (edges[i].channel == 0xff)
  1151. break;
  1152. if (f == edges[i].channel) {
  1153. /* exact freq match */
  1154. rc = edges[i].power_flags & ~AR9170_CALCTL_EDGE_FLAGS;
  1155. break;
  1156. }
  1157. if (i > 0 && f < edges[i].channel) {
  1158. if (f > edges[i - 1].channel &&
  1159. edges[i - 1].power_flags &
  1160. AR9170_CALCTL_EDGE_FLAGS) {
  1161. /* lower channel has the inband flag set */
  1162. rc = edges[i - 1].power_flags &
  1163. ~AR9170_CALCTL_EDGE_FLAGS;
  1164. }
  1165. break;
  1166. }
  1167. }
  1168. if (i == AR5416_NUM_BAND_EDGES) {
  1169. if (f > edges[i - 1].channel &&
  1170. edges[i - 1].power_flags & AR9170_CALCTL_EDGE_FLAGS) {
  1171. /* lower channel has the inband flag set */
  1172. rc = edges[i - 1].power_flags &
  1173. ~AR9170_CALCTL_EDGE_FLAGS;
  1174. }
  1175. }
  1176. return rc;
  1177. }
  1178. static u8 ar9170_get_heavy_clip(struct ar9170 *ar,
  1179. struct ar9170_calctl_edges edges[],
  1180. u32 freq, enum ar9170_bw bw)
  1181. {
  1182. u8 f;
  1183. int i;
  1184. u8 rc = 0;
  1185. if (freq < 3000)
  1186. f = freq - 2300;
  1187. else
  1188. f = (freq - 4800) / 5;
  1189. if (bw == AR9170_BW_40_BELOW || bw == AR9170_BW_40_ABOVE)
  1190. rc |= 0xf0;
  1191. for (i = 0; i < AR5416_NUM_BAND_EDGES; i++) {
  1192. if (edges[i].channel == 0xff)
  1193. break;
  1194. if (f == edges[i].channel) {
  1195. if (!(edges[i].power_flags & AR9170_CALCTL_EDGE_FLAGS))
  1196. rc |= 0x0f;
  1197. break;
  1198. }
  1199. }
  1200. return rc;
  1201. }
  1202. /*
  1203. * calculate the conformance test limits and the heavy clip parameter
  1204. * and apply them to ar->power* (derived from otus hal/hpmain.c, line 3706)
  1205. */
  1206. static void ar9170_calc_ctl(struct ar9170 *ar, u32 freq, enum ar9170_bw bw)
  1207. {
  1208. u8 ctl_grp; /* CTL group */
  1209. u8 ctl_idx; /* CTL index */
  1210. int i, j;
  1211. struct ctl_modes {
  1212. u8 ctl_mode;
  1213. u8 max_power;
  1214. u8 *pwr_cal_data;
  1215. int pwr_cal_len;
  1216. } *modes;
  1217. /*
  1218. * order is relevant in the mode_list_*: we fall back to the
  1219. * lower indices if any mode is missed in the EEPROM.
  1220. */
  1221. struct ctl_modes mode_list_2ghz[] = {
  1222. { CTL_11B, 0, ar->power_2G_cck, 4 },
  1223. { CTL_11G, 0, ar->power_2G_ofdm, 4 },
  1224. { CTL_2GHT20, 0, ar->power_2G_ht20, 8 },
  1225. { CTL_2GHT40, 0, ar->power_2G_ht40, 8 },
  1226. };
  1227. struct ctl_modes mode_list_5ghz[] = {
  1228. { CTL_11A, 0, ar->power_5G_leg, 4 },
  1229. { CTL_5GHT20, 0, ar->power_5G_ht20, 8 },
  1230. { CTL_5GHT40, 0, ar->power_5G_ht40, 8 },
  1231. };
  1232. int nr_modes;
  1233. #define EDGES(c, n) (ar->eeprom.ctl_data[c].control_edges[n])
  1234. ar->phy_heavy_clip = 0;
  1235. /*
  1236. * TODO: investigate the differences between OTUS'
  1237. * hpreg.c::zfHpGetRegulatoryDomain() and
  1238. * ath/regd.c::ath_regd_get_band_ctl() -
  1239. * e.g. for FCC3_WORLD the OTUS procedure
  1240. * always returns CTL_FCC, while the one in ath/ delivers
  1241. * CTL_ETSI for 2GHz and CTL_FCC for 5GHz.
  1242. */
  1243. ctl_grp = ath_regd_get_band_ctl(&ar->common.regulatory,
  1244. ar->hw->conf.channel->band);
  1245. /* ctl group not found - either invalid band (NO_CTL) or ww roaming */
  1246. if (ctl_grp == NO_CTL || ctl_grp == SD_NO_CTL)
  1247. ctl_grp = CTL_FCC;
  1248. if (ctl_grp != CTL_FCC)
  1249. /* skip CTL and heavy clip for CTL_MKK and CTL_ETSI */
  1250. return;
  1251. if (ar->hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
  1252. modes = mode_list_2ghz;
  1253. nr_modes = ARRAY_SIZE(mode_list_2ghz);
  1254. } else {
  1255. modes = mode_list_5ghz;
  1256. nr_modes = ARRAY_SIZE(mode_list_5ghz);
  1257. }
  1258. for (i = 0; i < nr_modes; i++) {
  1259. u8 c = ctl_grp | modes[i].ctl_mode;
  1260. for (ctl_idx = 0; ctl_idx < AR5416_NUM_CTLS; ctl_idx++)
  1261. if (c == ar->eeprom.ctl_index[ctl_idx])
  1262. break;
  1263. if (ctl_idx < AR5416_NUM_CTLS) {
  1264. int f_off = 0;
  1265. /* determine heav clip parameter from
  1266. the 11G edges array */
  1267. if (modes[i].ctl_mode == CTL_11G) {
  1268. ar->phy_heavy_clip =
  1269. ar9170_get_heavy_clip(ar,
  1270. EDGES(ctl_idx, 1),
  1271. freq, bw);
  1272. }
  1273. /* adjust freq for 40MHz */
  1274. if (modes[i].ctl_mode == CTL_2GHT40 ||
  1275. modes[i].ctl_mode == CTL_5GHT40) {
  1276. if (bw == AR9170_BW_40_BELOW)
  1277. f_off = -10;
  1278. else
  1279. f_off = 10;
  1280. }
  1281. modes[i].max_power =
  1282. ar9170_get_max_edge_power(ar, EDGES(ctl_idx, 1),
  1283. freq+f_off);
  1284. /*
  1285. * TODO: check if the regulatory max. power is
  1286. * controlled by cfg80211 for DFS
  1287. * (hpmain applies it to max_power itself for DFS freq)
  1288. */
  1289. } else {
  1290. /*
  1291. * Workaround in otus driver, hpmain.c, line 3906:
  1292. * if no data for 5GHT20 are found, take the
  1293. * legacy 5G value.
  1294. * We extend this here to fallback from any other *HT or
  1295. * 11G, too.
  1296. */
  1297. int k = i;
  1298. modes[i].max_power = AR5416_MAX_RATE_POWER;
  1299. while (k-- > 0) {
  1300. if (modes[k].max_power !=
  1301. AR5416_MAX_RATE_POWER) {
  1302. modes[i].max_power = modes[k].max_power;
  1303. break;
  1304. }
  1305. }
  1306. }
  1307. /* apply max power to pwr_cal_data (ar->power_*) */
  1308. for (j = 0; j < modes[i].pwr_cal_len; j++) {
  1309. modes[i].pwr_cal_data[j] = min(modes[i].pwr_cal_data[j],
  1310. modes[i].max_power);
  1311. }
  1312. }
  1313. if (ar->phy_heavy_clip & 0xf0) {
  1314. ar->power_2G_ht40[0]--;
  1315. ar->power_2G_ht40[1]--;
  1316. ar->power_2G_ht40[2]--;
  1317. }
  1318. if (ar->phy_heavy_clip & 0xf) {
  1319. ar->power_2G_ht20[0]++;
  1320. ar->power_2G_ht20[1]++;
  1321. ar->power_2G_ht20[2]++;
  1322. }
  1323. #undef EDGES
  1324. }
  1325. static int ar9170_set_power_cal(struct ar9170 *ar, u32 freq, enum ar9170_bw bw)
  1326. {
  1327. struct ar9170_calibration_target_power_legacy *ctpl;
  1328. struct ar9170_calibration_target_power_ht *ctph;
  1329. u8 *ctpres;
  1330. int ntargets;
  1331. int idx, i, n;
  1332. u8 ackpower, ackchains, f;
  1333. u8 pwr_freqs[AR5416_MAX_NUM_TGT_PWRS];
  1334. if (freq < 3000)
  1335. f = freq - 2300;
  1336. else
  1337. f = (freq - 4800)/5;
  1338. /*
  1339. * cycle through the various modes
  1340. *
  1341. * legacy modes first: 5G, 2G CCK, 2G OFDM
  1342. */
  1343. for (i = 0; i < 3; i++) {
  1344. switch (i) {
  1345. case 0: /* 5 GHz legacy */
  1346. ctpl = &ar->eeprom.cal_tgt_pwr_5G[0];
  1347. ntargets = AR5416_NUM_5G_TARGET_PWRS;
  1348. ctpres = ar->power_5G_leg;
  1349. break;
  1350. case 1: /* 2.4 GHz CCK */
  1351. ctpl = &ar->eeprom.cal_tgt_pwr_2G_cck[0];
  1352. ntargets = AR5416_NUM_2G_CCK_TARGET_PWRS;
  1353. ctpres = ar->power_2G_cck;
  1354. break;
  1355. case 2: /* 2.4 GHz OFDM */
  1356. ctpl = &ar->eeprom.cal_tgt_pwr_2G_ofdm[0];
  1357. ntargets = AR5416_NUM_2G_OFDM_TARGET_PWRS;
  1358. ctpres = ar->power_2G_ofdm;
  1359. break;
  1360. default:
  1361. BUG();
  1362. }
  1363. for (n = 0; n < ntargets; n++) {
  1364. if (ctpl[n].freq == 0xff)
  1365. break;
  1366. pwr_freqs[n] = ctpl[n].freq;
  1367. }
  1368. ntargets = n;
  1369. idx = ar9170_find_freq_idx(ntargets, pwr_freqs, f);
  1370. for (n = 0; n < 4; n++)
  1371. ctpres[n] = ar9170_interpolate_u8(
  1372. f,
  1373. ctpl[idx + 0].freq,
  1374. ctpl[idx + 0].power[n],
  1375. ctpl[idx + 1].freq,
  1376. ctpl[idx + 1].power[n]);
  1377. }
  1378. /*
  1379. * HT modes now: 5G HT20, 5G HT40, 2G CCK, 2G OFDM, 2G HT20, 2G HT40
  1380. */
  1381. for (i = 0; i < 4; i++) {
  1382. switch (i) {
  1383. case 0: /* 5 GHz HT 20 */
  1384. ctph = &ar->eeprom.cal_tgt_pwr_5G_ht20[0];
  1385. ntargets = AR5416_NUM_5G_TARGET_PWRS;
  1386. ctpres = ar->power_5G_ht20;
  1387. break;
  1388. case 1: /* 5 GHz HT 40 */
  1389. ctph = &ar->eeprom.cal_tgt_pwr_5G_ht40[0];
  1390. ntargets = AR5416_NUM_5G_TARGET_PWRS;
  1391. ctpres = ar->power_5G_ht40;
  1392. break;
  1393. case 2: /* 2.4 GHz HT 20 */
  1394. ctph = &ar->eeprom.cal_tgt_pwr_2G_ht20[0];
  1395. ntargets = AR5416_NUM_2G_OFDM_TARGET_PWRS;
  1396. ctpres = ar->power_2G_ht20;
  1397. break;
  1398. case 3: /* 2.4 GHz HT 40 */
  1399. ctph = &ar->eeprom.cal_tgt_pwr_2G_ht40[0];
  1400. ntargets = AR5416_NUM_2G_OFDM_TARGET_PWRS;
  1401. ctpres = ar->power_2G_ht40;
  1402. break;
  1403. default:
  1404. BUG();
  1405. }
  1406. for (n = 0; n < ntargets; n++) {
  1407. if (ctph[n].freq == 0xff)
  1408. break;
  1409. pwr_freqs[n] = ctph[n].freq;
  1410. }
  1411. ntargets = n;
  1412. idx = ar9170_find_freq_idx(ntargets, pwr_freqs, f);
  1413. for (n = 0; n < 8; n++)
  1414. ctpres[n] = ar9170_interpolate_u8(
  1415. f,
  1416. ctph[idx + 0].freq,
  1417. ctph[idx + 0].power[n],
  1418. ctph[idx + 1].freq,
  1419. ctph[idx + 1].power[n]);
  1420. }
  1421. /* calc. conformance test limits and apply to ar->power*[] */
  1422. ar9170_calc_ctl(ar, freq, bw);
  1423. /* set ACK/CTS TX power */
  1424. ar9170_regwrite_begin(ar);
  1425. if (ar->eeprom.tx_mask != 1)
  1426. ackchains = AR9170_TX_PHY_TXCHAIN_2;
  1427. else
  1428. ackchains = AR9170_TX_PHY_TXCHAIN_1;
  1429. if (freq < 3000)
  1430. ackpower = ar->power_2G_ofdm[0] & 0x3f;
  1431. else
  1432. ackpower = ar->power_5G_leg[0] & 0x3f;
  1433. ar9170_regwrite(0x1c3694, ackpower << 20 | ackchains << 26);
  1434. ar9170_regwrite(0x1c3bb4, ackpower << 5 | ackchains << 11 |
  1435. ackpower << 21 | ackchains << 27);
  1436. ar9170_regwrite_finish();
  1437. return ar9170_regwrite_result();
  1438. }
  1439. static int ar9170_calc_noise_dbm(u32 raw_noise)
  1440. {
  1441. if (raw_noise & 0x100)
  1442. return ~((raw_noise & 0x0ff) >> 1);
  1443. else
  1444. return (raw_noise & 0xff) >> 1;
  1445. }
  1446. int ar9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
  1447. enum ar9170_rf_init_mode rfi, enum ar9170_bw bw)
  1448. {
  1449. const struct ar9170_phy_freq_params *freqpar;
  1450. u32 cmd, tmp, offs;
  1451. __le32 vals[8];
  1452. int i, err;
  1453. bool bandswitch;
  1454. /* clear BB heavy clip enable */
  1455. err = ar9170_write_reg(ar, 0x1c59e0, 0x200);
  1456. if (err)
  1457. return err;
  1458. /* may be NULL at first setup */
  1459. if (ar->channel)
  1460. bandswitch = ar->channel->band != channel->band;
  1461. else
  1462. bandswitch = true;
  1463. /* HW workaround */
  1464. if (!ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] &&
  1465. channel->center_freq <= 2417)
  1466. bandswitch = true;
  1467. err = ar->exec_cmd(ar, AR9170_CMD_FREQ_START, 0, NULL, 0, NULL);
  1468. if (err)
  1469. return err;
  1470. if (rfi != AR9170_RFI_NONE || bandswitch) {
  1471. u32 val = 0x400;
  1472. if (rfi == AR9170_RFI_COLD)
  1473. val = 0x800;
  1474. /* warm/cold reset BB/ADDA */
  1475. err = ar9170_write_reg(ar, 0x1d4004, val);
  1476. if (err)
  1477. return err;
  1478. err = ar9170_write_reg(ar, 0x1d4004, 0x0);
  1479. if (err)
  1480. return err;
  1481. err = ar9170_init_phy(ar, channel->band);
  1482. if (err)
  1483. return err;
  1484. err = ar9170_init_rf_banks_0_7(ar,
  1485. channel->band == IEEE80211_BAND_5GHZ);
  1486. if (err)
  1487. return err;
  1488. cmd = AR9170_CMD_RF_INIT;
  1489. } else {
  1490. cmd = AR9170_CMD_FREQUENCY;
  1491. }
  1492. err = ar9170_init_rf_bank4_pwr(ar,
  1493. channel->band == IEEE80211_BAND_5GHZ,
  1494. channel->center_freq, bw);
  1495. if (err)
  1496. return err;
  1497. switch (bw) {
  1498. case AR9170_BW_20:
  1499. tmp = 0x240;
  1500. offs = 0;
  1501. break;
  1502. case AR9170_BW_40_BELOW:
  1503. tmp = 0x2c4;
  1504. offs = 3;
  1505. break;
  1506. case AR9170_BW_40_ABOVE:
  1507. tmp = 0x2d4;
  1508. offs = 1;
  1509. break;
  1510. default:
  1511. BUG();
  1512. return -ENOSYS;
  1513. }
  1514. if (ar->eeprom.tx_mask != 1)
  1515. tmp |= 0x100;
  1516. err = ar9170_write_reg(ar, 0x1c5804, tmp);
  1517. if (err)
  1518. return err;
  1519. err = ar9170_set_freq_cal_data(ar, channel);
  1520. if (err)
  1521. return err;
  1522. err = ar9170_set_power_cal(ar, channel->center_freq, bw);
  1523. if (err)
  1524. return err;
  1525. freqpar = ar9170_get_hw_dyn_params(channel, bw);
  1526. vals[0] = cpu_to_le32(channel->center_freq * 1000);
  1527. vals[1] = cpu_to_le32(conf_is_ht40(&ar->hw->conf));
  1528. vals[2] = cpu_to_le32(offs << 2 | 1);
  1529. vals[3] = cpu_to_le32(freqpar->coeff_exp);
  1530. vals[4] = cpu_to_le32(freqpar->coeff_man);
  1531. vals[5] = cpu_to_le32(freqpar->coeff_exp_shgi);
  1532. vals[6] = cpu_to_le32(freqpar->coeff_man_shgi);
  1533. vals[7] = cpu_to_le32(1000);
  1534. err = ar->exec_cmd(ar, cmd, sizeof(vals), (u8 *)vals,
  1535. sizeof(vals), (u8 *)vals);
  1536. if (err)
  1537. return err;
  1538. if (ar->phy_heavy_clip) {
  1539. err = ar9170_write_reg(ar, 0x1c59e0,
  1540. 0x200 | ar->phy_heavy_clip);
  1541. if (err) {
  1542. if (ar9170_nag_limiter(ar))
  1543. printk(KERN_ERR "%s: failed to set "
  1544. "heavy clip\n",
  1545. wiphy_name(ar->hw->wiphy));
  1546. }
  1547. }
  1548. for (i = 0; i < 2; i++) {
  1549. ar->noise[i] = ar9170_calc_noise_dbm(
  1550. (le32_to_cpu(vals[2 + i]) >> 19) & 0x1ff);
  1551. ar->noise[i + 2] = ar9170_calc_noise_dbm(
  1552. (le32_to_cpu(vals[5 + i]) >> 23) & 0x1ff);
  1553. }
  1554. ar->channel = channel;
  1555. return 0;
  1556. }