xref: /openbmc/linux/drivers/net/wireless/ath/carl9170/phy.c (revision f26e8817b235d8764363bffcc9cbfc61867371f2)
1319da621SChristian Lamparter /*
2319da621SChristian Lamparter  * Atheros CARL9170 driver
3319da621SChristian Lamparter  *
4319da621SChristian Lamparter  * PHY and RF code
5319da621SChristian Lamparter  *
6319da621SChristian Lamparter  * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7319da621SChristian Lamparter  *
8319da621SChristian Lamparter  * This program is free software; you can redistribute it and/or modify
9319da621SChristian Lamparter  * it under the terms of the GNU General Public License as published by
10319da621SChristian Lamparter  * the Free Software Foundation; either version 2 of the License, or
11319da621SChristian Lamparter  * (at your option) any later version.
12319da621SChristian Lamparter  *
13319da621SChristian Lamparter  * This program is distributed in the hope that it will be useful,
14319da621SChristian Lamparter  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15319da621SChristian Lamparter  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16319da621SChristian Lamparter  * GNU General Public License for more details.
17319da621SChristian Lamparter  *
18319da621SChristian Lamparter  * You should have received a copy of the GNU General Public License
19319da621SChristian Lamparter  * along with this program; see the file COPYING.  If not, see
20319da621SChristian Lamparter  * http://www.gnu.org/licenses/.
21319da621SChristian Lamparter  *
22319da621SChristian Lamparter  * This file incorporates work covered by the following copyright and
23319da621SChristian Lamparter  * permission notice:
24319da621SChristian Lamparter  *    Copyright (c) 2007-2008 Atheros Communications, Inc.
25319da621SChristian Lamparter  *
26319da621SChristian Lamparter  *    Permission to use, copy, modify, and/or distribute this software for any
27319da621SChristian Lamparter  *    purpose with or without fee is hereby granted, provided that the above
28319da621SChristian Lamparter  *    copyright notice and this permission notice appear in all copies.
29319da621SChristian Lamparter  *
30319da621SChristian Lamparter  *    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
31319da621SChristian Lamparter  *    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
32319da621SChristian Lamparter  *    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
33319da621SChristian Lamparter  *    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
34319da621SChristian Lamparter  *    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
35319da621SChristian Lamparter  *    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
36319da621SChristian Lamparter  *    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
37319da621SChristian Lamparter  */
38319da621SChristian Lamparter 
39319da621SChristian Lamparter #include <linux/bitrev.h>
40319da621SChristian Lamparter #include "carl9170.h"
41319da621SChristian Lamparter #include "cmd.h"
42319da621SChristian Lamparter #include "phy.h"
43319da621SChristian Lamparter 
carl9170_init_power_cal(struct ar9170 * ar)44319da621SChristian Lamparter static int carl9170_init_power_cal(struct ar9170 *ar)
45319da621SChristian Lamparter {
46319da621SChristian Lamparter 	carl9170_regwrite_begin(ar);
47319da621SChristian Lamparter 
48319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE_MAX, 0x7f);
49319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE1, 0x3f3f3f3f);
50319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE2, 0x3f3f3f3f);
51319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE3, 0x3f3f3f3f);
52319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE4, 0x3f3f3f3f);
53319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE5, 0x3f3f3f3f);
54319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE6, 0x3f3f3f3f);
55319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE7, 0x3f3f3f3f);
56319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE8, 0x3f3f3f3f);
57319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_POWER_TX_RATE9, 0x3f3f3f3f);
58319da621SChristian Lamparter 
59319da621SChristian Lamparter 	carl9170_regwrite_finish();
60319da621SChristian Lamparter 	return carl9170_regwrite_result();
61319da621SChristian Lamparter }
62319da621SChristian Lamparter 
63319da621SChristian Lamparter struct carl9170_phy_init {
64319da621SChristian Lamparter 	u32 reg, _5ghz_20, _5ghz_40, _2ghz_40, _2ghz_20;
65319da621SChristian Lamparter };
66319da621SChristian Lamparter 
67319da621SChristian Lamparter static struct carl9170_phy_init ar5416_phy_init[] = {
68319da621SChristian Lamparter 	{ 0x1c5800, 0x00000007, 0x00000007, 0x00000007, 0x00000007, },
69319da621SChristian Lamparter 	{ 0x1c5804, 0x00000300, 0x000003c4, 0x000003c4, 0x00000300, },
70319da621SChristian Lamparter 	{ 0x1c5808, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
71319da621SChristian Lamparter 	{ 0x1c580c, 0xad848e19, 0xad848e19, 0xad848e19, 0xad848e19, },
72319da621SChristian Lamparter 	{ 0x1c5810, 0x7d14e000, 0x7d14e000, 0x7d14e000, 0x7d14e000, },
73319da621SChristian Lamparter 	{ 0x1c5814, 0x9c0a9f6b, 0x9c0a9f6b, 0x9c0a9f6b, 0x9c0a9f6b, },
74319da621SChristian Lamparter 	{ 0x1c5818, 0x00000090, 0x00000090, 0x00000090, 0x00000090, },
75319da621SChristian Lamparter 	{ 0x1c581c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
76319da621SChristian Lamparter 	{ 0x1c5820, 0x02020200, 0x02020200, 0x02020200, 0x02020200, },
77319da621SChristian Lamparter 	{ 0x1c5824, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, },
78319da621SChristian Lamparter 	{ 0x1c5828, 0x0a020001, 0x0a020001, 0x0a020001, 0x0a020001, },
79319da621SChristian Lamparter 	{ 0x1c582c, 0x0000a000, 0x0000a000, 0x0000a000, 0x0000a000, },
80319da621SChristian Lamparter 	{ 0x1c5830, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
81319da621SChristian Lamparter 	{ 0x1c5834, 0x00000e0e, 0x00000e0e, 0x00000e0e, 0x00000e0e, },
82319da621SChristian Lamparter 	{ 0x1c5838, 0x00000007, 0x00000007, 0x00000007, 0x00000007, },
83319da621SChristian Lamparter 	{ 0x1c583c, 0x00200400, 0x00200400, 0x00200400, 0x00200400, },
84319da621SChristian Lamparter 	{ 0x1c5840, 0x206a002e, 0x206a002e, 0x206a002e, 0x206a002e, },
85319da621SChristian Lamparter 	{ 0x1c5844, 0x1372161e, 0x13721c1e, 0x13721c24, 0x137216a4, },
86319da621SChristian Lamparter 	{ 0x1c5848, 0x001a6a65, 0x001a6a65, 0x00197a68, 0x00197a68, },
87319da621SChristian Lamparter 	{ 0x1c584c, 0x1284233c, 0x1284233c, 0x1284233c, 0x1284233c, },
88c807666aSChristian Lamparter 	{ 0x1c5850, 0x6c48b4e4, 0x6d48b4e4, 0x6d48b0e4, 0x6c48b0e4, },
89319da621SChristian Lamparter 	{ 0x1c5854, 0x00000859, 0x00000859, 0x00000859, 0x00000859, },
90319da621SChristian Lamparter 	{ 0x1c5858, 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e, 0x7ec80d2e, },
91c807666aSChristian Lamparter 	{ 0x1c585c, 0x31395c5e, 0x3139605e, 0x3139605e, 0x31395c5e, },
92319da621SChristian Lamparter 	{ 0x1c5860, 0x0004dd10, 0x0004dd10, 0x0004dd20, 0x0004dd20, },
93c807666aSChristian Lamparter 	{ 0x1c5864, 0x0001c600, 0x0001c600, 0x0001c600, 0x0001c600, },
94319da621SChristian Lamparter 	{ 0x1c5868, 0x409a4190, 0x409a4190, 0x409a4190, 0x409a4190, },
95319da621SChristian Lamparter 	{ 0x1c586c, 0x050cb081, 0x050cb081, 0x050cb081, 0x050cb081, },
96319da621SChristian Lamparter 	{ 0x1c5900, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
97319da621SChristian Lamparter 	{ 0x1c5904, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
98319da621SChristian Lamparter 	{ 0x1c5908, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
99319da621SChristian Lamparter 	{ 0x1c590c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
100319da621SChristian Lamparter 	{ 0x1c5914, 0x000007d0, 0x000007d0, 0x00000898, 0x00000898, },
101319da621SChristian Lamparter 	{ 0x1c5918, 0x00000118, 0x00000230, 0x00000268, 0x00000134, },
102319da621SChristian Lamparter 	{ 0x1c591c, 0x10000fff, 0x10000fff, 0x10000fff, 0x10000fff, },
103319da621SChristian Lamparter 	{ 0x1c5920, 0x0510081c, 0x0510081c, 0x0510001c, 0x0510001c, },
104319da621SChristian Lamparter 	{ 0x1c5924, 0xd0058a15, 0xd0058a15, 0xd0058a15, 0xd0058a15, },
105319da621SChristian Lamparter 	{ 0x1c5928, 0x00000001, 0x00000001, 0x00000001, 0x00000001, },
106319da621SChristian Lamparter 	{ 0x1c592c, 0x00000004, 0x00000004, 0x00000004, 0x00000004, },
107319da621SChristian Lamparter 	{ 0x1c5934, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
108319da621SChristian Lamparter 	{ 0x1c5938, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
109319da621SChristian Lamparter 	{ 0x1c593c, 0x0000007f, 0x0000007f, 0x0000007f, 0x0000007f, },
110319da621SChristian Lamparter 	{ 0x1c5944, 0xdfb81020, 0xdfb81020, 0xdfb81020, 0xdfb81020, },
111319da621SChristian Lamparter 	{ 0x1c5948, 0x9280b212, 0x9280b212, 0x9280b212, 0x9280b212, },
112319da621SChristian Lamparter 	{ 0x1c594c, 0x00020028, 0x00020028, 0x00020028, 0x00020028, },
113319da621SChristian Lamparter 	{ 0x1c5954, 0x5d50e188, 0x5d50e188, 0x5d50e188, 0x5d50e188, },
114319da621SChristian Lamparter 	{ 0x1c5958, 0x00081fff, 0x00081fff, 0x00081fff, 0x00081fff, },
115319da621SChristian Lamparter 	{ 0x1c5960, 0x00009b40, 0x00009b40, 0x00009b40, 0x00009b40, },
116319da621SChristian Lamparter 	{ 0x1c5964, 0x00001120, 0x00001120, 0x00001120, 0x00001120, },
117319da621SChristian Lamparter 	{ 0x1c5970, 0x190fb515, 0x190fb515, 0x190fb515, 0x190fb515, },
118319da621SChristian Lamparter 	{ 0x1c5974, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
119319da621SChristian Lamparter 	{ 0x1c5978, 0x00000001, 0x00000001, 0x00000001, 0x00000001, },
120319da621SChristian Lamparter 	{ 0x1c597c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
121319da621SChristian Lamparter 	{ 0x1c5980, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
122319da621SChristian Lamparter 	{ 0x1c5984, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
123319da621SChristian Lamparter 	{ 0x1c5988, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
124319da621SChristian Lamparter 	{ 0x1c598c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
125319da621SChristian Lamparter 	{ 0x1c5990, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
126319da621SChristian Lamparter 	{ 0x1c5994, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
127319da621SChristian Lamparter 	{ 0x1c5998, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
128319da621SChristian Lamparter 	{ 0x1c599c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
129319da621SChristian Lamparter 	{ 0x1c59a0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
130319da621SChristian Lamparter 	{ 0x1c59a4, 0x00000007, 0x00000007, 0x00000007, 0x00000007, },
131319da621SChristian Lamparter 	{ 0x1c59a8, 0x001fff00, 0x001fff00, 0x001fff00, 0x001fff00, },
132319da621SChristian Lamparter 	{ 0x1c59ac, 0x006f00c4, 0x006f00c4, 0x006f00c4, 0x006f00c4, },
133319da621SChristian Lamparter 	{ 0x1c59b0, 0x03051000, 0x03051000, 0x03051000, 0x03051000, },
134319da621SChristian Lamparter 	{ 0x1c59b4, 0x00000820, 0x00000820, 0x00000820, 0x00000820, },
135c807666aSChristian Lamparter 	{ 0x1c59bc, 0x00181400, 0x00181400, 0x00181400, 0x00181400, },
136319da621SChristian Lamparter 	{ 0x1c59c0, 0x038919be, 0x038919be, 0x038919be, 0x038919be, },
137319da621SChristian Lamparter 	{ 0x1c59c4, 0x06336f77, 0x06336f77, 0x06336f77, 0x06336f77, },
138c807666aSChristian Lamparter 	{ 0x1c59c8, 0x6af6532c, 0x6af6532c, 0x6af6532c, 0x6af6532c, },
139319da621SChristian Lamparter 	{ 0x1c59cc, 0x08f186c8, 0x08f186c8, 0x08f186c8, 0x08f186c8, },
140319da621SChristian Lamparter 	{ 0x1c59d0, 0x00046384, 0x00046384, 0x00046384, 0x00046384, },
141319da621SChristian Lamparter 	{ 0x1c59d4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
142319da621SChristian Lamparter 	{ 0x1c59d8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
143319da621SChristian Lamparter 	{ 0x1c59dc, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
144319da621SChristian Lamparter 	{ 0x1c59e0, 0x00000200, 0x00000200, 0x00000200, 0x00000200, },
145319da621SChristian Lamparter 	{ 0x1c59e4, 0x64646464, 0x64646464, 0x64646464, 0x64646464, },
146319da621SChristian Lamparter 	{ 0x1c59e8, 0x3c787878, 0x3c787878, 0x3c787878, 0x3c787878, },
147319da621SChristian Lamparter 	{ 0x1c59ec, 0x000000aa, 0x000000aa, 0x000000aa, 0x000000aa, },
148319da621SChristian Lamparter 	{ 0x1c59f0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
149319da621SChristian Lamparter 	{ 0x1c59fc, 0x00001042, 0x00001042, 0x00001042, 0x00001042, },
150319da621SChristian Lamparter 	{ 0x1c5a00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
151319da621SChristian Lamparter 	{ 0x1c5a04, 0x00000040, 0x00000040, 0x00000040, 0x00000040, },
152319da621SChristian Lamparter 	{ 0x1c5a08, 0x00000080, 0x00000080, 0x00000080, 0x00000080, },
153319da621SChristian Lamparter 	{ 0x1c5a0c, 0x000001a1, 0x000001a1, 0x00000141, 0x00000141, },
154319da621SChristian Lamparter 	{ 0x1c5a10, 0x000001e1, 0x000001e1, 0x00000181, 0x00000181, },
155319da621SChristian Lamparter 	{ 0x1c5a14, 0x00000021, 0x00000021, 0x000001c1, 0x000001c1, },
156319da621SChristian Lamparter 	{ 0x1c5a18, 0x00000061, 0x00000061, 0x00000001, 0x00000001, },
157319da621SChristian Lamparter 	{ 0x1c5a1c, 0x00000168, 0x00000168, 0x00000041, 0x00000041, },
158319da621SChristian Lamparter 	{ 0x1c5a20, 0x000001a8, 0x000001a8, 0x000001a8, 0x000001a8, },
159319da621SChristian Lamparter 	{ 0x1c5a24, 0x000001e8, 0x000001e8, 0x000001e8, 0x000001e8, },
160319da621SChristian Lamparter 	{ 0x1c5a28, 0x00000028, 0x00000028, 0x00000028, 0x00000028, },
161319da621SChristian Lamparter 	{ 0x1c5a2c, 0x00000068, 0x00000068, 0x00000068, 0x00000068, },
162319da621SChristian Lamparter 	{ 0x1c5a30, 0x00000189, 0x00000189, 0x000000a8, 0x000000a8, },
163319da621SChristian Lamparter 	{ 0x1c5a34, 0x000001c9, 0x000001c9, 0x00000169, 0x00000169, },
164319da621SChristian Lamparter 	{ 0x1c5a38, 0x00000009, 0x00000009, 0x000001a9, 0x000001a9, },
165319da621SChristian Lamparter 	{ 0x1c5a3c, 0x00000049, 0x00000049, 0x000001e9, 0x000001e9, },
166319da621SChristian Lamparter 	{ 0x1c5a40, 0x00000089, 0x00000089, 0x00000029, 0x00000029, },
167319da621SChristian Lamparter 	{ 0x1c5a44, 0x00000170, 0x00000170, 0x00000069, 0x00000069, },
168319da621SChristian Lamparter 	{ 0x1c5a48, 0x000001b0, 0x000001b0, 0x00000190, 0x00000190, },
169319da621SChristian Lamparter 	{ 0x1c5a4c, 0x000001f0, 0x000001f0, 0x000001d0, 0x000001d0, },
170319da621SChristian Lamparter 	{ 0x1c5a50, 0x00000030, 0x00000030, 0x00000010, 0x00000010, },
171319da621SChristian Lamparter 	{ 0x1c5a54, 0x00000070, 0x00000070, 0x00000050, 0x00000050, },
172319da621SChristian Lamparter 	{ 0x1c5a58, 0x00000191, 0x00000191, 0x00000090, 0x00000090, },
173319da621SChristian Lamparter 	{ 0x1c5a5c, 0x000001d1, 0x000001d1, 0x00000151, 0x00000151, },
174319da621SChristian Lamparter 	{ 0x1c5a60, 0x00000011, 0x00000011, 0x00000191, 0x00000191, },
175319da621SChristian Lamparter 	{ 0x1c5a64, 0x00000051, 0x00000051, 0x000001d1, 0x000001d1, },
176319da621SChristian Lamparter 	{ 0x1c5a68, 0x00000091, 0x00000091, 0x00000011, 0x00000011, },
177319da621SChristian Lamparter 	{ 0x1c5a6c, 0x000001b8, 0x000001b8, 0x00000051, 0x00000051, },
178319da621SChristian Lamparter 	{ 0x1c5a70, 0x000001f8, 0x000001f8, 0x00000198, 0x00000198, },
179319da621SChristian Lamparter 	{ 0x1c5a74, 0x00000038, 0x00000038, 0x000001d8, 0x000001d8, },
180319da621SChristian Lamparter 	{ 0x1c5a78, 0x00000078, 0x00000078, 0x00000018, 0x00000018, },
181319da621SChristian Lamparter 	{ 0x1c5a7c, 0x00000199, 0x00000199, 0x00000058, 0x00000058, },
182319da621SChristian Lamparter 	{ 0x1c5a80, 0x000001d9, 0x000001d9, 0x00000098, 0x00000098, },
183319da621SChristian Lamparter 	{ 0x1c5a84, 0x00000019, 0x00000019, 0x00000159, 0x00000159, },
184319da621SChristian Lamparter 	{ 0x1c5a88, 0x00000059, 0x00000059, 0x00000199, 0x00000199, },
185319da621SChristian Lamparter 	{ 0x1c5a8c, 0x00000099, 0x00000099, 0x000001d9, 0x000001d9, },
186319da621SChristian Lamparter 	{ 0x1c5a90, 0x000000d9, 0x000000d9, 0x00000019, 0x00000019, },
187319da621SChristian Lamparter 	{ 0x1c5a94, 0x000000f9, 0x000000f9, 0x00000059, 0x00000059, },
188319da621SChristian Lamparter 	{ 0x1c5a98, 0x000000f9, 0x000000f9, 0x00000099, 0x00000099, },
189319da621SChristian Lamparter 	{ 0x1c5a9c, 0x000000f9, 0x000000f9, 0x000000d9, 0x000000d9, },
190319da621SChristian Lamparter 	{ 0x1c5aa0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
191319da621SChristian Lamparter 	{ 0x1c5aa4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
192319da621SChristian Lamparter 	{ 0x1c5aa8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
193319da621SChristian Lamparter 	{ 0x1c5aac, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
194319da621SChristian Lamparter 	{ 0x1c5ab0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
195319da621SChristian Lamparter 	{ 0x1c5ab4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
196319da621SChristian Lamparter 	{ 0x1c5ab8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
197319da621SChristian Lamparter 	{ 0x1c5abc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
198319da621SChristian Lamparter 	{ 0x1c5ac0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
199319da621SChristian Lamparter 	{ 0x1c5ac4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
200319da621SChristian Lamparter 	{ 0x1c5ac8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
201319da621SChristian Lamparter 	{ 0x1c5acc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
202319da621SChristian Lamparter 	{ 0x1c5ad0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
203319da621SChristian Lamparter 	{ 0x1c5ad4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
204319da621SChristian Lamparter 	{ 0x1c5ad8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
205319da621SChristian Lamparter 	{ 0x1c5adc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
206319da621SChristian Lamparter 	{ 0x1c5ae0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
207319da621SChristian Lamparter 	{ 0x1c5ae4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
208319da621SChristian Lamparter 	{ 0x1c5ae8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
209319da621SChristian Lamparter 	{ 0x1c5aec, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
210319da621SChristian Lamparter 	{ 0x1c5af0, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
211319da621SChristian Lamparter 	{ 0x1c5af4, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
212319da621SChristian Lamparter 	{ 0x1c5af8, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
213319da621SChristian Lamparter 	{ 0x1c5afc, 0x000000f9, 0x000000f9, 0x000000f9, 0x000000f9, },
214319da621SChristian Lamparter 	{ 0x1c5b00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
215319da621SChristian Lamparter 	{ 0x1c5b04, 0x00000001, 0x00000001, 0x00000001, 0x00000001, },
216319da621SChristian Lamparter 	{ 0x1c5b08, 0x00000002, 0x00000002, 0x00000002, 0x00000002, },
217319da621SChristian Lamparter 	{ 0x1c5b0c, 0x00000003, 0x00000003, 0x00000003, 0x00000003, },
218319da621SChristian Lamparter 	{ 0x1c5b10, 0x00000004, 0x00000004, 0x00000004, 0x00000004, },
219319da621SChristian Lamparter 	{ 0x1c5b14, 0x00000005, 0x00000005, 0x00000005, 0x00000005, },
220319da621SChristian Lamparter 	{ 0x1c5b18, 0x00000008, 0x00000008, 0x00000008, 0x00000008, },
221319da621SChristian Lamparter 	{ 0x1c5b1c, 0x00000009, 0x00000009, 0x00000009, 0x00000009, },
222319da621SChristian Lamparter 	{ 0x1c5b20, 0x0000000a, 0x0000000a, 0x0000000a, 0x0000000a, },
223319da621SChristian Lamparter 	{ 0x1c5b24, 0x0000000b, 0x0000000b, 0x0000000b, 0x0000000b, },
224319da621SChristian Lamparter 	{ 0x1c5b28, 0x0000000c, 0x0000000c, 0x0000000c, 0x0000000c, },
225319da621SChristian Lamparter 	{ 0x1c5b2c, 0x0000000d, 0x0000000d, 0x0000000d, 0x0000000d, },
226319da621SChristian Lamparter 	{ 0x1c5b30, 0x00000010, 0x00000010, 0x00000010, 0x00000010, },
227319da621SChristian Lamparter 	{ 0x1c5b34, 0x00000011, 0x00000011, 0x00000011, 0x00000011, },
228319da621SChristian Lamparter 	{ 0x1c5b38, 0x00000012, 0x00000012, 0x00000012, 0x00000012, },
229319da621SChristian Lamparter 	{ 0x1c5b3c, 0x00000013, 0x00000013, 0x00000013, 0x00000013, },
230319da621SChristian Lamparter 	{ 0x1c5b40, 0x00000014, 0x00000014, 0x00000014, 0x00000014, },
231319da621SChristian Lamparter 	{ 0x1c5b44, 0x00000015, 0x00000015, 0x00000015, 0x00000015, },
232319da621SChristian Lamparter 	{ 0x1c5b48, 0x00000018, 0x00000018, 0x00000018, 0x00000018, },
233319da621SChristian Lamparter 	{ 0x1c5b4c, 0x00000019, 0x00000019, 0x00000019, 0x00000019, },
234319da621SChristian Lamparter 	{ 0x1c5b50, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a, },
235319da621SChristian Lamparter 	{ 0x1c5b54, 0x0000001b, 0x0000001b, 0x0000001b, 0x0000001b, },
236319da621SChristian Lamparter 	{ 0x1c5b58, 0x0000001c, 0x0000001c, 0x0000001c, 0x0000001c, },
237319da621SChristian Lamparter 	{ 0x1c5b5c, 0x0000001d, 0x0000001d, 0x0000001d, 0x0000001d, },
238319da621SChristian Lamparter 	{ 0x1c5b60, 0x00000020, 0x00000020, 0x00000020, 0x00000020, },
239319da621SChristian Lamparter 	{ 0x1c5b64, 0x00000021, 0x00000021, 0x00000021, 0x00000021, },
240319da621SChristian Lamparter 	{ 0x1c5b68, 0x00000022, 0x00000022, 0x00000022, 0x00000022, },
241319da621SChristian Lamparter 	{ 0x1c5b6c, 0x00000023, 0x00000023, 0x00000023, 0x00000023, },
242319da621SChristian Lamparter 	{ 0x1c5b70, 0x00000024, 0x00000024, 0x00000024, 0x00000024, },
243319da621SChristian Lamparter 	{ 0x1c5b74, 0x00000025, 0x00000025, 0x00000025, 0x00000025, },
244319da621SChristian Lamparter 	{ 0x1c5b78, 0x00000028, 0x00000028, 0x00000028, 0x00000028, },
245319da621SChristian Lamparter 	{ 0x1c5b7c, 0x00000029, 0x00000029, 0x00000029, 0x00000029, },
246319da621SChristian Lamparter 	{ 0x1c5b80, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, },
247319da621SChristian Lamparter 	{ 0x1c5b84, 0x0000002b, 0x0000002b, 0x0000002b, 0x0000002b, },
248319da621SChristian Lamparter 	{ 0x1c5b88, 0x0000002c, 0x0000002c, 0x0000002c, 0x0000002c, },
249319da621SChristian Lamparter 	{ 0x1c5b8c, 0x0000002d, 0x0000002d, 0x0000002d, 0x0000002d, },
250319da621SChristian Lamparter 	{ 0x1c5b90, 0x00000030, 0x00000030, 0x00000030, 0x00000030, },
251319da621SChristian Lamparter 	{ 0x1c5b94, 0x00000031, 0x00000031, 0x00000031, 0x00000031, },
252319da621SChristian Lamparter 	{ 0x1c5b98, 0x00000032, 0x00000032, 0x00000032, 0x00000032, },
253319da621SChristian Lamparter 	{ 0x1c5b9c, 0x00000033, 0x00000033, 0x00000033, 0x00000033, },
254319da621SChristian Lamparter 	{ 0x1c5ba0, 0x00000034, 0x00000034, 0x00000034, 0x00000034, },
255319da621SChristian Lamparter 	{ 0x1c5ba4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
256319da621SChristian Lamparter 	{ 0x1c5ba8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
257319da621SChristian Lamparter 	{ 0x1c5bac, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
258319da621SChristian Lamparter 	{ 0x1c5bb0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
259319da621SChristian Lamparter 	{ 0x1c5bb4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
260319da621SChristian Lamparter 	{ 0x1c5bb8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
261319da621SChristian Lamparter 	{ 0x1c5bbc, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
262319da621SChristian Lamparter 	{ 0x1c5bc0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
263319da621SChristian Lamparter 	{ 0x1c5bc4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
264319da621SChristian Lamparter 	{ 0x1c5bc8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
265319da621SChristian Lamparter 	{ 0x1c5bcc, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
266319da621SChristian Lamparter 	{ 0x1c5bd0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
267319da621SChristian Lamparter 	{ 0x1c5bd4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
268319da621SChristian Lamparter 	{ 0x1c5bd8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
269319da621SChristian Lamparter 	{ 0x1c5bdc, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
270319da621SChristian Lamparter 	{ 0x1c5be0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
271319da621SChristian Lamparter 	{ 0x1c5be4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
272319da621SChristian Lamparter 	{ 0x1c5be8, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
273319da621SChristian Lamparter 	{ 0x1c5bec, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
274319da621SChristian Lamparter 	{ 0x1c5bf0, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
275319da621SChristian Lamparter 	{ 0x1c5bf4, 0x00000035, 0x00000035, 0x00000035, 0x00000035, },
276319da621SChristian Lamparter 	{ 0x1c5bf8, 0x00000010, 0x00000010, 0x00000010, 0x00000010, },
277319da621SChristian Lamparter 	{ 0x1c5bfc, 0x0000001a, 0x0000001a, 0x0000001a, 0x0000001a, },
278319da621SChristian Lamparter 	{ 0x1c5c00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
279319da621SChristian Lamparter 	{ 0x1c5c0c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
280319da621SChristian Lamparter 	{ 0x1c5c10, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
281319da621SChristian Lamparter 	{ 0x1c5c14, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
282319da621SChristian Lamparter 	{ 0x1c5c18, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
283319da621SChristian Lamparter 	{ 0x1c5c1c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
284319da621SChristian Lamparter 	{ 0x1c5c20, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
285319da621SChristian Lamparter 	{ 0x1c5c24, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
286319da621SChristian Lamparter 	{ 0x1c5c28, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
287319da621SChristian Lamparter 	{ 0x1c5c2c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
288319da621SChristian Lamparter 	{ 0x1c5c30, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
289319da621SChristian Lamparter 	{ 0x1c5c34, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
290319da621SChristian Lamparter 	{ 0x1c5c38, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
291319da621SChristian Lamparter 	{ 0x1c5c3c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
292319da621SChristian Lamparter 	{ 0x1c5cf0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
293319da621SChristian Lamparter 	{ 0x1c5cf4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
294319da621SChristian Lamparter 	{ 0x1c5cf8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
295319da621SChristian Lamparter 	{ 0x1c5cfc, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
296319da621SChristian Lamparter 	{ 0x1c6200, 0x00000008, 0x00000008, 0x0000000e, 0x0000000e, },
297319da621SChristian Lamparter 	{ 0x1c6204, 0x00000440, 0x00000440, 0x00000440, 0x00000440, },
298319da621SChristian Lamparter 	{ 0x1c6208, 0xd6be4788, 0xd6be4788, 0xd03e4788, 0xd03e4788, },
299319da621SChristian Lamparter 	{ 0x1c620c, 0x012e8160, 0x012e8160, 0x012a8160, 0x012a8160, },
300319da621SChristian Lamparter 	{ 0x1c6210, 0x40806333, 0x40806333, 0x40806333, 0x40806333, },
301319da621SChristian Lamparter 	{ 0x1c6214, 0x00106c10, 0x00106c10, 0x00106c10, 0x00106c10, },
302319da621SChristian Lamparter 	{ 0x1c6218, 0x009c4060, 0x009c4060, 0x009c4060, 0x009c4060, },
303319da621SChristian Lamparter 	{ 0x1c621c, 0x1883800a, 0x1883800a, 0x1883800a, 0x1883800a, },
304319da621SChristian Lamparter 	{ 0x1c6220, 0x018830c6, 0x018830c6, 0x018830c6, 0x018830c6, },
305319da621SChristian Lamparter 	{ 0x1c6224, 0x00000400, 0x00000400, 0x00000400, 0x00000400, },
306319da621SChristian Lamparter 	{ 0x1c6228, 0x000009b5, 0x000009b5, 0x000009b5, 0x000009b5, },
307319da621SChristian Lamparter 	{ 0x1c622c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
308319da621SChristian Lamparter 	{ 0x1c6230, 0x00000108, 0x00000210, 0x00000210, 0x00000108, },
309319da621SChristian Lamparter 	{ 0x1c6234, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
310319da621SChristian Lamparter 	{ 0x1c6238, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
311319da621SChristian Lamparter 	{ 0x1c623c, 0x13c889af, 0x13c889af, 0x13c889af, 0x13c889af, },
312319da621SChristian Lamparter 	{ 0x1c6240, 0x38490a20, 0x38490a20, 0x38490a20, 0x38490a20, },
313319da621SChristian Lamparter 	{ 0x1c6244, 0x00007bb6, 0x00007bb6, 0x00007bb6, 0x00007bb6, },
314319da621SChristian Lamparter 	{ 0x1c6248, 0x0fff3ffc, 0x0fff3ffc, 0x0fff3ffc, 0x0fff3ffc, },
315319da621SChristian Lamparter 	{ 0x1c624c, 0x00000001, 0x00000001, 0x00000001, 0x00000001, },
316319da621SChristian Lamparter 	{ 0x1c6250, 0x0000a000, 0x0000a000, 0x0000a000, 0x0000a000, },
317319da621SChristian Lamparter 	{ 0x1c6254, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
318319da621SChristian Lamparter 	{ 0x1c6258, 0x0cc75380, 0x0cc75380, 0x0cc75380, 0x0cc75380, },
319319da621SChristian Lamparter 	{ 0x1c625c, 0x0f0f0f01, 0x0f0f0f01, 0x0f0f0f01, 0x0f0f0f01, },
320319da621SChristian Lamparter 	{ 0x1c6260, 0xdfa91f01, 0xdfa91f01, 0xdfa91f01, 0xdfa91f01, },
321319da621SChristian Lamparter 	{ 0x1c6264, 0x00418a11, 0x00418a11, 0x00418a11, 0x00418a11, },
322319da621SChristian Lamparter 	{ 0x1c6268, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
323319da621SChristian Lamparter 	{ 0x1c626c, 0x09249126, 0x09249126, 0x09249126, 0x09249126, },
324319da621SChristian Lamparter 	{ 0x1c6274, 0x0a1a9caa, 0x0a1a9caa, 0x0a1a7caa, 0x0a1a7caa, },
325319da621SChristian Lamparter 	{ 0x1c6278, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, },
326319da621SChristian Lamparter 	{ 0x1c627c, 0x051701ce, 0x051701ce, 0x051701ce, 0x051701ce, },
327319da621SChristian Lamparter 	{ 0x1c6300, 0x18010000, 0x18010000, 0x18010000, 0x18010000, },
328319da621SChristian Lamparter 	{ 0x1c6304, 0x30032602, 0x30032602, 0x2e032402, 0x2e032402, },
329319da621SChristian Lamparter 	{ 0x1c6308, 0x48073e06, 0x48073e06, 0x4a0a3c06, 0x4a0a3c06, },
330319da621SChristian Lamparter 	{ 0x1c630c, 0x560b4c0a, 0x560b4c0a, 0x621a540b, 0x621a540b, },
331319da621SChristian Lamparter 	{ 0x1c6310, 0x641a600f, 0x641a600f, 0x764f6c1b, 0x764f6c1b, },
332319da621SChristian Lamparter 	{ 0x1c6314, 0x7a4f6e1b, 0x7a4f6e1b, 0x845b7a5a, 0x845b7a5a, },
333319da621SChristian Lamparter 	{ 0x1c6318, 0x8c5b7e5a, 0x8c5b7e5a, 0x950f8ccf, 0x950f8ccf, },
334319da621SChristian Lamparter 	{ 0x1c631c, 0x9d0f96cf, 0x9d0f96cf, 0xa5cf9b4f, 0xa5cf9b4f, },
335319da621SChristian Lamparter 	{ 0x1c6320, 0xb51fa69f, 0xb51fa69f, 0xbddfaf1f, 0xbddfaf1f, },
336319da621SChristian Lamparter 	{ 0x1c6324, 0xcb3fbd07, 0xcb3fbcbf, 0xd1ffc93f, 0xd1ffc93f, },
337319da621SChristian Lamparter 	{ 0x1c6328, 0x0000d7bf, 0x0000d7bf, 0x00000000, 0x00000000, },
338319da621SChristian Lamparter 	{ 0x1c632c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
339319da621SChristian Lamparter 	{ 0x1c6330, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
340319da621SChristian Lamparter 	{ 0x1c6334, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
341319da621SChristian Lamparter 	{ 0x1c6338, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
342319da621SChristian Lamparter 	{ 0x1c633c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
343319da621SChristian Lamparter 	{ 0x1c6340, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
344319da621SChristian Lamparter 	{ 0x1c6344, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
345319da621SChristian Lamparter 	{ 0x1c6348, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, },
346319da621SChristian Lamparter 	{ 0x1c634c, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, },
347319da621SChristian Lamparter 	{ 0x1c6350, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, },
348319da621SChristian Lamparter 	{ 0x1c6354, 0x0003ffff, 0x0003ffff, 0x0003ffff, 0x0003ffff, },
349319da621SChristian Lamparter 	{ 0x1c6358, 0x79a8aa1f, 0x79a8aa1f, 0x79a8aa1f, 0x79a8aa1f, },
350319da621SChristian Lamparter 	{ 0x1c6388, 0x08000000, 0x08000000, 0x08000000, 0x08000000, },
351319da621SChristian Lamparter 	{ 0x1c638c, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
352319da621SChristian Lamparter 	{ 0x1c6390, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
353319da621SChristian Lamparter 	{ 0x1c6394, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, },
354319da621SChristian Lamparter 	{ 0x1c6398, 0x000001ce, 0x000001ce, 0x000001ce, 0x000001ce, },
355319da621SChristian Lamparter 	{ 0x1c639c, 0x00000007, 0x00000007, 0x00000007, 0x00000007, },
356319da621SChristian Lamparter 	{ 0x1c63a0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
357319da621SChristian Lamparter 	{ 0x1c63a4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
358319da621SChristian Lamparter 	{ 0x1c63a8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
359319da621SChristian Lamparter 	{ 0x1c63ac, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
360319da621SChristian Lamparter 	{ 0x1c63b0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
361319da621SChristian Lamparter 	{ 0x1c63b4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
362319da621SChristian Lamparter 	{ 0x1c63b8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
363319da621SChristian Lamparter 	{ 0x1c63bc, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
364319da621SChristian Lamparter 	{ 0x1c63c0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
365319da621SChristian Lamparter 	{ 0x1c63c4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
366319da621SChristian Lamparter 	{ 0x1c63c8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
367319da621SChristian Lamparter 	{ 0x1c63cc, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
368319da621SChristian Lamparter 	{ 0x1c63d0, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
369319da621SChristian Lamparter 	{ 0x1c63d4, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, 0x3f3f3f3f, },
370319da621SChristian Lamparter 	{ 0x1c63d8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, },
371319da621SChristian Lamparter 	{ 0x1c63dc, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, },
372319da621SChristian Lamparter 	{ 0x1c63e0, 0x000000c0, 0x000000c0, 0x000000c0, 0x000000c0, },
373319da621SChristian Lamparter 	{ 0x1c6848, 0x00180a65, 0x00180a65, 0x00180a68, 0x00180a68, },
374319da621SChristian Lamparter 	{ 0x1c6920, 0x0510001c, 0x0510001c, 0x0510001c, 0x0510001c, },
375319da621SChristian Lamparter 	{ 0x1c6960, 0x00009b40, 0x00009b40, 0x00009b40, 0x00009b40, },
376319da621SChristian Lamparter 	{ 0x1c720c, 0x012e8160, 0x012e8160, 0x012a8160, 0x012a8160, },
377319da621SChristian Lamparter 	{ 0x1c726c, 0x09249126, 0x09249126, 0x09249126, 0x09249126, },
378319da621SChristian Lamparter 	{ 0x1c7848, 0x00180a65, 0x00180a65, 0x00180a68, 0x00180a68, },
379319da621SChristian Lamparter 	{ 0x1c7920, 0x0510001c, 0x0510001c, 0x0510001c, 0x0510001c, },
380319da621SChristian Lamparter 	{ 0x1c7960, 0x00009b40, 0x00009b40, 0x00009b40, 0x00009b40, },
381319da621SChristian Lamparter 	{ 0x1c820c, 0x012e8160, 0x012e8160, 0x012a8160, 0x012a8160, },
382319da621SChristian Lamparter 	{ 0x1c826c, 0x09249126, 0x09249126, 0x09249126, 0x09249126, },
383319da621SChristian Lamparter /*	{ 0x1c8864, 0x0001ce00, 0x0001ce00, 0x0001ce00, 0x0001ce00, }, */
384319da621SChristian Lamparter 	{ 0x1c8864, 0x0001c600, 0x0001c600, 0x0001c600, 0x0001c600, },
385319da621SChristian Lamparter 	{ 0x1c895c, 0x004b6a8e, 0x004b6a8e, 0x004b6a8e, 0x004b6a8e, },
386319da621SChristian Lamparter 	{ 0x1c8968, 0x000003ce, 0x000003ce, 0x000003ce, 0x000003ce, },
387319da621SChristian Lamparter 	{ 0x1c89bc, 0x00181400, 0x00181400, 0x00181400, 0x00181400, },
388319da621SChristian Lamparter 	{ 0x1c9270, 0x00820820, 0x00820820, 0x00820820, 0x00820820, },
389319da621SChristian Lamparter 	{ 0x1c935c, 0x066c420f, 0x066c420f, 0x066c420f, 0x066c420f, },
390319da621SChristian Lamparter 	{ 0x1c9360, 0x0f282207, 0x0f282207, 0x0f282207, 0x0f282207, },
391319da621SChristian Lamparter 	{ 0x1c9364, 0x17601685, 0x17601685, 0x17601685, 0x17601685, },
392319da621SChristian Lamparter 	{ 0x1c9368, 0x1f801104, 0x1f801104, 0x1f801104, 0x1f801104, },
393319da621SChristian Lamparter 	{ 0x1c936c, 0x37a00c03, 0x37a00c03, 0x37a00c03, 0x37a00c03, },
394319da621SChristian Lamparter 	{ 0x1c9370, 0x3fc40883, 0x3fc40883, 0x3fc40883, 0x3fc40883, },
395319da621SChristian Lamparter 	{ 0x1c9374, 0x57c00803, 0x57c00803, 0x57c00803, 0x57c00803, },
396319da621SChristian Lamparter 	{ 0x1c9378, 0x5fd80682, 0x5fd80682, 0x5fd80682, 0x5fd80682, },
397319da621SChristian Lamparter 	{ 0x1c937c, 0x7fe00482, 0x7fe00482, 0x7fe00482, 0x7fe00482, },
398319da621SChristian Lamparter 	{ 0x1c9380, 0x7f3c7bba, 0x7f3c7bba, 0x7f3c7bba, 0x7f3c7bba, },
399319da621SChristian Lamparter 	{ 0x1c9384, 0xf3307ff0, 0xf3307ff0, 0xf3307ff0, 0xf3307ff0, }
400319da621SChristian Lamparter };
401319da621SChristian Lamparter 
402319da621SChristian Lamparter /*
403319da621SChristian Lamparter  * look up a certain register in ar5416_phy_init[] and return the init. value
404319da621SChristian Lamparter  * for the band and bandwidth given. Return 0 if register address not found.
405319da621SChristian Lamparter  */
carl9170_def_val(u32 reg,bool is_2ghz,bool is_40mhz)406319da621SChristian Lamparter static u32 carl9170_def_val(u32 reg, bool is_2ghz, bool is_40mhz)
407319da621SChristian Lamparter {
408319da621SChristian Lamparter 	unsigned int i;
409319da621SChristian Lamparter 	for (i = 0; i < ARRAY_SIZE(ar5416_phy_init); i++) {
410319da621SChristian Lamparter 		if (ar5416_phy_init[i].reg != reg)
411319da621SChristian Lamparter 			continue;
412319da621SChristian Lamparter 
413319da621SChristian Lamparter 		if (is_2ghz) {
414319da621SChristian Lamparter 			if (is_40mhz)
415319da621SChristian Lamparter 				return ar5416_phy_init[i]._2ghz_40;
416319da621SChristian Lamparter 			else
417319da621SChristian Lamparter 				return ar5416_phy_init[i]._2ghz_20;
418319da621SChristian Lamparter 		} else {
419319da621SChristian Lamparter 			if (is_40mhz)
420319da621SChristian Lamparter 				return ar5416_phy_init[i]._5ghz_40;
421319da621SChristian Lamparter 			else
422319da621SChristian Lamparter 				return ar5416_phy_init[i]._5ghz_20;
423319da621SChristian Lamparter 		}
424319da621SChristian Lamparter 	}
425319da621SChristian Lamparter 	return 0;
426319da621SChristian Lamparter }
427319da621SChristian Lamparter 
428319da621SChristian Lamparter /*
429319da621SChristian Lamparter  * initialize some phy regs from eeprom values in modal_header[]
43025985edcSLucas De Marchi  * acc. to band and bandwidth
431319da621SChristian Lamparter  */
carl9170_init_phy_from_eeprom(struct ar9170 * ar,bool is_2ghz,bool is_40mhz)432319da621SChristian Lamparter static int carl9170_init_phy_from_eeprom(struct ar9170 *ar,
433319da621SChristian Lamparter 				bool is_2ghz, bool is_40mhz)
434319da621SChristian Lamparter {
435319da621SChristian Lamparter 	static const u8 xpd2pd[16] = {
436319da621SChristian Lamparter 		0x2, 0x2, 0x2, 0x1, 0x2, 0x2, 0x6, 0x2,
437319da621SChristian Lamparter 		0x2, 0x3, 0x7, 0x2, 0xb, 0x2, 0x2, 0x2
438319da621SChristian Lamparter 	};
439319da621SChristian Lamparter 	/* pointer to the modal_header acc. to band */
440319da621SChristian Lamparter 	struct ar9170_eeprom_modal *m = &ar->eeprom.modal_header[is_2ghz];
441319da621SChristian Lamparter 	u32 val;
442319da621SChristian Lamparter 
443319da621SChristian Lamparter 	carl9170_regwrite_begin(ar);
444319da621SChristian Lamparter 
445319da621SChristian Lamparter 	/* ant common control (index 0) */
446319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_SWITCH_COM,
447319da621SChristian Lamparter 		le32_to_cpu(m->antCtrlCommon));
448319da621SChristian Lamparter 
449319da621SChristian Lamparter 	/* ant control chain 0 (index 1) */
450319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_SWITCH_CHAIN_0,
451319da621SChristian Lamparter 		le32_to_cpu(m->antCtrlChain[0]));
452319da621SChristian Lamparter 
453319da621SChristian Lamparter 	/* ant control chain 2 (index 2) */
454319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_SWITCH_CHAIN_2,
455319da621SChristian Lamparter 		le32_to_cpu(m->antCtrlChain[1]));
456319da621SChristian Lamparter 
457319da621SChristian Lamparter 	/* SwSettle (index 3) */
458319da621SChristian Lamparter 	if (!is_40mhz) {
459319da621SChristian Lamparter 		val = carl9170_def_val(AR9170_PHY_REG_SETTLING,
460319da621SChristian Lamparter 				     is_2ghz, is_40mhz);
461319da621SChristian Lamparter 		SET_VAL(AR9170_PHY_SETTLING_SWITCH, val, m->switchSettling);
462319da621SChristian Lamparter 		carl9170_regwrite(AR9170_PHY_REG_SETTLING, val);
463319da621SChristian Lamparter 	}
464319da621SChristian Lamparter 
465319da621SChristian Lamparter 	/* adcDesired, pdaDesired (index 4) */
466319da621SChristian Lamparter 	val = carl9170_def_val(AR9170_PHY_REG_DESIRED_SZ, is_2ghz, is_40mhz);
467319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_DESIRED_SZ_PGA, val, m->pgaDesiredSize);
468319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_DESIRED_SZ_ADC, val, m->adcDesiredSize);
469319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_DESIRED_SZ, val);
470319da621SChristian Lamparter 
471319da621SChristian Lamparter 	/* TxEndToXpaOff, TxFrameToXpaOn (index 5) */
472319da621SChristian Lamparter 	val = carl9170_def_val(AR9170_PHY_REG_RF_CTL4, is_2ghz, is_40mhz);
473319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_RF_CTL4_TX_END_XPAB_OFF, val, m->txEndToXpaOff);
474319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_RF_CTL4_TX_END_XPAA_OFF, val, m->txEndToXpaOff);
475319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_RF_CTL4_FRAME_XPAB_ON, val, m->txFrameToXpaOn);
476319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_RF_CTL4_FRAME_XPAA_ON, val, m->txFrameToXpaOn);
477319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_RF_CTL4, val);
478319da621SChristian Lamparter 
479319da621SChristian Lamparter 	/* TxEndToRxOn (index 6) */
480319da621SChristian Lamparter 	val = carl9170_def_val(AR9170_PHY_REG_RF_CTL3, is_2ghz, is_40mhz);
481319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_RF_CTL3_TX_END_TO_A2_RX_ON, val, m->txEndToRxOn);
482319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_RF_CTL3, val);
483319da621SChristian Lamparter 
484319da621SChristian Lamparter 	/* thresh62 (index 7) */
485319da621SChristian Lamparter 	val = carl9170_def_val(0x1c8864, is_2ghz, is_40mhz);
486319da621SChristian Lamparter 	val = (val & ~0x7f000) | (m->thresh62 << 12);
487319da621SChristian Lamparter 	carl9170_regwrite(0x1c8864, val);
488319da621SChristian Lamparter 
489319da621SChristian Lamparter 	/* tx/rx attenuation chain 0 (index 8) */
490319da621SChristian Lamparter 	val = carl9170_def_val(AR9170_PHY_REG_RXGAIN, is_2ghz, is_40mhz);
491319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_RXGAIN_TXRX_ATTEN, val, m->txRxAttenCh[0]);
492319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_RXGAIN, val);
493319da621SChristian Lamparter 
494319da621SChristian Lamparter 	/* tx/rx attenuation chain 2 (index 9) */
495319da621SChristian Lamparter 	val = carl9170_def_val(AR9170_PHY_REG_RXGAIN_CHAIN_2,
496319da621SChristian Lamparter 			       is_2ghz, is_40mhz);
497319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_RXGAIN_TXRX_ATTEN, val, m->txRxAttenCh[1]);
498319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_RXGAIN_CHAIN_2, val);
499319da621SChristian Lamparter 
500319da621SChristian Lamparter 	/* tx/rx margin chain 0 (index 10) */
501319da621SChristian Lamparter 	val = carl9170_def_val(AR9170_PHY_REG_GAIN_2GHZ, is_2ghz, is_40mhz);
502319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_GAIN_2GHZ_RXTX_MARGIN, val, m->rxTxMarginCh[0]);
503319da621SChristian Lamparter 	/* bsw margin chain 0 for 5GHz only */
504319da621SChristian Lamparter 	if (!is_2ghz)
505319da621SChristian Lamparter 		SET_VAL(AR9170_PHY_GAIN_2GHZ_BSW_MARGIN, val, m->bswMargin[0]);
506319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_GAIN_2GHZ, val);
507319da621SChristian Lamparter 
508319da621SChristian Lamparter 	/* tx/rx margin chain 2 (index 11) */
509319da621SChristian Lamparter 	val = carl9170_def_val(AR9170_PHY_REG_GAIN_2GHZ_CHAIN_2,
510319da621SChristian Lamparter 			       is_2ghz, is_40mhz);
511319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_GAIN_2GHZ_RXTX_MARGIN, val, m->rxTxMarginCh[1]);
512319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_GAIN_2GHZ_CHAIN_2, val);
513319da621SChristian Lamparter 
514319da621SChristian Lamparter 	/* iqCall, iqCallq chain 0 (index 12) */
515319da621SChristian Lamparter 	val = carl9170_def_val(AR9170_PHY_REG_TIMING_CTRL4(0),
516319da621SChristian Lamparter 			       is_2ghz, is_40mhz);
517319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF, val, m->iqCalICh[0]);
518319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF, val, m->iqCalQCh[0]);
519319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_TIMING_CTRL4(0), val);
520319da621SChristian Lamparter 
521319da621SChristian Lamparter 	/* iqCall, iqCallq chain 2 (index 13) */
522319da621SChristian Lamparter 	val = carl9170_def_val(AR9170_PHY_REG_TIMING_CTRL4(2),
523319da621SChristian Lamparter 			       is_2ghz, is_40mhz);
524319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF, val, m->iqCalICh[1]);
525319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF, val, m->iqCalQCh[1]);
526319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_TIMING_CTRL4(2), val);
527319da621SChristian Lamparter 
528319da621SChristian Lamparter 	/* xpd gain mask (index 14) */
529319da621SChristian Lamparter 	val = carl9170_def_val(AR9170_PHY_REG_TPCRG1, is_2ghz, is_40mhz);
530319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_TPCRG1_PD_GAIN_1, val,
531319da621SChristian Lamparter 		xpd2pd[m->xpdGain & 0xf] & 3);
532319da621SChristian Lamparter 	SET_VAL(AR9170_PHY_TPCRG1_PD_GAIN_2, val,
533319da621SChristian Lamparter 		xpd2pd[m->xpdGain & 0xf] >> 2);
534319da621SChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_TPCRG1, val);
535319da621SChristian Lamparter 
5369dec6f9cSChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_RX_CHAINMASK, ar->eeprom.rx_mask);
5379dec6f9cSChristian Lamparter 	carl9170_regwrite(AR9170_PHY_REG_CAL_CHAINMASK, ar->eeprom.rx_mask);
5389dec6f9cSChristian Lamparter 
5399dec6f9cSChristian Lamparter 	carl9170_regwrite_finish();
540319da621SChristian Lamparter 	return carl9170_regwrite_result();
541319da621SChristian Lamparter }
542319da621SChristian Lamparter 
carl9170_init_phy(struct ar9170 * ar,enum nl80211_band band)543*57fbcce3SJohannes Berg static int carl9170_init_phy(struct ar9170 *ar, enum nl80211_band band)
544319da621SChristian Lamparter {
545319da621SChristian Lamparter 	int i, err;
546319da621SChristian Lamparter 	u32 val;
547*57fbcce3SJohannes Berg 	bool is_2ghz = band == NL80211_BAND_2GHZ;
548319da621SChristian Lamparter 	bool is_40mhz = conf_is_ht40(&ar->hw->conf);
549319da621SChristian Lamparter 
550319da621SChristian Lamparter 	carl9170_regwrite_begin(ar);
551319da621SChristian Lamparter 
552319da621SChristian Lamparter 	for (i = 0; i < ARRAY_SIZE(ar5416_phy_init); i++) {
553319da621SChristian Lamparter 		if (is_40mhz) {
554319da621SChristian Lamparter 			if (is_2ghz)
555319da621SChristian Lamparter 				val = ar5416_phy_init[i]._2ghz_40;
556319da621SChristian Lamparter 			else
557319da621SChristian Lamparter 				val = ar5416_phy_init[i]._5ghz_40;
558319da621SChristian Lamparter 		} else {
559319da621SChristian Lamparter 			if (is_2ghz)
560319da621SChristian Lamparter 				val = ar5416_phy_init[i]._2ghz_20;
561319da621SChristian Lamparter 			else
562319da621SChristian Lamparter 				val = ar5416_phy_init[i]._5ghz_20;
563319da621SChristian Lamparter 		}
564319da621SChristian Lamparter 
565319da621SChristian Lamparter 		carl9170_regwrite(ar5416_phy_init[i].reg, val);
566319da621SChristian Lamparter 	}
567319da621SChristian Lamparter 
568319da621SChristian Lamparter 	carl9170_regwrite_finish();
569319da621SChristian Lamparter 	err = carl9170_regwrite_result();
570319da621SChristian Lamparter 	if (err)
571319da621SChristian Lamparter 		return err;
572319da621SChristian Lamparter 
573319da621SChristian Lamparter 	err = carl9170_init_phy_from_eeprom(ar, is_2ghz, is_40mhz);
574319da621SChristian Lamparter 	if (err)
575319da621SChristian Lamparter 		return err;
576319da621SChristian Lamparter 
577319da621SChristian Lamparter 	err = carl9170_init_power_cal(ar);
578319da621SChristian Lamparter 	if (err)
579319da621SChristian Lamparter 		return err;
580319da621SChristian Lamparter 
5817ccc83b0SChristian Lamparter 	if (!ar->fw.hw_counters) {
5827ccc83b0SChristian Lamparter 		err = carl9170_write_reg(ar, AR9170_PWR_REG_PLL_ADDAC,
5837ccc83b0SChristian Lamparter 					 is_2ghz ? 0x5163 : 0x5143);
5847ccc83b0SChristian Lamparter 	}
585319da621SChristian Lamparter 
586319da621SChristian Lamparter 	return err;
587319da621SChristian Lamparter }
588319da621SChristian Lamparter 
589319da621SChristian Lamparter struct carl9170_rf_initvals {
590319da621SChristian Lamparter 	u32 reg, _5ghz, _2ghz;
591319da621SChristian Lamparter };
592319da621SChristian Lamparter 
593319da621SChristian Lamparter static struct carl9170_rf_initvals carl9170_rf_initval[] = {
594319da621SChristian Lamparter 	/* bank 0 */
595319da621SChristian Lamparter 	{ 0x1c58b0, 0x1e5795e5, 0x1e5795e5},
596319da621SChristian Lamparter 	{ 0x1c58e0, 0x02008020, 0x02008020},
597319da621SChristian Lamparter 	/* bank 1 */
598319da621SChristian Lamparter 	{ 0x1c58b0, 0x02108421, 0x02108421},
599319da621SChristian Lamparter 	{ 0x1c58ec, 0x00000008, 0x00000008},
600319da621SChristian Lamparter 	/* bank 2 */
601319da621SChristian Lamparter 	{ 0x1c58b0, 0x0e73ff17, 0x0e73ff17},
602319da621SChristian Lamparter 	{ 0x1c58e0, 0x00000420, 0x00000420},
603319da621SChristian Lamparter 	/* bank 3 */
604319da621SChristian Lamparter 	{ 0x1c58f0, 0x01400018, 0x01c00018},
605319da621SChristian Lamparter 	/* bank 4 */
606319da621SChristian Lamparter 	{ 0x1c58b0, 0x000001a1, 0x000001a1},
607319da621SChristian Lamparter 	{ 0x1c58e8, 0x00000001, 0x00000001},
608319da621SChristian Lamparter 	/* bank 5 */
609319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000013, 0x00000013},
610319da621SChristian Lamparter 	{ 0x1c58e4, 0x00000002, 0x00000002},
611319da621SChristian Lamparter 	/* bank 6 */
612319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000000, 0x00000000},
613319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000000, 0x00000000},
614319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000000, 0x00000000},
615319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000000, 0x00000000},
616319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000000, 0x00000000},
617319da621SChristian Lamparter 	{ 0x1c58b0, 0x00004000, 0x00004000},
618319da621SChristian Lamparter 	{ 0x1c58b0, 0x00006c00, 0x00006c00},
619319da621SChristian Lamparter 	{ 0x1c58b0, 0x00002c00, 0x00002c00},
620319da621SChristian Lamparter 	{ 0x1c58b0, 0x00004800, 0x00004800},
621319da621SChristian Lamparter 	{ 0x1c58b0, 0x00004000, 0x00004000},
622319da621SChristian Lamparter 	{ 0x1c58b0, 0x00006000, 0x00006000},
623319da621SChristian Lamparter 	{ 0x1c58b0, 0x00001000, 0x00001000},
624319da621SChristian Lamparter 	{ 0x1c58b0, 0x00004000, 0x00004000},
625319da621SChristian Lamparter 	{ 0x1c58b0, 0x00007c00, 0x00007c00},
626319da621SChristian Lamparter 	{ 0x1c58b0, 0x00007c00, 0x00007c00},
627319da621SChristian Lamparter 	{ 0x1c58b0, 0x00007c00, 0x00007c00},
628319da621SChristian Lamparter 	{ 0x1c58b0, 0x00007c00, 0x00007c00},
629319da621SChristian Lamparter 	{ 0x1c58b0, 0x00007c00, 0x00007c00},
630319da621SChristian Lamparter 	{ 0x1c58b0, 0x00087c00, 0x00087c00},
631319da621SChristian Lamparter 	{ 0x1c58b0, 0x00007c00, 0x00007c00},
632319da621SChristian Lamparter 	{ 0x1c58b0, 0x00005400, 0x00005400},
633319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000c00, 0x00000c00},
634319da621SChristian Lamparter 	{ 0x1c58b0, 0x00001800, 0x00001800},
635319da621SChristian Lamparter 	{ 0x1c58b0, 0x00007c00, 0x00007c00},
636319da621SChristian Lamparter 	{ 0x1c58b0, 0x00006c00, 0x00006c00},
637319da621SChristian Lamparter 	{ 0x1c58b0, 0x00006c00, 0x00006c00},
638319da621SChristian Lamparter 	{ 0x1c58b0, 0x00007c00, 0x00007c00},
639319da621SChristian Lamparter 	{ 0x1c58b0, 0x00002c00, 0x00002c00},
640319da621SChristian Lamparter 	{ 0x1c58b0, 0x00003c00, 0x00003c00},
641319da621SChristian Lamparter 	{ 0x1c58b0, 0x00003800, 0x00003800},
642319da621SChristian Lamparter 	{ 0x1c58b0, 0x00001c00, 0x00001c00},
643319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000800, 0x00000800},
644319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000408, 0x00000408},
645319da621SChristian Lamparter 	{ 0x1c58b0, 0x00004c15, 0x00004c15},
646319da621SChristian Lamparter 	{ 0x1c58b0, 0x00004188, 0x00004188},
647319da621SChristian Lamparter 	{ 0x1c58b0, 0x0000201e, 0x0000201e},
648319da621SChristian Lamparter 	{ 0x1c58b0, 0x00010408, 0x00010408},
649319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000801, 0x00000801},
650319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000c08, 0x00000c08},
651319da621SChristian Lamparter 	{ 0x1c58b0, 0x0000181e, 0x0000181e},
652319da621SChristian Lamparter 	{ 0x1c58b0, 0x00001016, 0x00001016},
653319da621SChristian Lamparter 	{ 0x1c58b0, 0x00002800, 0x00002800},
654319da621SChristian Lamparter 	{ 0x1c58b0, 0x00004010, 0x00004010},
655319da621SChristian Lamparter 	{ 0x1c58b0, 0x0000081c, 0x0000081c},
656319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000115, 0x00000115},
657319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000015, 0x00000015},
658319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000066, 0x00000066},
659319da621SChristian Lamparter 	{ 0x1c58b0, 0x0000001c, 0x0000001c},
660319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000000, 0x00000000},
661319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000004, 0x00000004},
662319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000015, 0x00000015},
663319da621SChristian Lamparter 	{ 0x1c58b0, 0x0000001f, 0x0000001f},
664319da621SChristian Lamparter 	{ 0x1c58e0, 0x00000000, 0x00000400},
665319da621SChristian Lamparter 	/* bank 7 */
666319da621SChristian Lamparter 	{ 0x1c58b0, 0x000000a0, 0x000000a0},
667319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000000, 0x00000000},
668319da621SChristian Lamparter 	{ 0x1c58b0, 0x00000040, 0x00000040},
669319da621SChristian Lamparter 	{ 0x1c58f0, 0x0000001c, 0x0000001c},
670319da621SChristian Lamparter };
671319da621SChristian Lamparter 
carl9170_init_rf_banks_0_7(struct ar9170 * ar,bool band5ghz)672319da621SChristian Lamparter static int carl9170_init_rf_banks_0_7(struct ar9170 *ar, bool band5ghz)
673319da621SChristian Lamparter {
674319da621SChristian Lamparter 	int err, i;
675319da621SChristian Lamparter 
676319da621SChristian Lamparter 	carl9170_regwrite_begin(ar);
677319da621SChristian Lamparter 
678319da621SChristian Lamparter 	for (i = 0; i < ARRAY_SIZE(carl9170_rf_initval); i++)
679319da621SChristian Lamparter 		carl9170_regwrite(carl9170_rf_initval[i].reg,
680319da621SChristian Lamparter 				  band5ghz ? carl9170_rf_initval[i]._5ghz
681319da621SChristian Lamparter 					   : carl9170_rf_initval[i]._2ghz);
682319da621SChristian Lamparter 
683319da621SChristian Lamparter 	carl9170_regwrite_finish();
684319da621SChristian Lamparter 	err = carl9170_regwrite_result();
685319da621SChristian Lamparter 	if (err)
686319da621SChristian Lamparter 		wiphy_err(ar->hw->wiphy, "rf init failed\n");
687319da621SChristian Lamparter 
688319da621SChristian Lamparter 	return err;
689319da621SChristian Lamparter }
690319da621SChristian Lamparter 
691319da621SChristian Lamparter struct carl9170_phy_freq_params {
692319da621SChristian Lamparter 	u8 coeff_exp;
693319da621SChristian Lamparter 	u16 coeff_man;
694319da621SChristian Lamparter 	u8 coeff_exp_shgi;
695319da621SChristian Lamparter 	u16 coeff_man_shgi;
696319da621SChristian Lamparter };
697319da621SChristian Lamparter 
698319da621SChristian Lamparter enum carl9170_bw {
699319da621SChristian Lamparter 	CARL9170_BW_20,
700319da621SChristian Lamparter 	CARL9170_BW_40_BELOW,
701319da621SChristian Lamparter 	CARL9170_BW_40_ABOVE,
702319da621SChristian Lamparter 
703319da621SChristian Lamparter 	__CARL9170_NUM_BW,
704319da621SChristian Lamparter };
705319da621SChristian Lamparter 
706319da621SChristian Lamparter struct carl9170_phy_freq_entry {
707319da621SChristian Lamparter 	u16 freq;
708319da621SChristian Lamparter 	struct carl9170_phy_freq_params params[__CARL9170_NUM_BW];
709319da621SChristian Lamparter };
710319da621SChristian Lamparter 
711319da621SChristian Lamparter /* NB: must be in sync with channel tables in main! */
712319da621SChristian Lamparter static const struct carl9170_phy_freq_entry carl9170_phy_freq_params[] = {
713319da621SChristian Lamparter /*
714319da621SChristian Lamparter  *	freq,
715319da621SChristian Lamparter  *		20MHz,
716319da621SChristian Lamparter  *		40MHz (below),
717319da621SChristian Lamparter  *		40Mhz (above),
718319da621SChristian Lamparter  */
719319da621SChristian Lamparter 	{ 2412, {
720319da621SChristian Lamparter 		{ 3, 21737, 3, 19563, },
721319da621SChristian Lamparter 		{ 3, 21827, 3, 19644, },
722319da621SChristian Lamparter 		{ 3, 21647, 3, 19482, },
723319da621SChristian Lamparter 	} },
724319da621SChristian Lamparter 	{ 2417, {
725319da621SChristian Lamparter 		{ 3, 21692, 3, 19523, },
726319da621SChristian Lamparter 		{ 3, 21782, 3, 19604, },
727319da621SChristian Lamparter 		{ 3, 21602, 3, 19442, },
728319da621SChristian Lamparter 	} },
729319da621SChristian Lamparter 	{ 2422, {
730319da621SChristian Lamparter 		{ 3, 21647, 3, 19482, },
731319da621SChristian Lamparter 		{ 3, 21737, 3, 19563, },
732319da621SChristian Lamparter 		{ 3, 21558, 3, 19402, },
733319da621SChristian Lamparter 	} },
734319da621SChristian Lamparter 	{ 2427, {
735319da621SChristian Lamparter 		{ 3, 21602, 3, 19442, },
736319da621SChristian Lamparter 		{ 3, 21692, 3, 19523, },
737319da621SChristian Lamparter 		{ 3, 21514, 3, 19362, },
738319da621SChristian Lamparter 	} },
739319da621SChristian Lamparter 	{ 2432, {
740319da621SChristian Lamparter 		{ 3, 21558, 3, 19402, },
741319da621SChristian Lamparter 		{ 3, 21647, 3, 19482, },
742319da621SChristian Lamparter 		{ 3, 21470, 3, 19323, },
743319da621SChristian Lamparter 	} },
744319da621SChristian Lamparter 	{ 2437, {
745319da621SChristian Lamparter 		{ 3, 21514, 3, 19362, },
746319da621SChristian Lamparter 		{ 3, 21602, 3, 19442, },
747319da621SChristian Lamparter 		{ 3, 21426, 3, 19283, },
748319da621SChristian Lamparter 	} },
749319da621SChristian Lamparter 	{ 2442, {
750319da621SChristian Lamparter 		{ 3, 21470, 3, 19323, },
751319da621SChristian Lamparter 		{ 3, 21558, 3, 19402, },
752319da621SChristian Lamparter 		{ 3, 21382, 3, 19244, },
753319da621SChristian Lamparter 	} },
754319da621SChristian Lamparter 	{ 2447, {
755319da621SChristian Lamparter 		{ 3, 21426, 3, 19283, },
756319da621SChristian Lamparter 		{ 3, 21514, 3, 19362, },
757319da621SChristian Lamparter 		{ 3, 21339, 3, 19205, },
758319da621SChristian Lamparter 	} },
759319da621SChristian Lamparter 	{ 2452, {
760319da621SChristian Lamparter 		{ 3, 21382, 3, 19244, },
761319da621SChristian Lamparter 		{ 3, 21470, 3, 19323, },
762319da621SChristian Lamparter 		{ 3, 21295, 3, 19166, },
763319da621SChristian Lamparter 	} },
764319da621SChristian Lamparter 	{ 2457, {
765319da621SChristian Lamparter 		{ 3, 21339, 3, 19205, },
766319da621SChristian Lamparter 		{ 3, 21426, 3, 19283, },
767319da621SChristian Lamparter 		{ 3, 21252, 3, 19127, },
768319da621SChristian Lamparter 	} },
769319da621SChristian Lamparter 	{ 2462, {
770319da621SChristian Lamparter 		{ 3, 21295, 3, 19166, },
771319da621SChristian Lamparter 		{ 3, 21382, 3, 19244, },
772319da621SChristian Lamparter 		{ 3, 21209, 3, 19088, },
773319da621SChristian Lamparter 	} },
774319da621SChristian Lamparter 	{ 2467, {
775319da621SChristian Lamparter 		{ 3, 21252, 3, 19127, },
776319da621SChristian Lamparter 		{ 3, 21339, 3, 19205, },
777319da621SChristian Lamparter 		{ 3, 21166, 3, 19050, },
778319da621SChristian Lamparter 	} },
779319da621SChristian Lamparter 	{ 2472, {
780319da621SChristian Lamparter 		{ 3, 21209, 3, 19088, },
781319da621SChristian Lamparter 		{ 3, 21295, 3, 19166, },
782319da621SChristian Lamparter 		{ 3, 21124, 3, 19011, },
783319da621SChristian Lamparter 	} },
784319da621SChristian Lamparter 	{ 2484, {
785319da621SChristian Lamparter 		{ 3, 21107, 3, 18996, },
786319da621SChristian Lamparter 		{ 3, 21192, 3, 19073, },
787319da621SChristian Lamparter 		{ 3, 21022, 3, 18920, },
788319da621SChristian Lamparter 	} },
789319da621SChristian Lamparter 	{ 4920, {
790319da621SChristian Lamparter 		{ 4, 21313, 4, 19181, },
791319da621SChristian Lamparter 		{ 4, 21356, 4, 19220, },
792319da621SChristian Lamparter 		{ 4, 21269, 4, 19142, },
793319da621SChristian Lamparter 	} },
794319da621SChristian Lamparter 	{ 4940, {
795319da621SChristian Lamparter 		{ 4, 21226, 4, 19104, },
796319da621SChristian Lamparter 		{ 4, 21269, 4, 19142, },
797319da621SChristian Lamparter 		{ 4, 21183, 4, 19065, },
798319da621SChristian Lamparter 	} },
799319da621SChristian Lamparter 	{ 4960, {
800319da621SChristian Lamparter 		{ 4, 21141, 4, 19027, },
801319da621SChristian Lamparter 		{ 4, 21183, 4, 19065, },
802319da621SChristian Lamparter 		{ 4, 21098, 4, 18988, },
803319da621SChristian Lamparter 	} },
804319da621SChristian Lamparter 	{ 4980, {
805319da621SChristian Lamparter 		{ 4, 21056, 4, 18950, },
806319da621SChristian Lamparter 		{ 4, 21098, 4, 18988, },
807319da621SChristian Lamparter 		{ 4, 21014, 4, 18912, },
808319da621SChristian Lamparter 	} },
809319da621SChristian Lamparter 	{ 5040, {
810319da621SChristian Lamparter 		{ 4, 20805, 4, 18725, },
811319da621SChristian Lamparter 		{ 4, 20846, 4, 18762, },
812319da621SChristian Lamparter 		{ 4, 20764, 4, 18687, },
813319da621SChristian Lamparter 	} },
814319da621SChristian Lamparter 	{ 5060, {
815319da621SChristian Lamparter 		{ 4, 20723, 4, 18651, },
816319da621SChristian Lamparter 		{ 4, 20764, 4, 18687, },
817319da621SChristian Lamparter 		{ 4, 20682, 4, 18614, },
818319da621SChristian Lamparter 	} },
819319da621SChristian Lamparter 	{ 5080, {
820319da621SChristian Lamparter 		{ 4, 20641, 4, 18577, },
821319da621SChristian Lamparter 		{ 4, 20682, 4, 18614, },
822319da621SChristian Lamparter 		{ 4, 20601, 4, 18541, },
823319da621SChristian Lamparter 	} },
824319da621SChristian Lamparter 	{ 5180, {
825319da621SChristian Lamparter 		{ 4, 20243, 4, 18219, },
826319da621SChristian Lamparter 		{ 4, 20282, 4, 18254, },
827319da621SChristian Lamparter 		{ 4, 20204, 4, 18183, },
828319da621SChristian Lamparter 	} },
829319da621SChristian Lamparter 	{ 5200, {
830319da621SChristian Lamparter 		{ 4, 20165, 4, 18148, },
831319da621SChristian Lamparter 		{ 4, 20204, 4, 18183, },
832319da621SChristian Lamparter 		{ 4, 20126, 4, 18114, },
833319da621SChristian Lamparter 	} },
834319da621SChristian Lamparter 	{ 5220, {
835319da621SChristian Lamparter 		{ 4, 20088, 4, 18079, },
836319da621SChristian Lamparter 		{ 4, 20126, 4, 18114, },
837319da621SChristian Lamparter 		{ 4, 20049, 4, 18044, },
838319da621SChristian Lamparter 	} },
839319da621SChristian Lamparter 	{ 5240, {
840319da621SChristian Lamparter 		{ 4, 20011, 4, 18010, },
841319da621SChristian Lamparter 		{ 4, 20049, 4, 18044, },
842319da621SChristian Lamparter 		{ 4, 19973, 4, 17976, },
843319da621SChristian Lamparter 	} },
844319da621SChristian Lamparter 	{ 5260, {
845319da621SChristian Lamparter 		{ 4, 19935, 4, 17941, },
846319da621SChristian Lamparter 		{ 4, 19973, 4, 17976, },
847319da621SChristian Lamparter 		{ 4, 19897, 4, 17907, },
848319da621SChristian Lamparter 	} },
849319da621SChristian Lamparter 	{ 5280, {
850319da621SChristian Lamparter 		{ 4, 19859, 4, 17873, },
851319da621SChristian Lamparter 		{ 4, 19897, 4, 17907, },
852319da621SChristian Lamparter 		{ 4, 19822, 4, 17840, },
853319da621SChristian Lamparter 	} },
854319da621SChristian Lamparter 	{ 5300, {
855319da621SChristian Lamparter 		{ 4, 19784, 4, 17806, },
856319da621SChristian Lamparter 		{ 4, 19822, 4, 17840, },
857319da621SChristian Lamparter 		{ 4, 19747, 4, 17772, },
858319da621SChristian Lamparter 	} },
859319da621SChristian Lamparter 	{ 5320, {
860319da621SChristian Lamparter 		{ 4, 19710, 4, 17739, },
861319da621SChristian Lamparter 		{ 4, 19747, 4, 17772, },
862319da621SChristian Lamparter 		{ 4, 19673, 4, 17706, },
863319da621SChristian Lamparter 	} },
864319da621SChristian Lamparter 	{ 5500, {
865319da621SChristian Lamparter 		{ 4, 19065, 4, 17159, },
866319da621SChristian Lamparter 		{ 4, 19100, 4, 17190, },
867319da621SChristian Lamparter 		{ 4, 19030, 4, 17127, },
868319da621SChristian Lamparter 	} },
869319da621SChristian Lamparter 	{ 5520, {
870319da621SChristian Lamparter 		{ 4, 18996, 4, 17096, },
871319da621SChristian Lamparter 		{ 4, 19030, 4, 17127, },
872319da621SChristian Lamparter 		{ 4, 18962, 4, 17065, },
873319da621SChristian Lamparter 	} },
874319da621SChristian Lamparter 	{ 5540, {
875319da621SChristian Lamparter 		{ 4, 18927, 4, 17035, },
876319da621SChristian Lamparter 		{ 4, 18962, 4, 17065, },
877319da621SChristian Lamparter 		{ 4, 18893, 4, 17004, },
878319da621SChristian Lamparter 	} },
879319da621SChristian Lamparter 	{ 5560, {
880319da621SChristian Lamparter 		{ 4, 18859, 4, 16973, },
881319da621SChristian Lamparter 		{ 4, 18893, 4, 17004, },
882319da621SChristian Lamparter 		{ 4, 18825, 4, 16943, },
883319da621SChristian Lamparter 	} },
884319da621SChristian Lamparter 	{ 5580, {
885319da621SChristian Lamparter 		{ 4, 18792, 4, 16913, },
886319da621SChristian Lamparter 		{ 4, 18825, 4, 16943, },
887319da621SChristian Lamparter 		{ 4, 18758, 4, 16882, },
888319da621SChristian Lamparter 	} },
889319da621SChristian Lamparter 	{ 5600, {
890319da621SChristian Lamparter 		{ 4, 18725, 4, 16852, },
891319da621SChristian Lamparter 		{ 4, 18758, 4, 16882, },
892319da621SChristian Lamparter 		{ 4, 18691, 4, 16822, },
893319da621SChristian Lamparter 	} },
894319da621SChristian Lamparter 	{ 5620, {
895319da621SChristian Lamparter 		{ 4, 18658, 4, 16792, },
896319da621SChristian Lamparter 		{ 4, 18691, 4, 16822, },
897319da621SChristian Lamparter 		{ 4, 18625, 4, 16762, },
898319da621SChristian Lamparter 	} },
899319da621SChristian Lamparter 	{ 5640, {
900319da621SChristian Lamparter 		{ 4, 18592, 4, 16733, },
901319da621SChristian Lamparter 		{ 4, 18625, 4, 16762, },
902319da621SChristian Lamparter 		{ 4, 18559, 4, 16703, },
903319da621SChristian Lamparter 	} },
904319da621SChristian Lamparter 	{ 5660, {
905319da621SChristian Lamparter 		{ 4, 18526, 4, 16673, },
906319da621SChristian Lamparter 		{ 4, 18559, 4, 16703, },
907319da621SChristian Lamparter 		{ 4, 18493, 4, 16644, },
908319da621SChristian Lamparter 	} },
909319da621SChristian Lamparter 	{ 5680, {
910319da621SChristian Lamparter 		{ 4, 18461, 4, 16615, },
911319da621SChristian Lamparter 		{ 4, 18493, 4, 16644, },
912319da621SChristian Lamparter 		{ 4, 18428, 4, 16586, },
913319da621SChristian Lamparter 	} },
914319da621SChristian Lamparter 	{ 5700, {
915319da621SChristian Lamparter 		{ 4, 18396, 4, 16556, },
916319da621SChristian Lamparter 		{ 4, 18428, 4, 16586, },
917319da621SChristian Lamparter 		{ 4, 18364, 4, 16527, },
918319da621SChristian Lamparter 	} },
919319da621SChristian Lamparter 	{ 5745, {
920319da621SChristian Lamparter 		{ 4, 18252, 4, 16427, },
921319da621SChristian Lamparter 		{ 4, 18284, 4, 16455, },
922319da621SChristian Lamparter 		{ 4, 18220, 4, 16398, },
923319da621SChristian Lamparter 	} },
924319da621SChristian Lamparter 	{ 5765, {
925319da621SChristian Lamparter 		{ 4, 18189, 5, 32740, },
926319da621SChristian Lamparter 		{ 4, 18220, 4, 16398, },
927319da621SChristian Lamparter 		{ 4, 18157, 5, 32683, },
928319da621SChristian Lamparter 	} },
929319da621SChristian Lamparter 	{ 5785, {
930319da621SChristian Lamparter 		{ 4, 18126, 5, 32626, },
931319da621SChristian Lamparter 		{ 4, 18157, 5, 32683, },
932319da621SChristian Lamparter 		{ 4, 18094, 5, 32570, },
933319da621SChristian Lamparter 	} },
934319da621SChristian Lamparter 	{ 5805, {
935319da621SChristian Lamparter 		{ 4, 18063, 5, 32514, },
936319da621SChristian Lamparter 		{ 4, 18094, 5, 32570, },
937319da621SChristian Lamparter 		{ 4, 18032, 5, 32458, },
938319da621SChristian Lamparter 	} },
939319da621SChristian Lamparter 	{ 5825, {
940319da621SChristian Lamparter 		{ 4, 18001, 5, 32402, },
941319da621SChristian Lamparter 		{ 4, 18032, 5, 32458, },
942319da621SChristian Lamparter 		{ 4, 17970, 5, 32347, },
943319da621SChristian Lamparter 	} },
944319da621SChristian Lamparter 	{ 5170, {
945319da621SChristian Lamparter 		{ 4, 20282, 4, 18254, },
946319da621SChristian Lamparter 		{ 4, 20321, 4, 18289, },
947319da621SChristian Lamparter 		{ 4, 20243, 4, 18219, },
948319da621SChristian Lamparter 	} },
949319da621SChristian Lamparter 	{ 5190, {
950319da621SChristian Lamparter 		{ 4, 20204, 4, 18183, },
951319da621SChristian Lamparter 		{ 4, 20243, 4, 18219, },
952319da621SChristian Lamparter 		{ 4, 20165, 4, 18148, },
953319da621SChristian Lamparter 	} },
954319da621SChristian Lamparter 	{ 5210, {
955319da621SChristian Lamparter 		{ 4, 20126, 4, 18114, },
956319da621SChristian Lamparter 		{ 4, 20165, 4, 18148, },
957319da621SChristian Lamparter 		{ 4, 20088, 4, 18079, },
958319da621SChristian Lamparter 	} },
959319da621SChristian Lamparter 	{ 5230, {
960319da621SChristian Lamparter 		{ 4, 20049, 4, 18044, },
961319da621SChristian Lamparter 		{ 4, 20088, 4, 18079, },
962319da621SChristian Lamparter 		{ 4, 20011, 4, 18010, },
963319da621SChristian Lamparter 	} },
964319da621SChristian Lamparter };
965319da621SChristian Lamparter 
carl9170_init_rf_bank4_pwr(struct ar9170 * ar,bool band5ghz,u32 freq,enum carl9170_bw bw)966319da621SChristian Lamparter static int carl9170_init_rf_bank4_pwr(struct ar9170 *ar, bool band5ghz,
967319da621SChristian Lamparter 				      u32 freq, enum carl9170_bw bw)
968319da621SChristian Lamparter {
969319da621SChristian Lamparter 	int err;
970319da621SChristian Lamparter 	u32 d0, d1, td0, td1, fd0, fd1;
971319da621SChristian Lamparter 	u8 chansel;
972319da621SChristian Lamparter 	u8 refsel0 = 1, refsel1 = 0;
973319da621SChristian Lamparter 	u8 lf_synth = 0;
974319da621SChristian Lamparter 
975319da621SChristian Lamparter 	switch (bw) {
976319da621SChristian Lamparter 	case CARL9170_BW_40_ABOVE:
977319da621SChristian Lamparter 		freq += 10;
978319da621SChristian Lamparter 		break;
979319da621SChristian Lamparter 	case CARL9170_BW_40_BELOW:
980319da621SChristian Lamparter 		freq -= 10;
981319da621SChristian Lamparter 		break;
982319da621SChristian Lamparter 	case CARL9170_BW_20:
983319da621SChristian Lamparter 		break;
984319da621SChristian Lamparter 	default:
985319da621SChristian Lamparter 		BUG();
986319da621SChristian Lamparter 		return -ENOSYS;
987319da621SChristian Lamparter 	}
988319da621SChristian Lamparter 
989319da621SChristian Lamparter 	if (band5ghz) {
990319da621SChristian Lamparter 		if (freq % 10) {
991319da621SChristian Lamparter 			chansel = (freq - 4800) / 5;
992319da621SChristian Lamparter 		} else {
993319da621SChristian Lamparter 			chansel = ((freq - 4800) / 10) * 2;
994319da621SChristian Lamparter 			refsel0 = 0;
995319da621SChristian Lamparter 			refsel1 = 1;
996319da621SChristian Lamparter 		}
9977a1283d8SJoe Perches 		chansel = bitrev8(chansel);
998319da621SChristian Lamparter 	} else {
999319da621SChristian Lamparter 		if (freq == 2484) {
1000319da621SChristian Lamparter 			chansel = 10 + (freq - 2274) / 5;
1001319da621SChristian Lamparter 			lf_synth = 1;
1002319da621SChristian Lamparter 		} else
1003319da621SChristian Lamparter 			chansel = 16 + (freq - 2272) / 5;
1004319da621SChristian Lamparter 		chansel *= 4;
10057a1283d8SJoe Perches 		chansel = bitrev8(chansel);
1006319da621SChristian Lamparter 	}
1007319da621SChristian Lamparter 
1008319da621SChristian Lamparter 	d1 =	chansel;
1009319da621SChristian Lamparter 	d0 =	0x21 |
1010319da621SChristian Lamparter 		refsel0 << 3 |
1011319da621SChristian Lamparter 		refsel1 << 2 |
1012319da621SChristian Lamparter 		lf_synth << 1;
1013319da621SChristian Lamparter 	td0 =	d0 & 0x1f;
1014319da621SChristian Lamparter 	td1 =	d1 & 0x1f;
1015319da621SChristian Lamparter 	fd0 =	td1 << 5 | td0;
1016319da621SChristian Lamparter 
1017319da621SChristian Lamparter 	td0 =	(d0 >> 5) & 0x7;
1018319da621SChristian Lamparter 	td1 =	(d1 >> 5) & 0x7;
1019319da621SChristian Lamparter 	fd1 =	td1 << 5 | td0;
1020319da621SChristian Lamparter 
1021319da621SChristian Lamparter 	carl9170_regwrite_begin(ar);
1022319da621SChristian Lamparter 
1023319da621SChristian Lamparter 	carl9170_regwrite(0x1c58b0, fd0);
1024319da621SChristian Lamparter 	carl9170_regwrite(0x1c58e8, fd1);
1025319da621SChristian Lamparter 
1026319da621SChristian Lamparter 	carl9170_regwrite_finish();
1027319da621SChristian Lamparter 	err = carl9170_regwrite_result();
1028319da621SChristian Lamparter 	if (err)
1029319da621SChristian Lamparter 		return err;
1030319da621SChristian Lamparter 
1031319da621SChristian Lamparter 	return 0;
1032319da621SChristian Lamparter }
1033319da621SChristian Lamparter 
1034319da621SChristian Lamparter static const struct carl9170_phy_freq_params *
carl9170_get_hw_dyn_params(struct ieee80211_channel * channel,enum carl9170_bw bw)1035319da621SChristian Lamparter carl9170_get_hw_dyn_params(struct ieee80211_channel *channel,
1036319da621SChristian Lamparter 			   enum carl9170_bw bw)
1037319da621SChristian Lamparter {
1038319da621SChristian Lamparter 	unsigned int chanidx = 0;
1039319da621SChristian Lamparter 	u16 freq = 2412;
1040319da621SChristian Lamparter 
1041319da621SChristian Lamparter 	if (channel) {
1042319da621SChristian Lamparter 		chanidx = channel->hw_value;
1043319da621SChristian Lamparter 		freq = channel->center_freq;
1044319da621SChristian Lamparter 	}
1045319da621SChristian Lamparter 
1046319da621SChristian Lamparter 	BUG_ON(chanidx >= ARRAY_SIZE(carl9170_phy_freq_params));
1047319da621SChristian Lamparter 
1048319da621SChristian Lamparter 	BUILD_BUG_ON(__CARL9170_NUM_BW != 3);
1049319da621SChristian Lamparter 
1050319da621SChristian Lamparter 	WARN_ON(carl9170_phy_freq_params[chanidx].freq != freq);
1051319da621SChristian Lamparter 
1052319da621SChristian Lamparter 	return &carl9170_phy_freq_params[chanidx].params[bw];
1053319da621SChristian Lamparter }
1054319da621SChristian Lamparter 
carl9170_find_freq_idx(int nfreqs,u8 * freqs,u8 f)1055319da621SChristian Lamparter static int carl9170_find_freq_idx(int nfreqs, u8 *freqs, u8 f)
1056319da621SChristian Lamparter {
1057319da621SChristian Lamparter 	int idx = nfreqs - 2;
1058319da621SChristian Lamparter 
1059319da621SChristian Lamparter 	while (idx >= 0) {
1060319da621SChristian Lamparter 		if (f >= freqs[idx])
1061319da621SChristian Lamparter 			return idx;
1062319da621SChristian Lamparter 		idx--;
1063319da621SChristian Lamparter 	}
1064319da621SChristian Lamparter 
1065319da621SChristian Lamparter 	return 0;
1066319da621SChristian Lamparter }
1067319da621SChristian Lamparter 
carl9170_interpolate_s32(s32 x,s32 x1,s32 y1,s32 x2,s32 y2)1068319da621SChristian Lamparter static s32 carl9170_interpolate_s32(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
1069319da621SChristian Lamparter {
1070319da621SChristian Lamparter 	/* nothing to interpolate, it's horizontal */
1071319da621SChristian Lamparter 	if (y2 == y1)
1072319da621SChristian Lamparter 		return y1;
1073319da621SChristian Lamparter 
1074319da621SChristian Lamparter 	/* check if we hit one of the edges */
1075319da621SChristian Lamparter 	if (x == x1)
1076319da621SChristian Lamparter 		return y1;
1077319da621SChristian Lamparter 	if (x == x2)
1078319da621SChristian Lamparter 		return y2;
1079319da621SChristian Lamparter 
1080319da621SChristian Lamparter 	/* x1 == x2 is bad, hopefully == x */
1081319da621SChristian Lamparter 	if (x2 == x1)
1082319da621SChristian Lamparter 		return y1;
1083319da621SChristian Lamparter 
1084319da621SChristian Lamparter 	return y1 + (((y2 - y1) * (x - x1)) / (x2 - x1));
1085319da621SChristian Lamparter }
1086319da621SChristian Lamparter 
carl9170_interpolate_u8(u8 x,u8 x1,u8 y1,u8 x2,u8 y2)1087319da621SChristian Lamparter static u8 carl9170_interpolate_u8(u8 x, u8 x1, u8 y1, u8 x2, u8 y2)
1088319da621SChristian Lamparter {
1089319da621SChristian Lamparter #define SHIFT		8
1090319da621SChristian Lamparter 	s32 y;
1091319da621SChristian Lamparter 
1092319da621SChristian Lamparter 	y = carl9170_interpolate_s32(x << SHIFT, x1 << SHIFT,
1093319da621SChristian Lamparter 		y1 << SHIFT, x2 << SHIFT, y2 << SHIFT);
1094319da621SChristian Lamparter 
1095319da621SChristian Lamparter 	/*
1096319da621SChristian Lamparter 	 * XXX: unwrap this expression
1097319da621SChristian Lamparter 	 *	Isn't it just DIV_ROUND_UP(y, 1<<SHIFT)?
1098319da621SChristian Lamparter 	 *	Can we rely on the compiler to optimise away the div?
1099319da621SChristian Lamparter 	 */
1100319da621SChristian Lamparter 	return (y >> SHIFT) + ((y & (1 << (SHIFT - 1))) >> (SHIFT - 1));
1101319da621SChristian Lamparter #undef SHIFT
1102319da621SChristian Lamparter }
1103319da621SChristian Lamparter 
carl9170_interpolate_val(u8 x,u8 * x_array,u8 * y_array)1104319da621SChristian Lamparter static u8 carl9170_interpolate_val(u8 x, u8 *x_array, u8 *y_array)
1105319da621SChristian Lamparter {
1106319da621SChristian Lamparter 	int i;
1107319da621SChristian Lamparter 
1108319da621SChristian Lamparter 	for (i = 0; i < 3; i++) {
1109319da621SChristian Lamparter 		if (x <= x_array[i + 1])
1110319da621SChristian Lamparter 			break;
1111319da621SChristian Lamparter 	}
1112319da621SChristian Lamparter 
1113319da621SChristian Lamparter 	return carl9170_interpolate_u8(x, x_array[i], y_array[i],
1114319da621SChristian Lamparter 		x_array[i + 1], y_array[i + 1]);
1115319da621SChristian Lamparter }
1116319da621SChristian Lamparter 
carl9170_set_freq_cal_data(struct ar9170 * ar,struct ieee80211_channel * channel)1117319da621SChristian Lamparter static int carl9170_set_freq_cal_data(struct ar9170 *ar,
1118319da621SChristian Lamparter 	struct ieee80211_channel *channel)
1119319da621SChristian Lamparter {
1120319da621SChristian Lamparter 	u8 *cal_freq_pier;
1121319da621SChristian Lamparter 	u8 vpds[2][AR5416_PD_GAIN_ICEPTS];
1122319da621SChristian Lamparter 	u8 pwrs[2][AR5416_PD_GAIN_ICEPTS];
1123319da621SChristian Lamparter 	int chain, idx, i;
1124319da621SChristian Lamparter 	u32 phy_data = 0;
1125319da621SChristian Lamparter 	u8 f, tmp;
1126319da621SChristian Lamparter 
1127319da621SChristian Lamparter 	switch (channel->band) {
1128*57fbcce3SJohannes Berg 	case NL80211_BAND_2GHZ:
1129319da621SChristian Lamparter 		f = channel->center_freq - 2300;
1130319da621SChristian Lamparter 		cal_freq_pier = ar->eeprom.cal_freq_pier_2G;
1131319da621SChristian Lamparter 		i = AR5416_NUM_2G_CAL_PIERS - 1;
1132319da621SChristian Lamparter 		break;
1133319da621SChristian Lamparter 
1134*57fbcce3SJohannes Berg 	case NL80211_BAND_5GHZ:
1135319da621SChristian Lamparter 		f = (channel->center_freq - 4800) / 5;
1136319da621SChristian Lamparter 		cal_freq_pier = ar->eeprom.cal_freq_pier_5G;
1137319da621SChristian Lamparter 		i = AR5416_NUM_5G_CAL_PIERS - 1;
1138319da621SChristian Lamparter 		break;
1139319da621SChristian Lamparter 
1140319da621SChristian Lamparter 	default:
1141319da621SChristian Lamparter 		return -EINVAL;
1142319da621SChristian Lamparter 	}
1143319da621SChristian Lamparter 
1144319da621SChristian Lamparter 	for (; i >= 0; i--) {
1145319da621SChristian Lamparter 		if (cal_freq_pier[i] != 0xff)
1146319da621SChristian Lamparter 			break;
1147319da621SChristian Lamparter 	}
1148319da621SChristian Lamparter 	if (i < 0)
1149319da621SChristian Lamparter 		return -EINVAL;
1150319da621SChristian Lamparter 
1151319da621SChristian Lamparter 	idx = carl9170_find_freq_idx(i, cal_freq_pier, f);
1152319da621SChristian Lamparter 
1153319da621SChristian Lamparter 	carl9170_regwrite_begin(ar);
1154319da621SChristian Lamparter 
1155319da621SChristian Lamparter 	for (chain = 0; chain < AR5416_MAX_CHAINS; chain++) {
1156319da621SChristian Lamparter 		for (i = 0; i < AR5416_PD_GAIN_ICEPTS; i++) {
1157319da621SChristian Lamparter 			struct ar9170_calibration_data_per_freq *cal_pier_data;
1158319da621SChristian Lamparter 			int j;
1159319da621SChristian Lamparter 
1160319da621SChristian Lamparter 			switch (channel->band) {
1161*57fbcce3SJohannes Berg 			case NL80211_BAND_2GHZ:
1162319da621SChristian Lamparter 				cal_pier_data = &ar->eeprom.
1163319da621SChristian Lamparter 					cal_pier_data_2G[chain][idx];
1164319da621SChristian Lamparter 				break;
1165319da621SChristian Lamparter 
1166*57fbcce3SJohannes Berg 			case NL80211_BAND_5GHZ:
1167319da621SChristian Lamparter 				cal_pier_data = &ar->eeprom.
1168319da621SChristian Lamparter 					cal_pier_data_5G[chain][idx];
1169319da621SChristian Lamparter 				break;
1170319da621SChristian Lamparter 
1171319da621SChristian Lamparter 			default:
1172319da621SChristian Lamparter 				return -EINVAL;
1173319da621SChristian Lamparter 			}
1174319da621SChristian Lamparter 
1175319da621SChristian Lamparter 			for (j = 0; j < 2; j++) {
1176319da621SChristian Lamparter 				vpds[j][i] = carl9170_interpolate_u8(f,
1177319da621SChristian Lamparter 					cal_freq_pier[idx],
1178319da621SChristian Lamparter 					cal_pier_data->vpd_pdg[j][i],
1179319da621SChristian Lamparter 					cal_freq_pier[idx + 1],
1180319da621SChristian Lamparter 					cal_pier_data[1].vpd_pdg[j][i]);
1181319da621SChristian Lamparter 
1182319da621SChristian Lamparter 				pwrs[j][i] = carl9170_interpolate_u8(f,
1183319da621SChristian Lamparter 					cal_freq_pier[idx],
1184319da621SChristian Lamparter 					cal_pier_data->pwr_pdg[j][i],
1185319da621SChristian Lamparter 					cal_freq_pier[idx + 1],
1186319da621SChristian Lamparter 					cal_pier_data[1].pwr_pdg[j][i]) / 2;
1187319da621SChristian Lamparter 			}
1188319da621SChristian Lamparter 		}
1189319da621SChristian Lamparter 
1190319da621SChristian Lamparter 		for (i = 0; i < 76; i++) {
1191319da621SChristian Lamparter 			if (i < 25) {
1192319da621SChristian Lamparter 				tmp = carl9170_interpolate_val(i, &pwrs[0][0],
1193319da621SChristian Lamparter 							       &vpds[0][0]);
1194319da621SChristian Lamparter 			} else {
1195319da621SChristian Lamparter 				tmp = carl9170_interpolate_val(i - 12,
1196319da621SChristian Lamparter 							       &pwrs[1][0],
1197319da621SChristian Lamparter 							       &vpds[1][0]);
1198319da621SChristian Lamparter 			}
1199319da621SChristian Lamparter 
1200319da621SChristian Lamparter 			phy_data |= tmp << ((i & 3) << 3);
1201319da621SChristian Lamparter 			if ((i & 3) == 3) {
1202319da621SChristian Lamparter 				carl9170_regwrite(0x1c6280 + chain * 0x1000 +
1203319da621SChristian Lamparter 						  (i & ~3), phy_data);
1204319da621SChristian Lamparter 				phy_data = 0;
1205319da621SChristian Lamparter 			}
1206319da621SChristian Lamparter 		}
1207319da621SChristian Lamparter 
1208319da621SChristian Lamparter 		for (i = 19; i < 32; i++)
1209319da621SChristian Lamparter 			carl9170_regwrite(0x1c6280 + chain * 0x1000 + (i << 2),
1210319da621SChristian Lamparter 					  0x0);
1211319da621SChristian Lamparter 	}
1212319da621SChristian Lamparter 
1213319da621SChristian Lamparter 	carl9170_regwrite_finish();
1214319da621SChristian Lamparter 	return carl9170_regwrite_result();
1215319da621SChristian Lamparter }
1216319da621SChristian Lamparter 
carl9170_get_max_edge_power(struct ar9170 * ar,u32 freq,struct ar9170_calctl_edges edges[])1217319da621SChristian Lamparter static u8 carl9170_get_max_edge_power(struct ar9170 *ar,
1218319da621SChristian Lamparter 	u32 freq, struct ar9170_calctl_edges edges[])
1219319da621SChristian Lamparter {
1220319da621SChristian Lamparter 	int i;
1221319da621SChristian Lamparter 	u8 rc = AR5416_MAX_RATE_POWER;
1222319da621SChristian Lamparter 	u8 f;
1223319da621SChristian Lamparter 	if (freq < 3000)
1224319da621SChristian Lamparter 		f = freq - 2300;
1225319da621SChristian Lamparter 	else
1226319da621SChristian Lamparter 		f = (freq - 4800) / 5;
1227319da621SChristian Lamparter 
1228319da621SChristian Lamparter 	for (i = 0; i < AR5416_NUM_BAND_EDGES; i++) {
1229319da621SChristian Lamparter 		if (edges[i].channel == 0xff)
1230319da621SChristian Lamparter 			break;
1231319da621SChristian Lamparter 		if (f == edges[i].channel) {
1232319da621SChristian Lamparter 			/* exact freq match */
1233319da621SChristian Lamparter 			rc = edges[i].power_flags & ~AR9170_CALCTL_EDGE_FLAGS;
1234319da621SChristian Lamparter 			break;
1235319da621SChristian Lamparter 		}
1236319da621SChristian Lamparter 		if (i > 0 && f < edges[i].channel) {
1237319da621SChristian Lamparter 			if (f > edges[i - 1].channel &&
1238319da621SChristian Lamparter 			    edges[i - 1].power_flags &
1239319da621SChristian Lamparter 			    AR9170_CALCTL_EDGE_FLAGS) {
1240319da621SChristian Lamparter 				/* lower channel has the inband flag set */
1241319da621SChristian Lamparter 				rc = edges[i - 1].power_flags &
1242319da621SChristian Lamparter 					~AR9170_CALCTL_EDGE_FLAGS;
1243319da621SChristian Lamparter 			}
1244319da621SChristian Lamparter 			break;
1245319da621SChristian Lamparter 		}
1246319da621SChristian Lamparter 	}
1247319da621SChristian Lamparter 
1248319da621SChristian Lamparter 	if (i == AR5416_NUM_BAND_EDGES) {
1249319da621SChristian Lamparter 		if (f > edges[i - 1].channel &&
1250319da621SChristian Lamparter 		    edges[i - 1].power_flags & AR9170_CALCTL_EDGE_FLAGS) {
1251319da621SChristian Lamparter 			/* lower channel has the inband flag set */
1252319da621SChristian Lamparter 			rc = edges[i - 1].power_flags &
1253319da621SChristian Lamparter 				~AR9170_CALCTL_EDGE_FLAGS;
1254319da621SChristian Lamparter 		}
1255319da621SChristian Lamparter 	}
1256319da621SChristian Lamparter 	return rc;
1257319da621SChristian Lamparter }
1258319da621SChristian Lamparter 
carl9170_get_heavy_clip(struct ar9170 * ar,u32 freq,enum carl9170_bw bw,struct ar9170_calctl_edges edges[])1259319da621SChristian Lamparter static u8 carl9170_get_heavy_clip(struct ar9170 *ar, u32 freq,
1260319da621SChristian Lamparter 	enum carl9170_bw bw, struct ar9170_calctl_edges edges[])
1261319da621SChristian Lamparter {
1262319da621SChristian Lamparter 	u8 f;
1263319da621SChristian Lamparter 	int i;
1264319da621SChristian Lamparter 	u8 rc = 0;
1265319da621SChristian Lamparter 
1266319da621SChristian Lamparter 	if (freq < 3000)
1267319da621SChristian Lamparter 		f = freq - 2300;
1268319da621SChristian Lamparter 	else
1269319da621SChristian Lamparter 		f = (freq - 4800) / 5;
1270319da621SChristian Lamparter 
1271319da621SChristian Lamparter 	if (bw == CARL9170_BW_40_BELOW || bw == CARL9170_BW_40_ABOVE)
1272319da621SChristian Lamparter 		rc |= 0xf0;
1273319da621SChristian Lamparter 
1274319da621SChristian Lamparter 	for (i = 0; i < AR5416_NUM_BAND_EDGES; i++) {
1275319da621SChristian Lamparter 		if (edges[i].channel == 0xff)
1276319da621SChristian Lamparter 			break;
1277319da621SChristian Lamparter 		if (f == edges[i].channel) {
1278319da621SChristian Lamparter 			if (!(edges[i].power_flags & AR9170_CALCTL_EDGE_FLAGS))
1279319da621SChristian Lamparter 				rc |= 0x0f;
1280319da621SChristian Lamparter 			break;
1281319da621SChristian Lamparter 		}
1282319da621SChristian Lamparter 	}
1283319da621SChristian Lamparter 
1284319da621SChristian Lamparter 	return rc;
1285319da621SChristian Lamparter }
1286319da621SChristian Lamparter 
1287319da621SChristian Lamparter /*
1288319da621SChristian Lamparter  * calculate the conformance test limits and the heavy clip parameter
1289319da621SChristian Lamparter  * and apply them to ar->power* (derived from otus hal/hpmain.c, line 3706)
1290319da621SChristian Lamparter  */
carl9170_calc_ctl(struct ar9170 * ar,u32 freq,enum carl9170_bw bw)1291319da621SChristian Lamparter static void carl9170_calc_ctl(struct ar9170 *ar, u32 freq, enum carl9170_bw bw)
1292319da621SChristian Lamparter {
1293319da621SChristian Lamparter 	u8 ctl_grp; /* CTL group */
1294319da621SChristian Lamparter 	u8 ctl_idx; /* CTL index */
1295319da621SChristian Lamparter 	int i, j;
1296319da621SChristian Lamparter 	struct ctl_modes {
1297319da621SChristian Lamparter 		u8 ctl_mode;
1298319da621SChristian Lamparter 		u8 max_power;
1299319da621SChristian Lamparter 		u8 *pwr_cal_data;
1300319da621SChristian Lamparter 		int pwr_cal_len;
1301319da621SChristian Lamparter 	} *modes;
1302319da621SChristian Lamparter 
1303319da621SChristian Lamparter 	/*
1304319da621SChristian Lamparter 	 * order is relevant in the mode_list_*: we fall back to the
1305319da621SChristian Lamparter 	 * lower indices if any mode is missed in the EEPROM.
1306319da621SChristian Lamparter 	 */
1307319da621SChristian Lamparter 	struct ctl_modes mode_list_2ghz[] = {
1308319da621SChristian Lamparter 		{ CTL_11B, 0, ar->power_2G_cck, 4 },
1309319da621SChristian Lamparter 		{ CTL_11G, 0, ar->power_2G_ofdm, 4 },
1310319da621SChristian Lamparter 		{ CTL_2GHT20, 0, ar->power_2G_ht20, 8 },
1311319da621SChristian Lamparter 		{ CTL_2GHT40, 0, ar->power_2G_ht40, 8 },
1312319da621SChristian Lamparter 	};
1313319da621SChristian Lamparter 	struct ctl_modes mode_list_5ghz[] = {
1314319da621SChristian Lamparter 		{ CTL_11A, 0, ar->power_5G_leg, 4 },
1315319da621SChristian Lamparter 		{ CTL_5GHT20, 0, ar->power_5G_ht20, 8 },
1316319da621SChristian Lamparter 		{ CTL_5GHT40, 0, ar->power_5G_ht40, 8 },
1317319da621SChristian Lamparter 	};
1318319da621SChristian Lamparter 	int nr_modes;
1319319da621SChristian Lamparter 
1320319da621SChristian Lamparter #define EDGES(c, n) (ar->eeprom.ctl_data[c].control_edges[n])
1321319da621SChristian Lamparter 
1322319da621SChristian Lamparter 	ar->heavy_clip = 0;
1323319da621SChristian Lamparter 
1324319da621SChristian Lamparter 	/*
1325319da621SChristian Lamparter 	 * TODO: investigate the differences between OTUS'
1326319da621SChristian Lamparter 	 * hpreg.c::zfHpGetRegulatoryDomain() and
1327319da621SChristian Lamparter 	 * ath/regd.c::ath_regd_get_band_ctl() -
1328319da621SChristian Lamparter 	 * e.g. for FCC3_WORLD the OTUS procedure
1329319da621SChristian Lamparter 	 * always returns CTL_FCC, while the one in ath/ delivers
1330319da621SChristian Lamparter 	 * CTL_ETSI for 2GHz and CTL_FCC for 5GHz.
1331319da621SChristian Lamparter 	 */
1332319da621SChristian Lamparter 	ctl_grp = ath_regd_get_band_ctl(&ar->common.regulatory,
1333675a0b04SKarl Beldan 					ar->hw->conf.chandef.chan->band);
1334319da621SChristian Lamparter 
1335319da621SChristian Lamparter 	/* ctl group not found - either invalid band (NO_CTL) or ww roaming */
1336319da621SChristian Lamparter 	if (ctl_grp == NO_CTL || ctl_grp == SD_NO_CTL)
1337319da621SChristian Lamparter 		ctl_grp = CTL_FCC;
1338319da621SChristian Lamparter 
1339319da621SChristian Lamparter 	if (ctl_grp != CTL_FCC)
1340319da621SChristian Lamparter 		/* skip CTL and heavy clip for CTL_MKK and CTL_ETSI */
1341319da621SChristian Lamparter 		return;
1342319da621SChristian Lamparter 
1343*57fbcce3SJohannes Berg 	if (ar->hw->conf.chandef.chan->band == NL80211_BAND_2GHZ) {
1344319da621SChristian Lamparter 		modes = mode_list_2ghz;
1345319da621SChristian Lamparter 		nr_modes = ARRAY_SIZE(mode_list_2ghz);
1346319da621SChristian Lamparter 	} else {
1347319da621SChristian Lamparter 		modes = mode_list_5ghz;
1348319da621SChristian Lamparter 		nr_modes = ARRAY_SIZE(mode_list_5ghz);
1349319da621SChristian Lamparter 	}
1350319da621SChristian Lamparter 
1351319da621SChristian Lamparter 	for (i = 0; i < nr_modes; i++) {
1352319da621SChristian Lamparter 		u8 c = ctl_grp | modes[i].ctl_mode;
1353319da621SChristian Lamparter 		for (ctl_idx = 0; ctl_idx < AR5416_NUM_CTLS; ctl_idx++)
1354319da621SChristian Lamparter 			if (c == ar->eeprom.ctl_index[ctl_idx])
1355319da621SChristian Lamparter 				break;
1356319da621SChristian Lamparter 		if (ctl_idx < AR5416_NUM_CTLS) {
1357319da621SChristian Lamparter 			int f_off = 0;
1358319da621SChristian Lamparter 
1359319da621SChristian Lamparter 			/*
1360319da621SChristian Lamparter 			 * determine heavy clip parameter
1361319da621SChristian Lamparter 			 * from the 11G edges array
1362319da621SChristian Lamparter 			 */
1363319da621SChristian Lamparter 			if (modes[i].ctl_mode == CTL_11G) {
1364319da621SChristian Lamparter 				ar->heavy_clip =
1365319da621SChristian Lamparter 					carl9170_get_heavy_clip(ar,
1366319da621SChristian Lamparter 						freq, bw, EDGES(ctl_idx, 1));
1367319da621SChristian Lamparter 			}
1368319da621SChristian Lamparter 
1369319da621SChristian Lamparter 			/* adjust freq for 40MHz */
1370319da621SChristian Lamparter 			if (modes[i].ctl_mode == CTL_2GHT40 ||
1371319da621SChristian Lamparter 			    modes[i].ctl_mode == CTL_5GHT40) {
1372319da621SChristian Lamparter 				if (bw == CARL9170_BW_40_BELOW)
1373319da621SChristian Lamparter 					f_off = -10;
1374319da621SChristian Lamparter 				else
1375319da621SChristian Lamparter 					f_off = 10;
1376319da621SChristian Lamparter 			}
1377319da621SChristian Lamparter 
1378319da621SChristian Lamparter 			modes[i].max_power =
1379319da621SChristian Lamparter 				carl9170_get_max_edge_power(ar,
1380319da621SChristian Lamparter 					freq + f_off, EDGES(ctl_idx, 1));
1381319da621SChristian Lamparter 
1382319da621SChristian Lamparter 			/*
1383319da621SChristian Lamparter 			 * TODO: check if the regulatory max. power is
1384319da621SChristian Lamparter 			 * controlled by cfg80211 for DFS.
1385319da621SChristian Lamparter 			 * (hpmain applies it to max_power itself for DFS freq)
1386319da621SChristian Lamparter 			 */
1387319da621SChristian Lamparter 
1388319da621SChristian Lamparter 		} else {
1389319da621SChristian Lamparter 			/*
1390319da621SChristian Lamparter 			 * Workaround in otus driver, hpmain.c, line 3906:
1391319da621SChristian Lamparter 			 * if no data for 5GHT20 are found, take the
1392319da621SChristian Lamparter 			 * legacy 5G value. We extend this here to fallback
1393319da621SChristian Lamparter 			 * from any other HT* or 11G, too.
1394319da621SChristian Lamparter 			 */
1395319da621SChristian Lamparter 			int k = i;
1396319da621SChristian Lamparter 
1397319da621SChristian Lamparter 			modes[i].max_power = AR5416_MAX_RATE_POWER;
1398319da621SChristian Lamparter 			while (k-- > 0) {
1399319da621SChristian Lamparter 				if (modes[k].max_power !=
1400319da621SChristian Lamparter 				    AR5416_MAX_RATE_POWER) {
1401319da621SChristian Lamparter 					modes[i].max_power = modes[k].max_power;
1402319da621SChristian Lamparter 					break;
1403319da621SChristian Lamparter 				}
1404319da621SChristian Lamparter 			}
1405319da621SChristian Lamparter 		}
1406319da621SChristian Lamparter 
1407319da621SChristian Lamparter 		/* apply max power to pwr_cal_data (ar->power_*) */
1408319da621SChristian Lamparter 		for (j = 0; j < modes[i].pwr_cal_len; j++) {
1409319da621SChristian Lamparter 			modes[i].pwr_cal_data[j] = min(modes[i].pwr_cal_data[j],
1410319da621SChristian Lamparter 						       modes[i].max_power);
1411319da621SChristian Lamparter 		}
1412319da621SChristian Lamparter 	}
1413319da621SChristian Lamparter 
1414319da621SChristian Lamparter 	if (ar->heavy_clip & 0xf0) {
1415319da621SChristian Lamparter 		ar->power_2G_ht40[0]--;
1416319da621SChristian Lamparter 		ar->power_2G_ht40[1]--;
1417319da621SChristian Lamparter 		ar->power_2G_ht40[2]--;
1418319da621SChristian Lamparter 	}
1419319da621SChristian Lamparter 	if (ar->heavy_clip & 0xf) {
1420319da621SChristian Lamparter 		ar->power_2G_ht20[0]++;
1421319da621SChristian Lamparter 		ar->power_2G_ht20[1]++;
1422319da621SChristian Lamparter 		ar->power_2G_ht20[2]++;
1423319da621SChristian Lamparter 	}
1424319da621SChristian Lamparter 
1425319da621SChristian Lamparter #undef EDGES
1426319da621SChristian Lamparter }
1427319da621SChristian Lamparter 
carl9170_set_power_cal(struct ar9170 * ar,u32 freq,enum carl9170_bw bw)142867e43de6SChristian Lamparter static void carl9170_set_power_cal(struct ar9170 *ar, u32 freq,
1429319da621SChristian Lamparter 				   enum carl9170_bw bw)
1430319da621SChristian Lamparter {
1431319da621SChristian Lamparter 	struct ar9170_calibration_target_power_legacy *ctpl;
1432319da621SChristian Lamparter 	struct ar9170_calibration_target_power_ht *ctph;
1433319da621SChristian Lamparter 	u8 *ctpres;
1434319da621SChristian Lamparter 	int ntargets;
1435319da621SChristian Lamparter 	int idx, i, n;
143667e43de6SChristian Lamparter 	u8 f;
1437319da621SChristian Lamparter 	u8 pwr_freqs[AR5416_MAX_NUM_TGT_PWRS];
1438319da621SChristian Lamparter 
1439319da621SChristian Lamparter 	if (freq < 3000)
1440319da621SChristian Lamparter 		f = freq - 2300;
1441319da621SChristian Lamparter 	else
1442319da621SChristian Lamparter 		f = (freq - 4800) / 5;
1443319da621SChristian Lamparter 
1444319da621SChristian Lamparter 	/*
1445319da621SChristian Lamparter 	 * cycle through the various modes
1446319da621SChristian Lamparter 	 *
1447319da621SChristian Lamparter 	 * legacy modes first: 5G, 2G CCK, 2G OFDM
1448319da621SChristian Lamparter 	 */
1449319da621SChristian Lamparter 	for (i = 0; i < 3; i++) {
1450319da621SChristian Lamparter 		switch (i) {
1451319da621SChristian Lamparter 		case 0: /* 5 GHz legacy */
1452319da621SChristian Lamparter 			ctpl = &ar->eeprom.cal_tgt_pwr_5G[0];
1453319da621SChristian Lamparter 			ntargets = AR5416_NUM_5G_TARGET_PWRS;
1454319da621SChristian Lamparter 			ctpres = ar->power_5G_leg;
1455319da621SChristian Lamparter 			break;
1456319da621SChristian Lamparter 		case 1: /* 2.4 GHz CCK */
1457319da621SChristian Lamparter 			ctpl = &ar->eeprom.cal_tgt_pwr_2G_cck[0];
1458319da621SChristian Lamparter 			ntargets = AR5416_NUM_2G_CCK_TARGET_PWRS;
1459319da621SChristian Lamparter 			ctpres = ar->power_2G_cck;
1460319da621SChristian Lamparter 			break;
1461319da621SChristian Lamparter 		case 2: /* 2.4 GHz OFDM */
1462319da621SChristian Lamparter 			ctpl = &ar->eeprom.cal_tgt_pwr_2G_ofdm[0];
1463319da621SChristian Lamparter 			ntargets = AR5416_NUM_2G_OFDM_TARGET_PWRS;
1464319da621SChristian Lamparter 			ctpres = ar->power_2G_ofdm;
1465319da621SChristian Lamparter 			break;
1466319da621SChristian Lamparter 		default:
1467319da621SChristian Lamparter 			BUG();
1468319da621SChristian Lamparter 		}
1469319da621SChristian Lamparter 
1470319da621SChristian Lamparter 		for (n = 0; n < ntargets; n++) {
1471319da621SChristian Lamparter 			if (ctpl[n].freq == 0xff)
1472319da621SChristian Lamparter 				break;
1473319da621SChristian Lamparter 			pwr_freqs[n] = ctpl[n].freq;
1474319da621SChristian Lamparter 		}
1475319da621SChristian Lamparter 		ntargets = n;
1476319da621SChristian Lamparter 		idx = carl9170_find_freq_idx(ntargets, pwr_freqs, f);
1477319da621SChristian Lamparter 		for (n = 0; n < 4; n++)
1478319da621SChristian Lamparter 			ctpres[n] = carl9170_interpolate_u8(f,
1479319da621SChristian Lamparter 				ctpl[idx + 0].freq, ctpl[idx + 0].power[n],
1480319da621SChristian Lamparter 				ctpl[idx + 1].freq, ctpl[idx + 1].power[n]);
1481319da621SChristian Lamparter 	}
1482319da621SChristian Lamparter 
1483319da621SChristian Lamparter 	/* HT modes now: 5G HT20, 5G HT40, 2G CCK, 2G OFDM, 2G HT20, 2G HT40 */
1484319da621SChristian Lamparter 	for (i = 0; i < 4; i++) {
1485319da621SChristian Lamparter 		switch (i) {
1486319da621SChristian Lamparter 		case 0: /* 5 GHz HT 20 */
1487319da621SChristian Lamparter 			ctph = &ar->eeprom.cal_tgt_pwr_5G_ht20[0];
1488319da621SChristian Lamparter 			ntargets = AR5416_NUM_5G_TARGET_PWRS;
1489319da621SChristian Lamparter 			ctpres = ar->power_5G_ht20;
1490319da621SChristian Lamparter 			break;
1491319da621SChristian Lamparter 		case 1: /* 5 GHz HT 40 */
1492319da621SChristian Lamparter 			ctph = &ar->eeprom.cal_tgt_pwr_5G_ht40[0];
1493319da621SChristian Lamparter 			ntargets = AR5416_NUM_5G_TARGET_PWRS;
1494319da621SChristian Lamparter 			ctpres = ar->power_5G_ht40;
1495319da621SChristian Lamparter 			break;
1496319da621SChristian Lamparter 		case 2: /* 2.4 GHz HT 20 */
1497319da621SChristian Lamparter 			ctph = &ar->eeprom.cal_tgt_pwr_2G_ht20[0];
1498319da621SChristian Lamparter 			ntargets = AR5416_NUM_2G_OFDM_TARGET_PWRS;
1499319da621SChristian Lamparter 			ctpres = ar->power_2G_ht20;
1500319da621SChristian Lamparter 			break;
1501319da621SChristian Lamparter 		case 3: /* 2.4 GHz HT 40 */
1502319da621SChristian Lamparter 			ctph = &ar->eeprom.cal_tgt_pwr_2G_ht40[0];
1503319da621SChristian Lamparter 			ntargets = AR5416_NUM_2G_OFDM_TARGET_PWRS;
1504319da621SChristian Lamparter 			ctpres = ar->power_2G_ht40;
1505319da621SChristian Lamparter 			break;
1506319da621SChristian Lamparter 		default:
1507319da621SChristian Lamparter 			BUG();
1508319da621SChristian Lamparter 		}
1509319da621SChristian Lamparter 
1510319da621SChristian Lamparter 		for (n = 0; n < ntargets; n++) {
1511319da621SChristian Lamparter 			if (ctph[n].freq == 0xff)
1512319da621SChristian Lamparter 				break;
1513319da621SChristian Lamparter 			pwr_freqs[n] = ctph[n].freq;
1514319da621SChristian Lamparter 		}
1515319da621SChristian Lamparter 		ntargets = n;
1516319da621SChristian Lamparter 		idx = carl9170_find_freq_idx(ntargets, pwr_freqs, f);
1517319da621SChristian Lamparter 		for (n = 0; n < 8; n++)
1518319da621SChristian Lamparter 			ctpres[n] = carl9170_interpolate_u8(f,
1519319da621SChristian Lamparter 				ctph[idx + 0].freq, ctph[idx + 0].power[n],
1520319da621SChristian Lamparter 				ctph[idx + 1].freq, ctph[idx + 1].power[n]);
1521319da621SChristian Lamparter 	}
1522319da621SChristian Lamparter 
1523319da621SChristian Lamparter 	/* calc. conformance test limits and apply to ar->power*[] */
1524319da621SChristian Lamparter 	carl9170_calc_ctl(ar, freq, bw);
1525319da621SChristian Lamparter }
1526319da621SChristian Lamparter 
carl9170_get_noisefloor(struct ar9170 * ar)1527319da621SChristian Lamparter int carl9170_get_noisefloor(struct ar9170 *ar)
1528319da621SChristian Lamparter {
1529319da621SChristian Lamparter 	static const u32 phy_regs[] = {
15309adc9e0fSChristian Lamparter 		AR9170_PHY_REG_CCA, AR9170_PHY_REG_CH2_CCA,
15319adc9e0fSChristian Lamparter 		AR9170_PHY_REG_EXT_CCA, AR9170_PHY_REG_CH2_EXT_CCA };
1532319da621SChristian Lamparter 	u32 phy_res[ARRAY_SIZE(phy_regs)];
1533319da621SChristian Lamparter 	int err, i;
1534319da621SChristian Lamparter 
1535319da621SChristian Lamparter 	BUILD_BUG_ON(ARRAY_SIZE(phy_regs) != ARRAY_SIZE(ar->noise));
1536319da621SChristian Lamparter 
1537319da621SChristian Lamparter 	err = carl9170_read_mreg(ar, ARRAY_SIZE(phy_regs), phy_regs, phy_res);
1538319da621SChristian Lamparter 	if (err)
1539319da621SChristian Lamparter 		return err;
1540319da621SChristian Lamparter 
15419adc9e0fSChristian Lamparter 	for (i = 0; i < 2; i++) {
1542b1d771eeSChristian Lamparter 		ar->noise[i] = sign_extend32(GET_VAL(
1543b1d771eeSChristian Lamparter 			AR9170_PHY_CCA_MIN_PWR, phy_res[i]), 8);
1544319da621SChristian Lamparter 
1545b1d771eeSChristian Lamparter 		ar->noise[i + 2] = sign_extend32(GET_VAL(
1546b1d771eeSChristian Lamparter 			AR9170_PHY_EXT_CCA_MIN_PWR, phy_res[i + 2]), 8);
1547319da621SChristian Lamparter 	}
1548319da621SChristian Lamparter 
1549acf17712SChristian Lamparter 	if (ar->channel)
1550acf17712SChristian Lamparter 		ar->survey[ar->channel->hw_value].noise = ar->noise[0];
1551acf17712SChristian Lamparter 
1552319da621SChristian Lamparter 	return 0;
1553319da621SChristian Lamparter }
1554319da621SChristian Lamparter 
nl80211_to_carl(enum nl80211_channel_type type)1555319da621SChristian Lamparter static enum carl9170_bw nl80211_to_carl(enum nl80211_channel_type type)
1556319da621SChristian Lamparter {
1557319da621SChristian Lamparter 	switch (type) {
1558319da621SChristian Lamparter 	case NL80211_CHAN_NO_HT:
1559319da621SChristian Lamparter 	case NL80211_CHAN_HT20:
1560319da621SChristian Lamparter 		return CARL9170_BW_20;
1561319da621SChristian Lamparter 	case NL80211_CHAN_HT40MINUS:
1562319da621SChristian Lamparter 		return CARL9170_BW_40_BELOW;
1563319da621SChristian Lamparter 	case NL80211_CHAN_HT40PLUS:
1564319da621SChristian Lamparter 		return CARL9170_BW_40_ABOVE;
1565319da621SChristian Lamparter 	default:
1566319da621SChristian Lamparter 		BUG();
1567319da621SChristian Lamparter 	}
1568319da621SChristian Lamparter }
1569319da621SChristian Lamparter 
carl9170_set_channel(struct ar9170 * ar,struct ieee80211_channel * channel,enum nl80211_channel_type _bw)1570319da621SChristian Lamparter int carl9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
157156771e50SChristian Lamparter 			 enum nl80211_channel_type _bw)
1572319da621SChristian Lamparter {
1573319da621SChristian Lamparter 	const struct carl9170_phy_freq_params *freqpar;
1574319da621SChristian Lamparter 	struct carl9170_rf_init_result rf_res;
1575319da621SChristian Lamparter 	struct carl9170_rf_init rf;
157656771e50SChristian Lamparter 	u32 tmp, offs = 0, new_ht = 0;
1577319da621SChristian Lamparter 	int err;
1578319da621SChristian Lamparter 	enum carl9170_bw bw;
1579319da621SChristian Lamparter 	struct ieee80211_channel *old_channel = NULL;
1580319da621SChristian Lamparter 
1581319da621SChristian Lamparter 	bw = nl80211_to_carl(_bw);
1582319da621SChristian Lamparter 
158373576110SChristian Lamparter 	if (conf_is_ht(&ar->hw->conf))
158473576110SChristian Lamparter 		new_ht |= CARL9170FW_PHY_HT_ENABLE;
158573576110SChristian Lamparter 
158673576110SChristian Lamparter 	if (conf_is_ht40(&ar->hw->conf))
158773576110SChristian Lamparter 		new_ht |= CARL9170FW_PHY_HT_DYN2040;
158873576110SChristian Lamparter 
1589319da621SChristian Lamparter 	/* may be NULL at first setup */
1590319da621SChristian Lamparter 	if (ar->channel) {
1591319da621SChristian Lamparter 		old_channel = ar->channel;
1592319da621SChristian Lamparter 		ar->channel = NULL;
1593319da621SChristian Lamparter 	}
1594319da621SChristian Lamparter 
159556771e50SChristian Lamparter 	/* cold reset BB/ADDA */
159656771e50SChristian Lamparter 	err = carl9170_write_reg(ar, AR9170_PWR_REG_RESET,
159756771e50SChristian Lamparter 				 AR9170_PWR_RESET_BB_COLD_RESET);
1598319da621SChristian Lamparter 	if (err)
1599319da621SChristian Lamparter 		return err;
1600319da621SChristian Lamparter 
1601319da621SChristian Lamparter 	err = carl9170_write_reg(ar, AR9170_PWR_REG_RESET, 0x0);
1602319da621SChristian Lamparter 	if (err)
1603319da621SChristian Lamparter 		return err;
1604319da621SChristian Lamparter 
1605319da621SChristian Lamparter 	err = carl9170_init_phy(ar, channel->band);
1606319da621SChristian Lamparter 	if (err)
1607319da621SChristian Lamparter 		return err;
1608319da621SChristian Lamparter 
1609319da621SChristian Lamparter 	err = carl9170_init_rf_banks_0_7(ar,
1610*57fbcce3SJohannes Berg 					 channel->band == NL80211_BAND_5GHZ);
1611319da621SChristian Lamparter 	if (err)
1612319da621SChristian Lamparter 		return err;
1613319da621SChristian Lamparter 
1614319da621SChristian Lamparter 	err = carl9170_exec_cmd(ar, CARL9170_CMD_FREQ_START, 0, NULL, 0, NULL);
1615319da621SChristian Lamparter 	if (err)
1616319da621SChristian Lamparter 		return err;
1617319da621SChristian Lamparter 
1618319da621SChristian Lamparter 	err = carl9170_write_reg(ar, AR9170_PHY_REG_HEAVY_CLIP_ENABLE,
1619319da621SChristian Lamparter 				 0x200);
1620c9e57f0fSChristian Lamparter 	if (err)
1621c9e57f0fSChristian Lamparter 		return err;
1622319da621SChristian Lamparter 
1623319da621SChristian Lamparter 	err = carl9170_init_rf_bank4_pwr(ar,
1624*57fbcce3SJohannes Berg 					 channel->band == NL80211_BAND_5GHZ,
1625319da621SChristian Lamparter 					 channel->center_freq, bw);
1626319da621SChristian Lamparter 	if (err)
1627319da621SChristian Lamparter 		return err;
1628319da621SChristian Lamparter 
1629319da621SChristian Lamparter 	tmp = AR9170_PHY_TURBO_FC_SINGLE_HT_LTF1 |
1630319da621SChristian Lamparter 	      AR9170_PHY_TURBO_FC_HT_EN;
1631319da621SChristian Lamparter 
1632319da621SChristian Lamparter 	switch (bw) {
1633319da621SChristian Lamparter 	case CARL9170_BW_20:
1634319da621SChristian Lamparter 		break;
1635319da621SChristian Lamparter 	case CARL9170_BW_40_BELOW:
1636319da621SChristian Lamparter 		tmp |= AR9170_PHY_TURBO_FC_DYN2040_EN |
1637319da621SChristian Lamparter 		       AR9170_PHY_TURBO_FC_SHORT_GI_40;
1638319da621SChristian Lamparter 		offs = 3;
1639319da621SChristian Lamparter 		break;
1640319da621SChristian Lamparter 	case CARL9170_BW_40_ABOVE:
1641319da621SChristian Lamparter 		tmp |= AR9170_PHY_TURBO_FC_DYN2040_EN |
1642319da621SChristian Lamparter 		       AR9170_PHY_TURBO_FC_SHORT_GI_40 |
1643319da621SChristian Lamparter 		       AR9170_PHY_TURBO_FC_DYN2040_PRI_CH;
1644319da621SChristian Lamparter 		offs = 1;
1645319da621SChristian Lamparter 		break;
1646319da621SChristian Lamparter 	default:
1647319da621SChristian Lamparter 		BUG();
1648319da621SChristian Lamparter 		return -ENOSYS;
1649319da621SChristian Lamparter 	}
1650319da621SChristian Lamparter 
1651319da621SChristian Lamparter 	if (ar->eeprom.tx_mask != 1)
1652319da621SChristian Lamparter 		tmp |= AR9170_PHY_TURBO_FC_WALSH;
1653319da621SChristian Lamparter 
1654319da621SChristian Lamparter 	err = carl9170_write_reg(ar, AR9170_PHY_REG_TURBO, tmp);
1655319da621SChristian Lamparter 	if (err)
1656319da621SChristian Lamparter 		return err;
1657319da621SChristian Lamparter 
1658319da621SChristian Lamparter 	err = carl9170_set_freq_cal_data(ar, channel);
1659319da621SChristian Lamparter 	if (err)
1660319da621SChristian Lamparter 		return err;
1661319da621SChristian Lamparter 
166267e43de6SChristian Lamparter 	carl9170_set_power_cal(ar, channel->center_freq, bw);
166367e43de6SChristian Lamparter 
166467e43de6SChristian Lamparter 	err = carl9170_set_mac_tpc(ar, channel);
1665319da621SChristian Lamparter 	if (err)
1666319da621SChristian Lamparter 		return err;
1667319da621SChristian Lamparter 
1668319da621SChristian Lamparter 	freqpar = carl9170_get_hw_dyn_params(channel, bw);
1669319da621SChristian Lamparter 
167073576110SChristian Lamparter 	rf.ht_settings = new_ht;
167173576110SChristian Lamparter 	if (conf_is_ht40(&ar->hw->conf))
167273576110SChristian Lamparter 		SET_VAL(CARL9170FW_PHY_HT_EXT_CHAN_OFF, rf.ht_settings, offs);
1673319da621SChristian Lamparter 
1674319da621SChristian Lamparter 	rf.freq = cpu_to_le32(channel->center_freq * 1000);
1675319da621SChristian Lamparter 	rf.delta_slope_coeff_exp = cpu_to_le32(freqpar->coeff_exp);
1676319da621SChristian Lamparter 	rf.delta_slope_coeff_man = cpu_to_le32(freqpar->coeff_man);
1677319da621SChristian Lamparter 	rf.delta_slope_coeff_exp_shgi = cpu_to_le32(freqpar->coeff_exp_shgi);
1678319da621SChristian Lamparter 	rf.delta_slope_coeff_man_shgi = cpu_to_le32(freqpar->coeff_man_shgi);
1679319da621SChristian Lamparter 	rf.finiteLoopCount = cpu_to_le32(2000);
168056771e50SChristian Lamparter 	err = carl9170_exec_cmd(ar, CARL9170_CMD_RF_INIT, sizeof(rf), &rf,
1681319da621SChristian Lamparter 				sizeof(rf_res), &rf_res);
1682319da621SChristian Lamparter 	if (err)
1683319da621SChristian Lamparter 		return err;
1684319da621SChristian Lamparter 
1685319da621SChristian Lamparter 	err = le32_to_cpu(rf_res.ret);
1686319da621SChristian Lamparter 	if (err != 0) {
1687319da621SChristian Lamparter 		ar->chan_fail++;
1688319da621SChristian Lamparter 		ar->total_chan_fail++;
1689319da621SChristian Lamparter 
1690319da621SChristian Lamparter 		wiphy_err(ar->hw->wiphy, "channel change: %d -> %d "
1691319da621SChristian Lamparter 			  "failed (%d).\n", old_channel ?
1692319da621SChristian Lamparter 			  old_channel->center_freq : -1, channel->center_freq,
1693319da621SChristian Lamparter 			  err);
1694319da621SChristian Lamparter 
169556771e50SChristian Lamparter 		if (ar->chan_fail > 3) {
169656771e50SChristian Lamparter 			/* We have tried very hard to change to _another_
1697319da621SChristian Lamparter 			 * channel and we've failed to do so!
1698319da621SChristian Lamparter 			 * Chances are that the PHY/RF is no longer
1699319da621SChristian Lamparter 			 * operable (due to corruptions/fatal events/bugs?)
1700319da621SChristian Lamparter 			 * and we need to reset at a higher level.
1701319da621SChristian Lamparter 			 */
1702319da621SChristian Lamparter 			carl9170_restart(ar, CARL9170_RR_TOO_MANY_PHY_ERRORS);
1703319da621SChristian Lamparter 			return 0;
1704319da621SChristian Lamparter 		}
1705319da621SChristian Lamparter 
170656771e50SChristian Lamparter 		err = carl9170_set_channel(ar, channel, _bw);
1707319da621SChristian Lamparter 		if (err)
1708319da621SChristian Lamparter 			return err;
1709319da621SChristian Lamparter 	} else {
1710319da621SChristian Lamparter 		ar->chan_fail = 0;
1711319da621SChristian Lamparter 	}
1712319da621SChristian Lamparter 
1713319da621SChristian Lamparter 	if (ar->heavy_clip) {
1714319da621SChristian Lamparter 		err = carl9170_write_reg(ar, AR9170_PHY_REG_HEAVY_CLIP_ENABLE,
1715319da621SChristian Lamparter 					 0x200 | ar->heavy_clip);
1716319da621SChristian Lamparter 		if (err) {
1717319da621SChristian Lamparter 			if (net_ratelimit()) {
1718319da621SChristian Lamparter 				wiphy_err(ar->hw->wiphy, "failed to set "
1719319da621SChristian Lamparter 				       "heavy clip\n");
1720319da621SChristian Lamparter 			}
1721319da621SChristian Lamparter 
1722319da621SChristian Lamparter 			return err;
1723319da621SChristian Lamparter 		}
1724319da621SChristian Lamparter 	}
1725319da621SChristian Lamparter 
1726319da621SChristian Lamparter 	ar->channel = channel;
172773576110SChristian Lamparter 	ar->ht_settings = new_ht;
1728319da621SChristian Lamparter 	return 0;
1729319da621SChristian Lamparter }
1730