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