phy.c 57 KB

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